--
-- MMRearCam
--
-- Rückfahr-Kamera
--
-- by MMAgrarservice
--

MMRearCam = {};

function MMRearCam.prerequisitesPresent(specializations)
    return true;
end;

function MMRearCam:load()
	self.MMRearCamPosX = 0.48;
	self.MMRearCamWidth = 0.32;
	self.MMRearCamPosY = 0.74;
	self.MMRearCamHeight = 0.24;
        self.MMRearCamFrame = Utils.getFilename("textures/MMRearCamFrame.dds", self.baseDirectory);
	self.MMRearCamFrameOverlay = Overlay:new("MMRearCamFrameOverlay", self.MMRearCamFrame, self.MMRearCamPosX, self.MMRearCamPosY, self.MMRearCamWidth, self.MMRearCamHeight);
	self.showMMRearCam = 0;
end;

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

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

function MMRearCam:update()
	if self:getIsActiveForInput() then
		if InputBinding.hasEvent(InputBinding.MMRearCam) and self.isEntered then
			self.showMMRearCam = self.showMMRearCam+1;
			if self.showMMRearCam == 2 then
				self.showMMRearCam = 0;
			end;
		end;
	end;
end;
	
function MMRearCam:draw()
	if self.showMMRearCam == 0 then
		g_currentMission:addHelpButtonText(g_i18n:getText("MMRearCamOFF"), InputBinding.MMRearCam);
		self.MMRearCam = 0;
		link(self.rootNode, self.MMRearCam);
		node = getRootNode(0);
		setRootNode(node, 1);
		setViewport(1, 0.48, 0.02, 0.32, 0.24);
		setCamera(self.MMRearCam,1);
	elseif self.showMMRearCam == 1 then
		g_currentMission:addHelpButtonText(g_i18n:getText("MMRearCamON"), InputBinding.MMRearCam);
		self.MMRearCam = createCamera("MMRearCam", 100, 0.1, 110);
		link(self.rootNode, self.MMRearCam);
		translate (self.MMRearCam,0,4,-3);
		rotate(self.MMRearCam,-0.8,0,0);
		node = getRootNode(0);
		setRootNode(node, 1);
		setViewport(1, 0.48, 0.02, 0.32, 0.24);
		setCamera(self.MMRearCam,1);
		self.MMRearCamFrameOverlay:render();
	end;
end;

function MMRearCam:delete()
end;

function MMRearCam:onLeave()
		self.MMRearCam = 0;
		link(self.rootNode, self.MMRearCam);
		node = getRootNode(0);
		setRootNode(node, 1);
		setViewport(1, 0.48, 0.02, 0.32, 0.24);
		setCamera(self.MMRearCam,1);
end;
