require( "scripts/style.lua" );

mmaxNumUsers = 5

MakeDialog
{
	-- Name the modal dialog
	name="chooseplayer",
	--Bitmap
	--{ 
		--image="backgrounds/profiles",
		--x=kCenter,
		--y=kCenter,
		
		ChoosePlayerWindow
		{
			name="chooseplayerwww",
			x = 0, y = 0, w=kMax, h=kMax,
		    maxNumUsers = mmaxNumUsers,
			listFontName = "fonts/lithos.mvec",
			listRect = "300, 174, 423, 37",
			fontH = 28,
			shiftDy = 67,
			shDx = 0, shDy = 0,
			listTextColor = "0,0,0,255",
			listActTextColor = "255,255,255,255",
			listActRectColor = "128,128,128,128",
			--listTextColorSh = "128,0,0,128",
			--listActTextColorSh = "0,128,0,128",
			
			
			Button
			{
				x=170, 	y=545,
				name="newplayer", type = kPush,
				graphics = {"backgrounds/profiles/b_add",	"backgrounds/profiles/b_add_pressed",	"backgrounds/profiles/b_add_mouseover"},
				command =
					function()
						PlayGSound("butt");
						if ( GetNumUsers() < mmaxNumUsers) then 
							gEnterNameValue = "";
							name = DoModal("scripts/addname.lua");
							if (not(name == nil) and IsNameValid(name) ) then
								CreateNewUser(name);
								FillUserDataList();
								SetWelcomeName();
							end
						else
							SetNameInfosToRun("infonumusers");
							DoModal("scripts/infos.lua");
						end	
						SetFocus( "chooseplayerwww" );
					end
			};

			Button
			{
				x=285, 	y=545,
				name="editname",	type = kPush,
				graphics = {"backgrounds/profiles/b_edit",	"backgrounds/profiles/b_edit_pressed",	"backgrounds/profiles/b_edit_mouseover"},
				command =
					function()
						PlayGSound("butt");
						gEnterNameValue = GetSelectedPlayerName();
						name = DoModal("scripts/editname.lua");
						if (not(name == nil)  and IsNameValid(name) ) then
							SetCurrentUser(GetCurrentSelectedUser(), true);
							ChangeCurrentUserName(name);
							FillUserDataList();
							SetWelcomeName();
						end
						SetFocus( "chooseplayerwww" );
					end
			};

				
			Button
			{
				x=610,	y=545,
				name="delete",
				type = kPush,
				graphics = {"backgrounds/profiles/b_delete",	"backgrounds/profiles/b_delete_pressed",	"backgrounds/profiles/b_delete_mouseover"},
				command =
					function()
						PlayGSound("butt");
						if (GetNumUsers() > 1 ) then 
							result = DisplayDialog { 
								"scripts/yesno.lua", 
								body ="deleteconfirm",
								title = "deletetitle" 
							};
							if (result=='yes') then
								DeleteUser(GetCurrentSelectedUser())
								FillUserDataList();
								SetWelcomeName();

							end
						else
							SetNameInfosToRun("infolastuser");
							DoModal("scripts/infos.lua");
						end	
						SetFocus( "chooseplayerwww" );
					end
				
			};
			
			Button
			{
				x=725,	y=545,
				name="chooseok",
				type = kPush,
				graphics = {"backgrounds/profiles/b_ok",	"backgrounds/profiles/b_ok_pressed",	"backgrounds/profiles/b_ok_mouseover"},
				command = 
					function()
						PlayGSound("butt");
						SetCurrentUser(GetCurrentSelectedUser(), true);
						SetWelcomeName();
						CloseAddBox();
						PopModal("chooseplayer");
					end
			};
			
		}
	--}
}

SetFocus( "chooseplayerwww" );



--SetPlayerChoices();

