author | koda |
Fri, 06 Nov 2009 18:59:43 +0000 | |
changeset 2606 | ed687a8d081f |
parent 2599 | c7153d2348f3 |
child 2613 | e873f4bfed09 |
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 |
|
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 |
||
2606
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
371 |
//numpad |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
372 |
//DefaultBinds[265]:= '+volup'; |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
373 |
//DefaultBinds[256]:= '+voldown'; |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
374 |
|
2379 | 375 |
DefaultBinds[KeyNameToCode('0')]:= '+volup'; |
376 |
DefaultBinds[KeyNameToCode('9')]:= '+voldown'; |
|
377 |
DefaultBinds[KeyNameToCode('c')]:= 'capture'; |
|
378 |
DefaultBinds[KeyNameToCode('h')]:= 'findhh'; |
|
379 |
DefaultBinds[KeyNameToCode('p')]:= 'pause'; |
|
380 |
DefaultBinds[KeyNameToCode('s')]:= '+speedup'; |
|
381 |
DefaultBinds[KeyNameToCode('t')]:= 'chat'; |
|
382 |
DefaultBinds[KeyNameToCode('y')]:= 'confirm'; |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
383 |
|
2407
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
384 |
DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
385 |
DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
386 |
DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
387 |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
388 |
DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
389 |
|
167 | 390 |
SetDefaultBinds |
4 | 391 |
end; |
392 |
||
167 | 393 |
procedure SetBinds(var binds: TBinds); |
394 |
begin |
|
2606
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
395 |
CurrentBinds:= binds; |
167 | 396 |
end; |
397 |
||
398 |
procedure SetDefaultBinds; |
|
399 |
begin |
|
400 |
CurrentBinds:= DefaultBinds |
|
401 |
end; |
|
402 |
||
948 | 403 |
procedure FreezeEnterKey; |
404 |
begin |
|
405 |
tkbd[13]:= 1; |
|
2567 | 406 |
tkbd[271]:= 1; |
948 | 407 |
end; |
167 | 408 |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
409 |
var Controller: array [0..5] of PSDL_Joystick; |
2428 | 410 |
|
411 |
procedure ControllerInit; |
|
412 |
var i, j: Integer; |
|
413 |
begin |
|
414 |
ControllerEnabled:= 0; |
|
415 |
ControllerNumControllers:= SDL_NumJoysticks; |
|
416 |
||
417 |
if ControllerNumControllers > 6 then ControllerNumControllers:= 6; |
|
418 |
||
419 |
WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers)); |
|
420 |
||
421 |
if ControllerNumControllers > 0 then |
|
422 |
begin |
|
423 |
for j:= 0 to pred(ControllerNumControllers) do |
|
424 |
begin |
|
425 |
WriteLnToConsole('Using game controller: ' + SDL_JoystickName(j)); |
|
426 |
Controller[j]:= SDL_JoystickOpen(j); |
|
427 |
if Controller[j] = nil then |
|
428 |
WriteLnToConsole('* Failed to open game controller!') |
|
429 |
else |
|
430 |
begin |
|
431 |
ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
|
432 |
//ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
|
433 |
ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
|
434 |
ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
|
435 |
WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j])); |
|
436 |
//WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j])); |
|
437 |
WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j])); |
|
438 |
WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j])); |
|
439 |
ControllerEnabled:= 1; |
|
440 |
||
441 |
if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; |
|
442 |
//if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
|
443 |
if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; |
|
444 |
if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20; |
|
445 |
||
446 |
// reset all buttons/axes |
|
447 |
for i:= 0 to pred(ControllerNumAxes[j]) do |
|
448 |
ControllerAxes[j][i]:= 0; |
|
449 |
(*for i:= 0 to pred(ControllerNumBalls[j]) do |
|
450 |
begin |
|
451 |
ControllerBalls[j][i][0]:= 0; |
|
452 |
ControllerBalls[j][i][1]:= 0; |
|
453 |
end;*) |
|
454 |
for i:= 0 to pred(ControllerNumHats[j]) do |
|
455 |
ControllerHats[j][i]:= SDL_HAT_CENTERED; |
|
456 |
for i:= 0 to pred(ControllerNumButtons[j]) do |
|
457 |
ControllerButtons[j][i]:= 0; |
|
458 |
end; |
|
459 |
end; |
|
460 |
// enable event generation/controller updating |
|
461 |
SDL_JoystickEventState(1); |
|
462 |
end |
|
463 |
else |
|
464 |
WriteLnToConsole('Not using any game controller'); |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
465 |
{$IFDEF IPHONEOS} |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
466 |
theJoystick:= Controller[0]; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
467 |
{$ENDIF} |
2428 | 468 |
end; |
469 |
||
470 |
procedure ControllerClose; |
|
471 |
var j: Integer; |
|
472 |
begin |
|
473 |
if ControllerEnabled > 0 then |
|
474 |
for j:= 0 to pred(ControllerNumControllers) do |
|
475 |
SDL_JoystickClose(Controller[j]); |
|
476 |
end; |
|
477 |
||
478 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
479 |
begin |
|
480 |
ControllerAxes[joy][axis]:= value; |
|
481 |
end; |
|
482 |
||
483 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
484 |
begin |
|
485 |
ControllerHats[joy][hat]:= value; |
|
486 |
end; |
|
487 |
||
488 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
489 |
begin |
|
490 |
if pressed then ControllerButtons[joy][button]:= 1 else ControllerButtons[joy][button]:= 0; |
|
491 |
end; |
|
492 |
||
4 | 493 |
initialization |
494 |
||
495 |
end. |