Ignore:
Timestamp:
Mar 12, 2014, 8:40:53 PM (11 years ago)
Author:
chronos
Message:
  • Added: Key press and mouse double click in new game player list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormNew.pas

    r40 r41  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, Spin, ExtCtrls, UGame;
     9  ComCtrls, Spin, ExtCtrls, ActnList, UGame;
    1010
    1111type
     
    1414
    1515  TFormNew = class(TForm)
    16     ButtonPlayerAdd: TButton;
     16    APlayerAdd: TAction;
     17    APlayerRemove: TAction;
     18    APlayerModify: TAction;
     19    ActionList1: TActionList;
    1720    ButtonCancel: TButton;
    1821    ButtonOk: TButton;
     22    ButtonPlayerAdd: TButton;
     23    ButtonPlayerModify: TButton;
    1924    ButtonPlayerRemove: TButton;
    20     ButtonPlayerModify: TButton;
     25    CheckBoxCity: TCheckBox;
    2126    CheckBoxVoid: TCheckBox;
    22     CheckBoxCity: TCheckBox;
    2327    ComboBoxGridType: TComboBox;
    2428    Label1: TLabel;
     
    2832    Label5: TLabel;
    2933    ListView1: TListView;
     34    Panel1: TPanel;
     35    Panel2: TPanel;
     36    RadioGroupGrowAmount: TRadioGroup;
    3037    RadioGroupGrowCells: TRadioGroup;
    31     RadioGroupGrowAmount: TRadioGroup;
    32     SpinEditVoidPercent: TSpinEdit;
     38    SpinEditCityPercent: TSpinEdit;
    3339    SpinEditMapSizeX: TSpinEdit;
    3440    SpinEditMapSizeY: TSpinEdit;
    35     SpinEditCityPercent: TSpinEdit;
     41    SpinEditVoidPercent: TSpinEdit;
     42    Splitter1: TSplitter;
    3643    TrackBarSizeX: TTrackBar;
    3744    TrackBarSizeY: TTrackBar;
    38     procedure ButtonPlayerAddClick(Sender: TObject);
    39     procedure ButtonPlayerModifyChangeBounds(Sender: TObject);
    40     procedure ButtonPlayerModifyClick(Sender: TObject);
    41     procedure ButtonPlayerRemoveClick(Sender: TObject);
     45    procedure APlayerAddExecute(Sender: TObject);
     46    procedure APlayerModifyExecute(Sender: TObject);
     47    procedure APlayerRemoveExecute(Sender: TObject);
    4248    procedure CheckBoxCityChange(Sender: TObject);
    4349    procedure CheckBoxVoidChange(Sender: TObject);
     
    4652    procedure FormShow(Sender: TObject);
    4753    procedure ListView1Data(Sender: TObject; Item: TListItem);
     54    procedure ListView1DblClick(Sender: TObject);
     55    procedure ListView1KeyPress(Sender: TObject; var Key: char);
     56    procedure ListView1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
     57      );
    4858    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
    4959      Selected: Boolean);
     
    8494end;
    8595
     96procedure TFormNew.ListView1DblClick(Sender: TObject);
     97begin
     98  APlayerModify.Execute;
     99end;
     100
     101procedure TFormNew.ListView1KeyPress(Sender: TObject; var Key: char);
     102begin
     103  if (Key = #13) then APlayerModify.Execute;
     104end;
     105
     106procedure TFormNew.ListView1KeyUp(Sender: TObject; var Key: Word;
     107  Shift: TShiftState);
     108begin
     109  if Key = 45 then APlayerAdd.Execute;
     110  if Key = 46 then APlayerRemove.Execute;
     111end;
     112
    86113procedure TFormNew.ListView1SelectItem(Sender: TObject; Item: TListItem;
    87114  Selected: Boolean);
     
    116143  ButtonPlayerRemove.Enabled := Assigned(ListView1.Selected);
    117144  ButtonPlayerAdd.Enabled := Players.Count < MaxPlayerCount;
    118   ButtonPlayerModify.Enabled := Assigned(ListView1.Selected);
     145  APlayerModify.Enabled := Assigned(ListView1.Selected);
    119146end;
    120147
     
    129156end;
    130157
    131 procedure TFormNew.ButtonPlayerRemoveClick(Sender: TObject);
    132 begin
    133   if Assigned(ListView1.Selected) then
     158procedure TFormNew.CheckBoxCityChange(Sender: TObject);
     159begin
     160  SpinEditCityPercent.Enabled := CheckBoxCity.Checked;
     161end;
     162
     163procedure TFormNew.CheckBoxVoidChange(Sender: TObject);
     164begin
     165  SpinEditVoidPercent.Enabled := CheckBoxVoid.Checked;
     166end;
     167
     168procedure TFormNew.APlayerModifyExecute(Sender: TObject);
     169begin
     170  if Assigned(ListView1.Selected) then begin
     171    FormPlayer.Load(TPlayer(ListView1.Selected.Data));
     172    if FormPlayer.ShowModal = mrOk then begin
     173      FormPlayer.Save(TPlayer(ListView1.Selected.Data));
     174      ReloadView;
     175    end;
     176  end;
     177end;
     178
     179procedure TFormNew.APlayerRemoveExecute(Sender: TObject);
     180begin
     181  if Assigned(ListView1.Selected) then begin
    134182    Players.Remove(ListView1.Selected.Data);
    135   ReloadView;
    136 end;
    137 
    138 procedure TFormNew.CheckBoxCityChange(Sender: TObject);
    139 begin
    140   SpinEditCityPercent.Enabled := CheckBoxCity.Checked;
    141 end;
    142 
    143 procedure TFormNew.CheckBoxVoidChange(Sender: TObject);
    144 begin
    145   SpinEditVoidPercent.Enabled := CheckBoxVoid.Checked;
    146 end;
    147 
    148 procedure TFormNew.ButtonPlayerAddClick(Sender: TObject);
     183    ReloadView;
     184  end;
     185end;
     186
     187procedure TFormNew.APlayerAddExecute(Sender: TObject);
    149188var
    150189  NewPlayer: TPlayer;
    151190begin
    152   NewPlayer := TPlayer.Create;
    153   NewPlayer.Name := 'Player ' + IntToStr(Players.Count + 1);
    154   NewPlayer.Color := PlayerColors[Players.Count];
    155   NewPlayer.Mode := pmComputer;
    156   Players.Add(NewPlayer);
    157   ReloadView;
    158 end;
    159 
    160 procedure TFormNew.ButtonPlayerModifyChangeBounds(Sender: TObject);
    161 begin
    162 
    163 end;
    164 
    165 procedure TFormNew.ButtonPlayerModifyClick(Sender: TObject);
    166 begin
    167   FormPlayer.Load(TPlayer(ListView1.Selected.Data));
    168   if FormPlayer.ShowModal = mrOk then
    169     FormPlayer.Save(TPlayer(ListView1.Selected.Data));
     191  if Players.Count <= (MaxPlayerCount - 1) then begin
     192    NewPlayer := TPlayer.Create;
     193    NewPlayer.Name := 'Player ' + IntToStr(Players.Count + 1);
     194    NewPlayer.Color := PlayerColors[Players.Count];
     195    NewPlayer.Mode := pmComputer;
     196    Players.Add(NewPlayer);
     197    ReloadView;
     198  end;
    170199end;
    171200
Note: See TracChangeset for help on using the changeset viewer.