author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 20 Feb 2018 22:21:33 +0100 | |
changeset 13042 | 29357016f374 |
parent 12997 | f06660523198 |
child 13045 | 25a9260244f3 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10080
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
6954
a61458a81480
changed uKeys to uInputHandler to better reflect its function
Xeli
parents:
6942
diff
changeset
|
21 |
unit uInputHandler; |
4 | 22 |
interface |
4363 | 23 |
uses SDLh, uTypes; |
4 | 24 |
|
3038 | 25 |
procedure initModule; |
26 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
27 |
|
7426
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
28 |
function KeyNameToCode(name: shortstring): LongInt; inline; |
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
29 |
function KeyNameToCode(name: shortstring; Modifier: shortstring): LongInt; |
13042
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
30 |
|
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
31 |
function KeyBindToCode(bind: shortstring): LongInt; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
32 |
function KeyBindToName(bind: shortstring): ansistring; |
7426
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
33 |
//procedure MaskModifier(var code: LongInt; modifier: LongWord); |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
34 |
procedure MaskModifier(Modifier: shortstring; var code: LongInt); |
6917 | 35 |
procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean); |
12621 | 36 |
//procedure ProcessMouseWheel(x, y: LongInt); |
37 |
procedure ProcessMouseWheel(y: LongInt); |
|
6992 | 38 |
procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
39 |
procedure ProcessKey(code: LongInt; KeyDown: boolean); |
|
40 |
||
4 | 41 |
procedure ResetKbd; |
11486 | 42 |
procedure ResetMouseWheel; |
948 | 43 |
procedure FreezeEnterKey; |
4 | 44 |
procedure InitKbdKeyTable; |
45 |
||
167 | 46 |
procedure SetBinds(var binds: TBinds); |
47 |
procedure SetDefaultBinds; |
|
8346 | 48 |
procedure chDefaultBind(var id: shortstring); |
9466 | 49 |
procedure loadBinds(cmd, s: shortstring); |
50 |
procedure addBind(var binds: TBinds; var id: shortstring); |
|
167 | 51 |
|
2428 | 52 |
procedure ControllerInit; |
53 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
54 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
55 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
56 |
||
4 | 57 |
implementation |
10015 | 58 |
uses uConsole, uCommands, uVariables, uConsts, uUtils, uDebug, uPhysFSLayer; |
167 | 59 |
|
7193 | 60 |
const |
61 |
LSHIFT = $0200; |
|
62 |
RSHIFT = $0400; |
|
63 |
LALT = $0800; |
|
64 |
RALT = $1000; |
|
65 |
LCTRL = $2000; |
|
8330 | 66 |
RCTRL = $4000; |
7193 | 67 |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
68 |
var tkbd: array[0..cKbdMaxIndex] of boolean; |
4 | 69 |
KeyNames: array [0..cKeyMaxIndex] of string[15]; |
6982 | 70 |
CurrentBinds: TBinds; |
8145
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7974
diff
changeset
|
71 |
ControllerNumControllers: Integer; |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7974
diff
changeset
|
72 |
ControllerEnabled: Integer; |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7974
diff
changeset
|
73 |
ControllerNumAxes: array[0..5] of Integer; |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7974
diff
changeset
|
74 |
//ControllerNumBalls: array[0..5] of Integer; |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7974
diff
changeset
|
75 |
ControllerNumHats: array[0..5] of Integer; |
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7974
diff
changeset
|
76 |
ControllerNumButtons: array[0..5] of Integer; |
8370 | 77 |
//ControllerAxes: array[0..5] of array[0..19] of Integer; |
8145
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
7974
diff
changeset
|
78 |
//ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer; |
8370 | 79 |
//ControllerHats: array[0..5] of array[0..19] of Byte; |
80 |
//ControllerButtons: array[0..5] of array[0..19] of Byte; |
|
3697 | 81 |
|
7426
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
82 |
function KeyNameToCode(name: shortstring): LongInt; inline; |
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
83 |
begin |
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
84 |
KeyNameToCode:= KeyNameToCode(name, ''); |
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
85 |
end; |
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
86 |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
87 |
function KeyNameToCode(name: shortstring; Modifier: shortstring): LongInt; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
88 |
var code: LongInt; |
2678
334016e8d895
injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
2674
diff
changeset
|
89 |
begin |
6917 | 90 |
name:= LowerCase(name); |
9694 | 91 |
code:= 0; |
92 |
while (code <= cKeyMaxIndex) and (KeyNames[code] <> name) do inc(code); |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
93 |
|
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
94 |
MaskModifier(Modifier, code); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
95 |
KeyNameToCode:= code; |
2678
334016e8d895
injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
2674
diff
changeset
|
96 |
end; |
13042
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
97 |
|
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
98 |
// Takes a control name (e.g. 'quit') and returns the corresponding key code, |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
99 |
// if it has been bound. |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
100 |
// Returns -1 if the control has not been bound. |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
101 |
function KeyBindToCode(bind: shortstring): LongInt; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
102 |
var code: LongInt; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
103 |
begin |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
104 |
code:= 0; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
105 |
while (code <= cKeyMaxIndex) and (CurrentBinds[code] <> bind) do inc(code); |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
106 |
if code > cKeyMaxIndex then |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
107 |
// Return error |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
108 |
KeyBindToCode:= -1 |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
109 |
else |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
110 |
KeyBindToCode:= code; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
111 |
end; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
112 |
|
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
113 |
// Takes a control name (e.g. 'quit') and returns the corresponding |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
114 |
// human-readable key name from SDL. |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
115 |
// FIXME: Does not work 100% for all keys yet, but at least it no |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
116 |
// longer hardcodes any key name. |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
117 |
// TODO: Localize |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
118 |
function KeyBindToName(bind: shortstring): ansistring; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
119 |
var code: LongInt; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
120 |
name: ansistring; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
121 |
begin |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
122 |
code:= KeyBindToCode(bind); |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
123 |
if code = -1 then |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
124 |
KeyBindToName:= trmsg[sidUnknownKey] |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
125 |
else |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
126 |
begin |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
127 |
name:= SDL_GetKeyName(SDL_GetKeyFromScancode(code)); |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
128 |
if (name <> '') then |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
129 |
KeyBindToName:= name |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
130 |
else |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
131 |
begin |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
132 |
WriteLnToConsole('Error: KeyBindToName('+bind+') failed to find SDL key name!'); |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
133 |
KeyBindToName:= trmsg[sidUnknownKey]; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
134 |
end; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
135 |
end; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
136 |
end; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
137 |
|
7426
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
138 |
(* |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
139 |
procedure MaskModifier(var code: LongInt; Modifier: LongWord); |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
140 |
begin |
8330 | 141 |
if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT; |
142 |
if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT; |
|
143 |
if(Modifier and KMOD_LALT) <> 0 then code:= code or LALT; |
|
144 |
if(Modifier and KMOD_RALT) <> 0 then code:= code or LALT; |
|
145 |
if(Modifier and KMOD_LCTRL) <> 0 then code:= code or LCTRL; |
|
146 |
if(Modifier and KMOD_RCTRL) <> 0 then code:= code or LCTRL; |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
147 |
end; |
7426
55b49cc1f33a
Changes for the benefit of pas2c. Use downto in for loops to avoid repeated calls of Random/GetRandom. Wrap nots.
nemo
parents:
7403
diff
changeset
|
148 |
*) |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
149 |
procedure MaskModifier(Modifier: shortstring; var code: LongInt); |
10015 | 150 |
var mod_ : shortstring = ''; |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
151 |
ModifierCount, i: LongInt; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
152 |
begin |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
153 |
if Modifier = '' then exit; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
154 |
ModifierCount:= 0; |
7202 | 155 |
|
156 |
for i:= 1 to Length(Modifier) do |
|
157 |
if(Modifier[i] = ':') then inc(ModifierCount); |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
158 |
|
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
159 |
SplitByChar(Modifier, mod_, ':');//remove the first mod: part |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
160 |
Modifier:= mod_; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
161 |
for i:= 0 to ModifierCount do |
8330 | 162 |
begin |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
163 |
mod_:= ''; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
164 |
SplitByChar(Modifier, mod_, ':'); |
7193 | 165 |
if (Modifier = 'lshift') then code:= code or LSHIFT; |
166 |
if (Modifier = 'rshift') then code:= code or RSHIFT; |
|
167 |
if (Modifier = 'lalt') then code:= code or LALT; |
|
168 |
if (Modifier = 'ralt') then code:= code or RALT; |
|
169 |
if (Modifier = 'lctrl') or (mod_ = 'lmeta') then code:= code or LCTRL; |
|
170 |
if (Modifier = 'rctrl') or (mod_ = 'rmeta') then code:= code or RCTRL; |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
171 |
Modifier:= mod_; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
172 |
end; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
173 |
end; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
174 |
|
6917 | 175 |
procedure ProcessKey(code: LongInt; KeyDown: boolean); |
176 |
var |
|
177 |
Trusted: boolean; |
|
178 |
s : string; |
|
179 |
begin |
|
7141
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
180 |
if not(tkbd[code] xor KeyDown) then exit; |
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
181 |
tkbd[code]:= KeyDown; |
7140
29948153fda2
Don't allow for multiple key up(or down) events, it will ignore the excess events
Xeli
parents:
7118
diff
changeset
|
182 |
|
6917 | 183 |
Trusted:= (CurrentTeam <> nil) |
184 |
and (not CurrentTeam^.ExtDriven) |
|
185 |
and (CurrentHedgehog^.BotLevel = 0); |
|
9714 | 186 |
// REVIEW OR FIXME |
187 |
// ctrl/cmd + q to close engine and frontend - this seems like a bad idea, since we let people set arbitrary binds, and don't warn them of this. |
|
188 |
// There's no confirmation at all |
|
6942 | 189 |
// ctrl/cmd + q to close engine and frontend |
8746
55539c550c33
use SDL keycode for shortcuts (doesn't fix layout issues)
koda
parents:
8370
diff
changeset
|
190 |
if(KeyDown and (code = SDLK_q)) then |
6942 | 191 |
begin |
192 |
{$IFDEF DARWIN} |
|
7141
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
193 |
if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then |
6942 | 194 |
{$ELSE} |
7141
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
195 |
if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then |
6942 | 196 |
{$ENDIF} |
7869
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
197 |
ParseCommand('halt', true); |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
198 |
end; |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
199 |
|
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
200 |
// ctrl/cmd + w to close engine |
8746
55539c550c33
use SDL keycode for shortcuts (doesn't fix layout issues)
koda
parents:
8370
diff
changeset
|
201 |
if(KeyDown and (code = SDLK_w)) then |
7869
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
202 |
begin |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
203 |
{$IFDEF DARWIN} |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
204 |
// on OS X it this is expected behaviour |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
205 |
if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
206 |
{$ELSE} |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
207 |
// on other systems use this shortcut only if the keys are not bound to any command |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
208 |
if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then |
7871 | 209 |
if ((CurrentBinds[KeyNameToCode('left_ctrl')] = '') or |
210 |
(CurrentBinds[KeyNameToCode('right_ctrl')] = '')) and |
|
8746
55539c550c33
use SDL keycode for shortcuts (doesn't fix layout issues)
koda
parents:
8370
diff
changeset
|
211 |
(CurrentBinds[SDLK_w] = '') then |
7869
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
212 |
{$ENDIF} |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
213 |
ParseCommand('forcequit', true); |
6942 | 214 |
end; |
215 |
||
6917 | 216 |
if CurrentBinds[code][0] <> #0 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
217 |
begin |
9694 | 218 |
if (code < cKeyMaxIndex - 2) // means not mouse buttons |
219 |
and KeyDown |
|
12790
abc9a99418cc
Fix ammo menu, placement and camera movement keys not working in ammo menu
Wuzzy <Wuzzy2@mail.ru>
parents:
12621
diff
changeset
|
220 |
and (not ((CurrentBinds[code] = 'put') or (CurrentBinds[code] = 'ammomenu') or (CurrentBinds[code] = '+cur_u') or (CurrentBinds[code] = '+cur_d') or (CurrentBinds[code] = '+cur_l') or (CurrentBinds[code] = '+cur_r'))) |
9694 | 221 |
and (CurrentTeam <> nil) |
222 |
and (not CurrentTeam^.ExtDriven) |
|
223 |
then bShowAmmoMenu:= false; |
|
7118 | 224 |
|
7140
29948153fda2
Don't allow for multiple key up(or down) events, it will ignore the excess events
Xeli
parents:
7118
diff
changeset
|
225 |
if KeyDown then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
226 |
begin |
10392 | 227 |
Trusted:= Trusted and (not isPaused); //releasing keys during pause should be allowed on the other hand |
10510 | 228 |
|
9693 | 229 |
if CurrentBinds[code] = 'switch' then |
9714 | 230 |
LocalMessage:= LocalMessage or gmSwitch |
231 |
else if CurrentBinds[code] = '+precise' then |
|
232 |
LocalMessage:= LocalMessage or gmPrecise; |
|
10015 | 233 |
|
6917 | 234 |
ParseCommand(CurrentBinds[code], Trusted); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
235 |
if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
236 |
ParseCommand('gencmd R', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
237 |
end |
7140
29948153fda2
Don't allow for multiple key up(or down) events, it will ignore the excess events
Xeli
parents:
7118
diff
changeset
|
238 |
else if (CurrentBinds[code][1] = '+') then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
239 |
begin |
9714 | 240 |
if CurrentBinds[code] = '+precise' then |
9954 | 241 |
LocalMessage:= LocalMessage and (not gmPrecise); |
6917 | 242 |
s:= CurrentBinds[code]; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
243 |
s[1]:= '-'; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
244 |
ParseCommand(s, Trusted); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
245 |
if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
246 |
ParseCommand('gencmd R', true) |
9693 | 247 |
end |
248 |
else |
|
249 |
begin |
|
250 |
if CurrentBinds[code] = 'switch' then |
|
9954 | 251 |
LocalMessage:= LocalMessage and (not gmSwitch) |
9693 | 252 |
end |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
253 |
end |
6917 | 254 |
end; |
255 |
||
9691 | 256 |
procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
257 |
var code: LongInt; |
|
258 |
begin |
|
11365 | 259 |
// TODO |
260 |
code:= LongInt(event.keysym.scancode); |
|
9694 | 261 |
//writelntoconsole('[KEY] '+inttostr(code)+ ' -> ''' +KeyNames[code] + ''', type = '+inttostr(event.type_)); |
9691 | 262 |
ProcessKey(code, event.type_ = SDL_KEYDOWN); |
263 |
end; |
|
6917 | 264 |
|
265 |
procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean); |
|
266 |
begin |
|
9694 | 267 |
//writelntoconsole('[MOUSE] '+inttostr(event.button)); |
268 |
case event.button of |
|
269 |
SDL_BUTTON_LEFT: |
|
270 |
ProcessKey(KeyNameToCode('mousel'), ButtonDown); |
|
271 |
SDL_BUTTON_MIDDLE: |
|
272 |
ProcessKey(KeyNameToCode('mousem'), ButtonDown); |
|
273 |
SDL_BUTTON_RIGHT: |
|
274 |
ProcessKey(KeyNameToCode('mouser'), ButtonDown); |
|
275 |
end; |
|
276 |
end; |
|
277 |
||
11486 | 278 |
var mwheelupCode, mwheeldownCode: Integer; |
279 |
||
12621 | 280 |
//procedure ProcessMouseWheel(x, y: LongInt); |
281 |
procedure ProcessMouseWheel(y: LongInt); |
|
9694 | 282 |
begin |
12621 | 283 |
// we don't use |
9694 | 284 |
//writelntoconsole('[MOUSEWHEEL] '+inttostr(x)+', '+inttostr(y)); |
285 |
if y > 0 then |
|
11486 | 286 |
begin |
287 |
// reset other direction |
|
288 |
if tkbd[mwheeldownCode] then |
|
289 |
ProcessKey(mwheeldownCode, false); |
|
290 |
// trigger "button down" event |
|
291 |
if (not tkbd[mwheelupCode]) then |
|
292 |
ProcessKey(mwheelupCode, true); |
|
293 |
end |
|
9694 | 294 |
else if y < 0 then |
11486 | 295 |
begin |
296 |
// reset other direction |
|
297 |
if tkbd[mwheelupCode] then |
|
298 |
ProcessKey(mwheelupCode, false); |
|
299 |
// trigger "button down" event |
|
300 |
if (not tkbd[mwheeldownCode]) then |
|
301 |
ProcessKey(mwheeldownCode, true); |
|
302 |
end; |
|
303 |
end; |
|
304 |
||
305 |
procedure ResetMouseWheel(); |
|
306 |
begin |
|
307 |
if tkbd[mwheelupCode] then |
|
308 |
ProcessKey(mwheelupCode, false); |
|
309 |
if tkbd[mwheeldownCode] then |
|
310 |
ProcessKey(mwheeldownCode, false); |
|
4 | 311 |
end; |
312 |
||
313 |
procedure ResetKbd; |
|
7117
7df6386f7090
reimplemented ResetKbd and calling it when exiting gsChat status, this restores behavior from.17: You can now walk -> press t/chat -> type some stuff while still walking -> exit gsChat and stop walking at that moment
Xeli
parents:
7106
diff
changeset
|
314 |
var t: LongInt; |
4 | 315 |
begin |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
316 |
for t:= 0 to cKbdMaxIndex do |
7141
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
317 |
if tkbd[t] then |
7117
7df6386f7090
reimplemented ResetKbd and calling it when exiting gsChat status, this restores behavior from.17: You can now walk -> press t/chat -> type some stuff while still walking -> exit gsChat and stop walking at that moment
Xeli
parents:
7106
diff
changeset
|
318 |
ProcessKey(t, False); |
4 | 319 |
end; |
320 |
||
9691 | 321 |
|
322 |
procedure InitDefaultBinds; |
|
323 |
var i: Longword; |
|
324 |
begin |
|
325 |
DefaultBinds[KeyNameToCode('escape')]:= 'quit'; |
|
326 |
DefaultBinds[KeyNameToCode(_S'`')]:= 'history'; |
|
327 |
DefaultBinds[KeyNameToCode('delete')]:= 'rotmask'; |
|
12997
f06660523198
Add separate control for changing hedgehog tags
Wuzzy <Wuzzy2@mail.ru>
parents:
12790
diff
changeset
|
328 |
DefaultBinds[KeyNameToCode('home')]:= 'rottags'; |
9691 | 329 |
|
330 |
//numpad |
|
331 |
//DefaultBinds[265]:= '+volup'; |
|
332 |
//DefaultBinds[256]:= '+voldown'; |
|
333 |
||
334 |
DefaultBinds[KeyNameToCode(_S'0')]:= '+volup'; |
|
335 |
DefaultBinds[KeyNameToCode(_S'9')]:= '+voldown'; |
|
336 |
DefaultBinds[KeyNameToCode(_S'8')]:= 'mute'; |
|
337 |
DefaultBinds[KeyNameToCode(_S'c')]:= 'capture'; |
|
338 |
DefaultBinds[KeyNameToCode(_S'r')]:= 'record'; |
|
339 |
DefaultBinds[KeyNameToCode(_S'h')]:= 'findhh'; |
|
340 |
DefaultBinds[KeyNameToCode(_S'p')]:= 'pause'; |
|
341 |
DefaultBinds[KeyNameToCode(_S's')]:= '+speedup'; |
|
342 |
DefaultBinds[KeyNameToCode(_S't')]:= 'chat'; |
|
343 |
DefaultBinds[KeyNameToCode(_S'y')]:= 'confirm'; |
|
344 |
||
345 |
DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset'; |
|
346 |
DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomin'; |
|
347 |
DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomout'; |
|
348 |
||
349 |
DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
|
350 |
||
351 |
||
352 |
DefaultBinds[KeyNameToCode('mousel')]:= '/put'; |
|
353 |
DefaultBinds[KeyNameToCode('mouser')]:= 'ammomenu'; |
|
354 |
DefaultBinds[KeyNameToCode('backspace')]:= 'hjump'; |
|
355 |
DefaultBinds[KeyNameToCode('tab')]:= 'switch'; |
|
356 |
DefaultBinds[KeyNameToCode('return')]:= 'ljump'; |
|
357 |
DefaultBinds[KeyNameToCode('space')]:= '+attack'; |
|
358 |
DefaultBinds[KeyNameToCode('up')]:= '+up'; |
|
359 |
DefaultBinds[KeyNameToCode('down')]:= '+down'; |
|
360 |
DefaultBinds[KeyNameToCode('left')]:= '+left'; |
|
361 |
DefaultBinds[KeyNameToCode('right')]:= '+right'; |
|
362 |
DefaultBinds[KeyNameToCode('left_shift')]:= '+precise'; |
|
363 |
||
364 |
||
365 |
DefaultBinds[KeyNameToCode('j0a0u')]:= '+left'; |
|
366 |
DefaultBinds[KeyNameToCode('j0a0d')]:= '+right'; |
|
367 |
DefaultBinds[KeyNameToCode('j0a1u')]:= '+up'; |
|
368 |
DefaultBinds[KeyNameToCode('j0a1d')]:= '+down'; |
|
11664
64465e0eb852
fix default binding for F10 / slot 10 not working
sheepluva
parents:
11486
diff
changeset
|
369 |
for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+char(48+i); |
9691 | 370 |
for i:= 1 to 5 do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i); |
371 |
||
12106
9bc19f722169
Bug #108 - Phyfs/Pathz: Fix binds not being loaded
sheepluva
parents:
11664
diff
changeset
|
372 |
loadBinds('dbind', cPathz[ptConfig] + '/settings.ini'); |
9691 | 373 |
end; |
374 |
||
375 |
||
376 |
procedure InitKbdKeyTable; |
|
377 |
var i, j, k, t: LongInt; |
|
378 |
s: string[15]; |
|
379 |
begin |
|
380 |
KeyNames[cKeyMaxIndex ]:= 'mousel'; |
|
381 |
KeyNames[cKeyMaxIndex - 1]:= 'mousem'; |
|
382 |
KeyNames[cKeyMaxIndex - 2]:= 'mouser'; |
|
11486 | 383 |
mwheelupCode:= cKeyMaxIndex - 3; |
384 |
KeyNames[mwheelupCode]:= 'wheelup'; |
|
385 |
mwheeldownCode:= cKeyMaxIndex - 4; |
|
386 |
KeyNames[mwheeldownCode]:= 'wheeldown'; |
|
9691 | 387 |
|
388 |
for i:= 0 to cKeyMaxIndex - 5 do |
|
389 |
begin |
|
11365 | 390 |
s:= shortstring(SDL_GetScancodeName(TSDL_Scancode(i))); |
9691 | 391 |
|
392 |
for t:= 1 to Length(s) do |
|
393 |
if s[t] = ' ' then |
|
394 |
s[t]:= '_'; |
|
395 |
KeyNames[i]:= LowerCase(s) |
|
396 |
end; |
|
397 |
||
398 |
||
399 |
// get the size of keyboard array |
|
11368
c481d087f653
cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents:
11365
diff
changeset
|
400 |
SDL_GetKeyboardState(@k); |
9691 | 401 |
|
402 |
// Controller(s) |
|
403 |
for j:= 0 to Pred(ControllerNumControllers) do |
|
404 |
begin |
|
405 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
406 |
begin |
|
407 |
KeyNames[k + 0]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'u'; |
|
408 |
KeyNames[k + 1]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'd'; |
|
409 |
inc(k, 2); |
|
410 |
end; |
|
411 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
412 |
begin |
|
413 |
KeyNames[k + 0]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'u'; |
|
414 |
KeyNames[k + 1]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'r'; |
|
415 |
KeyNames[k + 2]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'd'; |
|
416 |
KeyNames[k + 3]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'l'; |
|
417 |
inc(k, 4); |
|
418 |
end; |
|
419 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
420 |
begin |
|
421 |
KeyNames[k]:= 'j' + IntToStr(j) + 'b' + IntToStr(i); |
|
422 |
inc(k, 1); |
|
423 |
end; |
|
424 |
end; |
|
425 |
||
426 |
InitDefaultBinds |
|
427 |
end; |
|
2606
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
428 |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
429 |
|
2786 | 430 |
|
9691 | 431 |
{$IFNDEF MOBILE} |
167 | 432 |
procedure SetBinds(var binds: TBinds); |
7184
211ab9e2cb15
only reset those keys which actually change their bindings
Xeli
parents:
7151
diff
changeset
|
433 |
var |
211ab9e2cb15
only reset those keys which actually change their bindings
Xeli
parents:
7151
diff
changeset
|
434 |
t: LongInt; |
167 | 435 |
begin |
8346 | 436 |
for t:= 0 to cKbdMaxIndex do |
437 |
if (CurrentBinds[t] <> binds[t]) and tkbd[t] then |
|
438 |
ProcessKey(t, False); |
|
7184
211ab9e2cb15
only reset those keys which actually change their bindings
Xeli
parents:
7151
diff
changeset
|
439 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
440 |
CurrentBinds:= binds; |
9691 | 441 |
end; |
442 |
{$ELSE} |
|
443 |
procedure SetBinds(var binds: TBinds); |
|
444 |
begin |
|
445 |
binds:= binds; // avoid hint |
|
446 |
CurrentBinds:= DefaultBinds; |
|
447 |
end; |
|
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3651
diff
changeset
|
448 |
{$ENDIF} |
167 | 449 |
|
450 |
procedure SetDefaultBinds; |
|
451 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
452 |
CurrentBinds:= DefaultBinds; |
167 | 453 |
end; |
454 |
||
948 | 455 |
procedure FreezeEnterKey; |
456 |
begin |
|
7141
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
457 |
tkbd[3]:= True; |
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
458 |
tkbd[13]:= True; |
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
459 |
tkbd[27]:= True; |
ea6ad9a97fca
change the array which represents the keyboard state to be a boolean array rather than byte array
Xeli
parents:
7140
diff
changeset
|
460 |
tkbd[271]:= True; |
948 | 461 |
end; |
167 | 462 |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
463 |
var Controller: array [0..5] of PSDL_Joystick; |
3697 | 464 |
|
2428 | 465 |
procedure ControllerInit; |
8370 | 466 |
var j: Integer; |
2428 | 467 |
begin |
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3651
diff
changeset
|
468 |
ControllerEnabled:= 0; |
7088
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
469 |
{$IFDEF IPHONE} |
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3651
diff
changeset
|
470 |
exit; // joystick subsystem disabled on iPhone |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3493
diff
changeset
|
471 |
{$ENDIF} |
2674
2fce032f2f95
lupdate + Palewolf's updated spanish translation + other patches of mine
koda
parents:
2671
diff
changeset
|
472 |
|
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3651
diff
changeset
|
473 |
SDL_InitSubSystem(SDL_INIT_JOYSTICK); |
2674
2fce032f2f95
lupdate + Palewolf's updated spanish translation + other patches of mine
koda
parents:
2671
diff
changeset
|
474 |
ControllerNumControllers:= SDL_NumJoysticks(); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
475 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
476 |
if ControllerNumControllers > 6 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
477 |
ControllerNumControllers:= 6; |
2428 | 478 |
|
4374 | 479 |
WriteLnToConsole('Number of game controllers: ' + IntToStr(ControllerNumControllers)); |
2428 | 480 |
|
481 |
if ControllerNumControllers > 0 then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
482 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
483 |
for j:= 0 to pred(ControllerNumControllers) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
484 |
begin |
7151 | 485 |
WriteLnToConsole('Using game controller: ' + shortstring(SDL_JoystickName(j))); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
486 |
Controller[j]:= SDL_JoystickOpen(j); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
487 |
if Controller[j] = nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
488 |
WriteLnToConsole('* Failed to open game controller!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
489 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
490 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
491 |
ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
492 |
//ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
493 |
ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
494 |
ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
4374 | 495 |
WriteLnToConsole('* Number of axes: ' + IntToStr(ControllerNumAxes[j])); |
496 |
//WriteLnToConsole('* Number of balls: ' + IntToStr(ControllerNumBalls[j])); |
|
497 |
WriteLnToConsole('* Number of hats: ' + IntToStr(ControllerNumHats[j])); |
|
498 |
WriteLnToConsole('* Number of buttons: ' + IntToStr(ControllerNumButtons[j])); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
499 |
ControllerEnabled:= 1; |
3697 | 500 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
501 |
if ControllerNumAxes[j] > 20 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
502 |
ControllerNumAxes[j]:= 20; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
503 |
//if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
8330 | 504 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
505 |
if ControllerNumHats[j] > 20 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
506 |
ControllerNumHats[j]:= 20; |
8330 | 507 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
508 |
if ControllerNumButtons[j] > 20 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
509 |
ControllerNumButtons[j]:= 20; |
3697 | 510 |
|
8370 | 511 |
(*// reset all buttons/axes |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
512 |
for i:= 0 to pred(ControllerNumAxes[j]) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
513 |
ControllerAxes[j][i]:= 0; |
8370 | 514 |
for i:= 0 to pred(ControllerNumBalls[j]) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
515 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
516 |
ControllerBalls[j][i][0]:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
517 |
ControllerBalls[j][i][1]:= 0; |
8370 | 518 |
end; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
519 |
for i:= 0 to pred(ControllerNumHats[j]) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
520 |
ControllerHats[j][i]:= SDL_HAT_CENTERED; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
521 |
for i:= 0 to pred(ControllerNumButtons[j]) do |
8370 | 522 |
ControllerButtons[j][i]:= 0;*) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
523 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
524 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
525 |
// enable event generation/controller updating |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
526 |
SDL_JoystickEventState(1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
527 |
end |
3697 | 528 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
529 |
WriteLnToConsole('Not using any game controller'); |
2428 | 530 |
end; |
531 |
||
532 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
7088
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
533 |
var |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
534 |
k: LongInt; |
2428 | 535 |
begin |
11368
c481d087f653
cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents:
11365
diff
changeset
|
536 |
SDL_GetKeyboardState(@k); |
7088
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
537 |
k:= k + joy * (ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + ControllerNumButtons[joy]*2); |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
538 |
ProcessKey(k + axis*2, value > 20000); |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
539 |
ProcessKey(k + (axis*2)+1, value < -20000); |
2428 | 540 |
end; |
541 |
||
542 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
7088
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
543 |
var |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
544 |
k: LongInt; |
2428 | 545 |
begin |
11368
c481d087f653
cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents:
11365
diff
changeset
|
546 |
SDL_GetKeyboardState(@k); |
7088
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
547 |
k:= k + joy * (ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + ControllerNumButtons[joy]*2); |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
548 |
ProcessKey(k + ControllerNumAxes[joy]*2 + hat*4 + 0, (value and SDL_HAT_UP) <> 0); |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
549 |
ProcessKey(k + ControllerNumAxes[joy]*2 + hat*4 + 1, (value and SDL_HAT_RIGHT)<> 0); |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
550 |
ProcessKey(k + ControllerNumAxes[joy]*2 + hat*4 + 2, (value and SDL_HAT_DOWN) <> 0); |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
551 |
ProcessKey(k + ControllerNumAxes[joy]*2 + hat*4 + 3, (value and SDL_HAT_LEFT) <> 0); |
2428 | 552 |
end; |
553 |
||
554 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
7088
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
555 |
var |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
556 |
k: LongInt; |
2428 | 557 |
begin |
11368
c481d087f653
cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents:
11365
diff
changeset
|
558 |
SDL_GetKeyboardState(@k); |
7088
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
559 |
k:= k + joy * (ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + ControllerNumButtons[joy]*2); |
dbec9bae4de1
first attempt at fixing controller/gamepad, it works with the android controller but it doesnt have hats/buttons, needs testing
Xeli
parents:
7071
diff
changeset
|
560 |
ProcessKey(k + ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + button, pressed); |
2428 | 561 |
end; |
562 |
||
9466 | 563 |
procedure loadBinds(cmd, s: shortstring); |
564 |
var i: LongInt; |
|
565 |
f: PFSFile; |
|
566 |
p, l: shortstring; |
|
567 |
b: byte; |
|
568 |
begin |
|
10139 | 569 |
if cOnlyStats then exit; |
10510 | 570 |
|
9466 | 571 |
AddFileLog('[BINDS] Loading binds from: ' + s); |
572 |
||
573 |
l:= ''; |
|
574 |
if pfsExists(s) then |
|
575 |
begin |
|
576 |
f:= pfsOpenRead(s); |
|
577 |
while (not pfsEOF(f)) and (l <> '[Binds]') do |
|
578 |
pfsReadLn(f, l); |
|
579 |
||
580 |
while (not pfsEOF(f)) and (l <> '') do |
|
581 |
begin |
|
582 |
pfsReadLn(f, l); |
|
583 |
||
584 |
p:= ''; |
|
585 |
i:= 1; |
|
586 |
while (i <= length(l)) and (l[i] <> '=') do |
|
587 |
begin |
|
9981 | 588 |
if l[i] = '%' then |
9466 | 589 |
begin |
590 |
l[i]:= '$'; |
|
591 |
val(copy(l, i, 3), b); |
|
592 |
p:= p + char(b); |
|
593 |
inc(i, 3) |
|
10015 | 594 |
end |
9981 | 595 |
else |
596 |
begin |
|
597 |
p:= p + l[i]; |
|
598 |
inc(i) |
|
9466 | 599 |
end; |
600 |
end; |
|
601 |
||
602 |
if i < length(l) then |
|
603 |
begin |
|
604 |
l:= copy(l, i + 1, length(l) - i); |
|
605 |
if l <> 'default' then |
|
606 |
begin |
|
10015 | 607 |
if (length(l) = 2) and (l[1] = '\') then |
10080 | 608 |
l:= l[1] + '' |
9981 | 609 |
else if (l[1] = '"') and (l[length(l)] = '"') then |
610 |
l:= copy(l, 2, length(l) - 2); |
|
611 |
||
9466 | 612 |
p:= cmd + ' ' + l + ' ' + p; |
613 |
ParseCommand(p, true) |
|
614 |
end |
|
615 |
end |
|
616 |
end; |
|
617 |
||
618 |
pfsClose(f) |
|
10015 | 619 |
end |
9466 | 620 |
else |
621 |
AddFileLog('[BINDS] file not found'); |
|
622 |
end; |
|
623 |
||
624 |
||
625 |
procedure addBind(var binds: TBinds; var id: shortstring); |
|
8346 | 626 |
var KeyName, Modifier, tmp: shortstring; |
9466 | 627 |
i, b: LongInt; |
8346 | 628 |
begin |
629 |
KeyName:= ''; |
|
630 |
Modifier:= ''; |
|
631 |
||
9466 | 632 |
if(Pos('mod:', id) <> 0)then |
8346 | 633 |
begin |
634 |
tmp:= ''; |
|
635 |
SplitBySpace(id, tmp); |
|
636 |
Modifier:= id; |
|
637 |
id:= tmp; |
|
638 |
end; |
|
639 |
||
640 |
SplitBySpace(id, KeyName); |
|
641 |
if KeyName[1]='"' then |
|
642 |
Delete(KeyName, 1, 1); |
|
643 |
if KeyName[byte(KeyName[0])]='"' then |
|
644 |
Delete(KeyName, byte(KeyName[0]), 1); |
|
645 |
b:= KeyNameToCode(id, Modifier); |
|
646 |
if b = 0 then |
|
647 |
OutError(errmsgUnknownVariable + ' "' + id + '"', false) |
|
648 |
else |
|
10015 | 649 |
begin |
9466 | 650 |
// add bind: first check if this cmd is already bound, and remove old bind |
651 |
i:= cKbdMaxIndex; |
|
652 |
repeat |
|
653 |
dec(i) |
|
654 |
until (i < 0) or (binds[i] = KeyName); |
|
655 |
if (i >= 0) then |
|
656 |
binds[i]:= ''; |
|
657 |
||
658 |
binds[b]:= KeyName; |
|
659 |
end |
|
660 |
end; |
|
661 |
||
662 |
// Bind that isn't a team bind, but overrides defaultbinds. |
|
663 |
procedure chDefaultBind(var id: shortstring); |
|
664 |
begin |
|
665 |
addBind(DefaultBinds, id) |
|
8346 | 666 |
end; |
667 |
||
3038 | 668 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
669 |
begin |
11486 | 670 |
// assign 0 until InitKbdKeyTable is called |
671 |
mwheelupCode:= 0; |
|
672 |
mwheeldownCode:= 0; |
|
673 |
||
8346 | 674 |
RegisterVariable('dbind', @chDefaultBind, true ); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
675 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
676 |
|
3038 | 677 |
procedure freeModule; |
7026
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
678 |
var j: LongInt; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
679 |
begin |
7026
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
680 |
// close gamepad controllers |
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
681 |
if ControllerEnabled > 0 then |
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
682 |
for j:= 0 to pred(ControllerNumControllers) do |
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
683 |
SDL_JoystickClose(Controller[j]); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
684 |
end; |
4 | 685 |
|
686 |
end. |