Skip to content

Commit

Permalink
HUD: Tidy up some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dastrukar committed Jan 30, 2021
1 parent 324499b commit b126d2f
Showing 1 changed file with 106 additions and 71 deletions.
177 changes: 106 additions & 71 deletions fdhud.zs
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,20 @@ class fdhud : BaseStatusBar
{
DrawImage("STBAR", (0, 168), DI_ITEM_OFFSETS);

DrawFDBarHealth(47, 168);
DrawFDBarArmor(179, 168);
DrawFDBarHealth((47, 168));
DrawFDBarArmor((179, 168));

DrawFDBarCurrentAmm(0, 168);
DrawFDBarKeys(236, 168);
DrawFDBarAmmo(249, 168);
DrawFDBarCurrentAmm((0, 168));
DrawFDBarKeys((236, 168));
DrawFDBarAmmo((249, 168));

if (deathmatch || teamplay)
{
DrawString(mHUDFont, FormatNumber(CPlayer.FragCount, 3), (138, 171), DI_TEXT_ALIGN_RIGHT);
}
else
{
DrawFDBarWeapons(104, 168);
DrawFDBarWeapons((104, 168));
}

if (multiplayer)
Expand All @@ -153,7 +153,7 @@ class fdhud : BaseStatusBar

if (CPlayer.mo.InvSel != null && !Level.NoInventoryBar)
{
DrawInventoryIcon(CPlayer.mo.InvSel, (160, 198);
DrawInventoryIcon(CPlayer.mo.InvSel, (160, 198));
if (CPlayer.mo.InvSel.Amount > 1)
{
DrawString(mAmountFont, FormatNumber(CPlayer.mo.InvSel.Amount), (175, 198-mIndexFont.mFont.GetHeight()), DI_TEXT_ALIGN_RIGHT, Font.CR_GOLD);
Expand All @@ -171,43 +171,39 @@ class fdhud : BaseStatusBar

void DrawFDFullScreen()
{
int fdbar_weapons_X_pos = -71;
int fdbar_weapons_Y_pos = -64;
Vector2 fdbar_weapons_pos = (-71, -64);

// If true, stack Armor bar on top of Health bar
if (CVar.GetCVar("fdhud_stackarmorbar", CPlayer).GetBool())
{
DrawFDBarHealth(0, -32);
DrawFDBarArmor(0, -64);
DrawFDBarHealth((0, -32));
DrawFDBarArmor((0, -64));
}
else
{
DrawFDBarHealth(0, -32);
DrawFDBarArmor(58, -32);
DrawFDBarHealth((0, -32));
DrawFDBarArmor((58, -32));
}

// If true, only show the current weapon ammo
if (CVar.GetCVar("fdhud_onlycurrentweapon", CPlayer).GetBool())
{
DrawFDBarCurrentAmm(-48, -32);
DrawFDBarKeys(-61, -32);
fdbar_weapons_X_pos = -60;
fdbar_weapons_Y_pos = -32;
DrawFDBarCurrentAmm((-48, -32));
DrawFDBarKeys((-61, -32));
fdbar_weapons_pos = ((-60, -32));
}
else
{
DrawFDBarCurrentAmm(-48, -64);
DrawFDBarKeys(-61, -64);
DrawFDBarAmmo(-71, -32);
fdbar_weapons_X_pos = -71;
fdbar_weapons_Y_pos = -64;
DrawFDBarCurrentAmm((-48, -64));
DrawFDBarKeys((-61, -64));
DrawFDBarAmmo((-71, -32));
}

// If true, hide the Arms bar
if (!CVar.GetCVar("fdhud_hidearmsbar", CPlayer).GetBool())
{
Vector2 starms_size = TexMan.GetScaledSize(TexMan.CheckForTexture("STARMS", TexMan.TYPE_MiscPatch));
DrawFDBarWeapons(fdbar_weapons_X_pos - starms_size.X, -32);
DrawFDBarWeapons((fdbar_weapons_pos.X - starms_size.X, -32));
}

// Draw Inventory bar
Expand All @@ -218,14 +214,14 @@ class fdhud : BaseStatusBar
else
{
// Get position
Vector2 boxpos = (-diparms.boxsize.X, -diparms.boxsize.Y + fdbar_weapons_Y_pos);
Vector2 boxpos = (-diparms.boxsize.X, -diparms.boxsize.Y + fdbar_weapons_pos.Y);
DrawFDInventory(diparms, boxpos);
}
}

void DrawFDBarCurrentAmm(int x, int y)
void DrawFDBarCurrentAmm(Vector2 pos)
{
DrawImage("FDSTAMM", (x, y), DI_ITEM_OFFSETS);
DrawImage("FDSTAMM", pos, DI_ITEM_OFFSETS);

Inventory ammotype1, ammotype2;
[ammotype1, ammotype2] = GetCurrentAmmo();
Expand All @@ -236,41 +232,43 @@ class fdhud : BaseStatusBar
let ammotype2_value = mAltAmmoInterpolator.GetValue();

// Get format_value
let format_value1 = GetFormatAmount(ammotype1_value);
let format_value2 = GetFormatAmount(ammotype2_value);
let format1_value = GetFormatAmount(ammotype1_value);
let format2_value = GetFormatAmount(ammotype2_value);

// Draw icon
let ammotype = GetInventoryIcon(GetCurrentAmmo(), 0);
let adjustment = GetTextureOffsetCorrection(ammotype);
let alpha = CVar.GetCVar("fdhud_ammoiconalpha", CPlayer).GetFloat();

DrawInventoryIcon(GetCurrentAmmo(), (x+24+adjustment.X, y+21+adjustment.Y), DI_ITEM_OFFSETS, alpha);

// Define positions
let icon_pos = pos + adjustment + (24, 21);
let ammo1_pos = pos + (24, 3);
let ammo2_pos = pos + (46, 16);

DrawInventoryIcon(GetCurrentAmmo(), icon_pos, DI_ITEM_OFFSETS, alpha);

// Format ammo
string ammotype1_string = FormatNumber(ammotype1_value, format_value1);
string ammotype2_string = FormatNumber(ammotype2_value, format_value2);
string ammo1_string;
string ammo2_string;

if (CVar.GetCVar("fdhud_swapaltammo", CPlayer).GetBool())
if (ammotype2 != null)
{
if (ammotype2 != null)
{
DrawString(mHUDFont, ammotype2_string, (x+24, y+3), DI_TEXT_ALIGN_CENTER|DI_NOSHADOW);
DrawString(mIndexFont, ammotype1_string, (x+46, y+16), DI_TEXT_ALIGN_RIGHT|DI_NOSHADOW);
}
else { DrawString(mHUDFont, ammotype1_string, (x+24, y+3), DI_TEXT_ALIGN_CENTER|DI_NOSHADOW); }
if (CVar.GetCVar("fdhud_swapaltammo", CPlayer).GetBool()) { ammo1_string = FormatNumber(ammotype2_value, format2_value); }
else { ammo2_string = FormatNumber(ammotype2_value, format2_value); }
}
else
{
DrawString(mHUDFont, ammotype1_string, (x+24, y+3), DI_TEXT_ALIGN_CENTER|DI_NOSHADOW);
if (ammotype2 != null) { DrawString(mIndexFont, ammotype2_string, (x+46, y+16), DI_TEXT_ALIGN_RIGHT|DI_NOSHADOW); }
}


if (ammo1_string != "") { ammo2_string = FormatNumber(ammotype1_value, format1_value); }
else { ammo1_string = FormatNumber(ammotype1_value, format1_value); }

// Display numbers
DrawString(mHUDFont, ammo1_string, ammo1_pos, DI_TEXT_ALIGN_CENTER | DI_NOSHADOW);
if (ammo2_string != "") { DrawString(mIndexFont, ammo2_string, ammo2_pos, DI_TEXT_ALIGN_RIGHT | DI_NOSHADOW); }
}
}

void DrawFDBarHealth(int x, int y)
void DrawFDBarHealth(Vector2 pos)
{
DrawImage("FDSTHP", (x, y), DI_ITEM_OFFSETS);
DrawImage("FDSTHP", pos, DI_ITEM_OFFSETS);

// Get Health value
let health = mHealthInterpolator.GetValue();
Expand All @@ -285,8 +283,12 @@ class fdhud : BaseStatusBar
let hpTexID = TexMan.CheckForTexture(berserk? "PSTRA0" : "MEDIA0");
let adjustment = GetTextureOffsetCorrection(hpTexID);
let alpha = CVar.GetCVar("fdhud_hpiconalpha", CPlayer).GetFloat();

// Define positions
let icon_pos = pos + adjustment + (29, 21);
let text_pos = pos + (29, 3);

DrawImage(berserk? "PSTRA0" : "MEDIA0", (x+29+adjustment.X, y+21+adjustment.Y), DI_ITEM_OFFSETS, alpha);
DrawImage(berserk? "PSTRA0" : "MEDIA0", icon_pos, DI_ITEM_OFFSETS, alpha);

// Add percent to health? Also turn it into a string
string hp;
Expand All @@ -295,12 +297,12 @@ class fdhud : BaseStatusBar
if (!CVar.GetCVar("fdhud_hidepercent", CPlayer).GetBool()) { hp = String.Format("%s%%", hp); }

// Draw Health value
DrawString(mHUDFont, hp, (x+29, y+3), DI_TEXT_ALIGN_CENTER|DI_NOSHADOW);
DrawString(mHUDFont, hp, text_pos, DI_TEXT_ALIGN_CENTER|DI_NOSHADOW);
}

void DrawFDBarArmor(int x, int y)
void DrawFDBarArmor(Vector2 pos)
{
DrawImage("FDSTARMO", (x, y), DI_ITEM_OFFSETS);
DrawImage("FDSTARMO", pos, DI_ITEM_OFFSETS);

// Get Armor value
let armor_value = mArmorInterpolator.GetValue();
Expand All @@ -315,63 +317,96 @@ class fdhud : BaseStatusBar
let armorTexID = GetInventoryIcon(armor, 0);
let adjustment = GetTextureOffsetCorrection(armorTexID);
let alpha = CVar.GetCVar("fdhud_armoriconalpha", CPlayer).GetFloat();

// Set position
let icon_pos = pos + adjustment + (29, 21);

DrawInventoryIcon(armor, (x+29+adjustment.X, y+21+adjustment.Y), DI_ITEM_OFFSETS, alpha);
DrawInventoryIcon(armor, icon_pos, DI_ITEM_OFFSETS, alpha);
}

// Add percent?
string armor_string = FormatNumber(armor_value, format_value);
if (!CVar.GetCvar("fdhud_hidepercent", CPlayer).GetBool()) { armor_string = String.Format("%s%%", armor_string); }

// Set position
let text_pos = pos + (29, 3);

DrawString(mHUDFont, armor_string, (x+29, y+3), DI_TEXT_ALIGN_CENTER|DI_NOSHADOW);
DrawString(mHUDFont, armor_string, text_pos, DI_TEXT_ALIGN_CENTER|DI_NOSHADOW);
}

void DrawFDBarKeys(int x, int y)
void DrawFDBarKeys(Vector2 pos)
{
DrawImage("FDSTKEYS", (x, y), DI_ITEM_OFFSETS);
DrawImage("FDSTKEYS", pos, DI_ITEM_OFFSETS);

bool locks[6];
String image;

// Set positions
let key1_pos = pos + (3, 3);
let key2_pos = pos + (3, 13);
let key3_pos = pos + (3, 23);

for(int i = 0; i < 6; i++) locks[i] = CPlayer.mo.CheckKeys(i + 1, false, true);
// key 1
if (locks[1] && locks[4]) image = "STKEYS6";
else if (locks[1]) image = "STKEYS0";
else if (locks[4]) image = "STKEYS3";
DrawImage(image, (x+3, y+3), DI_ITEM_OFFSETS);
DrawImage(image, key1_pos, DI_ITEM_OFFSETS);
// key 2
if (locks[2] && locks[5]) image = "STKEYS7";
else if (locks[2]) image = "STKEYS1";
else if (locks[5]) image = "STKEYS4";
else image = "";
DrawImage(image, (x+3, y+13), DI_ITEM_OFFSETS);
DrawImage(image, key2_pos, DI_ITEM_OFFSETS);
// key 3
if (locks[0] && locks[3]) image = "STKEYS8";
else if (locks[0]) image = "STKEYS2";
else if (locks[3]) image = "STKEYS5";
else image = "";
DrawImage(image, (x+3, y+23), DI_ITEM_OFFSETS);
DrawImage(image, key3_pos, DI_ITEM_OFFSETS);
}

void DrawFDBarAmmo(int x, int y)
void DrawFDBarAmmo(Vector2 pos)
{
DrawImage("FDSTAAMM", (x, y), DI_ITEM_OFFSETS);

DrawString(mIndexFont, FormatNumber(mClipInterpolator.GetValue(), 3), (x+39, y+5), DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mMaxClipInterpolator.GetValue(), 3), (x+65, y+5), DI_TEXT_ALIGN_RIGHT);
DrawImage("FDSTAAMM", pos, DI_ITEM_OFFSETS);

DrawString(mIndexFont, FormatNumber(mShellInterpolator.GetValue(), 3), (x+39, y+11), DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mMaxShellInterpolator.GetValue(), 3), (x+65, y+11), DI_TEXT_ALIGN_RIGHT);
// Set positions
let l = 39;
let r = 65;

let clip_pos = pos + (l, 5);
let mclip_pos = pos + (r, 5);

let shell_pos = pos + (l, 11);
let mshell_pos = pos + (r, 11);

let rocket_pos = pos + (l, 17);
let mrocket_pos = pos + (r, 17);

let plasma_pos = pos + (l, 23);
let mplasma_pos = pos + (r, 23);


DrawString(mIndexFont, FormatNumber(mClipInterpolator.GetValue(), 3), clip_pos, DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mMaxClipInterpolator.GetValue(), 3), mclip_pos, DI_TEXT_ALIGN_RIGHT);

