1 | unit FormGameSystem;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
7 | ComCtrls, GameSystem, FormList, FormEx;
|
---|
8 |
|
---|
9 | type
|
---|
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 |
|
---|
48 | implementation
|
---|
49 |
|
---|
50 | {$R *.lfm}
|
---|
51 |
|
---|
52 | uses
|
---|
53 | MapType;
|
---|
54 |
|
---|
55 | resourcestring
|
---|
56 | SFileDialogFilter = 'xTactics game system (.xts)|*.xts|All files|*.*';
|
---|
57 |
|
---|
58 |
|
---|
59 | { TFormGameSystem }
|
---|
60 |
|
---|
61 | procedure TFormGameSystem.ButtonLoadClick(Sender: TObject);
|
---|
62 | begin
|
---|
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;
|
---|
70 | end;
|
---|
71 |
|
---|
72 | procedure TFormGameSystem.ButtonSaveClick(Sender: TObject);
|
---|
73 | begin
|
---|
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;
|
---|
81 | end;
|
---|
82 |
|
---|
83 | procedure TFormGameSystem.FormCreate(Sender: TObject);
|
---|
84 | begin
|
---|
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;
|
---|
98 | end;
|
---|
99 |
|
---|
100 | procedure TFormGameSystem.FormDestroy(Sender: TObject);
|
---|
101 | begin
|
---|
102 | GameSystem := nil;
|
---|
103 | FreeAndNil(FormNations);
|
---|
104 | FreeAndNil(FormUnitKinds);
|
---|
105 | FreeAndNil(FormBuildingKinds);
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TFormGameSystem.SetGameSystem(AValue: TGameSystem);
|
---|
109 | begin
|
---|
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;
|
---|
122 | end;
|
---|
123 |
|
---|
124 | procedure TFormGameSystem.Translate;
|
---|
125 | var
|
---|
126 | LastIndex: Integer;
|
---|
127 | begin
|
---|
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;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | procedure TFormGameSystem.LoadData(GameSystem: TGameSystem);
|
---|
143 | begin
|
---|
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;
|
---|
156 | end;
|
---|
157 |
|
---|
158 | procedure TFormGameSystem.SaveData(GameSystem: TGameSystem);
|
---|
159 | begin
|
---|
160 | GameSystem.EmptyCellsNeutral := CheckBoxEmptyCellsNeutral.Checked;
|
---|
161 | GameSystem.UnitsSplitMerge := CheckBoxUnitsSplitMerge.Checked;
|
---|
162 | GameSystem.UnitsMoveImmediately := CheckBoxUnitsMoveImmediately.Checked;
|
---|
163 | GameSystem.PreferedMapType := TMapType(ComboBoxPreferredGridType.ItemIndex);
|
---|
164 | end;
|
---|
165 |
|
---|
166 | end.
|
---|
167 |
|
---|