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