hedgewars/uTouch.pas
changeset 6951 a37e470c8694
parent 6950 f34ff54b0cbd
child 6955 71498ea59193
equal deleted inserted replaced
6950:f34ff54b0cbd 6951:a37e470c8694
    20 
    20 
    21 unit uTouch;
    21 unit uTouch;
    22 
    22 
    23 interface
    23 interface
    24 
    24 
    25 uses sysutils, uConsole, uVariables, SDLh, uFloat, uConsts, uCommands, uIO, GLUnit, uTypes;
    25 uses sysutils, uConsole, uVariables, SDLh, uFloat, uConsts, uCommands, uIO, GLUnit, uTypes, uCaptions;
    26 
    26 
    27 
    27 
    28 procedure initModule;
    28 procedure initModule;
    29 
    29 
    30 procedure ProcessTouch;
    30 procedure ProcessTouch;
    78     aimingCrosshair: boolean;
    78     aimingCrosshair: boolean;
    79     aimingUp, aimingDown: boolean; 
    79     aimingUp, aimingDown: boolean; 
    80     targetAngle: LongInt;
    80     targetAngle: LongInt;
    81 
    81 
    82     buttonsDown: Longword;
    82     buttonsDown: Longword;
       
    83     targetting: boolean; //true when targetting an airstrike or the like
    83 
    84 
    84 procedure onTouchDown(x,y: Longword; pointerId: TSDL_FingerId);
    85 procedure onTouchDown(x,y: Longword; pointerId: TSDL_FingerId);
    85 var 
    86 var 
    86     finger: PTouch_Data;
    87     finger: PTouch_Data;
    87 begin
    88 begin
    98     exit;
    99     exit;
    99 end;
   100 end;
   100 
   101 
   101 if isOnWidget(fireButton, finger^) then
   102 if isOnWidget(fireButton, finger^) then
   102     begin
   103     begin
   103     ParseTeamCommand('+attack');
   104     if not((CurrentHedgehog <> nil) and 
       
   105        (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0)) then
       
   106         ParseTeamCommand('+attack');
   104     moveCursor:= false;
   107     moveCursor:= false;
   105     finger^.pressedWidget:= @fireButton;
   108     finger^.pressedWidget:= @fireButton;
   106     exit;
   109     exit;
   107     end;
   110     end;
   108 if isOnWidget(arrowLeft, finger^) then
   111 if isOnWidget(arrowLeft, finger^) then
   150     end; 
   153     end; 
   151 dec(buttonsDown);//no buttonsDown, undo the inc() above
   154 dec(buttonsDown);//no buttonsDown, undo the inc() above
   152 if buttonsDown = 0 then
   155 if buttonsDown = 0 then
   153     begin
   156     begin
   154     moveCursor:= true;
   157     moveCursor:= true;
   155     if pointerCount = 2 then
   158     case pointerCount of
   156         begin
   159         1:
   157         moveCursor:= false;
   160             targetting:= (CurrentHedgehog <> nil) and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0);
   158         pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
   161         2:
   159         baseZoomValue := ZoomValue
   162             begin
   160     end;
   163             moveCursor:= false;
   161 end;
   164             pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
       
   165             baseZoomValue := ZoomValue
       
   166             end;
       
   167         end;
       
   168     end;
   162 {$ENDIF}
   169 {$ENDIF}
   163 end;
   170 end;
   164 
   171 
   165 procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: TSDL_FingerId);
   172 procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: TSDL_FingerId);
   166 var
   173 var
   246 
   253 
   247     if widget = @arrowDown then
   254     if widget = @arrowDown then
   248         ParseTeamCommand('-down');
   255         ParseTeamCommand('-down');
   249 
   256 
   250     if widget = @fireButton then
   257     if widget = @fireButton then
   251         ParseTeamCommand('-attack');
   258         if (CurrentHedgehog <> nil) and 
   252     end;
   259            (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0)then
       
   260             ParseTeamCommand('put')
       
   261         else
       
   262             ParseTeamCommand('-attack');
       
   263     end;
       
   264         
       
   265 if targetting then
       
   266     AddCaption('Press the attack button to mark the target', cWhiteColor, capgrpAmmoInfo);
   253  
   267  
   254 deleteFinger(pointerId);
   268 deleteFinger(pointerId);
   255 {$ENDIF}
   269 {$ENDIF}
   256 end;
   270 end;
   257 
   271 
   268     begin
   282     begin
   269     ParseTeamCommand('ljump');
   283     ParseTeamCommand('ljump');
   270     exit;
   284     exit;
   271     end;
   285     end;
   272 
   286 
   273 if (CurrentHedgehog <> nil) and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0)then
       
   274     ParseTeamCommand('put');
       
   275 {$ENDIF}
   287 {$ENDIF}
   276 end;
   288 end;
   277 
   289 
   278 procedure onTouchClick(finger: TTouch_Data);
   290 procedure onTouchClick(finger: TTouch_Data);
   279 begin
   291 begin
   391 
   403 
   392 procedure ProcessTouch;
   404 procedure ProcessTouch;
   393 var
   405 var
   394     deltaAngle: LongInt;
   406     deltaAngle: LongInt;
   395 begin
   407 begin
   396 invertCursor := not(bShowAmmoMenu);
   408 invertCursor := not(bShowAmmoMenu or targetting); 
   397 if aimingCrosshair then
   409 if aimingCrosshair then
   398     if CurrentHedgehog^.Gear <> nil then
   410     if CurrentHedgehog^.Gear <> nil then
   399         begin
   411         begin
   400         deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle;
   412         deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle;
   401         if (deltaAngle > -5) and (deltaAngle < 5) then 
   413         if (deltaAngle > -5) and (deltaAngle < 5) then