author | koda |
Wed, 11 Nov 2009 19:48:16 +0000 | |
changeset 2615 | b86abe068708 |
parent 2613 | e873f4bfed09 |
child 2630 | 079ef82eac75 |
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; |
2599 | 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 |
|
2613 | 312 |
begin |
313 |
s:= string(sdl_getkeyname(i)); |
|
314 |
//writeln(stdout,inttostr(i) + ': ' + s); |
|
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; |
|
321 |
end; |
|
322 |
||
323 |
//for i:= 0 to cKeyMaxIndex do writeln(stdout,inttostr(i) + ': ' + KeyNames[i]); |
|
167 | 324 |
|
2436 | 325 |
{$IFDEF SDL13} |
2438 | 326 |
PByteArray(SDL_GetKeyboardState(@i)); |
2436 | 327 |
{$ELSE} |
328 |
SDL_GetKeyState(@i); |
|
329 |
{$ENDIF} |
|
330 |
||
2428 | 331 |
// Controller(s) |
2436 | 332 |
k:= i; |
2428 | 333 |
for j:= 0 to Pred(ControllerNumControllers) do |
334 |
begin |
|
335 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
336 |
begin |
|
337 |
keynames[k + 0]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'u'; |
|
338 |
keynames[k + 1]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'd'; |
|
339 |
inc(k, 2); |
|
340 |
end; |
|
341 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
342 |
begin |
|
343 |
keynames[k + 0]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'u'; |
|
344 |
keynames[k + 1]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'r'; |
|
345 |
keynames[k + 2]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'd'; |
|
346 |
keynames[k + 3]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'l'; |
|
347 |
inc(k, 4); |
|
348 |
end; |
|
349 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
350 |
begin |
|
351 |
keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i); |
|
352 |
inc(k, 1); |
|
353 |
end; |
|
354 |
end; |
|
2581 | 355 |
|
2586
204e6b2885bc
added little/big endian checks, added symbol for touch input, simplified iphoneos definitions
koda
parents:
2581
diff
changeset
|
356 |
{$IFDEF TOUCHINPUT} |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
357 |
DefaultBinds[ 1]:= '/put'; |
2579 | 358 |
DefaultBinds[ 3]:= 'ammomenu'; |
359 |
DefaultBinds[ 8]:= 'hjump'; |
|
2590 | 360 |
DefaultBinds[ 9]:= 'switch'; |
2579 | 361 |
DefaultBinds[ 13]:= 'ljump'; |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
362 |
DefaultBinds[ 23]:= '+up'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
363 |
DefaultBinds[ 24]:= '+down'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
364 |
DefaultBinds[ 25]:= '+left'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
365 |
DefaultBinds[ 26]:= '+right'; |
2590 | 366 |
DefaultBinds[ 32]:= '+attack'; |
2579 | 367 |
{$ENDIF} |
2428 | 368 |
|
2379 | 369 |
DefaultBinds[ 27]:= 'quit'; |
370 |
DefaultBinds[ 96]:= 'history'; |
|
371 |
DefaultBinds[127]:= 'rotmask'; |
|
372 |
||
2606
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
373 |
//numpad |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
374 |
//DefaultBinds[265]:= '+volup'; |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
375 |
//DefaultBinds[256]:= '+voldown'; |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
376 |
|
2379 | 377 |
DefaultBinds[KeyNameToCode('0')]:= '+volup'; |
378 |
DefaultBinds[KeyNameToCode('9')]:= '+voldown'; |
|
379 |
DefaultBinds[KeyNameToCode('c')]:= 'capture'; |
|
380 |
DefaultBinds[KeyNameToCode('h')]:= 'findhh'; |
|
381 |
DefaultBinds[KeyNameToCode('p')]:= 'pause'; |
|
382 |
DefaultBinds[KeyNameToCode('s')]:= '+speedup'; |
|
383 |
DefaultBinds[KeyNameToCode('t')]:= 'chat'; |
|
384 |
DefaultBinds[KeyNameToCode('y')]:= 'confirm'; |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
385 |
|
2407
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
386 |
DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
387 |
DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
388 |
DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
389 |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
390 |
DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
391 |
|
167 | 392 |
SetDefaultBinds |
4 | 393 |
end; |
394 |
||
167 | 395 |
procedure SetBinds(var binds: TBinds); |
396 |
begin |
|
2606
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
397 |
CurrentBinds:= binds; |
167 | 398 |
end; |
399 |
||
400 |
procedure SetDefaultBinds; |
|
401 |
begin |
|
402 |
CurrentBinds:= DefaultBinds |
|
403 |
end; |
|
404 |
||
948 | 405 |
procedure FreezeEnterKey; |
406 |
begin |
|
407 |
tkbd[13]:= 1; |
|
2567 | 408 |
tkbd[271]:= 1; |
948 | 409 |
end; |
167 | 410 |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
411 |
var Controller: array [0..5] of PSDL_Joystick; |
2428 | 412 |
|
413 |
procedure ControllerInit; |
|
414 |
var i, j: Integer; |
|
415 |
begin |
|
416 |
ControllerEnabled:= 0; |
|
417 |
ControllerNumControllers:= SDL_NumJoysticks; |
|
418 |
||
419 |
if ControllerNumControllers > 6 then ControllerNumControllers:= 6; |
|
420 |
||
421 |
WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers)); |
|
422 |
||
423 |
if ControllerNumControllers > 0 then |
|
424 |
begin |
|
425 |
for j:= 0 to pred(ControllerNumControllers) do |
|
426 |
begin |
|
427 |
WriteLnToConsole('Using game controller: ' + SDL_JoystickName(j)); |
|
428 |
Controller[j]:= SDL_JoystickOpen(j); |
|
429 |
if Controller[j] = nil then |
|
430 |
WriteLnToConsole('* Failed to open game controller!') |
|
431 |
else |
|
432 |
begin |
|
433 |
ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
|
434 |
//ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
|
435 |
ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
|
436 |
ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
|
437 |
WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j])); |
|
438 |
//WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j])); |
|
439 |
WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j])); |
|
440 |
WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j])); |
|
441 |
ControllerEnabled:= 1; |
|
442 |
||
443 |
if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; |
|
444 |
//if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
|
445 |
if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; |
|
446 |
if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20; |
|
447 |
||
448 |
// reset all buttons/axes |
|
449 |
for i:= 0 to pred(ControllerNumAxes[j]) do |
|
450 |
ControllerAxes[j][i]:= 0; |
|
451 |
(*for i:= 0 to pred(ControllerNumBalls[j]) do |
|
452 |
begin |
|
453 |
ControllerBalls[j][i][0]:= 0; |
|
454 |
ControllerBalls[j][i][1]:= 0; |
|
455 |
end;*) |
|
456 |
for i:= 0 to pred(ControllerNumHats[j]) do |
|
457 |
ControllerHats[j][i]:= SDL_HAT_CENTERED; |
|
458 |
for i:= 0 to pred(ControllerNumButtons[j]) do |
|
459 |
ControllerButtons[j][i]:= 0; |
|
460 |
end; |
|
461 |
end; |
|
462 |
// enable event generation/controller updating |
|
463 |
SDL_JoystickEventState(1); |
|
464 |
end |
|
465 |
else |
|
466 |
WriteLnToConsole('Not using any game controller'); |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
467 |
{$IFDEF IPHONEOS} |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
468 |
theJoystick:= Controller[0]; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
469 |
{$ENDIF} |
2428 | 470 |
end; |
471 |
||
472 |
procedure ControllerClose; |
|
473 |
var j: Integer; |
|
474 |
begin |
|
475 |
if ControllerEnabled > 0 then |
|
476 |
for j:= 0 to pred(ControllerNumControllers) do |
|
477 |
SDL_JoystickClose(Controller[j]); |
|
478 |
end; |
|
479 |
||
480 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
481 |
begin |
|
482 |
ControllerAxes[joy][axis]:= value; |
|
483 |
end; |
|
484 |
||
485 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
486 |
begin |
|
487 |
ControllerHats[joy][hat]:= value; |
|
488 |
end; |
|
489 |
||
490 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
491 |
begin |
|
492 |
if pressed then ControllerButtons[joy][button]:= 1 else ControllerButtons[joy][button]:= 0; |
|
493 |
end; |
|
494 |
||
4 | 495 |
initialization |
496 |
||
497 |
end. |