--Specjalizacja dla : Ursus 912 By Maciusboss1 & Asd4
--#Autor: Asd4
--#data: 27/03/2011 r.
--#Totalna edycja: 15/11/2011 r.
--Przy edycji nie zapomnij o oryginalnym autorze!
--

jd7930 = {};

function jd7930.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

function jd7930:load(xmlFile)

	local klapalewa = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#lewe"));
	if klapalewa ~= nil then
		self.klapalewa = klapalewa;
	end;
		local klapaprawa = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#prawe"));
	if klapaprawa ~= nil then
		self.klapaprawa = klapaprawa;
	end;
		local zaczep = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#zaczep"));
	if zaczep ~= nil then
		self.zaczep = zaczep;
	end;

      
   self.hudInfoBasePosX = 0.3;
    self.hudInfoBaseWidth = 0.65;
    self.hudInfoBasePosY = 0.445;
    self.hudInfoBaseHeight = 0.50;
    self.infoPanelPath = Utils.getFilename("HUD.png", self.baseDirectory);
	  self.hudInfoBaseOverlay = Overlay:new("hudInfoBaseOverlay", self.infoPanelPath, self.hudInfoBasePosX, self.hudInfoBasePosY, self.hudInfoBaseWidth, self.hudInfoBaseHeight);
    self.showHudInfoBase = false;    


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

   if isDown and sym == Input.KEY_0 then
		self.pomoc = not self.pomoc;
	end;
  
end;


function jd7930:update(dt)

        local nearestDistance = 2.1;
		local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
		
		local px, py, pz = getWorldTranslation(self.klapalewa); 
		local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);	
		if distance < nearestDistance then
			self.przyklapiel = true; 
		else
			self.przyklapiel = false; 
		end;
		
		local rx, ry, rz = getWorldTranslation(self.klapaprawa); 
		local distance = Utils.vector3Length(rx-vx, ry-vy, rz-vz);	
		if distance < nearestDistance then
			self.przytuzie = true;
		else
			self.przytuzie = false;
		end; 
		
		local ax, ay, az = getWorldTranslation(self.zaczep); 
		local distance = Utils.vector3Length(ax-vx, ay-vy, az-vz);	
		if distance < nearestDistance then
			self.przyzaczepie = true; 
		else
			self.przyzaczepie = false; 
		end; 
--------drzwi----------------

	if self.przyklapiel or self.isEntered then
	if InputBinding.hasEvent(InputBinding.LEWE) then
			if self.animationParts[1].clipEndTime then
				self:setAnimationTime(1, self.animationParts[1].offSet);
			elseif self.animationParts[1].clipStartTime then
				self:setAnimationTime(1, self.animationParts[1].animDuration);
			end;
		end;
	end;
	--tuz-
	
		if self.przytuzie or self.isEntered then
		if InputBinding.isPressed(InputBinding.HYDP_WYZEJ) then
               self:setAnimationTime(5, self.animationParts[5].currentPosition+(self.animationParts[5].offSet+dt), false);
           elseif InputBinding.isPressed(InputBinding.HYDP_NIZEJ) then
               self:setAnimationTime(5, self.animationParts[5].currentPosition-(self.animationParts[5].offSet+dt), false);
        end;
		end;

	--szyba--
	if self.isEntered then
		if InputBinding.hasEvent(InputBinding.SZYBA) then
			if self.animationParts[2].clipEndTime then
				self:setAnimationTime(2, self.animationParts[2].offSet);
			elseif self.animationParts[2].clipStartTime then
				self:setAnimationTime(2, self.animationParts[2].animDuration);
			end;
		end;
		end;
	--podnosnik
		if self.przyzaczepie or self.isEntered then
		if InputBinding.isPressed(InputBinding.PODW) then
               self:setAnimationTime(4, self.animationParts[4].currentPosition+(self.animationParts[4].offSet+dt), false);
           elseif InputBinding.isPressed(InputBinding.PODN) then
               self:setAnimationTime(4, self.animationParts[4].currentPosition-(self.animationParts[4].offSet+dt), false);
        end;
		end;
	--zaczep--
	if self.przyzaczepie or self.isEntered then
	 	if InputBinding.isPressed(InputBinding.ZACZEPW) then
               self:setAnimationTime(3, self.animationParts[3].currentPosition+(self.animationParts[3].offSet+dt), false);
           elseif InputBinding.isPressed(InputBinding.ZACZEPN) then
               self:setAnimationTime(3, self.animationParts[3].currentPosition-(self.animationParts[3].offSet+dt), false);
        end;
        end;
     ---skladanie tuza --
     	if self.przytuzie then
    	if InputBinding.hasEvent(InputBinding.HYD_SKLADANIE) then
			if self.animationParts[6].clipEndTime then
				self:setAnimationTime(6, self.animationParts[6].offSet);
			elseif self.animationParts[6].clipStartTime then
				self:setAnimationTime(6, self.animationParts[6].animDuration);
			end;
		end;
  end;
	  --napisy
		if self.przyzaczepie then
			g_currentMission:addExtraPrintText(string.format("%s: Zaczep Nizej", InputBinding.getKeyNamesOfDigitalAction(InputBinding.ZACZEPW)));
			g_currentMission:addExtraPrintText(string.format("%s: Zaczep Wyzej", InputBinding.getKeyNamesOfDigitalAction(InputBinding.ZACZEPN)));
		end;
		if self.przyklapiel then
	if self.animationParts[2].clipStartTime then
			g_currentMission:addExtraPrintText(string.format("%s: Otworz Drzwi", InputBinding.getKeyNamesOfDigitalAction(InputBinding.LEWE)));
		else
			g_currentMission:addExtraPrintText(string.format("%s: Zamknij Drzwi", InputBinding.getKeyNamesOfDigitalAction(InputBinding.LEWE)));
		end;
		end;
			if self.przytuzie then
	if self.animationParts[6].clipStartTime then
			g_currentMission:addExtraPrintText(string.format("%s: Rozloz TUZ", InputBinding.getKeyNamesOfDigitalAction(InputBinding.HYD_SKLADANIE)));
		else
			g_currentMission:addExtraPrintText(string.format("%s: Zloz TUZ", InputBinding.getKeyNamesOfDigitalAction(InputBinding.HYD_SKLADANIE)));
		end;
		end;
			 

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

function jd7930:validateAttacherJoint(implement, jointDesc, dt)
    return true;
end;
function jd7930:draw()

    if self.isEntered then
		if not self.pomoc then
			renderText(0.833, 0.175, 0.02, "Wcisnij 0: Pokaz pomoc");
		else
			renderText(0.833, 0.175, 0.02, "Wcisnij 0: Schowaj pomoc");
		end;		
		if self.pomoc and self.isEntered then
		self.hudInfoBaseOverlay:render();
	end;
	end;
	
  
end;

