1 | unit FormGameSystems;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
7 | ActnList, Menus, GameSystem, FormEx;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormGameSystems }
|
---|
12 |
|
---|
13 | TFormGameSystems = class(TFormEx)
|
---|
14 | AAdd: TAction;
|
---|
15 | ASelectAll: TAction;
|
---|
16 | AModify: TAction;
|
---|
17 | ARemove: TAction;
|
---|
18 | AClone: TAction;
|
---|
19 | ActionList1: TActionList;
|
---|
20 | ListView1: TListView;
|
---|
21 | MenuItem1: TMenuItem;
|
---|
22 | MenuItem2: TMenuItem;
|
---|
23 | MenuItem3: TMenuItem;
|
---|
24 | MenuItem4: TMenuItem;
|
---|
25 | MenuItem5: TMenuItem;
|
---|
26 | PopupMenu1: TPopupMenu;
|
---|
27 | ToolBar1: TToolBar;
|
---|
28 | ToolButton1: TToolButton;
|
---|
29 | ToolButton2: TToolButton;
|
---|
30 | ToolButton3: TToolButton;
|
---|
31 | ToolButton4: TToolButton;
|
---|
32 | procedure AAddExecute(Sender: TObject);
|
---|
33 | procedure AModifyExecute(Sender: TObject);
|
---|
34 | procedure ARemoveExecute(Sender: TObject);
|
---|
35 | procedure ASelectAllExecute(Sender: TObject);
|
---|
36 | procedure FormCreate(Sender: TObject);
|
---|
37 | procedure FormDestroy(Sender: TObject);
|
---|
38 | procedure FormShow(Sender: TObject);
|
---|
39 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
40 | procedure ListView1KeyPress(Sender: TObject; var Key: char);
|
---|
41 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
42 | Selected: Boolean);
|
---|
43 | private
|
---|
44 | FGameSystems: TGameSystems;
|
---|
45 | procedure SetGameSystems(AValue: TGameSystems);
|
---|
46 | public
|
---|
47 | procedure UpdateInterface;
|
---|
48 | procedure UpdateList;
|
---|
49 | property GameSystems: TGameSystems read FGameSystems write SetGameSystems;
|
---|
50 | end;
|
---|
51 |
|
---|
52 |
|
---|
53 | implementation
|
---|
54 |
|
---|
55 | {$R *.lfm}
|
---|
56 |
|
---|
57 | uses
|
---|
58 | FormGameSystem;
|
---|
59 |
|
---|
60 | resourcestring
|
---|
61 | SRemoveItems = 'Remove items';
|
---|
62 | SRemoveItemsQuery = 'Do you want to remove selected items?';
|
---|
63 | SNewGameSystem = 'New game system';
|
---|
64 |
|
---|
65 | { TFormGameSystems }
|
---|
66 |
|
---|
67 | procedure TFormGameSystems.ARemoveExecute(Sender: TObject);
|
---|
68 | var
|
---|
69 | I: Integer;
|
---|
70 | begin
|
---|
71 | if Assigned(ListView1.Selected) then begin
|
---|
72 | if MessageDlg(SRemoveItems, SRemoveItemsQuery,
|
---|
73 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
74 | for I := ListView1.Items.Count - 1 downto 0 do
|
---|
75 | if ListView1.Items[I].Selected then begin
|
---|
76 | ListView1.Items[I].Selected := False;
|
---|
77 | GameSystems.Remove(TGameSystem(ListView1.Items[I].Data));
|
---|
78 | end;
|
---|
79 | UpdateList;
|
---|
80 | UpdateInterface;
|
---|
81 | end;
|
---|
82 | end;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | procedure TFormGameSystems.AModifyExecute(Sender: TObject);
|
---|
86 | var
|
---|
87 | TempEntry: TGameSystem;
|
---|
88 | FormGameSystem: TFormGameSystem;
|
---|
89 | begin
|
---|
90 | if Assigned(ListView1.Selected) then
|
---|
91 | with TGameSystem(ListView1.Selected.Data) do begin
|
---|
92 | TempEntry := TGameSystem.Create;
|
---|
93 | TempEntry.Assign(TGameSystem(ListView1.Selected.Data));
|
---|
94 | FormGameSystem := TFormGameSystem.Create(Self);
|
---|
95 | try
|
---|
96 | FormGameSystem.LoadData(TempEntry);
|
---|
97 | if FormGameSystem.ShowModal = mrOk then begin
|
---|
98 | FormGameSystem.SaveData(TempEntry);
|
---|
99 | TGameSystem(ListView1.Selected.Data).Assign(TempEntry);
|
---|
100 | UpdateList;
|
---|
101 | UpdateInterface;
|
---|
102 | end;
|
---|
103 | finally
|
---|
104 | FreeAndNil(FormGameSystem);
|
---|
105 | FreeAndNil(TempEntry);
|
---|
106 | end;
|
---|
107 | end;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | procedure TFormGameSystems.AAddExecute(Sender: TObject);
|
---|
111 | var
|
---|
112 | TempEntry: TGameSystem;
|
---|
113 | FormGameSystem: TFormGameSystem;
|
---|
114 | begin
|
---|
115 | TempEntry := TGameSystem.Create;
|
---|
116 | FormGameSystem := TFormGameSystem.Create(Self);
|
---|
117 | try
|
---|
118 | TempEntry.FileName := SNewGameSystem + GameSystemExt;
|
---|
119 | FormGameSystem.LoadData(TempEntry);
|
---|
120 | if FormGameSystem.ShowModal = mrOk then begin
|
---|
121 | FormGameSystem.SaveData(TempEntry);
|
---|
122 | GameSystems.Add(TempEntry);
|
---|
123 | TempEntry := nil;
|
---|
124 | UpdateList;
|
---|
125 | UpdateInterface;
|
---|
126 | end;
|
---|
127 | finally
|
---|
128 | FreeAndNil(FormGameSystem);
|
---|
129 | FreeAndNil(TempEntry);
|
---|
130 | end;
|
---|
131 | end;
|
---|
132 |
|
---|
133 | procedure TFormGameSystems.ASelectAllExecute(Sender: TObject);
|
---|
134 | var
|
---|
135 | I: Integer;
|
---|
136 | begin
|
---|
137 | for I := 0 to ListView1.Items.Count - 1 do
|
---|
138 | ListView1.Items[I].Selected := True;
|
---|
139 | end;
|
---|
140 |
|
---|
141 | procedure TFormGameSystems.FormCreate(Sender: TObject);
|
---|
142 | var
|
---|
143 | I: Integer;
|
---|
144 | begin
|
---|
145 | for I := 0 to ToolBar1.ButtonCount - 1 do
|
---|
146 | ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure TFormGameSystems.FormDestroy(Sender: TObject);
|
---|
150 | begin
|
---|
151 | GameSystems := nil;
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TFormGameSystems.FormShow(Sender: TObject);
|
---|
155 | begin
|
---|
156 | UpdateList;
|
---|
157 | UpdateInterface;
|
---|
158 | end;
|
---|
159 |
|
---|
160 | procedure TFormGameSystems.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
161 | begin
|
---|
162 | if Item.Index < ListView1.Items.Count then
|
---|
163 | with TGameSystem(GameSystems[Item.Index]) do begin
|
---|
164 | Item.Caption := GetName;
|
---|
165 | Item.Data := GameSystems[Item.Index];
|
---|
166 | end;
|
---|
167 | end;
|
---|
168 |
|
---|
169 | procedure TFormGameSystems.ListView1KeyPress(Sender: TObject; var Key: char);
|
---|
170 | begin
|
---|
171 | if Key = #13 then AModify.Execute;
|
---|
172 | if Key = #27 then Close;
|
---|
173 | end;
|
---|
174 |
|
---|
175 | procedure TFormGameSystems.ListView1SelectItem(Sender: TObject;
|
---|
176 | Item: TListItem; Selected: Boolean);
|
---|
177 | begin
|
---|
178 | UpdateInterface;
|
---|
179 | end;
|
---|
180 |
|
---|
181 | procedure TFormGameSystems.SetGameSystems(AValue: TGameSystems);
|
---|
182 | begin
|
---|
183 | if FGameSystems = AValue then Exit;
|
---|
184 | FGameSystems := AValue;
|
---|
185 | end;
|
---|
186 |
|
---|
187 | procedure TFormGameSystems.UpdateInterface;
|
---|
188 | begin
|
---|
189 | ARemove.Enabled := Assigned(FGameSystems) and Assigned(ListView1.Selected);
|
---|
190 | AModify.Enabled := Assigned(FGameSystems) and Assigned(ListView1.Selected);
|
---|
191 | AAdd.Enabled := Assigned(FGameSystems);
|
---|
192 | ASelectAll.Enabled := ListView1.Items.Count > 0;
|
---|
193 | end;
|
---|
194 |
|
---|
195 | procedure TFormGameSystems.UpdateList;
|
---|
196 | begin
|
---|
197 | if Assigned(GameSystems) then ListView1.Items.Count := GameSystems.Count
|
---|
198 | else ListView1.Items.Count := 0;
|
---|
199 | ListView1.Refresh;
|
---|
200 | end;
|
---|
201 |
|
---|
202 | end.
|
---|
203 |
|
---|