47 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
47 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
48 procedure ControllerHatEvent(joy, hat, value: Byte); |
48 procedure ControllerHatEvent(joy, hat, value: Byte); |
49 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
49 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
50 |
50 |
51 implementation |
51 implementation |
52 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug, uPhysFSLayer; |
52 uses uConsole, uCommands, uVariables, uConsts, uUtils, uDebug, uPhysFSLayer; |
53 |
53 |
54 const |
54 const |
55 LSHIFT = $0200; |
55 LSHIFT = $0200; |
56 RSHIFT = $0400; |
56 RSHIFT = $0400; |
57 LALT = $0800; |
57 LALT = $0800; |
58 RALT = $1000; |
58 RALT = $1000; |
59 LCTRL = $2000; |
59 LCTRL = $2000; |
60 RCTRL = $4000; |
60 RCTRL = $4000; |
61 |
61 |
62 var tkbd: array[0..cKbdMaxIndex] of boolean; |
62 var tkbd: array[0..cKbdMaxIndex] of boolean; |
63 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
63 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
64 CurrentBinds: TBinds; |
64 CurrentBinds: TBinds; |
65 ControllerNumControllers: Integer; |
65 ControllerNumControllers: Integer; |
89 KeyNameToCode:= code; |
89 KeyNameToCode:= code; |
90 end; |
90 end; |
91 (* |
91 (* |
92 procedure MaskModifier(var code: LongInt; Modifier: LongWord); |
92 procedure MaskModifier(var code: LongInt; Modifier: LongWord); |
93 begin |
93 begin |
94 if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT; |
94 if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT; |
95 if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT; |
95 if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT; |
96 if(Modifier and KMOD_LALT) <> 0 then code:= code or LALT; |
96 if(Modifier and KMOD_LALT) <> 0 then code:= code or LALT; |
97 if(Modifier and KMOD_RALT) <> 0 then code:= code or LALT; |
97 if(Modifier and KMOD_RALT) <> 0 then code:= code or LALT; |
98 if(Modifier and KMOD_LCTRL) <> 0 then code:= code or LCTRL; |
98 if(Modifier and KMOD_LCTRL) <> 0 then code:= code or LCTRL; |
99 if(Modifier and KMOD_RCTRL) <> 0 then code:= code or LCTRL; |
99 if(Modifier and KMOD_RCTRL) <> 0 then code:= code or LCTRL; |
100 end; |
100 end; |
101 *) |
101 *) |
102 procedure MaskModifier(Modifier: shortstring; var code: LongInt); |
102 procedure MaskModifier(Modifier: shortstring; var code: LongInt); |
103 var mod_ : shortstring; |
103 var mod_ : shortstring = ''; |
104 ModifierCount, i: LongInt; |
104 ModifierCount, i: LongInt; |
105 begin |
105 begin |
106 if Modifier = '' then exit; |
106 if Modifier = '' then exit; |
107 ModifierCount:= 0; |
107 ModifierCount:= 0; |
108 |
108 |
110 if(Modifier[i] = ':') then inc(ModifierCount); |
110 if(Modifier[i] = ':') then inc(ModifierCount); |
111 |
111 |
112 SplitByChar(Modifier, mod_, ':');//remove the first mod: part |
112 SplitByChar(Modifier, mod_, ':');//remove the first mod: part |
113 Modifier:= mod_; |
113 Modifier:= mod_; |
114 for i:= 0 to ModifierCount do |
114 for i:= 0 to ModifierCount do |
115 begin |
115 begin |
116 mod_:= ''; |
116 mod_:= ''; |
117 SplitByChar(Modifier, mod_, ':'); |
117 SplitByChar(Modifier, mod_, ':'); |
118 if (Modifier = 'lshift') then code:= code or LSHIFT; |
118 if (Modifier = 'lshift') then code:= code or LSHIFT; |
119 if (Modifier = 'rshift') then code:= code or RSHIFT; |
119 if (Modifier = 'rshift') then code:= code or RSHIFT; |
120 if (Modifier = 'lalt') then code:= code or LALT; |
120 if (Modifier = 'lalt') then code:= code or LALT; |
173 begin |
173 begin |
174 if CurrentBinds[code] = 'switch' then |
174 if CurrentBinds[code] = 'switch' then |
175 LocalMessage:= LocalMessage or gmSwitch |
175 LocalMessage:= LocalMessage or gmSwitch |
176 else if CurrentBinds[code] = '+precise' then |
176 else if CurrentBinds[code] = '+precise' then |
177 LocalMessage:= LocalMessage or gmPrecise; |
177 LocalMessage:= LocalMessage or gmPrecise; |
178 |
178 |
179 ParseCommand(CurrentBinds[code], Trusted); |
179 ParseCommand(CurrentBinds[code], Trusted); |
180 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
180 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
181 ParseCommand('gencmd R', true) |
181 ParseCommand('gencmd R', true) |
182 end |
182 end |
183 else if (CurrentBinds[code][1] = '+') then |
183 else if (CurrentBinds[code][1] = '+') then |
184 begin |
184 begin |
185 if CurrentBinds[code] = '+precise' then |
185 if CurrentBinds[code] = '+precise' then |
186 LocalMessage:= LocalMessage and not(gmPrecise); |
186 LocalMessage:= LocalMessage and (not gmPrecise); |
187 s:= CurrentBinds[code]; |
187 s:= CurrentBinds[code]; |
188 s[1]:= '-'; |
188 s[1]:= '-'; |
189 ParseCommand(s, Trusted); |
189 ParseCommand(s, Trusted); |
190 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
190 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
191 ParseCommand('gencmd R', true) |
191 ParseCommand('gencmd R', true) |
192 end |
192 end |
193 else |
193 else |
194 begin |
194 begin |
195 if CurrentBinds[code] = 'switch' then |
195 if CurrentBinds[code] = 'switch' then |
196 LocalMessage:= LocalMessage and not(gmSwitch) |
196 LocalMessage:= LocalMessage and (not gmSwitch) |
197 end |
197 end |
198 end |
198 end |
199 end; |
199 end; |
200 |
200 |
201 procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
201 procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
244 for i:= 6 to cKeyMaxIndex do |
244 for i:= 6 to cKeyMaxIndex do |
245 begin |
245 begin |
246 s:= shortstring(sdl_getkeyname(i)); |
246 s:= shortstring(sdl_getkeyname(i)); |
247 //WriteLnToConsole('uInputHandler - ' + IntToStr(i) + ': ' + s + ' ' + IntToStr(cKeyMaxIndex)); |
247 //WriteLnToConsole('uInputHandler - ' + IntToStr(i) + ': ' + s + ' ' + IntToStr(cKeyMaxIndex)); |
248 if s = 'unknown key' then KeyNames[i]:= '' |
248 if s = 'unknown key' then KeyNames[i]:= '' |
249 else |
249 else |
250 begin |
250 begin |
251 for t:= 1 to Length(s) do |
251 for t:= 1 to Length(s) do |
252 if s[t] = ' ' then |
252 if s[t] = ' ' then |
253 s[t]:= '_'; |
253 s[t]:= '_'; |
254 KeyNames[i]:= LowerCase(s) |
254 KeyNames[i]:= LowerCase(s) |
402 ControllerEnabled:= 1; |
402 ControllerEnabled:= 1; |
403 |
403 |
404 if ControllerNumAxes[j] > 20 then |
404 if ControllerNumAxes[j] > 20 then |
405 ControllerNumAxes[j]:= 20; |
405 ControllerNumAxes[j]:= 20; |
406 //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
406 //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
407 |
407 |
408 if ControllerNumHats[j] > 20 then |
408 if ControllerNumHats[j] > 20 then |
409 ControllerNumHats[j]:= 20; |
409 ControllerNumHats[j]:= 20; |
410 |
410 |
411 if ControllerNumButtons[j] > 20 then |
411 if ControllerNumButtons[j] > 20 then |
412 ControllerNumButtons[j]:= 20; |
412 ControllerNumButtons[j]:= 20; |
413 |
413 |
414 (*// reset all buttons/axes |
414 (*// reset all buttons/axes |
415 for i:= 0 to pred(ControllerNumAxes[j]) do |
415 for i:= 0 to pred(ControllerNumAxes[j]) do |
503 if i < length(l) then |
503 if i < length(l) then |
504 begin |
504 begin |
505 l:= copy(l, i + 1, length(l) - i); |
505 l:= copy(l, i + 1, length(l) - i); |
506 if l <> 'default' then |
506 if l <> 'default' then |
507 begin |
507 begin |
508 if (length(l) = 2) and (l[1] = '\') then |
508 if (length(l) = 2) and (l[1] = '\') then |
509 l:= l[1] |
509 l:= l[1] |
510 else if (l[1] = '"') and (l[length(l)] = '"') then |
510 else if (l[1] = '"') and (l[length(l)] = '"') then |
511 l:= copy(l, 2, length(l) - 2); |
511 l:= copy(l, 2, length(l) - 2); |
512 |
512 |
513 p:= cmd + ' ' + l + ' ' + p; |
513 p:= cmd + ' ' + l + ' ' + p; |
545 Delete(KeyName, byte(KeyName[0]), 1); |
545 Delete(KeyName, byte(KeyName[0]), 1); |
546 b:= KeyNameToCode(id, Modifier); |
546 b:= KeyNameToCode(id, Modifier); |
547 if b = 0 then |
547 if b = 0 then |
548 OutError(errmsgUnknownVariable + ' "' + id + '"', false) |
548 OutError(errmsgUnknownVariable + ' "' + id + '"', false) |
549 else |
549 else |
550 begin |
550 begin |
551 // add bind: first check if this cmd is already bound, and remove old bind |
551 // add bind: first check if this cmd is already bound, and remove old bind |
552 i:= cKbdMaxIndex; |
552 i:= cKbdMaxIndex; |
553 repeat |
553 repeat |
554 dec(i) |
554 dec(i) |
555 until (i < 0) or (binds[i] = KeyName); |
555 until (i < 0) or (binds[i] = KeyName); |