- made DMenu's static variables regular global variables because that class is going to go completely scripted soon.

This commit is contained in:
Christoph Oelckers 2017-02-18 19:19:14 +01:00
parent 1b4c9e13b8
commit 06141338f1
9 changed files with 74 additions and 74 deletions

View file

@ -207,7 +207,7 @@ DEFINE_ACTION_FUNCTION(_CVar, SetInt)
{
// Only menus are allowed to change CVARs.
PARAM_SELF_STRUCT_PROLOGUE(FBaseCVar);
if (!(self->GetFlags() & CVAR_MOD) && DMenu::CurrentMenu == nullptr) return 0;
if (!(self->GetFlags() & CVAR_MOD) && CurrentMenu == nullptr) return 0;
PARAM_INT(val);
UCVarValue v;
v.Int = val;
@ -219,7 +219,7 @@ DEFINE_ACTION_FUNCTION(_CVar, SetFloat)
{
// Only menus are allowed to change CVARs.
PARAM_SELF_STRUCT_PROLOGUE(FBaseCVar);
if (!(self->GetFlags() & CVAR_MOD) && DMenu::CurrentMenu == nullptr) return 0;
if (!(self->GetFlags() & CVAR_MOD) && CurrentMenu == nullptr) return 0;
PARAM_FLOAT(val);
UCVarValue v;
v.Float = (float)val;
@ -231,7 +231,7 @@ DEFINE_ACTION_FUNCTION(_CVar, SetString)
{
// Only menus are allowed to change CVARs.
PARAM_SELF_STRUCT_PROLOGUE(FBaseCVar);
if (!(self->GetFlags() & CVAR_MOD) && DMenu::CurrentMenu == nullptr) return 0;
if (!(self->GetFlags() & CVAR_MOD) && CurrentMenu == nullptr) return 0;
PARAM_STRING(val);
UCVarValue v;
v.String = val.GetChars();

View file

@ -666,7 +666,7 @@ void C_DoCommand (const char *cmd, int keynum)
// This is only accessible to the special menu item to run CCMDs.
DEFINE_ACTION_FUNCTION(DOptionMenuItemCommand, DoCommand)
{
if (DMenu::CurrentMenu == nullptr) return 0;
if (CurrentMenu == nullptr) return 0;
PARAM_PROLOGUE;
PARAM_STRING(cmd);
C_DoCommand(cmd);

View file

@ -189,9 +189,9 @@ void UpdateJoystickMenu(IJoystickConfig *selected)
//opt->CalcIndent();
// If the joystick config menu is open, close it if the device it's open for is gone.
if (DMenu::CurrentMenu != nullptr && (DMenu::CurrentMenu->IsKindOf("JoystickConfigMenu")))
if (CurrentMenu != nullptr && (CurrentMenu->IsKindOf("JoystickConfigMenu")))
{
auto p = DMenu::CurrentMenu->PointerVar<IJoystickConfig>("mJoy");
auto p = CurrentMenu->PointerVar<IJoystickConfig>("mJoy");
if (p != nullptr)
{
unsigned i;
@ -204,7 +204,7 @@ void UpdateJoystickMenu(IJoystickConfig *selected)
}
if (i == Joysticks.Size())
{
DMenu::CurrentMenu->Close();
CurrentMenu->Close();
}
}
}

View file

@ -69,18 +69,16 @@ CVAR (Float, snd_menuvolume, 0.6f, CVAR_ARCHIVE)
CVAR(Int, m_use_mouse, 2, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Int, m_show_backbutton, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
DMenu *DMenu::CurrentMenu;
DEFINE_ACTION_FUNCTION(DMenu, GetCurrentMenu)
{
ACTION_RETURN_OBJECT(DMenu::CurrentMenu);
ACTION_RETURN_OBJECT(CurrentMenu);
}
int DMenu::MenuTime;
DEFINE_ACTION_FUNCTION(DMenu, MenuTime)
{
ACTION_RETURN_INT(DMenu::MenuTime);
ACTION_RETURN_INT(MenuTime);
}
FGameStartup GameStartupInfo;
@ -92,6 +90,8 @@ bool MenuButtonOrigin[NUM_MKEYS];
int BackbuttonTime;
float BackbuttonAlpha;
static bool MenuEnabled = true;
DMenu *CurrentMenu;
int MenuTime;
void M_InitVideoModes();
extern PClass *DefaultListMenuClass;
@ -140,7 +140,7 @@ void M_MarkMenus()
{
GC::Mark(pair->Value);
}
GC::Mark(DMenu::CurrentMenu);
GC::Mark(CurrentMenu);
}
//============================================================================
//
@ -237,7 +237,7 @@ bool DMenu::MenuEvent (int mkey, bool fromcontroller)
{
Close();
S_Sound (CHAN_VOICE | CHAN_UI,
DMenu::CurrentMenu != nullptr? "menu/backup" : "menu/clear", snd_menuvolume, ATTN_NONE);
CurrentMenu != nullptr? "menu/backup" : "menu/clear", snd_menuvolume, ATTN_NONE);
return true;
}
}
@ -272,13 +272,13 @@ bool DMenu::CallMenuEvent(int mkey, bool fromcontroller)
void DMenu::Close ()
{
if (DMenu::CurrentMenu == nullptr) return; // double closing can happen in the save menu.
assert(DMenu::CurrentMenu == this);
DMenu::CurrentMenu = mParentMenu;
if (CurrentMenu == nullptr) return; // double closing can happen in the save menu.
assert(CurrentMenu == this);
CurrentMenu = mParentMenu;
Destroy();
if (DMenu::CurrentMenu != nullptr)
if (CurrentMenu != nullptr)
{
GC::WriteBarrier(DMenu::CurrentMenu);
GC::WriteBarrier(CurrentMenu);
}
else
{
@ -401,7 +401,7 @@ void DMenu::CallTicker()
void DMenu::Drawer ()
{
if (this == DMenu::CurrentMenu && BackbuttonAlpha > 0 && m_show_backbutton >= 0 && m_use_mouse)
if (this == CurrentMenu && BackbuttonAlpha > 0 && m_show_backbutton >= 0 && m_use_mouse)
{
FTexture *tex = TexMan(gameinfo.mBackButton);
int w = tex->GetScaledWidth() * CleanXfac;
@ -471,7 +471,7 @@ bool DMenu::TranslateKeyboardEvents()
void M_StartControlPanel (bool makeSound)
{
// intro might call this repeatedly
if (DMenu::CurrentMenu != nullptr)
if (CurrentMenu != nullptr)
return;
ResetButtonStates ();
@ -503,9 +503,9 @@ void M_StartControlPanel (bool makeSound)
void M_ActivateMenu(DMenu *menu)
{
if (menuactive == MENU_Off) menuactive = MENU_On;
if (DMenu::CurrentMenu != nullptr) DMenu::CurrentMenu->ReleaseCapture();
DMenu::CurrentMenu = menu;
GC::WriteBarrier(DMenu::CurrentMenu);
if (CurrentMenu != nullptr) CurrentMenu->ReleaseCapture();
CurrentMenu = menu;
GC::WriteBarrier(CurrentMenu);
}
DEFINE_ACTION_FUNCTION(DMenu, ActivateMenu)
@ -617,7 +617,7 @@ void M_SetMenu(FName menu, int param)
DMenu *newmenu = (DMenu *)cls->CreateNew();
IFVIRTUALPTRNAME(newmenu, "ListMenu", Init)
{
VMValue params[3] = { newmenu, DMenu::CurrentMenu, ld };
VMValue params[3] = { newmenu, CurrentMenu, ld };
GlobalVMStack.Call(func, params, 3, nullptr, 0);
}
M_ActivateMenu(newmenu);
@ -633,7 +633,7 @@ void M_SetMenu(FName menu, int param)
DMenu *newmenu = (DMenu*)cls->CreateNew();
IFVIRTUALPTRNAME(newmenu, "OptionMenu", Init)
{
VMValue params[3] = { newmenu, DMenu::CurrentMenu, ld };
VMValue params[3] = { newmenu, CurrentMenu, ld };
GlobalVMStack.Call(func, params, 3, nullptr, 0);
}
M_ActivateMenu(newmenu);
@ -648,7 +648,7 @@ void M_SetMenu(FName menu, int param)
if (menuclass->IsDescendantOf(RUNTIME_CLASS(DMenu)))
{
DMenu *newmenu = (DMenu*)menuclass->CreateNew();
newmenu->mParentMenu = DMenu::CurrentMenu;
newmenu->mParentMenu = CurrentMenu;
M_ActivateMenu(newmenu);
return;
}
@ -684,7 +684,7 @@ bool M_Responder (event_t *ev)
return false;
}
if (DMenu::CurrentMenu != nullptr && menuactive != MENU_Off)
if (CurrentMenu != nullptr && menuactive != MENU_Off)
{
// There are a few input sources we are interested in:
//
@ -719,9 +719,9 @@ bool M_Responder (event_t *ev)
}
// pass everything else on to the current menu
return DMenu::CurrentMenu->CallResponder(ev);
return CurrentMenu->CallResponder(ev);
}
else if (DMenu::CurrentMenu->TranslateKeyboardEvents())
else if (CurrentMenu->TranslateKeyboardEvents())
{
ch = ev->data1;
keyup = ev->subtype == EV_GUI_KeyUp;
@ -740,7 +740,7 @@ bool M_Responder (event_t *ev)
default:
if (!keyup)
{
return DMenu::CurrentMenu->CallResponder(ev);
return CurrentMenu->CallResponder(ev);
}
break;
}
@ -823,11 +823,11 @@ bool M_Responder (event_t *ev)
{
MenuButtonTickers[mkey] = KEY_REPEAT_DELAY;
}
DMenu::CurrentMenu->CallMenuEvent(mkey, fromcontroller);
CurrentMenu->CallMenuEvent(mkey, fromcontroller);
return true;
}
}
return DMenu::CurrentMenu->CallResponder(ev) || !keyup;
return CurrentMenu->CallResponder(ev) || !keyup;
}
else if (MenuEnabled)
{
@ -868,10 +868,10 @@ bool M_Responder (event_t *ev)
void M_Ticker (void)
{
DMenu::MenuTime++;
if (DMenu::CurrentMenu != nullptr && menuactive != MENU_Off)
MenuTime++;
if (CurrentMenu != nullptr && menuactive != MENU_Off)
{
DMenu::CurrentMenu->CallTicker();
CurrentMenu->CallTicker();
for (int i = 0; i < NUM_MKEYS; ++i)
{
@ -880,7 +880,7 @@ void M_Ticker (void)
if (MenuButtonTickers[i] > 0 && --MenuButtonTickers[i] <= 0)
{
MenuButtonTickers[i] = KEY_REPEAT_RATE;
DMenu::CurrentMenu->CallMenuEvent(i, MenuButtonOrigin[i]);
CurrentMenu->CallMenuEvent(i, MenuButtonOrigin[i]);
}
}
}
@ -920,14 +920,14 @@ void M_Drawer (void)
}
if (DMenu::CurrentMenu != nullptr && menuactive != MENU_Off)
if (CurrentMenu != nullptr && menuactive != MENU_Off)
{
if (DMenu::CurrentMenu->DimAllowed())
if (CurrentMenu->DimAllowed())
{
screen->Dim(fade);
V_SetBorderNeedRefresh();
}
DMenu::CurrentMenu->CallDrawer();
CurrentMenu->CallDrawer();
}
}
@ -940,10 +940,10 @@ void M_Drawer (void)
void M_ClearMenus ()
{
M_DemoNoPlay = false;
if (DMenu::CurrentMenu != nullptr)
if (CurrentMenu != nullptr)
{
DMenu::CurrentMenu->Destroy();
DMenu::CurrentMenu = nullptr;
CurrentMenu->Destroy();
CurrentMenu = nullptr;
}
V_SetBorderNeedRefresh();
menuactive = MENU_Off;
@ -1181,11 +1181,11 @@ CCMD(reset2saved)
// This really should be in the script but we can't do scripted CCMDs yet.
CCMD(undocolorpic)
{
if (DMenu::CurrentMenu != NULL)
if (CurrentMenu != NULL)
{
IFVIRTUALPTR(DMenu::CurrentMenu, DMenu, ResetColor)
IFVIRTUALPTR(CurrentMenu, DMenu, ResetColor)
{
VMValue params[] = { (DObject*)DMenu::CurrentMenu };
VMValue params[] = { (DObject*)CurrentMenu };
GlobalVMStack.Call(func, params, countof(params), nullptr, 0, nullptr);
}
}

View file

@ -107,6 +107,9 @@ public:
};
extern FSavegameManager savegameManager;
class DMenu;
extern DMenu *CurrentMenu;
extern int MenuTime;
//=============================================================================
//
@ -267,9 +270,6 @@ public:
BACKBUTTON_TIME = 4*TICRATE
};
static DMenu *CurrentMenu;
static int MenuTime;
TObjPtr<DMenu> mParentMenu;
DMenu(DMenu *parent = NULL);

View file

@ -147,7 +147,7 @@ static void DeinitMenus()
}
MenuDescriptors.Clear();
OptionValues.Clear();
DMenu::CurrentMenu = nullptr;
CurrentMenu = nullptr;
savegameManager.ClearSaveGames();
}

