- More HealthTex to clan structure
authorunc0rr
Wed, 30 Oct 2013 00:18:10 +0400
changeset 9656 18422d205080
parent 9655 e154ccca4dad
child 9657 2d8cae3c0855
- More HealthTex to clan structure - GenericHealthTexture for proper highlight tinting
hedgewars/uScript.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
hedgewars/uTypes.pas
hedgewars/uVariables.pas
hedgewars/uVisualGearsHandlers.pas
hedgewars/uWorld.pas
--- a/hedgewars/uScript.pas	Tue Oct 29 23:47:57 2013 +0400
+++ b/hedgewars/uScript.pas	Wed Oct 30 00:18:10 2013 +0400
@@ -781,8 +781,6 @@
     team : PTeam;
     hh   : THedgehog;
     i, j : LongInt;
-    r, rr: TSDL_Rect;
-    texsurf: PSDL_Surface;
 begin
     if lua_gettop(L) <> 2 then
         LuaError('Lua: Wrong number of parameters passed to SetClanColor!')
@@ -790,6 +788,7 @@
         begin
         clan := ClansArray[lua_tointeger(L, 1)];
         clan^.Color:= lua_tointeger(L, 2) shr 8;
+
         for i:= 0 to Pred(clan^.TeamsNumber) do
             begin
             team:= clan^.Teams[i];
@@ -805,24 +804,11 @@
                 end;
             FreeTexture(team^.NameTagTex);
             team^.NameTagTex:= RenderStringTex(clan^.Teams[i]^.TeamName, clan^.Color, fnt16);
-            r.w:= cTeamHealthWidth + 5;
-            r.h:= team^.NameTagTex^.h;
-
-            texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
-            TryDo(texsurf <> nil, errmsgCreateSurface, true);
-            TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
+            end;
 
-            DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true);
-            rr:= r;
-            inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
-            DrawRoundRect(@rr, clan^.Color, clan^.Color, texsurf, false);
+        clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color);
+        end;
 
-            FreeTexture(team^.HealthTex);
-            team^.HealthTex:= Surface2Tex(texsurf, false);
-            SDL_FreeSurface(texsurf);
-            MakeCrossHairs
-            end
-        end;
     lc_setclancolor:= 0
 end;
 
@@ -1898,7 +1884,6 @@
 
 
 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
-var gear: PGear;
 begin
     if lua_gettop(L) <> 4 then
         LuaError('Lua: Wrong number of parameters passed to DeclareAchievement!')
--- a/hedgewars/uStore.pas	Tue Oct 29 23:47:57 2013 +0400
+++ b/hedgewars/uStore.pas	Wed Oct 30 00:18:10 2013 +0400
@@ -29,6 +29,7 @@
 procedure StoreLoad(reload: boolean);
 procedure StoreRelease(reload: boolean);
 procedure RenderHealth(var Hedgehog: THedgehog);
+function makeHealthBarTexture(w, h, Color: Longword): PTexture;
 procedure AddProgress;
 procedure FinishProgress;
 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
@@ -119,11 +120,36 @@
     SDL_FreeSurface(tmpsurf)
 end;
 
+function makeHealthBarTexture(w, h, Color: Longword): PTexture;
+var
+    rr: TSDL_Rect;
+    texsurf: PSDL_Surface;
+begin
+    rr.x:= 0;
+    rr.y:= 0;
+    rr.w:= w;
+    rr.h:= h;
+
+    texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask);
+    TryDo(texsurf <> nil, errmsgCreateSurface, true);
+    TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
+
+    DrawRoundRect(@rr, cWhiteColor, cNearBlackColor, texsurf, true);
+
+    rr.x:= 2;
+    rr.y:= 2;
+    rr.w:= w - 4;
+    rr.h:= h - 4;
+
+    DrawRoundRect(@rr, Color, Color, texsurf, false);
+    makeHealthBarTexture:= Surface2Tex(texsurf, false);
+    SDL_FreeSurface(texsurf);
+end;
 
 procedure WriteNames(Font: THWFont);
 var t: LongInt;
     i, maxLevel: LongInt;
-    r, rr: TSDL_Rect;
+    r: TSDL_Rect;
     drY: LongInt;
     texsurf, flagsurf, iconsurf: PSDL_Surface;
     foundBot: boolean;
@@ -137,20 +163,6 @@
         begin
         NameTagTex:= RenderStringTexLim(TeamName, Clan^.Color, Font, cTeamHealthWidth);
 
-        r.w:= cTeamHealthWidth + 5;
-        r.h:= NameTagTex^.h;
-
-        texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
-        TryDo(texsurf <> nil, errmsgCreateSurface, true);
-        TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
-
-        DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true);
-        rr:= r;
-        inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
-        DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false);
-        HealthTex:= Surface2Tex(texsurf, false);
-        SDL_FreeSurface(texsurf);
-
         r.x:= 0;
         r.y:= 0;
         r.w:= 32;
@@ -246,8 +258,16 @@
         SDL_FreeSurface(iconsurf);
         iconsurf:= nil;
         end;
+
+
+for t:= 0 to Pred(ClansCount) do
+    with ClansArray[t]^ do
+        HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, Teams[0]^.NameTagTex^.h, Color);
+
+GenericHealthTexture:= makeHealthBarTexture(cTeamHealthWidth + 5, TeamsArray[0]^.NameTagTex^.h, cWhiteColor)
 end;
 
+
 procedure InitHealth;
 var i, t: LongInt;
 begin
@@ -467,7 +487,7 @@
 FreeAndNilTexture(ConfirmTexture);
 FreeAndNilTexture(ropeIconTex);
 FreeAndNilTexture(HHTexture);
