  require "scripts/style"
-- The "Twodemos" game handles its messages in Lua, unlike the "TGame" game
-- which handles them in C++.

-- if it is false initialization is not yet OK
gWorldMapInitDone = false;

-- global variables for weaponUnlocked.lua
gWeaponUnlockedIcon = "pics/weapons/weapon_icons/w1_icon"
gWeaponUnlockedDescription = "weaponUnlockedDescription01"
-- global variable for nextStationDialog
gNextStationDescription = "nextStation_DontHaveMoneyText"
gNextStationImage = "buildings/icons/building_icon_00"
gNextBuildingName = "BuildingName0"
gFoodNbr = 0;
gMoneyNbr = 0;
gStoneNbr = 0;
gWoodNbr = 0;

-- global variables for level chooser menu (choose_level_menu.lua)
gLvlNumber = 1; -- starting level number of the station

-- global variable for weapon buy menu
gWUnlockArray = { 0, 0, 0, 0, 0, 0, 0 }; -- w1 .. w7
gWCostArray   = {100, 100, 100, 100, 100, 100, 100}; -- how much each weapon costs
gUserWeaponPoints = 0; -- how many points the user have?

-- global variables for worldmap
gLevelInProgress = false;
gGameFinished    = false;
gNextStationDialogClosed = 0; -- important hen the outro should be played
-- helper for the infoBar text positioning
infoBarBestTimesTextPosX = 30
infoBarBestTimesTextPosY = 60
infoBarLevelNameOffsetX  = 20
infoBarLevelTimeOffsetX  = 55


function swapToOutro( )
    SwapToModal("scripts/outro.lua");
end

function enablePrevNextStationButtons( enab )
    
    if (enab == true) then -- weapon is locked, disabled
        SetWindowVisible( "PrevStationButton", true )	
        SetWindowVisible( "NextStationButton", true )
    else
        SetWindowVisible( "PrevStationButton", false )	
        SetWindowVisible( "NextStationButton", false )
    end
end

function setPlayButton( cont )
    
    if (cont == true) then
        SetWindowVisible( "ContNextLevelButton", true )	
        SetWindowVisible( "NextLevelButton", false )
    else
        SetWindowVisible( "ContNextLevelButton", false )	
        SetWindowVisible( "NextLevelButton", true )
    end
end

