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