hedgewars/uTouch.pas
author belphegorr <szabibibi@gmail.com>
Tue, 26 Jun 2012 02:07:58 +0300
changeset 7211 a1e9335f1d50
parent 7185 92a045156255
child 7237 1bbe31e0d707
permissions -rw-r--r--
Fixed a bug in Mission 2, where hidden hogs appeared before getting deleted on losing the game.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5621
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     1
(*
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6698
diff changeset
     3
 * Copyright (c) 2012 Richard Deurwaarder <xeli@xelification.com>
5621
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     4
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     8
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    12
 * GNU General Public License for more details.
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    13
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    15
 * along with this program; if not, write to the Free Software
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    17
 *)
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    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
7063
a0326412e96a sysutils -> SysUtils
unc0rr
parents: 7022
diff changeset
    25
uses SysUtils, uConsole, uVariables, SDLh, uFloat, uConsts, uCommands, uIO, 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;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    29
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
    30
procedure ProcessTouch;
6961
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
    31
procedure NewTurnBeginning;
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
    32
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    33
procedure onTouchDown(x,y: Longword; pointerId: TSDL_FingerId);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    34
procedure onTouchMotion(x,y: Longword; dx,dy: LongInt; pointerId: TSDL_FingerId);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    35
procedure onTouchUp(x,y: Longword; pointerId: TSDL_FingerId);
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    36
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
    37
