require( "scripts/style.lua" );


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

MyFont = {
  standardFont,
  30,
  BlackColor
};

NameFont = {
  standardFont,
  25,
  NameColor
};

local playername = gEnterNameValue;

MakeDialog
{
	Bitmap
	{ 
		image="backgrounds/dialog",
		x=kCenter,
		y=kCenter,
		
		EnterNameWindow
		{
			x=0,y=145,w=kMax,h=kMax,
			Text
			{
				font = DialogTitleFont,
				name = "entername",
				x=0,y=9,w=kMax,h=60,
				flags = kHAlignCenter + kVAlignTop,
				label = "entername"
			};
			
			Bitmap
			{
				image="backgrounds/textfield.png",
				x=kCenter,
				y=120,
				
				TextEdit
				{
					font = NameFont,
					name = "nameedit",
					label = playername,
					x=8,y=5,w=kMax-3,h=kMax,
					length=12,
					ignore = kIllegalNameChars
					
				};
			};
				
			Button
			{
				x=45,
				y=170,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="enterok",
				label="ok",
				type = kPush,
				command = 
					function()
						okorenter();
					end
			},
			
			Button
			{
				x=210,
				y=170,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="entercancel",
				label="cancel",
				type = kPush,
				command = 
					function()
						cancelorenter();
					end
			};
		}
		
	},
	
	SetFocus( "nameedit" )
}


function okorenter()
	if (IsNameInUse(GetLabel("nameedit"))) then
		DisplayDialog { 
			"scripts/ok.lua", 
			body ="nameinuse",
			title = "nameinusetitle"
		};
		SetFocus( "nameedit" )
	else
		CloseWindow(GetLabel("nameedit"));
	end
end

function cancelorenter()
	CloseWindow(nil);
end