unit uGamePage;

interface
uses
  LexUtils, zglHeader, uPage, uScene, uConst, uMaterials;

type
  TPageText = record
    X, Y : Integer;
    Flag, Color : LongWord;
    Str : String;
  end;

  TGamePage = class(TPage)
    mX, mY : Integer;
    PageText : array of TPageText;
    constructor Create(const Scene : TScene); virtual;
    function    NoActive : boolean;
    procedure   Show;
    procedure   Draw; override;
    procedure   AddText(const Text_ : string; const X_, Y_ : Integer; const Color_, Flag_ : LongWord);
  end;

  TGameButton = class(TPageButton)
    pScene : TScene;
    pPage : TPage;
    constructor Create(const X, Y : Integer; const Text : string; const Scene : TScene; const Page : TPage); overload;
  end;

implementation

{ TGamePage }

procedure TGamePage.AddText(const Text_ : string; const X_, Y_ : Integer; const Color_, Flag_ : LongWord);
var
  L : Integer;
begin
  L := Length(PageText);
  SetLength(PageText, L + 1);
  with PageText[L] do
  begin
    X := X_;
    Y := Y_;
    Color := Color_;
    Flag := Flag_;
    Str := Text_;
  end;

end;

constructor TGamePage.Create(const Scene: TScene);
begin
  Wd2 := W div 2;
  PScene := Scene;
  bgDraw := True;
  mX := 0;
  mY := 0;

  PageX := @mX;
  PageY := @mY;
end;

procedure TGamePage.Draw;
var
  I : Integer;
begin
  if Enabled then
  begin
    inherited;
    for I := 0 to Length(PageText) - 1 do
    with PageText[I] do
      text_DrawEx(mFont_1, pX + X, pY + Y, 1, 1, Str, 250, Color, Flag)
  end;
end;

function TGamePage.NoActive: boolean;
begin
  if Enabled then
  begin
    if abs(mX) > 3 then
      mX := trunc(mX * 0.92)
    else
      mX := 0;
    if abs(mY) > 3 then
      mY := trunc(mY * 0.92)
    else
      mY := 0;
    Update;
    Result := False;
  end
  else
    Result := True;
end;

procedure TGamePage.Show;
begin
  mX := 0;
  mY := -1000;
  Update;
  Enabled := true;
end;

{ TGameButton }

constructor TGameButton.Create(const X, Y: Integer; const Text: string;
  const Scene: TScene; const Page: TPage);
begin
  Create(X, Y, 128, 64, 100, 50, Text, True);
  pPage := Page;
  pScene := Scene;
end;

end.
