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