unit uherogui;

{$mode delphi}

interface

uses
  uScene, uMeForm;

type

{ THeroGUI }

THeroGUI = class(TMeForm)
  Btn_Shape      : TShapeRect;
  PowerText, LiveText : string;
  constructor Create(pX, pY : Integer; pAlpha : Byte; PScene : TScene); override;
  procedure Draw; override;
  function  Update(pX, pY: Integer): Boolean; override;
end;

{ TWinForm }

TWinForm = class(TMeForm)
  Text : string;
  constructor Create(pX, pY : Integer; pAlpha : Byte; PScene : TScene); override;
  procedure Draw; override;
end;

{ TLoseForm }

TLoseForm = class(TMeForm)
  Text : string;
  constructor Create(pX, pY : Integer; pAlpha : Byte; PScene : TScene); override;
  procedure Draw; override;
end;
implementation

uses
  sysutils, zglHeader, uGlobal, uGMPL, uGMPBul, uGMP, GSound;
{ TGunButton }
  type
TGunButton = class(TMeFormObjectText)
  N : Integer;
  constructor Create(pX, pY : Integer; pSText : string; PShape : TMeFormShape; PForm : TMeForm); override;
  procedure Draw(pX, pY : Integer; pAlpha : Byte); override;
  procedure Click; override;
end;

{ TWinButton }

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

{ TLoseButton }

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

TSdButton = class(TMeFormObjectText)
  Text0 : string;
  procedure Click; override;
end;

TMzButton = class(TMeFormObjectText)
  Text0 : string;
  procedure Click; override;
end;

{ TMzButton }
procedure TSdButton.Click;
begin
  GSound.SoundEn := not GSound.SoundEn;
  if GSound.SoundEn then
  Text := Text0 + ' ON'
  else
  Text := Text0 + ' OFF';
end;

procedure TMzButton.Click;
begin
  GSound.MuzEn := not GSound.MuzEn;
  if GSound.MuzEn then
  begin
    TrackPlay(1);
    Text := Text0 + ' ON';
  end
  else
  begin
    TrackStop;
    Text := Text0 + ' OFF';
  end;

end;

{ TLoseButton }

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

{ TWinButton }

procedure TWinButton.Click;
begin
  SceneManager.ChangeScene(MainMenu, 0);
end;

{ TLoseForm }

constructor TLoseForm.Create(pX, pY: Integer; pAlpha: Byte; PScene: TScene);
begin
  inherited Create(pX, pY, pAlpha, PScene);
  Text := UTF8Decode('Очень жаль, но Вы потерпели поражение.');
  TLoseButton.Create(0, 70, UTF8Decode('Начать уровень еще раз'), TShapeRect.Create(196, 40), Self);
end;

procedure TLoseForm.Draw;
begin
  pr2d_Rect(X - 184, Y - 24, 368, 128, $803040, $FF, PR2D_FILL);
  pr2d_Rect(X - 180, Y - 20, 360, 120, $502030, $FF, PR2D_FILL);
  text_Draw(mFont, X , Y, Text, TEXT_HALIGN_CENTER);
  inherited Draw;
end;

{ TWinForm }

constructor TWinForm.Create(pX, pY: Integer; pAlpha: Byte; PScene: TScene);
begin
  inherited Create(pX, pY, pAlpha, PScene);
  Text := UTF8Decode('Поздравляем, Вы прошли все уровни в игре!');
  TWinButton.Create(0, 70, UTF8Decode('Перейти в главное меню'), TShapeRect.Create(190, 40), Self);
end;

procedure TWinForm.Draw;
begin
  pr2d_Rect(X - 184, Y - 24, 368, 128, $303080, $FF, PR2D_FILL);
  pr2d_Rect(X - 180, Y - 20, 360, 120, $202060, $FF, PR2D_FILL);
  text_Draw(mFont, X , Y, Text, TEXT_HALIGN_CENTER);
  inherited Draw;
end;

{ THeroGUI }

constructor THeroGUI.Create(pX, pY: Integer; pAlpha: Byte; PScene: TScene);
var
  I : Integer;
begin
  inherited Create(pX, pY, pAlpha, PScene);
  Btn_Shape := TShapeRect.Create(120, 50);
  for I := 1 to cGunsCount do
    TGunButton.Create(170+I*130, 1, UTF8Decode(Guns[I].Name), Btn_Shape, Self).N := I;
  LiveText := UTF8Decode('Здоровье:');
  PowerText := UTF8Decode('Раж-режим: ');

  TSdButton.Create(WinW - 150, -15, UTF8Decode('Звук ON'), TShapeRect.Create(100, 20), Self).Text0 := UTF8Decode('Звук');
  TMzButton.Create(WinW - 150, 15, UTF8Decode('Музыка ON'), TShapeRect.Create(100, 20), Self).Text0 := UTF8Decode('Музыка');

end;

procedure THeroGUI.Draw;
begin
  pr2d_Rect(0,0,WinW, 65, $3070C0, $FF, PR2D_FILL);
  pr2d_Rect(10, 25, 210, 21, $202060, $FF, PR2D_FILL);
  pr2d_Rect(15, 30, Map.GH.Live, 11, $20FF60, $FF, PR2D_FILL);
  text_Draw(mFont, 100, 8, LiveText, TEXT_HALIGN_CENTER);
  if Map.GH.Live > 0 then
  text_Draw(mFont, 150, 8, IntToStr(trunc(Map.GH.Live)), TEXT_HALIGN_CENTER);
  if Map.GH.PowerTime > 0 then
    text_Draw(mFont, 70, 48, PowerText + IntToStr(Map.GH.PowerTime div 10), TEXT_HALIGN_LEFT);


  inherited Draw;
end;

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

{ TGunButton }

constructor TGunButton.Create(pX, pY: Integer; pSText: string;
  PShape: TMeFormShape; PForm: TMeForm);
begin
  inherited Create(pX, pY, pSText, PShape, PForm);
  TextX := 0;
  TextY := -7;
end;

procedure TGunButton.Draw(pX, pY: Integer; pAlpha: Byte);
begin
  inherited Draw(pX, pY, pAlpha);
  pX := pX + X;
  pY := pY + Y;

  pr2d_Rect(pX - 50, pY + 3, 100, 20, $202060, $FF, PR2D_FILL);
  text_Draw(mFont, pX - 10, pY + 7, IntToStr(Map.GH.GunMag[N].Count1), TEXT_HALIGN_RIGHT);
  text_Draw(mFont, pX , pY + 7, '/', TEXT_HALIGN_CENTER);
  text_Draw(mFont, pX + 10, pY + 7, IntToStr(Map.GH.GunMag[N].Count2), TEXT_HALIGN_LEFT);
  if Map.GH.Gun = N then
  begin
    pr2d_Rect(pX - 60, pY - 25, 10, 50, $20C020, $FF, PR2D_FILL);
    pr2d_Rect(pX + 50, pY - 25, 10, 50, $20C020, $FF, PR2D_FILL);

  end;
end;

procedure TGunButton.Click;
begin
  Map.GH.Gun := N;
end;

end.

