PDA

View Full Version : Code review: sgHUD



Higor
05-26-2012, 05:50 PM
Fixing log spams on sgHUD:

DrawIdentifyInfo:
Unified indentation style, added safer checks, moved code that draws sgBuilding info inside a block that checks if we're aiming at a sgBuilding.

simulated function bool DrawIdentifyInfo(canvas Canvas)
{
local sgTeleporter tel;
local string s, timeleft;
local float l,buildTime;

local bool bSiegeStats;

local PlayerReplicationInfo BuilderPRI;
local sgBuilding Building;
local Pawn ViewedBuilder;

local float NextLVCost;
local int BasicUpgradeCost;

if ( PlayerPawn(Owner) != none )
{
if ( sgPRI(PlayerPawn(Owner).PlayerReplicationInfo) != None )
l = sgPRI(PlayerPawn(Owner).PlayerReplicationInfo).iSt atus;
if (int(l/2)*2 != l)
bSiegeStats = true;
}

if (bSiegeStats)
return false;

if ( !TraceIdentify(Canvas) )
return false;


if( sgBuilding(IdentifyPawn) != None )
{
// We Are Looking at a building
if ( IdentifyPawn.bDeleteMe )
return false;

Building = sgBuilding(IdentifyPawn); //Higor, don't do a subclass lookup like 20 times.

if ( IdentifyPawn.Owner != None ) //Higor, why check for sgBuilding(IdentifyPawn) like 4 times if it can be done once?
BuilderPRI = Pawn(Building.Owner).PlayerReplicationInfo;

s = string(Building.Energy / Building.MaxEnergy * 100);

s = left(s, InStr(s, ".")+nHUDDecPlaces+1);
if (right(s,1)==".")
s = left(s,len(s)-1);
s = s @ "%";

Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
DrawTwoColorID(Canvas,Building.BuildingName $ ": ", s,Canvas.ClipY - 216 * Scale);

Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);

if( Building.bNoUpgrade == True )
s = "N/A";
else
{
s = string(Building.Grade);
s = left(s, InStr(s, ".")+nHUDDecPlaces+1);
if (right(s,1)==".")
s = left(s,len(s)-1);
if( Building.Grade != 5 && ( Building.Team == PlayerPawn(Owner).PlayerReplicationInfo.Team || Spectator(Owner) != None ))
{
NextLVCost = Building.Grade - int(Building.Grade);
NextLVCost = 1 - NextLVCost;
if( NextLVCost == 0 )
NextLVCost=1;
if( WildcardsForceField(IdentifyPawn) != None )
BasicUpgradeCost=class'WildcardsForceField'.defaul t.UpgradeCost;
else
BasicUpgradeCost=Building.UpgradeCost;
// log(NextLVCost); //Higor: make this log only happen if we are on debug mode, maybe bDebugMode boolean? Log spamming every Tick is BAD
NextLVCost *= ( BasicUpgradeCost * (int(Building.Grade)+1));
s = s$" [Next Level:"@Left( string(NextLVCost) ,InStr( string(NextLVCost), "."))$" RU]";
}
}

DrawTwoColorID(Canvas,"Level:",s,Canvas.ClipY - 176 * Scale);

if ( BuilderPRI != None ) //Higor: only happens if looking at building, place it inside building status code block
{
Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
DrawTwoColorID(Canvas,"Built by:",
BuilderPRI.PlayerName,
Canvas.ClipY - 136 * Scale);
}

if(!Building.DoneBuilding) //Higor: same here, placing it in this block ensures Building exists and preventes yet another log warning
{
buildTime = Building.BuildTime / Building.GS;
timeleft = string(buildTime - (buildTime * (Building.TotalSCount - Building.SCount) / Building.TotalSCount));
timeleft = left(timeleft, InStr(timeleft, ".")+nHUDDecPlaces+1);

if(float(timeleft) > 0)
{
Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
DrawTwoColorID(Canvas,"Time left:", timeleft @ "sec" ,Canvas.ClipY - 96 * Scale);
}
}
}
else
{
// We are looking at a Player
if ( IdentifyTarget != None )
if ( IdentifyTarget.PlayerName != "" )
{
Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
DrawTwoColorID(Canvas,IdentifyTarget.PlayerName,st ring(IdentifyPawn.Health)
,Canvas.ClipY - 256 * Scale);
}
}
}



DrawGameSynopsis:
Fixes at beginning of function, fixes log warnings on spectators by not trying to check the spectator's team ru and core health

