2019-11-08 22:02:52 +00:00
|
|
|
/*
|
|
|
|
** menu.cpp
|
|
|
|
** Menu base class and global interface
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2010 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "d_gui.h"
|
|
|
|
#include "c_console.h"
|
|
|
|
#include "c_bind.h"
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "d_event.h"
|
|
|
|
//#include "i_input.h"
|
|
|
|
#include "gameconfigfile.h"
|
|
|
|
#include "gstrings.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "textures.h"
|
|
|
|
#include "c_buttons.h"
|
|
|
|
#include "v_2ddrawer.h"
|
|
|
|
#include "printf.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "gamecontrol.h"
|
2019-11-25 23:29:51 +00:00
|
|
|
#include "pragmas.h"
|
|
|
|
#include "build.h"
|
2019-12-08 23:43:48 +00:00
|
|
|
#include "statistics.h"
|
2020-06-11 07:57:17 +00:00
|
|
|
#include "m_joy.h"
|
2020-04-12 06:09:38 +00:00
|
|
|
#include "raze_sound.h"
|
2020-05-24 19:19:33 +00:00
|
|
|
#include "texturemanager.h"
|
2020-05-25 15:11:32 +00:00
|
|
|
#include "v_video.h"
|
2020-07-21 22:42:50 +00:00
|
|
|
#include "gamestate.h"
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2020-06-11 07:22:16 +00:00
|
|
|
void RegisterDuke3dMenus();
|
2019-12-01 14:31:08 +00:00
|
|
|
void RegisterBloodMenus();
|
2019-12-02 23:01:04 +00:00
|
|
|
void RegisterSWMenus();
|
2019-12-14 11:39:18 +00:00
|
|
|
void RegisterPSMenus();
|
2019-11-28 22:27:10 +00:00
|
|
|
void RegisterLoadsaveMenus();
|
2019-12-05 18:52:46 +00:00
|
|
|
void RegisterOptionMenus();
|
2019-12-14 18:21:49 +00:00
|
|
|
void RegisterJoystickMenus();
|
|
|
|
void UpdateJoystickMenu(IJoystickConfig* joy);
|
2019-11-23 22:05:24 +00:00
|
|
|
bool help_disabled, credits_disabled;
|
|
|
|
int g_currentMenu; // accessible by CON scripts - contains the current menu's script ID if defined or INT_MAX if none given.
|
2019-12-05 23:06:41 +00:00
|
|
|
TArray<DMenu*> toDelete;
|
2019-11-22 21:52:11 +00:00
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
//
|
|
|
|
// Todo: Move these elsewhere
|
|
|
|
//
|
|
|
|
CVAR (Float, mouse_sensitivity, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
EXTERN_CVAR (Bool, show_messages)
|
|
|
|
|
|
|
|
|
2019-12-01 07:23:35 +00:00
|
|
|
CVAR(Bool, menu_sounds, true, CVAR_ARCHIVE) // added mainly because RR's sounds are so supremely annoying.
|
|
|
|
//CVAR (Float, snd_menuvolume, 0.6f, CVAR_ARCHIVE) the current sound engine cannot deal with this.
|
2019-12-31 01:48:16 +00:00
|
|
|
CVAR(Int, m_use_mouse, 2, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
2019-11-08 22:02:52 +00:00
|
|
|
CVAR(Int, m_show_backbutton, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
|
2019-11-22 21:52:11 +00:00
|
|
|
TArray<MenuClassDescriptor*> menuClasses(TArray<MenuClassDescriptor*>::ENoInit(0));
|
|
|
|
|
2020-06-14 16:57:55 +00:00
|
|
|
DMenu *CurrentMenu;
|
|
|
|
bool DMenu::InMenu;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2020-04-23 19:18:40 +00:00
|
|
|
FNewGameStartup NewGameStartupInfo;
|
2019-11-08 22:02:52 +00:00
|
|
|
EMenuState menuactive;
|
|
|
|
bool M_DemoNoPlay;
|
|
|
|
FButtonStatus MenuButtons[NUM_MKEYS];
|
|
|
|
int MenuButtonTickers[NUM_MKEYS];
|
|
|
|
bool MenuButtonOrigin[NUM_MKEYS];
|
2019-11-22 21:52:11 +00:00
|
|
|
int BackbuttonTime;
|
2019-11-08 22:02:52 +00:00
|
|
|
float BackbuttonAlpha;
|
|
|
|
static bool MenuEnabled = true;
|
|
|
|
|
|
|
|
|
|
|
|
#define KEY_REPEAT_DELAY (MENU_TICRATE*5/12)
|
|
|
|
#define KEY_REPEAT_RATE (3)
|
|
|
|
|
2019-11-25 23:29:51 +00:00
|
|
|
|
2019-11-25 23:43:20 +00:00
|
|
|
static MenuTransition transition;
|
|
|
|
|
2019-11-28 22:27:10 +00:00
|
|
|
bool MenuTransition::StartTransition(DMenu *from, DMenu *to, MenuTransitionType animtype)
|
2019-11-25 23:29:51 +00:00
|
|
|
{
|
|
|
|
if (!from->canAnimate || !to->canAnimate || animtype == MA_None)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-25 17:42:11 +00:00
|
|
|
start = I_GetTimeNS() * (120. / 1'000'000'000.);
|
2019-11-28 23:37:19 +00:00
|
|
|
length = 30;
|
2019-11-28 22:27:10 +00:00
|
|
|
dir = animtype == MA_Advance? 1 : -1;
|
|
|
|
previous = from;
|
|
|
|
current = to;
|
2019-11-25 23:29:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 22:27:10 +00:00
|
|
|
bool MenuTransition::Draw()
|
2019-11-25 23:29:51 +00:00
|
|
|
{
|
2020-08-25 17:42:11 +00:00
|
|
|
double now = I_GetTimeNS() * (120. / 1'000'000'000);
|
|
|
|
if (now < start + length)
|
2019-11-25 23:29:51 +00:00
|
|
|
{
|
|
|
|
double factor = 120 * xdim / ydim;
|
2020-08-25 17:42:11 +00:00
|
|
|
double phase = (now - start) / double(length) * M_PI + M_PI/2;
|
2019-11-25 23:29:51 +00:00
|
|
|
|
2019-11-28 22:27:10 +00:00
|
|
|
previous->origin.X = factor * dir * (sin(phase) - 1.);
|
|
|
|
current->origin.X = factor * dir * (sin(phase) + 1.);
|
|
|
|
previous->Drawer();
|
|
|
|
current->Drawer();
|
2019-11-25 23:43:20 +00:00
|
|
|
return true;
|
2019-11-25 23:29:51 +00:00
|
|
|
}
|
2019-11-25 23:43:20 +00:00
|
|
|
return false;
|
2019-11-25 23:29:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// DMenu base class
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
DMenu::DMenu(DMenu *parent)
|
|
|
|
{
|
|
|
|
mParentMenu = parent;
|
|
|
|
mMouseCapture = false;
|
|
|
|
mBackbuttonSelected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DMenu::Responder (event_t *ev)
|
|
|
|
{
|
|
|
|
bool res = false;
|
|
|
|
if (ev->type == EV_GUI_Event)
|
|
|
|
{
|
|
|
|
if (ev->subtype == EV_GUI_LButtonDown)
|
|
|
|
{
|
|
|
|
res = MouseEventBack(MOUSE_Click, ev->data1, ev->data2);
|
|
|
|
// make the menu's mouse handler believe that the current coordinate is outside the valid range
|
|
|
|
if (res) ev->data2 = -1;
|
|
|
|
res |= MouseEvent(MOUSE_Click, ev->data1, ev->data2);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
SetCapture();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (ev->subtype == EV_GUI_MouseMove)
|
|
|
|
{
|
|
|
|
BackbuttonTime = BACKBUTTON_TIME;
|
|
|
|
if (mMouseCapture || m_use_mouse == 1)
|
|
|
|
{
|
|
|
|
res = MouseEventBack(MOUSE_Move, ev->data1, ev->data2);
|
|
|
|
if (res) ev->data2 = -1;
|
|
|
|
res |= MouseEvent(MOUSE_Move, ev->data1, ev->data2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ev->subtype == EV_GUI_LButtonUp)
|
|
|
|
{
|
|
|
|
if (mMouseCapture)
|
|
|
|
{
|
|
|
|
ReleaseCapture();
|
|
|
|
res = MouseEventBack(MOUSE_Release, ev->data1, ev->data2);
|
|
|
|
if (res) ev->data2 = -1;
|
|
|
|
res |= MouseEvent(MOUSE_Release, ev->data1, ev->data2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
bool DMenu::MenuEvent (int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
switch (mkey)
|
|
|
|
{
|
|
|
|
case MKEY_Back:
|
|
|
|
{
|
2020-07-21 22:42:50 +00:00
|
|
|
//if (scriptID != 0)
|
2019-11-23 22:05:24 +00:00
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
M_MenuSound(CurrentMenu->mParentMenu? BackSound : CloseSound);
|
2019-11-23 22:05:24 +00:00
|
|
|
Close();
|
2020-08-23 19:24:31 +00:00
|
|
|
if (!CurrentMenu && gamestate == GS_MENUSCREEN) C_FullConsole();
|
2019-11-23 22:05:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void DMenu::Close ()
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
assert(CurrentMenu == this);
|
2019-11-25 23:43:20 +00:00
|
|
|
|
2020-06-14 16:57:55 +00:00
|
|
|
CurrentMenu = mParentMenu;
|
2019-11-28 22:27:10 +00:00
|
|
|
if (mParentMenu && transition.StartTransition(this, mParentMenu, MA_Return))
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
g_currentMenu = CurrentMenu->scriptID;
|
2019-11-23 22:05:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-25 23:43:20 +00:00
|
|
|
Destroy();
|
2019-12-05 23:06:41 +00:00
|
|
|
toDelete.Push(this);
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu == NULL)
|
2019-11-25 23:43:20 +00:00
|
|
|
{
|
|
|
|
M_ClearMenus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
g_currentMenu = CurrentMenu->scriptID;
|
2019-11-25 23:43:20 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
bool DMenu::MouseEvent(int type, int x, int y)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
bool DMenu::MouseEventBack(int type, int x, int y)
|
|
|
|
{
|
|
|
|
if (m_show_backbutton >= 0)
|
|
|
|
{
|
2020-05-24 19:19:33 +00:00
|
|
|
auto texid = TexMan.CheckForTexture("engine/graphics/m_back.png", ETextureType::Any);
|
|
|
|
if (texid.isValid())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-05-25 21:59:07 +00:00
|
|
|
auto tex = TexMan.GetGameTexture(texid);
|
2020-05-23 22:38:10 +00:00
|
|
|
if (m_show_backbutton&1) x -= screen->GetWidth() - tex->GetDisplayWidth() * CleanXfac;
|
|
|
|
if (m_show_backbutton&2) y -= screen->GetHeight() - tex->GetDisplayHeight() * CleanYfac;
|
|
|
|
mBackbuttonSelected = ( x >= 0 && x < tex->GetDisplayWidth() * CleanXfac &&
|
|
|
|
y >= 0 && y < tex->GetDisplayHeight() * CleanYfac);
|
2019-11-08 22:02:52 +00:00
|
|
|
if (mBackbuttonSelected && type == MOUSE_Release)
|
|
|
|
{
|
|
|
|
if (m_use_mouse == 2) mBackbuttonSelected = false;
|
|
|
|
MenuEvent(MKEY_Back, true);
|
|
|
|
}
|
|
|
|
return mBackbuttonSelected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void DMenu::SetCapture()
|
|
|
|
{
|
|
|
|
if (!mMouseCapture)
|
|
|
|
{
|
|
|
|
mMouseCapture = true;
|
|
|
|
I_SetMouseCapture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DMenu::ReleaseCapture()
|
|
|
|
{
|
|
|
|
if (mMouseCapture)
|
|
|
|
{
|
|
|
|
mMouseCapture = false;
|
|
|
|
I_ReleaseMouseCapture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void DMenu::Ticker ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DMenu::Drawer ()
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
if (this == CurrentMenu && BackbuttonAlpha > 0 && m_show_backbutton >= 0 && m_use_mouse)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-05-24 19:19:33 +00:00
|
|
|
auto texid = TexMan.CheckForTexture("engine/graphics/m_back.png", ETextureType::Any);
|
|
|
|
if (texid.isValid())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-05-25 21:59:07 +00:00
|
|
|
auto tex = TexMan.GetGameTexture(texid);
|
2020-05-23 22:38:10 +00:00
|
|
|
int w = tex->GetDisplayWidth() * CleanXfac;
|
|
|
|
int h = tex->GetDisplayHeight() * CleanYfac;
|
|
|
|
int x = (!(m_show_backbutton & 1)) ? 0 : screen->GetWidth() - w;
|
|
|
|
int y = (!(m_show_backbutton & 2)) ? 0 : screen->GetHeight() - h;
|
|
|
|
if (mBackbuttonSelected && (mMouseCapture || m_use_mouse == 1))
|
|
|
|
{
|
|
|
|
DrawTexture(twod, tex, x, y, DTA_CleanNoMove, true, DTA_ColorOverlay, MAKEARGB(40, 255, 255, 255), TAG_DONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DrawTexture(twod, tex, x, y, DTA_CleanNoMove, true, DTA_Alpha, BackbuttonAlpha, TAG_DONE);
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 23:37:19 +00:00
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
bool DMenu::DimAllowed()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DMenu::TranslateKeyboardEvents()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void M_StartControlPanel (bool makeSound)
|
|
|
|
{
|
2019-11-25 22:21:51 +00:00
|
|
|
static bool created = false;
|
2019-11-08 22:02:52 +00:00
|
|
|
// intro might call this repeatedly
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu != NULL)
|
2019-11-08 22:02:52 +00:00
|
|
|
return;
|
|
|
|
|
2019-11-25 22:21:51 +00:00
|
|
|
if (!created) // Cannot do this earlier.
|
|
|
|
{
|
|
|
|
created = true;
|
|
|
|
M_CreateMenus();
|
|
|
|
}
|
2020-02-16 19:08:04 +00:00
|
|
|
GSnd->SetSfxPaused(true, PAUSESFX_MENU);
|
2019-11-30 18:23:54 +00:00
|
|
|
gi->MenuOpened();
|
2020-08-02 20:16:26 +00:00
|
|
|
if (makeSound) M_MenuSound(ActivateSound);
|
2019-11-25 22:21:51 +00:00
|
|
|
|
2020-01-01 10:35:47 +00:00
|
|
|
inputState.ClearAllInput();
|
2019-11-08 22:02:52 +00:00
|
|
|
for (int i = 0; i < NUM_MKEYS; ++i)
|
|
|
|
{
|
|
|
|
MenuButtons[i].ReleaseKey(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
C_HideConsole (); // [RH] Make sure console goes bye bye.
|
|
|
|
menuactive = MENU_On;
|
|
|
|
// Pause sound effects before we play the menu switch sound.
|
|
|
|
// That way, it won't be paused.
|
|
|
|
//P_CheckTickerPaused ();
|
|
|
|
|
|
|
|
BackbuttonTime = 0;
|
|
|
|
BackbuttonAlpha = 0;
|
|
|
|
}
|
|
|
|
|
2019-11-23 22:05:24 +00:00
|
|
|
void Menu_Open(int playerid)
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
M_StartControlPanel(CurrentMenu == nullptr);
|
2019-11-23 22:05:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void M_ActivateMenu(DMenu *menu)
|
|
|
|
{
|
2019-11-23 22:05:24 +00:00
|
|
|
g_currentMenu = menu->scriptID;
|
2019-11-08 22:02:52 +00:00
|
|
|
if (menuactive == MENU_Off) menuactive = MENU_On;
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu != NULL)
|
2019-11-25 23:43:20 +00:00
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
CurrentMenu->ReleaseCapture();
|
|
|
|
transition.StartTransition(CurrentMenu, menu, MA_Advance);
|
2019-11-25 23:43:20 +00:00
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
CurrentMenu = menu;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-11-25 22:21:51 +00:00
|
|
|
bool M_SetMenu(FName menu, int param, FName caller)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-25 10:26:19 +00:00
|
|
|
#if 0
|
2019-12-24 18:47:34 +00:00
|
|
|
// skip the menu and go right into the first level.
|
|
|
|
// For tracking memory leaks that normally require operating the menu to start the game so that they always get the same allocation number.
|
2020-04-23 19:18:40 +00:00
|
|
|
NewGameStartupInfo.Episode = NewGameStartupInfo.Skill = 0;
|
2020-04-11 22:02:48 +00:00
|
|
|
menu = NAME_Startgame;
|
2019-12-24 18:47:34 +00:00
|
|
|
#endif
|
2019-11-08 22:02:52 +00:00
|
|
|
// some menus need some special treatment (needs to be adjusted for the various frontends.
|
2020-04-11 21:50:43 +00:00
|
|
|
switch (caller.GetIndex())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-04-11 22:02:48 +00:00
|
|
|
case NAME_Episodemenu:
|
2020-02-27 18:26:30 +00:00
|
|
|
case NAME_TargetMenu:
|
2019-11-25 22:21:51 +00:00
|
|
|
// sent from the episode menu
|
2020-04-23 19:18:40 +00:00
|
|
|
NewGameStartupInfo.Episode = param;
|
|
|
|
NewGameStartupInfo.Level = 0;
|
|
|
|
NewGameStartupInfo.Skill = gDefaultSkill;
|
2019-11-08 22:02:52 +00:00
|
|
|
break;
|
|
|
|
|
2020-02-27 18:26:30 +00:00
|
|
|
case NAME_WeaponMenu:
|
2020-04-23 19:18:40 +00:00
|
|
|
NewGameStartupInfo.Skill = param;
|
2020-02-27 18:26:30 +00:00
|
|
|
break;
|
|
|
|
|
2020-04-11 22:02:48 +00:00
|
|
|
case NAME_Skillmenu:
|
2020-04-23 19:18:40 +00:00
|
|
|
NewGameStartupInfo.Skill = param;
|
2019-11-08 22:02:52 +00:00
|
|
|
break;
|
2020-01-15 19:39:41 +00:00
|
|
|
|
|
|
|
case NAME_EngineCredits:
|
|
|
|
case NAME_EngineCredits2:
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
auto m = CurrentMenu;
|
|
|
|
CurrentMenu = m->mParentMenu;
|
2020-01-15 19:39:41 +00:00
|
|
|
m->mParentMenu = nullptr;
|
|
|
|
toDelete.Push(m);
|
|
|
|
break;
|
|
|
|
}
|
2019-11-25 22:21:51 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2020-04-11 21:50:43 +00:00
|
|
|
switch (menu.GetIndex())
|
2019-11-25 22:21:51 +00:00
|
|
|
{
|
2020-04-11 22:02:48 +00:00
|
|
|
case NAME_Startgame:
|
2019-11-26 22:20:54 +00:00
|
|
|
M_ClearMenus(); // must be done before starting the level.
|
2020-04-23 19:18:40 +00:00
|
|
|
if (caller == NAME_Mainmenu || caller == NAME_IngameMenu) NewGameStartupInfo.Episode = param;
|
|
|
|
STAT_StartNewGame(gVolumeNames[NewGameStartupInfo.Episode], NewGameStartupInfo.Skill);
|
2020-01-05 09:36:52 +00:00
|
|
|
inputState.ClearAllInput();
|
2020-02-17 18:43:58 +00:00
|
|
|
|
2020-04-23 19:18:40 +00:00
|
|
|
gi->StartGame(NewGameStartupInfo);
|
2019-11-25 22:21:51 +00:00
|
|
|
return false;
|
|
|
|
|
2019-11-27 21:41:15 +00:00
|
|
|
case NAME_CustomSubMenu1:
|
2020-01-05 11:56:32 +00:00
|
|
|
menu = ENamedName(menu.GetIndex() + param);
|
2019-11-27 21:41:15 +00:00
|
|
|
break;
|
|
|
|
|
2019-11-25 22:21:51 +00:00
|
|
|
#if 0
|
2019-11-08 22:02:52 +00:00
|
|
|
case NAME_StartgameConfirm:
|
|
|
|
{
|
|
|
|
// sent from the skill menu for a skill that needs to be confirmed
|
2020-04-23 19:18:40 +00:00
|
|
|
NewGameStartupInfo.Skill = param;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
const char *msg = AllSkills[param].MustConfirmText;
|
|
|
|
if (*msg==0) msg = GStrings("NIGHTMARE");
|
2019-11-29 00:28:13 +00:00
|
|
|
M_StartMessage (msg, 0, -1, NAME_StartgameConfirmed);
|
2019-11-08 22:02:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-12-05 22:17:55 +00:00
|
|
|
#endif
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2020-04-11 22:02:48 +00:00
|
|
|
case NAME_Savegamemenu:
|
2019-12-05 22:17:55 +00:00
|
|
|
if (!gi->CanSave())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
// cannot save outside the game.
|
2019-11-29 00:28:13 +00:00
|
|
|
M_StartMessage (GStrings("SAVEDEAD"), 1, -1);
|
2019-12-05 22:17:55 +00:00
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-12-10 21:22:59 +00:00
|
|
|
break;
|
2019-12-02 23:57:03 +00:00
|
|
|
|
2020-04-11 22:02:48 +00:00
|
|
|
case NAME_Quitmenu:
|
2019-12-05 22:17:55 +00:00
|
|
|
// This is no separate class
|
2019-12-02 23:57:03 +00:00
|
|
|
C_DoCommand("menu_quit");
|
|
|
|
return true;
|
|
|
|
|
2020-04-11 22:02:48 +00:00
|
|
|
case NAME_EndGameMenu:
|
2019-12-05 22:17:55 +00:00
|
|
|
// This is no separate class
|
2019-12-06 17:36:49 +00:00
|
|
|
C_DoCommand("menu_endgame");
|
2019-12-02 23:57:03 +00:00
|
|
|
return true;
|
2019-11-25 22:21:51 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
// End of special checks
|
|
|
|
|
|
|
|
FMenuDescriptor **desc = MenuDescriptors.CheckKey(menu);
|
|
|
|
if (desc != NULL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if ((*desc)->mNetgameMessage.IsNotEmpty() && netgame && !demoplayback)
|
|
|
|
{
|
|
|
|
M_StartMessage((*desc)->mNetgameMessage, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((*desc)->mType == MDESC_ListMenu)
|
|
|
|
{
|
|
|
|
FListMenuDescriptor *ld = static_cast<FListMenuDescriptor*>(*desc);
|
|
|
|
if (ld->mAutoselect >= 0 && ld->mAutoselect < (int)ld->mItems.Size())
|
|
|
|
{
|
|
|
|
// recursively activate the autoselected item without ever creating this menu.
|
2019-11-25 22:21:51 +00:00
|
|
|
ld->mItems[ld->mAutoselect]->Activate(ld->mMenuName);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-22 21:52:11 +00:00
|
|
|
DListMenu* newmenu;
|
|
|
|
if (ld->mClass != NAME_None)
|
|
|
|
{
|
|
|
|
auto ndx = menuClasses.FindEx([=](const auto p) { return p->mName == ld->mClass; });
|
|
|
|
if (ndx == menuClasses.Size())
|
|
|
|
{
|
|
|
|
I_Error("Bad menu class %s\n", ld->mClass.GetChars());
|
2020-01-07 00:11:19 +00:00
|
|
|
return true;
|
2019-11-22 21:52:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newmenu = (DListMenu*)menuClasses[ndx]->CreateNew();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newmenu = new DListMenu;
|
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
newmenu->Init(CurrentMenu, ld);
|
2019-11-08 22:02:52 +00:00
|
|
|
M_ActivateMenu(newmenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((*desc)->mType == MDESC_OptionsMenu)
|
|
|
|
{
|
|
|
|
FOptionMenuDescriptor *ld = static_cast<FOptionMenuDescriptor*>(*desc);
|
2020-01-07 00:11:19 +00:00
|
|
|
DOptionMenu* newmenu = nullptr;
|
2019-12-05 18:52:46 +00:00
|
|
|
if (ld->mClass != NAME_None)
|
|
|
|
{
|
|
|
|
auto ndx = menuClasses.FindEx([=](const auto p) { return p->mName == ld->mClass; });
|
|
|
|
if (ndx == menuClasses.Size())
|
|
|
|
{
|
|
|
|
I_Error("Bad menu class %s\n", ld->mClass.GetChars());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newmenu = (DOptionMenu*)menuClasses[ndx]->CreateNew();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newmenu = new DOptionMenu;
|
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
newmenu->Init(CurrentMenu, ld);
|
2019-11-08 22:02:52 +00:00
|
|
|
M_ActivateMenu(newmenu);
|
|
|
|
}
|
2019-11-28 22:27:10 +00:00
|
|
|
else if ((*desc)->mType == MDESC_ImageScroller)
|
|
|
|
{
|
|
|
|
FImageScrollerDescriptor* ld = static_cast<FImageScrollerDescriptor*>(*desc);
|
2019-12-01 16:48:56 +00:00
|
|
|
DImageScrollerMenu* newmenu;
|
|
|
|
if (ld->mClass != NAME_None)
|
2019-11-28 22:27:10 +00:00
|
|
|
{
|
2019-12-01 16:48:56 +00:00
|
|
|
auto ndx = menuClasses.FindEx([=](const auto p) { return p->mName == ld->mClass; });
|
|
|
|
if (ndx == menuClasses.Size())
|
|
|
|
{
|
|
|
|
I_Error("Bad menu class %s\n", ld->mClass.GetChars());
|
2020-01-07 00:11:19 +00:00
|
|
|
return true;
|
2019-12-01 16:48:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newmenu = (DImageScrollerMenu*)menuClasses[ndx]->CreateNew();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newmenu = new DImageScrollerMenu;
|
2019-11-28 22:27:10 +00:00
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
newmenu->Init(CurrentMenu, ld);
|
2019-12-01 16:48:56 +00:00
|
|
|
M_ActivateMenu(newmenu);
|
2019-11-28 22:27:10 +00:00
|
|
|
}
|
2019-11-25 22:21:51 +00:00
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-22 21:52:11 +00:00
|
|
|
/*
|
2019-11-08 22:02:52 +00:00
|
|
|
const PClass *menuclass = PClass::FindClass(menu);
|
|
|
|
if (menuclass != NULL)
|
|
|
|
{
|
|
|
|
if (menuclass->IsDescendantOf(RUNTIME_CLASS(DMenu)))
|
|
|
|
{
|
|
|
|
DMenu *newmenu = (DMenu*)menuclass->CreateNew();
|
2020-06-14 16:57:55 +00:00
|
|
|
newmenu->mParentMenu = CurrentMenu;
|
2019-11-08 22:02:52 +00:00
|
|
|
M_ActivateMenu(newmenu);
|
2019-11-25 22:21:51 +00:00
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-22 21:52:11 +00:00
|
|
|
*/
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
Printf("Attempting to open menu of unknown type '%s'\n", menu.GetChars());
|
2019-11-29 23:49:50 +00:00
|
|
|
M_ClearMenus();
|
2019-11-25 22:21:51 +00:00
|
|
|
return false;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-12-05 23:06:41 +00:00
|
|
|
bool M_DoResponder (event_t *ev)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
int ch = 0;
|
|
|
|
bool keyup = false;
|
|
|
|
int mkey = NUM_MKEYS;
|
|
|
|
bool fromcontroller = true;
|
|
|
|
|
|
|
|
if (chatmodeon)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu != NULL && menuactive != MENU_Off)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
// There are a few input sources we are interested in:
|
|
|
|
//
|
|
|
|
// EV_KeyDown / EV_KeyUp : joysticks/gamepads/controllers
|
|
|
|
// EV_GUI_KeyDown / EV_GUI_KeyUp : the keyboard
|
|
|
|
// EV_GUI_Char : printable characters, which we want in string input mode
|
|
|
|
//
|
|
|
|
// This code previously listened for EV_GUI_KeyRepeat to handle repeating
|
|
|
|
// in the menus, but that doesn't work with gamepads, so now we combine
|
|
|
|
// the multiple inputs into buttons and handle the repetition manually.
|
|
|
|
if (ev->type == EV_GUI_Event)
|
|
|
|
{
|
|
|
|
fromcontroller = false;
|
|
|
|
if (ev->subtype == EV_GUI_KeyRepeat)
|
|
|
|
{
|
|
|
|
// We do our own key repeat handling but still want to eat the
|
|
|
|
// OS's repeated keys.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ev->subtype == EV_GUI_BackButtonDown || ev->subtype == EV_GUI_BackButtonUp)
|
|
|
|
{
|
|
|
|
mkey = MKEY_Back;
|
|
|
|
keyup = ev->subtype == EV_GUI_BackButtonUp;
|
|
|
|
}
|
|
|
|
else if (ev->subtype != EV_GUI_KeyDown && ev->subtype != EV_GUI_KeyUp)
|
|
|
|
{
|
|
|
|
// do we want mouse input?
|
|
|
|
if (ev->subtype >= EV_GUI_FirstMouseEvent && ev->subtype <= EV_GUI_LastMouseEvent)
|
|
|
|
{
|
|
|
|
if (!m_use_mouse)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass everything else on to the current menu
|
2020-06-14 16:57:55 +00:00
|
|
|
return CurrentMenu->Responder(ev);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
else if (CurrentMenu->TranslateKeyboardEvents())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
ch = ev->data1;
|
|
|
|
keyup = ev->subtype == EV_GUI_KeyUp;
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case GK_BACK: mkey = MKEY_Back; break;
|
|
|
|
case GK_ESCAPE: mkey = MKEY_Back; break;
|
|
|
|
case GK_RETURN: mkey = MKEY_Enter; break;
|
|
|
|
case GK_UP: mkey = MKEY_Up; break;
|
|
|
|
case GK_DOWN: mkey = MKEY_Down; break;
|
|
|
|
case GK_LEFT: mkey = MKEY_Left; break;
|
|
|
|
case GK_RIGHT: mkey = MKEY_Right; break;
|
|
|
|
case GK_BACKSPACE: mkey = MKEY_Clear; break;
|
|
|
|
case GK_PGUP: mkey = MKEY_PageUp; break;
|
|
|
|
case GK_PGDN: mkey = MKEY_PageDown; break;
|
|
|
|
default:
|
|
|
|
if (!keyup)
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
return CurrentMenu->Responder(ev);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (menuactive != MENU_WaitKey && (ev->type == EV_KeyDown || ev->type == EV_KeyUp))
|
|
|
|
{
|
|
|
|
keyup = ev->type == EV_KeyUp;
|
|
|
|
|
|
|
|
ch = ev->data1;
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case KEY_JOY1:
|
|
|
|
case KEY_PAD_A:
|
|
|
|
mkey = MKEY_Enter;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_JOY2:
|
|
|
|
case KEY_PAD_B:
|
|
|
|
mkey = MKEY_Back;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_JOY3:
|
|
|
|
case KEY_PAD_X:
|
|
|
|
mkey = MKEY_Clear;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_JOY5:
|
|
|
|
case KEY_PAD_LSHOULDER:
|
|
|
|
mkey = MKEY_PageUp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_JOY6:
|
|
|
|
case KEY_PAD_RSHOULDER:
|
|
|
|
mkey = MKEY_PageDown;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_PAD_DPAD_UP:
|
|
|
|
case KEY_PAD_LTHUMB_UP:
|
|
|
|
case KEY_JOYAXIS1MINUS:
|
|
|
|
case KEY_JOYPOV1_UP:
|
|
|
|
mkey = MKEY_Up;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_PAD_DPAD_DOWN:
|
|
|
|
case KEY_PAD_LTHUMB_DOWN:
|
|
|
|
case KEY_JOYAXIS1PLUS:
|
|
|
|
case KEY_JOYPOV1_DOWN:
|
|
|
|
mkey = MKEY_Down;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_PAD_DPAD_LEFT:
|
|
|
|
case KEY_PAD_LTHUMB_LEFT:
|
|
|
|
case KEY_JOYAXIS2MINUS:
|
|
|
|
case KEY_JOYPOV1_LEFT:
|
|
|
|
mkey = MKEY_Left;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_PAD_DPAD_RIGHT:
|
|
|
|
case KEY_PAD_LTHUMB_RIGHT:
|
|
|
|
case KEY_JOYAXIS2PLUS:
|
|
|
|
case KEY_JOYPOV1_RIGHT:
|
|
|
|
mkey = MKEY_Right;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mkey != NUM_MKEYS)
|
|
|
|
{
|
|
|
|
if (keyup)
|
|
|
|
{
|
|
|
|
MenuButtons[mkey].ReleaseKey(ch);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MenuButtons[mkey].PressKey(ch);
|
|
|
|
MenuButtonOrigin[mkey] = fromcontroller;
|
|
|
|
if (mkey <= MKEY_PageDown)
|
|
|
|
{
|
|
|
|
MenuButtonTickers[mkey] = KEY_REPEAT_DELAY;
|
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
CurrentMenu->MenuEvent(mkey, fromcontroller);
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
return CurrentMenu->Responder(ev) || !keyup;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
else if (MenuEnabled)
|
|
|
|
{
|
|
|
|
if (ev->type == EV_KeyDown)
|
|
|
|
{
|
|
|
|
// Pop-up menu?
|
2019-12-01 09:18:38 +00:00
|
|
|
if (ev->data1 == KEY_ESCAPE) // Should we let the games handle Escape for special actions, like backing out of cameras?
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-07-21 22:42:50 +00:00
|
|
|
if (gamestate != GS_STARTUP && gamestate != GS_INTRO)
|
|
|
|
{
|
|
|
|
M_StartControlPanel(true);
|
|
|
|
M_SetMenu(gi->CanSave()? NAME_IngameMenu : NAME_Mainmenu, -1);
|
2020-08-10 22:46:27 +00:00
|
|
|
if (gamestate == GS_FULLCONSOLE) gamestate = GS_MENUSCREEN;
|
2020-07-21 22:42:50 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (ev->type == EV_GUI_Event && ev->subtype == EV_GUI_LButtonDown &&
|
|
|
|
ConsoleState != c_down && m_use_mouse)
|
|
|
|
{
|
|
|
|
M_StartControlPanel(true);
|
2020-04-11 22:02:48 +00:00
|
|
|
M_SetMenu(NAME_Mainmenu, -1);
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-05 23:06:41 +00:00
|
|
|
bool M_Responder(event_t* ev)
|
|
|
|
{
|
2020-03-01 15:32:41 +00:00
|
|
|
bool res = false;
|
2019-12-06 17:36:49 +00:00
|
|
|
// delayed deletion, so that self-deleting menus don't crash if they are getting accessed after being closed.
|
2020-03-01 15:32:41 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
res = M_DoResponder(ev);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
for (auto p : toDelete) delete p;
|
|
|
|
toDelete.Clear();
|
|
|
|
throw;
|
|
|
|
}
|
2019-12-05 23:06:41 +00:00
|
|
|
for (auto p : toDelete) delete p;
|
|
|
|
toDelete.Clear();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void M_Ticker (void)
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu != NULL && menuactive != MENU_Off)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-26 21:05:52 +00:00
|
|
|
if (transition.previous) transition.previous->Ticker();
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu == nullptr) return; // In case one of the sub-screens has closed the menu.
|
|
|
|
CurrentMenu->Ticker();
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < NUM_MKEYS; ++i)
|
|
|
|
{
|
|
|
|
if (MenuButtons[i].bDown)
|
|
|
|
{
|
|
|
|
if (MenuButtonTickers[i] > 0 && --MenuButtonTickers[i] <= 0)
|
|
|
|
{
|
|
|
|
MenuButtonTickers[i] = KEY_REPEAT_RATE;
|
2020-06-14 16:57:55 +00:00
|
|
|
CurrentMenu->MenuEvent(i, MenuButtonOrigin[i]);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (BackbuttonTime > 0)
|
|
|
|
{
|
|
|
|
if (BackbuttonAlpha < 1.0f) BackbuttonAlpha += 0.1f;
|
|
|
|
BackbuttonTime--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (BackbuttonAlpha > 0) BackbuttonAlpha -= 0.1f;
|
|
|
|
if (BackbuttonAlpha < 0) BackbuttonAlpha = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void M_Drawer (void)
|
|
|
|
{
|
2019-11-21 21:31:46 +00:00
|
|
|
PalEntry fade = 0x70000000;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu != NULL && menuactive != MENU_Off)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-08-10 22:46:27 +00:00
|
|
|
if (CurrentMenu->DimAllowed() && fade && gamestate != GS_MENUSCREEN) twod->AddColorOnlyQuad(0, 0, screen->GetWidth(), screen->GetHeight(), fade);
|
2019-11-25 23:43:20 +00:00
|
|
|
|
2019-11-26 21:05:52 +00:00
|
|
|
bool going = false;
|
2019-11-25 23:43:20 +00:00
|
|
|
if (transition.previous)
|
|
|
|
{
|
2019-11-28 22:27:10 +00:00
|
|
|
going = transition.Draw();
|
2019-11-26 21:05:52 +00:00
|
|
|
if (!going)
|
2019-11-25 23:43:20 +00:00
|
|
|
{
|
2019-11-26 21:05:52 +00:00
|
|
|
if (transition.dir == -1) delete transition.previous;
|
2019-11-25 23:43:20 +00:00
|
|
|
transition.previous = nullptr;
|
|
|
|
transition.current = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2019-11-26 21:05:52 +00:00
|
|
|
if (!going)
|
2019-11-25 23:43:20 +00:00
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
assert(CurrentMenu);
|
|
|
|
CurrentMenu->origin = { 0,0 };
|
|
|
|
CurrentMenu->Drawer();
|
2019-11-25 23:43:20 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2020-02-17 17:40:32 +00:00
|
|
|
void M_UnpauseSound()
|
|
|
|
{
|
|
|
|
GSnd->SetSfxPaused(false, PAUSESFX_MENU);
|
|
|
|
}
|
|
|
|
|
2019-12-25 10:26:19 +00:00
|
|
|
void M_ClearMenus (bool final)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-02-09 21:57:04 +00:00
|
|
|
if (menuactive == MENU_Off) return;
|
2019-11-08 22:02:52 +00:00
|
|
|
M_DemoNoPlay = false;
|
2019-11-30 21:46:00 +00:00
|
|
|
transition.previous = transition.current = nullptr;
|
|
|
|
transition.dir = 0;
|
2020-06-14 16:57:55 +00:00
|
|
|
auto menu = CurrentMenu;
|
2019-11-30 21:46:00 +00:00
|
|
|
while (menu != nullptr)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-30 21:46:00 +00:00
|
|
|
auto nextm = menu->mParentMenu;
|
|
|
|
menu->Destroy();
|
|
|
|
delete menu;
|
|
|
|
menu = nextm;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
CurrentMenu = nullptr;
|
2019-11-08 22:02:52 +00:00
|
|
|
menuactive = MENU_Off;
|
2020-02-17 17:40:32 +00:00
|
|
|
M_UnpauseSound();
|
2020-07-15 07:21:47 +00:00
|
|
|
inputState.ClearAllInput();
|
2019-12-25 10:26:19 +00:00
|
|
|
if (!final)
|
|
|
|
{
|
2020-02-09 21:57:04 +00:00
|
|
|
gi->MenuClosed();
|
2019-12-25 10:26:19 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 09:18:38 +00:00
|
|
|
bool M_Active()
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
return CurrentMenu != nullptr || ConsoleState == c_down || ConsoleState == c_falling;
|
2019-12-01 09:18:38 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void M_MenuSound(EMenuSounds snd)
|
|
|
|
{
|
|
|
|
if (menu_sounds) gi->MenuSound(snd);
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-12-23 09:53:58 +00:00
|
|
|
void M_PreviousMenu()
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu != nullptr)
|
2019-12-23 09:53:58 +00:00
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
DMenu* parent = CurrentMenu->mParentMenu;
|
|
|
|
CurrentMenu->Destroy();
|
|
|
|
CurrentMenu = parent;
|
2019-12-23 09:53:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
void M_Init (void)
|
|
|
|
{
|
2020-06-11 07:22:16 +00:00
|
|
|
RegisterDuke3dMenus();
|
2019-12-01 14:31:08 +00:00
|
|
|
RegisterBloodMenus();
|
2019-12-02 23:01:04 +00:00
|
|
|
RegisterSWMenus();
|
2019-12-14 11:39:18 +00:00
|
|
|
RegisterPSMenus();
|
2019-11-28 22:27:10 +00:00
|
|
|
RegisterLoadsaveMenus();
|
2019-12-05 18:52:46 +00:00
|
|
|
RegisterOptionMenus();
|
2019-12-14 18:21:49 +00:00
|
|
|
RegisterJoystickMenus();
|
2019-11-08 22:02:52 +00:00
|
|
|
M_ParseMenuDefs();
|
2019-12-14 18:21:49 +00:00
|
|
|
UpdateJoystickMenu(nullptr);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void M_EnableMenu (bool on)
|
|
|
|
{
|
|
|
|
MenuEnabled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 17:56:13 +00:00
|
|
|
bool M_IsAnimated()
|
|
|
|
{
|
|
|
|
if (ConsoleState == c_down) return false;
|
|
|
|
if (!CurrentMenu) return false;
|
|
|
|
if (CurrentMenu->IsAnimated()) return true;
|
|
|
|
if(transition.previous) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// [RH] Most menus can now be accessed directly
|
|
|
|
// through console commands.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
CCMD (openmenu)
|
|
|
|
{
|
|
|
|
if (argv.argc() < 2)
|
|
|
|
{
|
|
|
|
Printf("Usage: openmenu \"menu_name\"");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
M_StartControlPanel (true);
|
|
|
|
M_SetMenu(argv[1], -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (closemenu)
|
|
|
|
{
|
|
|
|
M_ClearMenus();
|
|
|
|
}
|
|
|
|
|
|
|
|
EXTERN_CVAR (Int, screenblocks)
|
|
|
|
|
|
|
|
CCMD(menuconsole)
|
|
|
|
{
|
|
|
|
M_ClearMenus();
|
|
|
|
C_ToggleConsole();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(reset2defaults)
|
|
|
|
{
|
|
|
|
C_SetDefaultBindings ();
|
|
|
|
C_SetCVarsToDefaults ();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(reset2saved)
|
|
|
|
{
|
|
|
|
GameConfig->DoGlobalSetup ();
|
|
|
|
GameConfig->DoGameSetup (currentGame);
|
|
|
|
}
|
2019-11-23 22:05:24 +00:00
|
|
|
|
2020-04-11 22:09:39 +00:00
|
|
|
CCMD(menu_main)
|
|
|
|
{
|
|
|
|
M_StartControlPanel(true);
|
2020-08-14 20:41:32 +00:00
|
|
|
M_SetMenu(gi->CanSave() ? NAME_IngameMenu : NAME_Mainmenu, -1);
|
2019-11-23 22:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(openhelpmenu)
|
|
|
|
{
|
|
|
|
if (!help_disabled)
|
|
|
|
{
|
2019-11-30 18:23:54 +00:00
|
|
|
M_StartControlPanel(true);
|
2019-11-23 22:05:24 +00:00
|
|
|
M_SetMenu(NAME_HelpMenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(opensavemenu)
|
|
|
|
{
|
|
|
|
if (gi->CanSave())
|
|
|
|
{
|
2019-11-30 18:23:54 +00:00
|
|
|
M_StartControlPanel(true);
|
2020-04-11 22:02:48 +00:00
|
|
|
M_SetMenu(NAME_Savegamemenu);
|
2019-11-23 22:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(openloadmenu)
|
|
|
|
{
|
2019-11-30 18:23:54 +00:00
|
|
|
M_StartControlPanel(true);
|
2020-04-11 22:02:48 +00:00
|
|
|
M_SetMenu(NAME_Loadgamemenu);
|
2019-11-23 22:05:24 +00:00
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
|