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