Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
Also add GearHidden to health recount.
Oh. and NEEDS TESTING.
--- a/hedgewars/uScript.pas Sun Jan 30 20:04:34 2011 +0100
+++ b/hedgewars/uScript.pas Sun Jan 30 17:54:02 2011 -0500
@@ -58,7 +58,10 @@
uUtils,
uCaptions,
uDebug,
- uCollisions;
+ uCollisions,
+ uRenderUtils,
+ uTextures,
+ SDLh;
var luaState : Plua_State;
ScriptAmmoLoadout : shortstring;
@@ -549,11 +552,52 @@
end;
function lc_setclancolor(L : Plua_State) : LongInt; Cdecl;
-var gear : PGear;
+var clan : PClan;
+ 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!')
- else ClansArray[lua_tointeger(L, 1)]^.Color:= lua_tointeger(L, 2) shr 8;
+ else
+ 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];
+ for j:= 0 to 7 do
+ begin
+ hh:= team^.Hedgehogs[i];
+ if (hh.Gear <> nil) and (hh.GearHidden <> nil) then
+ begin
+ FreeTexture(hh.NameTagTex);
+ hh.NameTagTex:= RenderStringTex(hh.Name, clan^.Color, fnt16);
+ RenderHealth(hh);
+ end;
+ 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);
+
+ DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, 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);
+
+ FreeTexture(team^.HealthTex);
+ team^.HealthTex:= Surface2Tex(texsurf, false);
+ SDL_FreeSurface(texsurf);
+ MakeCrossHairs
+ end
+ end;
lc_setclancolor:= 0
end;
--- a/hedgewars/uStore.pas Sun Jan 30 20:04:34 2011 +0100
+++ b/hedgewars/uStore.pas Sun Jan 30 17:54:02 2011 -0500
@@ -39,6 +39,7 @@
procedure RenderWeaponTooltip(atype: TAmmoType);
procedure ShowWeaponTooltip(x, y: LongInt);
procedure FreeWeaponTooltip;
+procedure MakeCrossHairs;
implementation
uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, uDebug;
@@ -75,6 +76,47 @@
WriteInRect:= finalRect
end;
+procedure MakeCrossHairs;
+var t: LongInt;
+ tmpsurf, texsurf: PSDL_Surface;
+ Color, i: Longword;
+ s : shortstring;
+begin
+s:= Pathz[ptGraphics] + '/' + cCHFileName;
+tmpsurf:= LoadImage(s, ifAlpha or ifCritical);
+
+for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
+ begin
+ texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask);
+ TryDo(texsurf <> nil, errmsgCreateSurface, true);
+
+ Color:= Clan^.Color;
+ Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF);
+ SDL_FillRect(texsurf, nil, Color);
+
+ SDL_UpperBlit(tmpsurf, nil, texsurf, nil);
+
+ TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true);
+
+ if SDL_MustLock(texsurf) then
+ SDLTry(SDL_LockSurface(texsurf) >= 0, true);
+
+ // make black pixel be alpha-transparent
+ for i:= 0 to texsurf^.w * texsurf^.h - 1 do
+ if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color;
+
+ if SDL_MustLock(texsurf) then
+ SDL_UnlockSurface(texsurf);
+
+ if CrosshairTex <> nil then FreeTexture(CrosshairTex);
+ CrosshairTex:= Surface2Tex(texsurf, false);
+ SDL_FreeSurface(texsurf)
+ end;
+
+SDL_FreeSurface(tmpsurf)
+end;
+
procedure StoreLoad;
var s: shortstring;
@@ -152,7 +194,7 @@
with Hedgehogs[i] do
if Gear <> nil then
begin
- NameTagTex:= RenderStringTex(Name, Clan^.Color, CheckCJKFont(Name,fnt16));
+ NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16);
if Hat <> 'NoHat' then
begin
if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then
@@ -177,45 +219,6 @@
end;
end;
- procedure MakeCrossHairs;
- var t: LongInt;
- tmpsurf, texsurf: PSDL_Surface;
- Color, i: Longword;
- begin
- s:= Pathz[ptGraphics] + '/' + cCHFileName;
- tmpsurf:= LoadImage(s, ifAlpha or ifCritical);
-
- for t:= 0 to Pred(TeamsCount) do
- with TeamsArray[t]^ do
- begin
- texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask);
- TryDo(texsurf <> nil, errmsgCreateSurface, true);
-
- Color:= Clan^.Color;
- Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF);
- SDL_FillRect(texsurf, nil, Color);
-
- SDL_UpperBlit(tmpsurf, nil, texsurf, nil);
-
- TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true);
-
- if SDL_MustLock(texsurf) then
- SDLTry(SDL_LockSurface(texsurf) >= 0, true);
-
- // make black pixel be alpha-transparent
- for i:= 0 to texsurf^.w * texsurf^.h - 1 do
- if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color;
-
- if SDL_MustLock(texsurf) then
- SDL_UnlockSurface(texsurf);
-
- CrosshairTex:= Surface2Tex(texsurf, false);
- SDL_FreeSurface(texsurf)
- end;
-
- SDL_FreeSurface(tmpsurf)
- end;
-
procedure InitHealth;
var i, t: LongInt;
begin
--- a/hedgewars/uTeams.pas Sun Jan 30 20:04:34 2011 +0100
+++ b/hedgewars/uTeams.pas Sun Jan 30 17:54:02 2011 -0500
@@ -372,7 +372,9 @@
if not hasGone then
for i:= 0 to cMaxHHIndex do
if Hedgehogs[i].Gear <> nil then
- inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health);
+ inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health)
+ else if Hedgehogs[i].GearHidden <> nil then
+ inc(NewTeamHealthBarWidth, Hedgehogs[i].GearHidden^.Health);
TeamHealth:= NewTeamHealthBarWidth;
if NewTeamHealthBarWidth > MaxTeamHealth then