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