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