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