require( "scripts/style.lua" );


MyFont = {
  standardFont,
  30,
  BlackColor
};

NameFont = {
  standardFont,
  25,
  BlackColor
};

--local playername = gEnterNameValue;gDialogTable.title
local playername = gDialogTable.body;
--local deleteselected = false;
local deleteselected = true;

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


MakeDialog
{
	Window
	{
		w=1024,h=768,
		Bitmap
		{
			image="backgrounds/shade",
			alpha = 0.99,
		},
		
		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 = gDialogTable.title
			};

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

			};

			SetStyle(EmptyButtonStyle),
			Button
			{
				--sound = "audio/sfx/buttons/default_click.ogg",
				graphics=
				{
					"buttons/stddone",
					"buttons/stddonedown",
					"buttons/stddoneover",
				},
				command = function()
							local newname = GetLabel("nameedit");
							if (newname ~= playername and IsNameInUse(newname)) then
								DisplayDialog {
									"scripts/ok.lua",
									body ="nameinuse",
									title = ""
								};
								SetFocus( "nameedit" );
							else
									SetProfile(GetLabel("nameedit"));
									CloseWindow();
							end
						  end,
				--close = true,
				default = true,
				flags = 5,
				name = "ok",
				x = 130,
				y = 200,
			},
			Button
			{
				--sound = "audio/sfx/buttons/default_click.ogg",
				graphics=
				{
					"buttons/stdcancel",
					"buttons/stdcanceldown",
					"buttons/stdcancelover",
				},
				close = true,
				flags = 5,
				name = "cancel",
				x = 210,
				y = 200,
			},
		}
	}
}

SetFocus( "nameedit" );

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


