| 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 | ScrollBoxGeneral: TScrollBox;
|
|---|
| 27 | TabSheetBuildings: TTabSheet;
|
|---|
| 28 | TabSheetNations: TTabSheet;
|
|---|
| 29 | TabSheetGeneral: TTabSheet;
|
|---|
| 30 | TabSheetUnits: TTabSheet;
|
|---|
| 31 | procedure ButtonLoadClick(Sender: TObject);
|
|---|
| 32 | procedure ButtonSaveClick(Sender: TObject);
|
|---|
| 33 | procedure FormCreate(Sender: TObject);
|
|---|
| 34 | procedure FormDestroy(Sender: TObject);
|
|---|
| 35 | private
|
|---|
| 36 | FGameSystem: TGameSystem;
|
|---|
| 37 | FormUnitKinds: TFormList;
|
|---|
| 38 | FormNations: TFormList;
|
|---|
| 39 | FormBuildingKinds: TFormList;
|
|---|
| 40 | procedure SetGameSystem(AValue: TGameSystem);
|
|---|
| 41 | procedure Translate;
|
|---|
| 42 | public
|
|---|
| 43 | property GameSystem: TGameSystem read FGameSystem write SetGameSystem;
|
|---|
| 44 | procedure LoadData(GameSystem: TGameSystem);
|
|---|
| 45 | procedure SaveData(GameSystem: TGameSystem);
|
|---|
| 46 | end;
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | implementation
|
|---|
| 50 |
|
|---|
| 51 | {$R *.lfm}
|
|---|
| 52 |
|
|---|
| 53 | uses
|
|---|
| 54 | MapType, ItemList, Core;
|
|---|
| 55 |
|
|---|
| 56 | resourcestring
|
|---|
| 57 | SFileDialogFilter = 'xTactics game system (.xts)|*.xts|All files|*.*';
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | { TFormGameSystem }
|
|---|
| 61 |
|
|---|
| 62 | procedure TFormGameSystem.ButtonLoadClick(Sender: TObject);
|
|---|
| 63 | begin
|
|---|
| 64 | OpenDialog1.Filter := SFileDialogFilter;
|
|---|
| 65 | OpenDialog1.InitialDir := ExtractFileDir(GameSystem.FileName);
|
|---|
| 66 | OpenDialog1.FileName := ExtractFileName(GameSystem.FileName);
|
|---|
| 67 | if OpenDialog1.Execute then begin
|
|---|
| 68 | GameSystem.LoadFromFile(OpenDialog1.FileName);
|
|---|
| 69 | LoadData(GameSystem);
|
|---|
| 70 | end;
|
|---|
| 71 | end;
|
|---|
| 72 |
|
|---|
| 73 | procedure TFormGameSystem.ButtonSaveClick(Sender: TObject);
|
|---|
| 74 | begin
|
|---|
| 75 | SaveDialog1.Filter := SFileDialogFilter;
|
|---|
| 76 | SaveDialog1.InitialDir := ExtractFileDir(GameSystem.FileName);
|
|---|
| 77 | SaveDialog1.FileName := ExtractFileName(GameSystem.FileName);
|
|---|
| 78 | SaveDialog1.DefaultExt := GameSystemExt;
|
|---|
| 79 | if SaveDialog1.Execute then begin
|
|---|
| 80 | GameSystem.SaveToFile(SaveDialog1.FileName);
|
|---|
| 81 | end;
|
|---|
| 82 | end;
|
|---|
| 83 |
|
|---|
| 84 | procedure TFormGameSystem.FormCreate(Sender: TObject);
|
|---|
| 85 | begin
|
|---|
| 86 | FormUnitKinds := TFormList.Create(nil);
|
|---|
| 87 | FormUnitKinds.ManualDock(TabSheetUnits, nil, alClient);
|
|---|
| 88 | FormUnitKinds.Align := alClient;
|
|---|
| 89 | FormUnitKinds.Visible := True;
|
|---|
| 90 | FormUnitKinds.Images := Core.Core.ImageListSmall;
|
|---|
| 91 | FormNations := TFormList.Create(nil);
|
|---|
| 92 | FormNations.ManualDock(TabSheetNations, nil, alClient);
|
|---|
| 93 | FormNations.Align := alClient;
|
|---|
| 94 | FormNations.Visible := True;
|
|---|
| 95 | FormNations.Images := Core.Core.ImageListSmall;
|
|---|
| 96 | FormBuildingKinds := TFormList.Create(nil);
|
|---|
| 97 | FormBuildingKinds.ManualDock(TabSheetBuildings, nil, alClient);
|
|---|
| 98 | FormBuildingKinds.Align := alClient;
|
|---|
| 99 | FormBuildingKinds.Visible := True;
|
|---|
| 100 | FormBuildingKinds.Images := Core.Core.ImageListSmall;
|
|---|
| 101 | Translate;
|
|---|
| 102 | end;
|
|---|
| 103 |
|
|---|
| 104 | procedure TFormGameSystem.FormDestroy(Sender: TObject);
|
|---|
| 105 | begin
|
|---|
| 106 | GameSystem := nil;
|
|---|
| 107 | FreeAndNil(FormNations);
|
|---|
| 108 | FreeAndNil(FormUnitKinds);
|
|---|
| 109 | FreeAndNil(FormBuildingKinds);
|
|---|
| 110 | end;
|
|---|
| 111 |
|
|---|
| 112 | procedure TFormGameSystem.SetGameSystem(AValue: TGameSystem);
|
|---|
| 113 | begin
|
|---|
| 114 | if FGameSystem = AValue then Exit;
|
|---|
| 115 | if Assigned(FGameSystem) then begin
|
|---|
| 116 | FormUnitKinds.List := nil;
|
|---|
| 117 | FormNations.List := nil;
|
|---|
| 118 | FormBuildingKinds.List := nil;
|
|---|
| 119 | end;
|
|---|
| 120 | FGameSystem := AValue;
|
|---|
| 121 | if Assigned(FGameSystem) then begin
|
|---|
| 122 | FormUnitKinds.List := GameSystem.UnitKinds.BaseItemList;
|
|---|
| 123 | FormNations.List := GameSystem.Nations.BaseItemList;
|
|---|
| 124 | FormBuildingKinds.List := GameSystem.BuildingKinds.BaseItemList;
|
|---|
| 125 | end;
|
|---|
| 126 | end;
|
|---|
| 127 |
|
|---|
| 128 | procedure TFormGameSystem.Translate;
|
|---|
| 129 | var
|
|---|
| 130 | LastIndex: Integer;
|
|---|
| 131 | begin
|
|---|
| 132 | with ComboBoxPreferredGridType do begin
|
|---|
| 133 | LastIndex := ItemIndex;
|
|---|
| 134 | Clear;
|
|---|
| 135 | Items.AddObject(SGridTypeNone, TObject(mtNone));
|
|---|
| 136 | Items.AddObject(SGridTypeHexagonVertical, TObject(mtHexagonVertical));
|
|---|
| 137 | Items.AddObject(SGridTypeHexagonHorizontal, TObject(mtHexagonHorizontal));
|
|---|
| 138 | Items.AddObject(SGridTypeSquare, TObject(mtSquare));
|
|---|
| 139 | Items.AddObject(SGridTypeTriangle, TObject(mtTriangle));
|
|---|
| 140 | Items.AddObject(SGridTypeRandom, TObject(mtRandom));
|
|---|
| 141 | Items.AddObject(SGridTypeIsometric, TObject(mtIsometric));
|
|---|
| 142 | ItemIndex := LastIndex;
|
|---|
| 143 | end;
|
|---|
| 144 | end;
|
|---|
| 145 |
|
|---|
| 146 | procedure TFormGameSystem.LoadData(GameSystem: TGameSystem);
|
|---|
| 147 | begin
|
|---|
| 148 | Self.GameSystem := GameSystem;
|
|---|
| 149 | CheckBoxEmptyCellsNeutral.Checked := GameSystem.EmptyCellsNeutral;
|
|---|
| 150 | CheckBoxUnitsSplitMerge.Checked := GameSystem.UnitsSplitMerge;
|
|---|
| 151 | CheckBoxUnitsMoveImmediately.Checked := GameSystem.UnitsMoveImmediately;
|
|---|
| 152 | ComboBoxPreferredGridType.ItemIndex := Integer(GameSystem.PreferedMapType);
|
|---|
| 153 | FormNations.UpdateList;
|
|---|
| 154 | FormNations.UpdateInterface;
|
|---|
| 155 | FormUnitKinds.UpdateList;
|
|---|
| 156 | FormUnitKinds.UpdateInterface;
|
|---|
| 157 | FormBuildingKinds.UpdateList;
|
|---|
| 158 | FormBuildingKinds.UpdateInterface;
|
|---|
| 159 | Caption := ExtractFileName(Self.GameSystem.FileName) + ' - ' + SGameSystem;
|
|---|
| 160 | end;
|
|---|
| 161 |
|
|---|
| 162 | procedure TFormGameSystem.SaveData(GameSystem: TGameSystem);
|
|---|
| 163 | begin
|
|---|
| 164 | GameSystem.EmptyCellsNeutral := CheckBoxEmptyCellsNeutral.Checked;
|
|---|
| 165 | GameSystem.UnitsSplitMerge := CheckBoxUnitsSplitMerge.Checked;
|
|---|
| 166 | GameSystem.UnitsMoveImmediately := CheckBoxUnitsMoveImmediately.Checked;
|
|---|
| 167 | GameSystem.PreferedMapType := TMapType(ComboBoxPreferredGridType.ItemIndex);
|
|---|
| 168 | end;
|
|---|
| 169 |
|
|---|
| 170 | end.
|
|---|
| 171 |
|
|---|