require "scripts/style"

gGameRunning = false;

-- globals for items_and_matches_02
gLevel = 2; -- level 2 or 3
gItemType = 4; -- 1=food, 2=money, 3=stone, 4=wood

--[[
function enableReShuffle( enab )
	SetWindowVisible( "reShuffle", enab )
	if(enab == true) then
		invEnab = false
	else 
		invEnab = true
	end
	
	SetWindowVisible( "reShuffleDisabled", invEnab )
end
--]]
function enableWeapon( num, enab )
	local weaponName = "";

	if    (num == 1) then weaponName = "earthquake"
	elseif(num == 2) then weaponName = "hurricane"
	elseif(num == 3) then weaponName = "lightning"
	elseif(num == 4) then weaponName = "tsunami"
	elseif(num == 5) then weaponName = "landslide"
	elseif(num == 6) then weaponName = "chainlightning"
	elseif(num == 7) then weaponName = "freezeTime"
	elseif(num == 8) then weaponName = "reShuffle"
	end
    
    if     (enab == 0) then -- weapon is locked, disabled
        SetWindowVisible( weaponName, false )	
        SetWindowVisible( weaponName .. "Empty", false )
        SetWindowVisible( weaponName .. "Disabled", true )
		if (num == 8) then -- only reshuffle has 2 charges and button for it
			SetWindowVisible( weaponName .. "2", false )	
		end		
    elseif (enab == 1) then -- weapon is enabled but empty
        SetWindowVisible( weaponName, false )	
        SetWindowVisible( weaponName .. "Empty", true )
        SetWindowVisible( weaponName .. "Disabled", false )    
		if (num == 8) then -- only reshuffle has 2 charges and button for it
			SetWindowVisible( weaponName .. "2", false )	
		end		
    elseif (enab == 2) then -- weapon is enabled
        SetWindowVisible( weaponName, true )	
        SetWindowVisible( weaponName .. "Empty", false )
        SetWindowVisible( weaponName .. "Disabled", false )    
		if (num == 8) then -- only reshuffle has 2 charges and button for it
			SetWindowVisible( weaponName .. "2", false )	
		end
	elseif (enab == 3) then -- weapon is enabled, 2 charges
        SetWindowVisible( weaponName .. "2", true )	
		SetWindowVisible( weaponName, false )
        SetWindowVisible( weaponName .. "Empty", false )
        SetWindowVisible( weaponName .. "Disabled", false )    
    end
end

function setLockVisible( enab )
    SetWindowVisible( "pointsLock", enab )
    SetWindowVisible( "foodLock", enab )
    SetWindowVisible( "moneyLock", enab )
    SetWindowVisible( "stoneLock", enab )
    SetWindowVisible( "woodLock", enab )    
end

