unit UFormPlayer;

{$mode delphi}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ColorBox, Menus, Spin, UGame;

type

  { TFormPlayer }

  TFormPlayer = class(TForm)
    ButtonCancel: TButton;
    ButtonOk: TButton;
    CheckBoxDefensive: TCheckBox;
    ColorBox1: TColorBox;
    ComboBoxMode: TComboBox;
    ComboBoxAgressivity: TComboBox;
    EditName: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    SpinEditStartUnits: TSpinEdit;
    procedure ComboBoxModeChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    procedure Translate;
    procedure UpdateInterface;
    procedure Load(Player: TPlayer);
    procedure Save(Player: TPlayer);
  end;

var
  FormPlayer: TFormPlayer;

implementation

{$R *.lfm}

resourcestring
  SHuman = 'Human';
  SComputer = 'Computer';
  SAgroLow = 'Low';
  SAgroMedium = 'Medium';
  SAgroHigh = 'High';

{ TFormPlayer }

procedure TFormPlayer.ComboBoxModeChange(Sender: TObject);
begin
  UpdateInterface;
end;

procedure TFormPlayer.FormShow(Sender: TObject);
begin
  UpdateInterface;
end;

procedure TFormPlayer.Translate;
var
  LastIndex: Integer;
begin
  with ComboBoxMode do begin
    LastIndex := ItemIndex;
    Clear;
    Items.Add(SHuman);
    Items.Add(SComputer);
    ItemIndex := LastIndex;
  end;
  with ComboBoxAgressivity do begin
    LastIndex := ItemIndex;
    Clear;
    Items.Add(SAgroLow);
    Items.Add(SAgroMedium);
    Items.Add(SAgroHigh);
    ItemIndex := LastIndex;
  end;
end;

procedure TFormPlayer.UpdateInterface;
begin
  ComboBoxAgressivity.Visible := ComboBoxMode.ItemIndex = 1;
  CheckBoxDefensive.Visible := ComboBoxMode.ItemIndex = 1;
  Label4.Visible := ComboBoxMode.ItemIndex = 1;
end;

procedure TFormPlayer.Load(Player: TPlayer);
begin
  EditName.Text := Player.Name;
  ComboBoxMode.ItemIndex := Integer(Player.Mode);
  ColorBox1.Selected := Player.Color;
  ComboBoxAgressivity.ItemIndex := Integer(Player.Agressivity);
  CheckBoxDefensive.Checked := Player.Defensive;
  SpinEditStartUnits.Value := Player.StartUnits;
  UpdateInterface;
end;

procedure TFormPlayer.Save(Player: TPlayer);
begin
  Player.Name := EditName.Text;
  Player.Mode := TPlayerMode(ComboBoxMode.ItemIndex);
  Player.Color := ColorBox1.Selected;
  Player.Agressivity := TComputerAgressivity(ComboBoxAgressivity.ItemIndex);
  Player.Defensive := CheckBoxDefensive.Checked;
  Player.StartUnits := SpinEditStartUnits.Value;
end;

end.

