_=[[
author: igor29381

strings for xml:	строки для xml (желательно для каждого груза свою строку, строк может быть сколько угодно)

<CargoUnits>
	<cargoUnit index=" " fruitType=" " />
	<cargoUnit index=" " fruitType=" " />
</CargoUnits>
]]

ShowCargoUnits = {};

function ShowCargoUnits.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Trailer, specializations);
end;

function ShowCargoUnits:load(xmlFile)
	self.CargoUnits = {};
	local c = 0;
	while true do
		local baseString = string.format("vehicle.CargoUnits.cargoUnit(%d)#",c);
		local index = getXMLString(xmlFile,baseString.."index");
		local fruitType = getXMLString(xmlFile,baseString.."fruitType");
		if index == nil or fruitType == nil then break; end;
		local units = {};
		units.index = Utils.indexToObject(self.components, index);
		units.count = getNumOfChildren(units.index);
		units.fruitType = fruitType;
		table.insert(self.CargoUnits, units);
		c = c + 1;
	end;
end;

function ShowCargoUnits:delete()
end;

function ShowCargoUnits:readStream(streamId, connection)
end;

function ShowCargoUnits:writeStream(streamId, connection)
end;

function ShowCargoUnits:mouseEvent(posX, posY, isDown, isUp, button)
end;

function ShowCargoUnits:keyEvent(unicode, sym, modifier, isDown)
end;

function ShowCargoUnits:update(dt)
	local FL = math.floor(self.fillLevel);
	local LFL = 0;
	if self.lastFillLevel ~= nil then LFL = math.floor(self.lastFillLevel); end;

	if FL ~= LFL then
		for _,units in ipairs(self.CargoUnits) do
			if self.currentFillType == Fillable.fillTypeNameToInt[units.fruitType] then
				self.UnitsRootNode = units.index;
				self.UnitsCount = units.count;
			end;
		end;
		if self.UnitsCount ~= nil then
			for i=1, self.UnitsCount do
				local units = getChildAt(self.UnitsRootNode, i-1);
				setVisibility(units, false);
			end;
			local percentDecimal = self.fillLevel/self.capacity;
			local UnitsToShow = math.ceil(self.UnitsCount*percentDecimal);
			for i=1, UnitsToShow do
				local units = getChildAt(self.UnitsRootNode, i-1);
				setVisibility(units, true);
			end;
		end;
	end;
	self.lastFillLevel = self.fillLevel;
end;

function ShowCargoUnits:updateTick(dt)
	
end;

function ShowCargoUnits:draw()
end;