From e833360b65fbe0348d67df37c02a1f7bfd4c9e1c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 2 Jul 2020 23:56:22 +0200 Subject: [PATCH] - ported the level stats display to be game independent. --- source/core/statusbar.cpp | 34 +++++++++++++++++++ source/core/statusbar.h | 13 ++++++++ source/games/duke/src/game_main.cpp | 1 + source/games/duke/src/sbar.cpp | 50 ++++++++++++++++++++++++++++ source/games/duke/src/sbar.h | 3 ++ source/games/duke/src/sbar_d.cpp | 20 ++++++----- source/games/duke/src/sbar_r.cpp | 4 +++ source/games/duke/src/zz_screens.cpp | 48 -------------------------- wadsrc/static/textcolors.txt | 4 +-- 9 files changed, 119 insertions(+), 58 deletions(-) diff --git a/source/core/statusbar.cpp b/source/core/statusbar.cpp index 31ca154be..c228c877a 100644 --- a/source/core/statusbar.cpp +++ b/source/core/statusbar.cpp @@ -798,3 +798,37 @@ void FormatNumber(int number, int minsize, int maxsize, int flags, const FString else fmt.Format("%s%*d", prefix.GetChars(), minsize, number); } +CVAR(Float, hud_statscale, 2, CVAR_ARCHIVE) + +void DBaseStatusBar::PrintLevelStats(FLevelStats &stats) +{ + BeginHUD(320, 200, 1.f, false); + double scale = stats.fontscale * hud_statscale; + if (stats.spacing <= 0) stats.spacing = stats.font->GetHeight() * stats.fontscale; + double spacing = stats.spacing * hud_statscale; + double y = (stats.screenbottomspace < 0 ? RelTop : screen->GetHeight() - stats.screenbottomspace * defaultScale.Y) - spacing; + + FString text; + if (stats.maxsecrets > 0) // don't bother if there are no secrets. + { + text.Format(TEXTCOLOR_ESCAPESTR "%cS: " TEXTCOLOR_ESCAPESTR "%c%d/%d", + stats.letterColor + 'A', stats.secrets == stats.maxsecrets ? stats.completeColor + 'A' : stats.standardColor + 'A', stats.secrets, stats.maxsecrets); + DrawText(twod, stats.font, CR_UNTRANSLATED, 2 * hud_statscale, y, text, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE); + y -= spacing; + } + + text = ""; + if (stats.frags > -1) text.Format(TEXTCOLOR_ESCAPESTR "%cF: " TEXTCOLOR_ESCAPESTR "%c%d", stats.letterColor + 'A', stats.standardColor + 'A', stats.frags); + else if (stats.maxkills == -2) text.Format(TEXTCOLOR_ESCAPESTR "%cK: " TEXTCOLOR_ESCAPESTR "%c%d", stats.letterColor + 'A', stats.standardColor + 'A', stats.kills); + else if (stats.maxkills != -1) text.Format(TEXTCOLOR_ESCAPESTR "%cK: " TEXTCOLOR_ESCAPESTR "%c%d/%d", + stats.letterColor + 'A', stats.kills == stats.maxkills ? stats.completeColor + 'A' : stats.standardColor + 'A', stats.kills, stats.maxkills); + + if (text.IsNotEmpty()) + { + DrawText(twod, stats.font, CR_UNTRANSLATED, 2 * hud_statscale, y, text, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE); + y -= spacing; + } + + text.Format(TEXTCOLOR_ESCAPESTR "%cT: " TEXTCOLOR_ESCAPESTR "%c%d:%02d", stats.letterColor+'A', stats.standardColor + 'A', stats.time / 60000, (stats.time % 60000) / 1000); + DrawText(twod, stats.font, CR_UNTRANSLATED, 2 * hud_statscale, y, text, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE); +} \ No newline at end of file diff --git a/source/core/statusbar.h b/source/core/statusbar.h index aaeee206d..97af9e6c2 100644 --- a/source/core/statusbar.h +++ b/source/core/statusbar.h @@ -68,6 +68,18 @@ enum HUDMSGLayer_Default = HUDMSGLayer_OverHUD, }; +struct FLevelStats +{ + int screenbottomspace; + int time; // in milliseconds + int frags; + int kills, maxkills; // set maxkills to -1 to ignore, or to -2 to only print kills + int secrets, maxsecrets; // set maxsecrets to -1 to ignore + int spacing; // uses fontheight if 0 or less. + EColorRange letterColor, standardColor, completeColor; + double fontscale; + FFont* font; +}; //============================================================================ // @@ -174,6 +186,7 @@ public: void BeginHUD(int resW, int resH, double Alpha, bool forceScaled = false); bool ForceHUDScale(bool on) { std::swap(ForcedScale, on); return on; } // This is for SBARINFO which should not use BeginStatusBar or BeginHUD. void StatusbarToRealCoords(double &x, double &y, double &w, double &h) const; + void PrintLevelStats(FLevelStats& stats); int GetTopOfStatusbar() const { return SBarTop; diff --git a/source/games/duke/src/game_main.cpp b/source/games/duke/src/game_main.cpp index 076ae68bc..8b4d7929c 100644 --- a/source/games/duke/src/game_main.cpp +++ b/source/games/duke/src/game_main.cpp @@ -35,6 +35,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "m_argv.h" #include "mapinfo.h" #include "texturemanager.h" +#include "statusbar.h" BEGIN_DUKE_NS diff --git a/source/games/duke/src/sbar.cpp b/source/games/duke/src/sbar.cpp index 0d48e8059..d364c6c02 100644 --- a/source/games/duke/src/sbar.cpp +++ b/source/games/duke/src/sbar.cpp @@ -170,4 +170,54 @@ PalEntry DDukeCommonStatusBar::LightForShade(int shade) return PalEntry(255, ll, ll, ll); } +//========================================================================== +// +// Statistics output +// +//========================================================================== + +void DDukeCommonStatusBar::PrintLevelStats(int bottomy) +{ + // JBF 20040124: display level stats in screen corner + if (ud.overhead_on != 2 && hud_stats) + { + FLevelStats stats{}; + auto pp = &ps[myconnectindex]; + + stats.fontscale = isRR() ? 0.5 : 1.; + stats.spacing = isRR() ? 10 : 7; + stats.screenbottomspace = bottomy; + + stats.time = Scale(pp->player_par, 1000, REALGAMETICSPERSEC); + stats.kills = pp->actors_killed; + stats.maxkills = !isRR() && ud.player_skill > 3 ? -2 : pp->max_actors_killed; + stats.frags = ud.multimode > 1 && !ud.coop ? pp->frag - pp->fraggedself : -1; + stats.secrets = pp->secret_rooms; + stats.maxsecrets = pp->max_secret_rooms; + stats.font = SmallFont; + if (isNamWW2GI()) + { + // The stock font of these games is totally unusable for this. + stats.font = ConFont; + stats.spacing = ConFont->GetHeight() + 2; + stats.letterColor = CR_ORANGE; + stats.standardColor = CR_YELLOW; + stats.completeColor = CR_FIRE; + } + else if (!isRR()) + { + stats.letterColor = CR_ORANGE; + stats.standardColor = CR_CREAM; + stats.completeColor = CR_FIRE; + } + else + { + stats.letterColor = CR_ORANGE; + stats.standardColor = + stats.completeColor = CR_UNTRANSLATED; + } + DBaseStatusBar::PrintLevelStats(stats); + } +} + END_DUKE_NS diff --git a/source/games/duke/src/sbar.h b/source/games/duke/src/sbar.h index 7d96ec4c5..5edfed99c 100644 --- a/source/games/duke/src/sbar.h +++ b/source/games/duke/src/sbar.h @@ -22,6 +22,9 @@ protected: std::pair ontext(DukePlayer_t *p); void DrawInventory(const DukePlayer_t* p, double x, double y, int align); PalEntry LightForShade(int shade); +public: + void PrintLevelStats(int bottomy); + }; END_DUKE_NS diff --git a/source/games/duke/src/sbar_d.cpp b/source/games/duke/src/sbar_d.cpp index 6cf2d93fb..62ea362c8 100644 --- a/source/games/duke/src/sbar_d.cpp +++ b/source/games/duke/src/sbar_d.cpp @@ -114,7 +114,7 @@ public: // // Health // - DrawGraphic(tileGetTexture(TILE_COLA), 2, -2, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, 0.75, 0.75); + DrawGraphic(tileGetTexture(COLA), 2, -2, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, 0.75, 0.75); FString format; if (!althud_flashing || p->last_extra > (max_player_health >> 2) || ((int)totalclock & 32) || (sprite[p->i].pal == 1 && p->last_extra < 2)) @@ -131,7 +131,7 @@ public: // // Armor // - DrawGraphic(tileGetTexture(TILE_SHIELD), 62, -2, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, 0.75, 0.75); + DrawGraphic(tileGetTexture(SHIELD), 62, -2, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, 0.75, 0.75); format.Format("%d", GetMoraleOrShield(p, snum)); SBar_DrawString(this, &numberFont, format, 105, -numberFont.mFont->GetHeight() - 0.5, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, 1, 1); @@ -181,9 +181,9 @@ public: // // keys // - if (p->got_access & 1) DrawGraphic(tileGetTexture(TILE_ACCESSCARD), -29, -30, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 0)); - if (p->got_access & 4) DrawGraphic(tileGetTexture(TILE_ACCESSCARD), -24, -28, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 23)); - if (p->got_access & 2) DrawGraphic(tileGetTexture(TILE_ACCESSCARD), -19, -26, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 21)); + if (p->got_access & 1) DrawGraphic(tileGetTexture(ACCESSCARD), -29, -30, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 0)); + if (p->got_access & 4) DrawGraphic(tileGetTexture(ACCESSCARD), -24, -28, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 23)); + if (p->got_access & 2) DrawGraphic(tileGetTexture(ACCESSCARD), -19, -26, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 21)); } @@ -198,7 +198,7 @@ public: // // health // - DrawGraphic(tileGetTexture(TILE_HEALTHBOX), 5, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale); + DrawGraphic(tileGetTexture(HEALTHBOX), 5, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale); int health = (sprite[p->i].pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; FStringf format("%d", health); SBar_DrawString(this, &digiFont, format, 19, -digiFont.mFont->GetHeight() * scale - 7, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, scale, scale); @@ -206,7 +206,7 @@ public: // // ammo // - DrawGraphic(tileGetTexture(TILE_AMMOBOX), 37, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale); + DrawGraphic(tileGetTexture(AMMOBOX), 37, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale); int wp = (p->curr_weapon == HANDREMOTE_WEAPON) ? HANDBOMB_WEAPON : p->curr_weapon; format.Format("%d", p->ammo_amount[wp]); SBar_DrawString(this, &digiFont, format, 53, -digiFont.mFont->GetHeight() * scale - 7, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, scale, scale); @@ -218,7 +218,7 @@ public: if (icon > 0) { int x = 73; - DrawGraphic(tileGetTexture(TILE_INVENTORYBOX), 69, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale); + DrawGraphic(tileGetTexture(INVENTORYBOX), 69, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale); if (icon < ICON_MAX) DrawGraphic(tileGetTexture(item_icons[icon]), x, -14, DI_ITEM_LEFT|DI_ITEM_VCENTER, 1, -1, -1, scale, scale); @@ -247,15 +247,18 @@ public: { DrawInventory(p, 0, -46, DI_SCREEN_CENTER_BOTTOM); FullscreenHUD1(p, snum); + PrintLevelStats(tilesiz[BIGALPHANUM].y +10); } else if (style == 2) { DrawInventory(p, (ud.multimode > 1) ? 56 : 65, -28, DI_SCREEN_CENTER_BOTTOM); FullscreenHUD2(p); + PrintLevelStats(tilesiz[HEALTHBOX].y + 2); } else { DrawInventory(p, 0, -28, DI_SCREEN_CENTER_BOTTOM); + PrintLevelStats(2); } } @@ -393,6 +396,7 @@ public: auto text = ontext(p); if (text.first) SBar_DrawString(this, &miniFont, text.first, x + 34, top + 14, DI_TEXT_ALIGN_RIGHT, text.second, 1, 0, 0, 1, 1); } + PrintLevelStats(-1); } diff --git a/source/games/duke/src/sbar_r.cpp b/source/games/duke/src/sbar_r.cpp index 37dbd208d..41aa707ce 100644 --- a/source/games/duke/src/sbar_r.cpp +++ b/source/games/duke/src/sbar_r.cpp @@ -229,15 +229,18 @@ public: y -= 4; DrawInventory(p, 0, y, DI_SCREEN_CENTER_BOTTOM); FullscreenHUD1(p, snum); + PrintLevelStats(scale * tilesiz[BIGALPHANUM].y + 10); } else if (style == 2) { DrawInventory(p, 56, -20, DI_SCREEN_CENTER_BOTTOM); FullscreenHUD2(p); + PrintLevelStats(scale * tilesiz[HEALTHBOX].y + 2); } else { DrawInventory(p, 0, -20, DI_SCREEN_CENTER_BOTTOM); + PrintLevelStats(2); } } @@ -379,6 +382,7 @@ public: { DrawGraphic(tileGetTexture(GUTMETER_LIGHT4), 302, top + 24, DI_ITEM_OFFSETS, 1, -1, -1, scale, scale); } + PrintLevelStats(-1); } }; diff --git a/source/games/duke/src/zz_screens.cpp b/source/games/duke/src/zz_screens.cpp index 289903a67..e9118ebc7 100644 --- a/source/games/duke/src/zz_screens.cpp +++ b/source/games/duke/src/zz_screens.cpp @@ -478,54 +478,6 @@ void G_DisplayRest(int32_t smoothratio) mdpause = (ud.pause_on || (ud.recstat==2 && (g_demo_paused && g_demo_goalCnt==0)) || (g_player[myconnectindex].ps->gm&MODE_MENU && numplayers < 2)); - // JBF 20040124: display level stats in screen corner - if (ud.overhead_on != 2 && hud_stats) - { - DukePlayer_t const * const myps = g_player[myconnectindex].ps; - int const sbarshift = RR ? 15 : 16; - int const ystep = RR ? (10<<16) : (7<<16); - - i = 198<<16; - - if (ud.screen_size == 4) - { - if (ud.althud == 0 || hud_position == 0) - i -= sbarsc(ud.althud ? ((tilesiz[TILE_BIGALPHANUM].y< 2) - i -= sbarsc(tilesiz[TILE_BOTTOMSTATUSBAR].y<player_par/(REALGAMETICSPERSEC*60)), - (myps->player_par/REALGAMETICSPERSEC)%60, - ((myps->player_par%REALGAMETICSPERSEC)*33)/10 - ); - G_ScreenText(MF_Bluefont.tilenum, 2<<16, i-gtextsc(ystep*3), gtextsc(MF_Bluefont.zoom), 0, 0, tempbuf, 0, 10, 2|8|16|256|ROTATESPRITE_FULL16, 0, MF_Bluefont.emptychar.x, MF_Bluefont.emptychar.y, xbetween, MF_Bluefont.between.y, MF_Bluefont.textflags|TEXT_XOFFSETZERO|TEXT_GAMETEXTNUMHACK, 0, 0, xdim-1, ydim-1); - - if ((!RR && ud.player_skill > 3) || ((g_netServer || ud.multimode > 1) && !GTFLAGS(GAMETYPE_PLAYERSFRIENDLY))) - Bsprintf(tempbuf, "K:^15%d", (ud.multimode>1 &&!GTFLAGS(GAMETYPE_PLAYERSFRIENDLY)) ? - myps->frag-myps->fraggedself : myps->actors_killed); - else - { - if (myps->actors_killed >= myps->max_actors_killed) - Bsprintf(tempbuf, "K:%d/%d", myps->actors_killed, myps->actors_killed); - else - Bsprintf(tempbuf, "K:^15%d/%d", myps->actors_killed, myps->max_actors_killed); - } - G_ScreenText(MF_Bluefont.tilenum, 2<<16, i-gtextsc(ystep*2), gtextsc(MF_Bluefont.zoom), 0, 0, tempbuf, 0, 10, 2|8|16|256|ROTATESPRITE_FULL16, 0, MF_Bluefont.emptychar.x, MF_Bluefont.emptychar.y, xbetween, MF_Bluefont.between.y, MF_Bluefont.textflags|TEXT_XOFFSETZERO|TEXT_GAMETEXTNUMHACK, 0, 0, xdim-1, ydim-1); - - if (myps->secret_rooms == myps->max_secret_rooms) - Bsprintf(tempbuf, "S:%d/%d", myps->secret_rooms, myps->max_secret_rooms); - else Bsprintf(tempbuf, "S:^15%d/%d", myps->secret_rooms, myps->max_secret_rooms); - G_ScreenText(MF_Bluefont.tilenum, 2<<16, i-gtextsc(ystep), gtextsc(MF_Bluefont.zoom), 0, 0, tempbuf, 0, 10, 2|8|16|256|ROTATESPRITE_FULL16, 0, MF_Bluefont.emptychar.x, MF_Bluefont.emptychar.y, xbetween, MF_Bluefont.between.y, MF_Bluefont.textflags|TEXT_XOFFSETZERO|TEXT_GAMETEXTNUMHACK, 0, 0, xdim-1, ydim-1); - } - Net_DisplaySyncMsg(); if (VOLUMEONE) diff --git a/wadsrc/static/textcolors.txt b/wadsrc/static/textcolors.txt index d8e40182e..a03281b96 100644 --- a/wadsrc/static/textcolors.txt +++ b/wadsrc/static/textcolors.txt @@ -140,8 +140,8 @@ Flat: Cream { - #6B4727 #BF7B4B 0 94 - #BF7B4B #FFBF9B 95 256 + #18120a #BF7B4B 0 128 + #BF7B4B #FFBF9B 129 256 Console: #2B230F #BF7B4B 0 127 #FFB383 #FFFFFF 128 256