Ignore:
Timestamp:
Nov 25, 2017, 12:27:33 AM (7 years ago)
Author:
chronos
Message:
  • Modified: Improved New game window.
  • Modified: Used newer version of Common and CoolTranslator packages.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33backup
        44tunneler.exe
         5tunneler.dbg
         6tunneler.lps
        57heaptrclog.trc
        6 tunneler.lps
         8Components/Common/Languages/*.mo
         9Components/CoolTranslator/Demo/lib
  • trunk/Forms/UNewGameForm.pas

    r24 r34  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls;
     9  ComCtrls, UCore;
    1010
    1111type
     
    1616    ButtonStart: TButton;
    1717    ButtonCancel: TButton;
     18    ColorButton1: TColorButton;
     19    EditUp: TEdit;
     20    EditDown: TEdit;
     21    EditLeft: TEdit;
     22    EditRight: TEdit;
     23    EditShoot: TEdit;
     24    EditName: TEdit;
     25    GroupBox1: TGroupBox;
    1826    Label1: TLabel;
     27    Label2: TLabel;
     28    Label3: TLabel;
     29    Label4: TLabel;
     30    Label5: TLabel;
     31    Label6: TLabel;
     32    Label7: TLabel;
     33    Label8: TLabel;
    1934    ListView1: TListView;
    20     procedure ButtonStartClick(Sender: TObject);
     35    procedure ColorButton1ColorChanged(Sender: TObject);
     36    procedure EditDownChange(Sender: TObject);
     37    procedure EditDownKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
     38      );
     39    procedure EditLeftChange(Sender: TObject);
     40    procedure EditLeftKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
     41      );
     42    procedure EditNameChange(Sender: TObject);
     43    procedure EditRightChange(Sender: TObject);
     44    procedure EditRightKeyDown(Sender: TObject; var Key: Word;
     45      Shift: TShiftState);
     46    procedure EditShootChange(Sender: TObject);
     47    procedure EditShootKeyDown(Sender: TObject; var Key: Word;
     48      Shift: TShiftState);
     49    procedure EditUpChange(Sender: TObject);
     50    procedure EditUpKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     51    procedure FormCreate(Sender: TObject);
     52    procedure FormDestroy(Sender: TObject);
    2153    procedure FormShow(Sender: TObject);
    2254    procedure ListView1Change(Sender: TObject; Item: TListItem;
    2355      Change: TItemChange);
     56    procedure ListView1Data(Sender: TObject; Item: TListItem);
     57    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
     58      Selected: Boolean);
    2459  private
    25     { private declarations }
     60    Players: TPlayers;
     61    procedure ReloadList;
    2662  public
    27     { public declarations }
     63    procedure LoadData(Engine: TEngine);
     64    procedure SaveData(Engine: TEngine);
    2865  end;
    2966
     
    3471
    3572uses
    36   UCore, UMainForm;
     73  UMainForm;
    3774
    3875{$R *.lfm}
     
    4784end;
    4885
    49 procedure TNewGameForm.ButtonStartClick(Sender: TObject);
    50 begin
    51 
     86procedure TNewGameForm.ListView1Data(Sender: TObject; Item: TListItem);
     87begin
     88  if Item.Index < Players.Count then
     89  with TPlayer(Players[Item.Index]) do begin
     90    Item.Caption := Name;
     91    Item.SubItems.Add(IntToHex(Color, 6));
     92    Item.SubItems.Add('');
     93    Item.Checked := Enabled;
     94    Item.Data := Pointer(Players[Item.Index]);
     95  end;
     96end;
     97
     98procedure TNewGameForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
     99  Selected: Boolean);
     100begin
     101  if Assigned(Item) and Selected then
     102  with TPlayer(Item.Data) do begin
     103    EditName.Text := Name;
     104    ColorButton1.ButtonColor := Color;
     105    EditDown.Text := IntToStr(Keys.Down);
     106    EditUp.Text := IntToStr(Keys.Up);
     107    EditLeft.Text := IntToStr(Keys.Left);
     108    EditRight.Text := IntToStr(Keys.Right);
     109    EditShoot.Text := IntToStr(Keys.Shoot);
     110  end;
     111end;
     112
     113procedure TNewGameForm.ReloadList;
     114begin
     115  ListView1.Items.Count := Players.Count;
     116  ListView1.Refresh;
     117end;
     118
     119procedure TNewGameForm.LoadData(Engine: TEngine);
     120begin
     121  Players.Assign(Engine.PlayerPool);
     122end;
     123
     124procedure TNewGameForm.SaveData(Engine: TEngine);
     125begin
     126  Engine.PlayerPool.Assign(Players);
     127end;
     128
     129procedure TNewGameForm.ColorButton1ColorChanged(Sender: TObject);
     130begin
     131  if Assigned(ListView1.Selected) then
     132  with TPlayer(ListView1.Selected.Data) do begin
     133    Color := ColorButton1.ButtonColor;
     134    ReloadList;
     135  end;
     136end;
     137
     138procedure TNewGameForm.EditDownChange(Sender: TObject);
     139var
     140  Value: Integer;
     141begin
     142  if Assigned(ListView1.Selected) then
     143  with TPlayer(ListView1.Selected.Data) do begin
     144    if TryStrToInt(EditDown.Text, Value) then Keys.Down := Value;
     145    ReloadList;
     146  end;
     147end;
     148
     149procedure TNewGameForm.EditDownKeyDown(Sender: TObject; var Key: Word;
     150  Shift: TShiftState);
     151begin
     152  EditDown.Text := IntToStr(Key);
     153end;
     154
     155procedure TNewGameForm.EditLeftChange(Sender: TObject);
     156var
     157  Value: Integer;
     158begin
     159  if Assigned(ListView1.Selected) then
     160  with TPlayer(ListView1.Selected.Data) do begin
     161    if TryStrToInt(EditLeft.Text, Value) then Keys.Left := Value;
     162    ReloadList;
     163  end;
     164end;
     165
     166procedure TNewGameForm.EditLeftKeyDown(Sender: TObject; var Key: Word;
     167  Shift: TShiftState);
     168begin
     169  EditLeft.Text := IntToStr(Key);
     170end;
     171
     172procedure TNewGameForm.EditNameChange(Sender: TObject);
     173begin
     174  if Assigned(ListView1.Selected) then
     175  with TPlayer(ListView1.Selected.Data) do begin
     176    Name := EditName.Text;
     177    ReloadList;
     178  end;
     179end;
     180
     181procedure TNewGameForm.EditRightChange(Sender: TObject);
     182var
     183  Value: Integer;
     184begin
     185  if Assigned(ListView1.Selected) then
     186  with TPlayer(ListView1.Selected.Data) do begin
     187    if TryStrToInt(EditRight.Text, Value) then Keys.Right := Value;
     188    ReloadList;
     189  end;
     190end;
     191
     192procedure TNewGameForm.EditRightKeyDown(Sender: TObject; var Key: Word;
     193  Shift: TShiftState);
     194begin
     195  EditRight.Text := IntToStr(Key);
     196end;
     197
     198procedure TNewGameForm.EditShootChange(Sender: TObject);
     199var
     200  Value: Integer;
     201begin
     202  if Assigned(ListView1.Selected) then
     203  with TPlayer(ListView1.Selected.Data) do begin
     204    if TryStrToInt(EditShoot.Text, Value) then Keys.Shoot := Value;
     205    ReloadList;
     206  end;
     207end;
     208
     209procedure TNewGameForm.EditShootKeyDown(Sender: TObject; var Key: Word;
     210  Shift: TShiftState);
     211begin
     212  EditShoot.Text := IntToStr(Key);
     213end;
     214
     215procedure TNewGameForm.EditUpChange(Sender: TObject);
     216var
     217  Value: Integer;
     218begin
     219  if Assigned(ListView1.Selected) then
     220  with TPlayer(ListView1.Selected.Data) do begin
     221    if TryStrToInt(EditUp.Text, Value) then Keys.Up := Value;
     222    ReloadList;
     223  end;
     224end;
     225
     226procedure TNewGameForm.EditUpKeyDown(Sender: TObject; var Key: Word;
     227  Shift: TShiftState);
     228begin
     229  EditUp.Text := IntToStr(Key);
     230end;
     231
     232procedure TNewGameForm.FormCreate(Sender: TObject);
     233begin
     234  Players := TPlayers.Create
     235end;
     236
     237procedure TNewGameForm.FormDestroy(Sender: TObject);
     238begin
     239  FreeAndNil(Players);
    52240end;
    53241
    54242procedure TNewGameForm.FormShow(Sender: TObject);
    55 var
    56   NewItem: TListItem;
    57   I: Integer;
    58 begin
    59   with ListView1 do try
    60     BeginUpdate;
    61     Clear;
    62     for I := 0 to MainForm.Engine.PlayerPool.Count - 1 do
    63     with TPlayer(MainForm.Engine.PlayerPool[I]) do begin
    64       NewItem := Items.Add;
    65       NewItem.Caption := Name;
    66       NewItem.SubItems.Add(IntToStr(Color));
    67       NewItem.SubItems.Add('');
    68       NewItem.Checked := Enabled;
    69       NewItem.Data := Pointer(Engine.PlayerPool[I]);
    70     end;
    71   finally
    72     EndUpdate;
    73   end;
     243begin
     244  ReloadList;
    74245end;
    75246
Note: See TracChangeset for help on using the changeset viewer.