unit uLevelMenu;

{$mode delphi}

interface

uses
  uMeForm, uScene, zglHeader;

type

  { TLevelMenu }
  TLevelMenu = class(TMeForm)
    Btn_Shape      : TShapeCircle;
    Btn_Shape2     : TShapeRect;
    BtnPart_Shape  : TShapeRect;
    BtnClose_Shape : TShapeRect;

    FormRect : TMeRect;
    Text : string;
    constructor Create(pX, pY : Integer; pAlpha : Byte; PScene : TScene); override;
    procedure ButtonsInit;
    procedure Show;
    procedure Draw; override;
    function  Update(pX, pY: Integer): Boolean; override;
  end;


implementation
uses
  uGlobal, ulevels;

type

TButtonLM = class(TMeFormObjectText)
  LevelNum : Integer;
  procedure Click; override;
end;

{ TButtonGL }

procedure TButtonLM.Click;
begin
  SceneManager.ChangeSceneAndPar(GMP, LevelNum, 0);
  Form.Visible := false;
  Form.Alpha := 0;
end;

{ButtonsInit}
const
  c_button_XCount = 7;
  c_button_space = 20;
  c_button_w = 48;
  c_button_h = 64;
  c_button_x = c_button_w + c_button_space;
  c_button_y = c_button_h + c_button_space;

  c_rXCount = c_button_XCount;
  c_leftSpaceX = (c_rXCount + 1) * c_button_x div 2;

  { TLevelMenu }

constructor TLevelMenu.Create(pX, pY: Integer; pAlpha: Byte; PScene: TScene);
begin
  inherited Create(pX, pY, pAlpha, PScene);
  BtnClose_Shape := TShapeRect.Create(162, 30);
  BtnPart_Shape := TShapeRect.Create(182, 28);
  Btn_Shape := TShapeCircle.Create(64);
  Btn_Shape2 := TShapeRect.Create(64, 64);
  FormRect.X := c_button_x div 3 - c_leftSpaceX;
  FormRect.Y := 200 - c_button_x div 4 * 3;
  SetLength(Obj, 0);

  ButtonsInit;

  Text := UTF8Decode('Выберите уровень:');
end;

procedure TLevelMenu.ButtonsInit;
var
  I, vX, vY : Integer;
begin

  for I := 0 to Length(Obj) - 1 do
    Obj[I].Free;
  SetLength(Obj, 0);

  for I := 1 to Length(Levels) do
  begin
    vY := (I - 1) div c_rXCount;
    vX := I - c_rXCount * vY;
    vX := trunc(vX * c_button_x - c_leftSpaceX);
    vY := 225 + vY * c_button_y;
    with TButtonLM.Create(vX, vY, Levels[I], Btn_Shape2, Self) do
    begin
      LevelNum := I;
    end;
  end;

  TButtonEMClose.Create(0, vY + 80, UTF8Decode('Закрыть'), BtnClose_Shape, Self);

  FormRect.W := -2*FormRect.X;
  FormRect.H := vY + 80 + 32 - FormRect.Y;
end;

procedure TLevelMenu.Show;
begin
  Visible := true;
end;

procedure TLevelMenu.Draw;
begin
  pr2d_Rect(X + FormRect.X, 0, FormRect.W, WinH, $E0E0EF, trunc(Alpha * 0.7), PR2D_FILL);
  pr2d_Rect(X + FormRect.X, Y + FormRect.Y, FormRect.W, FormRect.H, $F0F0FF, Alpha, PR2D_FILL);
  text_DrawEx(mFont, X, Y + FormRect.Y + 25, 1, 0, Text, Alpha, $020202, TEXT_ALIGN_CENTER);
  inherited Draw;
end;

function TLevelMenu.Update(pX, pY: Integer): Boolean;
begin
  Result:=inherited Update(pX, pY);
end;

end.

