hedgewars/uWorld.pas
branchqmlfrontend
changeset 10748 dc587913987c
parent 10672 c2004c3e9c7d
child 10818 f642a28cab0c
equal deleted inserted replaced
10616:20a2d5e6930a 10748:dc587913987c
   226 uCursor.init();
   226 uCursor.init();
   227 prevPoint.X:= 0;
   227 prevPoint.X:= 0;
   228 prevPoint.Y:= cScreenHeight div 2;
   228 prevPoint.Y:= cScreenHeight div 2;
   229 //prevTargetPoint.X:= 0;
   229 //prevTargetPoint.X:= 0;
   230 //prevTargetPoint.Y:= 0;
   230 //prevTargetPoint.Y:= 0;
   231 WorldDx:=  -(LAND_WIDTH div 2);// + cScreenWidth div 2;
   231 WorldDx:=  -(LongInt(leftX + (playWidth div 2))); // -(LAND_WIDTH div 2);// + cScreenWidth div 2;
   232 WorldDy:=  -(LAND_HEIGHT - (playHeight div 2)) + (cScreenHeight div 2);
   232 WorldDy:=  -(LAND_HEIGHT - (playHeight div 2)) + (cScreenHeight div 2);
   233 
   233 
   234 //aligns it to the bottom of the screen, minus the border
   234 //aligns it to the bottom of the screen, minus the border
   235 SkyOffset:= 0;
   235 SkyOffset:= 0;
   236 HorizontOffset:= 0;
   236 HorizontOffset:= 0;
   402 end;
   402 end;
   403 
   403 
   404 // for uStore texture resetting
   404 // for uStore texture resetting
   405 procedure ResetWorldTex;
   405 procedure ResetWorldTex;
   406 begin
   406 begin
   407     FreeTexture(fpsTexture);
   407     FreeAndNilTexture(fpsTexture);
   408     fpsTexture:= nil;
   408     FreeAndNilTexture(timeTexture);
   409     FreeTexture(timeTexture);
   409     FreeAndNilTexture(missionTex);
   410     timeTexture:= nil;
   410     FreeAndNilTexture(recTexture);
   411     FreeTexture(missionTex);
   411     FreeAndNilTexture(AmmoMenuTex);
   412     missionTex:= nil;
       
   413     FreeTexture(recTexture);
       
   414     recTexture:= nil;
       
   415     FreeTexture(AmmoMenuTex);
       
   416     AmmoMenuInvalidated:= true;
   412     AmmoMenuInvalidated:= true;
   417     AmmoMenuTex:= nil;
       
   418 end;
   413 end;
   419 
   414 
   420 function GetAmmoMenuTexture(Ammo: PHHAmmo): PTexture;
   415 function GetAmmoMenuTexture(Ammo: PHHAmmo): PTexture;
   421 const BORDERSIZE = 2;
   416 const BORDERSIZE = 2;
   422 var x, y, i, t, SlotsNumY, SlotsNumX, AMFrame: LongInt;
   417 var x, y, i, t, SlotsNumY, SlotsNumX, AMFrame: LongInt;
   564 
   559 
   565 //Init the menu
   560 //Init the menu
   566 if(AmmoMenuInvalidated) then
   561 if(AmmoMenuInvalidated) then
   567     begin
   562     begin
   568     AmmoMenuInvalidated:= false;
   563     AmmoMenuInvalidated:= false;
   569     FreeTexture(AmmoMenuTex);
   564     FreeAndNilTexture(AmmoMenuTex);
   570     AmmoMenuTex:= GetAmmoMenuTexture(Ammo);
   565     AmmoMenuTex:= GetAmmoMenuTexture(Ammo);
   571 
   566 
   572 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   567 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   573     if isPhone() then
   568     if isPhone() then
   574         begin
   569         begin
   747             if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
   742             if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
   748                 begin
   743                 begin
   749                 bShowAmmoMenu:= false;
   744                 bShowAmmoMenu:= false;
   750                 SetWeapon(Ammo^[Slot, Pos].AmmoType);
   745                 SetWeapon(Ammo^[Slot, Pos].AmmoType);
   751                 bSelected:= false;
   746                 bSelected:= false;
   752                 FreeWeaponTooltip;
   747                 FreeAndNilTexture(WeaponTooltipTex);
   753 {$IFDEF USE_TOUCH_INTERFACE}//show the aiming buttons + animation
   748 {$IFDEF USE_TOUCH_INTERFACE}//show the aiming buttons + animation
   754                 if (Ammo^[Slot, Pos].Propz and ammoprop_NeedUpDown) <> 0 then
   749                 if (Ammo^[Slot, Pos].Propz and ammoprop_NeedUpDown) <> 0 then
   755                     begin
   750                     begin
   756                     if (not arrowUp.show) then
   751                     if (not arrowUp.show) then
   757                         begin
   752                         begin
   770                 exit
   765                 exit
   771                 end;
   766                 end;
   772             end
   767             end
   773         end
   768         end
   774     else
   769     else
   775         FreeWeaponTooltip;
   770         FreeAndNilTexture(WeaponTooltipTex);
   776 
   771 
   777     if (WeaponTooltipTex <> nil) and (AMShiftX = 0) and (AMShiftY = 0) then
   772     if (WeaponTooltipTex <> nil) and (AMShiftX = 0) and (AMShiftY = 0) then
   778 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   773 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   779         if (not isPhone()) then
   774         if (not isPhone()) then
   780             ShowWeaponTooltip(-WeaponTooltipTex^.w div 2, AmmoRect.y - WeaponTooltipTex^.h - AMSlotSize);
   775             ShowWeaponTooltip(-WeaponTooltipTex^.w div 2, AmmoRect.y - WeaponTooltipTex^.h - AMSlotSize);
  1030 
  1025 
  1031     if w > 0 then
  1026     if w > 0 then
  1032         begin
  1027         begin
  1033         rect.w:= w;
  1028         rect.w:= w;
  1034         rect.x:= ViewLeftX;
  1029         rect.x:= ViewLeftX;
  1035         DrawRect(rect, $30, $30, $30, $40, true);
  1030         DrawRect(rect, $10, $10, $10, $80, true);
  1036         if WorldEdge = weBounce then
  1031         if WorldEdge = weBounce then
  1037             DrawLineOnScreen(tmp - 1, ViewTopY, tmp - 1, ViewBottomY, 2, $54, $54, $FF, $FF);
  1032             DrawLineOnScreen(tmp - 1, ViewTopY, tmp - 1, ViewBottomY, 2, $54, $54, $FF, $FF);
  1038         end;
  1033         end;
  1039 
  1034 
  1040     tmp:= LongInt(rightX) + WorldDx;
  1035     tmp:= LongInt(rightX) + WorldDx;
  1042 
  1037 
  1043     if w > 0 then
  1038     if w > 0 then
  1044         begin
  1039         begin
  1045         rect.w:= w;
  1040         rect.w:= w;
  1046         rect.x:= tmp;
  1041         rect.x:= tmp;
  1047         DrawRect(rect, $30, $30, $30, $40, true);
  1042         DrawRect(rect, $10, $10, $10, $80, true);
  1048         if WorldEdge = weBounce then
  1043         if WorldEdge = weBounce then
  1049             DrawLineOnScreen(tmp - 1, ViewTopY, tmp - 1, ViewBottomY, 2, $54, $54, $FF, $FF);
  1044             DrawLineOnScreen(tmp - 1, ViewTopY, tmp - 1, ViewBottomY, 2, $54, $54, $FF, $FF);
  1050         end;
  1045         end;
  1051 
  1046 
  1052     (*
  1047     (*
  1680         s:= inttostr(i div 60) + ':' + s;
  1675         s:= inttostr(i div 60) + ':' + s;
  1681 
  1676 
  1682 
  1677 
  1683         tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
  1678         tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
  1684         tmpSurface:= doSurfaceConversion(tmpSurface);
  1679         tmpSurface:= doSurfaceConversion(tmpSurface);
  1685         FreeTexture(timeTexture);
  1680         FreeAndNilTexture(timeTexture);
  1686         timeTexture:= Surface2Tex(tmpSurface, false);
  1681         timeTexture:= Surface2Tex(tmpSurface, false);
  1687         SDL_FreeSurface(tmpSurface)
  1682         SDL_FreeSurface(tmpSurface)
  1688         end;
  1683         end;
  1689 
  1684 
  1690     if timeTexture <> nil then
  1685     if timeTexture <> nil then
  1698             Frames:= 0;
  1693             Frames:= 0;
  1699             CountTicks:= 0;
  1694             CountTicks:= 0;
  1700             s:= inttostr(FPS) + ' fps';
  1695             s:= inttostr(FPS) + ' fps';
  1701             tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
  1696             tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
  1702             tmpSurface:= doSurfaceConversion(tmpSurface);
  1697             tmpSurface:= doSurfaceConversion(tmpSurface);
  1703             FreeTexture(fpsTexture);
  1698             FreeAndNilTexture(fpsTexture);
  1704             fpsTexture:= Surface2Tex(tmpSurface, false);
  1699             fpsTexture:= Surface2Tex(tmpSurface, false);
  1705             SDL_FreeSurface(tmpSurface)
  1700             SDL_FreeSurface(tmpSurface)
  1706             end;
  1701             end;
  1707         if fpsTexture <> nil then
  1702         if fpsTexture <> nil then
  1708             DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture);
  1703             DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture);
  1761     if recTexture = nil then
  1756     if recTexture = nil then
  1762         begin
  1757         begin
  1763         s:= 'rec';
  1758         s:= 'rec';
  1764         tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fntBig].Handle, Str2PChar(s), cWhiteColorChannels);
  1759         tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fntBig].Handle, Str2PChar(s), cWhiteColorChannels);
  1765         tmpSurface:= doSurfaceConversion(tmpSurface);
  1760         tmpSurface:= doSurfaceConversion(tmpSurface);
  1766         FreeTexture(recTexture);
  1761         FreeAndNilTexture(recTexture);
  1767         recTexture:= Surface2Tex(tmpSurface, false);
  1762         recTexture:= Surface2Tex(tmpSurface, false);
  1768         SDL_FreeSurface(tmpSurface)
  1763         SDL_FreeSurface(tmpSurface)
  1769         end;
  1764         end;
  1770     DrawTexture( -(cScreenWidth shr 1) + 50, 20, recTexture);
  1765     DrawTexture( -(cScreenWidth shr 1) + 50, 20, recTexture);
  1771 
  1766 
  1860 {$IFNDEF MOBILE}
  1855 {$IFNDEF MOBILE}
  1861 if (not (CurrentTeam^.ExtDriven and isCursorVisible and (not bShowAmmoMenu) and autoCameraOn)) and cHasFocus and (GameState <> gsConfirm) then
  1856 if (not (CurrentTeam^.ExtDriven and isCursorVisible and (not bShowAmmoMenu) and autoCameraOn)) and cHasFocus and (GameState <> gsConfirm) then
  1862     uCursor.updatePosition();
  1857     uCursor.updatePosition();
  1863 {$ENDIF}
  1858 {$ENDIF}
  1864 z:= round(200/zoom);
  1859 z:= round(200/zoom);
  1865 inbtwnTrgtAttks := (CurrentHedgehog <> nil) and ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) <> 0) and ((GameFlags and gfInfAttack) <> 0);
  1860 inbtwnTrgtAttks := ((GameFlags and gfInfAttack) <> 0) and (CurrentHedgehog <> nil) and ((CurrentHedgehog^.Gear = nil) or (CurrentHedgehog^.Gear <> FollowGear)) and ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) <> 0);
  1866 if autoCameraOn and (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not bShowAmmoMenu) and (not fastUntilLag) and (not inbtwnTrgtAttks) then
  1861 if autoCameraOn and (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not bShowAmmoMenu) and (not fastUntilLag) and (not inbtwnTrgtAttks) then
  1867     if ((abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y)) > 4) then
  1862     if ((abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y)) > 4) then
  1868         begin
  1863         begin
  1869         FollowGear:= nil;
  1864         FollowGear:= nil;
  1870         prevPoint:= CursorPoint;
  1865         prevPoint:= CursorPoint;
  1871         exit
  1866         exit
  1872         end
  1867         end
  1873     else
  1868     else
  1874         begin
  1869         begin
  1875         if abs(prevPoint.X - WorldDx - hwRound(FollowGear^.X)) > LongInt(rightX) - leftX - 100 then
  1870         if (WorldEdge = weWrap) then
       
  1871             cameraJump:= LongInt(playWidth) div 2 + 50
       
  1872         else
       
  1873             cameraJump:= LongInt(rightX) - leftX - 100;
       
  1874 
       
  1875         if abs(prevPoint.X - WorldDx - hwRound(FollowGear^.X)) > cameraJump then
  1876             begin
  1876             begin
  1877             if (prevPoint.X - WorldDx) * 2 < LongInt((rightX + leftX)) then
  1877             if prevPoint.X - WorldDx < LongInt(playWidth div 2) then
  1878                 cameraJump:= LongInt(rightX) - leftX
  1878                 cameraJump:= LongInt(playWidth)
  1879                 else
  1879             else
  1880                 cameraJump:= LongInt(leftX) - rightX;
  1880                 cameraJump:= -LongInt(playWidth);
  1881             WorldDx:= WorldDx - cameraJump;
  1881             WorldDx:= WorldDx - cameraJump;
  1882             end;
  1882             end;
  1883 
  1883 
  1884         CursorPoint.X:= (prevPoint.X * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * z + WorldDx) div 8;
  1884         CursorPoint.X:= (prevPoint.X * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * z + WorldDx) div 8;
  1885 
  1885 
  1999 r.h:= 32;
  1999 r.h:= 32;
  2000 
  2000 
  2001 if time = 0 then
  2001 if time = 0 then
  2002     time:= 5000;
  2002     time:= 5000;
  2003 missionTimer:= time;
  2003 missionTimer:= time;
  2004 FreeTexture(missionTex);
  2004 FreeAndNilTexture(missionTex);
  2005 
  2005 
  2006 if icon > -1 then
  2006 if icon > -1 then
  2007     begin
  2007     begin
  2008     r.x:= 0;
  2008     r.x:= 0;
  2009     r.y:= icon * 32;
  2009     r.y:= icon * 32;