source: trunk/Forms/FormNewGame.pas

Last change on this file was 73, checked in by chronos, 8 months ago
  • Modified: Removed U prefix from unit names.
File size: 8.0 KB
Line 
1unit FormNewGame;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
7 ComCtrls, Engine;
8
9type
10
11 { TFormNewGame }
12
13 TFormNewGame = class(TForm)
14 ButtonStart: TButton;
15 ButtonCancel: TButton;
16 CheckBoxEnabled: TCheckBox;
17 ColorButton1: TColorButton;
18 ColorButton2: TColorButton;
19 EditUp: TEdit;
20 EditDown: TEdit;
21 EditLeft: TEdit;
22 EditRight: TEdit;
23 EditShoot: TEdit;
24 EditName: TEdit;
25 GroupBox1: TGroupBox;
26 Label1: TLabel;
27 Label2: TLabel;
28 Label3: TLabel;
29 Label4: TLabel;
30 Label5: TLabel;
31 Label6: TLabel;
32 Label7: TLabel;
33 Label8: TLabel;
34 Label9: TLabel;
35 ListView1: TListView;
36 procedure CheckBoxEnabledChange(Sender: TObject);
37 procedure ColorButton1ColorChanged(Sender: TObject);
38 procedure ColorButton2ColorChanged(Sender: TObject);
39 procedure EditDownChange(Sender: TObject);
40 procedure EditDownKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
41 );
42 procedure EditLeftChange(Sender: TObject);
43 procedure EditLeftKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
44 );
45 procedure EditNameChange(Sender: TObject);
46 procedure EditRightChange(Sender: TObject);
47 procedure EditRightKeyDown(Sender: TObject; var Key: Word;
48 Shift: TShiftState);
49 procedure EditShootChange(Sender: TObject);
50 procedure EditShootKeyDown(Sender: TObject; var Key: Word;
51 Shift: TShiftState);
52 procedure EditUpChange(Sender: TObject);
53 procedure EditUpKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
54 procedure FormCreate(Sender: TObject);
55 procedure FormDestroy(Sender: TObject);
56 procedure FormShow(Sender: TObject);
57 procedure ListView1Change(Sender: TObject; Item: TListItem;
58 Change: TItemChange);
59 procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
60 Item: TListItem; SubItem: Integer; State: TCustomDrawState;
61 var DefaultDraw: Boolean);
62 procedure ListView1Data(Sender: TObject; Item: TListItem);
63 procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
64 Selected: Boolean);
65 private
66 Players: TPlayers;
67 procedure ReloadList;
68 public
69 procedure UpdateInterface;
70 procedure LoadData(Engine: TEngine);
71 procedure SaveData(Engine: TEngine);
72 end;
73
74
75implementation
76
77{$R *.lfm}
78
79uses
80 Core;
81
82{ TFormNewGame }
83
84procedure TFormNewGame.ListView1Change(Sender: TObject; Item: TListItem;
85 Change: TItemChange);
86begin
87 if Change = ctState then
88 TPlayer(Item.Data).Enabled := Item.Checked;
89end;
90
91procedure TFormNewGame.ListView1CustomDrawSubItem(Sender: TCustomListView;
92 Item: TListItem; SubItem: Integer; State: TCustomDrawState;
93 var DefaultDraw: Boolean);
94begin
95 if SubItem = 1 then
96 with ListView1.Canvas do begin
97 Brush.Color := TPlayer(Item.Data).Color1;
98 Brush.Style := bsSolid;
99 FillRect(Item.DisplayRectSubItem(1, drBounds));
100 end;
101end;
102
103procedure TFormNewGame.ListView1Data(Sender: TObject; Item: TListItem);
104begin
105 if Item.Index < Players.Count then
106 with TPlayer(Players[Item.Index]) do begin
107 Item.Caption := Name;
108 Item.SubItems.Add('');
109 Item.SubItems.Add('');
110 Item.Checked := Enabled;
111 Item.Data := Pointer(Players[Item.Index]);
112 end;
113end;
114
115procedure TFormNewGame.ListView1SelectItem(Sender: TObject; Item: TListItem;
116 Selected: Boolean);
117begin
118 if Assigned(Item) and Selected then
119 with TPlayer(Item.Data) do begin
120 EditName.Text := Name;
121 ColorButton1.ButtonColor := Color1;
122 ColorButton2.ButtonColor := Color2;
123 EditDown.Text := IntToStr(Keys.Down);
124 EditUp.Text := IntToStr(Keys.Up);
125 EditLeft.Text := IntToStr(Keys.Left);
126 EditRight.Text := IntToStr(Keys.Right);
127 EditShoot.Text := IntToStr(Keys.Shoot);
128 CheckBoxEnabled.Checked := Enabled;
129 end;
130 UpdateInterface;
131end;
132
133procedure TFormNewGame.ReloadList;
134begin
135 ListView1.Items.Count := Players.Count;
136 ListView1.Refresh;
137end;
138
139procedure TFormNewGame.UpdateInterface;
140begin
141 EditUp.Enabled := Assigned(ListView1.Selected);
142 EditDown.Enabled := Assigned(ListView1.Selected);
143 EditLeft.Enabled := Assigned(ListView1.Selected);
144 EditRight.Enabled := Assigned(ListView1.Selected);
145 EditShoot.Enabled := Assigned(ListView1.Selected);
146 EditName.Enabled := Assigned(ListView1.Selected);
147 ColorButton1.Enabled := Assigned(ListView1.Selected);
148 ColorButton2.Enabled := Assigned(ListView1.Selected);
149 CheckBoxEnabled.Enabled := Assigned(ListView1.Selected);
150end;
151
152procedure TFormNewGame.LoadData(Engine: TEngine);
153begin
154 Players.Assign(Engine.PlayerPool);
155end;
156
157procedure TFormNewGame.SaveData(Engine: TEngine);
158begin
159 Engine.PlayerPool.Assign(Players);
160end;
161
162procedure TFormNewGame.ColorButton1ColorChanged(Sender: TObject);
163begin
164 if Assigned(ListView1.Selected) then
165 with TPlayer(ListView1.Selected.Data) do begin
166 Color1 := ColorButton1.ButtonColor;
167 ReloadList;
168 end;
169end;
170
171procedure TFormNewGame.CheckBoxEnabledChange(Sender: TObject);
172begin
173 if Assigned(ListView1.Selected) then
174 with TPlayer(ListView1.Selected.Data) do begin
175 Enabled := CheckBoxEnabled.Checked;
176 ReloadList;
177 end;
178end;
179
180procedure TFormNewGame.ColorButton2ColorChanged(Sender: TObject);
181begin
182 if Assigned(ListView1.Selected) then
183 with TPlayer(ListView1.Selected.Data) do begin
184 Color2 := ColorButton2.ButtonColor;
185 ReloadList;
186 end;
187end;
188
189procedure TFormNewGame.EditDownChange(Sender: TObject);
190var
191 Value: Integer;
192begin
193 if Assigned(ListView1.Selected) then
194 with TPlayer(ListView1.Selected.Data) do begin
195 if TryStrToInt(EditDown.Text, Value) then Keys.Down := Value;
196 ReloadList;
197 end;
198end;
199
200procedure TFormNewGame.EditDownKeyDown(Sender: TObject; var Key: Word;
201 Shift: TShiftState);
202begin
203 EditDown.Text := IntToStr(Key);
204end;
205
206procedure TFormNewGame.EditLeftChange(Sender: TObject);
207var
208 Value: Integer;
209begin
210 if Assigned(ListView1.Selected) then
211 with TPlayer(ListView1.Selected.Data) do begin
212 if TryStrToInt(EditLeft.Text, Value) then Keys.Left := Value;
213 ReloadList;
214 end;
215end;
216
217procedure TFormNewGame.EditLeftKeyDown(Sender: TObject; var Key: Word;
218 Shift: TShiftState);
219begin
220 EditLeft.Text := IntToStr(Key);
221end;
222
223procedure TFormNewGame.EditNameChange(Sender: TObject);
224begin
225 if Assigned(ListView1.Selected) then
226 with TPlayer(ListView1.Selected.Data) do begin
227 Name := EditName.Text;
228 ReloadList;
229 end;
230end;
231
232procedure TFormNewGame.EditRightChange(Sender: TObject);
233var
234 Value: Integer;
235begin
236 if Assigned(ListView1.Selected) then
237 with TPlayer(ListView1.Selected.Data) do begin
238 if TryStrToInt(EditRight.Text, Value) then Keys.Right := Value;
239 ReloadList;
240 end;
241end;
242
243procedure TFormNewGame.EditRightKeyDown(Sender: TObject; var Key: Word;
244 Shift: TShiftState);
245begin
246 EditRight.Text := IntToStr(Key);
247end;
248
249procedure TFormNewGame.EditShootChange(Sender: TObject);
250var
251 Value: Integer;
252begin
253 if Assigned(ListView1.Selected) then
254 with TPlayer(ListView1.Selected.Data) do begin
255 if TryStrToInt(EditShoot.Text, Value) then Keys.Shoot := Value;
256 ReloadList;
257 end;
258end;
259
260procedure TFormNewGame.EditShootKeyDown(Sender: TObject; var Key: Word;
261 Shift: TShiftState);
262begin
263 EditShoot.Text := IntToStr(Key);
264end;
265
266procedure TFormNewGame.EditUpChange(Sender: TObject);
267var
268 Value: Integer;
269begin
270 if Assigned(ListView1.Selected) then
271 with TPlayer(ListView1.Selected.Data) do begin
272 if TryStrToInt(EditUp.Text, Value) then Keys.Up := Value;
273 ReloadList;
274 end;
275end;
276
277procedure TFormNewGame.EditUpKeyDown(Sender: TObject; var Key: Word;
278 Shift: TShiftState);
279begin
280 EditUp.Text := IntToStr(Key);
281end;
282
283procedure TFormNewGame.FormCreate(Sender: TObject);
284begin
285 Core.Core.Translator1.TranslateComponentRecursive(Self);
286 Players := TPlayers.Create;
287end;
288
289procedure TFormNewGame.FormDestroy(Sender: TObject);
290begin
291 FreeAndNil(Players);
292end;
293
294procedure TFormNewGame.FormShow(Sender: TObject);
295begin
296 ReloadList;
297 UpdateInterface;
298end;
299
300end.
301
Note: See TracBrowser for help on using the repository browser.