-- wndmainmenu.lua

-- We must include this line, in order to use our visual styles
require("scripts/blg.lua");
require("scripts/style.lua");
require("scripts/styles/mainmenustyle.lua");

-- Initial button position in the y-axis (where 
-- the first button is going to be placed)
initialPosY = 150.0;
initialPosX = 30;

MakeDialog
{
	name = "dlgMainMenu",
	
	BlgBitmap
	{
		-- Set the background image
		image = "common/screens/main_menu/background",
		x = kCenter,
		y = kCenter,
		
		-- Create our main menu window
		WndMainMenu
		{
			-- Bubbles position
			bubblesPos = {x = 460.0, y = 160.0};
	
			bgm = "audio/music/music_menu_main.ogg",
			w = width, h = height,
										
			BlgBitmap
			{
				name = "username_bckg",
				x = 435, y = 428,
				enteranimation = DefaultAppearingAnimation,
				image = "common/screens/main_menu/username_popup",
			},			
			
			-- Creates the label with the welcome message
			SetStyle(MainMenuTextStyle),
			BlgText
			{ 
				name = "lblWelcome",  
				x = 455, y = 462,
				w = 190, h = 300,
				label = "welcomeplayer",
                flags = kHAlignCenter,
				--typewriter = true,
				--typewriteEvery = 1,
				--typewriteSound = "audio/sfx/sfx_typing_01.ogg",
				--typewriteDelay = 60,
				--fps = 30,
			},
            
            BlgText
			{ 
				name = "txtPlayerName",  
				x = 460, y = 500,
				w = 190, h = 300,
				flags = kHAlignCenter,
				label = "",
                --typewriter = true,
				--typewriteEvery = 1,
				--typewriteSound = "audio/sfx/sfx_typing_01.ogg",
				--typewriteDelay = 60,
				--fps = 30,
			},
			
			--[[ Create our buttons for each option ]]
			SetStyle(AnimatedButtonOrangeStyle),
			
			-- Play button
   			BlgButton
			{
				name = "btnPlay",
				x = 768, y = 319,
				width = 800 - (initialPosX + 245), height = 500,	
            			label = "play",
            			positionMatrix = { x = 10, y = 10 },
            			labelMatrix = { x = 0, y = 0 },
				
				graphics = {				
					"common/screens/button/play_orange",
					"",
					"",
					"",
				},
			   	
				command =
		        	function()
		        			        		
		        		-- If there are no users, we ask the player for her name
		        		--if UserCount() == 0 then
		        		--	DoModal("scripts/windows/dialogs/requestname.lua");
		        		--end
		        		
		        		PopSound();
		        		-- We show the comics window since it's the first time the game is played
		        		if FirstTimePlayed() then
						ClearUserData();
		        			MarkAsPlayed();
		        			
		        			SetSound("audio/music/music_popup_story.ogg");
		        			
		        			
		        			SwapToModalWithTransition("comicwindow.lua");
		        			
		        			
		        		
		        		-- It's not the first the time the game is played, so we ask the player what to do
		        		else
		        			t = {"scripts/windows/wnddialog.lua", title = "#"..GetCurrentUser(), body = "continuegame", result = false};
		        			DisplayDialog(t);
		        			PopSound();
                			
						if t.result then                			
							LoadUserData()
							SwapToModalWithTransition("wndlevelselectorx.lua")
						else			
							
							t = {"scripts/windows/wnddialog.lua", title = "confirm_new_game_title", body = "confirm_new_game_body", result = false}
								DisplayDialog(t)
								if t.result then
									ClearUserData();                				
									SetSound("audio/music/music_popup_story.ogg");
									SwapToModalWithTransition("comicwindow.lua");
																
									
								else
									SetSound("audio/music/music_menu_main.ogg");
									return
								end
						end
					end
				end
			},
			
			SetStyle(AnimatedButtonGreenStyle),
			
			--[[ Create our buttons for each option ]]
			-- Instructions
   			BlgButton
			{
				name = "btnInstructions",
				--x = initialPosX, y = (initialPosY),
				x=782, y= 396,
				width = 800 - (initialPosX + 240), height = 500,
				label = "instructions",
				positionMatrix = { x = 10, y = 10 },
				delay = 5,
				graphics = {
					"common/screens/button/option_green",
					"",
					"",
					"",
				},
				command =
					function()
						DoModalWithTransition("wndinstructions.lua")
					end
			},
			
			-- Options button
   			BlgButton
			{
				name = "btnOptions",
				--x = initialPosX, y = (initialPosY + 100),
				x=743, y=464,
				width = 800 - (initialPosX + 220), height = 400,
				label = "options",
				positionMatrix = { x = 50, y = 10 },
				delay = 10,
				graphics = {
					"common/screens/button/option_green",
					"",
					"",
					"",
				},
				command =
					function()
						DoModalWithTransition("wndoptions.lua")
					end	
			},
			
			-- High Scores button
   			BlgButton
			{
				name = "btnHighScores",
				--x = initialPosX, y = (initialPosY + 200),
				x=665, y=533,
				width = 800 - (initialPosX + 160), height = 300,
				label = "highscores",
				delay = 15,			    
				positionMatrix = { x = 105, y = 10 },
				graphics = {
					"common/screens/button/option_green",
					"",
					"",
					"",
				},
				command =
					function()
						SwapToModalWithTransition("wndhighscores.lua")
					end
			},
			
			-- Quit button
   			BlgButton
			{
				name = "btnQuit",
				--x = initialPosX, y = (initialPosY + 300),
				x=543,y=600,
				width = 800 - (initialPosX + 80), height = 300,
				label = "quit",
				positionMatrix = { x = 180, y = 10 },
				delay = 20,
				graphics = {
					"common/screens/button/option_green",
					"",
					"",
					"",
				},
				command =
			        function()
			        	t = {"scripts/windows/wnddialog.lua", name="quitwindow", body = "quitconfirm", title = "quittitle", result = false}
          				DisplayDialog(t);
						
						if t.result then
							PostMessage(CreateNamedMessage(kQuitNow, "Quit"));
							SaveWindowMode()
						end
					end
			},			
			
			--SetStyle(AnimatedButtonDarkStyle),			
			SetStyle(AnimatedButtonGreenStyle),		
			
			-- Change User button
   			BlgButton
			{
				name = "btnUser",
				x = 482, y = 537,
				--x=733,y=611,
				w = 345, h = 300,
				label = "changeplayer",
				labelMatrix = {x = 0, y = 0},
				positionMatrix = { x = 10, y = 10 },
				delay = 0,
				enteranimation = DefaultAppearingAnimation,
				graphics = {
					"common/screens/main_menu/button_change_user",
					"",
					"",
					"",
				},
				command =
			        function()
			        	DoModalWithTransition("dialogs/wndchangeplayer.lua")
				end
			},	
			
			--[[
			-- Water mark
			SetStyle(MainMenuTextStyle),
			BlgText
			{ 
				
				x = 305, y = 50,
				w = 500, h = 300,
				label = "#Build for RealArcade",
				--typewriter = true,
				--typewriteEvery = 1,
				--typewriteSound = "audio/sfx/sfx_typing_01.ogg",
				--typewriteDelay = 0,
				--fps = 30,
			},
			]]
	
		}
	}
}
