unit u_Menu;

interface
uses
  LexUtils, u_Button,
  u_Menu_Name, u_Menu_I, u_Menu_Level, SD_Menu;

type
  T_MenuButton = class(T_Button)
//    procedure Draw;
  end;

  T_Menu = class
    S : Integer;
    M_Name  : T_M_Name;
    M_I     : T_M_I;
    M_Level : T_M_Level;
    SetupMenu : tSetupMenu;
    //_________________
    Button : array[1..7] of T_MenuButton;
    StartGame : Boolean;
    constructor Create;
    procedure Work;
    procedure Draw;
    
  end;
var
  Menu : T_Menu;

implementation
uses
  u_Records,
  zglHeader, uConst, uGame, u_SceneM, uMaterials;

{procedure T_MenuButton.Draw;
begin

  text_DrawInRectEx(mFont_1, Rect, 1, 0, AnsiToUtf8(S), 225, MBtnColor[ST], TEXT_HALIGN_CENTER or TEXT_VALIGN_CENTER);
end;  }

var
  SN_Btn : array[1..7] of AnsiString = ('Продолжить', 'Играть', 'Уровень', 'Игрок', 'Рекорды',
                                    'Автор', 'Выход');

constructor T_Menu.Create;
var
  I : Integer;
begin
  M_Name  := T_M_Name.Create;
  M_I     := T_M_I.Create;
  M_Level := T_M_Level.Create;
  SetupMenu := tSetupMenu.Create;
  SetupMenu.Init;
  S := 1;

  for I := 1 to 7 do
    Button[I] := T_MenuButton.Create(SN_Btn[I], 0, (WinW - 180) div 2, trunc(WinH / 2.5 + 36 * I), 180, 32);

  StartGame := True;
end;

const
  c_m_2Game   = 2;
  c_m_Game   = 2;
  c_m_Level  = 3;
  c_m_Name   = 4;
  c_m_Rec    = 5;
  c_m_I      = 6;
  c_m_Exit   = 7;


procedure T_Menu.Work;
var
  I : Integer;
begin
  case S of

    c_m_Name : M_Name.Work;
    c_m_I    : M_I.Work;
    c_m_Level : if M_Level.Work then
                begin
                  if M_Level.Select > 0 then
                    uGame.Start(M_Level.Select);
                end;
    c_m_Rec   : Rec.Work;
  else
    begin
      for I := 1 to 7 do
      if Button[I].Work then
      begin
        case I of
          c_m_Game   :
          begin
             uGame.Start(1);
             Main.SetScene(tg_game, true);
          end;
          c_m_Exit   : zgl_Exit();
          c_m_Rec    : begin
                         Rec.Lev := 1;
                         Rec.LoadTRec(M_Level.LevelS[1, 2]);
                       end;
         end;
          S := I;
      end;
    end;
  end;
end;

procedure T_Menu.Draw;
var
  I : Integer;
begin
  case S of
    c_m_Name : M_Name.Draw;
    c_m_I : M_I.Draw;
    c_m_Level : M_Level.Draw;
    c_m_Rec   : Rec.Draw;
  else
    begin
      Pr2D_Rect(WinW div 2 - 91, trunc(WinH / 2.5) + 1, 182, 320, $FFBACF, $E5, PR2D_FILL);
      SSprite2d_Draw(m_PName, (WinW - 512) / 2, WinH / 2.5 - 140, 512, 128, 0);
      //SSprite_Draw(m_menu, (WinW - 256) / 2, WinH / 2.5 - 20, 256, 256);
      for I := 1 to 7 do
        Button[I].Draw;
    end;
  end;
end;

end.
