hedgewars/uWorld.pas
changeset 6795 e4831e13e04a
parent 6794 95ee7bde3514
child 6796 3e89dbdc7db9
equal deleted inserted replaced
6794:95ee7bde3514 6795:e4831e13e04a
    65 var cWaveWidth, cWaveHeight: LongInt;
    65 var cWaveWidth, cWaveHeight: LongInt;
    66     AMShiftTargetX, AMShiftTargetY, AMShiftX, AMShiftY, SlotsNum: LongInt;
    66     AMShiftTargetX, AMShiftTargetY, AMShiftX, AMShiftY, SlotsNum: LongInt;
    67     tmpSurface: PSDL_Surface;
    67     tmpSurface: PSDL_Surface;
    68     fpsTexture: PTexture;
    68     fpsTexture: PTexture;
    69     timeTexture: PTexture;
    69     timeTexture: PTexture;
    70     MenuSpeedX, MenuSpeedY: LongInt;
    70     AMAnimStartTime : LongInt;
       
    71     AMAnimState: Single;
       
    72     AMState: LongInt;
    71     FPS: Longword;
    73     FPS: Longword;
    72     CountTicks: Longword;
    74     CountTicks: Longword;
    73     SoundTimerTicks: Longword;
    75     SoundTimerTicks: Longword;
    74     prevPoint: TPoint;
    76     prevPoint: TPoint;
    75     amSel: TAmmoType = amNothing;
    77     amSel: TAmmoType = amNothing;
    82       cStereo_MidDistance   = 0.0175;
    84       cStereo_MidDistance   = 0.0175;
    83       cStereo_Water_distant = 0.0125;
    85       cStereo_Water_distant = 0.0125;
    84       cStereo_Land          = 0.0075;
    86       cStereo_Land          = 0.0075;
    85       cStereo_Water_near    = 0.0025;
    87       cStereo_Water_near    = 0.0025;
    86       cStereo_Outside       = -0.0400;
    88       cStereo_Outside       = -0.0400;
    87 
       
    88 
    89 
    89 // helper functions to create the goal/game mode string
    90 // helper functions to create the goal/game mode string
    90 function AddGoal(s: ansistring; gf: longword; si: TGoalStrId; i: LongInt): ansistring;
    91 function AddGoal(s: ansistring; gf: longword; si: TGoalStrId; i: LongInt): ansistring;
    91 var t: ansistring;
    92 var t: ansistring;
    92 begin
    93 begin
   198 //aligns it to the bottom of the screen, minus the border
   199 //aligns it to the bottom of the screen, minus the border
   199 SkyOffset:= 0;
   200 SkyOffset:= 0;
   200 HorizontOffset:= 0;
   201 HorizontOffset:= 0;
   201 
   202 
   202 InitTouchInterface();
   203 InitTouchInterface();
       
   204 
   203 end;
   205 end;
   204 
   206 
   205 procedure InitCameraBorders;
   207 procedure InitCameraBorders;
   206 begin
   208 begin
   207 cGearScrEdgesDist:= min(2 * cScreenHeight div 5, 2 * cScreenWidth div 5);
   209 cGearScrEdgesDist:= min(2 * cScreenHeight div 5, 2 * cScreenWidth div 5);
   451 if amSurface <> nil then SDL_FreeSurface(amSurface);
   453 if amSurface <> nil then SDL_FreeSurface(amSurface);
   452 end;
   454 end;
   453 
   455 
   454 procedure ShowAmmoMenu;
   456 procedure ShowAmmoMenu;
   455 const BORDERSIZE = 2;
   457 const BORDERSIZE = 2;
   456       MENUSPEED = 15;
       
   457 var Slot, Pos: LongInt;
   458 var Slot, Pos: LongInt;
   458     Ammo: PHHAmmo;
   459     Ammo: PHHAmmo;
   459     c,i,g,t,STurns: LongInt;
   460     c,i,g,t,STurns: LongInt;
   460 begin
   461 begin
   461 if (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil)
   462 if (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil)
   472 Ammo:= GetAmmoByNum(LocalAmmo);
   473 Ammo:= GetAmmoByNum(LocalAmmo);
   473 Pos:= -1;
   474 Pos:= -1;
   474 if Ammo = nil then
   475 if Ammo = nil then
   475 begin
   476 begin
   476 bShowAmmoMenu:= false;
   477 bShowAmmoMenu:= false;
       
   478 AMState:= AMHidden;
   477 exit
   479 exit
   478 end;
   480 end;
   479 
   481 
   480 //Init the menu 
   482 //Init the menu 
   481 if(AmmoMenuInvalidated) then 
   483 if(AmmoMenuInvalidated) then 
   498 {$ELSE}
   500 {$ELSE}
   499         AmmoRect.x:= (cScreenWidth shr 1) - AmmoRect.w - AMSlotSize;
   501         AmmoRect.x:= (cScreenWidth shr 1) - AmmoRect.w - AMSlotSize;
   500         AmmoRect.y:= cScreenHeight - (AmmoRect.h + AMSlotSize);
   502         AmmoRect.y:= cScreenHeight - (AmmoRect.h + AMSlotSize);
   501 {$ENDIF}
   503 {$ENDIF}
   502     AMShiftTargetX:= (cScreenWidth shr 1) - AmmoRect.x;
   504     AMShiftTargetX:= (cScreenWidth shr 1) - AmmoRect.x;
   503     AMShiftTargetY:= cScreenHeight - AmmoRect.y;
   505     AMShiftTargetY:= cScreenHeight        - AmmoRect.y;
   504     AMShiftX:= AMShiftTargetX;
   506     AMShiftX:= AMShiftTargetX;
   505     AMShiftY:= AMShiftTargetY;
   507     AMShiftY:= AMShiftTargetY;
   506     
   508 end;
   507     if (AMShiftTargetX = 0) or (AMShiftTargetY = 0) then
   509 
   508         begin
   510 AMAnimState:= (RealTicks - AMAnimStartTime) / AMAnimDuration;
   509         MenuSpeedX:= MENUSPEED;
   511 if AMState = AMShowingUp then // show ammo menu
   510         MENUSpeedY:= MENUSPEED;
   512     begin
       
   513     FollowGear:= nil;
       
   514     if (cReducedQuality and rqSlowMenu) <> 0 then
       
   515         begin
       
   516         AMShiftX:= 0;
       
   517         AMShiftY:= 0;
       
   518         AMState:= AMShowing;
   511         end
   519         end
   512     else
   520     else
   513         if (AMShiftTargetX div MENUSPEED) <  (AMShiftTargetY div MENUSPEED) then
   521         if AMAnimState < 1 then
   514             begin
   522             begin
   515             MenuSpeedX:= MENUSPEED;
   523             AMShiftX:= Round(AMShiftTargetX * (1 - AMAnimState));
   516             MenuSpeedY:= AMShiftTargetY div (AMShiftTargetX div MENUSPEED);
   524             AMShiftY:= Round(AMShiftTargetY * (1 - AMAnimState));
       
   525             Tint($FF, $ff, $ff, Round($ff * AMAnimState));
   517             end
   526             end
   518         else
   527         else
   519             begin
   528             begin
   520             MenuSpeedX:= AMShiftTargetX div (AMShiftTargetY div MENUSPEED);
   529             AMShiftX:= 0;
   521             MenuSpeedY:= MENUSPEED;
   530             AMShiftY:= 0;
       
   531             CursorPoint.X:= AmmoRect.x + AmmoRect.w;
       
   532             CursorPoint.Y:= AmmoRect.y;
       
   533             AMState:= AMShowing;
   522             end;
   534             end;
   523 end;
   535     end;
   524 
   536 if AMState = AMHiding then // hide ammo menu
   525 if bShowAmmoMenu then // show ammo menu
   537     begin
   526     begin
       
   527     FollowGear:= nil;
       
   528     if (cReducedQuality and rqSlowMenu) <> 0 then
       
   529         begin
       
   530         AMShiftX:= 0;
       
   531         AMShiftY:= 0;
       
   532         end
       
   533     else
       
   534         if (AMShiftX <> 0) or (AMShiftY <> 0) then
       
   535             begin
       
   536             dec(AMShiftX, MenuSpeedX);
       
   537             if AMShiftX < 0 then AMShiftX:= 0;
       
   538             dec(AMShiftY, MenuSpeedY);
       
   539             if AMShiftY < 0 then AMShiftY:= 0;
       
   540             if (AMShiftX = 0) and (AMShiftY = 0) then
       
   541                 begin
       
   542                 CursorPoint.X:= AmmoRect.x + AmmoRect.w;
       
   543                 CursorPoint.Y:= AmmoRect.y;
       
   544                 end;
       
   545             end
       
   546     end
       
   547 else  // hide ammo menu
       
   548     begin
       
   549     if (AMShiftX = AMShiftTargetX) and (AMShiftY = AMShiftTargetY) then
       
   550         begin
       
   551         prevPoint:= CursorPoint;
       
   552         end;
       
   553     if (cReducedQuality and rqSlowMenu) <> 0 then
   538     if (cReducedQuality and rqSlowMenu) <> 0 then
   554         begin
   539         begin
   555         AMShiftX:= AMShiftTargetX;
   540         AMShiftX:= AMShiftTargetX;
   556         AMShiftY:= AMShiftTargetY;
   541         AMShiftY:= AMShiftTargetY;
       
   542         AMState:= AMHidden;
   557         end
   543         end
   558     else
   544     else
   559         if (AMShiftX <> AMShiftTargetX) or (AMShiftY <> AMShiftTargetY) then
   545         if AMAnimState < 1 then
   560             begin
   546             begin
   561             inc(AMShiftX, MenuSpeedX);
   547             AMShiftX:= Round(AMShiftTargetX * AMAnimState);
   562             if AMShiftX > AMShiftTargetX then AMShiftX:= AMShiftTargetX;
   548             AMShiftY:= Round(AMShiftTargetY * AMAnimState);
   563             inc(AMShiftY, MenuSpeedY);
   549             Tint($FF, $ff, $ff, Round($ff * (1-AMAnimState)));
   564             if AMShiftY> AMShiftTargetY then AMShiftY:= AMShiftTargetY;
       
   565             end
   550             end
   566     end;
   551          else 
   567 
   552             begin
   568     DrawTexture(AmmoRect.x + AMShiftX, AmmoRect.y + AMShiftY, AmmoMenuTex);
   553             AMShiftX:= AMShiftTargetX;
       
   554             AMShiftY:= AMShiftTargetY;
       
   555             prevPoint:= CursorPoint;
       
   556             AMState:= AMHidden;
       
   557             end;
       
   558     end;
       
   559     
       
   560 DrawTexture(AmmoRect.x + AMShiftX, AmmoRect.y + AMShiftY, AmmoMenuTex);
       
   561 Tint($FF, $ff, $ff, $ff);
   569 
   562 
   570     Pos:= -1;
   563     Pos:= -1;
   571     Slot:= -1;
   564     Slot:= -1;
   572     c:= -1;
   565     c:= -1;
   573 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   566 {$IFDEF USE_LANDSCAPE_AMMOMENU}
  1337             r.h:= 13;
  1330             r.h:= 13;
  1338             DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
  1331             DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
  1339         end;
  1332         end;
  1340 
  1333 
  1341 // AmmoMenu
  1334 // AmmoMenu
  1342 if bShowAmmoMenu or ((AMShiftX <> AMShiftTargetX) or (AMShiftY <> AMShiftTargetY)) then
  1335 if bShowAmmoMenu and ((AMState = AMHidden) or (AMState = AMHiding)) then
       
  1336     begin
       
  1337     if (AMState = AMHidden) then
       
  1338         AMAnimStartTime:= RealTicks
       
  1339     else
       
  1340         AMAnimStartTime:= RealTicks - (AMAnimDuration - (RealTicks - AMAnimStartTime));
       
  1341     AMState:= AMShowingUp;
       
  1342     end;
       
  1343 if not(bShowAmmoMenu) and ((AMstate = AMShowing) or (AMState = AMShowingUp)) then
       
  1344     begin
       
  1345     if (AMState = AMShowing) then
       
  1346         AMAnimStartTime:= RealTicks
       
  1347     else
       
  1348         AMAnimStartTime:= RealTicks - (AMAnimDuration - (RealTicks - AMAnimStartTime));
       
  1349     AMState:= AMHiding;
       
  1350     end; 
       
  1351 
       
  1352 if bShowAmmoMenu or (AMState = AMHiding) then
  1343     ShowAmmoMenu;
  1353     ShowAmmoMenu;
  1344 
  1354 
  1345 // Cursor
  1355 // Cursor
  1346 if isCursorVisible and bShowAmmoMenu then
  1356 if isCursorVisible and bShowAmmoMenu then
  1347     DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
  1357     DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
  1702 prevPoint.Y:= 0;
  1712 prevPoint.Y:= 0;
  1703 missionTimer:= 0;
  1713 missionTimer:= 0;
  1704 missionTex:= nil;
  1714 missionTex:= nil;
  1705 cOffsetY:= 0;
  1715 cOffsetY:= 0;
  1706 stereoDepth:= 0;
  1716 stereoDepth:= 0;
       
  1717 AMState:= AMHidden;
  1707 end;
  1718 end;
  1708 
  1719 
  1709 procedure freeModule;
  1720 procedure freeModule;
  1710 begin
  1721 begin
  1711 stereoDepth:= stereoDepth; // avoid hint
  1722 stereoDepth:= stereoDepth; // avoid hint