View file

@ -139,7 +139,7 @@ void DMessageBoxMenu::OnDestroy()
void DMessageBoxMenu::CloseSound()
{
S_Sound (CHAN_VOICE | CHAN_UI,
DMenu::CurrentMenu != NULL? "menu/backup" : "menu/dismiss", snd_menuvolume, ATTN_NONE);
CurrentMenu != NULL? "menu/backup" : "menu/dismiss", snd_menuvolume, ATTN_NONE);
}
//=============================================================================
@ -212,7 +212,7 @@ void DMessageBoxMenu::Drawer ()
if (messageSelection >= 0)
{
if ((DMenu::MenuTime%8) < 6)
if ((MenuTime%8) < 6)
{
screen->DrawText(ConFont, OptionSettings.mFontColorSelection,
(150 - 160) * CleanXfac + screen->GetWidth() / 2,
@ -431,7 +431,7 @@ CCMD (menu_quit)
{ // F10
M_StartControlPanel (true);
DMenu *newmenu = new DQuitMenu(false);
newmenu->mParentMenu = DMenu::CurrentMenu;
newmenu->mParentMenu = CurrentMenu;
M_ActivateMenu(newmenu);
}
@ -511,7 +511,7 @@ CCMD (menu_endgame)
//M_StartControlPanel (true);
S_Sound (CHAN_VOICE | CHAN_UI, "menu/activate", snd_menuvolume, ATTN_NONE);
DMenu *newmenu = new DEndGameMenu(false);
newmenu->mParentMenu = DMenu::CurrentMenu;
newmenu->mParentMenu = CurrentMenu;
M_ActivateMenu(newmenu);
}
@ -607,7 +607,7 @@ CCMD (quicksave)
S_Sound(CHAN_VOICE | CHAN_UI, "menu/activate", snd_menuvolume, ATTN_NONE);
DMenu *newmenu = new DQuickSaveMenu(false);
newmenu->mParentMenu = DMenu::CurrentMenu;
newmenu->mParentMenu = CurrentMenu;
M_ActivateMenu(newmenu);
}
@ -702,7 +702,7 @@ CCMD (quickload)
M_StartControlPanel(true);
DMenu *newmenu = new DQuickLoadMenu(false);
newmenu->mParentMenu = DMenu::CurrentMenu;
newmenu->mParentMenu = CurrentMenu;
M_ActivateMenu(newmenu);
}
@ -714,13 +714,13 @@ CCMD (quickload)
void M_StartMessage(const char *message, int messagemode, FName action)
{
if (DMenu::CurrentMenu == NULL)
if (CurrentMenu == NULL)
{
// only play a sound if no menu was active before
M_StartControlPanel(menuactive == MENU_Off);
}
DMenu *newmenu = new DMessageBoxMenu(DMenu::CurrentMenu, message, messagemode, false, action);
newmenu->mParentMenu = DMenu::CurrentMenu;
DMenu *newmenu = new DMessageBoxMenu(CurrentMenu, message, messagemode, false, action);
newmenu->mParentMenu = CurrentMenu;
M_ActivateMenu(newmenu);
}

