require( "scripts/style.lua" );

NameColor = Color(255,255,255,255);

NameFont = {
  standardFont,
  26,
  NameColor
};

ButtonX = kCenter;
ButtonY = 92;
ButtonYSpace = 30;
buttonOff = 40;

NameButtonGraphics = {
	"buttons/choosenameover.png",
	"buttons/choosenamedown.png",
	"buttons/choosenameover.png",
	"buttons/choosenamedown.png"
};	

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


MakeDialog
{
	Bitmap
	{ 
		image="backgrounds/longdialog",
		x=kCenter,
		y=kCenter,
		
		ChoosePlayerWindow
		{
			x = 0, y = 30, w=kMax, h=kMax,
			
			Text
			{
				font = DialogTitleFont,
				name = "selectaplayer",
				x=0,y=22,w=kMax,h=kMax,
				flags = kHAlignCenter + kVAlignTop,
				label = "selectaplayer"
			};
			
			
			SetStyle(NameStyle);
			BeginGroup();
			Button{
				font=NameFont,
				name="button0",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*0),
			};
			
			Button{
				font=NameFont,
				name="button1",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*1)
			};
			
			Button{
				font=NameFont,
				name="button2",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*2)
			};
			
			Button{
				font=NameFont,		
				name="button3",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*3)
			};
			
			Button{
				font=NameFont,			
				name="button4",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*4)
			};
			
			Button{
				font=NameFont,
				name="button5",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*5)
			};
			Button{
				font=NameFont,			
				name="button6",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*6)
			};
			Button{
				font=NameFont,			
				name="button7",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*7)
			};
			Button{
				font=NameFont,			
				name="button8",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*8)
			};
			Button{
				font=NameFont,			
				name="button9",
				label="name",
				x=ButtonX,
				y=ButtonY+(ButtonYSpace*9)
			};
			SetStyle(DefaultStyle);
			
				
			Button{
				x=60+buttonOff,
				y=410,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="editname",
				label="",
				type = kPush,
				label="editname",
				command =
					function()
						gEnterNameValue = GetSelectedPlayerName();
						name = DoModal("scripts/entername.lua");
						if (not(name == nil)) then

							userNum = GetCurrentSelectedUser();
							SetCurrentUser(userNum);	
					
							ChangeCurrentUserName(name);
							SetPlayerChoices();
							SetWelcomeName();
						end
					end
			};
			

			Button{
				x=220+buttonOff,
				y=460,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="chooseok",
				label="ok",
				type = kPush,
				command = 
					function()
						userNum = GetCurrentSelectedUser();
						SetCurrentUser(userNum);
						SetWelcomeName();
						PopModal();
					end
				
			};
			
				
			Button{
				x=220+buttonOff,
				y=410,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="newplayer",
				label="newplayer",
				type = kPush,
				command =
					function()
						gEnterNameValue = "";
						name = DoModal("scripts/entername.lua");
						if (not(name == nil)) then
							CreateNewUser(name);
							SetPlayerChoices()
						end
					end
			};
			
				
			Button{
				x=60+buttonOff,
				y=460,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="delete",
				label="deleteplayer",
				type = kPush,
				command =
					function()
						result = DisplayDialog { 
							"scripts/yesno.lua", 
							body ="deleteconfirm",
							title = "deletetitle" 
						};
						if (result=='yes') then
							userNum = GetCurrentSelectedUser();
							DeleteUser(userNum)
							SetPlayerChoices()
						end
					end
				
			};
		}
	}
}

SetPlayerChoices();



