---------------------------------------------------------------------------------------------------
--  Copyright © 2009 PoBros, Incorporated. All Rights Reserved.
--
--  This source code is the proprietary confidential property of PoBros Incorporated.
--  Modification, reproduction, publication, or distribution in any form to any party 
--  other than the licensee is strictly prohibited.
--
--  FOR USE BY AUTHORIZED PERSONS ONLY
---------------------------------------------------------------------------------------------------

require( "scripts/style.lua" );

local kButtonOKX = kCenter;

if( not gDialogTable.nocancel ) then
	kButtonOKX = kCenter - 125;
end

---------------------------------------------------------------------------------------------------

MakeDialog
{
	name = "createplayer";
	SetStyle( GameWindowStyle );
	
	GameWindow
	{
		SetStyle( DialogWindowStyle );
		
		DialogWindow
		{
			SetStyle( DialogTitleText );

			Text
			{
				name = "createplayerheader";
				label = "createplayerheader";
			};
			
			SetStyle( DialogBodyText );
			
			Text
			{
				name = "createplayerbody";
				label = "createplayerbody";
				y = kCenter + 40;
				h = 150;
			};
			
			SetStyle( DefaultStyle );

			Bitmap
			{
				image = "backgrounds/textfield";
				x = kCenter;
				y = kCenter;

				TextEdit
				{
					font = NameFont;
					name = "nameedit";
					enablewindow = "enterok";
					clearinitial = deleteselected;
					x = 30;
					y = 5;
					w = kMax - 30;
					h = kMax - 5;
					length = 12;
					ignore = gs_illigalNameChars;
					sounds = gs_soundTyping;
				};
			};
			
			SetStyle( TwoButtonDialogButton1Style );

			Button
			{
				name = "enterok";
				text = "ok";
				default = true;
				x = kButtonOKX;
				
				command =
					function()
						local newname = GetLabel( "nameedit" );
						
						if( IsUserNameInUse( newname ) ) then
							DisplayDialog 
							{
								"scripts/ok.lua";
								body = "playernameusedbody";
								title = "playernameusedheader";
							};
							
							SetFocus( "nameedit" );
						elseif( newname ~= "" ) then
							WindowReturn( GetLabel( "nameedit" ) );
						end
					end
			};
			
			SetStyle( TwoButtonDialogButton2Style );

			Button
			{
				name = "cancel";
				text = "cancel";

				command =
					function()
						WindowReturn();
					end
			};
		};
	};
};

---------------------------------------------------------------------------------------------------

SetFocus( "nameedit" );
EnableWindow( "enterok", false );

if( gDialogTable.nocancel ) then
	EnableWindow( "cancel", false );
end