2019-11-08 22:02:52 +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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2019-11-30 18:23:54 +00:00
|
|
|
#include "menu.h"
|
2019-11-08 22:02:52 +00:00
|
|
|
#include "d_event.h"
|
|
|
|
#include "d_gui.h"
|
|
|
|
#include "v_text.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "gstrings.h"
|
|
|
|
#include "c_dispatch.h"
|
2019-12-08 23:55:30 +00:00
|
|
|
#include "statistics.h"
|
2019-11-08 22:02:52 +00:00
|
|
|
#include "v_2ddrawer.h"
|
2020-05-25 15:11:32 +00:00
|
|
|
#include "v_video.h"
|
2020-06-20 16:01:02 +00:00
|
|
|
#include "engineerrors.h"
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
extern FSaveGameNode *quickSaveSlot;
|
|
|
|
|
|
|
|
class DMessageBoxMenu : public DMenu
|
|
|
|
{
|
2019-11-22 21:52:11 +00:00
|
|
|
using Super = DMenu;
|
2019-12-05 22:17:55 +00:00
|
|
|
FString mFullMessage;
|
2019-11-08 22:02:52 +00:00
|
|
|
TArray<FBrokenLines> mMessage;
|
|
|
|
int mMessageMode;
|
|
|
|
int messageSelection;
|
|
|
|
int mMouseLeft, mMouseRight, mMouseY;
|
|
|
|
FName mAction;
|
2019-11-30 18:23:54 +00:00
|
|
|
std::function<void(bool)> mActionFunc;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-11-30 18:23:54 +00:00
|
|
|
DMessageBoxMenu(DMenu *parent = NULL, const char *message = NULL, int messagemode = 0, bool playsound = false, FName action = NAME_None, hFunc handler = nullptr);
|
2019-11-08 22:02:52 +00:00
|
|
|
void Destroy();
|
|
|
|
void Init(DMenu *parent, const char *message, int messagemode, bool playsound = false);
|
|
|
|
void Drawer();
|
|
|
|
bool Responder(event_t *ev);
|
|
|
|
bool MenuEvent(int mkey, bool fromcontroller);
|
|
|
|
bool MouseEvent(int type, int x, int y);
|
|
|
|
void CloseSound();
|
|
|
|
virtual void HandleResult(bool res);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-11-30 18:23:54 +00:00
|
|
|
DMessageBoxMenu::DMessageBoxMenu(DMenu *parent, const char *message, int messagemode, bool playsound, FName action, hFunc handler)
|
2019-11-08 22:02:52 +00:00
|
|
|
: DMenu(parent)
|
|
|
|
{
|
|
|
|
mAction = action;
|
2019-11-30 18:23:54 +00:00
|
|
|
mActionFunc = handler;
|
2019-11-08 22:02:52 +00:00
|
|
|
messageSelection = 0;
|
|
|
|
mMouseLeft = 140;
|
|
|
|
mMouseY = INT_MIN;
|
|
|
|
int mr1 = 170 + SmallFont->StringWidth(GStrings["TXT_YES"]);
|
|
|
|
int mr2 = 170 + SmallFont->StringWidth(GStrings["TXT_NO"]);
|
|
|
|
mMouseRight = std::max(mr1, mr2);
|
|
|
|
|
|
|
|
Init(parent, message, messagemode, playsound);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void DMessageBoxMenu::Init(DMenu *parent, const char *message, int messagemode, bool playsound)
|
|
|
|
{
|
|
|
|
mParentMenu = parent;
|
|
|
|
if (message != NULL)
|
|
|
|
{
|
2019-12-05 22:17:55 +00:00
|
|
|
mFullMessage = message;
|
2019-12-01 14:31:08 +00:00
|
|
|
mMessage = V_BreakLines(SmallFont, 300, GStrings.localize(message));
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
mMessageMode = messagemode;
|
|
|
|
if (playsound)
|
|
|
|
{
|
|
|
|
//S_StopSound (CHAN_VOICE);
|
2019-12-16 23:29:38 +00:00
|
|
|
//S_Sound (CHAN_VOICE | CHANF_UI, "menu/prompt", snd_menuvolume, ATTN_NONE);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void DMessageBoxMenu::Destroy()
|
|
|
|
{
|
|
|
|
mMessage.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void DMessageBoxMenu::CloseSound()
|
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
M_MenuSound(CurrentMenu ? BackSound : ::CloseSound);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
void DMessageBoxMenu::HandleResult(bool res)
|
|
|
|
{
|
2020-02-04 20:02:22 +00:00
|
|
|
if (mMessageMode == 0)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-02-04 20:02:22 +00:00
|
|
|
if (mActionFunc)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-02-04 20:02:22 +00:00
|
|
|
mActionFunc(res);
|
|
|
|
Close();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2020-02-04 20:02:22 +00:00
|
|
|
else if (mAction == NAME_None && mParentMenu)
|
|
|
|
{
|
|
|
|
mParentMenu->MenuEvent(res ? MKEY_MBYes : MKEY_MBNo, false);
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
if (res) M_SetMenu(mAction, -1);
|
|
|
|
}
|
|
|
|
CloseSound();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-12-05 22:17:55 +00:00
|
|
|
CVAR(Bool, m_generic_messagebox, false, CVAR_ARCHIVE)
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-12-05 22:17:55 +00:00
|
|
|
void DMessageBoxMenu::Drawer()
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
int y;
|
|
|
|
PalEntry fade = 0;
|
|
|
|
|
|
|
|
int fontheight = SmallFont->GetHeight();
|
|
|
|
//V_SetBorderNeedRefresh();
|
|
|
|
//ST_SetNeedRefresh();
|
|
|
|
|
|
|
|
y = 100;
|
|
|
|
|
2019-12-05 22:17:55 +00:00
|
|
|
if (m_generic_messagebox)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-05 22:17:55 +00:00
|
|
|
if (mMessage.Size())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-05 22:17:55 +00:00
|
|
|
for (unsigned i = 0; i < mMessage.Size(); i++)
|
|
|
|
y -= SmallFont->GetHeight() / 2;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < mMessage.Size(); i++)
|
|
|
|
{
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - mMessage[i].Width / 2, y, mMessage[i].Text,
|
2019-12-05 22:17:55 +00:00
|
|
|
DTA_Clean, true, TAG_DONE);
|
|
|
|
y += fontheight;
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 22:17:55 +00:00
|
|
|
if (mMessageMode == 0)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-05 22:17:55 +00:00
|
|
|
y += fontheight;
|
|
|
|
mMouseY = y;
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewSmallFont,
|
2019-12-05 22:17:55 +00:00
|
|
|
messageSelection == 0 ? OptionSettings.mFontColorSelection : OptionSettings.mFontColor,
|
|
|
|
160, y, GStrings["TXT_YES"], DTA_Clean, true, TAG_DONE);
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewSmallFont,
|
2019-12-05 22:17:55 +00:00
|
|
|
messageSelection == 1 ? OptionSettings.mFontColorSelection : OptionSettings.mFontColor,
|
|
|
|
160, y + fontheight + 1, GStrings["TXT_NO"], DTA_Clean, true, TAG_DONE);
|
|
|
|
|
|
|
|
if (messageSelection >= 0)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-05 22:17:55 +00:00
|
|
|
if (((DMenu::MenuTime >> 2) % 8) < 6)
|
|
|
|
{
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewSmallFont, OptionSettings.mFontColorSelection,
|
2019-12-05 22:17:55 +00:00
|
|
|
(150 - 160) * CleanXfac + screen->GetWidth() / 2,
|
|
|
|
(y + (fontheight + 1) * messageSelection - 100 + fontheight / 2 - 5) * CleanYfac + screen->GetHeight() / 2,
|
|
|
|
"\xd",
|
|
|
|
DTA_CellX, 8 * CleanXfac,
|
|
|
|
DTA_CellY, 8 * CleanYfac,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-05 22:17:55 +00:00
|
|
|
else
|
|
|
|
{
|
2020-01-05 09:48:44 +00:00
|
|
|
twod->ClearScreen(0xa0000000);
|
2019-12-05 22:17:55 +00:00
|
|
|
gi->DrawCenteredTextScreen(origin, mFullMessage, 100, false);
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
bool DMessageBoxMenu::Responder(event_t *ev)
|
|
|
|
{
|
|
|
|
if (ev->type == EV_GUI_Event && ev->subtype == EV_GUI_KeyDown)
|
|
|
|
{
|
|
|
|
if (mMessageMode == 0)
|
|
|
|
{
|
|
|
|
int ch = tolower(ev->data1);
|
|
|
|
if (ch == 'n' || ch == ' ')
|
|
|
|
{
|
|
|
|
HandleResult(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ch == 'y')
|
|
|
|
{
|
|
|
|
HandleResult(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (ev->type == EV_KeyDown)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return Super::Responder(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
bool DMessageBoxMenu::MenuEvent(int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
if (mMessageMode == 0)
|
|
|
|
{
|
2019-12-05 22:17:55 +00:00
|
|
|
if ((mkey == MKEY_Up || mkey == MKEY_Down) && m_generic_messagebox)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-16 23:29:38 +00:00
|
|
|
//S_Sound (CHAN_VOICE | CHANF_UI, "menu/cursor", snd_menuvolume, ATTN_NONE);
|
2019-11-08 22:02:52 +00:00
|
|
|
messageSelection = !messageSelection;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (mkey == MKEY_Enter)
|
|
|
|
{
|
|
|
|
// 0 is yes, 1 is no
|
|
|
|
HandleResult(!messageSelection);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (mkey == MKEY_Back)
|
|
|
|
{
|
|
|
|
HandleResult(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
CloseSound();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
bool DMessageBoxMenu::MouseEvent(int type, int x, int y)
|
|
|
|
{
|
2019-12-05 22:17:55 +00:00
|
|
|
if (mMessageMode == 1 || m_generic_messagebox)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (type == MOUSE_Click)
|
|
|
|
{
|
|
|
|
return MenuEvent(MKEY_Enter, true);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int sel = -1;
|
|
|
|
int fh = SmallFont->GetHeight() + 1;
|
|
|
|
|
|
|
|
// convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture
|
|
|
|
x = ((x - (screen->GetWidth() / 2)) / CleanXfac) + 160;
|
|
|
|
y = ((y - (screen->GetHeight() / 2)) / CleanYfac) + 100;
|
|
|
|
|
|
|
|
if (x >= mMouseLeft && x <= mMouseRight && y >= mMouseY && y < mMouseY + 2 * fh)
|
|
|
|
{
|
|
|
|
sel = y >= mMouseY + fh;
|
|
|
|
}
|
|
|
|
if (sel != -1 && sel != messageSelection)
|
|
|
|
{
|
2019-12-05 22:17:55 +00:00
|
|
|
gi->MenuSound(CursorSound);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
messageSelection = sel;
|
|
|
|
if (type == MOUSE_Release)
|
|
|
|
{
|
|
|
|
return MenuEvent(MKEY_Enter, true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
void M_StartMessage(const char *message, int messagemode, int scriptId, FName action)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
if (CurrentMenu == NULL)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
// only play a sound if no menu was active before
|
|
|
|
M_StartControlPanel(menuactive == MENU_Off);
|
|
|
|
}
|
2020-06-14 16:57:55 +00:00
|
|
|
DMenu *newmenu = new DMessageBoxMenu(CurrentMenu, message, messagemode, false, action);
|
|
|
|
newmenu->mParentMenu = CurrentMenu;
|
2019-11-29 00:28:13 +00:00
|
|
|
newmenu->scriptID = scriptId;
|
2019-11-08 22:02:52 +00:00
|
|
|
M_ActivateMenu(newmenu);
|
|
|
|
}
|
|
|
|
|
2019-11-30 18:23:54 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-11-30 21:46:00 +00:00
|
|
|
DMenu* CreateMessageBoxMenu(DMenu* parent, const char* message, int messagemode, int scriptId, bool playsound, FName action, hFunc handler)
|
2019-11-30 18:23:54 +00:00
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
auto newmenu = new DMessageBoxMenu(CurrentMenu, message, messagemode, false, action, handler);
|
2019-11-30 18:23:54 +00:00
|
|
|
newmenu->scriptID = scriptId;
|
|
|
|
return newmenu;
|
|
|
|
|
|
|
|
}
|
2019-12-02 23:57:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ActivateEndGameMenu()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (menu_endgame)
|
|
|
|
{ // F7
|
2019-12-05 22:17:55 +00:00
|
|
|
if (!gi->CanSave())
|
2019-12-02 23:57:03 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-05 22:17:55 +00:00
|
|
|
M_StartControlPanel (true);
|
2020-02-11 20:33:20 +00:00
|
|
|
FString tempstring;
|
|
|
|
tempstring << GStrings("ENDGAME") << "\n\n" << GStrings("PRESSYN");
|
2020-06-14 16:57:55 +00:00
|
|
|
DMenu* newmenu = CreateMessageBoxMenu(CurrentMenu, tempstring, 0, 501, false, NAME_None, [](bool res)
|
2019-12-05 22:17:55 +00:00
|
|
|
{
|
|
|
|
if (res)
|
|
|
|
{
|
2019-12-08 23:55:30 +00:00
|
|
|
STAT_Cancel();
|
2019-12-06 17:36:49 +00:00
|
|
|
gi->QuitToTitle();
|
2019-12-05 22:17:55 +00:00
|
|
|
}
|
|
|
|
});
|
2019-12-02 23:57:03 +00:00
|
|
|
|
2019-12-05 22:17:55 +00:00
|
|
|
M_ActivateMenu(newmenu);
|
2019-12-02 23:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
CCMD (menu_quit)
|
|
|
|
{ // F10
|
|
|
|
|
|
|
|
M_StartControlPanel (true);
|
|
|
|
|
2020-02-11 20:33:20 +00:00
|
|
|
FString EndString;
|
|
|
|
EndString << GStrings("CONFIRM_QUITMSG") << "\n\n" << GStrings("PRESSYN");
|
2019-12-02 23:57:03 +00:00
|
|
|
|
2020-06-14 16:57:55 +00:00
|
|
|
DMenu *newmenu = CreateMessageBoxMenu(CurrentMenu, EndString, 0, 500, false, NAME_None, [](bool res)
|
2019-12-02 23:57:03 +00:00
|
|
|
{
|
2020-04-11 21:50:43 +00:00
|
|
|
if (res) throw CExitEvent(0);
|
2019-12-02 23:57:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
M_ActivateMenu(newmenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|