author | koda |
Sun, 25 Oct 2009 23:52:36 +0000 | |
changeset 2590 | e7e87e3c67db |
parent 2586 | 204e6b2885bc |
child 2591 | c6597b65caea |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 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 |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uKeys; |
|
20 |
interface |
|
345 | 21 |
uses uConsts; |
4 | 22 |
{$INCLUDE options.inc} |
167 | 23 |
|
24 |
type TBinds = array[0..cKeyMaxIndex] of shortstring; |
|
2567 | 25 |
type TKeyboardState = array[0..cKeyMaxIndex] of Byte; |
4 | 26 |
|
2567 | 27 |
function KeyNameToCode(name: string): word; |
4 | 28 |
procedure ProcessKbd; |
29 |
procedure ResetKbd; |
|
948 | 30 |
procedure FreezeEnterKey; |
4 | 31 |
procedure InitKbdKeyTable; |
32 |
||
167 | 33 |
procedure SetBinds(var binds: TBinds); |
34 |
procedure SetDefaultBinds; |
|
35 |
||
2428 | 36 |
procedure ControllerInit; |
37 |
procedure ControllerClose; |
|
38 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
39 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
40 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
41 |
||
42 |
var hideAmmoMenu: boolean; |
|
2379 | 43 |
wheelUp: boolean = false; |
44 |
wheelDown: boolean = false; |
|
2586
204e6b2885bc
added little/big endian checks, added symbol for touch input, simplified iphoneos definitions
koda
parents:
2581
diff
changeset
|
45 |
{$IFDEF TOUCHINPUT} |
2567 | 46 |
leftClick: boolean = false; |
47 |
middleClick: boolean = false; |
|
48 |
rightClick: boolean = false; |
|
161 | 49 |
|
2567 | 50 |
upKey: boolean = false; |
51 |
downKey: boolean = false; |
|
52 |
rightKey: boolean = false; |
|
53 |
leftKey: boolean = false; |
|
54 |
||
2579 | 55 |
backspaceKey: boolean = false; |
2567 | 56 |
spaceKey: boolean = false; |
57 |
enterKey: boolean = false; |
|
2590 | 58 |
tabKey: boolean = false; |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
59 |
|
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
60 |
isAttacking: boolean = false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
61 |
isWalking: boolean = false; |
2579 | 62 |
|
2567 | 63 |
{$ENDIF} |
2428 | 64 |
ControllerNumControllers: Integer; |
65 |
ControllerEnabled: Integer; |
|
66 |
ControllerNumAxes: array[0..5] of Integer; |
|
67 |
//ControllerNumBalls: array[0..5] of Integer; |
|
68 |
ControllerNumHats: array[0..5] of Integer; |
|
69 |
ControllerNumButtons: array[0..5] of Integer; |
|
70 |
ControllerAxes: array[0..5] of array[0..19] of Integer; |
|
71 |
//ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer; |
|
72 |
ControllerHats: array[0..5] of array[0..19] of Byte; |
|
73 |
ControllerButtons: array[0..5] of array[0..19] of Byte; |
|
74 |
||
4 | 75 |
implementation |
2222 | 76 |
uses SDLh, uTeams, uConsole, uMisc, uStore; |
109 | 77 |
const KeyNumber = 1024; |
167 | 78 |
|
2436 | 79 |
var tkbd, tkbdn: TKeyboardState; |
4 | 80 |
KeyNames: array [0..cKeyMaxIndex] of string[15]; |
167 | 81 |
DefaultBinds, CurrentBinds: TBinds; |
4 | 82 |
|
83 |
function KeyNameToCode(name: string): word; |
|
351 | 84 |
var Result: Word; |
4 | 85 |
begin |
86 |
Result:= cKeyMaxIndex; |
|
351 | 87 |
while (Result > 0) and (KeyNames[Result] <> name) do dec(Result); |
88 |
KeyNameToCode:= Result |
|
4 | 89 |
end; |
90 |
||
91 |
procedure ProcessKbd; |
|
2428 | 92 |
var i, j, k: LongInt; |
2436 | 93 |
s: shortstring; |
4 | 94 |
pkbd: PByteArray; |
167 | 95 |
Trusted: boolean; |
4 | 96 |
begin |
2428 | 97 |
hideAmmoMenu:= false; |
167 | 98 |
Trusted:= (CurrentTeam <> nil) |
351 | 99 |
and (not CurrentTeam^.ExtDriven) |
846 | 100 |
and (CurrentHedgehog^.BotLevel = 0); |
161 | 101 |
|
2428 | 102 |
// move cursor/camera |
103 |
// TODO: Scale on screen dimensions and/or axis value (game controller)? |
|
104 |
movecursor(5 * CursorMovementX, 5 * CursorMovementY); |
|
2436 | 105 |
|
2152 | 106 |
{$IFDEF SDL13} |
2436 | 107 |
pkbd := SDL_GetKeyboardState(@j); |
108 |
k := SDL_GetMouseState(0, nil, nil); |
|
2152 | 109 |
{$ELSE} |
2436 | 110 |
pkbd := SDL_GetKeyState(@j); |
111 |
k := SDL_GetMouseState(nil, nil); |
|
2152 | 112 |
{$ENDIF} |
2436 | 113 |
|
2579 | 114 |
{$IFNDEF IPHONEOS} |
2436 | 115 |
for i:= 6 to pred(j) do // first 6 will be overwritten |
116 |
tkbdn[i]:= pkbd^[i]; |
|
2579 | 117 |
{$ENDIF} |
2436 | 118 |
|
2379 | 119 |
// mouse buttons |
2152 | 120 |
{$IFDEF DARWIN} |
2436 | 121 |
tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305])); |
122 |
tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4); |
|
2152 | 123 |
{$ELSE} |
2436 | 124 |
tkbdn[1]:= (k and 1); |
125 |
tkbdn[3]:= ((k shr 2) and 1); |
|
2152 | 126 |
{$ENDIF} |
2436 | 127 |
tkbdn[2]:= ((k shr 1) and 1); |
2328 | 128 |
|
2379 | 129 |
// mouse wheels (see event loop in project file) |
2436 | 130 |
tkbdn[4]:= ord(wheelDown); |
131 |
tkbdn[5]:= ord(wheelUp); |
|
2379 | 132 |
wheelUp:= false; |
133 |
wheelDown:= false; |
|
2586
204e6b2885bc
added little/big endian checks, added symbol for touch input, simplified iphoneos definitions
koda
parents:
2581
diff
changeset
|
134 |
{$IFDEF TOUCHINPUT} |
2567 | 135 |
tkbdn[1]:= ord(leftClick); |
136 |
tkbdn[2]:= ord(middleClick); |
|
137 |
tkbdn[3]:= ord(rightClick); |
|
138 |
leftClick:= false; |
|
139 |
middleClick:= false; |
|
140 |
rightClick:= false; |
|
141 |
||
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
142 |
tkbdn[23]:= ord(upKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
143 |
tkbdn[24]:= ord(downKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
144 |
tkbdn[25]:= ord(leftKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
145 |
tkbdn[26]:= ord(rightKey); |
2567 | 146 |
|
2579 | 147 |
tkbdn[ 8]:= ord(backspaceKey); |
2590 | 148 |
tkbdn[ 9]:= ord(tabKey); |
2579 | 149 |
tkbdn[13]:= ord(enterKey); |
2567 | 150 |
tkbdn[32]:= ord(spaceKey); |
151 |
||
152 |
upKey:= false; |
|
153 |
downKey:= false; |
|
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
154 |
if isWalking = false then rightKey:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
155 |
if isWalking = false then leftKey:= false; |
2567 | 156 |
|
2579 | 157 |
if isAttacking = false then spaceKey:= false; |
2590 | 158 |
tabKey:= false; |
2567 | 159 |
enterKey:= false; |
2579 | 160 |
backspaceKey:= false; |
161 |
||
2567 | 162 |
{$ENDIF} |
2152 | 163 |
|
2428 | 164 |
// Controller(s) |
2436 | 165 |
k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
2428 | 166 |
for j:= 0 to Pred(ControllerNumControllers) do |
167 |
begin |
|
168 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
169 |
begin |
|
2436 | 170 |
if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; |
171 |
if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; |
|
2428 | 172 |
inc(k, 2); |
173 |
end; |
|
174 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
175 |
begin |
|
2436 | 176 |
tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
177 |
tkbdn[k + 1]:= ControllerHats[j][i] and SDL_HAT_RIGHT; |
|
178 |
tkbdn[k + 2]:= ControllerHats[j][i] and SDL_HAT_DOWN; |
|
179 |
tkbdn[k + 3]:= ControllerHats[j][i] and SDL_HAT_LEFT; |
|
2428 | 180 |
inc(k, 4); |
181 |
end; |
|
182 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
183 |
begin |
|
2436 | 184 |
tkbdn[k]:= ControllerButtons[j][i]; |
2428 | 185 |
inc(k, 1); |
186 |
end; |
|
187 |
end; |
|
188 |
||
2379 | 189 |
// now process strokes |
2436 | 190 |
for i:= 0 to cKeyMaxIndex do |
947 | 191 |
if CurrentBinds[i][0] <> #0 then |
192 |
begin |
|
2436 | 193 |
if (i > 3) and (tkbdn[i] <> 0) and not ((CurrentBinds[i] = 'put') or (CurrentBinds[i] = 'ammomenu') or (CurrentBinds[i] = '+cur_u') or (CurrentBinds[i] = '+cur_d') or (CurrentBinds[i] = '+cur_l') or (CurrentBinds[i] = '+cur_r')) then hideAmmoMenu:= true; |
194 |
if (tkbd[i] = 0) and (tkbdn[i] <> 0) then ParseCommand(CurrentBinds[i], Trusted) |
|
947 | 195 |
else if (CurrentBinds[i][1] = '+') |
2436 | 196 |
and (tkbdn[i] = 0) |
948 | 197 |
and (tkbd[i] <> 0) then |
947 | 198 |
begin |
199 |
s:= CurrentBinds[i]; |
|
200 |
s[1]:= '-'; |
|
201 |
ParseCommand(s, Trusted) |
|
202 |
end; |
|
2436 | 203 |
tkbd[i]:= tkbdn[i] |
204 |
end |
|
4 | 205 |
end; |
206 |
||
207 |
procedure ResetKbd; |
|
2590 | 208 |
var i, j, k, t: LongInt; |
4 | 209 |
pkbd: PByteArray; |
210 |
begin |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
211 |
|
2152 | 212 |
{$IFDEF SDL13} |
2436 | 213 |
pkbd:= SDL_GetKeyboardState(@j); |
2567 | 214 |
k:= SDL_GetMouseState(0, nil, nil); |
2152 | 215 |
{$ELSE} |
2436 | 216 |
pkbd:= SDL_GetKeyState(@j); |
2567 | 217 |
k:= SDL_GetMouseState(nil, nil); |
2152 | 218 |
{$ENDIF} |
2436 | 219 |
TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true); |
220 |
||
2579 | 221 |
{$IFNDEF IPHONEOS} |
2436 | 222 |
for i:= 1 to pred(j) do |
223 |
tkbdn[i]:= pkbd^[i]; |
|
2579 | 224 |
{$ENDIF} |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
225 |
|
2436 | 226 |
// mouse buttons |
227 |
{$IFDEF DARWIN} |
|
228 |
tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305])); |
|
229 |
tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4); |
|
230 |
{$ELSE} |
|
231 |
tkbdn[1]:= (k and 1); |
|
232 |
tkbdn[3]:= ((k shr 2) and 1); |
|
233 |
{$ENDIF} |
|
234 |
tkbdn[2]:= ((k shr 1) and 1); |
|
235 |
||
236 |
// mouse wheels (see event loop in project file) |
|
237 |
tkbdn[4]:= ord(wheelDown); |
|
238 |
tkbdn[5]:= ord(wheelUp); |
|
239 |
wheelUp:= false; |
|
240 |
wheelDown:= false; |
|
2567 | 241 |
{$IFDEF IPHONEOS} |
242 |
tkbdn[1]:= ord(leftClick); |
|
243 |
tkbdn[2]:= ord(middleClick); |
|
244 |
tkbdn[3]:= ord(rightClick); |
|
245 |
leftClick:= false; |
|
246 |
middleClick:= false; |
|
247 |
rightClick:= false; |
|
248 |
||
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
249 |
tkbdn[23]:= ord(upKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
250 |
tkbdn[24]:= ord(downKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
251 |
tkbdn[25]:= ord(leftKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
252 |
tkbdn[26]:= ord(rightKey); |
2567 | 253 |
|
2579 | 254 |
tkbdn[ 8]:= ord(backspaceKey); |
2590 | 255 |
tkbdn[ 9]:= ord(tabKey); |
2579 | 256 |
tkbdn[13]:= ord(enterKey); |
2567 | 257 |
tkbdn[32]:= ord(spaceKey); |
258 |
||
259 |
upKey:= false; |
|
260 |
downKey:= false; |
|
2590 | 261 |
tabKey:= false; |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
262 |
if isWalking = false then rightKey:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
263 |
if isWalking = false then leftKey:= false; |
2567 | 264 |
|
2579 | 265 |
if isAttacking = false then spaceKey:= false; |
2567 | 266 |
enterKey:= false; |
2579 | 267 |
backspaceKey:= false; |
2567 | 268 |
{$ENDIF} |
2436 | 269 |
|
270 |
// Controller(s) |
|
271 |
k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
|
2428 | 272 |
for j:= 0 to Pred(ControllerNumControllers) do |
273 |
begin |
|
274 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
275 |
begin |
|
2436 | 276 |
if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; |
277 |
if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; |
|
2428 | 278 |
inc(k, 2); |
279 |
end; |
|
280 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
281 |
begin |
|
2436 | 282 |
tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
283 |
tkbdn[k + 1]:= ControllerHats[j][i] and SDL_HAT_RIGHT; |
|
284 |
tkbdn[k + 2]:= ControllerHats[j][i] and SDL_HAT_DOWN; |
|
285 |
tkbdn[k + 3]:= ControllerHats[j][i] and SDL_HAT_LEFT; |
|
2428 | 286 |
inc(k, 4); |
287 |
end; |
|
288 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
289 |
begin |
|
2436 | 290 |
tkbdn[k]:= ControllerButtons[j][i]; |
2428 | 291 |
inc(k, 1); |
292 |
end; |
|
293 |
end; |
|
2436 | 294 |
|
295 |
for t:= 0 to cKeyMaxIndex do |
|
296 |
tkbd[i]:= tkbdn[i] |
|
4 | 297 |
end; |
298 |
||
299 |
procedure InitKbdKeyTable; |
|
2428 | 300 |
var i, j, k, t: LongInt; |
4 | 301 |
s: string[15]; |
302 |
begin |
|
303 |
KeyNames[1]:= 'mousel'; |
|
304 |
KeyNames[2]:= 'mousem'; |
|
305 |
KeyNames[3]:= 'mouser'; |
|
2379 | 306 |
KeyNames[4]:= 'wheelup'; |
307 |
KeyNames[5]:= 'wheeldown'; |
|
308 |
||
309 |
for i:= 6 to cKeyMaxIndex do |
|
4 | 310 |
begin |
311 |
s:= SDL_GetKeyName(i); |
|
2590 | 312 |
// addfilelog(inttostr(i) + ' ' + s); |
4 | 313 |
if s = 'unknown key' then KeyNames[i]:= '' |
314 |
else begin |
|
315 |
for t:= 1 to Length(s) do |
|
316 |
if s[t] = ' ' then s[t]:= '_'; |
|
317 |
KeyNames[i]:= s |
|
318 |
end; |
|
167 | 319 |
end; |
320 |
||
2436 | 321 |
{$IFDEF SDL13} |
2438 | 322 |
PByteArray(SDL_GetKeyboardState(@i)); |
2436 | 323 |
{$ELSE} |
324 |
SDL_GetKeyState(@i); |
|
325 |
{$ENDIF} |
|
326 |
||
2428 | 327 |
// Controller(s) |
2436 | 328 |
k:= i; |
2428 | 329 |
for j:= 0 to Pred(ControllerNumControllers) do |
330 |
begin |
|
331 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
332 |
begin |
|
333 |
keynames[k + 0]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'u'; |
|
334 |
keynames[k + 1]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'd'; |
|
335 |
inc(k, 2); |
|
336 |
end; |
|
337 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
338 |
begin |
|
339 |
keynames[k + 0]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'u'; |
|
340 |
keynames[k + 1]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'r'; |
|
341 |
keynames[k + 2]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'd'; |
|
342 |
keynames[k + 3]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'l'; |
|
343 |
inc(k, 4); |
|
344 |
end; |
|
345 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
346 |
begin |
|
347 |
keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i); |
|
348 |
inc(k, 1); |
|
349 |
end; |
|
350 |
end; |
|
2581 | 351 |
|
2586
204e6b2885bc
added little/big endian checks, added symbol for touch input, simplified iphoneos definitions
koda
parents:
2581
diff
changeset
|
352 |
{$IFDEF TOUCHINPUT} |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
353 |
DefaultBinds[ 1]:= '/put'; |
2579 | 354 |
DefaultBinds[ 3]:= 'ammomenu'; |
355 |
DefaultBinds[ 8]:= 'hjump'; |
|
2590 | 356 |
DefaultBinds[ 9]:= 'switch'; |
2579 | 357 |
DefaultBinds[ 13]:= 'ljump'; |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
358 |
DefaultBinds[ 23]:= '+up'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
359 |
DefaultBinds[ 24]:= '+down'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
360 |
DefaultBinds[ 25]:= '+left'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
361 |
DefaultBinds[ 26]:= '+right'; |
2590 | 362 |
DefaultBinds[ 32]:= '+attack'; |
2579 | 363 |
{$ENDIF} |
2428 | 364 |
|
2379 | 365 |
DefaultBinds[ 27]:= 'quit'; |
366 |
DefaultBinds[ 96]:= 'history'; |
|
367 |
DefaultBinds[127]:= 'rotmask'; |
|
368 |
||
369 |
DefaultBinds[KeyNameToCode('0')]:= '+volup'; |
|
370 |
DefaultBinds[KeyNameToCode('9')]:= '+voldown'; |
|
371 |
DefaultBinds[KeyNameToCode('c')]:= 'capture'; |
|
372 |
DefaultBinds[KeyNameToCode('h')]:= 'findhh'; |
|
373 |
DefaultBinds[KeyNameToCode('p')]:= 'pause'; |
|
374 |
DefaultBinds[KeyNameToCode('s')]:= '+speedup'; |
|
375 |
DefaultBinds[KeyNameToCode('t')]:= 'chat'; |
|
376 |
DefaultBinds[KeyNameToCode('y')]:= 'confirm'; |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
377 |
|
2407
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
378 |
DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
379 |
DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
380 |
DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
381 |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
382 |
DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
383 |
|
167 | 384 |
SetDefaultBinds |
4 | 385 |
end; |
386 |
||
167 | 387 |
procedure SetBinds(var binds: TBinds); |
388 |
begin |
|
389 |
CurrentBinds:= binds |
|
390 |
end; |
|
391 |
||
392 |
procedure SetDefaultBinds; |
|
393 |
begin |
|
394 |
CurrentBinds:= DefaultBinds |
|
395 |
end; |
|
396 |
||
948 | 397 |
procedure FreezeEnterKey; |
398 |
begin |
|
399 |
tkbd[13]:= 1; |
|
2567 | 400 |
tkbd[271]:= 1; |
948 | 401 |
end; |
167 | 402 |
|
2428 | 403 |
var Controller: array [0..5] of PSDLJoystick; |
404 |
||
405 |
procedure ControllerInit; |
|
406 |
var i, j: Integer; |
|
407 |
begin |
|
408 |
ControllerEnabled:= 0; |
|
409 |
ControllerNumControllers:= SDL_NumJoysticks; |
|
410 |
||
411 |
if ControllerNumControllers > 6 then ControllerNumControllers:= 6; |
|
412 |
||
413 |
WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers)); |
|
414 |
||
415 |
if ControllerNumControllers > 0 then |
|
416 |
begin |
|
417 |
for j:= 0 to pred(ControllerNumControllers) do |
|
418 |
begin |
|
419 |
WriteLnToConsole('Using game controller: ' + SDL_JoystickName(j)); |
|
420 |
Controller[j]:= SDL_JoystickOpen(j); |
|
421 |
if Controller[j] = nil then |
|
422 |
WriteLnToConsole('* Failed to open game controller!') |
|
423 |
else |
|
424 |
begin |
|
425 |
ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
|
426 |
//ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
|
427 |
ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
|
428 |
ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
|
429 |
WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j])); |
|
430 |
//WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j])); |
|
431 |
WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j])); |
|
432 |
WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j])); |
|
433 |
ControllerEnabled:= 1; |
|
434 |
||
435 |
if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; |
|
436 |
//if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
|
437 |
if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; |
|
438 |
if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20; |
|
439 |
||
440 |
// reset all buttons/axes |
|
441 |
for i:= 0 to pred(ControllerNumAxes[j]) do |
|
442 |
ControllerAxes[j][i]:= 0; |
|
443 |
(*for i:= 0 to pred(ControllerNumBalls[j]) do |
|
444 |
begin |
|
445 |
ControllerBalls[j][i][0]:= 0; |
|
446 |
ControllerBalls[j][i][1]:= 0; |
|
447 |
end;*) |
|
448 |
for i:= 0 to pred(ControllerNumHats[j]) do |
|
449 |
ControllerHats[j][i]:= SDL_HAT_CENTERED; |
|
450 |
for i:= 0 to pred(ControllerNumButtons[j]) do |
|
451 |
ControllerButtons[j][i]:= 0; |
|
452 |
end; |
|
453 |
end; |
|
454 |
// enable event generation/controller updating |
|
455 |
SDL_JoystickEventState(1); |
|
456 |
end |
|
457 |
else |
|
458 |
WriteLnToConsole('Not using any game controller'); |
|
459 |
end; |
|
460 |
||
461 |
procedure ControllerClose; |
|
462 |
var j: Integer; |
|
463 |
begin |
|
464 |
if ControllerEnabled > 0 then |
|
465 |
for j:= 0 to pred(ControllerNumControllers) do |
|
466 |
SDL_JoystickClose(Controller[j]); |
|
467 |
end; |
|
468 |
||
469 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
470 |
begin |
|
471 |
ControllerAxes[joy][axis]:= value; |
|
472 |
end; |
|
473 |
||
474 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
475 |
begin |
|
476 |
ControllerHats[joy][hat]:= value; |
|
477 |
end; |
|
478 |
||
479 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
480 |
begin |
|
481 |
if pressed then ControllerButtons[joy][button]:= 1 else ControllerButtons[joy][button]:= 0; |
|
482 |
end; |
|
483 |
||
4 | 484 |
initialization |
485 |
||
486 |
end. |