Add key to display extra gear info tags
authorWuzzy <Wuzzy2@mail.ru>
Sun, 07 Apr 2019 18:21:14 +0200
changeset 14749 533ac9774279
parent 14748 2ad6f0555e61
child 14750 ab7bf5036314
Add key to display extra gear info tags
QTfrontend/binds.cpp
QTfrontend/binds.h
hedgewars/uCommandHandlers.pas
hedgewars/uGears.pas
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsList.pas
hedgewars/uGearsRender.pas
hedgewars/uGearsUtils.pas
hedgewars/uInputHandler.pas
hedgewars/uTypes.pas
hedgewars/uVariables.pas
--- a/QTfrontend/binds.cpp	Wed Apr 03 13:00:05 2019 +0200
+++ b/QTfrontend/binds.cpp	Sun Apr 07 18:21:14 2019 +0200
@@ -70,6 +70,7 @@
     {"capture",   "c",          QT_TRANSLATE_NOOP("binds", "capture"),         NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Take a screenshot:")},
     {"+speedup",  "s",          QT_TRANSLATE_NOOP("binds", "speed up replay"),         NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Demo replay:")},
     {"+mission",  "m",          QT_TRANSLATE_NOOP("binds", "show mission information"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Heads-up display:")},
+    {"gearinfo",  "o",          QT_TRANSLATE_NOOP("binds", "show object information"), NULL, NULL},
     //: This refers to the team info bars (name/flag/health) of all teams. These are shown at the bottom center of the screen
     {"rotmask",   "delete",     QT_TRANSLATE_NOOP("binds", "toggle team bars"), NULL, NULL},
     {"rottags",   "home",       QT_TRANSLATE_NOOP("binds", "toggle hedgehog tags"), NULL, NULL},
--- a/QTfrontend/binds.h	Wed Apr 03 13:00:05 2019 +0200
+++ b/QTfrontend/binds.h	Sun Apr 07 18:21:14 2019 +0200
@@ -22,9 +22,9 @@
 #include <QString>
 
 #ifdef VIDEOREC
-#define BINDS_NUMBER 52
+#define BINDS_NUMBER 53
 #else
-#define BINDS_NUMBER 51
+#define BINDS_NUMBER 52
 #endif
 
 struct BindAction
--- a/hedgewars/uCommandHandlers.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uCommandHandlers.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -939,6 +939,12 @@
     HideMission();
 end;
 
+procedure chGearInfo(var s: shortstring);
+begin
+  s:= s; // avoid compiler hint
+  isShowGearInfo:= not isShowGearInfo;
+end;
+
 procedure initModule;
 begin
 //////// Begin top sorted by freq analysis not including chatmsg
@@ -1031,6 +1037,7 @@
     RegisterVariable('advmapgen',@chAdvancedMapGenMode, false);
     RegisterVariable('+mission', @chShowMission_p, true);
     RegisterVariable('-mission', @chShowMission_m, true);
+    RegisterVariable('gearinfo', @chGearInfo     , true );
     RegisterVariable('timer_u' , @chTimerU       , true );
 end;
 
--- a/hedgewars/uGears.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uGears.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -686,6 +686,7 @@
     begin
     x:= hwRound(Gear^.X) + WorldDx;
     y:= hwRound(Gear^.Y) + WorldDy;
+    RenderGearHealth(Gear, x, y);
     RenderGearTimer(Gear, x, y);
     if Gear^.Kind = gtHedgehog then
         RenderHHGuiExtras(Gear, x, y);
@@ -1079,6 +1080,7 @@
         HealthCrate:
             begin
             gear^.Pos := posCaseHealth;
+            gear^.RenderHealth:= true;
             // health crate is smaller than the other crates
             gear^.Radius := cCaseHealthRadius;
             gear^.Health := content;
@@ -1125,6 +1127,7 @@
         HealthCrate:
             begin
             gear^.Pos := gear^.Pos + posCaseHealth;
+            gear^.RenderHealth:= true;
             // health crate is smaller than the other crates
             gear^.Radius := cCaseHealthRadius;
             if(FinishedTurnsTotal > -1) then
--- a/hedgewars/uGearsHandlersMess.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -2391,6 +2391,9 @@
             AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmoke)
     else
         AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmokeWhite);
+    // health texture
+    FreeAndNilTexture(Gear^.Tex);
+    Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff808080, fnt16);
     dec(Gear^.Health, Gear^.Damage);
     Gear^.Damage := 0;
     if Gear^.Health <= 0 then
@@ -2465,9 +2468,19 @@
                 AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmokeWhite);
         dec(Gear^.Health, Gear^.Damage);
         Gear^.Damage := 0;
