require( "scripts/style.lua" );






NameFont = {
  standardFont,
  24,
  BorderColor
};

HeaderFont = {
  standardFont,
  48,
  BorderColor
};

ButtonX = kCenter;
ButtonY = 77;
ButtonYSpace = 27;


NameButtonGraphics = {
	"buttons/select_none.png",
	"buttons/select_highlight.png",
	"buttons/select_field.png",
	"buttons/select_highlight.png"
};	

NameStyle= {
	type = kRadio,
	flags = kHAlignCenter + kVAlignCenter,
	font = StandardButtonFont,
	graphics = NameButtonGraphics,
	sound = kDefaultButtonSound
};

gGotoSSSGLogin = false;

MakeDialog
{
	Bitmap
	{ 
		image="backgrounds/longdialog",
		x=kCenter,
		y=kCenter,
		
		ChoosePlayerWindow
		{
			x = 0, y = 0, w=kMax, h=kMax,
			
			Text
			{
				font = HeaderFont,
				name = "selectaplayer",
				x=0,y=30,w=kMax,h=kMax,
				flags = kHAlignCenter + kVAlignTop,
				label = "selectaplayer"
			};
			
			
			SetStyle(NameStyle);
			BeginGroup();
			Button{
				name="button0",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*0),
			};
			
			Button{
				name="button1",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*1)
			};
			
			Button{
				name="button2",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*2)
			};
			
			Button{
				name="button3",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*3)
			};
			
			Button{
				name="button4",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*4)
			};
			
			Button{
				name="button5",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*5)
			};
			Button{
				name="button6",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*6)
			};
			Button{
				name="button7",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*7)
			};
			Button{
				name="button8",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*8)
			};
			Button{
				name="button9",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*9)
			};
			SetStyle(DefaultStyle);
			
			SetStyle(SmallButtonStyle);
				
			Button{
				x=43,
				y=390,
				name="editname",
				label="",
				type = kPush,
				label="editname",
				command =
					function()
						gEnterNameValue = GetSelectedPlayerName();
						name = DoModal("scripts/entername.lua");
						if (not(name == nil)) then
							ChangeCurrentUserName(name);
							SetPlayerChoices();
							SetWelcomeName();
						end
						if (gGotoSSSGLogin == true) then
							DoModal("scripts/sssgsetup.lua");
							gGotoSSSGLogin = false;
						end
					end
			};
			

			Button{
				x=220,
				y=430,
				name="chooseok",
				label="ok",
				type = kPush,
				command = 
					function()
						userNum = GetCurrentSelectedUser();
						SetCurrentUser(userNum, false);
						SetWelcomeName();
						PopModal();
					end
				
			};
			
			
				
			Button{
				x=kCenter,
				y=350,
				name="newplayer",
				label="newplayer",
				type = kPush,
				command =
					function()
						gEnterNameValue = "";
						name = DoModal("scripts/entername.lua");
						if (not(name == nil)) then
							CreateNewUser(name);
							SetPlayerChoices();
						end
						if (gGotoSSSGLogin == true) then
							DoModal("scripts/sssgsetup.lua");
							gGotoSSSGLogin = false;
						end
					end
			};
			
				
			Button{
				x=220,
				y=390,
				name="delete",
				label="deleteplayer",
				type = kPush,
				command =
					function()
						result = DisplayDialog { 
							"scripts/yesno.lua", 
							body ="deleteconfirm",
							title = "" 
						};
						if (result=='yes') then
							userNum = GetCurrentSelectedUser();
							DeleteUser(userNum)
							SetPlayerChoices()
						end
					end
				
			};
			Button{
				x=43,
				y=430,
				name="advanced",
				label="advanced",
				type = kPush,
				command =
					function()
						userNum = GetCurrentSelectedUser();
						SetCurrentUser(userNum, false);
						SetWelcomeName();
						gEnterNameValue = "";
						name = DoModal("scripts/sssgsetup.lua");
					end
			};
			
			SetStyle(DefaultStyle);
		}
	}
}

SetPlayerChoices();



