Skip to content

Commit

Permalink
- fixed: The powerup icons did not blink when expiring.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Apr 21, 2017
1 parent 0ed3ee6 commit 3ccd4aa
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 41 deletions.
42 changes: 27 additions & 15 deletions src/g_shared/shared_hud.cpp
Expand Up @@ -1088,23 +1088,35 @@ static void DrawPowerups(player_t *CPlayer)

for (item = CPlayer->mo->Inventory; item != NULL; item = item->Inventory)
{
IFVIRTUALPTR(item, AInventory, GetPowerupIcon)
if (item->IsKindOf(NAME_Powerup))
{
VMValue param[] = { item };
int rv;
VMReturn ret(&rv);
VMCall(func, param, 1, &ret, 1);
auto tex = FSetTextureID(rv);
if (!tex.isValid()) continue;
auto texture = TexMan(tex);

screen->DrawTexture(texture, x, y, DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_CenterBottomOffset, true, TAG_DONE);

x -= POWERUPICONSIZE;
if (x < -hudwidth / 2)
IFVIRTUALPTRNAME(item, NAME_Powerup, GetPowerupIcon)
{
x = -20;
y += POWERUPICONSIZE * 3 / 2;
VMValue param[] = { item };
int rv;
VMReturn ret(&rv);
VMCall(func, param, 1, &ret, 1);
auto tex = FSetTextureID(rv);
if (!tex.isValid()) continue;
auto texture = TexMan(tex);

IFVIRTUALPTRNAME(item, NAME_Powerup, IsBlinking)
{
// Reuse the parameters from GetPowerupIcon
VMCall(func, param, 1, &ret, 1);
if (!rv)
{

screen->DrawTexture(texture, x, y, DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_CenterBottomOffset, true, TAG_DONE);

x -= POWERUPICONSIZE;
if (x < -hudwidth / 2)
{
x = -20;
y += POWERUPICONSIZE * 3 / 2;
}
}
}
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions wadsrc/static/zscript/inventory/inventory.txt
Expand Up @@ -858,21 +858,6 @@ class Inventory : Actor native

virtual ui version("2.4") bool DrawPowerup(int x, int y) { return false; }

//===========================================================================
//
// AInventory :: GetPowerupIcon
//
// Returns the icon that should be drawn for an active powerup.
//
//===========================================================================

virtual clearscope version("2.5") TextureID GetPowerupIcon() const
{
TextureID id;
id.SetInvalid();
return id;
}

//===========================================================================
//
// AInventory :: AbsorbDamage
Expand Down
6 changes: 4 additions & 2 deletions wadsrc/static/zscript/inventory/powerups.txt
Expand Up @@ -269,11 +269,13 @@ class Powerup : Inventory

//===========================================================================
//
// APowerup :: DrawPowerup
// AInventory :: GetPowerupIcon
//
// Returns the icon that should be drawn for an active powerup.
//
//===========================================================================

override TextureID GetPowerupIcon()
virtual clearscope version("2.5") TextureID GetPowerupIcon() const
{
return Icon;
}
Expand Down
22 changes: 13 additions & 9 deletions wadsrc/static/zscript/statusbar/statusbar.txt
Expand Up @@ -813,18 +813,22 @@ class BaseStatusBar native ui
// that can obey AltHUD rules - which this cannot.
Vector2 pos = (-20, POWERUPICONSIZE * 5 / 4);
double maxpos = screen.GetWidth() / 2;
for (let item = CPlayer.mo.Inv; item != NULL; item = item.Inv)
for (let iitem = CPlayer.mo.Inv; iitem != NULL; iitem = iitem.Inv)
{
let icon = item.GetPowerupIcon();
if (icon.IsValid())
let item = Powerup(iitem);
if (item != null)
{
// Each icon gets a 32x32 block.
DrawTexture(icon, pos, DI_SCREEN_RIGHT_TOP, 1.0, (POWERUPICONSIZE, POWERUPICONSIZE));
pos.x -= POWERUPICONSIZE;
if (pos.x < -maxpos)
let icon = item.GetPowerupIcon();
if (icon.IsValid() && !item.IsBlinking())
{
pos.x = -20;
pos.y += POWERUPICONSIZE * 3 / 2;
// Each icon gets a 32x32 block.
DrawTexture(icon, pos, DI_SCREEN_RIGHT_TOP, 1.0, (POWERUPICONSIZE, POWERUPICONSIZE));
pos.x -= POWERUPICONSIZE;
if (pos.x < -maxpos)
{
pos.x = -20;
pos.y += POWERUPICONSIZE * 3 / 2;
}
}
}
}
Expand Down

0 comments on commit 3ccd4aa

Please sign in to comment.