MakeDialog
{
	name="worldMapDialog",
	
    Bitmap
	{
		name="backgroundimage",
		image="backgrounds/blackbcg",		
		x=kCenter,
		y=kCenter,
	
		WorldMap
		{
			name="MapOfTheWorld",
			x=0,
			y=0,
			w=kMax,
			h=kMax,
			rows=gRows,
			columns=gColumns,
-- Buttons
-- Buy button
			SetStyle(WorldMapMenuButtonStyle);
			Button
			{
				-- x=390,
				-- y=685,
				x=390,--405,
				y=707,
				name="weaponBuyButton",
				graphics=ReBuildButtonGraphics,
				type = kPush,
				command=
					function()
						if (gWorldMapInitDone == true) then
							-- Bring forth the weapon buy menu
							if (gLevelInProgress == false) then
								DoModal("scripts/weapon_buy_menu.lua");
							else
								DisplayDialog {
									"scripts/ok.lua",
									body ="cantbuyweapon",
									title = "levelinprogress"
								};  
							end                        
						end
					end	
			};				
-- station info button
            Button
            {
                x=574,
                y=707,
                name="StationInfoButton",
                graphics=StationInfoButtonGraphics,
                type = kPush,
                command=
                    function()
						if (gWorldMapInitDone == true) then
                            -- Bring forth the info page
                            DoModal("scripts/infopage.lua");
						end
                    end	
            };  
-- Exit            
			Button
			{
				x=945,
				y=0,
				name="WorldMapExitButton",
				graphics=WorldMapExitGraphics,
				type = kPush,
				command=
					function()
						if (gWorldMapInitDone == true) then
							SwapToModal("scripts/mainmenu.lua");
						end
					end	
			};
-- Play next level  START
			Button
			{
				x=453,
				y=650,
				name="NextLevelButton",
				graphics=NextLevelButtonGraphics,
				type = kPush,
				command=
					function()
						if (gWorldMapInitDone == true) then
							if gGameFinished then
								nextLevelButtonPressed();
								startLvl = DoModal("scripts/choose_level_menu.lua");
								if startLvl == true  then
									SetCurrentGameMode(1);
									SetState( kGameMode, "samplegame" );
									stopMusic();
									-- Switch to the appropriate screen
									SwapToModal("scripts/game.lua");
								end
							else
								-- tell worldMap that the button has been pressed
								stopMusic();
								-- Tell TSettings what game mode we're entering
								SetCurrentGameMode(1);
								SetState( kGameMode, "samplegame" )
								-- Switch to the appropriate screen
								SwapToModal("scripts/game.lua");
							end
						end
					end
			};
-- Play next level  CONTINUE
			Button
			{
				x=453,
				y=650,
				name="ContNextLevelButton",
				graphics=ContinueLevelButtonGraphics,
				type = kPush,
				command=
					function()
						if (gWorldMapInitDone == true) then
							-- tell worldMap that the button has been pressed
							stopMusic();
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(1);
							SetState( kGameMode, "samplegame" );
							-- Switch to the appropriate screen
							SwapToModal("scripts/game.lua");
						end
					end
			};     
-- Previous Station button
            Button
            {
                x=440,--430,
                y=595,--610,
                --scale=0.8,                
                name="PrevStationButton",
                graphics=PrevStationButtonGraphics,
                type = kPush,
                command=
                    function()
						if (gWorldMapInitDone == true) then
							if gLevelInProgress == true then
								resetLevel = DoModal("scripts/reset_or_play_level.lua");
								if resetLevel == true then
									gLevelInProgress = false;
									resetLevelInProgress();
									setPlayButton(false);
									prevStation();
								end
							else
								prevStation()
							end
						end
                    end	
            };
-- Next Station button
            Button
            {
                x=524,--534,
                y=595,--610,
                --scale=0.8,
                name="NextStationButton",
                graphics=NextStationButtonGraphics,
                type = kPush,
                command=
                    function()
						if (gWorldMapInitDone == true) then
							if gLevelInProgress == true then
								resetLevel = DoModal("scripts/reset_or_play_level.lua");
								if resetLevel == true then
									gLevelInProgress = false;
									resetLevelInProgress();
									setPlayButton(false);
									nextStation();
								end
							else                    
								nextStation()
							end
						end
                    end	
            };	
--[[            
			Button
			{
				x=930,
				y=295,
				name="NextStationButton",
				graphics=NextStationButtonGraphics,
				type = kPush,
				command=
					function()
							nextStation()
					end	
			};			
			Button
			{
				x=830,
				y=295,
				name="PrevStationButton",
				graphics=PrevStationButtonGraphics,
				type = kPush,
				command=
					function()
							prevStation()
					end	
			};--]]	
            
            
-- ***********************            
-- infobar with statistics
-- ***********************            
			Bitmap
			{
				name="InfoBar",
				image="backgrounds/infobar_background",
				x=835,
				y=250,

                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFontBig,
                    name = "infoBar_stationName",
                    x=20,
                    y=25,
                    w=142,
                    h=30,
                    flags = kHAlignCenter + kVAlignCenter,
                    label = "StationName1"
                };

                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFontSmall,
                    name = "infoBar_bestTimeText",
                    x=infoBarBestTimesTextPosX,
                    y=infoBarBestTimesTextPosY,
                    w=100,
                    h=20,
                    label = "infoBar_bestTimeText"
                };            
-- level1 best time
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level1Text",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX,
                    y=infoBarBestTimesTextPosY + 20,
                    w=55,
                    h=20,
                    label = "infoBar_Level1Text"
                };       
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level1Time",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX + infoBarLevelTimeOffsetX,
                    y=infoBarBestTimesTextPosY + 20,
                    w=50,
                    h=20,
                    label = "infoBar_LevelTimeEmpty"
                };            
-- level2 best time
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level2Text",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX,
                    y=infoBarBestTimesTextPosY + 40,
                    w=55,
                    h=20,
                    label = "infoBar_Level2Text"
                };       
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level2Time",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX + infoBarLevelTimeOffsetX,
                    y=infoBarBestTimesTextPosY + 40,
                    w=50,
                    h=20,
                    label = "infoBar_LevelTimeEmpty"
                };     
-- level3 best time
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level3Text",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX,
                    y=infoBarBestTimesTextPosY + 60,
                    w=55,
                    h=20,
                    label = "infoBar_Level3Text"
                };       
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level3Time",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX + infoBarLevelTimeOffsetX,
                    y=infoBarBestTimesTextPosY + 60,
                    w=50,
                    h=20,
                    label = "infoBar_LevelTimeEmpty"
                };  
