require("scripts/styles/mainmenustyle.lua")
require("scripts/styles/loadingstyle.lua")
require("scripts/anim_enums.lua");

starAnimation = {
	keyframes = {
		{
			index = 0,
			skewX = 0.2,
			scaleY = 0.2,
			x = -200,
			blank = false,
			tweens = {
				{
					type = "FunctionEase", 
					target = TWEEN_X, 
					functionName = "Back",
					easingMethod = "easeOut",
				},
				{
					type = "SimpleEase", 
					target = TWEEN_SCALE, 
					ease = -1,
				},
			},
		},
		{
			index = 30,
			scaleX = 0.5,
			scaleY = 0.5,
			tweens = {
				{
					type = "FunctionEase", 
					target = TWEEN_SCALE, 
					functionName = "Elastic",
					easingMethod = "easeOut",
					--[[params = {
						sineWaveAmplitude = 20,
						sinWavePeriod = 15,
					},]]
				},
			},
		},
	},
};

glowAnimation = {
	
};

-- Define a function to create a given number of buttons
function CreateButtons(level, sublevel)

	groupTable = {};
	for i = 0, level - 1 do			
		for j = 0, sublevel - 1 do
		
			tempStr = "";
			if j==0 then
				tempStr="_big";
			end 

			
			table.insert(groupTable,
			BlgButton
			{
				name = string.format("btn_%i_%i", i, j),
				label = "", --string.format("sublevel%i", j + 1),
				font = MainMenuButtonFont,
				width = 200,
				height = 200,
				sound = "audio/sfx/buttonclick.ogg",
				--upColor = Color(200, 200, 200, 255),
				--downColor = Color(180, 180, 180, 255),
				--disabledColor = Color(200, 200, 200, 200),
				rolloveranimation = DefaultRollOverAnimation,
				rolloutanimation = DefaultRollOutAnimation,
				disabledsound = "audio/sfx/sfx_typing_01.ogg",
				fps = 30,
				positionMatrix = { x = 100, y = 100 },
					
				graphics = {
					"common/screens/level_select/sublevel_open"..tempStr,
					"",
					"",
					""
					--[[{
						colormatrix = {saturation = 0},
					},]]
				},
				--positionMatrix = {x = 0, y = 0},
			}
			);	
		end
	end
	
	return Group(groupTable)
end

function StopScrollFunction()
	StopScroll();
end