View file

@ -66,7 +66,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged)
PARAM_INT(g);
PARAM_INT(b);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
char command[24];
players[consoleplayer].userinfo.ColorChanged(MAKERGB(r, g, b));
@ -91,7 +91,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged)
const char *pp = s;
FString command("name \"");
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
// Escape any backslashes or quotation marks before sending the name to the console.
for (auto p = pp; *p != '\0'; ++p)
@ -118,7 +118,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged)
{
PARAM_SELF_PROLOGUE(DMenu);
PARAM_INT(sel);
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
players[consoleplayer].userinfo.ColorSetChanged(sel);
char command[24];
@ -139,7 +139,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ClassChanged)
PARAM_SELF_PROLOGUE(DMenu);
PARAM_INT(sel);
PARAM_POINTER(cls, FPlayerClass);
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
players[consoleplayer].userinfo.PlayerClassNumChanged(gameinfo.norandomplayerclass ? sel : sel - 1);
cvar_set("playerclass", sel == 0 && !gameinfo.norandomplayerclass ? "Random" : GetPrintableDisplayName(cls->Type).GetChars());
@ -158,7 +158,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, SkinChanged)
{
PARAM_SELF_PROLOGUE(DMenu);
PARAM_INT(sel);
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
players[consoleplayer].userinfo.SkinNumChanged(sel);
cvar_set("skin", Skins[sel].Name);
@ -177,7 +177,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged)
PARAM_SELF_PROLOGUE(DMenu);
PARAM_FLOAT(val);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
autoaim = float(val);
}
@ -195,7 +195,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged)
PARAM_SELF_PROLOGUE(DMenu);
PARAM_INT(val);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
team = val == 0 ? TEAM_NONE : val - 1;
}
@ -213,7 +213,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged)
PARAM_SELF_PROLOGUE(DMenu);
PARAM_INT(v);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
cvar_set("gender", v == 0 ? "male" : v == 1 ? "female" : "other");
}
@ -231,7 +231,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged)
PARAM_SELF_PROLOGUE(DMenu);
PARAM_INT(v);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
neverswitchonpickup = !!v;
}
@ -249,7 +249,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, AlwaysRunChanged)
PARAM_SELF_PROLOGUE(DMenu);
PARAM_INT(v);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
if (self == CurrentMenu)
{
cl_run = !!v;
}

