--
--SearchBuyableObjectScript = {}
--
--to search MapBuyableObject.zip. If is build in the current Map and script is bulid in the show Message
-- 
-- Include into the map moddesc.xml / Einbinden in die Map moddesc.xml
--	<extraSourceFiles>
--		<sourceFile filename="scripte/SearchBuyableObjectScript.lua" />
--	</extraSourceFiles>
--
--
--@date: 07/09/2013
--@Author: Bluebaby210		www.mod-portal.com
--@Version: v1.0	release 
--
--darf in jede Map eingebaut werden, MapBuyableObject.zip darf nicht neu hochgeladen werden
--
--Keine Änderung ohne meine Erlaubnis
--No modification without my permission


	print("   SearchBuyableObjectScript v1.0  by Bluebaby210 loaded!");

SearchBuyableObjectScript = {}
SearchBuyableObjectScript_dir = g_currentModDirectory;

function SearchBuyableObjectScript:loadMap(name)

		self.nameBase = g_currentMission.missionInfo.baseDirectory
		self.searchName = g_modsDirectory.."/MapBuyableObject.zip";
		
		if not fileExists(self.searchName) then
			if self.nameBase == SearchBuyableObjectScript_dir then
				self.mapBuyableObjectFailed = true;
				self.showMessage = true;
				print("--		Warning: MapBuyableObject.zip failed! Download the file: www.mod-portal.com");
				--print(self.nameBase);
				--print(SearchBuyableObjectScript_dir);
				self.leng = getSystemLanguage();
				if self.leng == 1 then
					self:readTextDE();
				elseif self.leng == 5 then
					self:readTextFR();
				else
					self:readTextEN();
				end;
			end;
		else
			self.mapBuyableObjectFailed = false;
			self.showMessage = false;
		end;
		
		self.newOverlay = g_currentMission.hudWarningBaseOverlay.overlayId;
end;

function SearchBuyableObjectScript:deleteMap()
end;

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

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

function SearchBuyableObjectScript:readStream(streamId, connection)
end;

function SearchBuyableObjectScript:writeStream(streamId, connection)
end;

function SearchBuyableObjectScript:update(dt)

	if self.mapBuyableObjectFailed then
		if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA) then
			self.mapBuyableObjectFailed = false;
			self.showMessage = false;
		end;
	end;

end;

function SearchBuyableObjectScript:draw()
	if self.showMessage and self.mapBuyableObjectFailed then
		renderOverlay(self.newOverlay, -0.1, 0.33, 1.5, 0.375);
		setTextColor(1,0.80,0,1);
		setTextBold(true);
		renderText(self.textHeadPL, self.textHeadPH, self.textHeadFS, self.textHead);
		setTextBold(false);
		for k=1,table.getn(self.textName) do 
			renderText(0.06, self.textPos[k], 0.03, self.textName[k]);
		end;
		renderText(0.26, (0.62- (0.031 * (table.getn(self.textName)+2))), 0.03, ("Close Message:"));
		renderText(0.48, (0.62- (0.031 * (table.getn(self.textName)+2))), 0.03, InputBinding.getKeyNamesOfDigitalAction(InputBinding.IMPLEMENT_EXTRA));
		setTextColor(0,0,0,1);
	end;
end;

function SearchBuyableObjectScript:readTextDE()
	self.textName = {};
	self.textPos = {};
	self.textHead = "Fehlen der MapBuyableObject.zip"
	self.textHeadPL = 0.26;
	self.textHeadPH = 0.625;
	self.textHeadFS = 0.04;
	self.textName[1] = "Ihnen fehlt die MapBuyableObject.zip im Mods Ordner. Ohne diesen Mod ist die Map nur"
	self.textName[2] = "bedingt spielbar. Es kann dazu führen, das sie Objekte auf der Map ineinander stehen haben,"
	self.textName[3] = "oder Icons die nicht drehen und nicht deaktivieren lassen. Der Erbauer der Map hat für"
	self.textName[4] = "maximalen Spielspass einige Objekte so ausgestattet, das sie erst gekauft werden müssen um"
	self.textName[5] = "die vollen Funktionen der Map nutzen zu können."
	self.textName[6] = "Sie können die MapBuyableObject.zip unter www.mod-portal.com kostenlos runterladen."
		for k=1,table.getn(self.textName) do 
			self.textPos[k] = 0.62 - (0.031 * k);
		end;
end;

function SearchBuyableObjectScript:readTextFR()
	self.textName = {};
	self.textPos = {};
	self.textHead = "Missing MapBuyableObject.zip"
	self.textHeadPL = 0.26;
	self.textHeadPH = 0.625;
	self.textHeadFS = 0.04;
	self.textName[1] = "You miss the MapBuyableObject.zip in the mods directory. Without this mod the "
	self.textName[2] = "map is only conditionally playable.It may have cause they are objects on the map into each other,"
	self.textName[3] = "or icons that do not turn and do not let off. The Creator has build some "
	self.textName[4] = "new Objects which must buyed before playing."
	self.textName[5] = ""
	self.textName[6] = "You can download MapBuyableObject.zip on www.mod-portal.com for free."
		for k=1,table.getn(self.textName) do 
			self.textPos[k] = 0.62 - (0.031 * k);
		end;
end;

function SearchBuyableObjectScript:readTextEN()
	self.textName = {};
	self.textPos = {};
	self.textHead = "Missing MapBuyableObject.zip"
	self.textHeadPL = 0.26;
	self.textHeadPH = 0.625;
	self.textHeadFS = 0.04;
	self.textName[1] = "You miss the MapBuyableObject.zip in the mods directory. Without this mod the "
	self.textName[2] = "map is only conditionally playable.It may have cause they are objects on the map into each other,"
	self.textName[3] = "or icons that do not turn and do not let off. The Creator has build some "
	self.textName[4] = "new Objects which must buyed before playing."
	self.textName[5] = ""
	self.textName[6] = "You can download MapBuyableObject.zip on www.mod-portal.com for free."
		for k=1,table.getn(self.textName) do 
			self.textPos[k] = 0.62 - (0.031 * k);
		end;
end;
addModEventListener(SearchBuyableObjectScript);