function convertToCursorY(y: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    38
function convertToCursorDeltaX(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 convertToCursorDeltaY(y: LongInt): LongInt;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    40
function addFinger(x,y: Longword; id: TSDL_FingerId): PTouch_Data;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    41
function updateFinger(x,y,dx,dy: Longword; id: TSDL_FingerId): PTouch_Data;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    42
procedure deleteFinger(id: TSDL_FingerId);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    43
procedure onTouchClick(finger: TTouch_Data);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    44
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
    45
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
    46
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    47
function findFinger(id: TSDL_FingerId): PTouch_Data;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    48
procedure aim(finger: TTouch_Data);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    49
function isOnCrosshair(finger: TTouch_Data): boolean;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    50
function isOnCurrentHog(finger: TTouch_Data): boolean;
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
    51
procedure convertToWorldCoord(var x,y: LongInt; finger: TTouch_Data);
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
    52
procedure convertToFingerCoord(var x,y: LongInt; oldX, oldY: LongInt);
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    53
function fingerHasMoved(finger: TTouch_Data): boolean;
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
    54
function calculateDelta(finger1, finger2: TTouch_Data): LongInt;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    55
function getSecondFinger(finger: TTouch_Data): PTouch_Data;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    56
function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean;
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    57
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
    58
function isOnWidget(widget: TOnScreenWidget; finger: TTouch_Data): boolean;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    59
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
    60
implementation
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    61
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    62
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
    63
    clickTime = 200;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    64
    nilFingerId = High(TSDL_FingerId);
7185
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
    65
    baseRectSize = 96;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    66
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    67
var
7185
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
    68
    rectSize, halfRectSize: LongInt;
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
    69
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    70
    pointerCount : Longword;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    71
    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
    72
    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
    73
    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
    74
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
    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
    76
    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
    77
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    78
    //Pinch to zoom 
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
    79
    pinchSize : LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    80
    baseZoomValue: GLFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    81
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
    82
    //aiming
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    83
    aimingCrosshair: boolean;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
    84
    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
    85
    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
    86
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
    87
    buttonsDown: Longword;
6957
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
    88
    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
    89
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    90
procedure onTouchDown(x,y: Longword; pointerId: TSDL_FingerId);
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    91
var 
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    92
    finger: PTouch_Data;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    93
begin
6676
21cf35a570a7 add keywords for landscape ammomenu and touch interface
koda
parents: 6654
diff changeset
    94
{$IFDEF USE_TOUCH_INTERFACE}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
    95
finger := addFinger(x,y,pointerId);
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    96
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    97
inc(buttonsDown);//inc buttonsDown, if we don't see a button down we'll dec it
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    98
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
    99
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
   100
begin
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   101
    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
   102
    aim(finger^);
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   103
    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
   104
    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
   105
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
   106
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   107
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
   108
    begin
6957
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   109
    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
   110
    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
   111
    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
   112
    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
   113
    end;
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   114
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
   115
    begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   116
    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
   117
    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
   118
    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
   119
    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
   120
    end;
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   121
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
   122
    begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   123
    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
   124
    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
   125
    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
   126
    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
   127
    end;
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   128
if isOnWidget(arrowUp, finger^) then
6806
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   129
    begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   130
    ParseTeamCommand('+up');
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   131
    aimingUp:= true;
6806
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   132
    moveCursor:= false;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   133
    finger^.pressedWidget:= @arrowUp;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   134
    exit;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   135
    end;
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   136
if isOnWidget(arrowDown, finger^) then
6806
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   137
    begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   138
    ParseTeamCommand('+down');
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   139
    aimingDown:= true;
6806
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   140
    moveCursor:= false;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   141
    finger^.pressedWidget:= @arrowDown;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   142
    exit;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   143
    end;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   144
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   145
if isOnWidget(pauseButton, finger^) then
6806
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   146
    begin
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   147
    isPaused:= not isPaused;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   148
    moveCursor:= false;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   149
    finger^.pressedWidget:= @pauseButton;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   150
    exit;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   151
    end;
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   152
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   153
if isOnWidget(utilityWidget, finger^) then
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   154
    begin
6957
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   155
    finger^.pressedWidget:= @utilityWidget;
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   156
    moveCursor:= false;
6956
7d9e2669c2f5 enabled grenade timer, needs a button image
Xeli
parents: 6955
diff changeset
   157
    if(CurrentHedgehog <> nil) then
7d9e2669c2f5 enabled grenade timer, needs a button image
Xeli
parents: 6955
diff changeset
   158
        begin
7d9e2669c2f5 enabled grenade timer, needs a button image
Xeli
parents: 6955
diff changeset
   159
        if Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Timerable <> 0 then
7d9e2669c2f5 enabled grenade timer, needs a button image
Xeli
parents: 6955
diff changeset
   160
            ParseTeamCommand('/timer ' + inttostr((GetCurAmmoEntry(CurrentHedgeHog^)^.Timer div 1000) mod 5 + 1));
7d9e2669c2f5 enabled grenade timer, needs a button image
Xeli
parents: 6955
diff changeset
   161
        end;
6957
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   162
    exit;
6806
cdfb6c7099e5 first part of the utilitywidget (grenade timer/swap hogs) code
Xeli
parents: 6723
diff changeset
   163
    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
   164
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
   165
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
   166
    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
   167
    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
   168
    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
   169
        1:
6957
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   170
            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
   171
        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
   172
            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
   173
            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
   174
            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
   175
            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
   176
            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
   177
        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
   178
    end;
6676
21cf35a570a7 add keywords for landscape ammomenu and touch interface
koda
parents: 6654
diff changeset
   179
{$ENDIF}
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   180
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   181
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   182
procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: TSDL_FingerId);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   183
var
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   184
    finger, secondFinger: PTouch_Data;
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   185
    currentPinchDelta, zoom : single;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   186
begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   187
finger:= updateFinger(x,y,dx,dy,pointerId);
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   188
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   189
if moveCursor then
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   190
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   191
        if invertCursor then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   192
        begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   193
            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
   194
            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
   195
        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   196
    else
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   197
        begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   198
            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
   199
            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
   200
        end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   201
        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
   202
    end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   203
    
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   204
if aimingCrosshair then 
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   205
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   206
        aim(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   207
        exit
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   208
    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
   209
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
   210
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
   211
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   212
       secondFinger := getSecondFinger(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   213
       currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   214
       zoom := currentPinchDelta/cScreenWidth;
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   215
       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
   216
       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
   217
           ZoomValue := cMaxZoomLevel;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   218
       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
   219
           ZoomValue := cMinZoomLevel;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   220
    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
   221
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   222
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   223
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   224
procedure onTouchUp(x,y: Longword; pointerId: TSDL_FingerId);
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   225
var
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   226
    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
   227
    widget: POnScreenWidget;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   228
begin
6707
07c8704b6b08 one more USE_TOUCH_INTERFACE
koda
parents: 6705
diff changeset
   229
{$IFDEF USE_TOUCH_INTERFACE}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   230
x := x;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   231
y := y;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   232
finger:= updateFinger(x,y,0,0,pointerId);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   233
//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
   234
if not(fingerHasMoved(finger^)) then
6950
f34ff54b0cbd -Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents: 6949
diff changeset
   235
    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
   236
    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
   237
        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
   238
    else
6950
f34ff54b0cbd -Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents: 6949
diff changeset
   239
            onTouchLongClick(finger^);
f34ff54b0cbd -Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents: 6949
diff changeset
   240
    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
   241
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   242
if aimingCrosshair then
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   243
    begin
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   244
    aimingCrosshair:= false;
7022
107651b3c5a0 fix breakage
Xeli
parents: 6962
diff changeset
   245
    ParseTeamCommand('-up');
107651b3c5a0 fix breakage
Xeli
parents: 6962
diff changeset
   246
    ParseTeamCommand('-down');
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   247
    dec(buttonsDown);
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   248
    end;
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   249
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
   250
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
   251
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
   252
    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
   253
    dec(buttonsDown);
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
   254
    
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
   255
    if widget = @arrowLeft then
6949
615cc50903c8 remove last boolean keys references and using only ParseCommand in uTouch now
Xeli
parents: 6919
diff changeset
   256
        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
   257
    
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
   258
    if widget = @arrowRight then
6949
615cc50903c8 remove last boolean keys references and using only ParseCommand in uTouch now
Xeli
parents: 6919
diff changeset
   259
        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
   260
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
   261
    if widget = @arrowUp then
6949
615cc50903c8 remove last boolean keys references and using only ParseCommand in uTouch now
Xeli
parents: 6919
diff changeset
   262
        ParseTeamCommand('-up');
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   263
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
   264
    if widget = @arrowDown then
6949
615cc50903c8 remove last boolean keys references and using only ParseCommand in uTouch now
Xeli
parents: 6919
diff changeset
   265
        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
   266
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
   267
    if widget = @fireButton then
6957
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   268
        ParseTeamCommand('-attack');
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   269
    
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   270
    if widget = @utilityWidget then
6962
ec308eabe09b implement switch for the touch interface
Xeli
parents: 6961
diff changeset
   271
        if (CurrentHedgehog <> nil)then
ec308eabe09b implement switch for the touch interface
Xeli
parents: 6961
diff changeset
   272
            if(Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0)then
ec308eabe09b implement switch for the touch interface
Xeli
parents: 6961
diff changeset
   273
                begin
ec308eabe09b implement switch for the touch interface
Xeli
parents: 6961
diff changeset
   274
                ParseTeamCommand('put');
ec308eabe09b implement switch for the touch interface
Xeli
parents: 6961
diff changeset
   275
                targetted:= true;
ec308eabe09b implement switch for the touch interface
Xeli
parents: 6961
diff changeset
   276
                end
7105
9007531f813f add a nilcheck
koda
parents: 7087
diff changeset
   277
            else if (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amSwitch) then
6962
ec308eabe09b implement switch for the touch interface
Xeli
parents: 6961
diff changeset
   278
                ParseTeamCommand('switch')
ec308eabe09b implement switch for the touch interface
Xeli
parents: 6961
diff changeset
   279
            else WriteLnToConsole(inttostr(ord(Ammoz[CurrentHedgehog^.CurAmmoType].NameId)) + ' ' + inttostr(ord(sidSwitch)));
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   280
    end;
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
   281
        
a37e470c8694 - changed targetting, to launch an airstrike move the cursor/pointer to a location and then press the firebutton
Xeli
parents: 6950
diff changeset
   282
if targetting then
6957
ab8034208fcd target using the utility button, this fixes bee
Xeli
parents: 6956
diff changeset
   283
    AddCaption('Press the target button to mark the target', cWhiteColor, capgrpAmmoInfo);
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
   284
 
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
   285
deleteFinger(pointerId);
6707
07c8704b6b08 one more USE_TOUCH_INTERFACE
koda
parents: 6705
diff changeset
   286
{$ENDIF}
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   287
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   288
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   289
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
   290
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   291
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
   292
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
   293
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
   294
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
   295
begin
6716
c9e873cf2b08 two more this time
koda
parents: 6714
diff changeset
   296
{$IFDEF USE_TOUCH_INTERFACE}
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   297
if isOnWidget(jumpWidget, finger) then
6950
f34ff54b0cbd -Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents: 6949
diff changeset
   298
    begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   299
    ParseTeamCommand('ljump');
6950
f34ff54b0cbd -Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents: 6949
diff changeset
   300
    exit;
f34ff54b0cbd -Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents: 6949
diff changeset
   301
    end;
f34ff54b0cbd -Fixed FingerHasMoved function, still might need a little tweaking
Xeli
parents: 6949
diff changeset
   302
6716
c9e873cf2b08 two more this time
koda
parents: 6714
diff changeset
   303
{$ENDIF}
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
   304
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
   305
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   306
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
   307
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
   308
//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
   309
//    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
   310
//    onTouchDoubleClick(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
   311
//    timeSinceClick:= 0;//we make an assumption there won't be an 'click' in the first 300 ticks(milliseconds) 
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
   312
//    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
   313
//    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
   314
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   315
xTouchClick:= finger.x;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   316
yTouchClick:= finger.y;
6687
98be933770e0 use realtick rather than SDL_GetTicks
Xeli
parents: 6685
diff changeset
   317
timeSinceClick:= RealTicks;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   318
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
   319
if bShowAmmoMenu then
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
   320
    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
   321
    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
   322
        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
   323
        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
   324
        CursorPoint.Y:= finger.y;
7087
d2089f2ea5af dont allow choosing weapons when the AI is playing
Xeli
parents: 7063
diff changeset
   325
        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
   326
        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
   327
    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
   328
        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
   329
    exit;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   330
    end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   331
6716
c9e873cf2b08 two more this time
koda
parents: 6714
diff changeset
   332
{$IFDEF USE_TOUCH_INTERFACE}
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   333
if isOnCurrentHog(finger) or isOnWidget(AMWidget, finger) then
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   334
    begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   335
    bShowAmmoMenu := true;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   336
    exit;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   337
    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
   338
6723
b77e2d4d664b check if the widget is shown before checking if the finger is on the widget
Xeli
parents: 6716
diff changeset
   339
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
   340
    begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   341
    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
   342
    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
   343
    end;
6716
c9e873cf2b08 two more this time
koda
parents: 6714
diff changeset
   344
{$ENDIF}
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   345
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   346
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   347
function addFinger(x,y: Longword; id: TSDL_FingerId): PTouch_Data;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   348
var 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   349
    xCursor, yCursor, index : LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   350
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   351
    //Check array sizes
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   352
    if length(fingers) < Integer(pointerCount) then 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   353
    begin
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   354
        setLength(fingers, length(fingers)*2);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   355
        for index := length(fingers) div 2 to length(fingers) do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   356
            fingers[index].id := nilFingerId;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   357
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   358
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   359
    
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   360
    xCursor := convertToCursorX(x);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   361
    yCursor := convertToCursorY(y);
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   362
    
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   363
    //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
   364
    //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
   365
    fingers[pointerCount].id := id;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   366
    fingers[pointerCount].historicalX := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   367
    fingers[pointerCount].historicalY := yCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   368
    fingers[pointerCount].x := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   369
    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
   370
    fingers[pointerCount].dx := 0;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   371
    fingers[pointerCount].dy := 0;
6687
98be933770e0 use realtick rather than SDL_GetTicks
Xeli
parents: 6685
diff changeset
   372
    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
   373
    fingers[pointerCount].pressedWidget:= nil;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   374
 
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   375
    addFinger:= @fingers[pointerCount];
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   376
    inc(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   377
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   378
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   379
function updateFinger(x,y,dx,dy: Longword; id: TSDL_FingerId): PTouch_Data;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   380
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   381
   updateFinger:= findFinger(id);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   382
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   383
   updateFinger^.x:= convertToCursorX(x);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   384
   updateFinger^.y:= convertToCursorY(y);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   385
   updateFinger^.dx:= convertToCursorDeltaX(dx);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   386
   updateFinger^.dy:= convertToCursorDeltaY(dy);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   387
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   388
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   389
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
   390
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
   391
    index : Longword;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   392
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   393
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   394
    dec(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   395
    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
   396
    begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   397
        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
   398
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   399
 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   400
            //put the last finger into the spot of the finger to be removed, 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   401
            //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
   402
            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
   403
                begin
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   404
                fingers[index].id := fingers[pointerCount].id;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   405
                fingers[index].x := fingers[pointerCount].x;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   406
                fingers[index].y := fingers[pointerCount].y;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   407
                fingers[index].historicalX := fingers[pointerCount].historicalX;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   408
                fingers[index].historicalY := fingers[pointerCount].historicalY;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   409
                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
   410
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   411
                fingers[pointerCount].id := nilFingerId;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   412
            end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   413
        else fingers[index].id := nilFingerId;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   414
            break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   415
        end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   416
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   417
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   418
end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   419
6961
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
   420
procedure NewTurnBeginning;
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
   421
begin
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
   422
targetted:= false;
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
   423
targetting:= false;
7022
107651b3c5a0 fix breakage
Xeli
parents: 6962
diff changeset
   424
SetUtilityWidgetState(amNothing);
6961
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
   425
end;
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
   426
d5ac09894a1b hide utilitywidget when changing turns, this also fixes some inconsistency when using targetting weapons
Xeli
parents: 6957
diff changeset
   427
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
   428
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
   429
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
   430
    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
   431
begin
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
   432
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
   433
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
   434
    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
   435
        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
   436
        deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle;
6705
d2e95dcf2bb0 stop the crosshair from twitching when it's not supposed to move + fix aimingUp/Down booleans
Xeli
parents: 6704
diff changeset
   437
        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
   438
            begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   439
                if(aimingUp)then
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   440
                    begin
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   441
                    aimingUp:= false;
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   442
                    ParseTeamCommand('-up');
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   443
                    end;
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   444
                if(aimingDown)then
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   445
                    begin
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   446
                    aimingDown:= false;
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   447
                    ParseTeamCommand('-down');
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   448
                    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
   449
            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
   450
        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
   451
            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
   452
            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
   453
                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
   454
                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
   455
                    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
   456
                    aimingUp:= false;
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   457
                    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
   458
                    end;
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   459
                if(aimingDown)then
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   460
                    begin
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   461
                    aimingDown:= true;
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   462
                    ParseTeamCommand('-down');
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   463
                    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
   464
                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
   465
            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
   466
                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
   467
                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
   468
                    begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   469
                    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
   470
                    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
   471
                    end;
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   472
                if aimingUp then
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   473
                    begin
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   474
                    aimingUp:= true;
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   475
                    ParseTeamCommand('+up');
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   476
                    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
   477
                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
   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
        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
   480
    else  
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   481
        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
   482
        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
   483
            begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   484
            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
   485
            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
   486
            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
   487
        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
   488
            begin
6919
bf7433e62b9c in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents: 6808
diff changeset
   489
            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
   490
            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
   491
            end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   492
        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
   493
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
   494
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   495
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
   496
var
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   497
    index: LongWord;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   498
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   499
    for index := 0 to High(fingers) do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   500
        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
   501
            begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   502
            findFinger := @fingers[index];
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   503
            break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   504
            end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   505
end;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   506
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   507
procedure aim(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
   508
var 
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   509
    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
   510
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
   511
    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
   512
        begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   513
        touchX := 0;//avoid compiler hint
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   514
        touchY := 0;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   515
        hogX := hwRound(CurrentHedgehog^.Gear^.X);
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   516
        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
   517
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   518
        convertToWorldCoord(touchX, touchY, finger);
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   519
        deltaX := abs(TouchX-HogX);
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   520
        deltaY := TouchY-HogY;
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
   521
        
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   522
        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
   523
        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
   524
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
   525
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   526
// These 4 convertToCursor functions convert xy coords from the SDL coordinate system to our CursorPoint coor system:
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   527
// - the SDL coordinate system goes from 0 to 32768 on the x axis and 0 to 32768 on the y axis, (0,0) being top left;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   528
// - the CursorPoint coordinate system goes from -cScreenWidth/2 to cScreenWidth/2 on the x axis
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   529
//   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
   530
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
   531
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   532
    convertToCursorX := round((x/32768)*cScreenWidth) - (cScreenWidth shr 1);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   533
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   534
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   535
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
   536
begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   537
    convertToCursorY := cScreenHeight - round((y/32768)*cScreenHeight)
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   538
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   539
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   540
function convertToCursorDeltaX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   541
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   542
    convertToCursorDeltaX := round(x/32768*cScreenWidth)
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   543
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   544
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   545
function convertToCursorDeltaY(y: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   546
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   547
    convertToCursorDeltaY := round(y/32768*cScreenHeight)
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
   548
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
   549
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   550
function isOnCrosshair(finger: TTouch_Data): boolean;
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   551
var
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   552
    x,y : LongInt;
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   553
begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   554
    x := 0;//avoid compiler hint
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   555
    y := 0;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   556
    convertToFingerCoord(x, y, CrosshairX, CrosshairY);
7185
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   557
    isOnCrosshair:= isOnRect((x-HalfRectSize), (y-HalfRectSize), RectSize, RectSize, finger);
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   558
    printFinger(finger);
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   559
    WriteLnToConsole(inttostr(finger.x) + '   ' + inttostr(x));
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   560
    WriteLnToConsole(inttostr(x) + '  ' + inttostr(y) + '   ' + inttostr(round(Android_JNI_getDensity() * 10)));
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   561
end;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   562
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   563
function isOnCurrentHog(finger: TTouch_Data): boolean;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   564
var
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   565
    x,y : LongInt;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   566
begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   567
    x := 0;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   568
    y := 0;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   569
    convertToFingerCoord(x,y, hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y));
7185
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   570
    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
   571
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
   572
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   573
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
   574
begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   575
    x := oldX + WorldDx;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   576
    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
   577
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
   578
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   579
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
   580
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
   581
//if x <> nil then 
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   582
    x := finger.x-WorldDx;
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
   583
//if y <> nil then 
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   584
    y := (cScreenHeight - finger.y)-WorldDy;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   585
end;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   586
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   587
//Method to calculate the distance this finger has moved since the downEvent
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   588
function fingerHasMoved(finger: TTouch_Data): boolean;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   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
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   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
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   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
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   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
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   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
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   608
function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean;
6698
804e9076d136 forgot begin
Xeli
parents: 6695
diff changeset
   609
begin
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   610
    isOnRect:= isOnRect(rect.x, rect.y, rect.w, rect.h, finger);
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   611
end;
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   612
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   613
function isOnRect(x,y,w,h: LongInt; finger: TTouch_Data): boolean;
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   614
begin
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   615
    isOnRect:= (finger.x > x)   and
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   616
               (finger.x < x + w) and
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   617
               (cScreenHeight - finger.y > y) and
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   618
               (cScreenHeight - finger.y < y + h);
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   619
end;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   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
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   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
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   628
    WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [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
   629
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   630
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   631
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   632
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
   633
    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
   634
    //uRenderCoordScaleX, uRenderCoordScaleY: Longword;
7185
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   635
    density: Single;
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;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   638
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   639
    setLength(fingers, 4);
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   640
    for index := 0 to High(fingers) do 
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   641
        fingers[index].id := nilFingerId;
7185
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   642
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   643
{$IFDEF ANDROID}
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   644
    density:= Android_JNI_getDensity();
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   645
{$ELSE}
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   646
    density:= 1.0;
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   647
{$ENDIF}
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   648
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   649
    rectSize:= round(baseRectSize * density);
92a045156255 Android: first attempt at using the density call from java
Xeli
parents: 7105
diff changeset
   650
    halfRectSize:= rectSize shl 1;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   651
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   652
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   653
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   654
end.