2016-03-01 15:47:10 +00:00
|
|
|
/*
|
|
|
|
** messagebox.cpp
|
|
|
|
** Confirmation, notification screns
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** 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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2016-10-12 17:22:33 +00:00
|
|
|
#include <ctype.h>
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "menu/menu.h"
|
|
|
|
#include "d_event.h"
|
|
|
|
#include "d_gui.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "v_text.h"
|
|
|
|
#include "d_main.h"
|
|
|
|
#include "gstrings.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "i_video.h"
|
|
|
|
#include "st_start.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "g_game.h"
|
|
|
|
|
2016-03-03 08:27:37 +00:00
|
|
|
EXTERN_CVAR (Bool, saveloadconfirmation) // [mxd]
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
typedef void(*hfunc)();
|
|
|
|
DEFINE_ACTION_FUNCTION(DMessageBoxMenu, CallHandler)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-02-18 22:39:02 +00:00
|
|
|
PARAM_PROLOGUE;
|
|
|
|
PARAM_POINTERTYPE(Handler, hfunc);
|
|
|
|
Handler();
|
|
|
|
return 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
DMenu *CreateMessageBoxMenu(DMenu *parent, const char *message, int messagemode, bool playsound, FName action = NAME_None, hfunc handler = nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-02-18 22:39:02 +00:00
|
|
|
auto c = PClass::FindClass("MessageBoxMenu");
|
|
|
|
auto p = c->CreateNew();
|
2017-02-26 11:51:24 +00:00
|
|
|
VMValue params[] = { p, parent, FString(message), messagemode, playsound, action.GetIndex(), reinterpret_cast<void*>(handler) };
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
auto f = dyn_cast<PFunction>(c->Symbols.FindSymbol("Init", false));
|
|
|
|
GlobalVMStack.Call(f->Variants[0].Implementation, params, countof(params), nullptr, 0);
|
|
|
|
return (DMenu*)p;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-02-18 21:07:28 +00:00
|
|
|
CCMD (menu_quit)
|
|
|
|
{ // F10
|
|
|
|
M_StartControlPanel (true);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
int messageindex = gametic % gameinfo.quitmessages.Size();
|
|
|
|
FString EndString;
|
|
|
|
const char *msg = gameinfo.quitmessages[messageindex];
|
2017-02-18 21:07:28 +00:00
|
|
|
if (msg[0] == '$')
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (msg[1] == '*')
|
|
|
|
{
|
2017-02-18 21:07:28 +00:00
|
|
|
EndString = GStrings(msg + 2);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-18 21:07:28 +00:00
|
|
|
EndString.Format("%s\n\n%s", GStrings(msg + 1), GStrings("DOSY"));
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else EndString = gameinfo.quitmessages[messageindex];
|
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
DMenu *newmenu = CreateMessageBoxMenu(CurrentMenu, EndString, 0, false, NAME_None, []()
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (!netgame)
|
|
|
|
{
|
|
|
|
if (gameinfo.quitSound.IsNotEmpty())
|
|
|
|
{
|
2017-02-18 21:07:28 +00:00
|
|
|
S_Sound(CHAN_VOICE | CHAN_UI, gameinfo.quitSound, snd_menuvolume, ATTN_NONE);
|
|
|
|
I_WaitVBL(105);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ST_Endoom();
|
2017-02-18 21:07:28 +00:00
|
|
|
});
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
M_ActivateMenu(newmenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-02-23 08:20:02 +00:00
|
|
|
void ActivateEndGameMenu()
|
|
|
|
{
|
2017-02-18 21:07:28 +00:00
|
|
|
FString tempstring = GStrings(netgame ? "NETEND" : "ENDGAME");
|
2017-02-18 22:39:02 +00:00
|
|
|
DMenu *newmenu = CreateMessageBoxMenu(CurrentMenu, tempstring, 0, false, NAME_None, []()
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
M_ClearMenus();
|
2017-02-18 21:07:28 +00:00
|
|
|
if (!netgame)
|
|
|
|
{
|
|
|
|
D_StartTitle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
M_ActivateMenu(newmenu);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 08:20:02 +00:00
|
|
|
CCMD (menu_endgame)
|
|
|
|
{ // F7
|
|
|
|
if (!usergame)
|
|
|
|
{
|
|
|
|
S_Sound (CHAN_VOICE | CHAN_UI, "menu/invalid", snd_menuvolume, ATTN_NONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//M_StartControlPanel (true);
|
|
|
|
S_Sound (CHAN_VOICE | CHAN_UI, "menu/activate", snd_menuvolume, ATTN_NONE);
|
|
|
|
|
|
|
|
ActivateEndGameMenu();
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
CCMD (quicksave)
|
|
|
|
{ // F6
|
|
|
|
if (!usergame || (players[consoleplayer].health <= 0 && !multiplayer))
|
|
|
|
{
|
|
|
|
S_Sound (CHAN_VOICE | CHAN_UI, "menu/invalid", snd_menuvolume, ATTN_NONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gamestate != GS_LEVEL)
|
|
|
|
return;
|
|
|
|
|
2017-02-11 16:20:12 +00:00
|
|
|
if (savegameManager.quickSaveSlot == NULL)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-03 08:27:37 +00:00
|
|
|
S_Sound(CHAN_VOICE | CHAN_UI, "menu/activate", snd_menuvolume, ATTN_NONE);
|
2016-03-01 15:47:10 +00:00
|
|
|
M_StartControlPanel(false);
|
|
|
|
M_SetMenu(NAME_Savegamemenu);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-03 08:27:37 +00:00
|
|
|
|
|
|
|
// [mxd]. Just save the game, no questions asked.
|
|
|
|
if (!saveloadconfirmation)
|
|
|
|
{
|
2017-02-18 11:36:31 +00:00
|
|
|
G_SaveGame(savegameManager.quickSaveSlot->Filename.GetChars(), savegameManager.quickSaveSlot->SaveTitle.GetChars());
|
2016-03-03 08:27:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
S_Sound(CHAN_VOICE | CHAN_UI, "menu/activate", snd_menuvolume, ATTN_NONE);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
FString tempstring;
|
2017-02-18 21:07:28 +00:00
|
|
|
tempstring.Format(GStrings("QSPROMPT"), savegameManager.quickSaveSlot->SaveTitle.GetChars());
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
DMenu *newmenu = CreateMessageBoxMenu(CurrentMenu, tempstring, 0, false, NAME_None, []()
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-02-18 21:07:28 +00:00
|
|
|
G_SaveGame(savegameManager.quickSaveSlot->Filename.GetChars(), savegameManager.quickSaveSlot->SaveTitle.GetChars());
|
|
|
|
S_Sound(CHAN_VOICE | CHAN_UI, "menu/dismiss", snd_menuvolume, ATTN_NONE);
|
2016-03-01 15:47:10 +00:00
|
|
|
M_ClearMenus();
|
2017-02-18 21:07:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
M_ActivateMenu(newmenu);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
CCMD (quickload)
|
|
|
|
{ // F9
|
|
|
|
if (netgame)
|
|
|
|
{
|
2016-03-03 08:27:37 +00:00
|
|
|
M_StartControlPanel(true);
|
2016-03-01 15:47:10 +00:00
|
|
|
M_StartMessage (GStrings("QLOADNET"), 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:20:12 +00:00
|
|
|
if (savegameManager.quickSaveSlot == NULL)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-03 08:27:37 +00:00
|
|
|
M_StartControlPanel(true);
|
2016-03-01 15:47:10 +00:00
|
|
|
// signal that whatever gets loaded should be the new quicksave
|
2017-02-11 16:20:12 +00:00
|
|
|
savegameManager.quickSaveSlot = (FSaveGameNode *)1;
|
2016-03-01 15:47:10 +00:00
|
|
|
M_SetMenu(NAME_Loadgamemenu);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-03 08:27:37 +00:00
|
|
|
|
|
|
|
// [mxd]. Just load the game, no questions asked.
|
|
|
|
if (!saveloadconfirmation)
|
|
|
|
{
|
2017-02-11 16:20:12 +00:00
|
|
|
G_LoadGame(savegameManager.quickSaveSlot->Filename.GetChars());
|
2016-03-03 08:27:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-02-18 21:07:28 +00:00
|
|
|
FString tempstring;
|
|
|
|
tempstring.Format(GStrings("QLPROMPT"), savegameManager.quickSaveSlot->SaveTitle.GetChars());
|
2016-03-03 08:27:37 +00:00
|
|
|
|
|
|
|
M_StartControlPanel(true);
|
2017-02-18 21:07:28 +00:00
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
DMenu *newmenu = CreateMessageBoxMenu(CurrentMenu, tempstring, 0, false, NAME_None, []()
|
2017-02-18 21:07:28 +00:00
|
|
|
{
|
|
|
|
G_LoadGame(savegameManager.quickSaveSlot->Filename.GetChars());
|
|
|
|
S_Sound(CHAN_VOICE | CHAN_UI, "menu/dismiss", snd_menuvolume, ATTN_NONE);
|
|
|
|
M_ClearMenus();
|
|
|
|
});
|
2016-03-01 15:47:10 +00:00
|
|
|
M_ActivateMenu(newmenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void M_StartMessage(const char *message, int messagemode, FName action)
|
|
|
|
{
|
2017-02-18 18:19:14 +00:00
|
|
|
if (CurrentMenu == NULL)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
// only play a sound if no menu was active before
|
|
|
|
M_StartControlPanel(menuactive == MENU_Off);
|
|
|
|
}
|
2017-02-18 22:39:02 +00:00
|
|
|
DMenu *newmenu = CreateMessageBoxMenu(CurrentMenu, message, messagemode, false, action);
|
2017-02-18 18:19:14 +00:00
|
|
|
newmenu->mParentMenu = CurrentMenu;
|
2016-03-01 15:47:10 +00:00
|
|
|
M_ActivateMenu(newmenu);
|
|
|
|
}
|
|
|
|
|
2017-02-10 23:36:53 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(DMenu, StartMessage)
|
|
|
|
{
|
|
|
|
PARAM_PROLOGUE;
|
|
|
|
PARAM_STRING(msg);
|
2017-02-24 09:09:25 +00:00
|
|
|
PARAM_INT_DEF(mode);
|
2017-02-10 23:36:53 +00:00
|
|
|
PARAM_NAME_DEF(action);
|
|
|
|
M_StartMessage(msg, mode, action);
|
|
|
|
return 0;
|
2017-02-18 22:05:01 +00:00
|
|
|
}
|