MakeDialog
{
	WndLevelSelectorX 
	{
		fit = true,
		w = 1024, h = 768,
        
		particlesWaterPositions = { 
		
				{0,0},
				{490,532},
				{1122,652},
				{1836,430},
				{1936,64},
		},
		particlesShinePositions = { 
		
				{0,0},
				{490,532},
				{1122,652},
				{1836,430},
				{1936,64},
				{1546,0},
				{1370,0},
		},
		particlesWaterFallPosition = {
			
				{1330,156},
		
		},
		
		sublevelDisabledMatrix = {saturation = 0, brightness=-0.2, contrast=0.5},
		
		Window{
			w = width, h = height,
			name="buttonContainer",
			-- Create the buttons for all sublevels
			CreateButtons(10, 5),
		},
	
		bgm = "audio/music/music_menu_level.ogg",
		

		Bitmap
		{
			-- Set the background image
			image = "common/screens/level_select/right_bar",
			x = 0,
			y = 662,
		},

--~ 		Bitmap
--~ 		{
--~ 			-- Set the background image
--~ 			name = "left_bar",
--~ 			image = "common/screens/level_select/left_bar",
--~ 			x = 0,
--~ 			y = 710,
--~ 		},
		
		--[[
		Bitmap
		{
			-- Set the background image
			image = "common/screens/level_select/minigames",
			x = 0,
			y = 528,
		},
		]]

		-- Create the button for the back arrow
		SetStyle(OrangeButtonStyle),

		BlgButton
		{
			name = "btnBack",
			x = 0, y = 20,
			width = 400, height = 200,				
			label = "",
			positionMatrix = { x = 10, y = 10 },
			delay = 5,
			graphics = {
				"common/screens/level_select/arrow",
				"",
				"",
				"",
			},
			pressCommand = function()
					ScrollBack()
				end,
			releaseCommand = StopScrollFunction,
			releaseOutsideCommand = StopScrollFunction,
		},
		
		-- Create the button for the next arrow
		BlgButton
		{
			name = "btnNext",
			x = 824, y = 20,
			width = 400, height = 200,				
			label = "",
			positionMatrix = { x = 174, y = 10, scaleX = -1,},
			delay = 5,
			graphics = {
				"common/screens/level_select/arrow",
				"",
				"",
				"",
			},
			pressCommand = function()
					ScrollForward()
				end,
			releaseCommand = StopScrollFunction,
			releaseOutsideCommand = StopScrollFunction,
		},
		
			----------------------------------------------------------------------
			-- minigame buttons
			
			SetStyle(MiniGameButtonStyle),
			
			BlgButton 
			{
				name= "DeliveryTruckMiniGame",
				width = 245,
				height = 70,
				label = "tea_minigame",
				graphics = {
								"common/screens/level_select/tea",
								"",
								"",
								"",
				},
				positionMatrix = {x = 15, y = 10},
				labelMatrix = {x = 30, y = 0},
				x = 221, y = 700,
			    command =
			        function()
				        LaunchMiniGame("DeliveryTruckMiniGame", false);
			        end
			},
			
			BlgButton
			{
				name = "TreatmentFactoryMiniGame",
				width = 245,
				height = 70,
				label = "treatments_minigame",			
				graphics = {
								"common/screens/level_select/treatment",
								"",
								"",
								"",
				},
				positionMatrix = {x = 15, y = 10},
				labelMatrix = {x = 32, y = 0},
				x = 444, y = 700,
			    command =
			        function()
				        LaunchMiniGame("TreatmentFactoryMiniGame", false);
			        end
			},
			
			BlgButton
			{
				name = "BalloonMiniGame",
				width = 245,
				height = 70,
				label = "incense_minigame",			
				graphics = {
								"common/screens/level_select/incense",
								"",
								"",
								"",
				},
				positionMatrix = {x = 15, y = 10},
				labelMatrix = {x = 32, y = 0},
                x = 4, y = 700,
			    command =
			        function()
				        LaunchMiniGame("BalloonMiniGame", false);
			        end
			},
			
--~ 			BlgButton
--~ 			{
--~ 				name = "Mixer",
--~ 				width = 210,
--~ 				height = 70,
--~ 				label = "MixerMiniGame",			
--~ 				graphics = {
--~ 								"common/screens/level_select/mix",
--~ 								"",
--~ 								"",
--~ 								"",
--~ 				},
--~ 				positionMatrix = {x = 10, y = 10},
--~ 				labelMatrix = {x = 10, y = 0},
--~ 				x = -5, y = 708,
--~ 			    command =
--~ 			        function()
--~ 				        LaunchMiniGame("Mixer", false);
--~ 			        end
--~ 			},
--~ 			
--~ 			BlgButton
--~ 			{
--~ 				name= "MeditationMiniGame",
--~ 				width = 200,
--~ 				height = 70,
--~ 				label = "MeditationMiniGame",
--~ 				graphics = {
--~ 								"common/screens/level_select/meditation",
--~ 								"",
--~ 								"",
--~ 								"",
--~ 				},
--~ 				positionMatrix = {x = 10, y = 10},
--~ 				labelMatrix = {x = 10, y = 0},
--~ 				x = 152, y = 708,
--~ 			    command =
--~ 			        function()
--~ 				        LaunchMiniGame("MeditationMiniGame", false);
--~ 			        end
--~ 			},
--~ 			
--~ 			BlgButton 
--~ 			{
--~ 				name= "Sandalwood",
--~ 				width = 245,
--~ 				height = 70,
--~ 				label = "Sandalwood",
--~ 				graphics = {
--~ 								"common/screens/level_select/combo",
--~ 								"",
--~ 								"",
--~ 								"",
--~ 				},
--~ 				positionMatrix = {x = 10, y = 10},
--~ 				labelMatrix = {x = 15, y = 0},
--~ 				x = 301, y = 708,
--~ 			    command =
--~ 			        function()
--~ 				        LaunchMiniGame("Sandalwood", false);
--~ 			        end
--~ 			},
					
			BlgButton
			{
				name= "CustomizeJadeGame",
				label = "CustomizeJadeGame",
				width = 245,
				height = 70,
				graphics = {
								"common/screens/level_select/dress",
								"",
								"",
								"",
				},
				positionMatrix = {x = 15, y = 10},
				labelMatrix = {x = 32, y = 0},
				x = 663, y = 700,
			    command =
			        function()
				        LaunchMiniGame("CustomizeJadeGame", false);
			        end
			},
			
			----
			BlgButton 
			{
				name= "Back to main menu",
				label= "mainmenu",
				width = 150, height = 90,
				graphics = {
								"common/screens/button/menu_green",
								"",
								"",
								"",
				},
				positionMatrix = {x = 10, y = 10},
				x = 870.0, y = 674.0,
            	command =
			        function()
			        	SwapToModalWithTransition("wndmainmenu.lua")
			        end
			},	

			BlgButton 
			{
				name = "btnPlay",
				label = "play_next_level",
				width = 150, height = 100,
				graphics = {
								"common/screens/button/menu_green",
								"",
								"",
								"",
				},
				positionMatrix = {x = 10, y = 10},
				x = kCenter, y = 5, --570.0,
				--x = 895, y = 620,
            		},	            
		
		pos = {
		-- level 0
			btn_0_0 = {x=21, y=-16},
			btn_0_1 = {x=56, y=44},
			btn_0_2 = {x=74, y=96},
			btn_0_3 = {x=83, y=151},
			btn_0_4 = {x=83, y=207},
			
		-- level 1
			btn_1_0 = {x=47, y=308},
			btn_1_1 = {x=55, y=372},
			btn_1_2 = {x=96, y=409},
			btn_1_3 = {x=152, y=408},
			btn_1_4 = {x=197, y=377},
			
		-- level 2
			btn_2_0 = {x=246, y=303},
			btn_2_1 = {x=307, y=291},
			btn_2_2 = {x=357, y=304},
			btn_2_3 = {x=400, y=338},
			btn_2_4 = {x=448, y=333},
			
		-- level 3
			btn_3_0 = {x=508, y=261},
			btn_3_1 = {x=536, y=210},
			btn_3_2 = {x=563, y=161},
			btn_3_3 = {x=606, y=126},
			btn_3_4 = {x=659, y=115},				

		-- level 4
			btn_4_0 = {x=743, y=109},
			btn_4_1 = {x=797, y=147},
			btn_4_2 = {x=827, y=190},
			btn_4_3 = {x=827, y=240},
			btn_4_4 = {x=822, y=290},
			
			
		-- level 5
			btn_5_0 = {x=860, y=393},
			btn_5_1 = {x=928, y=436},
			btn_5_2 = {x=982, y=445},
			btn_5_3 = {x=1034, y=440},
			btn_5_4 = {x=1084, y=420},
						
		-- level 6
			btn_6_0 = {x=1173, y=363},
			btn_6_1 = {x=1242, y=346},	
			btn_6_2 = {x=1299, y=339},
			btn_6_3 = {x=1358, y=352},
			btn_6_4 = {x=1408, y=383},				
						
		-- level 7
			btn_7_0 = {x=1485, y=444},
			btn_7_1 = {x=1563, y=477},	
			btn_7_2 = {x=1623, y=477},
			btn_7_3 = {x=1678, y=463},
			btn_7_4 = {x=1718, y=431},			
			
		-- level 8
			btn_8_0 = {x=1783, y=335},
			btn_8_1 = {x=1821, y=284},
			btn_8_2 = {x=1831, y=232},
			btn_8_3 = {x=1821, y=176},
			btn_8_4 = {x=1783, y=131},
			
		-- level 9
			btn_9_0 = {x=1700, y=86},
			btn_9_1 = {x=1641, y=95},
			btn_9_2 = {x=1578, y=90},
			btn_9_3 = {x=1520, y=68},
			btn_9_4 = {x=1488, y=26},
		},

		-- country images		
		posImg = {
--~ 			level_usa = {x=134, y=200},
--~ 			level_mexico = {x=458, y=163},
--~ 			level_japan= {x=135, y=469},
--~ 			level_india = {x=512, y=340},
--~ 			level_peru = {x=707, y=141},
--~ 			level_china = {x=1115, y=133},
--~ 			level_swiss = {x=846, y=457},
--~ 			level_africa = {x=1249, y=436},
--~ 			level_australia = {x=1452, y=168},
--~ 			level_france = {x=1584, y=310},
			level_sanfrancisco= {x=302, y=134},
			level_honolulu= {x=219, y=533},
			level_holywood= {x=391, y=330},
			level_lasvegas= {x=736, y=420},
			level_colorado= {x=942, y=187},
			level_texas= {x=1113, y=466},
			level_neworleans= {x=1410, y=573},
			level_washington= {x=1712, y=489},
			level_newyork= {x=1812, y=306},
			level_vermont= {x=1772, y=103}
		};
		-- country titles
		posTxt = {
			
			w=150,
			h=50,
			size=14,
			font="fonts/arial_rounded.mvec",
			
			level_sanfrancisco= {x=234, y=182 , label="level_sanfrancisco"},
			level_honolulu= {x=210, y=567, label="level_honolulu"},
			level_holywood= {x=234, y=352, label="level_holywood"},
			level_lasvegas= {x=663, y=463, label="level_lasvegas"},
			level_colorado= {x=936, y=220, label="level_colorado"},
			level_texas= {x=1030, y=492, label="level_texas"},
			level_neworleans= {x=1337, y=600, label="level_neworleans"},
			level_washington= {x=1632, y=525, label="level_washington"},
			level_newyork= {x=1739, y=360, label="level_newyork"},
			level_vermont= {x=1687, y=149, label="level_vermont"}
		};		
	}
}