require( "scripts/style.lua" );


MyFont = {
  standardFont,
  30,
  BlackColor
};

NameFont = {
  standardFont,
  25,
  BlackColor
};

local playername = gEnterNameValue;
local deleteselected = false;

if not playername or playername=="" then
	deleteselected = true;
	playername = GetString("enternameprompt");
end


MakeDialog
{
	Bitmap
	{
		image="gui/profilemanager/editbg.png",
		x=kCenter,
		y=kCenter,

		Text
		{
			font = DialogTitleFont,
			name = "entername",
			x=0,y=20,w=kMax,h=30,
			flags = kHAlignCenter + kVAlignTop,
			label = "entername"
		};


		TextEdit
		{
			font = NameFont,
			name = "nameedit",
			label = playername,
			enablewindow = "enterok",
			clearinitial = deleteselected,
			x=3,y=30,w=kMax-3,h=kMax,
			length=9,
			ignore = kIllegalNameChars,
			flags = kHAlignCenter + kVAlignCenter

		};


		Button
		{
			x=kCenter,
			y=kMax - 80,
			font = StandardButtonFont,
			graphics = StandardButtonOkGraphics,
			name="enterok",
			label="ok",
			type = kPush,
			default=true,	-- Make this the default button
			command =
				function()
					local newname = GetLabel("nameedit");
					if (newname ~= playername and IsNameInUse(newname)) then
						DisplayDialog {
							"scripts/ok.lua",
							body ="nameinuse",
							title = ""
						};
						SetFocus( "nameedit" )
					else
						CloseWindow(GetLabel("nameedit"));
					end
				end
		}
	}
}

SetFocus( "nameedit" );

if (deleteselected) then
	EnableWindow("enterok", false);
end


