1 | unit FormNew;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
7 | ComCtrls, Spin, ExtCtrls, ActnList, ExtDlgs, Menus, Game, Geometry, Player,
|
---|
8 | GameServer, ServerList, Map, GameSystem, FormList, FormEx, FormChat;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TFormNew }
|
---|
13 |
|
---|
14 | TFormNew = class(TFormEx)
|
---|
15 | ActionList1: TActionList;
|
---|
16 | AServerAdd: TAction;
|
---|
17 | AServerModify: TAction;
|
---|
18 | AServerRemove: TAction;
|
---|
19 | Button1: TButton;
|
---|
20 | Button2: TButton;
|
---|
21 | Button3: TButton;
|
---|
22 | ButtonGameSystems: TButton;
|
---|
23 | ButtonRandomize: TButton;
|
---|
24 | ButtonCancel: TButton;
|
---|
25 | ButtonImageBrowse: TButton;
|
---|
26 | ButtonOk: TButton;
|
---|
27 | CheckBoxBridges: TCheckBox;
|
---|
28 | CheckBoxCity: TCheckBox;
|
---|
29 | CheckBoxCyclicMap: TCheckBox;
|
---|
30 | CheckBoxFogOfWar: TCheckBox;
|
---|
31 | CheckBoxSymetricMap: TCheckBox;
|
---|
32 | CheckBoxVoid: TCheckBox;
|
---|
33 | ComboBoxGameSystem: TComboBox;
|
---|
34 | ComboBoxGridType: TComboBox;
|
---|
35 | ComboBoxMapShape: TComboBox;
|
---|
36 | ComboBoxWinObjective: TComboBox;
|
---|
37 | EditImageFile: TEdit;
|
---|
38 | EditServerAddress: TEdit;
|
---|
39 | Image1: TImage;
|
---|
40 | Label1: TLabel;
|
---|
41 | Label10: TLabel;
|
---|
42 | Label11: TLabel;
|
---|
43 | Label12: TLabel;
|
---|
44 | Label13: TLabel;
|
---|
45 | Label14: TLabel;
|
---|
46 | Label15: TLabel;
|
---|
47 | Label16: TLabel;
|
---|
48 | Label2: TLabel;
|
---|
49 | Label3: TLabel;
|
---|
50 | Label4: TLabel;
|
---|
51 | Label5: TLabel;
|
---|
52 | Label6: TLabel;
|
---|
53 | Label7: TLabel;
|
---|
54 | Label8: TLabel;
|
---|
55 | Label9: TLabel;
|
---|
56 | ListViewServers: TListView;
|
---|
57 | MenuItem4: TMenuItem;
|
---|
58 | MenuItem5: TMenuItem;
|
---|
59 | MenuItem6: TMenuItem;
|
---|
60 | OpenPictureDialog1: TOpenPictureDialog;
|
---|
61 | PageControl1: TPageControl;
|
---|
62 | PageControlWinObjective: TPageControl;
|
---|
63 | Panel1: TPanel;
|
---|
64 | Panel2: TPanel;
|
---|
65 | Panel3: TPanel;
|
---|
66 | Panel4: TPanel;
|
---|
67 | Panel5: TPanel;
|
---|
68 | PanelButtons: TPanel;
|
---|
69 | PanelChat: TPanel;
|
---|
70 | PopupMenuServers: TPopupMenu;
|
---|
71 | RadioButtonModeLocal: TRadioButton;
|
---|
72 | RadioButtonModeNetworkClient: TRadioButton;
|
---|
73 | RadioButtonModeNetworkServer: TRadioButton;
|
---|
74 | RadioGroupGrowAmount: TRadioGroup;
|
---|
75 | RadioGroupGrowCells: TRadioGroup;
|
---|
76 | SpinEditCityPercent: TSpinEdit;
|
---|
77 | SpinEditMapSizeX: TSpinEdit;
|
---|
78 | SpinEditMapSizeY: TSpinEdit;
|
---|
79 | SpinEditMaxPower: TSpinEdit;
|
---|
80 | SpinEditNeutralUnits: TSpinEdit;
|
---|
81 | SpinEditServerPort: TSpinEdit;
|
---|
82 | SpinEditSpecialCells: TSpinEdit;
|
---|
83 | SpinEditTurns: TSpinEdit;
|
---|
84 | SpinEditVoidPercent: TSpinEdit;
|
---|
85 | Splitter1: TSplitter;
|
---|
86 | TabSheetUnits: TTabSheet;
|
---|
87 | TabSheetCaptureEntireMap: TTabSheet;
|
---|
88 | TabSheetNone: TTabSheet;
|
---|
89 | TabSheetCaptureCells: TTabSheet;
|
---|
90 | TabSheetCaptureCities: TTabSheet;
|
---|
91 | TabSheetDefeatEnemies: TTabSheet;
|
---|
92 | TabSheetPlayers: TTabSheet;
|
---|
93 | TabSheetMap: TTabSheet;
|
---|
94 | TabSheetRules: TTabSheet;
|
---|
95 | TabSheetMode: TTabSheet;
|
---|
96 | TabSheetStayAliveTurns: TTabSheet;
|
---|
97 | TimerMapPreview: TTimer;
|
---|
98 | TrackBarSizeX: TTrackBar;
|
---|
99 | TrackBarSizeY: TTrackBar;
|
---|
100 | procedure AServerAddExecute(Sender: TObject);
|
---|
101 | procedure AServerModifyExecute(Sender: TObject);
|
---|
102 | procedure AServerRemoveExecute(Sender: TObject);
|
---|
103 | procedure ButtonGameSystemsClick(Sender: TObject);
|
---|
104 | procedure ButtonImageBrowseClick(Sender: TObject);
|
---|
105 | procedure ButtonOkClick(Sender: TObject);
|
---|
106 | procedure ButtonRandomizeClick(Sender: TObject);
|
---|
107 | procedure CheckBoxBridgesChange(Sender: TObject);
|
---|
108 | procedure CheckBoxCityChange(Sender: TObject);
|
---|
109 | procedure CheckBoxCyclicMapChange(Sender: TObject);
|
---|
110 | procedure CheckBoxSymetricMapChange(Sender: TObject);
|
---|
111 | procedure CheckBoxVoidChange(Sender: TObject);
|
---|
112 | procedure ComboBoxGameSystemChange(Sender: TObject);
|
---|
113 | procedure ComboBoxGridTypeChange(Sender: TObject);
|
---|
114 | procedure ComboBoxMapShapeChange(Sender: TObject);
|
---|
115 | procedure ComboBoxWinObjectiveChange(Sender: TObject);
|
---|
116 | procedure EditImageFileChange(Sender: TObject);
|
---|
117 | procedure FormCreate(Sender: TObject);
|
---|
118 | procedure FormDestroy(Sender: TObject);
|
---|
119 | procedure FormShow(Sender: TObject);
|
---|
120 | procedure Image1Resize(Sender: TObject);
|
---|
121 | procedure ListViewServersData(Sender: TObject; Item: TListItem);
|
---|
122 | procedure ListViewServersKeyPress(Sender: TObject; var Key: char);
|
---|
123 | procedure ListViewServersSelectItem(Sender: TObject; Item: TListItem;
|
---|
124 | Selected: Boolean);
|
---|
125 | procedure PageControl1Change(Sender: TObject);
|
---|
126 | procedure RadioButtonModeLocalChange(Sender: TObject);
|
---|
127 | procedure SpinEditCityPercentChange(Sender: TObject);
|
---|
128 | procedure SpinEditMapSizeXChange(Sender: TObject);
|
---|
129 | procedure SpinEditMapSizeYChange(Sender: TObject);
|
---|
130 | procedure SpinEditMaxPowerChange(Sender: TObject);
|
---|
131 | procedure SpinEditNeutralUnitsChange(Sender: TObject);
|
---|
132 | procedure SpinEditVoidPercentChange(Sender: TObject);
|
---|
133 | procedure TabSheetMapShow(Sender: TObject);
|
---|
134 | procedure TimerMapPreviewTimer(Sender: TObject);
|
---|
135 | procedure TrackBarSizeYChange(Sender: TObject);
|
---|
136 | procedure TrackBarSizeXChange(Sender: TObject);
|
---|
137 | private
|
---|
138 | FServer: TServer;
|
---|
139 | ServerList: TServerList;
|
---|
140 | GamePreview: TGame;
|
---|
141 | MapPreviewRedrawPending: Boolean;
|
---|
142 | NewRandSeed: Cardinal;
|
---|
143 | FormPlayers: TFormList;
|
---|
144 | FormChat: TFormChat;
|
---|
145 | procedure LoadGame(Game: TGame);
|
---|
146 | procedure SaveGame(Game: TGame);
|
---|
147 | procedure Load(Server: TServer);
|
---|
148 | procedure Save(Server: TServer);
|
---|
149 | procedure MapPreviewPaint;
|
---|
150 | procedure MapPreviewRedraw;
|
---|
151 | procedure ReloadGameSystemsMenu;
|
---|
152 | procedure SetServer(AValue: TServer);
|
---|
153 | public
|
---|
154 | procedure Translate;
|
---|
155 | procedure ReloadView;
|
---|
156 | procedure UpdateInterface;
|
---|
157 | property Server: TServer read FServer write SetServer;
|
---|
158 | end;
|
---|
159 |
|
---|
160 |
|
---|
161 | implementation
|
---|
162 |
|
---|
163 | {$R *.lfm}
|
---|
164 |
|
---|
165 | uses
|
---|
166 | Core, FormServer, ClientGUI, FormClient, FormGameSystems, MapType;
|
---|
167 |
|
---|
168 | resourcestring
|
---|
169 | SWinObjectiveNone = 'None';
|
---|
170 | SWinObjectiveDefeatAllOponents = 'Defeat all oponents';
|
---|
171 | SWinObjectiveDefeatAllCities = 'Defeat all oponents cities';
|
---|
172 | SWinObjectiveCapturePosition = 'Capture all special cells';
|
---|
173 | SWinObjectiveStayAliveForTurns = 'Stay alive for number of turns';
|
---|
174 | SWinObjectiveCaptureEntireMap = 'Capture entire map';
|
---|
175 | SGrowNone = 'None';
|
---|
176 | SGrowPlayerCities = 'Player cities';
|
---|
177 | SGrowPlayerAllCells = 'Player all cells';
|
---|
178 | SGrowAmountByOne = 'By one';
|
---|
179 | SGrowAmountBySquareRoot = 'By square root';
|
---|
180 | SRectangular = 'Rectangular';
|
---|
181 | SRounded = 'Rounded';
|
---|
182 | SFromImageFile = 'From image file';
|
---|
183 | SRemoveServer = 'Remove server';
|
---|
184 | SRemoveServerQuery = 'Do you want to remove server?';
|
---|
185 |
|
---|
186 | { TFormNew }
|
---|
187 |
|
---|
188 | procedure TFormNew.ListViewServersData(Sender: TObject; Item: TListItem);
|
---|
189 | begin
|
---|
190 | if Item.Index < ServerList.Items.Count then
|
---|
191 | with TServerInfo(ServerList.Items[Item.Index]) do begin
|
---|
192 | Item.Caption := Name;
|
---|
193 | Item.Data := ServerList.Items[Item.Index];
|
---|
194 | Item.SubItems.Add(Address + ':' + IntToStr(Port));
|
---|
195 | end;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | procedure TFormNew.ListViewServersKeyPress(Sender: TObject; var Key: char);
|
---|
199 | begin
|
---|
200 | if Key = #13 then AServerModify.Execute;
|
---|
201 | end;
|
---|
202 |
|
---|
203 | procedure TFormNew.ListViewServersSelectItem(Sender: TObject; Item: TListItem;
|
---|
204 | Selected: Boolean);
|
---|
205 | begin
|
---|
206 | UpdateInterface;
|
---|
207 | end;
|
---|
208 |
|
---|
209 | procedure TFormNew.PageControl1Change(Sender: TObject);
|
---|
210 | begin
|
---|
211 | MapPreviewRedraw;
|
---|
212 | end;
|
---|
213 |
|
---|
214 | procedure TFormNew.RadioButtonModeLocalChange(Sender: TObject);
|
---|
215 | begin
|
---|
216 | UpdateInterface;
|
---|
217 | end;
|
---|
218 |
|
---|
219 | procedure TFormNew.SpinEditCityPercentChange(Sender: TObject);
|
---|
220 | begin
|
---|
221 | MapPreviewRedraw;
|
---|
222 | end;
|
---|
223 |
|
---|
224 | procedure TFormNew.SpinEditMapSizeXChange(Sender: TObject);
|
---|
225 | begin
|
---|
226 | TrackBarSizeX.Position := SpinEditMapSizeX.Value;
|
---|
227 | MapPreviewRedraw;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TFormNew.SpinEditMapSizeYChange(Sender: TObject);
|
---|
231 | begin
|
---|
232 | TrackBarSizeY.Position := SpinEditMapSizeY.Value;
|
---|
233 | MapPreviewRedraw;
|
---|
234 | end;
|
---|
235 |
|
---|
236 | procedure TFormNew.SpinEditMaxPowerChange(Sender: TObject);
|
---|
237 | begin
|
---|
238 | UpdateInterface;
|
---|
239 | end;
|
---|
240 |
|
---|
241 | procedure TFormNew.SpinEditNeutralUnitsChange(Sender: TObject);
|
---|
242 | begin
|
---|
243 | MapPreviewRedraw;
|
---|
244 | end;
|
---|
245 |
|
---|
246 | procedure TFormNew.SpinEditVoidPercentChange(Sender: TObject);
|
---|
247 | begin
|
---|
248 | MapPreviewRedraw;
|
---|
249 | end;
|
---|
250 |
|
---|
251 | procedure TFormNew.TabSheetMapShow(Sender: TObject);
|
---|
252 | begin
|
---|
253 | MapPreviewRedraw;
|
---|
254 | end;
|
---|
255 |
|
---|
256 | procedure TFormNew.TimerMapPreviewTimer(Sender: TObject);
|
---|
257 | begin
|
---|
258 | if MapPreviewRedrawPending then begin
|
---|
259 | MapPreviewPaint;
|
---|
260 | MapPreviewRedrawPending := False;
|
---|
261 | end;
|
---|
262 | end;
|
---|
263 |
|
---|
264 | procedure TFormNew.TrackBarSizeYChange(Sender: TObject);
|
---|
265 | begin
|
---|
266 | SpinEditMapSizeY.Value := TrackBarSizeY.Position;
|
---|
267 | end;
|
---|
268 |
|
---|
269 | procedure TFormNew.TrackBarSizeXChange(Sender: TObject);
|
---|
270 | begin
|
---|
271 | SpinEditMapSizeX.Value := TrackBarSizeX.Position;
|
---|
272 | end;
|
---|
273 |
|
---|
274 | procedure TFormNew.LoadGame(Game: TGame);
|
---|
275 | begin
|
---|
276 | with Game do begin
|
---|
277 | CheckBoxSymetricMap.Checked := SymetricMap;
|
---|
278 | CheckBoxCyclicMap.Checked := CyclicMap;
|
---|
279 | CheckBoxVoid.Checked := VoidEnabled;
|
---|
280 | SpinEditVoidPercent.Value := VoidPercentage;
|
---|
281 | SpinEditVoidPercent.Enabled := VoidEnabled;
|
---|
282 | CheckBoxCity.Checked := CityEnabled;
|
---|
283 | SpinEditCityPercent.Value := CityPercentage;
|
---|
284 | SpinEditMapSizeX.Value := Map.Size.X;
|
---|
285 | SpinEditMapSizeY.Value := Map.Size.Y;
|
---|
286 | TrackBarSizeX.Position := Map.Size.X;
|
---|
287 | TrackBarSizeY.Position := Map.Size.Y;
|
---|
288 | RadioGroupGrowAmount.ItemIndex := Integer(GrowAmount);
|
---|
289 | RadioGroupGrowCells.ItemIndex := Integer(GrowCells);
|
---|
290 | ComboBoxGridType.ItemIndex := ComboBoxGridType.Items.IndexOfObject(TObject(MapType));
|
---|
291 | ComboBoxWinObjective.ItemIndex := Integer(WinObjective);
|
---|
292 | SpinEditNeutralUnits.Value := MaxNeutralUnits;
|
---|
293 | ComboBoxMapShape.ItemIndex := Integer(Map.Shape);
|
---|
294 | EditImageFile.Text := MapImageFileName;
|
---|
295 | CheckBoxFogOfWar.Checked := FogOfWar;
|
---|
296 | CheckBoxBridges.Checked := BridgeEnabled;
|
---|
297 | SpinEditMaxPower.Value := MaxPower;
|
---|
298 | SpinEditTurns.Value := StayAliveForDefinedTurns;
|
---|
299 | SpinEditSpecialCells.Value := SpecialCaptureCellCount;
|
---|
300 | ComboBoxGameSystem.ItemIndex := ComboBoxGameSystem.Items.IndexOf(GameSystem.GetName);
|
---|
301 | if (ComboBoxGameSystem.ItemIndex = -1) and (ComboBoxGameSystem.Items.Count > 0) then
|
---|
302 | ComboBoxGameSystem.ItemIndex := 0;
|
---|
303 | end;
|
---|
304 | end;
|
---|
305 |
|
---|
306 | procedure TFormNew.SaveGame(Game: TGame);
|
---|
307 | begin
|
---|
308 | with Game do begin
|
---|
309 | StoredRandSeed := NewRandSeed;
|
---|
310 | SymetricMap := CheckBoxSymetricMap.Checked;
|
---|
311 | CyclicMap := CheckBoxCyclicMap.Checked;
|
---|
312 | VoidEnabled := CheckBoxVoid.Checked;
|
---|
313 | VoidPercentage := SpinEditVoidPercent.Value;
|
---|
314 | CityEnabled := CheckBoxCity.Checked;
|
---|
315 | CityPercentage := SpinEditCityPercent.Value;
|
---|
316 | Map.Cyclic := CyclicMap;
|
---|
317 | Map.Size := TPoint.Create(SpinEditMapSizeX.Value, SpinEditMapSizeY.Value);
|
---|
318 | GrowAmount := TGrowAmount(RadioGroupGrowAmount.ItemIndex);
|
---|
319 | GrowCells := TGrowCells(RadioGroupGrowCells.ItemIndex);
|
---|
320 | MapType := TMapType(ComboBoxGridType.Items.Objects[ComboBoxGridType.ItemIndex]);
|
---|
321 | WinObjective := TWinObjective(ComboBoxWinObjective.ItemIndex);
|
---|
322 | MaxNeutralUnits := SpinEditNeutralUnits.Value;
|
---|
323 | Map.Shape := TMapShape(ComboBoxMapShape.ItemIndex);
|
---|
324 | MapImageFileName := EditImageFile.Text;
|
---|
325 | FogOfWar := CheckBoxFogOfWar.Checked;
|
---|
326 | BridgeEnabled := CheckBoxBridges.Checked;
|
---|
327 | MaxPower := SpinEditMaxPower.Value;
|
---|
328 | StayAliveForDefinedTurns := SpinEditTurns.Value;
|
---|
329 | SpecialCaptureCellCount := SpinEditSpecialCells.Value;
|
---|
330 | end;
|
---|
331 | end;
|
---|
332 |
|
---|
333 | procedure TFormNew.MapPreviewRedraw;
|
---|
334 | begin
|
---|
335 | MapPreviewRedrawPending := True;
|
---|
336 | end;
|
---|
337 |
|
---|
338 | procedure TFormNew.ReloadGameSystemsMenu;
|
---|
339 | var
|
---|
340 | I: Integer;
|
---|
341 | LastSystem: Pointer;
|
---|
342 | begin
|
---|
343 | if ComboBoxGameSystem.ItemIndex <> -1 then
|
---|
344 | LastSystem := ComboBoxGameSystem.Items.Objects[ComboBoxGameSystem.ItemIndex]
|
---|
345 | else LastSystem := nil;
|
---|
346 | ComboBoxGameSystem.Items.BeginUpdate;
|
---|
347 | try
|
---|
348 | while ComboBoxGameSystem.Items.Count > Core.Core.GameSystems.Count do
|
---|
349 | ComboBoxGameSystem.Items.Delete(ComboBoxGameSystem.Items.Count - 1);
|
---|
350 | while ComboBoxGameSystem.Items.Count < Core.Core.GameSystems.Count do
|
---|
351 | ComboBoxGameSystem.Items.Add('');
|
---|
352 | for I := 0 to Core.Core.GameSystems.Count - 1 do begin
|
---|
353 | ComboBoxGameSystem.Items[I] := Core.Core.GameSystems[I].GetName;
|
---|
354 | ComboBoxGameSystem.Items.Objects[I] := Core.Core.GameSystems[I];
|
---|
355 | end;
|
---|
356 | if Assigned(LastSystem) then
|
---|
357 | ComboBoxGameSystem.ItemIndex := ComboBoxGameSystem.Items.IndexOfObject(LastSystem);
|
---|
358 | if (ComboBoxGameSystem.ItemIndex = -1) and (ComboBoxGameSystem.Items.Count > 0) then
|
---|
359 | ComboBoxGameSystem.ItemIndex := 0;
|
---|
360 | finally
|
---|
361 | ComboBoxGameSystem.Items.EndUpdate;
|
---|
362 | end;
|
---|
363 | if (ComboBoxGameSystem.ItemIndex = -1) and (ComboBoxGameSystem.Items.Count > 0) then
|
---|
364 | ComboBoxGameSystem.ItemIndex := 0;
|
---|
365 | end;
|
---|
366 |
|
---|
367 | procedure TFormNew.SetServer(AValue: TServer);
|
---|
368 | begin
|
---|
369 | if FServer = AValue then Exit;
|
---|
370 | FServer := AValue;
|
---|
371 | if Assigned(FServer) then begin
|
---|
372 | Load(FServer);
|
---|
373 | FormPlayers.List := FServer.Game.Players;
|
---|
374 | end else begin
|
---|
375 | FormPlayers.List := nil;
|
---|
376 | end;
|
---|
377 | end;
|
---|
378 |
|
---|
379 | procedure TFormNew.MapPreviewPaint;
|
---|
380 | var
|
---|
381 | Client: TClientGUI;
|
---|
382 | Bitmap: TBitmap;
|
---|
383 | begin
|
---|
384 | Image1.Height := Round(Image1.Width * SpinEditMapSizeY.Value / SpinEditMapSizeX.Value);
|
---|
385 | GamePreview.GameSystem.Assign(FServer.Game.GameSystem);
|
---|
386 | SaveGame(GamePreview);
|
---|
387 | GamePreview.PostConfig;
|
---|
388 | GamePreview.GeneratePlayers := False;
|
---|
389 | GamePreview.New;
|
---|
390 | GamePreview.CurrentPlayer := TPlayer(GamePreview.Players.First);
|
---|
391 | Bitmap := Image1.Picture.Bitmap;
|
---|
392 | Bitmap.SetSize(Image1.Width, Image1.Height);
|
---|
393 | Client := TClientGUI.Create;
|
---|
394 | Client.Game := GamePreview;
|
---|
395 | Client.View.Game := GamePreview;
|
---|
396 | Client.View.DestRect := TRect.Create(TPoint.Create(0, 0), TPoint.Create(Image1.Width, Image1.Height));
|
---|
397 | Client.View.ZoomAll;
|
---|
398 | //Client.ControlPlayer := GamePreview.Players.First;
|
---|
399 | Client.CellGridVisible := Core.Core.CellGridVisible;
|
---|
400 | Client.UnitShapeVisible := Core.Core.UnitShapeVisible;
|
---|
401 | Bitmap.Canvas.Brush.Color := MapBackgroundColor; //clBackground; //PaintBox1.GetColorResolvingParent;
|
---|
402 | Bitmap.Canvas.FillRect(0, 0, Bitmap.Width, Bitmap.Height);
|
---|
403 | Client.Paint(Bitmap.Canvas, Client.View);
|
---|
404 | Client.Free;
|
---|
405 | end;
|
---|
406 |
|
---|
407 | procedure TFormNew.Translate;
|
---|
408 | var
|
---|
409 | LastIndex: Integer;
|
---|
410 | begin
|
---|
411 | with ComboBoxGridType do begin
|
---|
412 | LastIndex := ItemIndex;
|
---|
413 | Clear;
|
---|
414 | Items.AddObject(SGridTypeHexagonVertical, TObject(mtHexagonVertical));
|
---|
415 | Items.AddObject(SGridTypeHexagonHorizontal, TObject(mtHexagonHorizontal));
|
---|
416 | Items.AddObject(SGridTypeSquare, TObject(mtSquare));
|
---|
417 | Items.AddObject(SGridTypeTriangle, TObject(mtTriangle));
|
---|
418 | Items.AddObject(SGridTypeRandom, TObject(mtRandom));
|
---|
419 | Items.AddObject(SGridTypeIsometric, TObject(mtIsometric));
|
---|
420 | ItemIndex := LastIndex;
|
---|
421 | end;
|
---|
422 | with ComboBoxWinObjective do begin
|
---|
423 | LastIndex := ItemIndex;
|
---|
424 | Clear;
|
---|
425 | Items.Add(SWinObjectiveNone);
|
---|
426 | Items.Add(SWinObjectiveDefeatAllOponents);
|
---|
427 | Items.Add(SWinObjectiveDefeatAllCities);
|
---|
428 | Items.Add(SWinObjectiveCapturePosition);
|
---|
429 | Items.Add(SWinObjectiveStayAliveForTurns);
|
---|
430 | Items.Add(SWinObjectiveCaptureEntireMap);
|
---|
431 | ItemIndex := LastIndex;
|
---|
432 | end;
|
---|
433 | with ComboBoxMapShape do begin
|
---|
434 | LastIndex := ItemIndex;
|
---|
435 | Clear;
|
---|
436 | Items.Add(SRectangular);
|
---|
437 | Items.Add(SFromImageFile);
|
---|
438 | Items.Add(SRounded);
|
---|
439 | ItemIndex := LastIndex;
|
---|
440 | end;
|
---|
441 | with RadioGroupGrowCells do begin
|
---|
442 | LastIndex := ItemIndex;
|
---|
443 | Items.Clear;
|
---|
444 | Items.Add(SGrowNone);
|
---|
445 | Items.Add(SGrowPlayerCities);
|
---|
446 | Items.Add(SGrowPlayerAllCells);
|
---|
447 | ItemIndex := LastIndex;
|
---|
448 | end;
|
---|
449 | with RadioGroupGrowAmount do begin
|
---|
450 | LastIndex := ItemIndex;
|
---|
451 | Items.Clear;
|
---|
452 | Items.Add(SGrowAmountByOne);
|
---|
453 | Items.Add(SGrowAmountBySquareRoot);
|
---|
454 | ItemIndex := LastIndex;
|
---|
455 | end;
|
---|
456 | Core.Core.Translator1.TranslateComponentRecursive(Self);
|
---|
457 | end;
|
---|
458 |
|
---|
459 | procedure TFormNew.ReloadView;
|
---|
460 | begin
|
---|
461 | ListViewServers.Items.Count := ServerList.Items.Count;
|
---|
462 | ListViewServers.Refresh;
|
---|
463 | UpdateInterface;
|
---|
464 | end;
|
---|
465 |
|
---|
466 | procedure TFormNew.UpdateInterface;
|
---|
467 | var
|
---|
468 | WinObjective: TWinObjective;
|
---|
469 | begin
|
---|
470 |
|
---|
471 | ComboBoxGridType.Enabled := FServer.Game.GameSystem.PreferedMapType = mtNone;
|
---|
472 | if FServer.Game.GameSystem.PreferedMapType <> mtNone then
|
---|
473 | ComboBoxGridType.ItemIndex := ComboBoxGridType.Items.IndexOfObject(TObject(FServer.Game.GameSystem.PreferedMapType));
|
---|
474 | EditImageFile.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
|
---|
475 | ButtonImageBrowse.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
|
---|
476 | EditServerAddress.Enabled := RadioButtonModeNetworkServer.Checked;
|
---|
477 | SpinEditServerPort.Enabled := RadioButtonModeNetworkServer.Checked;
|
---|
478 | ListViewServers.Enabled := RadioButtonModeNetworkClient.Checked;
|
---|
479 | PanelChat.Visible := RadioButtonModeNetworkClient.Checked or RadioButtonModeNetworkServer.Checked;
|
---|
480 | SpinEditNeutralUnits.MaxValue := SpinEditMaxPower.Value;
|
---|
481 | AServerRemove.Enabled := RadioButtonModeNetworkClient.Checked and Assigned(ListViewServers.Selected);
|
---|
482 | AServerAdd.Enabled := RadioButtonModeNetworkClient.Checked;
|
---|
483 | AServerModify.Enabled := RadioButtonModeNetworkClient.Checked;
|
---|
484 | WinObjective := TWinObjective(ComboBoxWinObjective.ItemIndex);
|
---|
485 | case WinObjective of
|
---|
486 | woNone: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetNone);
|
---|
487 | woDefeatAllOponents: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetDefeatEnemies);
|
---|
488 | woDefeatAllOponentsCities: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureCities);
|
---|
489 | woSpecialCaptureCell: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureCells);
|
---|
490 | woStayAliveForDefinedTurns: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetStayAliveTurns);
|
---|
491 | woCaptureEntireMap: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureEntireMap);
|
---|
492 | end;
|
---|
493 | end;
|
---|
494 |
|
---|
495 | procedure TFormNew.FormShow(Sender: TObject);
|
---|
496 | begin
|
---|
497 | Randomize;
|
---|
498 | NewRandSeed := RandSeed;
|
---|
499 | ReloadView;
|
---|
500 | //Height := Trunc(1.5 * Height);
|
---|
501 | //PageControl1.TabIndex := 0;
|
---|
502 | {$IFNDEF DEBUG}
|
---|
503 | TabSheetMode.TabVisible := False;
|
---|
504 | TabSheetMode.Enabled := False;
|
---|
505 | {$ENDIF}
|
---|
506 | end;
|
---|
507 |
|
---|
508 | procedure TFormNew.Image1Resize(Sender: TObject);
|
---|
509 | begin
|
---|
510 | MapPreviewRedraw;
|
---|
511 | end;
|
---|
512 |
|
---|
513 | procedure TFormNew.FormCreate(Sender: TObject);
|
---|
514 | begin
|
---|
515 | GamePreview := TGame.Create;
|
---|
516 | ServerList := TServerList.Create;
|
---|
517 | FormChat := TFormChat.Create(nil);
|
---|
518 | FormChat.ManualDock(PanelChat, nil, alClient);
|
---|
519 | FormChat.Align := alClient;
|
---|
520 | FormChat.Show;
|
---|
521 | FormPlayers := TFormList.Create(nil);
|
---|
522 | FormPlayers.MinItemCount := MinPlayerCount;
|
---|
523 | FormPlayers.MaxItemCount := MaxPlayerCount;
|
---|
524 | FormPlayers.ManualDock(Panel2, nil, alClient);
|
---|
525 | FormPlayers.Align := alClient;
|
---|
526 | FormPlayers.Visible := True;
|
---|
527 | Translate;
|
---|
528 | end;
|
---|
529 |
|
---|
530 | procedure TFormNew.CheckBoxCityChange(Sender: TObject);
|
---|
531 | begin
|
---|
532 | SpinEditCityPercent.Enabled := CheckBoxCity.Checked;
|
---|
533 | MapPreviewRedraw;
|
---|
534 | end;
|
---|
535 |
|
---|
536 | procedure TFormNew.CheckBoxCyclicMapChange(Sender: TObject);
|
---|
537 | begin
|
---|
538 | MapPreviewRedraw;
|
---|
539 | end;
|
---|
540 |
|
---|
541 | procedure TFormNew.CheckBoxSymetricMapChange(Sender: TObject);
|
---|
542 | begin
|
---|
543 | MapPreviewRedraw;
|
---|
544 | end;
|
---|
545 |
|
---|
546 | procedure TFormNew.CheckBoxVoidChange(Sender: TObject);
|
---|
547 | begin
|
---|
548 | SpinEditVoidPercent.Enabled := CheckBoxVoid.Checked;
|
---|
549 | MapPreviewRedraw;
|
---|
550 | end;
|
---|
551 |
|
---|
552 | procedure TFormNew.ComboBoxGameSystemChange(Sender: TObject);
|
---|
553 | begin
|
---|
554 | FServer.Game.GameSystem.Assign(TGameSystem(ComboBoxGameSystem.Items.Objects[ComboBoxGameSystem.ItemIndex]));
|
---|
555 | UpdateInterface;
|
---|
556 | MapPreviewRedraw;
|
---|
557 | end;
|
---|
558 |
|
---|
559 | procedure TFormNew.ComboBoxGridTypeChange(Sender: TObject);
|
---|
560 | begin
|
---|
561 | MapPreviewRedraw;
|
---|
562 | end;
|
---|
563 |
|
---|
564 | procedure TFormNew.ComboBoxMapShapeChange(Sender: TObject);
|
---|
565 | begin
|
---|
566 | ReloadView;
|
---|
567 | MapPreviewRedraw;
|
---|
568 | end;
|
---|
569 |
|
---|
570 | procedure TFormNew.ComboBoxWinObjectiveChange(Sender: TObject);
|
---|
571 | begin
|
---|
572 | UpdateInterface;
|
---|
573 | end;
|
---|
574 |
|
---|
575 | procedure TFormNew.EditImageFileChange(Sender: TObject);
|
---|
576 | begin
|
---|
577 | MapPreviewRedraw;
|
---|
578 | end;
|
---|
579 |
|
---|
580 | procedure TFormNew.AServerAddExecute(Sender: TObject);
|
---|
581 | var
|
---|
582 | NewServerInfo: TServerInfo;
|
---|
583 | FormServer: TFormServer;
|
---|
584 | begin
|
---|
585 | FormServer := TFormServer.Create(nil);
|
---|
586 | try
|
---|
587 | NewServerInfo := TServerInfo.Create;
|
---|
588 | FormServer.ServerInfo := NewServerInfo;
|
---|
589 | if FormServer.ShowModal = mrOK then begin
|
---|
590 | ServerList.Items.Add(NewServerInfo);
|
---|
591 | ReloadView;
|
---|
592 | end else NewServerInfo.Free;
|
---|
593 | finally
|
---|
594 | FormServer.Free;
|
---|
595 | end;
|
---|
596 | end;
|
---|
597 |
|
---|
598 | procedure TFormNew.AServerModifyExecute(Sender: TObject);
|
---|
599 | var
|
---|
600 | ServerInfo: TServerInfo;
|
---|
601 | FormServer: TFormServer;
|
---|
602 | begin
|
---|
603 | FormServer := TFormServer.Create(nil);
|
---|
604 | try
|
---|
605 | ServerInfo := TServerInfo(ListViewServers.Selected.Data);
|
---|
606 | FormServer.ServerInfo := ServerInfo;
|
---|
607 | if FormServer.ShowModal = mrOK then begin
|
---|
608 | ReloadView;
|
---|
609 | end;
|
---|
610 | finally
|
---|
611 | FormServer.Free;
|
---|
612 | end;
|
---|
613 | end;
|
---|
614 |
|
---|
615 | procedure TFormNew.AServerRemoveExecute(Sender: TObject);
|
---|
616 | var
|
---|
617 | I: Integer;
|
---|
618 | begin
|
---|
619 | if MessageDlg(SRemoveServer, SRemoveServerQuery,
|
---|
620 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
621 | for I := ListViewServers.Items.Count - 1 downto 0 do
|
---|
622 | if ListViewServers.Items[I].Selected then
|
---|
623 | ServerList.Items.Delete(I);
|
---|
624 | ReloadView;
|
---|
625 | end;
|
---|
626 | end;
|
---|
627 |
|
---|
628 | procedure TFormNew.ButtonGameSystemsClick(Sender: TObject);
|
---|
629 | var
|
---|
630 | FormGameSystems: TFormGameSystems;
|
---|
631 | begin
|
---|
632 | FormGameSystems := TFormGameSystems.Create(nil);
|
---|
633 | try
|
---|
634 | FormGameSystems.GameSystems := Core.Core.GameSystems;
|
---|
635 | FormGameSystems.ShowModal;
|
---|
636 | ReloadGameSystemsMenu;
|
---|
637 | finally
|
---|
638 | FreeAndNil(FormGameSystems);
|
---|
639 | end;
|
---|
640 | end;
|
---|
641 |
|
---|
642 | procedure TFormNew.ButtonImageBrowseClick(Sender: TObject);
|
---|
643 | begin
|
---|
644 | OpenPictureDialog1.FileName := EditImageFile.Text;
|
---|
645 | if OpenPictureDialog1.Execute then begin
|
---|
646 | EditImageFile.Text := OpenPictureDialog1.FileName;
|
---|
647 | end;
|
---|
648 | end;
|
---|
649 |
|
---|
650 | procedure TFormNew.ButtonOkClick(Sender: TObject);
|
---|
651 | begin
|
---|
652 | Save(FServer);
|
---|
653 | end;
|
---|
654 |
|
---|
655 | procedure TFormNew.ButtonRandomizeClick(Sender: TObject);
|
---|
656 | begin
|
---|
657 | Randomize;
|
---|
658 | NewRandSeed := RandSeed;
|
---|
659 | MapPreviewRedraw;
|
---|
660 | end;
|
---|
661 |
|
---|
662 | procedure TFormNew.CheckBoxBridgesChange(Sender: TObject);
|
---|
663 | begin
|
---|
664 | MapPreviewRedraw;
|
---|
665 | end;
|
---|
666 |
|
---|
667 | procedure TFormNew.FormDestroy(Sender: TObject);
|
---|
668 | begin
|
---|
669 | FreeAndNil(ServerList);
|
---|
670 | FreeAndNil(FormChat);
|
---|
671 | FreeAndNil(FormPlayers);
|
---|
672 | FreeAndNil(GamePreview);
|
---|
673 | end;
|
---|
674 |
|
---|
675 | procedure TFormNew.Load(Server: TServer);
|
---|
676 | begin
|
---|
677 | ReloadGameSystemsMenu;
|
---|
678 | with Server do begin
|
---|
679 | RadioButtonModeLocal.Checked := Mode = smLocal;
|
---|
680 | RadioButtonModeNetworkClient.Checked := Mode = smNetworkClient;
|
---|
681 | RadioButtonModeNetworkServer.Checked := Mode = smNetworkServer;
|
---|
682 | EditServerAddress.Text := LocalNetworkAddress;
|
---|
683 | SpinEditServerPort.Value := LocalNetworkPort;
|
---|
684 | end;
|
---|
685 | ServerList.Assign(Core.Core.ServerList);
|
---|
686 | LoadGame(Server.Game);
|
---|
687 | end;
|
---|
688 |
|
---|
689 | procedure TFormNew.Save(Server: TServer);
|
---|
690 | begin
|
---|
691 | with Server do begin
|
---|
692 | if RadioButtonModeLocal.Checked then Mode := smLocal
|
---|
693 | else if RadioButtonModeNetworkClient.Checked then Mode := smNetworkClient
|
---|
694 | else if RadioButtonModeNetworkServer.Checked then Mode := smNetworkServer;
|
---|
695 | LocalNetworkAddress := EditServerAddress.Text;
|
---|
696 | LocalNetworkPort := SpinEditServerPort.Value;
|
---|
697 | if Assigned(ListViewServers.Selected) then begin
|
---|
698 | RemoteNetworkAddress := TServerInfo(ListViewServers.Selected.Data).Address;
|
---|
699 | RemoteNetworkPort := TServerInfo(ListViewServers.Selected.Data).Port;
|
---|
700 | end else begin
|
---|
701 | RemoteNetworkAddress := '';
|
---|
702 | RemoteNetworkPort := 0;
|
---|
703 | end;
|
---|
704 | end;
|
---|
705 | Core.Core.ServerList.Assign(ServerList);
|
---|
706 | SaveGame(Server.Game);
|
---|
707 | end;
|
---|
708 |
|
---|
709 | end.
|
---|
710 |
|
---|