From acb4830eb5d2aec59070f7d84035c6f7bc1556b8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 11 May 2021 00:59:26 +0200 Subject: [PATCH] - ported the BaseStatusBar class to ZScript. Not hooked up yet, but it compiles. --- source/core/statusbar.h | 2 +- source/core/statusbar2.cpp | 2 - .../static/filter/exhumed/engine/rmapinfo.txt | 3 - wadsrc/static/zscript.txt | 1 + wadsrc/static/zscript/statusbar.zs | 180 ++++++++++++++++++ 5 files changed, 182 insertions(+), 6 deletions(-) create mode 100644 wadsrc/static/zscript/statusbar.zs diff --git a/source/core/statusbar.h b/source/core/statusbar.h index 086b4c383..c0ecb0ea1 100644 --- a/source/core/statusbar.h +++ b/source/core/statusbar.h @@ -85,7 +85,7 @@ struct FLevelStats //============================================================================ // -// encapsulates all settings a HUD font may need +// // //============================================================================ diff --git a/source/core/statusbar2.cpp b/source/core/statusbar2.cpp index 2844b354d..670ff7280 100644 --- a/source/core/statusbar2.cpp +++ b/source/core/statusbar2.cpp @@ -379,5 +379,3 @@ void drawMapTitle() } } - - diff --git a/wadsrc/static/filter/exhumed/engine/rmapinfo.txt b/wadsrc/static/filter/exhumed/engine/rmapinfo.txt index 5fafd97b6..01ac9c0ac 100644 --- a/wadsrc/static/filter/exhumed/engine/rmapinfo.txt +++ b/wadsrc/static/filter/exhumed/engine/rmapinfo.txt @@ -13,7 +13,6 @@ episode LEV0 cluster 1 { - name = "Exhumed" gameover { function = ExhumedCutscenes.BuildGameoverScene @@ -22,12 +21,10 @@ cluster 1 cluster 2 { - name = "$TXT_EX_MAP00" } cluster 3 { - name = "Multiplayer" } cluster 4 diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index 262e72b63..33645cada 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -29,6 +29,7 @@ version "4.3" #include "zscript/constants.zs" #include "zscript/razebase.zs" #include "zscript/screenjob.zs" +#include "zscript/statusbar.zs" #include "zscript/games/duke/dukegame.zs" #include "zscript/games/duke/ui/screens.zs" #include "zscript/games/duke/ui/cutscenes.zs" diff --git a/wadsrc/static/zscript/statusbar.zs b/wadsrc/static/zscript/statusbar.zs new file mode 100644 index 000000000..e9badd0c9 --- /dev/null +++ b/wadsrc/static/zscript/statusbar.zs @@ -0,0 +1,180 @@ + + +struct StatsPrintInfo +{ + int screenbottomspace; + int spacing; // uses fontheight if 0 or less. + String letterColor, standardColor, completeColor; + double fontscale; + Font statfont; +}; + + +//============================================================================ +// +// +// +//============================================================================ + +class RazeStatusBar : StatusBarCore +{ + void Init() + { + SetSize(0, 320, 200); + } + + virtual void Tick() {} + virtual void UpdateStatusBar(SummaryInfo info) {} + + void drawStatText(Font statFont, int x, int y, String text, double scale) + { + Screen.DrawText(statfont, Font.CR_UNTRANSLATED, x + scale, y + scale, text, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, + DTA_KeepRatio, true, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_LegacyRenderStyle, STYLE_TranslucentStencil, DTA_Color, 0); + Screen.DrawText(statfont, Font.CR_UNTRANSLATED, x, y, text, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, + DTA_KeepRatio, true, DTA_ScaleX, scale, DTA_ScaleY, scale); + } + + //============================================================================ + // + // Prints the current level statistics + // hud_statscale is the desired display scale for the stat display + // hud_scalefactor is the desired display scale for the actual status bar / HUD + // + //============================================================================ + + void PrintLevelStats(StatsPrintInfo info, SummaryInfo stats) + { + + double y; + double scale = info.fontscale * hud_statscale; + if (info.spacing <= 0) info.spacing = info.statfont.GetHeight() * info.fontscale; + double spacing = info.spacing * hud_statscale; + if (info.screenbottomspace < 0) + { + y = 200 - (RelTop - info.screenbottomspace) * hud_scalefactor - spacing; + } + else + { + y = 200 - info.screenbottomspace * hud_scalefactor - spacing; + } + + double y1, y2, y3; + + if (stats.maxsecrets > 0) // don't bother if there are no secrets. + { + y1 = y; + y -= spacing; + } + if (stats.maxkills != -1) + { + y2 = y; + y -= spacing; + } + y3 = y; + + String text; + + text = String.Format("%sT: %s%d:%02d", info.letterColor, info.standardColor, stats.time / 60000, (stats.time % 60000) / 1000); + drawStatText(info.statFont, 2 * hud_statscale, y3, text, scale); + + if (stats.maxkills != -1) + { + if (stats.maxkills == -3) text.Format("%sF: %s%d", info.letterColor, info.standardColor, stats.kills); + else if (stats.maxkills == -2) text.Format("%sK: %s%d", info.letterColor, info.standardColor, stats.kills); + else text.Format("%sK: %s%d/%d", info.letterColor, + stats.kills == stats.maxkills ? info.completeColor : info.standardColor, stats.kills, stats.maxkills); + + drawStatText(info.statFont, 2 * hud_statscale, y2, text, scale); + } + + if (stats.maxsecrets > 0) // don't bother if there are no secrets. + { + text.Format("%sS: %s%d/%d", info.letterColor, stats.secrets >= stats.maxsecrets ? info.completeColor : info.standardColor, stats.secrets, stats.maxsecrets); + if (stats.supersecrets > 0) text.AppendFormat("+%d", stats.supersecrets); + + drawStatText(info.statFont, 2 * hud_statscale, y1, text, scale); + } + } + + //============================================================================ + // + // Prints the automap label + // hud_statscale is the desired display scale for the stat display + // hud_scalefactor is the desired display scale for the actual status bar / HUD + // + //============================================================================ + + void PrintAutomapInfo(StatsPrintInfo info, bool forcetextfont = false) + { + let TEXTCOLOR_ESCAPESTR= "\034"; + let lev = currentLevel; + String mapname; + if (am_showlabel) + mapname.Format("%s%s: %s%s", info.letterColor, lev.GetLabelName(), info.standardColor, lev.DisplayName()); + else + mapname.Format("%s%s", info.standardColor, lev.DisplayName()); + + forcetextfont |= am_textfont; + double y; + double scale = info.fontScale * (forcetextfont ? hud_statscale : 1); // the tiny default font used by all games here cannot be scaled for readability purposes. + if (info.spacing <= 0) info.spacing = info.statfont.GetHeight() * info.fontScale; + double spacing = info.spacing * (forcetextfont ? hud_statscale : 1); + if (am_nameontop) + { + y = spacing + 1; + } + else if (info.screenbottomspace < 0) + { + y = 200 - RelTop - spacing; + } + else + { + y = 200 - info.screenbottomspace - spacing; + } + let cluster = lev.GetCluster(); + String volname; + if (cluster) volname = cluster.name; + if (volname.length() == 0 && am_nameontop) y = 1; + + Screen.DrawText(info.statfont, Font.CR_UNTRANSLATED, 2 * hud_statscale, y, mapname, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, + DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_KeepRatio, true); + y -= spacing; + if (volname.length() > 0) + Screen.DrawText(info.statfont, Font.CR_UNTRANSLATED, 2 * hud_statscale, y, volname, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, + DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_KeepRatio, true); + } + + //============================================================================ + // + // + // + //============================================================================ + + int CalcMagazineAmount(int ammo_remaining, int clip_capacity, bool reloading) + { + // Determine amount in clip. + int clip_amount = ammo_remaining % clip_capacity; + + // Set current clip value to clip capacity if wrapped around to zero, otherwise use determined value. + int clip_current = ammo_remaining != 0 && clip_amount == 0 ? clip_capacity : clip_amount; + + // Return current clip value if weapon has rounds or is not on a reload cycle. + return ammo_remaining == 0 || (reloading && clip_amount == 0) ? 0 : clip_current; + } + + //============================================================================ + // + // + // + //============================================================================ + + void Set43ClipRect() + { + let screenratio = screen.GetAspectRatio(); + if (screenratio < 1.34) return; + + int width = int(screen.GetWidth() * 1.333 / screenratio); + int left = (screen.GetWidth() - width) / 2; + screen.SetClipRect(left, 0, width, screen.GetHeight()); + } +}