-- gRows and gColumns are set up in mainmenu.lua
-- Our mini-game set-up
MakeDialog
{
-- dialog for the game screen /background, icon placing../
	name="gamePlayground",
	Bitmap
	{
        -- main background image while playing
		name="backgroundImage",
		image="backgrounds/bg_6",
		autoscale=true,
		GameWindow
		{
			-- the gameplay area with tiles
			name="gameMainWindow",
			x=0,
			y=0,
			w=kMax,
			h=kMax,
			rows=gRows,
			columns=gColumns,
--[[ 
****************************************************
*         ICONS FOR THE COLLECTIBLE ITEMS          *
****************************************************
--]]
-- points icon for number of food, upper menu			
			Bitmap
			{
				name = "pointsPicPointsMenu",
				image = "pics/items/points",
				x = 5,
				y = 5,
				scale = 1.00
			},
-- food icon for number of food, upper menu			
			Bitmap
			{
				name = "foodPicPointsMenu",
				image = "pics/food_lvl1",
				x = 215,
				y = 5,
				scale = 1.00
			},
-- money icon for number of money, upper menu			
			Bitmap
			{
				align=kHAlignLeft + kVAlignTop,
				name = "moneyPicPointsMenu",
				image = "pics/money_lvl1",
				x = 426,
				y = 5,
				scale = 1.00
			},
-- stone icon for number of stone, upper menu			
			Bitmap
			{
				align=kHAlignLeft + kVAlignTop,
				name = "stonePicPointsMenu",
				image = "pics/stone_lvl1",
				x = 635,
				y = 5,
				scale = 1.00
			},
-- wood icon for number of wood, upper menu
            Bitmap
	        {
                align=kHAlignLeft + kVAlignTop,
		        name = "woodPicPointsMenu",
		        image = "pics/wood_lvl1",
		        x = 838,
		        y = 5,
		        scale = 1.00
	        },
            
-- locks for the items
-- points
			Bitmap
			{
				name = "pointsLock",
				image = "pics/simple_lock",
				x = 15,
				y = 15,
				scale = 1.00
			},
-- food
			Bitmap
			{
				name = "foodLock",
				image = "pics/simple_lock",
				x = 225,
				y = 15,
				scale = 1.00
			},
-- money
			Bitmap
			{
				align=kHAlignLeft + kVAlignTop,
				name = "moneyLock",
				image = "pics/simple_lock",
				x = 436,
				y = 15,
				scale = 1.00
			},
-- stone
			Bitmap
			{
				align=kHAlignLeft + kVAlignTop,
				name = "stoneLock",
				image = "pics/simple_lock",
				x = 645,
				y = 15,
				scale = 1.00
			},
-- wood
            Bitmap
	        {
                align=kHAlignLeft + kVAlignTop,
		        name = "woodLock",
		        image = "pics/simple_lock",
		        x = 848,
		        y = 15,
		        scale = 1.00
	        },            
--[[ 
****************************************************
*                  WEAPON BUTTONS                  *
****************************************************
--]]
-- W1: earthquake button
			-- disabled state
			Bitmap
			{
				name = "earthquakeDisabled",
				image = "pics/weapons/w1_earthquake_inactive",
				x = 840,--283,
				y = 655,
				scale = 1.00
			},
			-- empty state
			Bitmap
			{
				name = "earthquakeEmpty",
				image = "pics/weapons/w1_earthquake_empty",
				x = 840,--283,
				y = 655,
				scale = 1.00
			},            
			-- enabled state
			SetStyle( earthquakeButtonStyle ),		
			Button
			{
				x = 840,--283,
				y = 655,
				name="earthquake",
				command=
					function()
						weaponButtonPushed(1);
					end
			},		
-- W2: hurricane button
			-- disabled state
			Bitmap
			{
				name = "hurricaneDisabled",
				image = "pics/weapons/w2_hurricane_inactive",
				x = 283,--173,
				y = 655,
				scale = 1.00
			},	
			-- empty state
			Bitmap
			{
				name = "hurricaneEmpty",
				image = "pics/weapons/w2_hurricane_empty",
				x = 283,--173,
				y = 655,
				scale = 1.00
			},            
			-- enabled state
			SetStyle( hurricaneButtonStyle ),		
			Button
			{
				x = 283,--173,
				y = 655,				
				name="hurricane",
				command=
					function()
						weaponButtonPushed(2);
					end
			},
-- W3: lightning button
			-- disabled state
			Bitmap
			{
				name = "lightningDisabled",
				image = "pics/weapons/w3_lightning_inactive",
				x = 173,--392,
				y = 655,
				scale = 1.00
			},			
			-- empty state
			Bitmap
			{
				name = "lightningEmpty",
				image = "pics/weapons/w3_lightning_empty",
				x = 173,--392,
				y = 655,
				scale = 1.00
			},	            
			-- enabled state
			SetStyle( lightningButtonStyle ),		
			Button
			{
				x = 173,--392,
				y = 655,
				name="lightning",
				command=
					function()
						weaponButtonPushed(3);
					end
			},
-- W4: tsunami button
			-- disabled state
			Bitmap
			{
				name = "tsunamiDisabled",
				image = "pics/weapons/w4_tsunami_inactive",
				x = 618,--732,
				y = 655,
				scale = 1.00
			},		
			-- empty state
			Bitmap
			{
				name = "tsunamiEmpty",
				image = "pics/weapons/w4_tsunami_empty",
				x = 618,--732,
				y = 655,
				scale = 1.00
			},	            
			-- enabled state
			SetStyle( tsunamiButtonStyle ),		
			Button
			{
				x = 618,--732,
				y = 655,
				name="tsunami",
				command=
					function()
						weaponButtonPushed(4);
					end
			},
-- W5: landslide button
			-- disabled state
			Bitmap
			{
				name = "landslideDisabled",
				image = "pics/weapons/w5_landslide_inactive",
				x = 731,--506,
				y = 655,
				scale = 1.00
			},
			-- empty state
			Bitmap
			{
				name = "landslideEmpty",
				image = "pics/weapons/w5_landslide_empty",
				x = 731,--506,
				y = 655,
				scale = 1.00
			},            
			-- enabled state
			SetStyle( landslideButtonStyle ),		
			Button
			{
				x = 731,--506,
				y = 655,
				name="landslide",
				command=
					function()
						weaponButtonPushed(5);
					end
			},
-- W6: chain lightning button
			-- disabled state
			Bitmap
			{
				name = "chainlightningDisabled",
				image = "pics/weapons/w6_chainlightning_inactive",
				x = 391,--618,
				y = 655,
				scale = 1.00
			},			
			-- empty state
			Bitmap
			{
				name = "chainlightningEmpty",
				image = "pics/weapons/w6_chainlightning_empty",
				x = 391,--618,
				y = 655,
				scale = 1.00
			},	            
			-- enabled state
			SetStyle( chainLightningButtonStyle ),		
			Button
			{
				x = 391,--618,
				y = 655,
				name="chainlightning",
				command=
					function()
						weaponButtonPushed(6);
					end
			},
-- W7: freeze time button
			-- disabled state
			Bitmap
			{
				name = "freezeTimeDisabled",
				image = "pics/weapons/w7_freezetime_inactive",
				x = 505,--840,
				y = 654,
				scale = 1.00
			},
			-- empty state
			Bitmap
			{
				name = "freezeTimeEmpty",
				image = "pics/weapons/w7_freezetime_empty",
				x = 505,--840,
				y = 654,
				scale = 1.00
			},            
			-- enabled state
			SetStyle( freezeTimeButtonStyle ),		
			Button
			{
				x = 505,--840,
				y = 654,
				name="freezeTime",
				command=
					function()
						weaponButtonPushed(7);
					end
			},
-- W8: reShuffle button
			-- disabled state
			Bitmap
			{
				name = "reShuffleEmpty",
				image = "pics/weapons/w8_reshuffle_inactive",
				x = 0,
				y = 464,
				--scale = 1.00
			},			
			-- enabled state, 1 charge
			SetStyle( reShuffle1ButtonStyle ),		
			Button
			{
				x=0,
				y=464,
				name="reShuffle",
				command=
					function()
						doReShuffle(true);
					end
			},	
			-- enabled state, 2 charges			
			SetStyle( reShuffle2ButtonStyle ),		
			Button
			{
				x=0,
				y=464,
				name="reShuffle2",
				command=
					function()
						doReShuffle(true);
					end
			},			
 		}, -- GameWindow
 		
		-- buttons in the screen
		SetStyle( pauseButtonStyle ),
		-- pause button
		Button
		{
			x=kMax - 100,
			y=kMax - 180,
			name="pause",
			-- label="pause",
			cancel=true,
			command=
				function()
                    pauseButtonPressed();
				end
		},
	},
}
--setReShuffleButtonVisibility();
setWeaponButtonVisibility(0); -- all weapons
SetFocus("gamePlayground");