DrawString(mIndexFont, FormatNumber(mShellInterpolator.GetValue(), 3), shell_pos, DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mMaxShellInterpolator.GetValue(), 3), mshell_pos, DI_TEXT_ALIGN_RIGHT);

DrawString(mIndexFont, FormatNumber(mRocketInterpolator.GetValue(), 3), (x+39, y+17), DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mMaxRocketInterpolator.GetValue(), 3), (x+65, y+17), DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mRocketInterpolator.GetValue(), 3), rocket_pos, DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mMaxRocketInterpolator.GetValue(), 3), mrocket_pos, DI_TEXT_ALIGN_RIGHT);

DrawString(mIndexFont, FormatNumber(mPlasmaInterpolator.GetValue(), 3), (x+39, y+23), DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mMaxPlasmaInterpolator.GetValue(), 3), (x+65, y+23), DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mPlasmaInterpolator.GetValue(), 3), plasma_pos, DI_TEXT_ALIGN_RIGHT);
DrawString(mIndexFont, FormatNumber(mMaxPlasmaInterpolator.GetValue(), 3), mplasma_pos, DI_TEXT_ALIGN_RIGHT);
}

void DrawFDBarWeapons(int x, int y)
void DrawFDBarWeapons(Vector2 pos)
{
DrawImage("STARMS", (x, y), DI_ITEM_OFFSETS);
DrawImage("STARMS", pos, DI_ITEM_OFFSETS);

let x = pos.X;
let y = pos.Y;

DrawImage(CPlayer.HasWeaponsInSlot(2)? "STYSNUM2" : "STGNUM2", (x+7, y+4), DI_ITEM_OFFSETS);
DrawImage(CPlayer.HasWeaponsInSlot(3)? "STYSNUM3" : "STGNUM3", (x+19, y+4), DI_ITEM_OFFSETS);
DrawImage(CPlayer.HasWeaponsInSlot(4)? "STYSNUM4" : "STGNUM4", (x+31, y+4), DI_ITEM_OFFSETS);
Expand Down

0 comments on commit b126d2f

Please sign in to comment.