-
+FreeAndNilTexture(GenericHealthTexture);
 // free all ammo name textures
 for ai:= Low(TAmmoType) to High(TAmmoType) do
     FreeAndNilTexture(Ammoz[ai].NameTex);
@@ -479,6 +499,12 @@
     CountTexz[i]:= nil
     end;
 
+    for t:= 0 to Pred(ClansCount) do
+        begin
+        if ClansArray[t] <> nil then
+            FreeAndNilTexture(ClansArray[t]^.HealthTex);
+        end;
+
     // free all team and hedgehog textures
     for t:= 0 to Pred(TeamsCount) do
         begin
@@ -486,7 +512,6 @@
             begin
             FreeAndNilTexture(TeamsArray[t]^.NameTagTex);
             FreeAndNilTexture(TeamsArray[t]^.GraveTex);
-            FreeAndNilTexture(TeamsArray[t]^.HealthTex);
             FreeAndNilTexture(TeamsArray[t]^.AIKillsTex);
             FreeAndNilTexture(TeamsArray[t]^.FlagTex);
 
--- a/hedgewars/uTeams.pas	Tue Oct 29 23:47:57 2013 +0400
+++ b/hedgewars/uTeams.pas	Wed Oct 30 00:18:10 2013 +0400
@@ -728,15 +728,17 @@
             begin
             FreeTexture(NameTagTex);
             FreeTexture(GraveTex);
-            FreeTexture(HealthTex);
             FreeTexture(AIKillsTex);
             FreeTexture(FlagTex);
             end;
 
         Dispose(TeamsArray[i]);
     end;
-for i:= 0 to Pred(ClansCount) do
-    Dispose(ClansArray[i]);
+    for i:= 0 to Pred(ClansCount) do
+        begin
+        FreeTexture(ClansArray[i]^.HealthTex);
+        Dispose(ClansArray[i]);
+        end
     end;
 TeamsCount:= 0;
 ClansCount:= 0;
--- a/hedgewars/uTypes.pas	Tue Oct 29 23:47:57 2013 +0400
+++ b/hedgewars/uTypes.pas	Wed Oct 30 00:18:10 2013 +0400
@@ -382,7 +382,6 @@
             CurrHedgehog: LongWord;
             NameTagTex: PTexture;
             GraveTex,
-            HealthTex,
             AIKillsTex,
             FlagTex: PTexture;
             Flag: shortstring;
@@ -403,6 +402,7 @@
     TClan = record
             Color: Longword;
             Teams: array[0..Pred(cMaxTeams)] of PTeam;
+            HealthTex: PTexture;
             TeamsNumber: Longword;
             TagTeamIndex: Longword;
             CurrTeam: LongWord;
--- a/hedgewars/uVariables.pas	Tue Oct 29 23:47:57 2013 +0400
+++ b/hedgewars/uVariables.pas	Wed Oct 30 00:18:10 2013 +0400
@@ -129,8 +129,9 @@
     LAND_HEIGHT      : LongInt;
     LAND_WIDTH_MASK  : LongWord;
     LAND_HEIGHT_MASK : LongWord;
-    
+
     CrosshairTexture : PTexture;
+    GenericHealthTexture : PTexture;
 
     cLeftScreenBorder     : LongInt;
     cRightScreenBorder    : LongInt;
--- a/hedgewars/uVisualGearsHandlers.pas	Tue Oct 29 23:47:57 2013 +0400
+++ b/hedgewars/uVisualGearsHandlers.pas	Wed Oct 30 00:18:10 2013 +0400
@@ -551,7 +551,7 @@
         with thexchar[i] do
           if team^.TeamHealth > 0 then
             begin
-            dec(t, team^.HealthTex^.h + 2);
+            dec(t, team^.Clan^.HealthTex^.h + 2);
             ny:= t;
             dy:= dy - ny
             end;
--- a/hedgewars/uWorld.pas	Tue Oct 29 23:47:57 2013 +0400
+++ b/hedgewars/uWorld.pas	Wed Oct 30 00:18:10 2013 +0400
@@ -1234,6 +1234,7 @@
 var t, i, h, smallScreenOffset : LongInt;
     r: TSDL_Rect;
     highlight: boolean;
+    htex: PTexture;
 begin
 if TeamsCount * 20 > Longword(cScreenHeight) div 7 then  // take up less screen on small displays
     begin
@@ -1251,7 +1252,12 @@
         highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
 
         if highlight then
+            begin
             Tint(Clan^.Color shl 8 or $FF);
+            htex:= GenericHealthTexture
+            end
+        else
+            htex:= Clan^.HealthTex;
 
          // draw name
         DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY + smallScreenOffset, NameTagTex);
@@ -1263,13 +1269,13 @@
         r.x:= 0;
         r.y:= 0;
         r.w:= 2 + TeamHealthBarWidth;
-        r.h:= HealthTex^.h;
-        DrawTextureFromRect(14, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex);
+        r.h:= htex^.h;
+        DrawTextureFromRect(14, cScreenHeight + DrawHealthY + smallScreenOffset, @r, htex);
 
         // draw health bars right border
         inc(r.x, cTeamHealthWidth + 2);
         r.w:= 3;
-        DrawTextureFromRect(TeamHealthBarWidth + 15, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex);
+        DrawTextureFromRect(TeamHealthBarWidth + 15, cScreenHeight + DrawHealthY + smallScreenOffset, @r, htex);
 
         if not hasGone then
             for i:= 0 to cMaxHHIndex do