2017-02-18 22:05:01 +00:00
|
|
|
/*
|
|
|
|
** messagebox.cpp
|
2018-11-26 16:15:40 +00:00
|
|
|
** Confirmation, notification screens
|
2017-02-18 22:05:01 +00:00
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2010-2017 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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
class MessageBoxMenu : Menu
|
2017-02-18 22:05:01 +00:00
|
|
|
{
|
2017-02-18 22:39:02 +00:00
|
|
|
BrokenLines mMessage;
|
|
|
|
voidptr Handler;
|
|
|
|
int mMessageMode;
|
|
|
|
int messageSelection;
|
|
|
|
int mMouseLeft, mMouseRight, mMouseY;
|
|
|
|
Name mAction;
|
2017-02-18 22:05:01 +00:00
|
|
|
|
2019-04-09 23:33:02 +00:00
|
|
|
Font textFont, arrowFont;
|
|
|
|
int destWidth, destHeight;
|
|
|
|
String selector;
|
|
|
|
|
2017-02-18 22:05:01 +00:00
|
|
|
native static void CallHandler(voidptr hnd);
|
|
|
|
|
|
|
|
|
2017-02-18 22:18:55 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-04-14 21:28:54 +00:00
|
|
|
virtual void Init(Menu parent, String message, int messagemode, bool playsound = false, Name cmd = 'None', voidptr native_handler = null)
|
2017-02-18 22:18:55 +00:00
|
|
|
{
|
2017-02-18 22:39:02 +00:00
|
|
|
Super.Init(parent);
|
|
|
|
mAction = cmd;
|
|
|
|
messageSelection = 0;
|
|
|
|
mMouseLeft = 140;
|
|
|
|
mMouseY = 0x80000000;
|
2019-04-23 06:46:35 +00:00
|
|
|
textFont = null;
|
|
|
|
|
|
|
|
if (!generic_ui)
|
|
|
|
{
|
2019-06-07 08:49:01 +00:00
|
|
|
if (SmallFont && SmallFont.CanPrint(message) && SmallFont.CanPrint("$TXT_YES") && SmallFont.CanPrint("$TXT_NO")) textFont = SmallFont;
|
|
|
|
else if (OriginalSmallFont && OriginalSmallFont.CanPrint(message) && OriginalSmallFont.CanPrint("$TXT_YES") && OriginalSmallFont.CanPrint("$TXT_NO")) textFont = OriginalSmallFont;
|
2019-04-23 06:46:35 +00:00
|
|
|
}
|
2019-04-09 23:33:02 +00:00
|
|
|
|
2019-04-23 06:46:35 +00:00
|
|
|
if (!textFont)
|
2019-04-09 23:33:02 +00:00
|
|
|
{
|
|
|
|
arrowFont = textFont = NewSmallFont;
|
|
|
|
int factor = (CleanXfac+1) / 2;
|
|
|
|
destWidth = screen.GetWidth() / factor;
|
|
|
|
destHeight = screen.GetHeight() / factor;
|
|
|
|
selector = "â–¶";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arrowFont = ConFont;
|
|
|
|
destWidth = CleanWidth;
|
|
|
|
destHeight = CleanHeight;
|
|
|
|
selector = "\xd";
|
|
|
|
}
|
|
|
|
|
|
|
|
int mr1 = destWidth/2 + 10 + textFont.StringWidth(Stringtable.Localize("$TXT_YES"));
|
|
|
|
int mr2 = destWidth/2 + 10 + textFont.StringWidth(Stringtable.Localize("$TXT_NO"));
|
2017-02-18 22:39:02 +00:00
|
|
|
mMouseRight = MAX(mr1, mr2);
|
|
|
|
mParentMenu = parent;
|
2019-04-11 22:20:42 +00:00
|
|
|
mMessage = textFont.BreakLines(Stringtable.Localize(message), generic_ui? 600 : 300);
|
2017-02-18 22:39:02 +00:00
|
|
|
mMessageMode = messagemode;
|
|
|
|
if (playsound)
|
|
|
|
{
|
|
|
|
MenuSound ("menu/prompt");
|
|
|
|
}
|
|
|
|
Handler = native_handler;
|
2017-02-18 22:18:55 +00:00
|
|
|
}
|
2017-02-18 22:39:02 +00:00
|
|
|
|
2017-02-18 22:18:55 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
override void Drawer ()
|
|
|
|
{
|
|
|
|
int i, y;
|
2019-04-09 23:33:02 +00:00
|
|
|
int fontheight = textFont.GetHeight();
|
2017-02-18 22:18:55 +00:00
|
|
|
|
2019-04-09 23:33:02 +00:00
|
|
|
y = destHeight / 2;
|
2017-02-18 22:18:55 +00:00
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
int c = mMessage.Count();
|
2019-04-09 23:33:02 +00:00
|
|
|
y -= c * fontHeight / 2;
|
2017-02-18 22:18:55 +00:00
|
|
|
|
2017-02-18 22:39:02 +00:00
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
{
|
2019-04-09 23:33:02 +00:00
|
|
|
screen.DrawText (textFont, Font.CR_UNTRANSLATED, destWidth/2 - mMessage.StringWidth(i)/2, y, mMessage.StringAt(i), DTA_VirtualWidth, destWidth, DTA_VirtualHeight, destHeight, DTA_KeepRatio, true);
|
2017-02-18 22:39:02 +00:00
|
|
|
y += fontheight;
|
2017-02-18 22:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mMessageMode == 0)
|
|
|
|
{
|
|
|
|
y += fontheight;
|
|
|
|
mMouseY = y;
|
2019-04-09 23:33:02 +00:00
|
|
|
screen.DrawText(textFont, messageSelection == 0? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, destWidth / 2, y, Stringtable.Localize("$TXT_YES"), DTA_VirtualWidth, destWidth, DTA_VirtualHeight, destHeight, DTA_KeepRatio, true);
|
|
|
|
screen.DrawText(textFont, messageSelection == 1? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, destWidth / 2, y + fontheight, Stringtable.Localize("$TXT_NO"), DTA_VirtualWidth, destWidth, DTA_VirtualHeight, destHeight, DTA_KeepRatio, true);
|
2017-02-18 22:18:55 +00:00
|
|
|
|
|
|
|
if (messageSelection >= 0)
|
|
|
|
{
|
|
|
|
if ((MenuTime() % 8) < 6)
|
|
|
|
{
|
2019-04-09 23:33:02 +00:00
|
|
|
screen.DrawText(arrowFont, OptionMenuSettings.mFontColorSelection,
|
|
|
|
destWidth/2 - 11, y + fontheight * messageSelection, selector, DTA_VirtualWidth, destWidth, DTA_VirtualHeight, destHeight, DTA_KeepRatio, true);
|
2017-02-18 22:18:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-18 22:05:01 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
protected void CloseSound()
|
|
|
|
{
|
|
|
|
MenuSound (GetCurrentMenu() != NULL? "menu/backup" : "menu/dismiss");
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
virtual void HandleResult(bool res)
|
|
|
|
{
|
|
|
|
if (Handler != null)
|
|
|
|
{
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
CallHandler(Handler);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
CloseSound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mParentMenu != NULL)
|
|
|
|
{
|
|
|
|
if (mMessageMode == 0)
|
|
|
|
{
|
|
|
|
if (mAction == 'None')
|
|
|
|
{
|
|
|
|
mParentMenu.MenuEvent(res? MKEY_MBYes : MKEY_MBNo, false);
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
if (res) SetMenu(mAction, -1);
|
|
|
|
}
|
|
|
|
CloseSound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-03-06 21:27:51 +00:00
|
|
|
override bool OnUIEvent(UIEvent ev)
|
2017-02-18 22:05:01 +00:00
|
|
|
{
|
2017-03-06 21:27:51 +00:00
|
|
|
if (ev.type == UIEvent.Type_KeyDown)
|
2017-02-18 22:05:01 +00:00
|
|
|
{
|
|
|
|
if (mMessageMode == 0)
|
|
|
|
{
|
|
|
|
// tolower
|
2017-03-06 21:27:51 +00:00
|
|
|
int ch = ev.KeyChar;
|
2017-02-18 22:05:01 +00:00
|
|
|
ch = ch >= 65 && ch <91? ch + 32 : ch;
|
|
|
|
|
2017-02-19 16:30:02 +00:00
|
|
|
if (ch == 110 /*'n'*/ || ch == 32)
|
2017-02-18 22:05:01 +00:00
|
|
|
{
|
|
|
|
HandleResult(false);
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-19 16:30:02 +00:00
|
|
|
else if (ch == 121 /*'y'*/)
|
2017-02-18 22:05:01 +00:00
|
|
|
{
|
|
|
|
HandleResult(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-06 21:27:51 +00:00
|
|
|
return Super.OnUIEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool OnInputEvent(InputEvent ev)
|
|
|
|
{
|
|
|
|
if (ev.type == InputEvent.Type_KeyDown)
|
2017-02-18 22:05:01 +00:00
|
|
|
{
|
|
|
|
Close();
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-06 21:27:51 +00:00
|
|
|
return Super.OnInputEvent(ev);
|
2017-02-18 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
override bool MenuEvent(int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
if (mMessageMode == 0)
|
|
|
|
{
|
|
|
|
if (mkey == MKEY_Up || mkey == MKEY_Down)
|
|
|
|
{
|
|
|
|
MenuSound("menu/cursor");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
override bool MouseEvent(int type, int x, int y)
|
|
|
|
{
|
|
|
|
if (mMessageMode == 1)
|
|
|
|
{
|
|
|
|
if (type == MOUSE_Click)
|
|
|
|
{
|
|
|
|
return MenuEvent(MKEY_Enter, true);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int sel = -1;
|
2019-04-09 23:33:02 +00:00
|
|
|
int fh = textFont.GetHeight() + 1;
|
2017-02-18 22:05:01 +00:00
|
|
|
|
|
|
|
// convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture
|
2019-04-09 23:33:02 +00:00
|
|
|
x = x * destWidth / screen.GetWidth();
|
|
|
|
y = y * destHeight / screen.GetHeight();
|
2017-02-18 22:05:01 +00:00
|
|
|
|
|
|
|
if (x >= mMouseLeft && x <= mMouseRight && y >= mMouseY && y < mMouseY + 2 * fh)
|
|
|
|
{
|
|
|
|
sel = y >= mMouseY + fh;
|
|
|
|
}
|
|
|
|
if (sel != -1 && sel != messageSelection)
|
|
|
|
{
|
2019-12-16 22:52:39 +00:00
|
|
|
//S_Sound (CHAN_VOICE, CHANF_UI, "menu/cursor", snd_menuvolume, ATTN_NONE);
|
2017-02-18 22:05:01 +00:00
|
|
|
}
|
|
|
|
messageSelection = sel;
|
|
|
|
if (type == MOUSE_Release)
|
|
|
|
{
|
|
|
|
return MenuEvent(MKEY_Enter, true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|