1 | unit FormNewGame;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
7 | ComCtrls, Engine;
|
---|
8 |
|
---|
9 | type
|
---|
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 |
|
---|
75 | implementation
|
---|
76 |
|
---|
77 | {$R *.lfm}
|
---|
78 |
|
---|
79 | uses
|
---|
80 | Core;
|
---|
81 |
|
---|
82 | { TFormNewGame }
|
---|
83 |
|
---|
84 | procedure TFormNewGame.ListView1Change(Sender: TObject; Item: TListItem;
|
---|
85 | Change: TItemChange);
|
---|
86 | begin
|
---|
87 | if Change = ctState then
|
---|
88 | TPlayer(Item.Data).Enabled := Item.Checked;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | procedure TFormNewGame.ListView1CustomDrawSubItem(Sender: TCustomListView;
|
---|
92 | Item: TListItem; SubItem: Integer; State: TCustomDrawState;
|
---|
93 | var DefaultDraw: Boolean);
|
---|
94 | begin
|
---|
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;
|
---|
101 | end;
|
---|
102 |
|
---|
103 | procedure TFormNewGame.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
104 | begin
|
---|
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;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TFormNewGame.ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
116 | Selected: Boolean);
|
---|
117 | begin
|
---|
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;
|
---|
131 | end;
|
---|
132 |
|
---|
133 | procedure TFormNewGame.ReloadList;
|
---|
134 | begin
|
---|
135 | ListView1.Items.Count := Players.Count;
|
---|
136 | ListView1.Refresh;
|
---|
137 | end;
|
---|
138 |
|
---|
139 | procedure TFormNewGame.UpdateInterface;
|
---|
140 | begin
|
---|
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);
|
---|
150 | end;
|
---|
151 |
|
---|
152 | procedure TFormNewGame.LoadData(Engine: TEngine);
|
---|
153 | begin
|
---|
154 | Players.Assign(Engine.PlayerPool);
|
---|
155 | end;
|
---|
156 |
|
---|
157 | procedure TFormNewGame.SaveData(Engine: TEngine);
|
---|
158 | begin
|
---|
159 | Engine.PlayerPool.Assign(Players);
|
---|
160 | end;
|
---|
161 |
|
---|
162 | procedure TFormNewGame.ColorButton1ColorChanged(Sender: TObject);
|
---|
163 | begin
|
---|
164 | if Assigned(ListView1.Selected) then
|
---|
165 | with TPlayer(ListView1.Selected.Data) do begin
|
---|
166 | Color1 := ColorButton1.ButtonColor;
|
---|
167 | ReloadList;
|
---|
168 | end;
|
---|
169 | end;
|
---|
170 |
|
---|
171 | procedure TFormNewGame.CheckBoxEnabledChange(Sender: TObject);
|
---|
172 | begin
|
---|
173 | if Assigned(ListView1.Selected) then
|
---|
174 | with TPlayer(ListView1.Selected.Data) do begin
|
---|
175 | Enabled := CheckBoxEnabled.Checked;
|
---|
176 | ReloadList;
|
---|
177 | end;
|
---|
178 | end;
|
---|
179 |
|
---|
180 | procedure TFormNewGame.ColorButton2ColorChanged(Sender: TObject);
|
---|
181 | begin
|
---|
182 | if Assigned(ListView1.Selected) then
|
---|
183 | with TPlayer(ListView1.Selected.Data) do begin
|
---|
184 | Color2 := ColorButton2.ButtonColor;
|
---|
185 | ReloadList;
|
---|
186 | end;
|
---|
187 | end;
|
---|
188 |
|
---|
189 | procedure TFormNewGame.EditDownChange(Sender: TObject);
|
---|
190 | var
|
---|
191 | Value: Integer;
|
---|
192 | begin
|
---|
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;
|
---|
198 | end;
|
---|
199 |
|
---|
200 | procedure TFormNewGame.EditDownKeyDown(Sender: TObject; var Key: Word;
|
---|
201 | Shift: TShiftState);
|
---|
202 | begin
|
---|
203 | EditDown.Text := IntToStr(Key);
|
---|
204 | end;
|
---|
205 |
|
---|
206 | procedure TFormNewGame.EditLeftChange(Sender: TObject);
|
---|
207 | var
|
---|
208 | Value: Integer;
|
---|
209 | begin
|
---|
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;
|
---|
215 | end;
|
---|
216 |
|
---|
217 | procedure TFormNewGame.EditLeftKeyDown(Sender: TObject; var Key: Word;
|
---|
218 | Shift: TShiftState);
|
---|
219 | begin
|
---|
220 | EditLeft.Text := IntToStr(Key);
|
---|
221 | end;
|
---|
222 |
|
---|
223 | procedure TFormNewGame.EditNameChange(Sender: TObject);
|
---|
224 | begin
|
---|
225 | if Assigned(ListView1.Selected) then
|
---|
226 | with TPlayer(ListView1.Selected.Data) do begin
|
---|
227 | Name := EditName.Text;
|
---|
228 | ReloadList;
|
---|
229 | end;
|
---|
230 | end;
|
---|
231 |
|
---|
232 | procedure TFormNewGame.EditRightChange(Sender: TObject);
|
---|
233 | var
|
---|
234 | Value: Integer;
|
---|
235 | begin
|
---|
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;
|
---|
241 | end;
|
---|
242 |
|
---|
243 | procedure TFormNewGame.EditRightKeyDown(Sender: TObject; var Key: Word;
|
---|
244 | Shift: TShiftState);
|
---|
245 | begin
|
---|
246 | EditRight.Text := IntToStr(Key);
|
---|
247 | end;
|
---|
248 |
|
---|
249 | procedure TFormNewGame.EditShootChange(Sender: TObject);
|
---|
250 | var
|
---|
251 | Value: Integer;
|
---|
252 | begin
|
---|
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;
|
---|
258 | end;
|
---|
259 |
|
---|
260 | procedure TFormNewGame.EditShootKeyDown(Sender: TObject; var Key: Word;
|
---|
261 | Shift: TShiftState);
|
---|
262 | begin
|
---|
263 | EditShoot.Text := IntToStr(Key);
|
---|
264 | end;
|
---|
265 |
|
---|
266 | procedure TFormNewGame.EditUpChange(Sender: TObject);
|
---|
267 | var
|
---|
268 | Value: Integer;
|
---|
269 | begin
|
---|
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;
|
---|
275 | end;
|
---|
276 |
|
---|
277 | procedure TFormNewGame.EditUpKeyDown(Sender: TObject; var Key: Word;
|
---|
278 | Shift: TShiftState);
|
---|
279 | begin
|
---|
280 | EditUp.Text := IntToStr(Key);
|
---|
281 | end;
|
---|
282 |
|
---|
283 | procedure TFormNewGame.FormCreate(Sender: TObject);
|
---|
284 | begin
|
---|
285 | Core.Core.Translator1.TranslateComponentRecursive(Self);
|
---|
286 | Players := TPlayers.Create;
|
---|
287 | end;
|
---|
288 |
|
---|
289 | procedure TFormNewGame.FormDestroy(Sender: TObject);
|
---|
290 | begin
|
---|
291 | FreeAndNil(Players);
|
---|
292 | end;
|
---|
293 |
|
---|
294 | procedure TFormNewGame.FormShow(Sender: TObject);
|
---|
295 | begin
|
---|
296 | ReloadList;
|
---|
297 | UpdateInterface;
|
---|
298 | end;
|
---|
299 |
|
---|
300 | end.
|
---|
301 |
|
---|