Render mine timer if gear info is active
authorWuzzy <Wuzzy2@mail.ru>
Sun, 07 Apr 2019 19:26:16 +0200
changeset 14771 ab7bf5036314
parent 14770 533ac9774279
child 14772 430c90fa6062
Render mine timer if gear info is active
hedgewars/uGears.pas
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsList.pas
hedgewars/uGearsRender.pas
hedgewars/uScript.pas
--- a/hedgewars/uGears.pas	Sun Apr 07 18:21:14 2019 +0200
+++ b/hedgewars/uGears.pas	Sun Apr 07 19:26:16 2019 +0200
@@ -274,10 +274,25 @@
             end;
         if curHandledGear^.Active then
             begin
-            if curHandledGear^.RenderTimer and (curHandledGear^.Timer > 500) and ((curHandledGear^.Timer mod 1000) = 0) then
+            if curHandledGear^.RenderTimer then
                 begin
-                FreeAndNilTexture(curHandledGear^.Tex);
-                curHandledGear^.Tex:= RenderStringTex(ansistring(inttostr(curHandledGear^.Timer div 1000)), cWhiteColor, fntSmall);
+                if (curHandledGear^.Kind in [gtMine, gtSMine, gtAirMine]) then
+                    begin
+                    if curHandledGear^.Tex = nil then
+                        begin
+                        i:= curHandledGear^.Timer;
+                        if (i > 0) and (i < 1000)  then
+                            i:= 1
+                        else
+                            i:= curHandledGear^.Timer div 1000;
+                        curHandledGear^.Tex:= RenderStringTex(ansistring(inttostr(i)), $ff808080, fntSmall);
+                        end;
+                    end
+                else if ((curHandledGear^.Timer > 500) and ((curHandledGear^.Timer mod 1000) = 0)) then
+                    begin
+                    FreeAndNilTexture(curHandledGear^.Tex);
+                    curHandledGear^.Tex:= RenderStringTex(ansistring(inttostr(curHandledGear^.Timer div 1000)), cWhiteColor, fntSmall);
+                    end;
                 end;
             curHandledGear^.doStep(curHandledGear);
             end
--- a/hedgewars/uGearsHandlersMess.pas	Sun Apr 07 18:21:14 2019 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Sun Apr 07 19:26:16 2019 +0200
@@ -1951,6 +1951,7 @@
     dmg: LongWord;
 begin
     if Gear^.Health = 0 then dxdy:= hwAbs(Gear^.dX)+hwAbs(Gear^.dY);
+    Gear^.RenderTimer:= ((Gear^.State and gstFrozen) = 0) and ((Gear^.State and gstAttacking) = 0) and (Gear^.Health <> 0);
     if (Gear^.State and gstMoving) <> 0 then
         begin
         DeleteCI(Gear);
@@ -2049,6 +2050,7 @@
     sparkle: PVisualGear;
 begin
     targ:= nil;
+    Gear^.RenderTimer:= ((Gear^.State and gstFrozen) = 0) and ((Gear^.State and gstAttacking) = 0);
     if (Gear^.State and gstFrozen) <> 0 then
         begin
         if Gear^.Damage > 0 then
@@ -2288,6 +2290,7 @@
         CalcRotationDirAngle(Gear);
         end;
 
+    Gear^.RenderTimer:= ((Gear^.State and gstFrozen) = 0) and ((Gear^.State and gstAttacking) = 0);
     if ((Gear^.State and gsttmpFlag) <> 0) and (Gear^.Health <> 0) then
         begin
         if ((Gear^.State and gstAttacking) = 0) and ((Gear^.State and gstFrozen) = 0) then
--- a/hedgewars/uGearsList.pas	Sun Apr 07 18:21:14 2019 +0200
+++ b/hedgewars/uGearsList.pas	Sun Apr 07 19:26:16 2019 +0200
@@ -433,7 +433,8 @@
                         gear^.Timer:= getrandom(51)*100
                     else
                         gear^.Timer:= cMinesTime
-                    end
+                    end;
+                gear^.RenderTimer:= true;
                 end;
      gtAirMine: begin
                 gear^.AdvBounce:= 1;
@@ -449,6 +450,7 @@
                 gear^.Power:= cMaxWindSpeed.QWordValue div 2; // hwFloat converted. 1/2 g default. defines the "seek" speed when a gear is in range.
                 gear^.Pos:= cMaxWindSpeed.QWordValue * 3 div 2; // air friction. slows it down when not hitting stuff
                 gear^.Tag:= 0;
+                gear^.RenderTimer:= true;
                 if gear^.Timer = 0 then
                     begin
                     if cMinesTime < 0 then
@@ -468,6 +470,7 @@
                 gear^.AdvBounce:= 1;
                 gear^.Sticky:= true;
                 if gear^.Timer = 0 then gear^.Timer:= 500;
+                gear^.RenderTimer:= true;
                 end;
        gtKnife: begin
                 gear^.ImpactSound:= sndKnifeImpact;
--- a/hedgewars/uGearsRender.pas	Sun Apr 07 18:21:14 2019 +0200
+++ b/hedgewars/uGearsRender.pas	Sun Apr 07 19:26:16 2019 +0200
@@ -1645,7 +1645,7 @@
 
 procedure RenderGearTimer(Gear: PGear; x, y: LongInt);
 begin
-if Gear^.RenderTimer and (Gear^.Tex <> nil) then
+if Gear^.RenderTimer and (Gear^.Tex <> nil) and (isShowGearInfo or (not (Gear^.Kind in [gtMine, gtSMine, gtAirMine]))) then
     DrawTextureCentered(x + 8, y + 8, Gear^.Tex);
 end;
 
--- a/hedgewars/uScript.pas	Sun Apr 07 18:21:14 2019 +0200
+++ b/hedgewars/uScript.pas	Sun Apr 07 19:26:16 2019 +0200
@@ -1907,7 +1907,12 @@
     if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then
         begin
         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
-        if gear <> nil then gear^.Timer:= Trunc(lua_tonumber(L, 2))
+        if gear <> nil then
+            begin
+            gear^.Timer:= Trunc(lua_tonumber(L, 2));
+            if gear^.RenderTimer and (gear^.Tex <> nil) then
+                FreeAndNilTexture(gear^.Tex);
+            end;
         end;
     lc_settimer:= 0
 end;