unit umm;

{$mode delphi}

interface

uses
  uMeForm, uScene, zglHeader;

type
TMainMenu = class(tScene)
  FormMain,
  Form : TMeForm;
  ButtonGame : TMeFormObjectText;
  constructor Create(const PSceneMng : tSceneMng); override;
  procedure Draw; override;
  procedure Update; override;
end;
implementation
uses
  uGlobal;
type

TButtonNew = class(TMeFormObjectText)
 procedure Click; override;
end;

{ TButtonGame }

TButtonGame = class(TMeFormObjectText)
 procedure Click; override;
end;

TButtonOpen = class(TMeFormObjectText)
 procedure Click; override;
end;

TButtonScene = class(TMeFormObjectText)
 Scene : tScene;
 procedure Click; override;
end;

TButtonExit = class(TMeFormObjectText)
 procedure Click; override;
end;

{ TMainMenuScene }

constructor TMainMenu.Create(const PSceneMng: tSceneMng);
var
  Shape : TShapeRect;
  I : Integer;
begin
  SceneMng := PSceneMng;
  FormMain := TMeForm.Create(WinW div 2, WinH div 2, $FF, Self);
  Shape := TShapeRect.Create(162, 30);

  ButtonGame := TButtonGame.Create(0, -100 + 0 * 52, UTF8Decode('Продолжить'), Shape, FormMain);
  ButtonGame.Visible:=false;
  TButtonNew.Create(0, -100 + 1 * 52, UTF8Decode('Новая игра'), Shape, FormMain);
  TButtonOpen.Create(0, -100 + 2 * 52, UTF8Decode('Загрузить'), Shape, FormMain);
 // TButtonScene.Create(0, -100 + 3 * 52, UTF8Decode('Редактор карт'), Shape, FormMain).Scene := nil;
  TButtonExit.Create(0, -100 + 3 * 52,UTF8Decode('Выход'), Shape, FormMain);
end;

procedure TMainMenu.Draw;
var
  I : Integer;
begin
  text_DrawEx(mFont, WinW div 2, 220, 1, 0, 'cdmlex Minimal TDS', $FF, $FFFFFF, TEXT_ALIGN_CENTER);
  FormMain.Draw;
  if (Form <> nil) and (Form.Visible) then
    Form.Draw;
end;

procedure TMainMenu.Update;
begin
  if (Form <> nil) and (Form.IsActive) then
  begin
    if key_Down(K_ESCAPE) then
      Form.Visible:=false
    else
      Form.Update(mouse_X, mouse_Y);
  end
  else
    FormMain.Update(mouse_X, mouse_Y);
end;

procedure TButtonScene.Click;
begin
  SceneManager.ChangeScene(Scene, 0);
end;

procedure TButtonNew.Click;
begin
  SceneManager.ChangeSceneAndPar(GMP, 0, 0);
end;

procedure TButtonOpen.Click;
begin
  LevelMenu.Show();
  TMainMenu(Form.Scene).Form := LevelMenu;
end;

procedure TButtonExit.Click;
begin
  zgl_Exit;
end;

procedure TButtonGame.Click;
begin
  SceneManager.ChangeScene(GMP, 0);
end;

end.

