From fb52b034b0242b393cef3d5c4f44c1221a2865ba Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Feb 2017 15:35:28 +0100 Subject: [PATCH] - added a GenericMenu class, so that all menus can be given a virtual Init method. Doing this to Menu itself would not work because the different menus require different parameters. This also means that all menus that are routed through menu items must inherit from either ListMenu, OptionMenu or GenericMenu. All other types can only be used internally. This should complete the menu scriptification. --- src/menu/menu.cpp | 9 +++++++-- wadsrc/static/zscript/menu/menu.txt | 8 ++++++++ wadsrc/static/zscript/menu/readthis.txt | 15 ++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index c64b05711..b2ceffc7a 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -469,10 +469,15 @@ void M_SetMenu(FName menu, int param) const PClass *menuclass = PClass::FindClass(menu); if (menuclass != nullptr) { - if (menuclass->IsDescendantOf(RUNTIME_CLASS(DMenu))) + if (menuclass->IsDescendantOf("GenericMenu")) { DMenu *newmenu = (DMenu*)menuclass->CreateNew(); - newmenu->mParentMenu = CurrentMenu; + + IFVIRTUALPTRNAME(newmenu, "GenericMenu", Init) + { + VMValue params[3] = { newmenu, CurrentMenu }; + GlobalVMStack.Call(func, params, 2, nullptr, 0); + } M_ActivateMenu(newmenu); return; } diff --git a/wadsrc/static/zscript/menu/menu.txt b/wadsrc/static/zscript/menu/menu.txt index dda75a739..84478ba81 100644 --- a/wadsrc/static/zscript/menu/menu.txt +++ b/wadsrc/static/zscript/menu/menu.txt @@ -296,3 +296,11 @@ class MenuDescriptor : Object native native static MenuDescriptor GetDescriptor(Name n); } +// This class is only needed to give it a virtual Init method that doesn't belong to Menu itself +class GenericMenu : Menu +{ + virtual void Init(Menu parent) + { + Super.Init(parent); + } +} \ No newline at end of file diff --git a/wadsrc/static/zscript/menu/readthis.txt b/wadsrc/static/zscript/menu/readthis.txt index a3db8a8a7..604fb489e 100644 --- a/wadsrc/static/zscript/menu/readthis.txt +++ b/wadsrc/static/zscript/menu/readthis.txt @@ -33,7 +33,7 @@ ** */ -class ReadThisMenu : Menu +class ReadThisMenu : GenericMenu { int mScreen; int mInfoTic; @@ -43,18 +43,19 @@ class ReadThisMenu : Menu // // //============================================================================= + + override void Init(Menu parent) + { + Super.Init(parent); + mScreen = 1; + mInfoTic = gametic; + } override void Drawer() { double alpha; TextureID tex, prevpic; - if (mScreen == 0) - { - mScreen = 1; - mInfoTic = gametic; - } - // Did the mapper choose a custom help page via MAPINFO? if (level.F1Pic.Length() != 0) {