source: trunk/Forms/FormGameSystem.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: 5.0 KB
Line 
1unit FormGameSystem;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
7 ComCtrls, GameSystem, FormList, FormEx;
8
9type
10
11 { TFormGameSystem }
12
13 TFormGameSystem = class(TFormEx)
14 ButtonCancel: TButton;
15 ButtonOk: TButton;
16 ButtonSave: TButton;
17 ButtonLoad: TButton;
18 CheckBoxEmptyCellsNeutral: TCheckBox;
19 CheckBoxUnitsMoveImmediately: TCheckBox;
20 CheckBoxUnitsSplitMerge: TCheckBox;
21 ComboBoxPreferredGridType: TComboBox;
22 Label5: TLabel;
23 OpenDialog1: TOpenDialog;
24 PageControl1: TPageControl;
25 SaveDialog1: TSaveDialog;
26 TabSheetBuildings: TTabSheet;
27 TabSheetNations: TTabSheet;
28 TabSheetGeneral: TTabSheet;
29 TabSheetUnits: TTabSheet;
30 procedure ButtonLoadClick(Sender: TObject);
31 procedure ButtonSaveClick(Sender: TObject);
32 procedure FormCreate(Sender: TObject);
33 procedure FormDestroy(Sender: TObject);
34 private
35 FGameSystem: TGameSystem;
36 FormUnitKinds: TFormList;
37 FormNations: TFormList;
38 FormBuildingKinds: TFormList;
39 procedure SetGameSystem(AValue: TGameSystem);
40 procedure Translate;
41 public
42 property GameSystem: TGameSystem read FGameSystem write SetGameSystem;
43 procedure LoadData(GameSystem: TGameSystem);
44 procedure SaveData(GameSystem: TGameSystem);
45 end;
46
47
48implementation
49
50{$R *.lfm}
51
52uses
53 MapType;
54
55resourcestring
56 SFileDialogFilter = 'xTactics game system (.xts)|*.xts|All files|*.*';
57
58
59{ TFormGameSystem }
60
61procedure TFormGameSystem.ButtonLoadClick(Sender: TObject);
62begin
63 OpenDialog1.Filter := SFileDialogFilter;
64 OpenDialog1.InitialDir := ExtractFileDir(GameSystem.FileName);
65 OpenDialog1.FileName := ExtractFileName(GameSystem.FileName);
66 if OpenDialog1.Execute then begin
67 GameSystem.LoadFromFile(OpenDialog1.FileName);
68 LoadData(GameSystem);
69 end;
70end;
71
72procedure TFormGameSystem.ButtonSaveClick(Sender: TObject);
73begin
74 SaveDialog1.Filter := SFileDialogFilter;
75 SaveDialog1.InitialDir := ExtractFileDir(GameSystem.FileName);
76 SaveDialog1.FileName := ExtractFileName(GameSystem.FileName);
77 SaveDialog1.DefaultExt := GameSystemExt;
78 if SaveDialog1.Execute then begin
79 GameSystem.SaveToFile(SaveDialog1.FileName);
80 end;
81end;
82
83procedure TFormGameSystem.FormCreate(Sender: TObject);
84begin
85 FormUnitKinds := TFormList.Create(nil);
86 FormUnitKinds.ManualDock(TabSheetUnits, nil, alClient);
87 FormUnitKinds.Align := alClient;
88 FormUnitKinds.Visible := True;
89 FormNations := TFormList.Create(nil);
90 FormNations.ManualDock(TabSheetNations, nil, alClient);
91 FormNations.Align := alClient;
92 FormNations.Visible := True;
93 FormBuildingKinds := TFormList.Create(nil);
94 FormBuildingKinds.ManualDock(TabSheetBuildings, nil, alClient);
95 FormBuildingKinds.Align := alClient;
96 FormBuildingKinds.Visible := True;
97 Translate;
98end;
99
100procedure TFormGameSystem.FormDestroy(Sender: TObject);
101begin
102 GameSystem := nil;
103 FreeAndNil(FormNations);
104 FreeAndNil(FormUnitKinds);
105 FreeAndNil(FormBuildingKinds);
106end;
107
108procedure TFormGameSystem.SetGameSystem(AValue: TGameSystem);
109begin
110 if FGameSystem = AValue then Exit;
111 if Assigned(FGameSystem) then begin
112 FormUnitKinds.List := nil;
113 FormNations.List := nil;
114 FormBuildingKinds.List := nil;
115 end;
116 FGameSystem := AValue;
117 if Assigned(FGameSystem) then begin
118 FormUnitKinds.List := GameSystem.UnitKinds;
119 FormNations.List := GameSystem.Nations;
120 FormBuildingKinds.List := GameSystem.BuildingKinds;
121 end;
122end;
123
124procedure TFormGameSystem.Translate;
125var
126 LastIndex: Integer;
127begin
128 with ComboBoxPreferredGridType do begin
129 LastIndex := ItemIndex;
130 Clear;
131 Items.AddObject(SGridTypeNone, TObject(mtNone));
132 Items.AddObject(SGridTypeHexagonVertical, TObject(mtHexagonVertical));
133 Items.AddObject(SGridTypeHexagonHorizontal, TObject(mtHexagonHorizontal));
134 Items.AddObject(SGridTypeSquare, TObject(mtSquare));
135 Items.AddObject(SGridTypeTriangle, TObject(mtTriangle));
136 Items.AddObject(SGridTypeRandom, TObject(mtRandom));
137 Items.AddObject(SGridTypeIsometric, TObject(mtIsometric));
138 ItemIndex := LastIndex;
139 end;
140end;
141
142procedure TFormGameSystem.LoadData(GameSystem: TGameSystem);
143begin
144 Self.GameSystem := GameSystem;
145 CheckBoxEmptyCellsNeutral.Checked := GameSystem.EmptyCellsNeutral;
146 CheckBoxUnitsSplitMerge.Checked := GameSystem.UnitsSplitMerge;
147 CheckBoxUnitsMoveImmediately.Checked := GameSystem.UnitsMoveImmediately;
148 ComboBoxPreferredGridType.ItemIndex := Integer(GameSystem.PreferedMapType);
149 FormNations.UpdateList;
150 FormNations.UpdateInterface;
151 FormUnitKinds.UpdateList;
152 FormUnitKinds.UpdateInterface;
153 FormBuildingKinds.UpdateList;
154 FormBuildingKinds.UpdateInterface;
155 Caption := ExtractFileName(Self.GameSystem.FileName) + ' - ' + SGameSystem;
156end;
157
158procedure TFormGameSystem.SaveData(GameSystem: TGameSystem);
159begin
160 GameSystem.EmptyCellsNeutral := CheckBoxEmptyCellsNeutral.Checked;
161 GameSystem.UnitsSplitMerge := CheckBoxUnitsSplitMerge.Checked;
162 GameSystem.UnitsMoveImmediately := CheckBoxUnitsMoveImmediately.Checked;
163 GameSystem.PreferedMapType := TMapType(ComboBoxPreferredGridType.ItemIndex);
164end;
165
166end.
167
Note: See TracBrowser for help on using the repository browser.