unit u_Menu_Name;

interface
uses
  LexUtils, u_Button, u_Player;

type
  T_M_Name = class
    SName  : string;
    Button : T_Button;
    Tild  : char;
    NewS,
    TildT : byte;

    procedure Draw;
    procedure Work;
    constructor Create;
  end;

implementation
uses
  u_Menu, zglHeader, uMaterials, uConst;
  
constructor T_M_Name.Create;
begin
  Button := T_Button.Create('ОК', 1, (WinW - 160) div 2, WinH div 2 + 55, 160, 48, 0.9);
  NewS   := 0;
  SName := iPlayer.Name;
  key_BeginReadText( SName, 20 );
end;

procedure T_M_Name.Work;

procedure KeyWork;
var
  I   : byte;
  BB  : boolean;
begin
  Inc(TildT, 8);
  SName := key_GetText();
end;

begin
  if (Button.Work)
  or (Key_Press(k_ENTER)) then
  begin
    iPlayer.Name := SName;
    Player_Save('Player');
    Menu.S := NewS;
    NewS := 0;
    Exit;
  end;
  KeyWork;

end;

procedure T_M_Name.Draw;
begin
  Pr2D_Rect((WinW - 512) div 2, WinH div 2 - 125, 512, 250, $E0A0A0, $E5, PR2D_FILL);

  Text_DrawEx(mFont_1, WinW div 2,
             WinH div 2 - 80, 0.85, 0,
             AnsiToUtf8('Введите свое имя:'), 240, $551111, TEXT_HALIGN_CENTER);

  Text_DrawEx(mFont_1, WinW div 2,
             WinH div 2 - 20, 1, 0,
             AnsiToUtf8(SName),  235, $772222, TEXT_HALIGN_CENTER);
  if TildT > 128 then
  pr2d_Rect(trunc(WinW + text_GetWidth( mFont_1, SName)) div 2,
             WinH div 2 - 26,
             10, 30, $992222, $77, PR2D_FILL );

  Button.Draw;
end;

end.
