author | unC0Rr |
Sat, 21 Dec 2013 01:14:59 +0400 | |
changeset 9809 | 1e32628eb167 |
parent 9380 | 563ab624522c |
child 9521 | 8054d9d775fd |
permissions | -rw-r--r-- |
5621 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
6700 | 3 |
* Copyright (c) 2012 Richard Deurwaarder <xeli@xelification.com> |
5621 | 4 |
* |
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 |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
*) |
|
18 |
||
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
19 |
{$INCLUDE "options.inc"} |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
20 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
21 |
unit uTouch; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
22 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
23 |
interface |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
24 |
|
8204 | 25 |
uses SysUtils, uConsole, uVariables, SDLh, uFloat, uConsts, uCommands, GLUnit, uTypes, uCaptions, uAmmos, uWorld; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
26 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
27 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
28 |
procedure initModule; |
7850 | 29 |
procedure freeModule; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
30 |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
31 |
procedure ProcessTouch; |
6961
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
32 |
procedure NewTurnBeginning; |
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
33 |
|
9379 | 34 |
procedure onTouchDown(x, y: Single; pointerId: TSDL_FingerId); |
35 |
procedure onTouchMotion(x, y, dx, dy: Single; pointerId: TSDL_FingerId); |
|
36 |
procedure onTouchUp(x, y: Single; pointerId: TSDL_FingerId); |
|
37 |
||
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
38 |
function convertToCursorX(x: LongInt): LongInt; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
39 |
function convertToCursorY(y: LongInt): LongInt; |
9379 | 40 |
|
6693 | 41 |
function addFinger(x,y: Longword; id: TSDL_FingerId): PTouch_Data; |
42 |
function updateFinger(x,y,dx,dy: Longword; id: TSDL_FingerId): PTouch_Data; |
|
43 |
procedure deleteFinger(id: TSDL_FingerId); |
|
9379 | 44 |
|
6693 | 45 |
procedure onTouchClick(finger: TTouch_Data); |
46 |
procedure onTouchDoubleClick(finger: TTouch_Data); |
|
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
47 |
procedure onTouchLongClick(finger: TTouch_Data); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
48 |
|
6693 | 49 |
function findFinger(id: TSDL_FingerId): PTouch_Data; |
50 |
procedure aim(finger: TTouch_Data); |
|
51 |
function isOnCrosshair(finger: TTouch_Data): boolean; |
|
52 |
function isOnCurrentHog(finger: TTouch_Data): boolean; |
|
6702 | 53 |
procedure convertToWorldCoord(var x,y: LongInt; finger: TTouch_Data); |
54 |
procedure convertToFingerCoord(var x,y: LongInt; oldX, oldY: LongInt); |
|
6693 | 55 |
function fingerHasMoved(finger: TTouch_Data): boolean; |
6702 | 56 |
function calculateDelta(finger1, finger2: TTouch_Data): LongInt; |
6693 | 57 |
function getSecondFinger(finger: TTouch_Data): PTouch_Data; |
58 |
function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean; |
|
6703 | 59 |
function isOnRect(x,y,w,h: LongInt; finger: TTouch_Data): boolean; |
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
60 |
function isOnWidget(widget: TOnScreenWidget; finger: TTouch_Data): boolean; |
6693 | 61 |
procedure printFinger(finger: TTouch_Data); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
62 |
implementation |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
63 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
64 |
const |
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
65 |
clickTime = 200; |
7185
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7105
diff
changeset
|
66 |
baseRectSize = 96; |
5828
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
67 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
68 |
var |
7185
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7105
diff
changeset
|
69 |
rectSize, halfRectSize: LongInt; |
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7105
diff
changeset
|
70 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
71 |
pointerCount : Longword; |
6693 | 72 |
fingers: array of TTouch_Data; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
73 |
moveCursor : boolean; |
5617
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
74 |
invertCursor : boolean; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
75 |
|
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
76 |
xTouchClick,yTouchClick : LongInt; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
77 |
timeSinceClick : Longword; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
78 |
|
9379 | 79 |
//Pinch to zoom |
6702 | 80 |
pinchSize : LongInt; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
81 |
baseZoomValue: GLFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
82 |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
83 |
//aiming |
6703 | 84 |
aimingCrosshair: boolean; |
9379 | 85 |
aimingUp, aimingDown: boolean; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
86 |
targetAngle: LongInt; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
87 |
|
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
88 |
buttonsDown: Longword; |
6957 | 89 |
targetting, targetted: boolean; //true when targetting an airstrike or the like |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
90 |
|
9379 | 91 |
procedure onTouchDown(x, y: Single; pointerId: TSDL_FingerId); |
92 |
var |
|
6693 | 93 |
finger: PTouch_Data; |
9379 | 94 |
xr, yr: LongWord; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
95 |
begin |
9379 | 96 |
xr:= round(x * cScreenWidth); |
97 |
yr:= round(y * cScreenHeight); |
|
98 |
||
99 |
finger:= addFinger(xr, yr, pointerId); |
|
6703 | 100 |
|
101 |
inc(buttonsDown);//inc buttonsDown, if we don't see a button down we'll dec it |
|
102 |
||
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
103 |
if isOnCrosshair(finger^) then |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
104 |
begin |
6703 | 105 |
aimingCrosshair:= true; |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
106 |
aim(finger^); |
6703 | 107 |
moveCursor:= false; |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
108 |
exit; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
109 |
end; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
110 |
|
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
111 |
if isOnWidget(fireButton, finger^) then |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
112 |
begin |
6957 | 113 |
ParseTeamCommand('+attack'); |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
114 |
moveCursor:= false; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
115 |
finger^.pressedWidget:= @fireButton; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
116 |
exit; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
117 |
end; |
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
118 |
if isOnWidget(arrowLeft, finger^) then |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
119 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
120 |
ParseTeamCommand('+left'); |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
121 |
moveCursor:= false; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
122 |
finger^.pressedWidget:= @arrowLeft; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
123 |
exit; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
124 |
end; |
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
125 |
if isOnWidget(arrowRight, finger^) then |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
126 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
127 |
ParseTeamCommand('+right'); |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
128 |
moveCursor:= false; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
129 |
finger^.pressedWidget:= @arrowRight; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
130 |
exit; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
131 |
end; |
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
132 |
if isOnWidget(arrowUp, finger^) then |
6806
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
133 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
134 |
ParseTeamCommand('+up'); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
135 |
aimingUp:= true; |
6806
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
136 |
moveCursor:= false; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
137 |
finger^.pressedWidget:= @arrowUp; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
138 |
exit; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
139 |
end; |
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
140 |
if isOnWidget(arrowDown, finger^) then |
6806
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
141 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
142 |
ParseTeamCommand('+down'); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
143 |
aimingDown:= true; |
6806
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
144 |
moveCursor:= false; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
145 |
finger^.pressedWidget:= @arrowDown; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
146 |
exit; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
147 |
end; |
6640 | 148 |
|
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
149 |
if isOnWidget(pauseButton, finger^) then |
6806
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
150 |
begin |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
151 |
isPaused:= not isPaused; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
152 |
moveCursor:= false; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
153 |
finger^.pressedWidget:= @pauseButton; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
154 |
exit; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
155 |
end; |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
156 |
|
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
157 |
if isOnWidget(utilityWidget, finger^) then |
cdfb6c7099e5
first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents:
6723
diff
changeset
|
158 |
begin |
6957 | 159 |
finger^.pressedWidget:= @utilityWidget; |
160 |
moveCursor:= false; |
|
6956 | 161 |
if(CurrentHedgehog <> nil) then |
162 |
begin |
|
163 |
if Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Timerable <> 0 then |
|
164 |
ParseTeamCommand('/timer ' + inttostr((GetCurAmmoEntry(CurrentHedgeHog^)^.Timer div 1000) mod 5 + 1)); |
|
165 |
end; |
|
6957 | 166 |
exit; |
9379 | 167 |
end; |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
168 |
dec(buttonsDown);//no buttonsDown, undo the inc() above |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
169 |
if buttonsDown = 0 then |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
170 |
begin |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
171 |
moveCursor:= true; |
6951
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
172 |
case pointerCount of |
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
173 |
1: |
6957 | 174 |
targetting:= not(targetted) and (CurrentHedgehog <> nil) and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0); |
6951
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
175 |
2: |
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
176 |
begin |
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
177 |
moveCursor:= false; |
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
178 |
pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^); |
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
179 |
baseZoomValue := ZoomValue |
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
180 |
end; |
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
181 |
end; |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
182 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
183 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
184 |
|
9379 | 185 |
procedure onTouchMotion(x, y, dx, dy: Single; pointerId: TSDL_FingerId); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
186 |
var |
6693 | 187 |
finger, secondFinger: PTouch_Data; |
9379 | 188 |
currentPinchDelta, zoom : Single; |
189 |
xr, yr, dxr, dyr: LongWord; |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
190 |
begin |
9379 | 191 |
xr:= round(x * cScreenWidth); |
192 |
yr:= round(y * cScreenHeight); |
|
193 |
dxr:= round(dx * cScreenWidth); |
|
194 |
dyr:= round(dy * cScreenHeight); |
|
195 |
||
196 |
finger:= updateFinger(xr, yr, dxr, dyr, pointerId); |
|
197 |
if finger = nil then |
|
198 |
exit; |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
199 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
200 |
if moveCursor then |
5828
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
201 |
begin |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
202 |
if invertCursor then |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
203 |
begin |
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
204 |
CursorPoint.X := CursorPoint.X - finger^.dx; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
205 |
CursorPoint.Y := CursorPoint.Y + finger^.dy; |
5828
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
206 |
end |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
207 |
else |
5828
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
208 |
begin |
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
209 |
CursorPoint.X := CursorPoint.X + finger^.dx; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
210 |
CursorPoint.Y := CursorPoint.Y - finger^.dy; |
5828
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
211 |
end; |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
212 |
exit //todo change into switch rather than ugly ifs |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
213 |
end; |
9379 | 214 |
|
215 |
if aimingCrosshair then |
|
5828
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
216 |
begin |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
217 |
aim(finger^); |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
218 |
exit |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
219 |
end; |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
220 |
|
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
221 |
if (buttonsDown = 0) and (pointerCount = 2) then |
5828
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
222 |
begin |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
223 |
secondFinger := getSecondFinger(finger^); |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
224 |
currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize; |
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
225 |
zoom := currentPinchDelta/cScreenWidth; |
6702 | 226 |
ZoomValue := baseZoomValue - (zoom * cMinMaxZoomLevelDelta); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
227 |
if ZoomValue < cMaxZoomLevel then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
228 |
ZoomValue := cMaxZoomLevel; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
229 |
if ZoomValue > cMinZoomLevel then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
230 |
ZoomValue := cMinZoomLevel; |
5828
667fb58d7f18
Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents:
5733
diff
changeset
|
231 |
end; |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
232 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
233 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
234 |
|
9379 | 235 |
procedure onTouchUp(x,y: Single; pointerId: TSDL_FingerId); |
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
236 |
var |
6693 | 237 |
finger: PTouch_Data; |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
238 |
widget: POnScreenWidget; |
9379 | 239 |
xr, yr: LongWord; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
240 |
begin |
9379 | 241 |
xr:= round(x * cScreenWidth); |
242 |
yr:= round(y * cScreenHeight); |
|
243 |
||
244 |
finger:= updateFinger(xr, yr, 0, 0, pointerId); |
|
245 |
if finger = nil then |
|
246 |
exit; |
|
247 |
||
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
248 |
//Check for onTouchClick event |
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
249 |
if not(fingerHasMoved(finger^)) then |
6950
f34ff54b0cbd
-Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents:
6949
diff
changeset
|
250 |
begin |
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
251 |
if (RealTicks - finger^.timeSinceDown) < clickTime then |
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
252 |
onTouchClick(finger^) |
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
253 |
else |
9379 | 254 |
onTouchLongClick(finger^); |
6950
f34ff54b0cbd
-Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents:
6949
diff
changeset
|
255 |
end; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
256 |
|
6703 | 257 |
if aimingCrosshair then |
258 |
begin |
|
259 |
aimingCrosshair:= false; |
|
7022 | 260 |
ParseTeamCommand('-up'); |
261 |
ParseTeamCommand('-down'); |
|
6703 | 262 |
dec(buttonsDown); |
263 |
end; |
|
264 |
||
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
265 |
widget:= finger^.pressedWidget; |
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
266 |
if (buttonsDown > 0) and (widget <> nil) then |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
267 |
begin |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
268 |
dec(buttonsDown); |
9379 | 269 |
|
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
270 |
if widget = @arrowLeft then |
6949
615cc50903c8
remove last boolean keys references and using only ParseCommand in uTouch now
Xeli
parents:
6919
diff
changeset
|
271 |
ParseTeamCommand('-left'); |
9379 | 272 |
|
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
273 |
if widget = @arrowRight then |
6949
615cc50903c8
remove last boolean keys references and using only ParseCommand in uTouch now
Xeli
parents:
6919
diff
changeset
|
274 |
ParseTeamCommand('-right'); |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
275 |
|
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
276 |
if widget = @arrowUp then |
6949
615cc50903c8
remove last boolean keys references and using only ParseCommand in uTouch now
Xeli
parents:
6919
diff
changeset
|
277 |
ParseTeamCommand('-up'); |
6640 | 278 |
|
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
279 |
if widget = @arrowDown then |
6949
615cc50903c8
remove last boolean keys references and using only ParseCommand in uTouch now
Xeli
parents:
6919
diff
changeset
|
280 |
ParseTeamCommand('-down'); |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
281 |
|
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
282 |
if widget = @fireButton then |
6957 | 283 |
ParseTeamCommand('-attack'); |
9379 | 284 |
|
6957 | 285 |
if widget = @utilityWidget then |
6962 | 286 |
if (CurrentHedgehog <> nil)then |
287 |
if(Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0)then |
|
288 |
begin |
|
289 |
ParseTeamCommand('put'); |
|
290 |
targetted:= true; |
|
291 |
end |
|
7105 | 292 |
else if (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amSwitch) then |
6962 | 293 |
ParseTeamCommand('switch') |
294 |
else WriteLnToConsole(inttostr(ord(Ammoz[CurrentHedgehog^.CurAmmoType].NameId)) + ' ' + inttostr(ord(sidSwitch))); |
|
6640 | 295 |
end; |
9379 | 296 |
|
6951
a37e470c8694
- changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents:
6950
diff
changeset
|
297 |
if targetting then |
6957 | 298 |
AddCaption('Press the target button to mark the target', cWhiteColor, capgrpAmmoInfo); |
9379 | 299 |
|
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
300 |
deleteFinger(pointerId); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
301 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
302 |
|
6693 | 303 |
procedure onTouchDoubleClick(finger: TTouch_Data); |
5617
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
304 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
305 |
finger := finger;//avoid compiler hint |
5617
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
306 |
end; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
307 |
|
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
308 |
procedure onTouchLongClick(finger: TTouch_Data); |
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
309 |
begin |
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
310 |
if isOnWidget(jumpWidget, finger) then |
6950
f34ff54b0cbd
-Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents:
6949
diff
changeset
|
311 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
312 |
ParseTeamCommand('ljump'); |
6950
f34ff54b0cbd
-Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents:
6949
diff
changeset
|
313 |
exit; |
f34ff54b0cbd
-Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents:
6949
diff
changeset
|
314 |
end; |
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
315 |
end; |
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
316 |
|
6693 | 317 |
procedure onTouchClick(finger: TTouch_Data); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
318 |
begin |
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
319 |
//if (RealTicks - timeSinceClick < 300) and (sqrt(sqr(finger.X-xTouchClick) + sqr(finger.Y-yTouchClick)) < 30) then |
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
320 |
// begin |
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
321 |
// onTouchDoubleClick(finger); |
9379 | 322 |
// timeSinceClick:= 0;//we make an assumption there won't be an 'click' in the first 300 ticks(milliseconds) |
323 |
// exit; |
|
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
324 |
// end; |
5617
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
325 |
|
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
326 |
xTouchClick:= finger.x; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
327 |
yTouchClick:= finger.y; |
6687 | 328 |
timeSinceClick:= RealTicks; |
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
329 |
|
6648
025473a2c420
prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents:
6640
diff
changeset
|
330 |
if bShowAmmoMenu then |
9379 | 331 |
begin |
6683
75a1d84ac606
small refactoring to touch screen buttons, use a record to store values, added 'offset' fields to adjust active button area
koda
parents:
6676
diff
changeset
|
332 |
if isOnRect(AmmoRect, finger) then |
6648
025473a2c420
prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents:
6640
diff
changeset
|
333 |
begin |
025473a2c420
prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents:
6640
diff
changeset
|
334 |
CursorPoint.X:= finger.x; |
025473a2c420
prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents:
6640
diff
changeset
|
335 |
CursorPoint.Y:= finger.y; |
9379 | 336 |
ParseTeamCommand('put'); |
6648
025473a2c420
prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents:
6640
diff
changeset
|
337 |
end |
025473a2c420
prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents:
6640
diff
changeset
|
338 |
else |
025473a2c420
prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents:
6640
diff
changeset
|
339 |
bShowAmmoMenu:= false; |
025473a2c420
prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents:
6640
diff
changeset
|
340 |
exit; |
5589 | 341 |
end; |
342 |
||
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
343 |
if isOnCurrentHog(finger) or isOnWidget(AMWidget, finger) then |
5595 | 344 |
begin |
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
345 |
bShowAmmoMenu := true; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
346 |
exit; |
5595 | 347 |
end; |
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
348 |
|
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
349 |
if isOnWidget(jumpWidget, finger) then |
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
350 |
begin |
9379 | 351 |
ParseTeamCommand('hjump'); |
6712
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
352 |
exit; |
c582869fbe7f
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents:
6707
diff
changeset
|
353 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
354 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
355 |
|
6693 | 356 |
function addFinger(x,y: Longword; id: TSDL_FingerId): PTouch_Data; |
9379 | 357 |
var |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
358 |
xCursor, yCursor, index : LongInt; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
359 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
360 |
//Check array sizes |
9379 | 361 |
if length(fingers) < pointerCount then |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
362 |
begin |
9379 | 363 |
setLength(fingers, pointerCount * 2); |
364 |
WriteLnToConsole('allocated ' + inttostr(length(fingers)) + ' finger elements'); |
|
5589 | 365 |
end; |
9379 | 366 |
|
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
367 |
xCursor := convertToCursorX(x); |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
368 |
yCursor := convertToCursorY(y); |
9379 | 369 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
370 |
//on removing fingers, all fingers are moved to the left |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
371 |
//with dynamic arrays being zero based, the new position of the finger is the old pointerCount |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
372 |
fingers[pointerCount].id := id; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
373 |
fingers[pointerCount].historicalX := xCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
374 |
fingers[pointerCount].historicalY := yCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
375 |
fingers[pointerCount].x := xCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
376 |
fingers[pointerCount].y := yCursor; |
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
377 |
fingers[pointerCount].dx := 0; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
378 |
fingers[pointerCount].dy := 0; |
6687 | 379 |
fingers[pointerCount].timeSinceDown:= RealTicks; |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
380 |
fingers[pointerCount].pressedWidget:= nil; |
9379 | 381 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
382 |
addFinger:= @fingers[pointerCount]; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
383 |
inc(pointerCount); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
384 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
385 |
|
9379 | 386 |
function updateFinger(x, y, dx, dy: Longword; id: TSDL_FingerId): PTouch_Data; |
387 |
var finger : PTouch_Data; |
|
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
388 |
begin |
9379 | 389 |
finger:= findFinger(id); |
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
390 |
|
9379 | 391 |
if finger <> nil then |
392 |
begin |
|
393 |
finger^.x:= convertToCursorX(x); |
|
394 |
finger^.y:= convertToCursorY(y); |
|
395 |
finger^.dx:= dx; |
|
396 |
finger^.dy:= dy; |
|
397 |
end |
|
398 |
else |
|
399 |
WriteLnToConsole('finger ' + inttostr(id) + ' not found'); |
|
400 |
updateFinger:= finger |
|
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
401 |
end; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
402 |
|
6693 | 403 |
procedure deleteFinger(id: TSDL_FingerId); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
404 |
var |
6228
1b7d4d7d162b
added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents:
6029
diff
changeset
|
405 |
index : Longword; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
406 |
begin |
9379 | 407 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
408 |
dec(pointerCount); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
409 |
for index := 0 to pointerCount do |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
410 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
411 |
if fingers[index].id = id then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
412 |
begin |
9379 | 413 |
|
414 |
//put the last finger into the spot of the finger to be removed, |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
415 |
//so that all fingers are packed to the far left |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
416 |
if pointerCount <> index then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
417 |
begin |
9379 | 418 |
fingers[index].id := fingers[pointerCount].id; |
419 |
fingers[index].x := fingers[pointerCount].x; |
|
420 |
fingers[index].y := fingers[pointerCount].y; |
|
421 |
fingers[index].historicalX := fingers[pointerCount].historicalX; |
|
422 |
fingers[index].historicalY := fingers[pointerCount].historicalY; |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
423 |
fingers[index].timeSinceDown := fingers[pointerCount].timeSinceDown; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
424 |
|
9379 | 425 |
fingers[pointerCount].id := 0; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
426 |
end |
9379 | 427 |
else fingers[index].id := 0; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
428 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
429 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
430 |
end; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
431 |
|
5589 | 432 |
end; |
433 |
||
6961
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
434 |
procedure NewTurnBeginning; |
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
435 |
begin |
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
436 |
targetted:= false; |
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
437 |
targetting:= false; |
7022 | 438 |
SetUtilityWidgetState(amNothing); |
6961
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
439 |
end; |
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
440 |
|
d5ac09894a1b
hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents:
6957
diff
changeset
|
441 |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
442 |
procedure ProcessTouch; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
443 |
var |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
444 |
deltaAngle: LongInt; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
445 |
begin |
9379 | 446 |
invertCursor := not(bShowAmmoMenu or targetting); |
6705
d2e95dcf2bb0
stop the crosshair from twitching when it's not supposed to move + fix aimingUp/Down booleans
Xeli
parents:
6704
diff
changeset
|
447 |
if aimingCrosshair then |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
448 |
if CurrentHedgehog^.Gear <> nil then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
449 |
begin |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
450 |
deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle; |
9379 | 451 |
if (deltaAngle > -5) and (deltaAngle < 5) then |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
452 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
453 |
if(aimingUp)then |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
454 |
begin |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
455 |
aimingUp:= false; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
456 |
ParseTeamCommand('-up'); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
457 |
end; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
458 |
if(aimingDown)then |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
459 |
begin |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
460 |
aimingDown:= false; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
461 |
ParseTeamCommand('-down'); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
462 |
end |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
463 |
end |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
464 |
else |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
465 |
begin |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
466 |
if (deltaAngle < 0) then |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
467 |
begin |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
468 |
if aimingUp then |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
469 |
begin |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
470 |
aimingUp:= false; |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
471 |
ParseTeamCommand('-up'); |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
472 |
end; |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
473 |
if(aimingDown)then |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
474 |
begin |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
475 |
aimingDown:= true; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
476 |
ParseTeamCommand('-down'); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
477 |
end |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
478 |
end |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
479 |
else |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
480 |
begin |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
481 |
if aimingDown then |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
482 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
483 |
ParseTeamCommand('-down'); |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
484 |
aimingDown:= false; |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
485 |
end; |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
486 |
if aimingUp then |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
487 |
begin |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
488 |
aimingUp:= true; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
489 |
ParseTeamCommand('+up'); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
490 |
end; |
9379 | 491 |
end; |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
492 |
end; |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
493 |
end |
9379 | 494 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
495 |
begin |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
496 |
if aimingUp then |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
497 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
498 |
ParseTeamCommand('-up'); |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
499 |
aimingUp:= false; |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
500 |
end; |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
501 |
if aimingDown then |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
502 |
begin |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6808
diff
changeset
|
503 |
ParseTeamCommand('-down'); |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
504 |
aimingDown:= false; |
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
505 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
506 |
end; |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
507 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
508 |
|
6693 | 509 |
function findFinger(id: TSDL_FingerId): PTouch_Data; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
510 |
var |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
511 |
index: LongWord; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
512 |
begin |
9379 | 513 |
for index:= 0 to length(fingers) do |
514 |
if fingers[index].id = id then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
515 |
begin |
9379 | 516 |
findFinger:= @fingers[index]; |
517 |
exit; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
518 |
end; |
9379 | 519 |
findFinger:= nil; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
520 |
end; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
521 |
|
6693 | 522 |
procedure aim(finger: TTouch_Data); |
9379 | 523 |
var |
6702 | 524 |
hogX, hogY, touchX, touchY, deltaX, deltaY: LongInt; |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
525 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
526 |
if CurrentHedgehog^.Gear <> nil then |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
527 |
begin |
6702 | 528 |
touchX := 0;//avoid compiler hint |
529 |
touchY := 0; |
|
530 |
hogX := hwRound(CurrentHedgehog^.Gear^.X); |
|
531 |
hogY := hwRound(CurrentHedgehog^.Gear^.Y); |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
532 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
533 |
convertToWorldCoord(touchX, touchY, finger); |
6702 | 534 |
deltaX := abs(TouchX-HogX); |
535 |
deltaY := TouchY-HogY; |
|
9379 | 536 |
|
6703 | 537 |
targetAngle:= (Round(DeltaY / sqrt(sqr(deltaX) + sqr(deltaY)) * 2048) + 2048) div 2; |
6651
4103354b7599
fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents:
6648
diff
changeset
|
538 |
end; //if CurrentHedgehog^.Gear <> nil |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
539 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
540 |
|
6693 | 541 |
// These 4 convertToCursor functions convert xy coords from the SDL coordinate system to our CursorPoint coor system: |
9379 | 542 |
// - the SDL coordinate system is proportional to the screen and values are normalized in the onTouch* functions |
6693 | 543 |
// - the CursorPoint coordinate system goes from -cScreenWidth/2 to cScreenWidth/2 on the x axis |
544 |
// and 0 to cScreenHeight on the x axis, (-cScreenWidth, cScreenHeight) being top left. |
|
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
545 |
function convertToCursorX(x: LongInt): LongInt; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
546 |
begin |
9379 | 547 |
convertToCursorX:= x - cScreenWidth shr 1; |
6625
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
548 |
end; |
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
549 |
|
2d8c5815292f
some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents:
6580
diff
changeset
|
550 |
function convertToCursorY(y: LongInt): LongInt; |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
551 |
begin |
9379 | 552 |
convertToCursorY:= cScreenHeight - y; |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
553 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
554 |
|
6693 | 555 |
function isOnCrosshair(finger: TTouch_Data): boolean; |
5615
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
556 |
var |
9379 | 557 |
x, y: LongInt; |
5615
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
558 |
begin |
9379 | 559 |
x:= 0; |
560 |
y:= 0; |
|
6702 | 561 |
convertToFingerCoord(x, y, CrosshairX, CrosshairY); |
9379 | 562 |
isOnCrosshair:= isOnRect(x - HalfRectSize, y - HalfRectSize, RectSize, RectSize, finger); |
5615
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
563 |
end; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
564 |
|
6693 | 565 |
function isOnCurrentHog(finger: TTouch_Data): boolean; |
5595 | 566 |
var |
9379 | 567 |
x, y: LongInt; |
5595 | 568 |
begin |
9379 | 569 |
x:= 0; |
570 |
y:= 0; |
|
571 |
convertToFingerCoord(x, y, hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y)); |
|
572 |
isOnCurrentHog:= isOnRect(x - HalfRectSize, y - HalfRectSize, RectSize, RectSize, finger); |
|
5938
c186c454779d
isOnCurrentHog and isOnCrosshair now look at the distance relative to the screen rather than world coords, this means that zooming out doesn't make it harder to touch the hog or crosshair
Xeli
parents:
5828
diff
changeset
|
573 |
end; |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
574 |
|
9379 | 575 |
procedure convertToFingerCoord(var x, y : LongInt; oldX, oldY: LongInt); |
5938
c186c454779d
isOnCurrentHog and isOnCrosshair now look at the distance relative to the screen rather than world coords, this means that zooming out doesn't make it harder to touch the hog or crosshair
Xeli
parents:
5828
diff
changeset
|
576 |
begin |
6702 | 577 |
x := oldX + WorldDx; |
9379 | 578 |
y := cScreenHeight - oldY - WorldDy; |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
579 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
580 |
|
6702 | 581 |
procedure convertToWorldCoord(var x,y: LongInt; finger: TTouch_Data); |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
582 |
begin |
9379 | 583 |
x := finger.x - WorldDx; |
584 |
y := cScreenHeight - finger.y - WorldDy; |
|
5595 | 585 |
end; |
586 |
||
5589 | 587 |
//Method to calculate the distance this finger has moved since the downEvent |
6693 | 588 |
function fingerHasMoved(finger: TTouch_Data): boolean; |
5589 | 589 |
begin |
6950
f34ff54b0cbd
-Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents:
6949
diff
changeset
|
590 |
fingerHasMoved := trunc(sqrt(sqr(finger.X-finger.historicalX) + sqr(finger.y-finger.historicalY))) > 30; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
591 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
592 |
|
6702 | 593 |
function calculateDelta(finger1, finger2: TTouch_Data): LongInt; inline; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
594 |
begin |
6702 | 595 |
calculateDelta := Round(sqrt(sqr(finger2.x-finger1.x) + sqr(finger2.y-finger1.y))); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
596 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
597 |
|
6693 | 598 |
// Under the premise that all pointer ids in pointerIds:TSDL_FingerId are packed to the far left. |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
599 |
// If the pointer to be ignored is not pointerIds[0] the second must be there |
6693 | 600 |
function getSecondFinger(finger: TTouch_Data): PTouch_Data; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
601 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
602 |
if fingers[0].id = finger.id then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
603 |
getSecondFinger := @fingers[1] |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
604 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6344
diff
changeset
|
605 |
getSecondFinger := @fingers[0]; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
606 |
end; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
607 |
|
6693 | 608 |
function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean; |
6698 | 609 |
begin |
6703 | 610 |
isOnRect:= isOnRect(rect.x, rect.y, rect.w, rect.h, finger); |
611 |
end; |
|
612 |
||
613 |
function isOnRect(x,y,w,h: LongInt; finger: TTouch_Data): boolean; |
|
614 |
begin |
|
615 |
isOnRect:= (finger.x > x) and |
|
616 |
(finger.x < x + w) and |
|
617 |
(cScreenHeight - finger.y > y) and |
|
618 |
(cScreenHeight - finger.y < y + h); |
|
6640 | 619 |
end; |
620 |
||
6723
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
621 |
function isOnWidget(widget: TOnScreenWidget; finger: TTouch_Data): boolean; |
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
622 |
begin |
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
623 |
isOnWidget:= widget.show and isOnRect(widget.active, finger); |
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
624 |
end; |
b77e2d4d664b
check if the widget is shown before checking if the finger is on the widget
Xeli
parents:
6716
diff
changeset
|
625 |
|
6693 | 626 |
procedure printFinger(finger: TTouch_Data); |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
627 |
begin |
9379 | 628 |
WriteLnToConsole(Format('id: %d, x: %d y: %d (rel x: %d rel y: %d), time: %d', |
629 |
[finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown])); |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
630 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
631 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
632 |
procedure initModule; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
633 |
var |
6228
1b7d4d7d162b
added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents:
6029
diff
changeset
|
634 |
index: Longword; |
1b7d4d7d162b
added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents:
6029
diff
changeset
|
635 |
//uRenderCoordScaleX, uRenderCoordScaleY: Longword; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
636 |
begin |
6701
58a43c2064ad
the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents:
6700
diff
changeset
|
637 |
buttonsDown:= 0; |
9379 | 638 |
pointerCount:= 0; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
639 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
640 |
setLength(fingers, 4); |
9379 | 641 |
for index := 0 to length(fingers) do |
642 |
fingers[index].id := 0; |
|
7185
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7105
diff
changeset
|
643 |
|
9377 | 644 |
rectSize:= baseRectSize; |
9379 | 645 |
halfRectSize:= baseRectSize shr 1; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
646 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
647 |
|
7850 | 648 |
procedure freeModule; |
649 |
begin |
|
650 |
end; |
|
651 |
||
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
652 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
653 |
end. |