unit uMainMenu;

interface
uses
  uMenu, uScene, uPage;
type
  TMainMenu = class(TMenu)
    procedure Draw; override;
    constructor Create(const SceneMng : tSceneMng); //overload;
  end;

implementation
uses
  uMyApp, LexUtils, uConst, zglHeader, uMaterials;

const
  c_button_startY = 256;
  c_button_space = 20;
  c_button_dw = 256;
  c_button_dh = 128;
  c_button_w = 184;
  c_button_h = 40;
  c_button_y = c_button_h + c_button_space;

type
  TButton = class(TPageButton)
    PSceneMng : tSceneMng;
    constructor Create(const X, Y : Integer; const Text : string; const SceneMng : tSceneMng); // overload;
  end;

  TButton_Game = class(TButton)
    procedure Click; override;
  end;

  TButton_Player = class(TButton)
    procedure Click; override;
  end;

  TButton_I = class(TButton)
    procedure Click; override;
  end;

  TButton_How = class(TButton)
    procedure Click; override;
  end;

  TButton_Exit = class(TButton)
    procedure Click; override;
  end;

{ TMenuLevel }

constructor TMainMenu.Create(const SceneMng : tSceneMng);
var
  Y : Integer;
begin
  inherited Create(SceneMng);
  Page := TMenuPage.Create(WinW div 2, 64, Self);
  Y := c_button_startY;
  Page.AddButton(TButton_Game.Create( 0, Y, 'Новая игра', SceneMng));
  Y := Y + c_button_y;
  Page.AddButton(TButton_How.Create( 0, Y, 'Как играть', SceneMng));
  Y := Y + c_button_y;
  Page.AddButton(TButton_I.Create( 0, Y, 'Автор', SceneMng));
  Y := Y + c_button_y;
  Page.AddButton(TButton_Exit.Create( 0, Y, 'Выход', SceneMng));
  Y := Y + c_button_y;
end;

constructor TButton.Create(const X, Y : Integer; const Text : string; const SceneMng : tSceneMng);
begin
  inherited Create(X, Y, c_button_dw, c_button_dh, c_button_w, c_button_h, Text, true);
  PSceneMng := SceneMng;
end;

{ TButton_Game }
procedure TButton_Game.Click;
begin
  with (PSceneMng as TMyApp) do
    ChangeSceneAndPar(Game, 0, 0);
end;

{ TButton_Player }
procedure TButton_I.Click;
begin
  with (PSceneMng as TMyApp) do
    ChangeScene(MenuI, 0);
end;

{ TButton_ScoreList }
procedure TButton_How.Click;
begin
  with (PSceneMng as TMyApp) do
    ChangeScene(MenuHow, 0);
end;

{ TButton_Player }

procedure TButton_Player.Click;
begin
  with (PSceneMng as TMyApp) do
    ChangeScene(MenuPlayer, 0);
end;

{ TButton_Exit }
procedure TButton_Exit.Click;
begin
  zgl_Exit;
end;

procedure TMainMenu.Draw;
begin
  inherited;
  with Page do
  ssprite2d_Draw(mName, Page.PageX^ - pX + 512, PageY^ - pY + 180, 1024, 128, 0);
end;

end.
