Here is the code snippet, which should do the trick. But it doesnt. The bar is displayed empty, like the item is missing. Point is the item is one of the startitems - this bar is just used to diplay lamp's battery. The battery is type of 'inventory'. Player has this item mostly slways, and when it depletes, it is regenerated. So no, the player has this item. But the bar is empty. So I bet I'm using the couninv() function incorrectly. But, the code ecompiles, so there is no hard bug, just some logical collision, taht doesnt prevent the code from running.
Code: Select all
int intLampMag = CPlayer.mo.CountInv("lampMagazine");
//lamp magazine FormatNumber(CPlayer.mo.FindInventory("lampMagazine"))
DrawBar("LGTBAR", "BCKBAR", 100, 100, (317, 4), intLampMag, 100, 0);
Code: Select all
class hunterStatusBar : BaseStatusBar
{
DynamicValueInterpolator mHealthInterpolator;
DynamicValueInterpolator mHealthInterpolator2;
HUDFont mHUDFont;
HUDFont mIndexFont;
HUDFont mBigFont;
InventoryBarState diparms;
InventoryBarState diparms_argsbar;
override void Init()
{
Super.Init();
SetSize(0, 320, 200);
// Create the font used for the fullscreen HUD
Font fnt = "SMALLFONT";
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0") + 1, true, 1, 1);
fnt = "INDEXFONT";
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
fnt = "BIGFONT";
mBigFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 2, 2);
diparms = InventoryBarState.Create(mIndexFont);
diparms_argsbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(36, 30), innersize:(40, 30), arrowoffs:(0, 0));
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8);
mHealthInterpolator2 = DynamicValueInterpolator.Create(0, 0.25, 1, 6); // the chain uses a maximum of 6, not 8.
}
override void NewGame ()
{
Super.NewGame();
mHealthInterpolator.Reset (0);
mHealthInterpolator2.Reset (0);
}
override int GetProtrusion(double scaleratio) const
{
return scaleratio > 0.85? 28 : 12; // need to get past the gargoyle's wings
}
override void Tick()
{
Super.Tick();
mHealthInterpolator.Update(CPlayer.health);
mHealthInterpolator2.Update(CPlayer.health);
//mLampMagazine.Update(CPlayer.mo.FindInventory("lampMagazine"));
}
override void Draw (int state, double TicFrac)
{
Super.Draw (state, TicFrac);
if (state == HUD_StatusBar)
{
BeginStatusBar();
DrawMainBar (TicFrac);
}
/*
else if (state == HUD_Fullscreen)
{
BeginHUD();
DrawFullScreenStuff ();
}
*/
}
/*
protected void DrawFullScreenStuff ()
{
//health
//DrawImage("PTN1A0", (51, -3));
DrawString(mBigFont, FormatNumber(mHealthInterpolator.GetValue()), (355, 12), DI_TEXT_ALIGN_RIGHT);
//frags/keys
if (deathmatch)
{
DrawString(mHUDFont, FormatNumber(CPlayer.FragCount, 3), (70, -16));
}
//inventory bar visible
if (!isInventoryBarVisible() && !level.NoInventoryBar && CPlayer.mo.InvSel != null)
{
// This code was changed to always fit the item into the box, regardless of alignment or sprite size.
// Heretic's ARTIBOX is 30x30 pixels.
DrawImage("ARTIBOX", (-66, -1), 0, HX_SHADOW);
DrawInventoryIcon(CPlayer.mo.InvSel, (-66, -15), DI_ARTIFLASH|DI_ITEM_CENTER, boxsize:(28, 28));
if (CPlayer.mo.InvSel.Amount > 1)
{
DrawString(mIndexFont, FormatNumber(CPlayer.mo.InvSel.Amount, 3), (-52, -2 - mIndexFont.mFont.GetHeight()), DI_TEXT_ALIGN_RIGHT);
}
}
Ammo ammo1, ammo2;
[ammo1, ammo2] = GetCurrentAmmo();
DrawString(mHUDFont, FormatNumber(GetAmount("Mana1"), 3), (-21, -30), DI_TEXT_ALIGN_RIGHT);
DrawString(mHUDFont, FormatNumber(GetAmount("Mana2"), 3), (-21, -15), DI_TEXT_ALIGN_RIGHT);
if (isInventoryBarVisible())
{
DrawInventoryBar(diparms, (0, 0), 7, DI_SCREEN_CENTER_BOTTOM, HX_SHADOW);
}
}
*/
protected void DrawMainBar (double TicFrac)
{
//life chain with gem
String Gem;
Gem = "gLIFEGEM";
int inthealth = mHealthInterpolator2.GetValue();
DrawGem("gCHAIN", "gLIFEGEM", inthealth, CPlayer.mo.GetMaxHealth(true), (30, 0), -23, 49, 15, (multiplayer? DI_TRANSLATABLE : 0) | DI_ITEM_LEFT_TOP);
//statusbar frame&background
DrawImage("gINVb", (-54, 0), DI_ITEM_OFFSETS, 0.5);
DrawImage("gFRAME", (-54, 0), DI_ITEM_OFFSETS);
//inv bar visible
if (isInventoryBarVisible())
{
//DrawImage("INVBAR", (21, 168), DI_ITEM_OFFSETS);
DrawInventoryBar(diparms_argsbar, (35, 170), 7, DI_ITEM_LEFT_TOP, HX_SHADOW);
}
//statusbar
if (!automapactive)
{
//weapon icon
DrawInventoryIcon(CPlayer.ReadyWeapon, (121, 18), DI_ITEM_OFFSETS);
//Health
DrawString(mHUDFont, FormatNumber(CPlayer.health, 3), (359, 12), DI_TEXT_ALIGN_RIGHT, Font.CR_DARKRED);
int intLampMag = CPlayer.mo.CountInv("lampMagazine");
//lamp magazine FormatNumber(CPlayer.mo.FindInventory("lampMagazine"))
DrawBar("LGTBAR", "BCKBAR", 100, 100, (317, 4), intLampMag, 100, 0);
//ammo
Ammo ammo1, ammo2;
[ammo1, ammo2] = GetCurrentAmmo();
if (ammo1 != null)
{
DrawTexture(ammo1.icon, (98, 20), DI_ITEM_CENTER);
DrawString(mHUDFont, FormatNumber(ammo1.amount, 3), (233, 18), DI_TEXT_ALIGN_RIGHT, Font.CR_GOLD);
}
//armor
let armor = CPlayer.mo.FindInventory("BasicArmor");
DrawInventoryIcon(armor, (-50, 12), DI_ITEM_OFFSETS);
DrawString(mHUDFont, FormatNumber(GetArmorAmount(), 3), (15, 13), DI_TEXT_ALIGN_RIGHT, Font.CR_GREY);
//inventory box
if (CPlayer.mo.InvSel != null)
{
DrawInventoryIcon(CPlayer.mo.InvSel, (-23, 179), DI_ARTIFLASH|DI_ITEM_CENTER, boxsize:(28, 28));
if (CPlayer.mo.InvSel.Amount > 1)
{
DrawString(mIndexFont, FormatNumber(CPlayer.mo.InvSel.Amount, 3), (-8, 188), DI_TEXT_ALIGN_RIGHT, Font.CR_YELLOW);
}
}
}
else // automap
{
DrawImage("KEYBAR", (38, 162), DI_ITEM_OFFSETS);
int cnt = 0;
Vector2 keypos = (46, 164);
for(let i = CPlayer.mo.Inv; i != null; i = i.Inv)
{
if (i is "Key" && i.Icon.IsValid())
{
DrawTexture(i.Icon, keypos, DI_ITEM_OFFSETS);
keypos.X += 20;
if (++cnt >= 5) break;
}
}
}
}
}