View file

@ -1097,7 +1097,7 @@ public:
if (response == mSelection+1)
{
int color = ((DMenu::MenuTime%8) < 4) || DMenu::CurrentMenu != this ? CR_RED:CR_GREY;
int color = ((MenuTime%8) < 4) || CurrentMenu != this ? CR_RED:CR_GREY;
x = (50 + 3 - 160) * CleanXfac + screen->GetWidth() / 2;
int yy = (y + fontheight/2 - 5 - 100) * CleanYfac + screen->GetHeight() / 2;
@ -1135,9 +1135,9 @@ void P_FreeStrifeConversations ()
ClassRoots.Clear();
PrevNode = NULL;
if (DMenu::CurrentMenu != NULL && DMenu::CurrentMenu->IsKindOf(RUNTIME_CLASS(DConversationMenu)))
if (CurrentMenu != NULL && CurrentMenu->IsKindOf(RUNTIME_CLASS(DConversationMenu)))
{
DMenu::CurrentMenu->Close();
CurrentMenu->Close();
}
}
@ -1482,10 +1482,10 @@ void P_ConversationCommand (int netcode, int pnum, BYTE **stream)
// The conversation menus are normally closed by the menu code, but that
// doesn't happen during demo playback, so we need to do it here.
if (demoplayback && DMenu::CurrentMenu != NULL &&
DMenu::CurrentMenu->IsKindOf(RUNTIME_CLASS(DConversationMenu)))
if (demoplayback && CurrentMenu != NULL &&
CurrentMenu->IsKindOf(RUNTIME_CLASS(DConversationMenu)))
{
DMenu::CurrentMenu->Close();
CurrentMenu->Close();
}
if (netcode == DEM_CONVREPLY)
{