source: trunk/Forms/FormNew.pas

Last change on this file was 330, checked in by chronos, 5 months ago
  • Fixed: New game symetric map units calcualtion.
  • Fixed: Map preview with cell and unit borders.
  • Fixed: Allow to set preferred game system grid type.
File size: 22.0 KB
Line 
1unit FormNew;
2
3interface
4
5uses
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
10type
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
161implementation
162
163{$R *.lfm}
164
165uses
166 Core, FormServer, ClientGUI, FormClient, FormGameSystems, MapType;
167
168resourcestring
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
188procedure TFormNew.ListViewServersData(Sender: TObject; Item: TListItem);
189begin
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;
196end;
197
198procedure TFormNew.ListViewServersKeyPress(Sender: TObject; var Key: char);
199begin
200 if Key = #13 then AServerModify.Execute;
201end;
202
203procedure TFormNew.ListViewServersSelectItem(Sender: TObject; Item: TListItem;
204 Selected: Boolean);
205begin
206 UpdateInterface;
207end;
208
209procedure TFormNew.PageControl1Change(Sender: TObject);
210begin
211 MapPreviewRedraw;
212end;
213
214procedure TFormNew.RadioButtonModeLocalChange(Sender: TObject);
215begin
216 UpdateInterface;
217end;
218
219procedure TFormNew.SpinEditCityPercentChange(Sender: TObject);
220begin
221 MapPreviewRedraw;
222end;
223
224procedure TFormNew.SpinEditMapSizeXChange(Sender: TObject);
225begin
226 TrackBarSizeX.Position := SpinEditMapSizeX.Value;
227 MapPreviewRedraw;
228end;
229
230procedure TFormNew.SpinEditMapSizeYChange(Sender: TObject);
231begin
232 TrackBarSizeY.Position := SpinEditMapSizeY.Value;
233 MapPreviewRedraw;
234end;
235
236procedure TFormNew.SpinEditMaxPowerChange(Sender: TObject);
237begin
238 UpdateInterface;
239end;
240
241procedure TFormNew.SpinEditNeutralUnitsChange(Sender: TObject);
242begin
243 MapPreviewRedraw;
244end;
245
246procedure TFormNew.SpinEditVoidPercentChange(Sender: TObject);
247begin
248 MapPreviewRedraw;
249end;
250
251procedure TFormNew.TabSheetMapShow(Sender: TObject);
252begin
253 MapPreviewRedraw;
254end;
255
256procedure TFormNew.TimerMapPreviewTimer(Sender: TObject);
257begin
258 if MapPreviewRedrawPending then begin
259 MapPreviewPaint;
260 MapPreviewRedrawPending := False;
261 end;
262end;
263
264procedure TFormNew.TrackBarSizeYChange(Sender: TObject);
265begin
266 SpinEditMapSizeY.Value := TrackBarSizeY.Position;
267end;
268
269procedure TFormNew.TrackBarSizeXChange(Sender: TObject);
270begin
271 SpinEditMapSizeX.Value := TrackBarSizeX.Position;
272end;
273
274procedure TFormNew.LoadGame(Game: TGame);
275begin
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;
304end;
305
306procedure TFormNew.SaveGame(Game: TGame);
307begin
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;
331end;
332
333procedure TFormNew.MapPreviewRedraw;
334begin
335 MapPreviewRedrawPending := True;
336end;
337
338procedure TFormNew.ReloadGameSystemsMenu;
339var
340 I: Integer;
341 LastSystem: Pointer;
342begin
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;
365end;
366
367procedure TFormNew.SetServer(AValue: TServer);
368begin
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;
377end;
378
379procedure TFormNew.MapPreviewPaint;
380var
381 Client: TClientGUI;
382 Bitmap: TBitmap;
383begin
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;
405end;
406
407procedure TFormNew.Translate;
408var
409 LastIndex: Integer;
410begin
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);
457end;
458
459procedure TFormNew.ReloadView;
460begin
461 ListViewServers.Items.Count := ServerList.Items.Count;
462 ListViewServers.Refresh;
463 UpdateInterface;
464end;
465
466procedure TFormNew.UpdateInterface;
467var
468 WinObjective: TWinObjective;
469begin
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;
493end;
494
495procedure TFormNew.FormShow(Sender: TObject);
496begin
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}
506end;
507
508procedure TFormNew.Image1Resize(Sender: TObject);
509begin
510 MapPreviewRedraw;
511end;
512
513procedure TFormNew.FormCreate(Sender: TObject);
514begin
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;
528end;
529
530procedure TFormNew.CheckBoxCityChange(Sender: TObject);
531begin
532 SpinEditCityPercent.Enabled := CheckBoxCity.Checked;
533 MapPreviewRedraw;
534end;
535
536procedure TFormNew.CheckBoxCyclicMapChange(Sender: TObject);
537begin
538 MapPreviewRedraw;
539end;
540
541procedure TFormNew.CheckBoxSymetricMapChange(Sender: TObject);
542begin
543 MapPreviewRedraw;
544end;
545
546procedure TFormNew.CheckBoxVoidChange(Sender: TObject);
547begin
548 SpinEditVoidPercent.Enabled := CheckBoxVoid.Checked;
549 MapPreviewRedraw;
550end;
551
552procedure TFormNew.ComboBoxGameSystemChange(Sender: TObject);
553begin
554 FServer.Game.GameSystem.Assign(TGameSystem(ComboBoxGameSystem.Items.Objects[ComboBoxGameSystem.ItemIndex]));
555 UpdateInterface;
556 MapPreviewRedraw;
557end;
558
559procedure TFormNew.ComboBoxGridTypeChange(Sender: TObject);
560begin
561 MapPreviewRedraw;
562end;
563
564procedure TFormNew.ComboBoxMapShapeChange(Sender: TObject);
565begin
566 ReloadView;
567 MapPreviewRedraw;
568end;
569
570procedure TFormNew.ComboBoxWinObjectiveChange(Sender: TObject);
571begin
572 UpdateInterface;
573end;
574
575procedure TFormNew.EditImageFileChange(Sender: TObject);
576begin
577 MapPreviewRedraw;
578end;
579
580procedure TFormNew.AServerAddExecute(Sender: TObject);
581var
582 NewServerInfo: TServerInfo;
583 FormServer: TFormServer;
584begin
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;
596end;
597
598procedure TFormNew.AServerModifyExecute(Sender: TObject);
599var
600 ServerInfo: TServerInfo;
601 FormServer: TFormServer;
602begin
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;
613end;
614
615procedure TFormNew.AServerRemoveExecute(Sender: TObject);
616var
617 I: Integer;
618begin
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;
626end;
627
628procedure TFormNew.ButtonGameSystemsClick(Sender: TObject);
629var
630 FormGameSystems: TFormGameSystems;
631begin
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;
640end;
641
642procedure TFormNew.ButtonImageBrowseClick(Sender: TObject);
643begin
644 OpenPictureDialog1.FileName := EditImageFile.Text;
645 if OpenPictureDialog1.Execute then begin
646 EditImageFile.Text := OpenPictureDialog1.FileName;
647 end;
648end;
649
650procedure TFormNew.ButtonOkClick(Sender: TObject);
651begin
652 Save(FServer);
653end;
654
655procedure TFormNew.ButtonRandomizeClick(Sender: TObject);
656begin
657 Randomize;
658 NewRandSeed := RandSeed;
659 MapPreviewRedraw;
660end;
661
662procedure TFormNew.CheckBoxBridgesChange(Sender: TObject);
663begin
664 MapPreviewRedraw;
665end;
666
667procedure TFormNew.FormDestroy(Sender: TObject);
668begin
669 FreeAndNil(ServerList);
670 FreeAndNil(FormChat);
671 FreeAndNil(FormPlayers);
672 FreeAndNil(GamePreview);
673end;
674
675procedure TFormNew.Load(Server: TServer);
676begin
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);
687end;
688
689procedure TFormNew.Save(Server: TServer);
690begin
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);
707end;
708
709end.
710
Note: See TracBrowser for help on using the repository browser.