- 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.
This commit is contained in:
Christoph Oelckers 2017-02-19 15:35:28 +01:00
parent 9089beb110
commit fb52b034b0
3 changed files with 23 additions and 9 deletions

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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)
{