From 4431ec06fd555cfe79d405f3710bab7af2e2db31 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 2 Dec 2018 10:30:56 +0100 Subject: [PATCH] - scriptified the AltHUD's inventory drawer and fixed the InvPrev CCMD. --- src/g_game.cpp | 2 +- src/g_shared/shared_hud.cpp | 56 +++---------------- wadsrc/static/zscript/statusbar/alt_hud.txt | 59 +++++++++++++++++++++ 3 files changed, 67 insertions(+), 50 deletions(-) diff --git a/src/g_game.cpp b/src/g_game.cpp index 13bd741ef..3fb1465d2 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -404,7 +404,7 @@ CCMD(invprev) { if (who != NULL) { - IFVM(PlayerPawn, InvNext) + IFVM(PlayerPawn, InvPrev) { VMValue param = who; VMCall(func, ¶m, 1, nullptr, 0); diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index 8b1966087..2c89f51ab 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -283,57 +283,12 @@ static void DrawWeapons(player_t *CPlayer, int x, int y) // //--------------------------------------------------------------------------- -static void DrawInventory(player_t * CPlayer, int x,int y) +static void DrawInventory(player_t * CPlayer, int x, int y) { - AInventory * rover; - int numitems = (hudwidth - 2*x) / 32; - int i; - - CPlayer->mo->InvFirst = rover = StatusBar->ValidateInvFirst(numitems); - if (rover!=NULL) + IFVM(AltHud, DrawInventory) { - if(rover->PrevInv()) - { - screen->DrawTexture(invgems[0], x-10, y, - DTA_KeepRatio, true, - DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, 0.4, TAG_DONE); - } - - for(i=0;iNextInv()) - { - if (rover->Amount>0) - { - FTextureID AltIcon = rover->AltHUDIcon; - - if (AltIcon.Exists() && (rover->Icon.isValid() || AltIcon.isValid()) ) - { - double trans = rover==CPlayer->mo->InvSel ? 1.0 : 0.4; - - DrawImageToBox(TexMan[AltIcon.isValid()? AltIcon : rover->Icon], x, y, 19, 25, trans); - if (rover->Amount>1) - { - char buffer[10]; - int xx; - mysnprintf(buffer, countof(buffer), "%d", rover->Amount); - if (rover->Amount>=1000) xx = 32 - IndexFont->StringWidth(buffer); - else xx = 22; - - screen->DrawText(IndexFont, CR_GOLD, x+xx, y+20, buffer, - DTA_KeepRatio, true, - DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, trans, TAG_DONE); - } - - x+=32; - i++; - } - } - } - if(rover) - { - screen->DrawTexture(invgems[1], x-10, y, - DTA_KeepRatio, true, - DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, 0.4, TAG_DONE); - } + VMValue params[] = { althud, CPlayer, x, y }; + VMCall(func, params, countof(params), nullptr, 0); } } @@ -651,7 +606,10 @@ void DrawHUD() althud->IntVar("healthpic") = healthpic? healthpic->id.GetIndex() : -1; althud->IntVar("berserkpic") = berserkpic? berserkpic->id.GetIndex() : -1; althud->IntVar("tnt1a0") = tnt1a0.GetIndex(); + althud->IntVar("invgem_left") = invgems[0]->id.GetIndex(); + althud->IntVar("invgem_right") = invgems[1]->id.GetIndex(); althud->PointerVar("HUDFont") = HudFont; + althud->PointerVar("IndexFont") = IndexFont; if (!automapactive) { diff --git a/wadsrc/static/zscript/statusbar/alt_hud.txt b/wadsrc/static/zscript/statusbar/alt_hud.txt index acb5f4e17..15271c5ab 100644 --- a/wadsrc/static/zscript/statusbar/alt_hud.txt +++ b/wadsrc/static/zscript/statusbar/alt_hud.txt @@ -44,6 +44,7 @@ class AltHud ui { TextureID healthPic, berserkPic; TextureID tnt1a0; + TextureID invgem_left, invgem_right; int hudwidth, hudheight; int statspace; Font HudFont; // The font for the health and armor display @@ -600,5 +601,63 @@ class AltHud ui } } + //--------------------------------------------------------------------------- + // + // Draw the Inventory + // + //--------------------------------------------------------------------------- + + void DrawInventory(PlayerInfo CPlayer, int x,int y) + { + Inventory rover; + int numitems = (hudwidth - 2*x) / 32; + int i; + + CPlayer.mo.InvFirst = rover = StatusBar.ValidateInvFirst(numitems); + if (rover!=NULL) + { + if(rover.PrevInv()) + { + screen.DrawTexture(invgem_left, true, x-10, y, + DTA_KeepRatio, true, + DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, 0.4); + } + + for(i = 0; i < numitems && rover; rover = rover.NextInv()) + { + if (rover.Amount > 0) + { + let AltIcon = rover.AltHUDIcon; + + if (AltIcon.Exists() && (rover.Icon.isValid() || AltIcon.isValid()) ) + { + double trans = rover == CPlayer.mo.InvSel ? 1.0 : 0.4; + + DrawImageToBox(AltIcon.isValid()? AltIcon : rover.Icon, x, y, 19, 25, trans); + if (rover.Amount > 1) + { + int xx; + String buffer = String.Format("%d", rover.Amount); + if (rover.Amount >= 1000) xx = 32 - IndexFont.StringWidth(buffer); + else xx = 22; + + screen.DrawText(IndexFont, Font.CR_GOLD, x+xx, y+20, buffer, + DTA_KeepRatio, true, + DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, trans); + } + + x+=32; + i++; + } + } + } + if(rover) + { + screen.DrawTexture(invgem_right, true, x-10, y, + DTA_KeepRatio, true, + DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, 0.4); + } + } + } } \ No newline at end of file