43 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
45 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
44 |
46 |
45 implementation |
47 implementation |
46 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug; |
48 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug; |
47 |
49 |
48 var tkbd: array[0..cKeyMaxIndex] of boolean; |
50 var tkbd: array[0..cKbdMaxIndex] of boolean; |
49 quitKeyCode: Byte; |
51 quitKeyCode: Byte; |
50 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
52 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
51 CurrentBinds: TBinds; |
53 CurrentBinds: TBinds; |
52 |
54 |
53 function KeyNameToCode(name: shortstring): word; |
55 function KeyNameToCode(name: shortstring; Modifier: shortstring): LongInt; |
54 var code: Word; |
56 var code: LongInt; |
55 begin |
57 begin |
56 name:= LowerCase(name); |
58 name:= LowerCase(name); |
57 code:= cKeyMaxIndex; |
59 code:= cKeyMaxIndex; |
58 while (code > 0) and (KeyNames[code] <> name) do dec(code); |
60 while (code > 0) and (KeyNames[code] <> name) do dec(code); |
|
61 |
|
62 MaskModifier(Modifier, code); |
59 KeyNameToCode:= code; |
63 KeyNameToCode:= code; |
|
64 end; |
|
65 |
|
66 procedure MaskModifier(var code: LongInt; Modifier: LongWord); |
|
67 begin |
|
68 code:= code or (modifier shl 10); |
|
69 end; |
|
70 |
|
71 procedure MaskModifier(Modifier: shortstring; var code: LongInt); |
|
72 var mod_ : shortstring; |
|
73 ModifierCount, i: LongInt; |
|
74 c : char; |
|
75 begin |
|
76 if Modifier = '' then exit; |
|
77 ModifierCount:= 0; |
|
78 for c in Modifier do |
|
79 if(c = ':') then inc(ModifierCount); |
|
80 |
|
81 SplitByChar(Modifier, mod_, ':');//remove the first mod: part |
|
82 Modifier:= mod_; |
|
83 for i:= 0 to ModifierCount do |
|
84 begin |
|
85 mod_:= ''; |
|
86 SplitByChar(Modifier, mod_, ':'); |
|
87 if (Modifier = 'lshift') then code:= code or (KMOD_LSHIFT shl 10); |
|
88 if (Modifier = 'rshift') then code:= code or (KMOD_RSHIFT shl 10); |
|
89 if (Modifier = 'lalt') then code:= code or (KMOD_LALT shl 10); |
|
90 if (Modifier = 'ralt') then code:= code or (KMOD_RALT shl 10); |
|
91 if (Modifier = 'lctrl') or (mod_ = 'lmeta') then code:= code or (KMOD_LCTRL shl 10); |
|
92 if (Modifier = 'rctrl') or (mod_ = 'rmeta') then code:= code or (KMOD_RCTRL shl 10); |
|
93 Modifier:= mod_; |
|
94 end; |
60 end; |
95 end; |
61 |
96 |
62 procedure ProcessKey(code: LongInt; KeyDown: boolean); |
97 procedure ProcessKey(code: LongInt; KeyDown: boolean); |
63 var |
98 var |
64 Trusted: boolean; |
99 Trusted: boolean; |
65 s : string; |
100 s : string; |
66 begin |
101 begin |
67 |
|
68 if not(tkbd[code] xor KeyDown) then exit; |
102 if not(tkbd[code] xor KeyDown) then exit; |
69 tkbd[code]:= KeyDown; |
103 tkbd[code]:= KeyDown; |
70 |
|
71 |
104 |
72 hideAmmoMenu:= false; |
105 hideAmmoMenu:= false; |
73 Trusted:= (CurrentTeam <> nil) |
106 Trusted:= (CurrentTeam <> nil) |
74 and (not CurrentTeam^.ExtDriven) |
107 and (not CurrentTeam^.ExtDriven) |
75 and (CurrentHedgehog^.BotLevel = 0); |
108 and (CurrentHedgehog^.BotLevel = 0); |
76 |
|
77 |
|
78 |
109 |
79 // ctrl/cmd + q to close engine and frontend |
110 // ctrl/cmd + q to close engine and frontend |
80 if(KeyDown and (code = quitKeyCode)) then |
111 if(KeyDown and (code = quitKeyCode)) then |
81 begin |
112 begin |
82 {$IFDEF DARWIN} |
113 {$IFDEF DARWIN} |
238 |
273 |
239 SetDefaultBinds(); |
274 SetDefaultBinds(); |
240 end; |
275 end; |
241 |
276 |
242 procedure SetBinds(var binds: TBinds); |
277 procedure SetBinds(var binds: TBinds); |
|
278 {$IFNDEF MOBILE} |
|
279 var |
|
280 t: LongInt; |
|
281 {$ENDIF} |
243 begin |
282 begin |
244 {$IFDEF MOBILE} |
283 {$IFDEF MOBILE} |
245 binds:= binds; // avoid hint |
284 binds:= binds; // avoid hint |
246 CurrentBinds:= DefaultBinds; |
285 CurrentBinds:= DefaultBinds; |
247 {$ELSE} |
286 {$ELSE} |
|
287 for t:= 0 to cKbdMaxIndex do |
|
288 if (CurrentBinds[t] <> binds[t]) and tkbd[t] then |
|
289 ProcessKey(t, False); |
|
290 |
248 CurrentBinds:= binds; |
291 CurrentBinds:= binds; |
249 {$ENDIF} |
292 {$ENDIF} |
250 end; |
293 end; |
251 |
294 |
252 procedure SetDefaultBinds; |
295 procedure SetDefaultBinds; |