source: OniTrainer/current/Unit9.pas@ 1142

Last change on this file since 1142 was 251, checked in by alloc, 17 years ago
File size: 16.3 KB
RevLine 
[251]1UNIT Unit9;
2
3INTERFACE
4
5USES
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, Grids, Math, StrUtils;
8
9TYPE
10 TForm9 = Class(TForm)
11 HotKeysTable: TStringGrid;
12 PROCEDURE FormCreate(Sender: TObject);
13 PROCEDURE HotKeysTableKeyPress(Sender: TObject; var Key: Char);
14 PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
15 PROCEDURE HotKeysTableSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
16 PROCEDURE HotKeysTableDblClick(Sender: TObject);
17 PROCEDURE DrawTable;
18 PROCEDURE UnregisterHotkeys;
19 PRIVATE
20 PROCEDURE WMHotKey(VAR Msg : TWMHotKey); MESSAGE WM_HOTKEY;
21 PUBLIC
22 END;
23
24VAR
25 Form9: TForm9;
26
27IMPLEMENTATION
28
29USES Unit1, Unit2, Unit3, Unit8, Unit10;
30
31VAR
32 _sel_col:Byte;
33 _sel_row:Byte;
34
35{$R *.dfm}
36
37PROCEDURE TForm9.HotKeysTableDblClick(Sender: TObject);
38 BEGIN
39 Form10.Visible:=True;
40 Form9.Enabled:=False;
41 IF HotKeysTable.Cells[_sel_col,_sel_row]='' THEN Form10.InitStuff(0)
42 ELSE Form10.InitStuff(_sel_row);
43 END;
44
45PROCEDURE TForm9.HotKeysTableSelectCell(Sender: TObject; ACol, ARow: Integer; VAR CanSelect: Boolean);
46 BEGIN
47 _sel_col:=ACol;
48 _sel_row:=ARow;
49 CanSelect:=True;
50 END;
51
52PROCEDURE TForm9.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
53 BEGIN
54 Form9.Visible:=False;
55 CanClose:=False;
56 END;
57
58PROCEDURE TForm9.HotKeysTableKeyPress(Sender: TObject; var Key: Char);
59 VAR i:Byte;
60 _temp:String;
61 BEGIN
62 IF key=#13 THEN BEGIN
63 Form10.Visible:=True;
64 Form9.Enabled:=False;
65 IF HotKeysTable.Cells[_sel_col,_sel_row]='' THEN Form10.InitStuff(0)
66 ELSE Form10.InitStuff(_sel_row);
67 END;
68 IF key=#8 THEN BEGIN
69 IF NOT (Form9.HotKeysTable.Cells[0,_sel_row]='') THEN BEGIN
70 _temp:='Do you really want to remove the hotkey "';
71 IF Hotkeys.Items[_sel_row-1].MOD_Alt THEN _temp:=_temp+'ALT+';
72 IF Hotkeys.Items[_sel_row-1].MOD_Ctrl THEN _temp:=_temp+'CTRL+';
73 _temp:=_temp+VKKeys[Hotkeys.Items[_sel_row-1].Key].Name+'"?';
74 IF MessageBox(Form9.Handle,PChar(_temp),PChar('Really???'),MB_OKCANCEL)=IDOK THEN BEGIN
75 UnregisterHotkeys;
76 IF Hotkeys.Size>1 THEN BEGIN
77 FOR i:=_sel_row-1 TO Hotkeys.Size-2 DO BEGIN
78 Hotkeys.Items[i]:=Hotkeys.Items[i+1];
79 END;
80 Hotkeys.Size:=Hotkeys.Size-1;
81 END ELSE BEGIN
82 IF Hotkeys.Size=1 THEN BEGIN
83 Hotkeys.Size:=0;
84 END;
85 END;
86 Form9.DrawTable;
87 END;
88 END;
89 END;
90 END;
91
92PROCEDURE TForm9.DrawTable;
93 VAR i:Byte;
94 _temp:String;
95 modifiers:Integer;
96 BEGIN
97 Form9.HotKeysTable.Cells[0,0]:='Hotkey';
98 Form9.HotKeysTable.Cells[1,0]:='Target';
99 Form9.HotKeysTable.Cells[2,0]:='ActionType';
100 Form9.HotKeysTable.Cells[3,0]:='Value';
101 Form9.HotKeysTable.Cells[4,0]:='Value2';
102 Form9.HotKeysTable.RowCount:=Hotkeys.Size+2;
103 IF Hotkeys.Size>0 THEN BEGIN
104 FOR i:=0 TO Hotkeys.Size-1 DO BEGIN
105 WITH Hotkeys.Items[i] DO BEGIN
106 modifiers:=0;
107 IF MOD_Ctrl THEN modifiers:=modifiers+MOD_Ctrl_Key;
108 IF MOD_Alt THEN modifiers:=modifiers+MOD_Alt_Key;
109
110 RegisterHotkey(Form9.Handle,i,modifiers,VKKeys[key].Value);
111
112 _temp:='';
113 IF MOD_Ctrl THEN _temp:=_temp+'CTRL+';
114 IF MOD_Alt THEN _temp:=_temp+'ALT+';
115 Form9.HotKeysTable.Cells[0,i+1]:=_temp+VKKeys[Key].Name;
116 IF Pos('Char',HK_Target_Types[Target_Type])>0 THEN BEGIN
117 _temp:=HK_Target_Types[Target_Type];
118 IF NOT (Target_Charname='') THEN BEGIN
119 _temp:=_temp+' (Char "'+Target_Charname+'"): ';
120 END ELSE BEGIN
121 _temp:=_temp+' (Char'+IntToStr(Target_CharID)+'): ';
122 END;
123 _temp:=_temp+CharDataStuff[Target_Item].Name;
124 END;
125 IF Pos('Global',HK_Target_Types[Target_Type])>0 THEN BEGIN
126 _temp:=HK_Target_Types[Target_Type]+': ';
127 IF Settings[Target_Item].has_box THEN
128 _temp:=_temp+Settings[Target_Item].Item_Checkbox.Caption
129 ELSE _temp:=_temp+Settings[Target_Item].Item_Label.Caption;
130 END;
131 Form9.HotKeysTable.Cells[1,i+1]:=_temp;
132 Form9.HotKeysTable.Cells[2,i+1]:=HK_Actions[Action];
133 IF ('Toggle'=HK_Actions[Action]) OR ('Freeze'=HK_Actions[Action]) THEN BEGIN
134 Form9.HotKeysTable.Cells[3,i+1]:='';
135 END ELSE BEGIN
136 Form9.HotKeysTable.Cells[3,i+1]:=FloatToStr(Value);
137 IF 'Switch value'=HK_Actions[Action] THEN BEGIN
138 Form9.HotKeysTable.Cells[4,i+1]:=FloatToStr(Value2);
139 END ELSE BEGIN
140 Form9.HotKeysTable.Cells[4,i+1]:='';
141 END;
142 END;
143 END;
144 END;
145 END;
146 FOR i:=0 TO 3 DO Form9.HotKeysTable.Cells[i,Form9.HotKeysTable.RowCount-1]:='';
147 END;
148
149PROCEDURE TForm9.FormCreate(Sender: TObject);
150 BEGIN
151 Sleep(50);
152 AssignFile(HotKeysFile,_path+'\hotkeys.cfg');
153 Reset(HotKeysFile);
154 Read(HotKeysFile,HotKeys);
155 CloseFile(HotKeysFile);
156 _sel_row:=1;
157 _sel_col:=0;
158 Form9.DrawTable;
159 Form9.UnregisterHotkeys;
160 END;
161
162PROCEDURE TForm9.WMHotkey(var Msg : TWMHotKey);
163 VAR hk_id:Byte;
164 i,chid:Byte;
165 BEGIN
166 IF _connected THEN BEGIN
167 hk_id:=Msg.HotKey;
168 WITH Hotkeys.Items[hk_id] DO BEGIN
169 IF Pos('Global',HK_Target_Types[Target_Type])>0 THEN BEGIN
170 IF 'Toggle'=HK_Actions[Action] THEN BEGIN
171 Settings[Target_Item].Item_Checkbox.Checked:=NOT Settings[Target_Item].Item_Checkbox.Checked;
172 Form1.Debug_Click(Settings[Target_Item].Item_Checkbox);
173 IF Settings[Target_Item].Item_Checkbox.Checked THEN
174 SendMessageToOni('[b. "'+Settings[Target_Item].Item_Checkbox.Caption+'" activated.]')
175 ELSE
176 SendMessageToOni('[b. "'+Settings[Target_Item].Item_Checkbox.Caption+'" deactivated.]');
177 END;
178 IF 'Set'=HK_Actions[Action] THEN BEGIN
179 IF Settings[Target_Item].edit_type=5 THEN BEGIN
180 SendMessageToOni('[b. Set "'+Settings[Target_Item].Item_Checkbox.Caption+'" to '+FloatToStr(Value)+'.]');
181 Settings[Target_Item].Item_Edit.Text:=FloatToStr( Value );
182 END ELSE BEGIN
183 SendMessageToOni('[b. Set "'+Settings[Target_Item].Item_Checkbox.Caption+'" to '+IntToStr(Floor(Value))+'.]');
184 Settings[Target_Item].Item_Edit.Text:=IntToStr( Floor(Value) );
185 END;
186 END;
187 IF 'Add'=HK_Actions[Action] THEN BEGIN
188 IF Settings[Target_Item].edit_type=5 THEN BEGIN
189 SendMessageToOni('[b. Added '+FloatToStr(Value)+' to "'+Settings[Target_Item].Item_Checkbox.Caption+'" (now='+FloatToStr( StrToFloat(Settings[Target_Item].Item_Edit.Text) + Value )+').]');
190 Settings[Target_Item].Item_Edit.Text:=FloatToStr( StrToFloat(Settings[Target_Item].Item_Edit.Text) + Value );
191 END ELSE BEGIN
192 SendMessageToOni('[b. Added '+IntToStr(Floor(Value))+' to "'+Settings[Target_Item].Item_Checkbox.Caption+'" (now='+IntToStr( StrToInt(Settings[Target_Item].Item_Edit.Text) + Floor(Value) )+').]');
193 Settings[Target_Item].Item_Edit.Text:=IntToStr( StrToInt(Settings[Target_Item].Item_Edit.Text) + Floor(Value) );
194 END;
195 END;
196 IF 'Multiply'=HK_Actions[Action] THEN BEGIN
197 IF Settings[Target_Item].edit_type=5 THEN BEGIN
198 SendMessageToOni('[b. Multiplied "'+Settings[Target_Item].Item_Checkbox.Caption+'" with '+FloatToStr(Value)+' (now='+FloatToStr( StrToFloat(Settings[Target_Item].Item_Edit.Text) * Value )+').]');
199 Settings[Target_Item].Item_Edit.Text:=FloatToStr( StrToFloat(Settings[Target_Item].Item_Edit.Text) * Value );
200 END ELSE BEGIN
201 SendMessageToOni('[b. Multiplied "'+Settings[Target_Item].Item_Checkbox.Caption+'" with '+IntToStr(Floor(Value))+' (now='+IntToStr( StrToInt(Settings[Target_Item].Item_Edit.Text) * Floor(Value) )+').]');
202 Settings[Target_Item].Item_Edit.Text:=IntToStr( StrToInt(Settings[Target_Item].Item_Edit.Text) * Floor(Value) );
203 END;
204 END;
205 IF 'Switch value'=HK_Actions[Action] THEN BEGIN
206 IF Settings[Target_Item].edit_type=5 THEN BEGIN
207 IF StrToFloat(Settings[Target_Item].Item_Edit.Text)=Value THEN BEGIN
208 SendMessageToOni('[b. Switched "'+Settings[Target_Item].Item_Checkbox.Caption+'" to '+FloatToStr(Value2)+'.]');
209 Settings[Target_Item].Item_Edit.Text:=FloatToStr( Value2 );
210 END ELSE BEGIN
211 SendMessageToOni('[b. Switched "'+Settings[Target_Item].Item_Checkbox.Caption+'" to '+FloatToStr(Value)+'.]');
212 Settings[Target_Item].Item_Edit.Text:=FloatToStr( Value );
213 END;
214 END ELSE BEGIN
215 IF StrToInt(Settings[Target_Item].Item_Edit.Text)=Floor(Value) THEN BEGIN
216 SendMessageToOni('[b. Switched "'+Settings[Target_Item].Item_Checkbox.Caption+'" to '+IntToStr(Floor(Value2))+'.]');
217 Settings[Target_Item].Item_Edit.Text:=IntToStr( Floor(Value2) );
218 END ELSE BEGIN
219 SendMessageToOni('[b. Switched "'+Settings[Target_Item].Item_Checkbox.Caption+'" to '+IntToStr(Floor(Value))+'.]');
220 Settings[Target_Item].Item_Edit.Text:=IntToStr( Floor(Value) );
221 END;
222 END;
223 END;
224 END;
225 IF Pos('Char',HK_Target_Types[Target_Type])>0 THEN BEGIN
226 IF NOT (Target_Charname='') THEN BEGIN
227 chid:=255;
228 FOR i:=0 TO ais_controlled DO BEGIN
229 IF CharData[i].Items[1].Item_Edit.Text=Target_Charname THEN BEGIN
230 chid:=i;
231 break;
232 END;
233 END;
234 IF chid=255 THEN exit;
235 END ELSE BEGIN
236 chid:=Target_CharID;
237 END;
238{ IF Pos('Toggle',HK_Actions[Action])>0 THEN BEGIN
239 Settings[Target_Item].Item_Checkbox.Checked:=NOT Settings[Target_Item].Item_Checkbox.Checked;
240 Form1.Debug_Click(Settings[Target_Item].Item_Checkbox);
241 END;}
242 IF 'Set'=HK_Actions[Action] THEN BEGIN
243 IF CharData[chid].Items[Target_Item].data_type=5 THEN BEGIN
244 SendMessageToOni('[b. Set "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' to '+FloatToStr(Value)+'.]');
245 CharData[chid].Items[Target_Item].Item_Edit.Text:=FloatToStr( Value );
246 END ELSE BEGIN
247 SendMessageToOni('[b. Set "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' to '+IntToStr(Floor(Value))+'.]');
248 CharData[chid].Items[Target_Item].Item_Edit.Text:=IntToStr( Floor(Value) );
249 END;
250 END;
251 IF 'Add'=HK_Actions[Action] THEN BEGIN
252 IF CharData[chid].Items[Target_Item].data_type=5 THEN BEGIN
253 SendMessageToOni('[b. Added '+FloatToStr(Value)+' to "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' (now='+FloatToStr( StrToFloat(CharData[chid].Items[Target_Item].Item_Edit.Text) + Value )+').]');
254 CharData[chid].Items[Target_Item].Item_Edit.Text:=FloatToStr( StrToFloat(CharData[chid].Items[Target_Item].Item_Edit.Text) + Value )
255 END ELSE BEGIN
256 SendMessageToOni('[b. Added '+IntToStr(Floor(Value))+' to "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' (now='+FloatToStr( StrToFloat(CharData[chid].Items[Target_Item].Item_Edit.Text) + Value )+').]');
257 CharData[chid].Items[Target_Item].Item_Edit.Text:=IntToStr( StrToInt(CharData[chid].Items[Target_Item].Item_Edit.Text) + Floor(Value) );
258 END;
259 END;
260 IF 'Multiply'=HK_Actions[Action] THEN BEGIN
261 IF CharData[chid].Items[Target_Item].data_type=5 THEN BEGIN
262 SendMessageToOni('[b. Multiplied "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' with '+FloatToStr(Value)+' (now='+FloatToStr( StrToFloat(CharData[chid].Items[Target_Item].Item_Edit.Text) * Value )+').]');
263 CharData[chid].Items[Target_Item].Item_Edit.Text:=FloatToStr( StrToFloat(CharData[chid].Items[Target_Item].Item_Edit.Text) * Value )
264 END ELSE BEGIN
265 SendMessageToOni('[b. Multiplied "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' with '+IntToStr(Floor(Value))+' (now='+FloatToStr( StrToFloat(CharData[chid].Items[Target_Item].Item_Edit.Text) * Value )+').]');
266 CharData[chid].Items[Target_Item].Item_Edit.Text:=IntToStr( StrToInt(CharData[chid].Items[Target_Item].Item_Edit.Text) * Floor(Value) );
267 END;
268 END;
269 IF 'Freeze'=HK_Actions[Action] THEN BEGIN
270 CharData[chid].Items[Target_Item].Item_Freeze.Checked:=NOT CharData[chid].Items[Target_Item].Item_Freeze.Checked;
271 IF CharData[chid].Items[Target_Item].Item_Freeze.Checked THEN
272 SendMessageToOni('[b. Freeze "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' activated.]')
273 ELSE
274 SendMessageToOni('[b. Freeze "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' deactivated.]');
275 END;
276 IF 'Set & Freeze'=HK_Actions[Action] THEN BEGIN
277 IF CharData[chid].Items[Target_Item].Item_Freeze.Checked=False THEN BEGIN
278 IF CharData[chid].Items[Target_Item].data_type=5 THEN BEGIN
279 SendMessageToOni('[b. Set "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' to '+FloatToStr(Value)+' and activated freeze.]');
280 CharData[chid].Items[Target_Item].Item_Edit.Text:=FloatToStr( Value )
281 END ELSE BEGIN
282 SendMessageToOni('[b. Set "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' to '+IntToStr(Floor(Value))+' and activated freeze.]');
283 CharData[chid].Items[Target_Item].Item_Edit.Text:=IntToStr( Floor(Value) );
284 END;
285 CharData[chid].Items[Target_Item].Item_Freeze.Checked:=True;
286 END ELSE BEGIN
287 SendMessageToOni('[b. Freeze "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' deactivated.]');
288 CharData[chid].Items[Target_Item].Item_Freeze.Checked:=False;
289 END;
290 END;
291 IF 'Switch value'=HK_Actions[Action] THEN BEGIN
292 IF CharData[chid].Items[Target_Item].data_type=5 THEN BEGIN
293 IF StrToFloat(CharData[chid].Items[Target_Item].Item_Edit.Text)=Value THEN BEGIN
294 SendMessageToOni('[b. Switched "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' to '+FloatToStr(Value2)+'.]');
295 CharData[chid].Items[Target_Item].Item_Edit.Text:=FloatToStr( Value2 )
296 END ELSE BEGIN
297 SendMessageToOni('[b. Switched "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' to '+FloatToStr(Value)+'.]');
298 CharData[chid].Items[Target_Item].Item_Edit.Text:=FloatToStr( Value );
299 END;
300 END ELSE BEGIN
301 IF StrToInt(CharData[chid].Items[Target_Item].Item_Edit.Text)=Floor(Value) THEN BEGIN
302 SendMessageToOni('[b. Switched "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' to '+IntToStr(Floor(Value2))+'.]');
303 CharData[chid].Items[Target_Item].Item_Edit.Text:=IntToStr( Floor(Value2) )
304 END ELSE BEGIN
305 SendMessageToOni('[b. Switched "'+CharData[chid].Items[Target_Item].Item_Freeze.Caption+'" for char'+IntToStr(chid)+' to '+IntToStr(Floor(Value))+'.]');
306 CharData[chid].Items[Target_Item].Item_Edit.Text:=IntToStr( Floor(Value) );
307 END;
308 END;
309 END;
310 END;
311 END;
312 END;
313 END;
314
315PROCEDURE TForm9.UnregisterHotkeys;
316 VAR i:Byte;
317 BEGIN
318 FOR i:=0 TO Hotkeys.Size-1 DO BEGIN
319 UnregisterHotkey(Form9.Handle,i);
320 END;
321 END;
322
323END.
Note: See TracBrowser for help on using the repository browser.