+        // health texture
+        FreeAndNilTexture(Gear^.Tex);
+        Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff808080, fnt16);
         end
     else
         begin
+        // health texture for health crate
+        if (k = gtCase) and ((Gear^.Pos and $02) <> 0) then
+            begin
+            FreeAndNilTexture(Gear^.Tex);
+            if ((Gear^.State and gstFrozen) = 0) then
+                Gear^.Tex := RenderStringTex(ansistring(inttostr(Gear^.Health)), $ff80ff80, fnt16);
+            end;
         if Gear^.Timer = 500 then
             begin
 (* Can't make sparkles team coloured without working out what the next team is going to be. This should be solved, really, since it also screws up
--- a/hedgewars/uGearsList.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uGearsList.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -487,6 +487,8 @@
                 end;
   gtExplosives: begin
                 gear^.AdvBounce:= 1;
+                if GameType in [gmtDemo, gmtSave, gmtRecord] then
+                    gear^.RenderHealth:= true;
                 gear^.ImpactSound:= sndGrenadeImpact;
                 gear^.nImpactSounds:= 1;
                 gear^.Radius:= 16;
--- a/hedgewars/uGearsRender.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uGearsRender.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -37,6 +37,7 @@
          end;
 procedure RenderGear(Gear: PGear; x, y: LongInt);
 procedure RenderGearTimer(Gear: PGear; x, y: LongInt);
+procedure RenderGearHealth(Gear: PGear; x, y: LongInt);
 procedure RenderHHGuiExtras(Gear: PGear; ox, oy: LongInt);
 procedure DrawHHOrder();
 
@@ -1648,4 +1649,15 @@
     DrawTextureCentered(x + 8, y + 8, Gear^.Tex);
 end;
 
+procedure RenderGearHealth(Gear: PGear; x, y: LongInt);
+begin
+if isShowGearInfo and (Gear^.RenderHealth) and (Gear^.Tex <> nil) then
+    begin
+    if (Gear^.Kind = gtCase) and ((Gear^.Pos and $02) <> 0) then
+        DrawTextureCentered(x, y - 38, Gear^.Tex);
+    if (Gear^.Kind = gtExplosives) then
+        DrawTextureCentered(x, y - 38, Gear^.Tex);
+    end;
+end;
+
 end.
--- a/hedgewars/uGearsUtils.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uGearsUtils.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -1591,6 +1591,7 @@
 if t<h then
     begin
     FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0);
+    FollowGear^.RenderHealth:= true;
     FollowGear^.Health:= cHealthCaseAmount;
     FollowGear^.Pos:= posCaseHealth;
     // health crate is smaller than the other crates
--- a/hedgewars/uInputHandler.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uInputHandler.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -362,6 +362,7 @@
     RegisterBind(DefaultBinds, 'delete', 'rotmask');
     RegisterBind(DefaultBinds, 'home', 'rottags');
     RegisterBind(DefaultBinds, _S'm', '+mission');
+    RegisterBind(DefaultBinds, _S'o', 'gearinfo');
 
     //numpad
     //DefaultBinds[265]:= '+volup';
--- a/hedgewars/uTypes.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uTypes.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -257,6 +257,7 @@
             doStep: TGearStepProcedure; // Code the gear is running
             AmmoType : TAmmoType;       // Ammo type associated with this kind of gear
             RenderTimer: Boolean;       // Will visually display Timer if true
+            RenderHealth: Boolean;      // Will visually display Health if true
             Target : TPoint;            // Gear target. Will render in uGearsRender unless a special case is added
             AIHints: LongWord;          // hints for ai.
             LastDamage: PHedgehog;      // Used to track damage source for stats
--- a/hedgewars/uVariables.pas	Wed Apr 03 13:00:05 2019 +0200
+++ b/hedgewars/uVariables.pas	Sun Apr 07 18:21:14 2019 +0200
@@ -80,6 +80,7 @@
     isSpeed         : boolean;
     isAFK           : boolean;
     isShowMission   : boolean;
+    isShowGearInfo  : boolean;
     isForceMission  : boolean;
     SpeedStart      : LongWord;
 
@@ -2882,6 +2883,7 @@
     isSpeed         := false;
     isAFK           := false;
     isShowMission   := false;
+    isShowGearInfo  := false;
     isForceMission  := false;
     SpeedStart      := 0;
     fastUntilLag    := false;