-- wndmainmenu.lua

require("blg/blgutilities.lua");
require("scripts/styles/style.lua");
require("scripts/styles/uistyle.lua");


MakeState{
	type = "StateMainMenu",
	BlgMovieClip{
	
		BlgBitmap{
			image = "common/backgrounds/bg_mainmenu",
			name = "mainmenuBG",
			center = {x = 0, y = 0},
		},
		
		-- animated flowers
		BlgContainer
		{
			transformMatrix = {x = 140, y = 440},
			
			BlgMovieClip
			{
				repeatCount = 0,
				SetStyle(UIFlower1Style),				
				BlgBitmap
				{
					image="common/backgrounds/menu_flower",
					center = {x = 130, y = 174},
					transformMatrix = {x = 30, y = 80, scaleX = -1},
				},
			},
			
			BlgMovieClip
			{
				repeatCount = 0,
				SetStyle(UILeaf2Style),				
				BlgBitmap
				{
					image="common/backgrounds/menu_leaf_1",
					center = {x = 61, y = 52},
					transformMatrix = {x = -55, y = 63},
				},
			},
					
			BlgMovieClip
			{
				SetStyle(UILeaf1Style),				
				repeatCount = 0,
				BlgBitmap
				{
					image="common/backgrounds/menu_leaf_3",
					center = {x = 87, y = 82},
					transformMatrix = {x = 65, y = 102},
				},
			},
		},
		
		BlgContainer
		{
			transformMatrix = {x = 720, y = 480, scaleX = 1},
			
			BlgMovieClip
			{
				repeatCount = 0,
				SetStyle(UIFlower2Style),				
				BlgBitmap
				{
					image="common/backgrounds/menu_flower",
					center = {x = 130, y = 174},
					transformMatrix = {x = 100, y = -280, scaleY = -1, rotation = -45},
				},
			},
			
			BlgMovieClip
			{
				repeatCount = 0,
				SetStyle(UILeaf2Style),				
				BlgBitmap
				{
					image="common/backgrounds/menu_leaf_1",
					center = {x = 61, y = 52},
					transformMatrix = {x = 100, y = -360},
				},
			},
			
			BlgMovieClip
			{
				repeatCount = 0,
				SetStyle(UILeaf1Style),				
				BlgBitmap
				{
					image="common/backgrounds/menu_leaf_2",
					center = {x = 71, y = 55},
					transformMatrix = {x = 40, y = -200},
				},
			},
		},
		
		SetStyle(WindowBGStyle),
		BlgBitmap {
			image="common/backgrounds/box_mainmenu",
			center = {x = 0, y = 0},
			transformMatrix = {x = 293, y = 140},
		},
		
		-- logo
		SetStyle(WindowLogoStyle),
		
		BlgMovieClip{
			--transformMatrix = {x = -80, y = 70},
			repeatCount = 1,
			
			SetStyle(MainMenuButtonStyle),
			BlgButton{
				name = "storymodeBtn",
				transformMatrix = {x = 255, y =182},
				label = "wnd_mainmenu_play",
				
				
				
				upState =
				{
					bitmap = "common/buttons/19_text_box5",
					text = {
						w=126, h=40,
						transformMatrix = {x = 240, y = 15 ,},
					},
				},
				overState = {
					bitmap = "common/buttons/18_text_box5_over",
					text = {
						w=126, h=40,
						transformMatrix = {x = 240, y = 15 ,},
					},
				},
				downState = {
					bitmap = "common/buttons/16_text_box5_down",
					text = {
						w=126, h=40,
						transformMatrix = {x = 240, y = 15 ,},
						
					},
					sound = kDefaultButtonSound,
				},
				animation = Button1Style.animation,
				command =
					function()
						SetLastVisitedScenario(-1);
						SwapToState({"scripts/states/stateloading.lua", nextState="scripts/states/statelevelselector.lua", assetScript="level/levelselector_assets.lua"});
					end
			},

			BlgButton{
				name = "optionsBtn",
				transformMatrix = {x = 306, y = 238},
				label = "wnd_mainmenu_options",
				
				upState =
				{
					bitmap = "common/buttons/14_text_box4",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
				},
				overState = {
					bitmap = "common/buttons/13_text_box4_over",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
				},
				downState = {
					bitmap = "common/buttons/12_text_box4_down",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
					sound = kDefaultButtonSound,
				},
				animation = Button2Style.animation,
				command =
					function()
						PushState("scripts/states/stateoptions.lua");
					end
			},

			BlgButton{
				name = "accountsBtn",
				transformMatrix = {x = 310, y = 297},
				label = "wnd_mainmenu_accounts",
				
				upState =
				{
					bitmap = "common/buttons/11_text_box3",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
				},
				overState = {
					bitmap = "common/buttons/10_text_box3_over",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
				},
				downState = {
					bitmap = "common/buttons/9_text_box3_down",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
					sound = kDefaultButtonSound,
				},
				animation = Button3Style.animation,
				command =
					function()
						PushState("scripts/states/stateaccounts.lua");
					end

			},
			
			BlgButton{
				name = "creditsBtn",
				transformMatrix = {x = 281, y = 353},
				label = "wnd_mainmenu_credits",
				
				upState =
				{
					bitmap = "common/buttons/8_text_box2",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
				},
				overState = {
					bitmap = "common/buttons/7_text_box2_over",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
				},
				downState = {
					bitmap = "common/buttons/6_text_box2_down",
					text = {
						w=126, h=40,
						transformMatrix = {x = 200, y = 15 ,},
					},
					sound = kDefaultButtonSound,
				},
				animation = Button4Style.animation,
				command =
					function()
						PushState("scripts/states/statecredits.lua");
					end
			},
			
			BlgButton
			{
				name = "quitBtn",
				transformMatrix = {x = 317, y = 412},
				label = "wnd_mainmenu_quit",
				
				upState =
				{
					bitmap = "common/buttons/5_text_box1",
					text = {
						w=126, h=40,
						transformMatrix = {x = 150, y = 15 ,},
					},
				},
				overState = {
					bitmap = "common/buttons/4_text_box1_over",
					text = {
						w=126, h=40,
						transformMatrix = {x = 150, y = 15 ,},
					},
				},
				downState = {
					bitmap = "common/buttons/3_text_box1_down",
					text = {
						w=126, h=40,
						transformMatrix = {x = 150, y = 15 ,},
					},
					sound = kDefaultButtonSound,
				},
				animation = Button5Style.animation,
				command=
						function()
							--ReadFile("scripts/quitverify.lua");
							-- TEMP: Survey only
							ReadFile("scripts/surveyquitverify.lua");
							-- END TEMP
						end
			},
		},
		
		BlgBitmap{
			image = "common/backgrounds/logo_01",
			name = "mainmenuBG",
			center = {x = 0, y = 0},
			transformMatrix = {x = 649, y = 421},
		},
		
		BlgBitmap{
			image = "common/backgrounds/kim_mainmenu",
			center = {x = 0, y = 0 },
			transformMatrix = {x = 178, y = 123},
			--playAnim = "DoAnim",
		},
	
		BlgBitmap{
			image = "common/backgrounds/title_mainmenu",
			--center = {x = 261, y = 101},
			center = {x = 0, y = 0},
			--transformMatrix = {x = 512, y = 110},
			transformMatrix = {x = 266, y = 475},
		},
		
		BlgParticles{
			name = "p4",
			path = "common/backgrounds/sheen.lua",
			transformMatrix = {x = 512, y = 475},
		},
		
		-- ----------------------------------------------------------------------------
		 --Comment this to hide the debug comic menu
		--[[
		BlgButton{
			name = "comicBtn",
			transformMatrix = {x = 281, y = 653},
			label = "#Comics",
			
			upState =
			{
		     	bitmap = "common/buttons/8_text_box2",
				text = {
					w=126, h=40,
					transformMatrix = {x = 200, y = 15 ,},
				},
			},
			overState = {
				bitmap = "common/buttons/7_text_box2_over",
				text = {
					w=126, h=40,
					transformMatrix = {x = 200, y = 15 ,},
				},
			},
			downState = {
				bitmap = "common/buttons/6_text_box2_down",
				text = {
					w=126, h=40,
					transformMatrix = {x = 200, y = 15 ,},
				},
				sound = kDefaultButtonSound,
			},
			animation = Button4Style.animation,
			command =
				function()
					PushState("scripts/states/statecomicmenu.lua");
				end
		},
		]]
		-- ----------------------------------------------------------------------------
		
		
	},
	
	SetStyle(MainMenuButtonStyle),
		
	BlgText {
		font = {
			standardFont,
			23,
			WhiteColor,
		},
		name = "txt",
		label = "#Welcome, "..GetCurrentUserName(),
		flags = kHAlignCenter + kVAlignCenter,
		w = 500,
		h = 150,

		transformMatrix = {x = 220, y = 500},
	},
};

gDialogTable = nil;

if GetNumUsers() == 0 then
	if IsFileCorrupted() then
		PushState("scripts/states/novalidfile.lua");
	else
		PushState("scripts/states/staterequestname.lua");
	end 
end