simulated function DrawGameSynopsis(canvas Canvas)
{
local TournamentGameReplicationInfo
GRI;
local float XL,XL2,
YL,YL2,
XOffset,l,
YOffset;
local int i,
X;
local string text;
local sgConstructor gun;
local class<sgBuilding>
buildType;
local Inventory inv;
local PlayerPawn POwner;

// Percents
local float fuelPercent, DashPercent;

local sgPRI PRI;
local Jetpack pack;
local string s;
local color cCol;
local bool bSiegeStats;

local sgBaseCore sgB;
local WildcardsOrbs Orb, OrbLocked;
local int OrbX;
local int OrbSpace;
local WildcardsOrbs WOR;

// HUD Item Slot Vars
local float HudItemSlotY;

POwner = PlayerPawn(Owner);

if ( (POwner != none) && (sgPRI(POwner.PlayerReplicationInfo) != none) )
{
l = sgPRI(POwner.PlayerReplicationInfo).iStatus;
if (int(l/2)*2 != l) bSiegeStats = true;
}
else
bSiegeStats=false;
if (bSiegeStats) return;

GRI = TournamentGameReplicationInfo(PlayerOwner.GameRepl icationInfo);
if ( GRI != None )
for ( i = 0; i < 4; i++ )
DrawTeam(Canvas, GRI.Teams[i]);

if ( PawnOwner.PlayerReplicationInfo == None ||
PawnOwner.PlayerReplicationInfo.bIsSpectator )
return;

PRI = sgPRI(PawnOwner.PlayerReplicationInfo);
sgB = PRI.Cores[PRI.Team];

Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
Canvas.DrawColor = WhiteColor;

Canvas.TextSize("RU:", XL, YL);
Canvas.TextSize("BaseCore:", XL2, YL2);

if ( bHideAllWeapons )
YOffset = Canvas.ClipY - YL*3;
else if ( HudScale * WeaponScale * Canvas.ClipX <= Canvas.ClipX - 256 * Scale )
YOffset = Canvas.ClipY - 64*Scale - YL*3;
else
YOffset = Canvas.ClipY - 128*Scale - YL*3;

Canvas.SetPos(0, YOffset);
Canvas.Style = ERenderStyle.STY_Masked;
Canvas.DrawText("RU:", false);

if (sgB != None)
{
Canvas.SetPos(0, YOffset+YL);
Canvas.DrawText("BaseCore:", false);

Orb = sgPRI(POwner.PlayerReplicationInfo).Orb;

if ( Orb != None )
{
Orb = sgPRI(POwner.PlayerReplicationInfo).Orb;
}

foreach AllActors( class'WildcardsOrbs',WOR)
{
Orb = WOR;
}

// The log is an EPIC fail so I want some facts NOW!!
OrbX = 384;
OrbSpace = 24;
Canvas.SetPos(0,YOffset-OrbX);

if ( Orb != None )
{
Canvas.DrawText("Orb Debug Information", false);
OrbX -= OrbSpace; Canvas.SetPos(0,YOffset-OrbX);
Canvas.DrawText("Type:"@Orb.OrbName, false);
OrbX -= OrbSpace; Canvas.SetPos(0,YOffset-OrbX);
Canvas.DrawText("Owner:"@Orb.Owner, false);
OrbX -= OrbSpace; Canvas.SetPos(0,YOffset-OrbX);
Canvas.DrawText("Location (server):"@Orb.ServerLocation, false);
OrbX -= OrbSpace; Canvas.SetPos(0,YOffset-OrbX);
Canvas.DrawText("Location (client):"@Orb.ClientLocation, false);
OrbX -= OrbSpace; Canvas.SetPos(0,YOffset-OrbX);
Canvas.DrawText("OrbHolder (server):"@Orb.ServerOrbHolder, false);
OrbX -= OrbSpace; Canvas.SetPos(0,YOffset-OrbX);
Canvas.DrawText("OrbHolder (client):"@Orb.ClientOrbHolder, false);
OrbX -= OrbSpace; Canvas.SetPos(0,YOffset-OrbX);
Canvas.DrawText("Physics (server):"@Orb.ServerPhysics, false);
OrbX -= OrbSpace; Canvas.SetPos(0,YOffset-OrbX);
Canvas.DrawText("Physics (client):"@Orb.ClientPhysics, false);
}

}



if ( sgPRI(PawnOwner.PlayerReplicationInfo) != None )
{

Canvas.DrawColor = GreyColor;
Canvas.SetPos(XL, YOffset);
Canvas.DrawText(""@int(PRI.RU)@"/"@
int(sgPRI(PawnOwner.PlayerReplicationInfo).MaxRU), false);

if (sgB != none)
{
Canvas.SetPos(XL2, YOffset+YL);

s = string(sgB.Energy / sgB.MaxEnergy * 100);
s = left(s, InStr(s, ".")+nHUDDecPlaces+1);
if (right(s,1)==".")
s = left(s,len(s)-1);

fuelPercent = float(s);
if (fuelPercent > sCore)
RedColour=256;
else if (fuelPercent < sCore)
RedColour = 0;

if (RedColour<128)
{
RedColour+=4;
cCol.R=128+(128-RedColour);
cCol.G=RedColour;
cCol.B=RedColour;
}
else if (RedColour>128)
{
RedColour-=4;
cCol.R=RedColour;
cCol.G=RedColour;
cCol.B=RedColour;

}
else
cCol=GreyColor;

Canvas.DrawColor = cCol;
sCore = fuelPercent;
Canvas.DrawText(""@s, false);
}


Canvas.SetPos(XL, YOffset+20);
}



gun = sgConstructor(PawnOwner.Weapon);
if ( gun != None )
{
text = gun.GetOptionName();

if ( gun.IsFunction() )
{
Canvas.DrawColor = WhiteColor;
X = Canvas.ClipX - 384 * Scale;
Canvas.TextSize(text, XL, YL);
Canvas.SetPos(X + XL/4, YOffset);
Canvas.DrawText(text, false);
}
else if ( gun.IsCategory() )
{
X = Canvas.ClipX - 384 * Scale;

Canvas.DrawColor = WhiteColor;
Canvas.TextSize("Select", XL, YL);
Canvas.SetPos(X, YOffset);
Canvas.DrawText(""@text, false);

Canvas.DrawColor = GreyColor;
Canvas.TextSize("Category", XL, YL);
Canvas.SetPos(X + XL/4, YOffset + YL);
Canvas.DrawText("Category", false);
}
else if ( gun.IsBuilding() )
{
Canvas.DrawColor = WhiteColor;
X = Canvas.ClipX - 384 * Scale;
Canvas.TextSize(text, XL, YL);
Canvas.SetPos(X - XL/4, YOffset);
Canvas.DrawText(text, false);

buildType = gun.GetBuildType();
if ( buildType != None )
text = "Cost:"@buildType.default.BuildCost;
else
text = "Cost:";
Canvas.DrawColor = GreyColor;
Canvas.TextSize(text, XL, YL);
Canvas.SetPos(X, YOffset + YL);
Canvas.DrawText(text, false);
}

}

///////////////////////////////////////////////////////////////
// HUD ITEM SLOTS /////////////////////////////////////////////
///////////////////////////////////////////////////////////////

HudItemSlotY = HudItemSlotOriginY;

//////////////////////// HUD ITEM /////////////////////////////
//////////////////////// JETPACK / Super JETPACK //////////////

for ( inv = PlayerOwner.Inventory; inv != None; inv = inv.Inventory )
{
if ( JetPack(inv) != None )
{
pack = Jetpack(inv);
Canvas.DrawColor = GreyColor;
fuelPercent = FClamp(Jetpack(inv).Fuel / Jetpack(inv).MaxFuel,0, 1);

if ( pack.MaxFuel == 999999999 )
{
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
Canvas.DrawTile(texture'IconSuperJetpackFuelBar', 128 * fuelPercent, 32, 0, 0, 128 * fuelPercent, 32);
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
Canvas.DrawTile(texture'IconSuperJetpackFrame', 128, 32, 0, 0, 128, 32);
}
else
{
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
Canvas.DrawTile(texture'IconJetpackFuelBar', 128 * fuelPercent, 32, 0, 0, 128 * fuelPercent, 32);
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
Canvas.DrawTile(texture'IconJetpackFrame', 128, 32, 0, 0, 128, 32);
}
HudItemSlotY += HudItemSlotSpace;
}

//////////////////////// HUD ITEM /////////////////////////////
//////////////////////// SPEED ////////////////////////////////

if ( sgSpeed(inv) != None && sgSpeed(inv).bActivated )
{
Canvas.DrawColor = GreyColor;
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
//Canvas.SetPos(4, YOffset - YL*2 + 26);
Canvas.DrawTile(texture'IconSpeed', 128, 32, 0, 0, 128, 32);
HudItemSlotY += HudItemSlotSpace;
}

//////////////////////// HUD ITEM /////////////////////////////
//////////////////////// JUMPBOOST ////////////////////////////////

if ( UT_Jumpboots(inv) != None )
{
Canvas.DrawColor = ChallengeHUD(PlayerOwner.MyHUD).HUDColor;
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
//Canvas.SetPos(4, YOffset - YL*2 + 26);
Canvas.DrawTile(texture'SiegeJumpBoots', 32, 32, 0, 0, 32, 32);
Canvas.SetPos(HudItemSlotOriginX + 35,YOffset - HudItemSlotY + 6);
Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
Canvas.DrawText(UT_Jumpboots(inv).Charge);
HudItemSlotY += HudItemSlotSpace;
}

//////////////////////// HUD ITEM /////////////////////////////
//////////////////////// INVISIBLE ////////////////////////////////

if ( UT_invisibility(inv) != None )
{
Canvas.DrawColor = ChallengeHUD(PlayerOwner.MyHUD).HUDColor;
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
//Canvas.SetPos(4, YOffset - YL*2 + 26);
Canvas.DrawTile(texture'SiegeInvisibility', 32, 32, 0, 0, 32, 32);
Canvas.SetPos(HudItemSlotOriginX + 35,YOffset - HudItemSlotY + 6);
Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
Canvas.DrawText(UT_invisibility(inv).Charge);
HudItemSlotY += HudItemSlotSpace;
}
//////////////////////// HUD ITEM /////////////////////////////
//////////////////////// AMPLIEIER/////////////////////////

if ( UDamage(inv) != None )
{
if(!bHasAmp){
AmpCharge = 0.1 * UDamage(inv).Charge;
SetTimer(1,true);
bHasAmp = true;
}

Canvas.DrawColor = ChallengeHUD(PlayerOwner.MyHUD).HUDColor;
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
//Canvas.SetPos(4, YOffset - YL*2 + 26);
Canvas.DrawTile(texture'SiegeUDamage', 32, 32, 0, 0, 32, 32);
Canvas.SetPos(HudItemSlotOriginX + 35,YOffset - HudItemSlotY + 6);
Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
Canvas.DrawText(AmpCharge);
HudItemSlotY += HudItemSlotSpace;
}




//////////////////////// HUD ITEM /////////////////////////////
//////////////////////// SCUBAGEAR/////////////////////////

if ( SCUBAGear(inv) != None )
{
Canvas.DrawColor = ChallengeHUD(PlayerOwner.MyHUD).HUDColor;
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
//Canvas.SetPos(4, YOffset - YL*2 + 26);
Canvas.DrawTile(texture'SiegeScuba', 32, 32, 0, 0, 32, 32);
Canvas.SetPos(HudItemSlotOriginX + 35,YOffset - HudItemSlotY + 6);
Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
Canvas.DrawText(SCUBAGear(inv).Charge);
HudItemSlotY += HudItemSlotSpace;
}


}


//////////////////////// HUD ITEM //////////////////////////////////////
//////////////////////// DASH PAD METER ////////////////////////////////
if ( DashPlayerInstance != None )
{
OrbX = 384;
OrbSpace = 24;
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
Canvas.DrawColor = NewColor(128,128,128);
DashPercent = FClamp(DashPlayerInstance.ClientLifeSpan / DashPlayerInstance.MaxCharge,0, 1);
Canvas.DrawTile(texture'IconDashPadChargeBar', 128 * DashPercent, 32, 0, 0, 128 * DashPercent, 32);
Canvas.SetPos(HudItemSlotOriginX,YOffset - HudItemSlotY);
Canvas.DrawTile(texture'IconDashPadFrame', 128, 32, 0, 0, 128, 32);
HudItemSlotY += HudItemSlotSpace;
}

/*
log("SiegeGI(Level.Game).MonsterMadness"@SiegeGI(Level.Game).MonsterMadness);
log("SiegeGI(Level.Game).MonsterMadness"@SiegeGI(Level.Game).MonstersLeft);
if ( SiegeGI(Level.Game).MonsterMadness == true )
{
XL = 20;
YL = 384;
Canvas.SetPos(XL,YL);
Canvas.DrawColor = NewColor(128,128,128);

Canvas.DrawText("Monster Left:"@SiegeGI(Level.Game).MonstersLeft, false);
}
*/
}

SAM
05-26-2012, 06:06 PM
Higor can I request Jetpack review please?

.seVered.][
05-26-2012, 06:20 PM
Speaking of unified indentation... There should be specific tabs stops for specific notifications in the server scroll. So that you can find messages quickly in the log... Like the extra spacing in the Player >??>>???>? was warned for Team Removing...

.seVered.][
05-26-2012, 09:28 PM
Also, on the HUD issue.. when you set your screen rez to 1600x1280 the server scroll (server message log in the top left corner)_ looks like your in the clouds. I mean the words are very small. Can you implement a way to increase the font if the screen rez is large?

Higor
05-26-2012, 10:00 PM
Could be done, but that won't be me.

.seVered.][
05-31-2012, 04:22 PM
Whilst it is in discussion, perhaps a change in the RU/Core graphic could be addressed. Maybe change it to a more adjustable graphic that is scale-able with the HUD/Screen Rez... same goes for the Message Scroll.

nOs*Wildcard
06-01-2012, 02:45 PM
mmm, more homework. I might just wipe out the hud as stands and make something more fancy like what I made for Gauntlet 10