source: OniTrainer/current/Unit10.pas@ 1080

Last change on this file since 1080 was 251, checked in by alloc, 17 years ago
File size: 13.0 KB
Line 
1UNIT Unit10;
2
3INTERFACE
4
5USES
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, Math;
8
9TYPE
10 TForm10 = Class(TForm)
11 label_key: TLabel;
12 label_group: TLabel;
13 combo_group: TComboBox;
14 label_target_char: TLabel;
15 check_charid: TRadioButton;
16 check_charname: TRadioButton;
17 edit_char: TEdit;
18 label_option: TLabel;
19 combo_option: TComboBox;
20 label_action: TLabel;
21 combo_action: TComboBox;
22 label_value: TLabel;
23 label_value2: TLabel;
24 edit_value: TEdit;
25 edit_value2: TEdit;
26 button_add: TButton;
27 button_cancel: TButton;
28 Check_Ctrl: TCheckBox;
29 Check_Alt: TCheckBox;
30 combo_keys: TComboBox;
31 procedure button_addClick(Sender: TObject);
32 procedure check_charnameClick(Sender: TObject);
33 PROCEDURE check_charidClick(Sender: TObject);
34 PROCEDURE button_cancelClick(Sender: TObject);
35 PROCEDURE combo_actionChange(Sender: TObject);
36 PROCEDURE combo_optionChange(Sender: TObject);
37 PROCEDURE combo_groupChange(Sender: TObject);
38 PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
39 PROCEDURE InitStuff(LoadHotKey:Byte);
40 PRIVATE
41 PUBLIC
42 END;
43
44VAR
45 Form10: TForm10;
46
47IMPLEMENTATION
48
49USES Unit1,Unit2,Unit3,Unit8,Unit9;
50
51{$R *.dfm}
52
53VAR change:Byte;
54
55PROCEDURE TForm10.InitStuff(LoadHotKey:Byte);
56 VAR i:Byte;
57 BEGIN
58 IF LoadHotKey=0 THEN BEGIN
59 change:=0;
60 Form10.Check_Ctrl.Checked:=False;
61 Form10.Check_Alt.Checked:=False;
62 Form10.combo_keys.Items.Clear;
63 FOR i:=1 TO Length(VKKeys) DO Form10.combo_keys.Items.Add(VKKeys[i].Name);
64 Form10.combo_keys.ItemIndex:=0;
65 Form10.combo_group.Items.Clear;
66 FOR i:=1 TO Length(HK_Target_Types) DO Form10.combo_group.Items.Add(HK_Target_Types[i]);
67 Form10.combo_group.ItemIndex:=0;
68 Form10.combo_groupChange(Self);
69 Form10.combo_option.ItemIndex:=0;
70 Form10.combo_optionChange(Self);
71 Form10.combo_action.ItemIndex:=0;
72 Form10.check_charid.Checked:=True;
73 Form10.label_target_char.Caption:='Target char ID:';
74 Form10.edit_char.Text:='';
75 Form10.edit_value.Text:='0';
76 Form10.edit_value2.Text:='0';
77 END ELSE BEGIN
78 change:=LoadHotKey;
79 WITH Hotkeys.Items[LoadHotKey-1] DO BEGIN
80 Form10.Check_Ctrl.Checked:=MOD_Ctrl;
81 Form10.Check_Alt.Checked:=MOD_Alt;
82 Form10.combo_keys.Items.Clear;
83 FOR i:=1 TO Length(VKKeys) DO Form10.combo_keys.Items.Add(VKKeys[i].Name);
84 Form10.combo_keys.ItemIndex:=key-1;
85 Form10.combo_group.Items.Clear;
86 FOR i:=1 TO Length(HK_Target_Types) DO Form10.combo_group.Items.Add(HK_Target_Types[i]);
87 Form10.combo_group.ItemIndex:=Target_Type-1;
88 Form10.combo_groupChange(Self);
89 Form10.combo_option.ItemIndex:=Target_Item-1;
90 Form10.combo_optionChange(Self);
91 FOR i:=0 TO Form10.combo_action.Items.Count-1 DO BEGIN
92 IF HK_Actions[Action]=Form10.combo_action.Items.Strings[i] THEN BEGIN
93 Form10.combo_action.ItemIndex:=i;
94 break;
95 END;
96 END;
97 IF Target_CharName='' THEN BEGIN
98 Form10.check_charid.Checked:=True;
99 Form10.label_target_char.Caption:='Target char ID:';
100 Form10.edit_char.Text:=IntToStr(Target_CharID);
101 END ELSE BEGIN
102 Form10.check_charname.Checked:=True;
103 Form10.label_target_char.Caption:='Target char name:';
104 Form10.edit_char.Text:=Target_CharName;
105 END;
106 Form10.edit_value.Text:=FloatToStr(Value);
107 Form10.edit_value2.Text:=FloatToStr(Value2);
108 END;
109 END;
110 END;
111
112PROCEDURE TForm10.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
113 BEGIN
114 Form9.Enabled:=True;
115 Form10.Visible:=False;
116 CanClose:=False;
117 END;
118
119PROCEDURE TForm10.combo_groupChange(Sender: TObject);
120 VAR i:Byte;
121 BEGIN
122 Form10.combo_option.Items.Clear;
123 IF Pos('Global',Form10.combo_group.Items.Strings[Form10.combo_group.ItemIndex])>0 THEN BEGIN
124 Form10.check_charid.Enabled:=False;
125 Form10.check_charname.Enabled:=False;
126 Form10.edit_char.Enabled:=False;
127 Form10.label_target_char.Enabled:=False;
128 FOR i:=1 TO Length(Settings) DO BEGIN
129 IF Settings[i].has_box THEN
130 Form10.combo_option.Items.Add(Settings[i].Item_Checkbox.Caption)
131 ELSE Form10.combo_option.Items.Add(Settings[i].Item_Label.Caption);
132 END;
133 END;
134 IF Pos('Char',Form10.combo_group.Items.Strings[Form10.combo_group.ItemIndex])>0 THEN BEGIN
135 Form10.check_charid.Enabled:=True;
136 Form10.check_charname.Enabled:=True;
137 Form10.edit_char.Enabled:=True;
138 Form10.label_target_char.Enabled:=True;
139 FOR i:=1 TO Length(CharDataStuff) DO BEGIN
140 Form10.combo_option.Items.Add(CharDataStuff[i].overview_name);
141 END;
142 END;
143 Form10.combo_option.ItemIndex:=0;
144 Form10.combo_optionChange(Self);
145 END;
146
147PROCEDURE TForm10.combo_optionChange(Sender: TObject);
148 BEGIN
149 Form10.button_add.Enabled:=True;
150 Form10.combo_action.Items.Clear;
151 IF Pos('Global',Form10.combo_group.Items.Strings[Form10.combo_group.ItemIndex])>0 THEN BEGIN
152 IF Settings[Form10.combo_option.ItemIndex+1].has_box THEN BEGIN
153 Form10.combo_action.Items.Add('Toggle');
154 END;
155 IF Settings[Form10.combo_option.ItemIndex+1].has_edit THEN BEGIN
156 Form10.combo_action.Items.Add('Set');
157 Form10.combo_action.Items.Add('Add');
158 Form10.combo_action.Items.Add('Multiply');
159 Form10.combo_action.Items.Add('Switch value');
160 END;
161 END;
162 IF Pos('Char',Form10.combo_group.Items.Strings[Form10.combo_group.ItemIndex])>0 THEN BEGIN
163 IF CharDataStuff[Form10.combo_option.ItemIndex+1].data_type=6 THEN BEGIN
164 Form10.combo_action.Items.Add('CAN''T CHANGE');
165 Form10.button_add.Enabled:=False;
166 END ELSE BEGIN
167 Form10.combo_action.Items.Add('Set');
168 Form10.combo_action.Items.Add('Add');
169 Form10.combo_action.Items.Add('Multiply');
170 Form10.combo_action.Items.Add('Freeze');
171 Form10.combo_action.Items.Add('Set & Freeze');
172 Form10.combo_action.Items.Add('Switch value');
173 END;
174 END;
175 Form10.combo_action.ItemIndex:=0;
176 Form10.combo_actionChange(Self);
177 END;
178
179PROCEDURE TForm10.combo_actionChange(Sender: TObject);
180 BEGIN
181 IF ('Toggle'=Form10.combo_action.Items.Strings[Form10.combo_action.ItemIndex]) OR ('Freeze'=Form10.combo_action.Items.Strings[Form10.combo_action.ItemIndex]) THEN BEGIN
182 Form10.label_value.Enabled:=False;
183 Form10.label_value2.Enabled:=False;
184 Form10.edit_value.Enabled:=False;
185 Form10.edit_value2.Enabled:=False;
186 END ELSE BEGIN
187 Form10.label_value.Enabled:=True;
188 Form10.edit_value.Enabled:=True;
189 IF Pos('Switch',Form10.combo_action.Items.Strings[Form10.combo_action.ItemIndex])>0 THEN BEGIN
190 Form10.label_value2.Enabled:=True;
191 Form10.edit_value2.Enabled:=True;
192 END ELSE BEGIN
193 Form10.label_value2.Enabled:=False;
194 Form10.edit_value2.Enabled:=False;
195 END;
196 END;
197 END;
198
199PROCEDURE TForm10.button_cancelClick(Sender: TObject);
200 BEGIN
201 Form9.Enabled:=True;
202 Form10.Visible:=False;
203 END;
204
205PROCEDURE TForm10.check_charidClick(Sender: TObject);
206 BEGIN
207 IF Form10.check_charid.Checked THEN
208 Form10.label_target_char.Caption:='Target char ID:'
209 ELSE
210 Form10.label_target_char.Caption:='Target char name:';
211 END;
212
213PROCEDURE TForm10.check_charnameClick(Sender: TObject);
214 BEGIN
215 IF Form10.check_charid.Checked THEN
216 Form10.label_target_char.Caption:='Target char ID:'
217 ELSE
218 Form10.label_target_char.Caption:='Target char name:';
219 END;
220
221PROCEDURE TForm10.button_addClick(Sender: TObject);
222 VAR i:Byte;
223 dataset:HotKey;
224 _temp:String;
225 _tempint:Integer;
226 _tempfloat:Double;
227 number:Word;
228 _wanted_datatype:Byte;
229 _check_value2:Boolean;
230 BEGIN
231 //check_valid_data:
232 dataset.Target_Type:=Form10.combo_group.ItemIndex+1;
233 dataset.Target_Item:=Form10.combo_option.ItemIndex+1;
234 FOR i:=1 TO Length(HK_Actions) DO BEGIN
235 IF HK_Actions[i]=Form10.combo_action.Items.Strings[Form10.combo_action.ItemIndex] THEN BEGIN
236 dataset.Action:=i;
237 break;
238 END;
239 END;
240 IF Pos('Char',HK_Target_Types[dataset.Target_Type])>0 THEN BEGIN
241 IF Form10.check_charid.Checked THEN BEGIN
242 IF TryStrToInt(Form10.edit_char.Text,_tempint)=False THEN BEGIN
243 MessageBox(Form10.Handle,PChar('Invalid character ID!'),PChar('Error'),MB_OK);
244 exit;
245 END;
246 IF (_tempint<0) OR (_tempint>100) THEN BEGIN
247 MessageBox(Form10.Handle,PChar('Invalid character ID!'),PChar('Error'),MB_OK);
248 exit;
249 END;
250 dataset.Target_CharID:=_tempint;
251 END ELSE BEGIN
252 IF (Length(Form10.edit_char.Text)<1) OR (Length(Form10.edit_char.Text)>20) THEN BEGIN
253 MessageBox(Form10.Handle,PChar('Invalid character name!'),PChar('Error'),MB_OK);
254 exit;
255 END;
256 dataset.Target_CharName:=Form10.edit_char.Text;
257 END;
258 END;
259 IF (Pos('Toggle',HK_Actions[dataset.Action])=0) AND (Pos('Freeze value',HK_Actions[dataset.Action])=0) THEN BEGIN
260 IF Pos('Global',HK_Target_Types[dataset.Target_Type])>0 THEN BEGIN
261 _wanted_datatype:=Settings[Form10.combo_option.ItemIndex+1].edit_type;
262 END;
263 IF Pos('Char',HK_Target_Types[dataset.Target_Type])>0 THEN BEGIN
264 _wanted_datatype:=CharDataStuff[Form10.combo_option.ItemIndex+1].data_type;
265 END;
266 IF Pos('Switch',HK_Actions[dataset.Action])>0 THEN BEGIN
267 _check_value2:=True;
268 END ELSE _check_value2:=False;
269 CASE _wanted_datatype OF
270 1..4: BEGIN
271 IF TryStrToInt(Form10.edit_value.Text,_tempint) THEN BEGIN
272 dataset.Value:=_tempint;
273 END ELSE BEGIN
274 MessageBox(Form10.Handle,PChar('Invalid value (has to be integer)!'),PChar('Error'),MB_OK);
275 exit;
276 END;
277 IF _check_value2 THEN BEGIN
278 IF TryStrToInt(Form10.edit_value2.Text,_tempint) THEN BEGIN
279 dataset.Value2:=_tempint;
280 END ELSE BEGIN
281 MessageBox(Form10.Handle,PChar('Invalid value2 (has to be integer)!'),PChar('Error'),MB_OK);
282 exit;
283 END;
284 END;
285 END;
286 5: BEGIN
287 IF TryStrToFloat(Form10.edit_value.Text,_tempfloat) THEN BEGIN
288 dataset.Value:=_tempfloat;
289 END ELSE BEGIN
290 MessageBox(Form10.Handle,PChar('Invalid value (has to be float)!'),PChar('Error'),MB_OK);
291 exit;
292 END;
293 IF _check_value2 THEN BEGIN
294 IF TryStrToFloat(Form10.edit_value2.Text,_tempfloat) THEN BEGIN
295 dataset.Value2:=_tempfloat;
296 END ELSE BEGIN
297 MessageBox(Form10.Handle,PChar('Invalid value2 (has to be float)!'),PChar('Error'),MB_OK);
298 exit;
299 END;
300 END;
301 END;
302 END;
303 END;
304 dataset.MOD_Alt:=Form10.Check_Alt.Checked;
305 dataset.MOD_Ctrl:=Form10.Check_Ctrl.Checked;
306 dataset.Key:=Form10.combo_keys.ItemIndex+1;
307
308 IF change=0 THEN BEGIN
309 //check_already_exist:
310 number:=65000;
311 IF Hotkeys.Size>0 THEN BEGIN
312 FOR i:=0 TO Hotkeys.Size-1 DO BEGIN
313 WITH Hotkeys.Items[i] DO BEGIN
314 IF (MOD_Alt=Form10.Check_Alt.Checked)
315 AND (MOD_Ctrl=Form10.Check_Ctrl.Checked)
316 AND (Key=Form10.combo_keys.ItemIndex+1) THEN BEGIN
317 _temp:='Do you really want to change the hotkey "';
318 IF MOD_Alt THEN _temp:=_temp+'ALT+';
319 IF MOD_Ctrl THEN _temp:=_temp+'CTRL+';
320 _temp:=_temp+VKKeys[Key].Name+'"?';
321 IF MessageBox(Form10.Handle,PChar(_temp),PChar('Really?'),MB_OKCANCEL)=IDCANCEL THEN BEGIN
322 exit;
323 END;
324 number:=i;
325 break;
326 END;
327 END;
328 END;
329 END;
330 //add/change_item:
331 IF number<65000 THEN BEGIN
332 Hotkeys.Items[number]:=dataset;
333 END ELSE BEGIN
334 Hotkeys.Size:=Hotkeys.Size+1;
335 HotKeys.Items[HotKeys.Size-1]:=dataset;
336 END;
337 //change_item:
338 END ELSE BEGIN
339 WITH HotKeys.Items[change-1] DO BEGIN
340 _temp:='Do you really want to change the hotkey "';
341 IF MOD_Alt THEN _temp:=_temp+'ALT+';
342 IF MOD_Ctrl THEN _temp:=_temp+'CTRL+';
343 _temp:=_temp+VKKeys[Key].Name+'"?';
344 IF MessageBox(Form10.Handle,PChar(_temp),PChar('Really?'),MB_OKCANCEL)=IDCANCEL THEN BEGIN
345 exit;
346 END;
347 END;
348 HotKeys.Items[change-1]:=dataset;
349 END;
350 Form10.Visible:=False;
351 Form9.Enabled:=True;
352 Form9.DrawTable;
353 END;
354
355END.
Note: See TracBrowser for help on using the repository browser.