44 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
44 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
45 |
45 |
46 var hideAmmoMenu: boolean; |
46 var hideAmmoMenu: boolean; |
47 wheelUp: boolean; |
47 wheelUp: boolean; |
48 wheelDown: boolean; |
48 wheelDown: boolean; |
49 {$IFDEF IPHONEOS} |
49 |
50 leftClick: boolean; |
|
51 middleClick: boolean; |
|
52 rightClick: boolean; |
|
53 |
|
54 upKey: boolean; |
|
55 downKey: boolean; |
|
56 rightKey: boolean; |
|
57 leftKey: boolean; |
|
58 |
|
59 backspaceKey: boolean; |
|
60 spaceKey: boolean; |
|
61 enterKey: boolean; |
|
62 tabKey: boolean; |
|
63 |
|
64 theJoystick: PSDL_Joystick; |
|
65 {$ENDIF} |
|
66 ControllerNumControllers: Integer; |
50 ControllerNumControllers: Integer; |
67 ControllerEnabled: Integer; |
51 ControllerEnabled: Integer; |
68 ControllerNumAxes: array[0..5] of Integer; |
52 ControllerNumAxes: array[0..5] of Integer; |
69 //ControllerNumBalls: array[0..5] of Integer; |
53 //ControllerNumBalls: array[0..5] of Integer; |
70 ControllerNumHats: array[0..5] of Integer; |
54 ControllerNumHats: array[0..5] of Integer; |
71 ControllerNumButtons: array[0..5] of Integer; |
55 ControllerNumButtons: array[0..5] of Integer; |
72 ControllerAxes: array[0..5] of array[0..19] of Integer; |
56 ControllerAxes: array[0..5] of array[0..19] of Integer; |
73 //ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer; |
57 //ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer; |
74 ControllerHats: array[0..5] of array[0..19] of Byte; |
58 ControllerHats: array[0..5] of array[0..19] of Byte; |
75 ControllerButtons: array[0..5] of array[0..19] of Byte; |
59 ControllerButtons: array[0..5] of array[0..19] of Byte; |
76 |
60 |
|
61 {$IFDEF IPHONEOS} |
|
62 leftClick: boolean; |
|
63 middleClick: boolean; |
|
64 rightClick: boolean; |
|
65 |
|
66 upKey: boolean; |
|
67 downKey: boolean; |
|
68 rightKey: boolean; |
|
69 leftKey: boolean; |
|
70 |
|
71 backspaceKey: boolean; |
|
72 spaceKey: boolean; |
|
73 enterKey: boolean; |
|
74 tabKey: boolean; |
|
75 |
|
76 chatAction: boolean; |
|
77 switchAction: boolean; |
|
78 |
|
79 theJoystick: PSDL_Joystick; |
|
80 |
|
81 procedure setiPhoneBinds; |
|
82 {$ENDIF} |
77 implementation |
83 implementation |
78 uses uTeams, uConsole, uMisc, uStore; |
84 uses uTeams, uConsole, uMisc, uStore; |
79 const KeyNumber = 1024; |
85 const KeyNumber = 1024; |
80 |
86 |
81 var tkbd, tkbdn: TKeyboardState; |
87 var tkbd, tkbdn: TKeyboardState; |
127 // mouse wheels |
133 // mouse wheels |
128 tkbdn[4]:= ord(wheelDown); |
134 tkbdn[4]:= ord(wheelDown); |
129 tkbdn[5]:= ord(wheelUp); |
135 tkbdn[5]:= ord(wheelUp); |
130 wheelUp:= false; |
136 wheelUp:= false; |
131 wheelDown:= false; |
137 wheelDown:= false; |
132 {$IFDEF IPHONEOS} |
138 |
133 tkbdn[1]:= ord(leftClick); |
139 {$IFDEF IPHONEOS} |
134 tkbdn[2]:= ord(middleClick); |
140 setiPhoneBinds(); |
135 tkbdn[3]:= ord(rightClick); |
|
136 leftClick:= false; |
|
137 middleClick:= false; |
|
138 rightClick:= false; |
|
139 |
|
140 tkbdn[23]:= ord(upKey); |
|
141 tkbdn[24]:= ord(downKey); |
|
142 tkbdn[25]:= ord(leftKey); |
|
143 tkbdn[26]:= ord(rightKey); |
|
144 |
|
145 tkbdn[ 8]:= ord(backspaceKey); |
|
146 tkbdn[ 9]:= ord(tabKey); |
|
147 tkbdn[13]:= ord(enterKey); |
|
148 tkbdn[32]:= ord(spaceKey); |
|
149 |
|
150 tabKey:= false; |
|
151 enterKey:= false; |
|
152 backspaceKey:= false; |
|
153 |
|
154 {$ENDIF} |
141 {$ENDIF} |
155 |
142 |
156 // Controller(s) |
143 // Controller(s) |
157 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
144 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
158 for j:= 0 to Pred(ControllerNumControllers) do |
145 for j:= 0 to Pred(ControllerNumControllers) do |
219 tkbdn[1]:= (k and 1); |
206 tkbdn[1]:= (k and 1); |
220 tkbdn[3]:= ((k shr 2) and 1); |
207 tkbdn[3]:= ((k shr 2) and 1); |
221 {$ENDIF} |
208 {$ENDIF} |
222 tkbdn[2]:= ((k shr 1) and 1); |
209 tkbdn[2]:= ((k shr 1) and 1); |
223 |
210 |
224 // mouse wheels (see event loop in project file) |
211 // mouse wheels |
225 tkbdn[4]:= ord(wheelDown); |
212 tkbdn[4]:= ord(wheelDown); |
226 tkbdn[5]:= ord(wheelUp); |
213 tkbdn[5]:= ord(wheelUp); |
227 wheelUp:= false; |
214 wheelUp:= false; |
228 wheelDown:= false; |
215 wheelDown:= false; |
229 |
216 |
230 {$IFDEF IPHONEOS} |
217 {$IFDEF IPHONEOS} |
231 tkbdn[1]:= ord(leftClick); |
218 setiPhoneBinds(); |
232 tkbdn[2]:= ord(middleClick); |
|
233 tkbdn[3]:= ord(rightClick); |
|
234 leftClick:= false; |
|
235 middleClick:= false; |
|
236 rightClick:= false; |
|
237 |
|
238 tkbdn[23]:= ord(upKey); |
|
239 tkbdn[24]:= ord(downKey); |
|
240 tkbdn[25]:= ord(leftKey); |
|
241 tkbdn[26]:= ord(rightKey); |
|
242 |
|
243 tkbdn[ 8]:= ord(backspaceKey); |
|
244 tkbdn[ 9]:= ord(tabKey); |
|
245 tkbdn[13]:= ord(enterKey); |
|
246 tkbdn[32]:= ord(spaceKey); |
|
247 |
|
248 tabKey:= false; |
|
249 enterKey:= false; |
|
250 backspaceKey:= false; |
|
251 {$ENDIF} |
219 {$ENDIF} |
252 |
220 |
253 // Controller(s) |
221 // Controller(s) |
254 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
222 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
255 for j:= 0 to Pred(ControllerNumControllers) do |
223 for j:= 0 to Pred(ControllerNumControllers) do |
328 keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i); |
296 keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i); |
329 inc(k, 1); |
297 inc(k, 1); |
330 end; |
298 end; |
331 end; |
299 end; |
332 |
300 |
333 {$IFDEF IPHONEOS} |
|
334 DefaultBinds[ 1]:= '/put'; |
|
335 DefaultBinds[ 3]:= 'ammomenu'; |
|
336 DefaultBinds[ 8]:= 'hjump'; |
|
337 DefaultBinds[ 9]:= 'switch'; |
|
338 DefaultBinds[ 13]:= 'ljump'; |
|
339 DefaultBinds[ 23]:= '+up'; |
|
340 DefaultBinds[ 24]:= '+down'; |
|
341 DefaultBinds[ 25]:= '+left'; |
|
342 DefaultBinds[ 26]:= '+right'; |
|
343 DefaultBinds[ 32]:= '+attack'; |
|
344 {$ENDIF} |
|
345 |
|
346 DefaultBinds[ 27]:= 'quit'; |
301 DefaultBinds[ 27]:= 'quit'; |
347 DefaultBinds[ 96]:= 'history'; |
302 DefaultBinds[ 96]:= 'history'; |
348 DefaultBinds[127]:= 'rotmask'; |
303 DefaultBinds[127]:= 'rotmask'; |
349 |
304 |
350 //numpad |
305 //numpad |
364 DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout'; |
319 DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout'; |
365 DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin'; |
320 DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin'; |
366 |
321 |
367 DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
322 DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
368 |
323 |
369 SetDefaultBinds |
324 {$IFDEF IPHONEOS} |
|
325 DefaultBinds[ 1]:= '/put'; |
|
326 DefaultBinds[ 3]:= 'ammomenu'; |
|
327 DefaultBinds[ 8]:= 'hjump'; |
|
328 DefaultBinds[ 9]:= 'switch'; |
|
329 DefaultBinds[13]:= 'ljump'; |
|
330 DefaultBinds[23]:= '+up'; |
|
331 DefaultBinds[24]:= '+down'; |
|
332 DefaultBinds[25]:= '+left'; |
|
333 DefaultBinds[26]:= '+right'; |
|
334 DefaultBinds[32]:= '+attack'; |
|
335 DefaultBinds[44]:= 'chat'; |
|
336 {$ENDIF} |
|
337 |
|
338 SetDefaultBinds(); |
370 end; |
339 end; |
371 |
340 |
372 procedure SetBinds(var binds: TBinds); |
341 procedure SetBinds(var binds: TBinds); |
373 begin |
342 begin |
374 CurrentBinds:= binds; |
343 CurrentBinds:= binds; |
375 end; |
344 end; |
376 |
345 |
377 procedure SetDefaultBinds; |
346 procedure SetDefaultBinds; |
378 begin |
347 begin |
379 CurrentBinds:= DefaultBinds |
348 CurrentBinds:= DefaultBinds; |
380 end; |
349 end; |
|
350 |
|
351 {$IFDEF IPHONEOS} |
|
352 procedure setiPhoneBinds; |
|
353 // set to false the keys that only need one stoke |
|
354 begin |
|
355 tkbdn[1]:= ord(leftClick); |
|
356 tkbdn[2]:= ord(middleClick); |
|
357 tkbdn[3]:= ord(rightClick); |
|
358 |
|
359 tkbdn[23]:= ord(upKey); |
|
360 tkbdn[24]:= ord(downKey); |
|
361 tkbdn[25]:= ord(leftKey); |
|
362 tkbdn[26]:= ord(rightKey); |
|
363 |
|
364 tkbdn[ 8]:= ord(backspaceKey); |
|
365 tkbdn[ 9]:= ord(tabKey); |
|
366 tkbdn[13]:= ord(enterKey); |
|
367 tkbdn[32]:= ord(spaceKey); |
|
368 |
|
369 tkbdn[44]:= ord(chatAction); |
|
370 //tkbdn[100]:= ord(switchAction); |
|
371 |
|
372 leftClick:= false; |
|
373 middleClick:= false; |
|
374 rightClick:= false; |
|
375 |
|
376 tabKey:= false; |
|
377 enterKey:= false; |
|
378 backspaceKey:= false; |
|
379 |
|
380 chatAction:= false; |
|
381 //switchAction:= false; |
|
382 end; |
|
383 {$ENDIF} |
381 |
384 |
382 procedure FreezeEnterKey; |
385 procedure FreezeEnterKey; |
383 begin |
386 begin |
384 tkbd[13]:= 1; |
387 tkbd[13]:= 1; |
385 tkbd[271]:= 1; |
388 tkbd[271]:= 1; |
449 end; |
452 end; |
450 |
453 |
451 procedure ControllerClose; |
454 procedure ControllerClose; |
452 var j: Integer; |
455 var j: Integer; |
453 begin |
456 begin |
454 if ControllerEnabled > 0 then |
457 if ControllerEnabled > 0 then |
455 for j:= 0 to pred(ControllerNumControllers) do |
458 for j:= 0 to pred(ControllerNumControllers) do |
456 SDL_JoystickClose(Controller[j]); |
459 SDL_JoystickClose(Controller[j]); |
457 end; |
460 end; |
458 |
461 |
459 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
462 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
460 begin |
463 begin |
461 ControllerAxes[joy][axis]:= value; |
464 ControllerAxes[joy][axis]:= value; |