From a08d87beb3a58daa618e79f8ef1445946be2d402 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 5 Oct 2020 00:14:55 +0200 Subject: [PATCH] - added a customization hook class for the menu. Currently the only thing it does is abstracting the menu caption, but more can be added here. Not exposed to modding yet, though, that's for later. --- src/common/menu/menu.cpp | 5 +++++ src/common/menu/menu.h | 1 + src/common/menu/menudef.cpp | 5 +++++ src/menu/doommenu.cpp | 3 +++ wadsrc/static/zscript.txt | 1 + wadsrc/static/zscript/base.zs | 1 + wadsrc/static/zscript/ui/menu/menucustomize.zs | 10 ++++++++++ wadsrc/static/zscript/ui/menu/optionmenu.zs | 10 +--------- 8 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 wadsrc/static/zscript/ui/menu/menucustomize.zs diff --git a/src/common/menu/menu.cpp b/src/common/menu/menu.cpp index 70aff7731a..7076d490da 100644 --- a/src/common/menu/menu.cpp +++ b/src/common/menu/menu.cpp @@ -100,6 +100,8 @@ float BackbuttonAlpha; static bool MenuEnabled = true; DMenu *CurrentMenu; int MenuTime; +DObject* menuCustomizer; + extern PClass *DefaultListMenuClass; extern PClass *DefaultOptionMenuClass; @@ -190,7 +192,9 @@ void M_MarkMenus() GC::Mark(pair->Value); } GC::Mark(CurrentMenu); + GC::Mark(menuCustomizer); } + //============================================================================ // // DMenu base class @@ -884,6 +888,7 @@ DEFINE_GLOBAL(menuactive) DEFINE_GLOBAL(BackbuttonTime) DEFINE_GLOBAL(BackbuttonAlpha) DEFINE_GLOBAL(GameTicRate) +DEFINE_GLOBAL(menuCustomizer) DEFINE_FIELD(DMenu, mParentMenu) DEFINE_FIELD(DMenu, mMouseCapture); diff --git a/src/common/menu/menu.h b/src/common/menu/menu.h index b4964a6f95..17ca811005 100644 --- a/src/common/menu/menu.h +++ b/src/common/menu/menu.h @@ -47,6 +47,7 @@ class DMenu; extern DMenu *CurrentMenu; extern int MenuTime; class DMenuItemBase; +extern DObject* menuCustomizer; //============================================================================= // diff --git a/src/common/menu/menudef.cpp b/src/common/menu/menudef.cpp index 56e2a8ddad..b9b97a7604 100644 --- a/src/common/menu/menudef.cpp +++ b/src/common/menu/menudef.cpp @@ -151,6 +151,11 @@ void DeinitMenus() } MenuDescriptors.Clear(); OptionValues.Clear(); + if (menuCustomizer) + { + menuCustomizer->Destroy(); + menuCustomizer = nullptr; + } } FTextureID GetMenuTexture(const char* const name) diff --git a/src/menu/doommenu.cpp b/src/menu/doommenu.cpp index a22f2244d7..b576e0f737 100644 --- a/src/menu/doommenu.cpp +++ b/src/menu/doommenu.cpp @@ -1261,6 +1261,9 @@ void SetDefaultMenuColors() OptionSettings.mFontColorHeader = V_FindFontColor(gameinfo.mFontColorHeader); OptionSettings.mFontColorHighlight = V_FindFontColor(gameinfo.mFontColorHighlight); OptionSettings.mFontColorSelection = V_FindFontColor(gameinfo.mFontColorSelection); + + auto cls = PClass::FindClass("MenuCustomize"); + menuCustomizer = cls->CreateNew(); } CCMD (menu_main) diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index 710f9d941f..5311aa2916 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -257,6 +257,7 @@ version "4.5" #include "zscript/ui/menu/readthis.zs" #include "zscript/ui/menu/reverbedit.zs" #include "zscript/ui/menu/textentermenu.zs" +#include "zscript/ui/menu/menucustomize.zs" #include "zscript/ui/menu/search/menu.zs" #include "zscript/ui/menu/search/searchfield.zs" diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index cfaf4685cf..f99609a8f2 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -50,6 +50,7 @@ struct _ native // These are the global variables, the struct is only here to av native readonly @MusPlayingInfo musplaying; native readonly bool generic_ui; native readonly int GameTicRate; + native MenuCustomize menuCustomizer; // sandbox state in multi-level setups: diff --git a/wadsrc/static/zscript/ui/menu/menucustomize.zs b/wadsrc/static/zscript/ui/menu/menucustomize.zs new file mode 100644 index 0000000000..137e5e68b9 --- /dev/null +++ b/wadsrc/static/zscript/ui/menu/menucustomize.zs @@ -0,0 +1,10 @@ +// This class allows global customization of certain menu aspects, e.g. replacing the menu caption. + +class MenuCustomize +{ + virtual int DrawCaption(String title, Font fnt, int y, bool drawit) + { + screen.DrawText(fnt, OptionMenuSettings.mTitleColor, (screen.GetWidth() - fnt.StringWidth(title) * CleanXfac_1) / 2, 10 * CleanYfac_1, title, DTA_CleanNoMove_1, true); + return y + fnt.GetHeight(); + } +} diff --git a/wadsrc/static/zscript/ui/menu/optionmenu.zs b/wadsrc/static/zscript/ui/menu/optionmenu.zs index 31aee1d02b..38fa33c1b9 100644 --- a/wadsrc/static/zscript/ui/menu/optionmenu.zs +++ b/wadsrc/static/zscript/ui/menu/optionmenu.zs @@ -433,15 +433,7 @@ class OptionMenu : Menu let font = generic_ui || !mDesc.mFont ? NewSmallFont : mDesc.mFont; if (font && mDesc.mTitle.Length() > 0) { - let font = generic_ui || !mDesc.mFont ? NewSmallFont : mDesc.mFont; - if (drawit) - { - let tt = Stringtable.Localize(title); - screen.DrawText(font, OptionMenuSettings.mTitleColor, - (screen.GetWidth() - font.StringWidth(tt) * CleanXfac_1) / 2, 10 * CleanYfac_1, - tt, DTA_CleanNoMove_1, true); - } - return y + font.GetHeight(); + return menuCustomizer.DrawCaption(title, font, y, drawit); } else {