unit UFormUnitMoves;

{$mode delphi}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls;

type

  { TFormUnitMoves }

  TFormUnitMoves = class(TForm)
    ListView1: TListView;
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ListView1Data(Sender: TObject; Item: TListItem);
  private

  public
    procedure ReloadList;
  end;

var
  FormUnitMoves: TFormUnitMoves;

implementation

uses
  UGame, UCore, UPlayer;

{$R *.lfm}

{ TFormUnitMoves }

procedure TFormUnitMoves.ListView1Data(Sender: TObject; Item: TListItem);
begin
  if Assigned(Core.Game) and Assigned(Core.Game.CurrentPlayer) then
  with Core.Game.CurrentPlayer do
  if (Mode = pmHuman) and (Item.Index < Moves.Count) then
  with TUnitMove(Moves[Item.Index]) do begin
    Item.Caption := IntToStr(CellFrom.MapCell.Id);
    Item.SubItems.Add(IntToStr(CellTo.Mapcell.Id));
    Item.SubItems.Add(IntToStr(CountOnce));
    Item.SubItems.Add(IntToStr(CountRepeat));
  end;
end;

procedure TFormUnitMoves.FormShow(Sender: TObject);
begin
  Core.PersistentForm.Load(Self);
  Core.ThemeManager1.UseTheme(Self);
  Core.CoolTranslator1.TranslateComponentRecursive(Self);
  ReloadList;
end;

procedure TFormUnitMoves.FormClose(Sender: TObject;
  var CloseAction: TCloseAction);
begin
  Core.PersistentForm.Save(Self);
end;

procedure TFormUnitMoves.ReloadList;
begin
  if Assigned(Core.Game) and Assigned(Core.Game.CurrentPlayer) and
  (Core.Game.CurrentPlayer.Mode = pmHuman) then
    ListView1.Items.Count := Core.Game.CurrentPlayer.Moves.Count
  else ListView1.Items.Count := 0;
  ListView1.Refresh;
end;

end.

