1 | unit UFormNew;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
7 | ComCtrls, Spin, ExtCtrls, ActnList, UGame, System.Actions;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormNew }
|
---|
12 |
|
---|
13 | TFormNew = class(TForm)
|
---|
14 | APlayerAdd: TAction;
|
---|
15 | APlayerRemove: TAction;
|
---|
16 | APlayerModify: TAction;
|
---|
17 | ActionList1: TActionList;
|
---|
18 | ButtonCancel: TButton;
|
---|
19 | ButtonOk: TButton;
|
---|
20 | ButtonPlayerAdd: TButton;
|
---|
21 | ButtonPlayerModify: TButton;
|
---|
22 | ButtonPlayerRemove: TButton;
|
---|
23 | CheckBoxCity: TCheckBox;
|
---|
24 | CheckBoxVoid: TCheckBox;
|
---|
25 | ComboBoxGridType: TComboBox;
|
---|
26 | Label1: TLabel;
|
---|
27 | Label2: TLabel;
|
---|
28 | Label3: TLabel;
|
---|
29 | Label4: TLabel;
|
---|
30 | Label5: TLabel;
|
---|
31 | ListView1: TListView;
|
---|
32 | Panel1: TPanel;
|
---|
33 | Panel2: TPanel;
|
---|
34 | RadioGroupGrowAmount: TRadioGroup;
|
---|
35 | RadioGroupGrowCells: TRadioGroup;
|
---|
36 | SpinEditCityPercent: TSpinEdit;
|
---|
37 | SpinEditMapSizeX: TSpinEdit;
|
---|
38 | SpinEditMapSizeY: TSpinEdit;
|
---|
39 | SpinEditVoidPercent: TSpinEdit;
|
---|
40 | Splitter1: TSplitter;
|
---|
41 | TrackBarSizeX: TTrackBar;
|
---|
42 | TrackBarSizeY: TTrackBar;
|
---|
43 | procedure APlayerAddExecute(Sender: TObject);
|
---|
44 | procedure APlayerModifyExecute(Sender: TObject);
|
---|
45 | procedure APlayerRemoveExecute(Sender: TObject);
|
---|
46 | procedure CheckBoxCityChange(Sender: TObject);
|
---|
47 | procedure CheckBoxVoidChange(Sender: TObject);
|
---|
48 | procedure FormCreate(Sender: TObject);
|
---|
49 | procedure FormDestroy(Sender: TObject);
|
---|
50 | procedure FormShow(Sender: TObject);
|
---|
51 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
52 | procedure ListView1DblClick(Sender: TObject);
|
---|
53 | procedure ListView1KeyPress(Sender: TObject; var Key: char);
|
---|
54 | procedure ListView1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
|
---|
55 | );
|
---|
56 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
57 | Selected: Boolean);
|
---|
58 | procedure SpinEditMapSizeXChange(Sender: TObject);
|
---|
59 | procedure SpinEditMapSizeYChange(Sender: TObject);
|
---|
60 | procedure TrackBarSizeYChange(Sender: TObject);
|
---|
61 | procedure TrackBarSizeXChange(Sender: TObject);
|
---|
62 | private
|
---|
63 | Players: TPlayers;
|
---|
64 | public
|
---|
65 | procedure ReloadView;
|
---|
66 | procedure Load(Game: TGame);
|
---|
67 | procedure Save(Game: TGame);
|
---|
68 | end;
|
---|
69 |
|
---|
70 | var
|
---|
71 | FormNew: TFormNew;
|
---|
72 |
|
---|
73 | implementation
|
---|
74 |
|
---|
75 | {$R *.dfm}
|
---|
76 |
|
---|
77 | uses
|
---|
78 | UFormPlayer;
|
---|
79 |
|
---|
80 | { TFormNew }
|
---|
81 |
|
---|
82 | procedure TFormNew.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
83 | begin
|
---|
84 | if (Item.Index >= 0) and (Item.Index < Players.Count) then
|
---|
85 | with TPlayer(Players[Item.Index]) do begin
|
---|
86 | Item.Caption := Name;
|
---|
87 | Item.Data := Players[Item.Index];
|
---|
88 | Item.SubItems.Add(PlayerModeText[Mode]);
|
---|
89 | Item.SubItems.Add(IntToStr(Color));
|
---|
90 | Item.SubItems.Add(IntToStr(StartUnits));
|
---|
91 | end;
|
---|
92 | end;
|
---|
93 |
|
---|
94 | procedure TFormNew.ListView1DblClick(Sender: TObject);
|
---|
95 | begin
|
---|
96 | APlayerModify.Execute;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TFormNew.ListView1KeyPress(Sender: TObject; var Key: char);
|
---|
100 | begin
|
---|
101 | if (Key = #13) then APlayerModify.Execute;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TFormNew.ListView1KeyUp(Sender: TObject; var Key: Word;
|
---|
105 | Shift: TShiftState);
|
---|
106 | begin
|
---|
107 | if Key = 45 then APlayerAdd.Execute;
|
---|
108 | if Key = 46 then APlayerRemove.Execute;
|
---|
109 | end;
|
---|
110 |
|
---|
111 | procedure TFormNew.ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
112 | Selected: Boolean);
|
---|
113 | begin
|
---|
114 | ReloadView;
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TFormNew.SpinEditMapSizeXChange(Sender: TObject);
|
---|
118 | begin
|
---|
119 | TrackBarSizeX.Position := SpinEditMapSizeX.Value;
|
---|
120 | end;
|
---|
121 |
|
---|
122 | procedure TFormNew.SpinEditMapSizeYChange(Sender: TObject);
|
---|
123 | begin
|
---|
124 | TrackBarSizeY.Position := SpinEditMapSizeY.Value;
|
---|
125 | end;
|
---|
126 |
|
---|
127 | procedure TFormNew.TrackBarSizeYChange(Sender: TObject);
|
---|
128 | begin
|
---|
129 | SpinEditMapSizeY.Value := TrackBarSizeY.Position;
|
---|
130 | end;
|
---|
131 |
|
---|
132 | procedure TFormNew.TrackBarSizeXChange(Sender: TObject);
|
---|
133 | begin
|
---|
134 | SpinEditMapSizeX.Value := TrackBarSizeX.Position;
|
---|
135 | end;
|
---|
136 |
|
---|
137 | procedure TFormNew.ReloadView;
|
---|
138 | begin
|
---|
139 | ListView1.Items.Count := Players.Count;
|
---|
140 | ListView1.Refresh;
|
---|
141 | ButtonPlayerRemove.Enabled := Assigned(ListView1.Selected);
|
---|
142 | ButtonPlayerAdd.Enabled := Players.Count < MaxPlayerCount;
|
---|
143 | APlayerModify.Enabled := Assigned(ListView1.Selected);
|
---|
144 | end;
|
---|
145 |
|
---|
146 | procedure TFormNew.FormShow(Sender: TObject);
|
---|
147 | begin
|
---|
148 | ReloadView;
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TFormNew.FormCreate(Sender: TObject);
|
---|
152 | begin
|
---|
153 | Players := TPlayers.Create;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | procedure TFormNew.CheckBoxCityChange(Sender: TObject);
|
---|
157 | begin
|
---|
158 | SpinEditCityPercent.Enabled := CheckBoxCity.Checked;
|
---|
159 | end;
|
---|
160 |
|
---|
161 | procedure TFormNew.CheckBoxVoidChange(Sender: TObject);
|
---|
162 | begin
|
---|
163 | SpinEditVoidPercent.Enabled := CheckBoxVoid.Checked;
|
---|
164 | end;
|
---|
165 |
|
---|
166 | procedure TFormNew.APlayerModifyExecute(Sender: TObject);
|
---|
167 | begin
|
---|
168 | if Assigned(ListView1.Selected) then begin
|
---|
169 | FormPlayer.Load(TPlayer(ListView1.Selected.Data));
|
---|
170 | if FormPlayer.ShowModal = mrOk then begin
|
---|
171 | FormPlayer.Save(TPlayer(ListView1.Selected.Data));
|
---|
172 | ReloadView;
|
---|
173 | end;
|
---|
174 | end;
|
---|
175 | end;
|
---|
176 |
|
---|
177 | procedure TFormNew.APlayerRemoveExecute(Sender: TObject);
|
---|
178 | begin
|
---|
179 | if Assigned(ListView1.Selected) then begin
|
---|
180 | Players.Remove(ListView1.Selected.Data);
|
---|
181 | ReloadView;
|
---|
182 | end;
|
---|
183 | end;
|
---|
184 |
|
---|
185 | procedure TFormNew.APlayerAddExecute(Sender: TObject);
|
---|
186 | var
|
---|
187 | NewPlayer: TPlayer;
|
---|
188 | begin
|
---|
189 | if Players.Count <= (MaxPlayerCount - 1) then begin
|
---|
190 | NewPlayer := TPlayer.Create;
|
---|
191 | NewPlayer.Name := 'Player ' + IntToStr(Players.Count + 1);
|
---|
192 | NewPlayer.Color := PlayerColors[Players.Count];
|
---|
193 | NewPlayer.Mode := pmComputer;
|
---|
194 | Players.Add(NewPlayer);
|
---|
195 | ReloadView;
|
---|
196 | end;
|
---|
197 | end;
|
---|
198 |
|
---|
199 | procedure TFormNew.FormDestroy(Sender: TObject);
|
---|
200 | begin
|
---|
201 | Players.Free;
|
---|
202 | end;
|
---|
203 |
|
---|
204 | procedure TFormNew.Load(Game: TGame);
|
---|
205 | var
|
---|
206 | I: Integer;
|
---|
207 | NewItem: TListItem;
|
---|
208 | begin
|
---|
209 | CheckBoxVoid.Checked := Game.VoidEnabled;
|
---|
210 | SpinEditVoidPercent.Value := Game.VoidPercentage;
|
---|
211 | SpinEditVoidPercent.Enabled := Game.VoidEnabled;
|
---|
212 | for I := 0 to Players.Count - 1 do
|
---|
213 | Players[I] := nil;
|
---|
214 | Players.Count := Game.Players.Count;
|
---|
215 | for I := 0 to Game.Players.Count - 1 do begin
|
---|
216 | Players[I] := TPlayer.Create;
|
---|
217 | TPlayer(Players[I]).Assign(TPlayer(Game.Players[I]));
|
---|
218 | end;
|
---|
219 | CheckBoxCity.Checked := Game.CityEnabled;
|
---|
220 | SpinEditCityPercent.Value := Game.CityPercentage;
|
---|
221 | SpinEditMapSizeX.Value := Game.Map.Size.X;
|
---|
222 | SpinEditMapSizeY.Value := Game.Map.Size.Y;
|
---|
223 | TrackBarSizeX.Position := Game.Map.Size.X;
|
---|
224 | TrackBarSizeY.Position := Game.Map.Size.Y;
|
---|
225 | RadioGroupGrowAmount.ItemIndex := Integer(Game.GrowAmount);
|
---|
226 | RadioGroupGrowCells.ItemIndex := Integer(Game.GrowCells);
|
---|
227 | ComboBoxGridType.ItemIndex := Integer(Game.MapType) - 1;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TFormNew.Save(Game: TGame);
|
---|
231 | var
|
---|
232 | I: Integer;
|
---|
233 | begin
|
---|
234 | while Game.Players.Count > Players.Count do
|
---|
235 | Game.Players.Delete(Game.Players.Count - 1);
|
---|
236 | while Game.Players.Count < Players.Count do
|
---|
237 | Game.Players.Add(TPlayer.Create);
|
---|
238 | for I := 0 to Game.Players.Count - 1 do begin
|
---|
239 | TPlayer(Game.Players[I]).Assign(TPlayer(Players[I]));
|
---|
240 | TPlayer(Game.Players[I]).Game := Game;
|
---|
241 | end;
|
---|
242 | Game.VoidEnabled := CheckBoxVoid.Checked;
|
---|
243 | Game.VoidPercentage := SpinEditVoidPercent.Value;
|
---|
244 | Game.CityEnabled := CheckBoxCity.Checked;
|
---|
245 | Game.CityPercentage := SpinEditCityPercent.Value;
|
---|
246 | Game.Map.Size := Point(SpinEditMapSizeX.Value, SpinEditMapSizeY.Value);
|
---|
247 | Game.GrowAmount := TGrowAmount(RadioGroupGrowAmount.ItemIndex);
|
---|
248 | Game.GrowCells := TGrowCells(RadioGroupGrowCells.ItemIndex);
|
---|
249 | Game.MapType := TMapType(ComboBoxGridType.ItemIndex + 1);
|
---|
250 | end;
|
---|
251 |
|
---|
252 | end.
|
---|
253 |
|
---|