source: trunk/Forms/FormGameSystems.pas

Last change on this file was 318, checked in by chronos, 6 months ago
  • Modified: Code cleanup.
File size: 5.2 KB
Line 
1unit FormGameSystems;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
7 ActnList, Menus, GameSystem, FormEx;
8
9type
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
53implementation
54
55{$R *.lfm}
56
57uses
58 FormGameSystem;
59
60resourcestring
61 SRemoveItems = 'Remove items';
62 SRemoveItemsQuery = 'Do you want to remove selected items?';
63 SNewGameSystem = 'New game system';
64
65{ TFormGameSystems }
66
67procedure TFormGameSystems.ARemoveExecute(Sender: TObject);
68var
69 I: Integer;
70begin
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;
83end;
84
85procedure TFormGameSystems.AModifyExecute(Sender: TObject);
86var
87 TempEntry: TGameSystem;
88 FormGameSystem: TFormGameSystem;
89begin
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;
108end;
109
110procedure TFormGameSystems.AAddExecute(Sender: TObject);
111var
112 TempEntry: TGameSystem;
113 FormGameSystem: TFormGameSystem;
114begin
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;
131end;
132
133procedure TFormGameSystems.ASelectAllExecute(Sender: TObject);
134var
135 I: Integer;
136begin
137 for I := 0 to ListView1.Items.Count - 1 do
138 ListView1.Items[I].Selected := True;
139end;
140
141procedure TFormGameSystems.FormCreate(Sender: TObject);
142var
143 I: Integer;
144begin
145 for I := 0 to ToolBar1.ButtonCount - 1 do
146 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
147end;
148
149procedure TFormGameSystems.FormDestroy(Sender: TObject);
150begin
151 GameSystems := nil;
152end;
153
154procedure TFormGameSystems.FormShow(Sender: TObject);
155begin
156 UpdateList;
157 UpdateInterface;
158end;
159
160procedure TFormGameSystems.ListView1Data(Sender: TObject; Item: TListItem);
161begin
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;
167end;
168
169procedure TFormGameSystems.ListView1KeyPress(Sender: TObject; var Key: char);
170begin
171 if Key = #13 then AModify.Execute;
172 if Key = #27 then Close;
173end;
174
175procedure TFormGameSystems.ListView1SelectItem(Sender: TObject;
176 Item: TListItem; Selected: Boolean);
177begin
178 UpdateInterface;
179end;
180
181procedure TFormGameSystems.SetGameSystems(AValue: TGameSystems);
182begin
183 if FGameSystems = AValue then Exit;
184 FGameSystems := AValue;
185end;
186
187procedure TFormGameSystems.UpdateInterface;
188begin
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;
193end;
194
195procedure TFormGameSystems.UpdateList;
196begin
197 if Assigned(GameSystems) then ListView1.Items.Count := GameSystems.Count
198 else ListView1.Items.Count := 0;
199 ListView1.Refresh;
200end;
201
202end.
203
Note: See TracBrowser for help on using the repository browser.