author | Wuzzy <Wuzzy2@mail.ru> |
Thu, 08 Mar 2018 23:36:16 +0100 | |
changeset 13133 | 733f3154198c |
parent 13131 | f10f4bf5f84d |
child 13132 | 52178e8ffdfc |
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; |
13068 | 102 |
var code, index: LongInt; |
13042
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
103 |
begin |
13068 | 104 |
index:= 0; |
105 |
while (index <= High(CurrentBinds.binds)) and (CurrentBinds.binds[index] <> bind) do inc(index); |
|
106 |
if index > High(CurrentBinds.binds) then |
|
13042
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 |
13068 | 109 |
else begin |
110 |
code:= 0; |
|
111 |
while (code <= High(CurrentBinds.indices)) and (CurrentBinds.indices[code] <> index) do inc(code); |
|
112 |
checkFails(code <= High(CurrentBinds.indices), 'binds registry inconsistency', True); |
|
13042
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
113 |
KeyBindToCode:= code; |
13068 | 114 |
end; |
13042
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
115 |
end; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
116 |
|
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
117 |
// 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
|
118 |
// human-readable key name from SDL. |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
119 |
// 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
|
120 |
// longer hardcodes any key name. |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
121 |
// TODO: Localize |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
122 |
function KeyBindToName(bind: shortstring): ansistring; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
123 |
var code: LongInt; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
124 |
name: ansistring; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
125 |
begin |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
126 |
code:= KeyBindToCode(bind); |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
127 |
if code = -1 then |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
128 |
KeyBindToName:= trmsg[sidUnknownKey] |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
129 |
else |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
130 |
begin |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
131 |
name:= SDL_GetKeyName(SDL_GetKeyFromScancode(code)); |
13045
25a9260244f3
InputHandler: Shorten "Escape" to "Esc"
Wuzzy <Wuzzy2@mail.ru>
parents:
13042
diff
changeset
|
132 |
if (name = 'Escape') then |
25a9260244f3
InputHandler: Shorten "Escape" to "Esc"
Wuzzy <Wuzzy2@mail.ru>
parents:
13042
diff
changeset
|
133 |
// Let's shorten the name “Escape” for the quit menu |
25a9260244f3
InputHandler: Shorten "Escape" to "Esc"
Wuzzy <Wuzzy2@mail.ru>
parents:
13042
diff
changeset
|
134 |
KeyBindToName:= 'Esc' |
25a9260244f3
InputHandler: Shorten "Escape" to "Esc"
Wuzzy <Wuzzy2@mail.ru>
parents:
13042
diff
changeset
|
135 |
else if (name <> '') then |
13042
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
136 |
KeyBindToName:= name |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
137 |
else |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
138 |
begin |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
139 |
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
|
140 |
KeyBindToName:= trmsg[sidUnknownKey]; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
141 |
end; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
142 |
end; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
143 |
end; |
29357016f374
uInputManager: Add functions to get SDL key name
Wuzzy <Wuzzy2@mail.ru>
parents:
12997
diff
changeset
|
144 |
|
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
|
145 |
(* |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
146 |
procedure MaskModifier(var code: LongInt; Modifier: LongWord); |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
147 |
begin |
8330 | 148 |
if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT; |
149 |
if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT; |
|
150 |
if(Modifier and KMOD_LALT) <> 0 then code:= code or LALT; |
|
151 |
if(Modifier and KMOD_RALT) <> 0 then code:= code or LALT; |
|
152 |
if(Modifier and KMOD_LCTRL) <> 0 then code:= code or LCTRL; |
|
153 |
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
|
154 |
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
|
155 |
*) |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
156 |
procedure MaskModifier(Modifier: shortstring; var code: LongInt); |
10015 | 157 |
var mod_ : shortstring = ''; |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
158 |
ModifierCount, i: LongInt; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
159 |
begin |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
160 |
if Modifier = '' then exit; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
161 |
ModifierCount:= 0; |
7202 | 162 |
|
163 |
for i:= 1 to Length(Modifier) do |
|
164 |
if(Modifier[i] = ':') then inc(ModifierCount); |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
165 |
|
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
166 |
SplitByChar(Modifier, mod_, ':');//remove the first mod: part |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
167 |
Modifier:= mod_; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
168 |
for i:= 0 to ModifierCount do |
8330 | 169 |
begin |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
170 |
mod_:= ''; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
171 |
SplitByChar(Modifier, mod_, ':'); |
7193 | 172 |
if (Modifier = 'lshift') then code:= code or LSHIFT; |
173 |
if (Modifier = 'rshift') then code:= code or RSHIFT; |
|
174 |
if (Modifier = 'lalt') then code:= code or LALT; |
|
175 |
if (Modifier = 'ralt') then code:= code or RALT; |
|
176 |
if (Modifier = 'lctrl') or (mod_ = 'lmeta') then code:= code or LCTRL; |
|
177 |
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
|
178 |
Modifier:= mod_; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
179 |
end; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
180 |
end; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
181 |
|
6917 | 182 |
procedure ProcessKey(code: LongInt; KeyDown: boolean); |
183 |
var |
|
184 |
Trusted: boolean; |
|
185 |
s : string; |
|
186 |
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
|
187 |
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
|
188 |
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
|
189 |
|
6917 | 190 |
Trusted:= (CurrentTeam <> nil) |
191 |
and (not CurrentTeam^.ExtDriven) |
|
192 |
and (CurrentHedgehog^.BotLevel = 0); |
|
9714 | 193 |
// REVIEW OR FIXME |
194 |
// 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. |
|
195 |
// There's no confirmation at all |
|
6942 | 196 |
// 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
|
197 |
if(KeyDown and (code = SDLK_q)) then |
6942 | 198 |
begin |
199 |
{$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
|
200 |
if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then |
6942 | 201 |
{$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
|
202 |
if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then |
6942 | 203 |
{$ENDIF} |
7869
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
204 |
ParseCommand('halt', true); |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
205 |
end; |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
206 |
|
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
207 |
// ctrl/cmd + w to close engine |
8746
55539c550c33
use SDL keycode for shortcuts (doesn't fix layout issues)
koda
parents:
8370
diff
changeset
|
208 |
if(KeyDown and (code = SDLK_w)) then |
7869
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
209 |
begin |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
210 |
{$IFDEF DARWIN} |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
211 |
// on OS X it this is expected behaviour |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
212 |
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
|
213 |
{$ELSE} |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
214 |
// 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
|
215 |
if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then |
13068 | 216 |
if ((CurrentBinds.indices[KeyNameToCode('left_ctrl')] = 0) or |
217 |
(CurrentBinds.indices[KeyNameToCode('right_ctrl')] = 0)) and |
|
218 |
(CurrentBinds.indices[SDLK_w] = 0) then |
|
7869
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
219 |
{$ENDIF} |
5dd2c047c96f
close engine shortcut, from the discussion in issue 317
koda
parents:
7848
diff
changeset
|
220 |
ParseCommand('forcequit', true); |
6942 | 221 |
end; |
222 |
||
13068 | 223 |
if CurrentBinds.indices[code] > 0 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
224 |
begin |
9694 | 225 |
if (code < cKeyMaxIndex - 2) // means not mouse buttons |
226 |
and KeyDown |
|
13068 | 227 |
and (not ((CurrentBinds.binds[CurrentBinds.indices[code]] = 'put') |
228 |
or (CurrentBinds.binds[CurrentBinds.indices[code]] = 'ammomenu') |
|
229 |
or (CurrentBinds.binds[CurrentBinds.indices[code]] = '+cur_u') |
|
230 |
or (CurrentBinds.binds[CurrentBinds.indices[code]] = '+cur_d') |
|
231 |
or (CurrentBinds.binds[CurrentBinds.indices[code]] = '+cur_l') |
|
232 |
or (CurrentBinds.binds[CurrentBinds.indices[code]] = '+cur_r'))) |
|
9694 | 233 |
and (CurrentTeam <> nil) |
234 |
and (not CurrentTeam^.ExtDriven) |
|
235 |
then bShowAmmoMenu:= false; |
|
7118 | 236 |
|
7140
29948153fda2
Don't allow for multiple key up(or down) events, it will ignore the excess events
Xeli
parents:
7118
diff
changeset
|
237 |
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
|
238 |
begin |
10392 | 239 |
Trusted:= Trusted and (not isPaused); //releasing keys during pause should be allowed on the other hand |
10510 | 240 |
|
13068 | 241 |
if CurrentBinds.binds[CurrentBinds.indices[code]] = 'switch' then |
9714 | 242 |
LocalMessage:= LocalMessage or gmSwitch |
13068 | 243 |
else if CurrentBinds.binds[CurrentBinds.indices[code]] = '+precise' then |
9714 | 244 |
LocalMessage:= LocalMessage or gmPrecise; |
10015 | 245 |
|
13068 | 246 |
ParseCommand(CurrentBinds.binds[CurrentBinds.indices[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
|
247 |
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
|
248 |
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
|
249 |
end |
13068 | 250 |
else if (CurrentBinds.binds[CurrentBinds.indices[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
|
251 |
begin |
13068 | 252 |
if CurrentBinds.binds[CurrentBinds.indices[code]] = '+precise' then |
9954 | 253 |
LocalMessage:= LocalMessage and (not gmPrecise); |
13068 | 254 |
s:= CurrentBinds.binds[CurrentBinds.indices[code]]; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
255 |
s[1]:= '-'; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
256 |
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
|
257 |
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
|
258 |
ParseCommand('gencmd R', true) |
9693 | 259 |
end |
260 |
else |
|
261 |
begin |
|
13068 | 262 |
if CurrentBinds.binds[CurrentBinds.indices[code]] = 'switch' then |
9954 | 263 |
LocalMessage:= LocalMessage and (not gmSwitch) |
9693 | 264 |
end |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
265 |
end |
6917 | 266 |
end; |
267 |
||
9691 | 268 |
procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
269 |
var code: LongInt; |
|
270 |
begin |
|
11365 | 271 |
// TODO |
272 |
code:= LongInt(event.keysym.scancode); |
|
9694 | 273 |
//writelntoconsole('[KEY] '+inttostr(code)+ ' -> ''' +KeyNames[code] + ''', type = '+inttostr(event.type_)); |
9691 | 274 |
ProcessKey(code, event.type_ = SDL_KEYDOWN); |
275 |
end; |
|
6917 | 276 |
|
277 |
procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean); |
|
278 |
begin |
|
9694 | 279 |
//writelntoconsole('[MOUSE] '+inttostr(event.button)); |
280 |
case event.button of |
|
281 |
SDL_BUTTON_LEFT: |
|
282 |
ProcessKey(KeyNameToCode('mousel'), ButtonDown); |
|
283 |
SDL_BUTTON_MIDDLE: |
|
284 |
ProcessKey(KeyNameToCode('mousem'), ButtonDown); |
|
285 |
SDL_BUTTON_RIGHT: |
|
286 |
ProcessKey(KeyNameToCode('mouser'), ButtonDown); |
|
287 |
end; |
|
288 |
end; |
|
289 |
||
11486 | 290 |
var mwheelupCode, mwheeldownCode: Integer; |
291 |
||
12621 | 292 |
//procedure ProcessMouseWheel(x, y: LongInt); |
293 |
procedure ProcessMouseWheel(y: LongInt); |
|
9694 | 294 |
begin |
12621 | 295 |
// we don't use |
9694 | 296 |
//writelntoconsole('[MOUSEWHEEL] '+inttostr(x)+', '+inttostr(y)); |
297 |
if y > 0 then |
|
11486 | 298 |
begin |
299 |
// reset other direction |
|
300 |
if tkbd[mwheeldownCode] then |
|
301 |
ProcessKey(mwheeldownCode, false); |
|
302 |
// trigger "button down" event |
|
303 |
if (not tkbd[mwheelupCode]) then |
|
304 |
ProcessKey(mwheelupCode, true); |
|
305 |
end |
|
9694 | 306 |
else if y < 0 then |
11486 | 307 |
begin |
308 |
// reset other direction |
|
309 |
if tkbd[mwheelupCode] then |
|
310 |
ProcessKey(mwheelupCode, false); |
|
311 |
// trigger "button down" event |
|
312 |
if (not tkbd[mwheeldownCode]) then |
|
313 |
ProcessKey(mwheeldownCode, true); |
|
314 |
end; |
|
315 |
end; |
|
316 |
||
317 |
procedure ResetMouseWheel(); |
|
318 |
begin |
|
319 |
if tkbd[mwheelupCode] then |
|
320 |
ProcessKey(mwheelupCode, false); |
|
321 |
if tkbd[mwheeldownCode] then |
|
322 |
ProcessKey(mwheeldownCode, false); |
|
4 | 323 |
end; |
324 |
||
325 |
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
|
326 |
var t: LongInt; |
4 | 327 |
begin |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7184
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
ProcessKey(t, False); |
4 | 331 |
end; |
332 |
||
13068 | 333 |
procedure RegisterBind(var binds: TBinds; key, value: shortstring); |
334 |
var code: LongInt; |
|
335 |
begin |
|
336 |
checkFails(binds.lastIndex < 255, 'too many binds', true); |
|
337 |
||
338 |
code:= KeyNameToCode(key); |
|
339 |
||
340 |
checkFails(code >= 0, 'unknown key', true); |
|
341 |
||
342 |
inc(binds.lastIndex); |
|
343 |
binds.indices[code]:= binds.lastIndex; |
|
344 |
binds.binds[binds.lastIndex]:= value |
|
345 |
end; |
|
9691 | 346 |
|
347 |
procedure InitDefaultBinds; |
|
348 |
var i: Longword; |
|
349 |
begin |
|
13068 | 350 |
RegisterBind(DefaultBinds, 'escape', 'quit'); |
351 |
RegisterBind(DefaultBinds, _S'`', 'history'); |
|
352 |
RegisterBind(DefaultBinds, 'delete', 'rotmask'); |
|
353 |
RegisterBind(DefaultBinds, 'home', 'rottags'); |
|
9691 | 354 |
|
355 |
//numpad |
|
356 |
//DefaultBinds[265]:= '+volup'; |
|
357 |
//DefaultBinds[256]:= '+voldown'; |
|
358 |
||
13068 | 359 |
RegisterBind(DefaultBinds, _S'0', '+volup'); |
360 |
RegisterBind(DefaultBinds, _S'9', '+voldown'); |
|
361 |
RegisterBind(DefaultBinds, _S'8', 'mute'); |
|
362 |
RegisterBind(DefaultBinds, _S'c', 'capture'); |
|
363 |
RegisterBind(DefaultBinds, _S'r', 'record'); |
|
364 |
RegisterBind(DefaultBinds, _S'h', 'findhh'); |
|
365 |
RegisterBind(DefaultBinds, _S'p', 'pause'); |
|
366 |
RegisterBind(DefaultBinds, _S's', '+speedup'); |
|
367 |
RegisterBind(DefaultBinds, _S't', 'chat'); |
|
368 |
RegisterBind(DefaultBinds, _S'y', 'confirm'); |
|
9691 | 369 |
|
13068 | 370 |
RegisterBind(DefaultBinds, 'mousem', 'zoomreset'); |
371 |
RegisterBind(DefaultBinds, 'wheelup', 'zoomin'); |
|
372 |
RegisterBind(DefaultBinds, 'wheeldown', 'zoomout'); |
|
9691 | 373 |
|
13068 | 374 |
RegisterBind(DefaultBinds, 'f12', 'fullscr'); |
9691 | 375 |
|
376 |
||
13068 | 377 |
RegisterBind(DefaultBinds, 'mousel', '/put'); |
378 |
RegisterBind(DefaultBinds, 'mouser', 'ammomenu'); |
|
379 |
RegisterBind(DefaultBinds, 'backspace', 'hjump'); |
|
380 |
RegisterBind(DefaultBinds, 'tab', 'switch'); |
|
381 |
RegisterBind(DefaultBinds, 'return', 'ljump'); |
|
382 |
RegisterBind(DefaultBinds, 'space', '+attack'); |
|
383 |
RegisterBind(DefaultBinds, 'up', '+up'); |
|
384 |
RegisterBind(DefaultBinds, 'down', '+down'); |
|
385 |
RegisterBind(DefaultBinds, 'left', '+left'); |
|
386 |
RegisterBind(DefaultBinds, 'right', '+right'); |
|
387 |
RegisterBind(DefaultBinds, 'left_shift', '+precise'); |
|
9691 | 388 |
|
389 |
||
13068 | 390 |
RegisterBind(DefaultBinds, 'j0a0u', '+left'); |
391 |
RegisterBind(DefaultBinds, 'j0a0d', '+right'); |
|
392 |
RegisterBind(DefaultBinds, 'j0a1u', '+up'); |
|
393 |
RegisterBind(DefaultBinds, 'j0a1d', '+down'); |
|
394 |
for i:= 1 to 10 do RegisterBind(DefaultBinds, 'f'+IntToStr(i), 'slot '+char(48+i)); |
|
395 |
for i:= 1 to 5 do RegisterBind(DefaultBinds, IntToStr(i), 'timer '+IntToStr(i)); |
|
9691 | 396 |
|
12106
9bc19f722169
Bug #108 - Phyfs/Pathz: Fix binds not being loaded
sheepluva
parents:
11664
diff
changeset
|
397 |
loadBinds('dbind', cPathz[ptConfig] + '/settings.ini'); |
9691 | 398 |
end; |
399 |
||
400 |
||
401 |
procedure InitKbdKeyTable; |
|
402 |
var i, j, k, t: LongInt; |
|
403 |
s: string[15]; |
|
404 |
begin |
|
405 |
KeyNames[cKeyMaxIndex ]:= 'mousel'; |
|
406 |
KeyNames[cKeyMaxIndex - 1]:= 'mousem'; |
|
407 |
KeyNames[cKeyMaxIndex - 2]:= 'mouser'; |
|
11486 | 408 |
mwheelupCode:= cKeyMaxIndex - 3; |
409 |
KeyNames[mwheelupCode]:= 'wheelup'; |
|
410 |
mwheeldownCode:= cKeyMaxIndex - 4; |
|
411 |
KeyNames[mwheeldownCode]:= 'wheeldown'; |
|
9691 | 412 |
|
413 |
for i:= 0 to cKeyMaxIndex - 5 do |
|
414 |
begin |
|
11365 | 415 |
s:= shortstring(SDL_GetScancodeName(TSDL_Scancode(i))); |
9691 | 416 |
|
417 |
for t:= 1 to Length(s) do |
|
418 |
if s[t] = ' ' then |
|
419 |
s[t]:= '_'; |
|
420 |
KeyNames[i]:= LowerCase(s) |
|
421 |
end; |
|
422 |
||
423 |
||
424 |
// 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
|
425 |
SDL_GetKeyboardState(@k); |
9691 | 426 |
|
427 |
// Controller(s) |
|
428 |
for j:= 0 to Pred(ControllerNumControllers) do |
|
429 |
begin |
|
430 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
431 |
begin |
|
432 |
KeyNames[k + 0]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'u'; |
|
433 |
KeyNames[k + 1]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'd'; |
|
434 |
inc(k, 2); |
|
435 |
end; |
|
436 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
437 |
begin |
|
438 |
KeyNames[k + 0]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'u'; |
|
439 |
KeyNames[k + 1]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'r'; |
|
440 |
KeyNames[k + 2]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'd'; |
|
441 |
KeyNames[k + 3]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'l'; |
|
442 |
inc(k, 4); |
|
443 |
end; |
|
444 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
445 |
begin |
|
446 |
KeyNames[k]:= 'j' + IntToStr(j) + 'b' + IntToStr(i); |
|
447 |
inc(k, 1); |
|
448 |
end; |
|
449 |
end; |
|
450 |
||
451 |
InitDefaultBinds |
|
452 |
end; |
|
2606
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
453 |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
454 |
|
2786 | 455 |
|
9691 | 456 |
{$IFNDEF MOBILE} |
167 | 457 |
procedure SetBinds(var binds: TBinds); |
7184
211ab9e2cb15
only reset those keys which actually change their bindings
Xeli
parents:
7151
diff
changeset
|
458 |
var |
211ab9e2cb15
only reset those keys which actually change their bindings
Xeli
parents:
7151
diff
changeset
|
459 |
t: LongInt; |
167 | 460 |
begin |
8346 | 461 |
for t:= 0 to cKbdMaxIndex do |
13068 | 462 |
if (CurrentBinds.binds[CurrentBinds.indices[t]] <> binds.binds[binds.indices[t]]) and tkbd[t] then |
8346 | 463 |
ProcessKey(t, False); |
7184
211ab9e2cb15
only reset those keys which actually change their bindings
Xeli
parents:
7151
diff
changeset
|
464 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
465 |
CurrentBinds:= binds; |
9691 | 466 |
end; |
467 |
{$ELSE} |
|
468 |
procedure SetBinds(var binds: TBinds); |
|
469 |
begin |
|
470 |
binds:= binds; // avoid hint |
|
471 |
CurrentBinds:= DefaultBinds; |
|
472 |
end; |
|
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3651
diff
changeset
|
473 |
{$ENDIF} |
167 | 474 |
|
475 |
procedure SetDefaultBinds; |
|
476 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
477 |
CurrentBinds:= DefaultBinds; |
167 | 478 |
end; |
479 |
||
948 | 480 |
procedure FreezeEnterKey; |
481 |
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
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
tkbd[271]:= True; |
948 | 486 |
end; |
167 | 487 |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
488 |
var Controller: array [0..5] of PSDL_Joystick; |
3697 | 489 |
|
2428 | 490 |
procedure ControllerInit; |
8370 | 491 |
var j: Integer; |
2428 | 492 |
begin |
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3651
diff
changeset
|
493 |
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
|
494 |
{$IFDEF IPHONE} |
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3651
diff
changeset
|
495 |
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
|
496 |
{$ENDIF} |
2674
2fce032f2f95
lupdate + Palewolf's updated spanish translation + other patches of mine
koda
parents:
2671
diff
changeset
|
497 |
|
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3651
diff
changeset
|
498 |
SDL_InitSubSystem(SDL_INIT_JOYSTICK); |
2674
2fce032f2f95
lupdate + Palewolf's updated spanish translation + other patches of mine
koda
parents:
2671
diff
changeset
|
499 |
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
|
500 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
501 |
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
|
502 |
ControllerNumControllers:= 6; |
2428 | 503 |
|
4374 | 504 |
WriteLnToConsole('Number of game controllers: ' + IntToStr(ControllerNumControllers)); |
2428 | 505 |
|
506 |
if ControllerNumControllers > 0 then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
507 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
508 |
for j:= 0 to pred(ControllerNumControllers) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
509 |
begin |
7151 | 510 |
WriteLnToConsole('Using game controller: ' + shortstring(SDL_JoystickName(j))); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
511 |
Controller[j]:= SDL_JoystickOpen(j); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
512 |
if Controller[j] = nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
513 |
WriteLnToConsole('* Failed to open game controller!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
514 |
else |
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 |
ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
517 |
//ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
518 |
ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
519 |
ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
4374 | 520 |
WriteLnToConsole('* Number of axes: ' + IntToStr(ControllerNumAxes[j])); |
521 |
//WriteLnToConsole('* Number of balls: ' + IntToStr(ControllerNumBalls[j])); |
|
522 |
WriteLnToConsole('* Number of hats: ' + IntToStr(ControllerNumHats[j])); |
|
523 |
WriteLnToConsole('* Number of buttons: ' + IntToStr(ControllerNumButtons[j])); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
524 |
ControllerEnabled:= 1; |
3697 | 525 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
526 |
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
|
527 |
ControllerNumAxes[j]:= 20; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
528 |
//if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
8330 | 529 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
530 |
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
|
531 |
ControllerNumHats[j]:= 20; |
8330 | 532 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6497
diff
changeset
|
533 |
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
|
534 |
ControllerNumButtons[j]:= 20; |
3697 | 535 |
|
8370 | 536 |
(*// reset all buttons/axes |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
537 |
for i:= 0 to pred(ControllerNumAxes[j]) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
538 |
ControllerAxes[j][i]:= 0; |
8370 | 539 |
for i:= 0 to pred(ControllerNumBalls[j]) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
540 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
541 |
ControllerBalls[j][i][0]:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
542 |
ControllerBalls[j][i][1]:= 0; |
8370 | 543 |
end; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
544 |
for i:= 0 to pred(ControllerNumHats[j]) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
545 |
ControllerHats[j][i]:= SDL_HAT_CENTERED; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
546 |
for i:= 0 to pred(ControllerNumButtons[j]) do |
8370 | 547 |
ControllerButtons[j][i]:= 0;*) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
548 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
549 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
550 |
// enable event generation/controller updating |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
551 |
SDL_JoystickEventState(1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
552 |
end |
3697 | 553 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
554 |
WriteLnToConsole('Not using any game controller'); |
2428 | 555 |
end; |
556 |
||
557 |
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
|
558 |
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
|
559 |
k: LongInt; |
2428 | 560 |
begin |
11368
c481d087f653
cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents:
11365
diff
changeset
|
561 |
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
|
562 |
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
|
563 |
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
|
564 |
ProcessKey(k + (axis*2)+1, value < -20000); |
2428 | 565 |
end; |
566 |
||
567 |
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
|
568 |
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
|
569 |
k: LongInt; |
2428 | 570 |
begin |
11368
c481d087f653
cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents:
11365
diff
changeset
|
571 |
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
|
572 |
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
|
573 |
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
|
574 |
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
|
575 |
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
|
576 |
ProcessKey(k + ControllerNumAxes[joy]*2 + hat*4 + 3, (value and SDL_HAT_LEFT) <> 0); |
2428 | 577 |
end; |
578 |
||
579 |
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
|
580 |
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
|
581 |
k: LongInt; |
2428 | 582 |
begin |
11368
c481d087f653
cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents:
11365
diff
changeset
|
583 |
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
|
584 |
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
|
585 |
ProcessKey(k + ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + button, pressed); |
2428 | 586 |
end; |
587 |
||
9466 | 588 |
procedure loadBinds(cmd, s: shortstring); |
589 |
var i: LongInt; |
|
590 |
f: PFSFile; |
|
591 |
p, l: shortstring; |
|
592 |
b: byte; |
|
593 |
begin |
|
10139 | 594 |
if cOnlyStats then exit; |
10510 | 595 |
|
9466 | 596 |
AddFileLog('[BINDS] Loading binds from: ' + s); |
597 |
||
598 |
l:= ''; |
|
599 |
if pfsExists(s) then |
|
600 |
begin |
|
601 |
f:= pfsOpenRead(s); |
|
602 |
while (not pfsEOF(f)) and (l <> '[Binds]') do |
|
603 |
pfsReadLn(f, l); |
|
604 |
||
605 |
while (not pfsEOF(f)) and (l <> '') do |
|
606 |
begin |
|
607 |
pfsReadLn(f, l); |
|
608 |
||
609 |
p:= ''; |
|
610 |
i:= 1; |
|
611 |
while (i <= length(l)) and (l[i] <> '=') do |
|
612 |
begin |
|
9981 | 613 |
if l[i] = '%' then |
9466 | 614 |
begin |
615 |
l[i]:= '$'; |
|
616 |
val(copy(l, i, 3), b); |
|
617 |
p:= p + char(b); |
|
618 |
inc(i, 3) |
|
10015 | 619 |
end |
9981 | 620 |
else |
621 |
begin |
|
622 |
p:= p + l[i]; |
|
623 |
inc(i) |
|
9466 | 624 |
end; |
625 |
end; |
|
626 |
||
627 |
if i < length(l) then |
|
628 |
begin |
|
629 |
l:= copy(l, i + 1, length(l) - i); |
|
630 |
if l <> 'default' then |
|
631 |
begin |
|
10015 | 632 |
if (length(l) = 2) and (l[1] = '\') then |
10080 | 633 |
l:= l[1] + '' |
9981 | 634 |
else if (l[1] = '"') and (l[length(l)] = '"') then |
635 |
l:= copy(l, 2, length(l) - 2); |
|
636 |
||
9466 | 637 |
p:= cmd + ' ' + l + ' ' + p; |
638 |
ParseCommand(p, true) |
|
639 |
end |
|
640 |
end |
|
641 |
end; |
|
642 |
||
643 |
pfsClose(f) |
|
10015 | 644 |
end |
9466 | 645 |
else |
646 |
AddFileLog('[BINDS] file not found'); |
|
647 |
end; |
|
648 |
||
649 |
||
650 |
procedure addBind(var binds: TBinds; var id: shortstring); |
|
8346 | 651 |
var KeyName, Modifier, tmp: shortstring; |
13068 | 652 |
i, code, b: LongInt; |
8346 | 653 |
begin |
654 |
KeyName:= ''; |
|
655 |
Modifier:= ''; |
|
656 |
||
9466 | 657 |
if(Pos('mod:', id) <> 0)then |
8346 | 658 |
begin |
659 |
tmp:= ''; |
|
660 |
SplitBySpace(id, tmp); |
|
661 |
Modifier:= id; |
|
662 |
id:= tmp; |
|
663 |
end; |
|
664 |
||
665 |
SplitBySpace(id, KeyName); |
|
666 |
if KeyName[1]='"' then |
|
667 |
Delete(KeyName, 1, 1); |
|
668 |
if KeyName[byte(KeyName[0])]='"' then |
|
669 |
Delete(KeyName, byte(KeyName[0]), 1); |
|
670 |
b:= KeyNameToCode(id, Modifier); |
|
671 |
if b = 0 then |
|
672 |
OutError(errmsgUnknownVariable + ' "' + id + '"', false) |
|
673 |
else |
|
13131 | 674 |
begin |
9466 | 675 |
// add bind: first check if this cmd is already bound, and remove old bind |
13131 | 676 |
i:= Low(binds.binds); |
677 |
while (i <= High(binds.binds)) and (binds.binds[i] <> KeyName) do |
|
678 |
inc(i); |
|
679 |
||
680 |
if (i <= High(binds.binds)) then |
|
13068 | 681 |
begin |
13131 | 682 |
code:= Low(binds.indices); |
683 |
while (code <= High(binds.indices)) and (binds.indices[code] <> i) do |
|
684 |
inc(code); |
|
685 |
||
686 |
checkFails(code <= High(binds.indices), 'binds registry inconsistency', true); |
|
687 |
||
688 |
if allOk then |
|
689 |
binds.indices[code]:= 0 |
|
13068 | 690 |
end else |
691 |
begin |
|
692 |
inc(binds.lastIndex); |
|
693 |
checkFails(binds.lastIndex < High(binds.binds), 'too many binds', true); |
|
694 |
i:= binds.lastIndex |
|
695 |
end; |
|
9466 | 696 |
|
13068 | 697 |
binds.indices[b]:= i; |
698 |
binds.binds[i]:= KeyName |
|
9466 | 699 |
end |
700 |
end; |
|
701 |
||
702 |
// Bind that isn't a team bind, but overrides defaultbinds. |
|
703 |
procedure chDefaultBind(var id: shortstring); |
|
704 |
begin |
|
705 |
addBind(DefaultBinds, id) |
|
8346 | 706 |
end; |
707 |
||
3038 | 708 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
709 |
begin |
11486 | 710 |
// assign 0 until InitKbdKeyTable is called |
711 |
mwheelupCode:= 0; |
|
712 |
mwheeldownCode:= 0; |
|
713 |
||
8346 | 714 |
RegisterVariable('dbind', @chDefaultBind, true ); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
715 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
716 |
|
3038 | 717 |
procedure freeModule; |
7026
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
718 |
var j: LongInt; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
719 |
begin |
7026
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
720 |
// close gamepad controllers |
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
721 |
if ControllerEnabled > 0 then |
8d1724e1337e
split OnDestroy across the appropriate modules (this doen't cause leaks on mobile, right?)
koda
parents:
6994
diff
changeset
|
722 |
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
|
723 |
SDL_JoystickClose(Controller[j]); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2714
diff
changeset
|
724 |
end; |
4 | 725 |
|
726 |
end. |