From fe39236ee1e0252b09c45f5021fd18b6582b616f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 2 Dec 2018 12:51:54 +0100 Subject: [PATCH] - scriptified the AltHUD'S powerup drawer. --- src/g_game.cpp | 1 + src/g_shared/shared_hud.cpp | 53 +++++---------------- wadsrc/static/zscript/base.txt | 1 + wadsrc/static/zscript/statusbar/alt_hud.txt | 48 ++++++++++++++++--- 4 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/g_game.cpp b/src/g_game.cpp index 3fb1465d27..e2a8d1e255 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -2996,3 +2996,4 @@ DEFINE_GLOBAL(gametic) DEFINE_GLOBAL(demoplayback) DEFINE_GLOBAL(automapactive); DEFINE_GLOBAL(Net_Arbitrator); +DEFINE_GLOBAL(netgame); \ No newline at end of file diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index d70789f2b9..26a5a6cb01 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -353,41 +353,6 @@ static void DrawLatency(int y) VMValue params[] = { althud, y }; VMCall(func, params, countof(params), nullptr, 0); } - - /* - if (!ST_IsLatencyVisible()) - { - return; - } - int i, localdelay = 0, arbitratordelay = 0; - for (i = 0; i < BACKUPTICS; i++) localdelay += netdelay[0][i]; - for (i = 0; i < BACKUPTICS; i++) arbitratordelay += netdelay[nodeforplayer[Net_Arbitrator]][i]; - localdelay = ((localdelay / BACKUPTICS) * ticdup) * (1000 / TICRATE); - arbitratordelay = ((arbitratordelay / BACKUPTICS) * ticdup) * (1000 / TICRATE); - int color = CR_GREEN; - if (MAX(localdelay, arbitratordelay) > 200) - { - color = CR_YELLOW; - } - if (MAX(localdelay, arbitratordelay) > 400) - { - color = CR_ORANGE; - } - if (MAX(localdelay, arbitratordelay) >= ((BACKUPTICS / 2 - 1) * ticdup) * (1000 / TICRATE)) - { - color = CR_RED; - } - - char tempstr[32]; - - const int millis = (level.time % TICRATE) * (1000 / TICRATE); - mysnprintf(tempstr, sizeof(tempstr), "a:%dms - l:%dms", arbitratordelay, localdelay); - - const int characterCount = (int)strlen(tempstr); - const int width = SmallFont->GetCharWidth('0') * characterCount + 2; // small offset from screen's border - - DrawHudText(SmallFont, color, tempstr, hudwidth - width, y, 0x10000); - */ } //--------------------------------------------------------------------------- @@ -396,18 +361,20 @@ static void DrawLatency(int y) // //--------------------------------------------------------------------------- -static void DrawPowerups(player_t *CPlayer) +static void DrawPowerups(player_t *CPlayer, int y) { + IFVM(AltHud, DrawPowerups) + { + VMValue params[] = { althud, CPlayer, y }; + VMCall(func, params, countof(params), nullptr, 0); + } +/* // Each icon gets a 32x32 block to draw itself in. int x, y; AInventory *item; - const int yshift = SmallFont->GetHeight(); const int POWERUPICONSIZE = 32; x = hudwidth -20; - y = POWERUPICONSIZE * 5/4 - + (ST_IsTimeVisible() ? yshift : 0) - + (ST_IsLatencyVisible() ? yshift : 0); for (item = CPlayer->mo->Inventory; item != NULL; item = item->Inventory) { @@ -443,6 +410,7 @@ static void DrawPowerups(player_t *CPlayer) } } } + */ } //--------------------------------------------------------------------------- @@ -481,6 +449,7 @@ void DrawHUD() { int i; + // No HUD in the title level! if (gamestate == GS_TITLELEVEL || !CPlayer) return; @@ -500,7 +469,9 @@ void DrawHUD() DrawTime(SmallFont->GetHeight()); DrawLatency(SmallFont->GetHeight()*2); // to be fixed when fully scripted. - DrawPowerups(CPlayer); + const int POWERUPICONSIZE = 32; + DrawPowerups(CPlayer, SmallFont->GetHeight() * 2 + POWERUPICONSIZE * 5 / 4); // to be fixed when fully scripted. + } else { diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 0d321dc139..ce7a8805be 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -14,6 +14,7 @@ struct _ native // These are the global variables, the struct is only here to av native readonly @GameInfoStruct gameinfo; native play @PlayerInfo players[MAXPLAYERS]; native readonly bool playeringame[MAXPLAYERS]; + native readonly ui bool netgame; native readonly bool automapactive; native play uint gameaction; diff --git a/wadsrc/static/zscript/statusbar/alt_hud.txt b/wadsrc/static/zscript/statusbar/alt_hud.txt index f04c0389e0..f606dcfb15 100644 --- a/wadsrc/static/zscript/statusbar/alt_hud.txt +++ b/wadsrc/static/zscript/statusbar/alt_hud.txt @@ -56,7 +56,7 @@ class AltHud ui // //--------------------------------------------------------------------------- - void DrawImageToBox(TextureID tex, int x, int y, int w, int h, double trans = 0.75) + void DrawImageToBox(TextureID tex, int x, int y, int w, int h, double trans = 0.75, bool animate = false) { double scale1, scale2; @@ -77,7 +77,7 @@ class AltHud ui w = (int)(texsize.X * scale1); h = (int)(texsize.Y * scale1); - screen.DrawTexture(tex, false, x, y, + screen.DrawTexture(tex, animate, x, y, DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, trans, DTA_DestWidth, w, DTA_DestHeight, h, DTA_CenterBottomOffset, 1); @@ -799,9 +799,9 @@ class AltHud ui //--------------------------------------------------------------------------- native static int, int, int GetLatency(); - static void DrawLatency(int y) + void DrawLatency(int y) { - if ((hud_showlag > 0) && (hud_showlag != 1 || netgame) && (hud_showlag <= 2) + if ((hud_showlag == 1 && netgame) || hud_showlag == 2) { int severity, localdelay, arbitratordelay; [severity, localdelay, arbitratordelay] = GetLatency(); @@ -809,12 +809,48 @@ class AltHud ui String tempstr = String.Format("a:%dms - l:%dms", arbitratordelay, localdelay); - const int characterCount = tempstr.Length(); - const int width = SmallFont.GetCharWidth("0") * characterCount + 2; // small offset from screen's border + int characterCount = tempstr.Length(); + int width = SmallFont.GetCharWidth("0") * characterCount + 2; // small offset from screen's border DrawHudText(SmallFont, color, tempstr, hudwidth - width, y, 1); } } + //--------------------------------------------------------------------------- + // + // draw the overlay + // + //--------------------------------------------------------------------------- + + void DrawPowerups(PlayerInfo CPlayer, int y) + { + // Each icon gets a 32x32 block to draw itself in. + int x, y; + Inventory item; + + x = hudwidth - POWERUPICONSIZE - 4; + + for (item = CPlayer.mo.Inv; item != NULL; item = item.Inv) + { + let power = Powerup(item); + if (power) + { + let icon = power.GetPowerupIcon(); + if (icon.isValid()) + { + if (!power.isBlinking()) + DrawImageToBox(icon, x, y, POWERUPICONSIZE, POWERUPICONSIZE, 1, true); + x -= POWERUPICONSIZE; + if (x < -hudwidth / 2) + { + x = hudwidth - 20; + y += POWERUPICONSIZE * 3 / 2; + } + } + } + } + } + + } \ No newline at end of file