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