-- level4 best time
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level4Text",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX,
                    y=infoBarBestTimesTextPosY + 80,
                    w=55,
                    h=20,
                    label = "infoBar_Level4Text"
                };       
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level4Time",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX + infoBarLevelTimeOffsetX,
                    y=infoBarBestTimesTextPosY + 80,
                    w=50,
                    h=20,
                    label = "infoBar_LevelTimeEmpty"
                }; 
-- level5 best time
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level5Text",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX,
                    y=infoBarBestTimesTextPosY + 100,
                    w=55,
                    h=20,
                    label = "infoBar_Level5Text"
                };       
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level5Time",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX + infoBarLevelTimeOffsetX,
                    y=infoBarBestTimesTextPosY + 100,
                    w=50,
                    h=20,
                    label = "infoBar_LevelTimeEmpty"
                }; 
-- level6 best time
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level6Text",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX,
                    y=infoBarBestTimesTextPosY + 120,
                    w=55,
                    h=20,
                    label = "infoBar_Level6Text"
                };       
                Text
                {
                    align=kHAlignLeft,
                    font = StandardButtonFont,
                    name = "infoBar_Level6Time",
                    x=infoBarBestTimesTextPosX + infoBarLevelNameOffsetX + infoBarLevelTimeOffsetX,
                    y=infoBarBestTimesTextPosY + 120,
                    w=50,
                    h=20,
                    label = "infoBar_LevelTimeEmpty"
                }; 
            };            
-- upper points menu			
			Bitmap
			{
				name="PointsCloud",
				image="pics/felso_felho",
				x=0,   --90,
				y=0, --735,
				scale=0.8
			};
			Bitmap
			{
				name="PointsIcon",
				image="pics/items/points",
				x=5,
				y=7
			};            
			Text
			{
				-- align=kHAlignRight + kVAlignTop,
				font = PointTextFont,
				name = "PointsNumber",
				x=45,
				y=15,
				w=100,
				h=100,
				--flags = kHAlignCenter + kVAlignCenter,
				label = "PointsNumber"
			};
			Bitmap
			{
				name="FoodCloud",
				image="pics/felso_felho",
				x=180,
				y=0,
				scale=0.8
			};	
			Bitmap
			{
				name="FoodIcon",
				image="pics/food_lvl1",
				x=185,
				y=7
			};	
			Text
			{
				font = PointTextFont,
				name = "FoodNumber",
				x=230,
				y=15,
				w=100,
				h=100,
				label = "FoodNumber"
			};		
			Bitmap
			{
				name="MoneyCloud",
				image="pics/felso_felho",
				x=360,
				y=0,
				scale=0.8
			};
			Bitmap
			{
				name="MoneyIcon",
				image="pics/money_lvl1",
				x=365,
				y=7
			};
			Text
			{
				font = PointTextFont,
				name = "MoneyNumber",
				x=415,
				y=15,
				w=100,
				h=100,
				label = "MoneyNumber"
			};				
			Bitmap
			{
				name="StoneCloud",
				image="pics/felso_felho",
				x=540,
				y=0,
				scale=0.8
			};
			Bitmap
			{
				name="StoneIcon",
				image="pics/stone_lvl1",
				x=545,
				y=7
			};
			Text
			{
				font = PointTextFont,
				name = "StoneNumber",
				x=590,
				y=15,
				w=100,
				h=100,
				label = "StoneNumber"
			};
			Bitmap
			{
				name="WoodCloud",
				image="pics/felso_felho",
				x=720,
				y=0,
				scale=0.8
			};
			Bitmap
			{
				name="WoodIcon",
				image="pics/wood_lvl1",
				x=725,
				y=7
			};
			Text
			{
				font = PointTextFont,
				name = "WoodNumber",
				x=770,
				y=15,
				w=100,
				h=100,
				label = "WoodNumber"
			};		
			Bitmap
			{
				name="blackness",
				image="backgrounds/blackbcg",
				x=0,   --90,
				y=0, --735,
			};        
--[[            
			Bitmap
			{
				name="ExtraCloud",
				image="pics/felso_felho",
				x=900,
				y=0,
				scale=0.8
			};
--]]            
--   Station name (Wol)
--[[
			Text
			{
				font = PointTextFont,
				name = "StationNameWindow",
				x=377,
				y=372,
				w=200,
				h=100,
				label = "StationName1"
			};		--]]		
--			SetStyle(ButtonStyle),
		}
	}
}

SetWindowVisible("blackness",false);
-- The swarm window wants to get any key presses, so let's give it the focus
--SetFocus("swarm");