2015-01-10 01:50:43 +00:00
|
|
|
#include "messagebox.hpp"
|
|
|
|
|
|
|
|
#include <MyGUI_LanguageManager.h>
|
|
|
|
#include <MyGUI_EditBox.h>
|
|
|
|
#include <MyGUI_RenderManager.h>
|
|
|
|
#include <MyGUI_Button.h>
|
|
|
|
|
2018-08-14 19:05:43 +00:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2013-02-10 14:58:46 +00:00
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
2013-02-26 15:37:59 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2013-03-30 14:51:07 +00:00
|
|
|
#include "../mwbase/inputmanager.hpp"
|
2015-01-10 02:56:06 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2011-06-14 14:41:30 +00:00
|
|
|
|
2015-01-20 16:07:26 +00:00
|
|
|
#undef MessageBox
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
namespace MWGui
|
2011-06-14 20:11:36 +00:00
|
|
|
{
|
2011-06-15 20:53:05 +00:00
|
|
|
|
2014-01-10 21:27:31 +00:00
|
|
|
MessageBoxManager::MessageBoxManager (float timePerChar)
|
2011-06-15 20:53:05 +00:00
|
|
|
{
|
2018-10-09 06:21:12 +00:00
|
|
|
mInterMessageBoxe = nullptr;
|
|
|
|
mStaticMessageBox = nullptr;
|
2013-10-14 09:15:23 +00:00
|
|
|
mLastButtonPressed = -1;
|
2014-01-10 21:27:31 +00:00
|
|
|
mMessageBoxSpeed = timePerChar;
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2012-05-16 13:00:20 +00:00
|
|
|
|
2013-12-30 22:08:53 +00:00
|
|
|
MessageBoxManager::~MessageBoxManager ()
|
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
for (MessageBox* messageBox : mMessageBoxes)
|
2013-12-30 22:08:53 +00:00
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
delete messageBox;
|
2013-12-30 22:08:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-28 07:44:14 +00:00
|
|
|
int MessageBoxManager::getMessagesCount()
|
|
|
|
{
|
|
|
|
return mMessageBoxes.size();
|
|
|
|
}
|
|
|
|
|
2014-06-14 19:52:54 +00:00
|
|
|
void MessageBoxManager::clear()
|
|
|
|
{
|
2017-09-27 20:18:47 +00:00
|
|
|
if (mInterMessageBoxe)
|
|
|
|
{
|
|
|
|
mInterMessageBoxe->setVisible(false);
|
|
|
|
|
|
|
|
delete mInterMessageBoxe;
|
2018-10-09 06:21:12 +00:00
|
|
|
mInterMessageBoxe = nullptr;
|
2017-09-27 20:18:47 +00:00
|
|
|
}
|
2014-06-14 19:52:54 +00:00
|
|
|
|
2019-03-02 09:27:59 +00:00
|
|
|
for (MessageBox* messageBox : mMessageBoxes)
|
2014-06-14 19:52:54 +00:00
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
if (messageBox == mStaticMessageBox)
|
2018-10-09 06:21:12 +00:00
|
|
|
mStaticMessageBox = nullptr;
|
2019-03-02 09:27:59 +00:00
|
|
|
delete messageBox;
|
2014-06-14 19:52:54 +00:00
|
|
|
}
|
|
|
|
mMessageBoxes.clear();
|
|
|
|
|
|
|
|
mLastButtonPressed = -1;
|
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void MessageBoxManager::onFrame (float frameDuration)
|
|
|
|
{
|
2013-11-20 04:49:05 +00:00
|
|
|
std::vector<MessageBox*>::iterator it;
|
|
|
|
for(it = mMessageBoxes.begin(); it != mMessageBoxes.end();)
|
2011-06-15 20:53:05 +00:00
|
|
|
{
|
2013-11-20 04:49:05 +00:00
|
|
|
(*it)->mCurrentTime += frameDuration;
|
|
|
|
if((*it)->mCurrentTime >= (*it)->mMaxTime && *it != mStaticMessageBox)
|
2011-06-16 15:11:50 +00:00
|
|
|
{
|
2013-11-20 04:49:05 +00:00
|
|
|
delete *it;
|
|
|
|
it = mMessageBoxes.erase(it);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
|
|
|
else
|
2013-07-31 16:46:32 +00:00
|
|
|
++it;
|
2013-11-20 04:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float height = 0;
|
|
|
|
it = mMessageBoxes.begin();
|
|
|
|
while(it != mMessageBoxes.end())
|
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
(*it)->update(static_cast<int>(height));
|
|
|
|
height += (*it)->getHeight();
|
|
|
|
++it;
|
2011-06-16 11:02:49 +00:00
|
|
|
}
|
2013-04-17 22:56:48 +00:00
|
|
|
|
2018-10-09 06:21:12 +00:00
|
|
|
if(mInterMessageBoxe != nullptr && mInterMessageBoxe->mMarkedToDelete) {
|
2013-10-14 09:15:23 +00:00
|
|
|
mLastButtonPressed = mInterMessageBoxe->readPressedButton();
|
2017-09-22 18:46:08 +00:00
|
|
|
mInterMessageBoxe->setVisible(false);
|
2013-04-17 22:56:48 +00:00
|
|
|
delete mInterMessageBoxe;
|
2018-10-09 06:21:12 +00:00
|
|
|
mInterMessageBoxe = nullptr;
|
2013-04-17 22:56:48 +00:00
|
|
|
MWBase::Environment::get().getInputManager()->changeInputMode(
|
|
|
|
MWBase::Environment::get().getWindowManager()->isGuiMode());
|
2011-06-15 20:53:05 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-05-03 10:44:27 +00:00
|
|
|
void MessageBoxManager::createMessageBox (const std::string& message, bool stat)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
MessageBox *box = new MessageBox(*this, message);
|
2013-11-20 04:49:05 +00:00
|
|
|
box->mCurrentTime = 0;
|
2014-01-09 21:17:51 +00:00
|
|
|
std::string realMessage = MyGUI::LanguageManager::getInstance().replaceTags(message);
|
|
|
|
box->mMaxTime = realMessage.length()*mMessageBoxSpeed;
|
2011-06-14 20:11:36 +00:00
|
|
|
|
2013-05-03 10:44:27 +00:00
|
|
|
if(stat)
|
|
|
|
mStaticMessageBox = box;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mMessageBoxes.push_back(box);
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
if(mMessageBoxes.size() > 3) {
|
|
|
|
delete *mMessageBoxes.begin();
|
|
|
|
mMessageBoxes.erase(mMessageBoxes.begin());
|
|
|
|
}
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
int height = 0;
|
2019-03-02 09:27:59 +00:00
|
|
|
for (MessageBox* messageBox : mMessageBoxes)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
messageBox->update(height);
|
|
|
|
height += messageBox->getHeight();
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2011-06-16 15:11:50 +00:00
|
|
|
}
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-05-03 10:44:27 +00:00
|
|
|
void MessageBoxManager::removeStaticMessageBox ()
|
|
|
|
{
|
|
|
|
removeMessageBox(mStaticMessageBox);
|
2018-10-09 06:21:12 +00:00
|
|
|
mStaticMessageBox = nullptr;
|
2013-05-03 10:44:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons)
|
2011-06-15 20:53:05 +00:00
|
|
|
{
|
2018-10-09 06:21:12 +00:00
|
|
|
if (mInterMessageBoxe != nullptr)
|
2015-11-28 18:14:47 +00:00
|
|
|
{
|
2018-08-14 19:05:43 +00:00
|
|
|
Log(Debug::Warning) << "Warning: replacing an interactive message box that was not answered yet";
|
2017-10-23 21:31:59 +00:00
|
|
|
mInterMessageBoxe->setVisible(false);
|
2015-11-28 18:14:47 +00:00
|
|
|
delete mInterMessageBoxe;
|
2018-10-09 06:21:12 +00:00
|
|
|
mInterMessageBoxe = nullptr;
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mInterMessageBoxe = new InteractiveMessageBox(*this, message, buttons);
|
2013-10-14 09:15:23 +00:00
|
|
|
mLastButtonPressed = -1;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-06-19 17:10:44 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
bool MessageBoxManager::isInteractiveMessageBox ()
|
|
|
|
{
|
2018-10-09 06:21:12 +00:00
|
|
|
return mInterMessageBoxe != nullptr;
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2011-06-14 16:29:55 +00:00
|
|
|
|
2011-06-15 20:53:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
bool MessageBoxManager::removeMessageBox (MessageBox *msgbox)
|
2011-06-16 11:02:49 +00:00
|
|
|
{
|
2013-04-17 22:56:48 +00:00
|
|
|
std::vector<MessageBox*>::iterator it;
|
|
|
|
for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it)
|
2011-06-16 11:02:49 +00:00
|
|
|
{
|
2013-04-17 22:56:48 +00:00
|
|
|
if((*it) == msgbox)
|
|
|
|
{
|
|
|
|
delete (*it);
|
|
|
|
mMessageBoxes.erase(it);
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-16 11:02:49 +00:00
|
|
|
}
|
2013-04-17 22:56:48 +00:00
|
|
|
return false;
|
2011-06-16 11:02:49 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 22:58:55 +00:00
|
|
|
int MessageBoxManager::readPressedButton (bool reset)
|
2011-07-12 18:05:04 +00:00
|
|
|
{
|
2013-10-14 09:15:23 +00:00
|
|
|
int pressed = mLastButtonPressed;
|
2015-01-10 22:58:55 +00:00
|
|
|
if (reset)
|
|
|
|
mLastButtonPressed = -1;
|
2013-10-14 09:15:23 +00:00
|
|
|
return pressed;
|
2011-07-12 18:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-15 20:53:05 +00:00
|
|
|
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message)
|
|
|
|
: Layout("openmw_messagebox.layout")
|
2013-11-20 04:49:05 +00:00
|
|
|
, mCurrentTime(0)
|
|
|
|
, mMaxTime(0)
|
2015-05-01 00:24:27 +00:00
|
|
|
, mMessageBoxManager(parMessageBoxManager)
|
|
|
|
, mMessage(message)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
// defines
|
2014-10-01 17:53:50 +00:00
|
|
|
mBottomPadding = 48;
|
|
|
|
mNextBoxPadding = 4;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mMessageWidget, "message");
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mMessageWidget->setCaptionWithReplacing(mMessage);
|
|
|
|
}
|
2011-06-15 11:58:57 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void MessageBox::update (int height)
|
|
|
|
{
|
|
|
|
MyGUI::IntSize gameWindowSize = MyGUI::RenderManager::getInstance().getViewSize();
|
2013-12-07 13:14:05 +00:00
|
|
|
MyGUI::IntPoint pos;
|
|
|
|
pos.left = (gameWindowSize.width - mMainWidget->getWidth())/2;
|
|
|
|
pos.top = (gameWindowSize.height - mMainWidget->getHeight() - height - mBottomPadding);
|
2013-04-17 22:56:48 +00:00
|
|
|
|
2013-12-07 13:14:05 +00:00
|
|
|
mMainWidget->setPosition(pos);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2011-06-15 11:58:57 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
int MessageBox::getHeight ()
|
|
|
|
{
|
2014-10-01 17:53:50 +00:00
|
|
|
return mMainWidget->getHeight()+mNextBoxPadding;
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2011-06-18 13:50:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector<std::string>& buttons)
|
2017-08-08 16:36:50 +00:00
|
|
|
: WindowModal(MWBase::Environment::get().getWindowManager()->isGuiMode() ? "openmw_interactive_messagebox_notransp.layout" : "openmw_interactive_messagebox.layout")
|
2013-04-17 22:56:48 +00:00
|
|
|
, mMessageBoxManager(parMessageBoxManager)
|
|
|
|
, mButtonPressed(-1)
|
|
|
|
{
|
|
|
|
int textPadding = 10; // padding between text-widget and main-widget
|
2014-08-16 15:31:36 +00:00
|
|
|
int textButtonPadding = 10; // padding between the text-widget und the button-widget
|
2013-04-17 22:56:48 +00:00
|
|
|
int buttonLeftPadding = 10; // padding between the buttons if horizontal
|
2014-08-16 15:31:36 +00:00
|
|
|
int buttonTopPadding = 10; // ^-- if vertical
|
2017-09-18 19:03:47 +00:00
|
|
|
int buttonLabelLeftPadding = 12; // padding between button label and button itself, from left
|
|
|
|
int buttonLabelTopPadding = 4; // padding between button label and button itself, from top
|
2013-04-17 22:56:48 +00:00
|
|
|
int buttonMainPadding = 10; // padding between buttons and bottom of the main widget
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mMarkedToDelete = false;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mMessageWidget, "message");
|
|
|
|
getWidget(mButtonsWidget, "buttons");
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2014-09-20 06:57:16 +00:00
|
|
|
mMessageWidget->setSize(400, mMessageWidget->getHeight());
|
2013-04-17 22:56:48 +00:00
|
|
|
mMessageWidget->setCaptionWithReplacing(message);
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MyGUI::IntSize textSize = mMessageWidget->getTextSize();
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MyGUI::IntSize gameWindowSize = MyGUI::RenderManager::getInstance().getViewSize();
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
int biggestButtonWidth = 0;
|
|
|
|
int buttonsWidth = 0;
|
2014-08-16 15:31:36 +00:00
|
|
|
int buttonsHeight = 0;
|
2013-04-17 22:56:48 +00:00
|
|
|
int buttonHeight = 0;
|
|
|
|
MyGUI::IntCoord dummyCoord(0, 0, 0, 0);
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2019-03-02 09:27:59 +00:00
|
|
|
for(const std::string& buttonId : buttons)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
MyGUI::Button* button = mButtonsWidget->createWidget<MyGUI::Button>(
|
|
|
|
MyGUI::WidgetStyle::Child,
|
|
|
|
std::string("MW_Button"),
|
|
|
|
dummyCoord,
|
|
|
|
MyGUI::Align::Default);
|
2019-03-02 09:27:59 +00:00
|
|
|
button->setCaptionWithReplacing(buttonId);
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
button->eventMouseButtonClick += MyGUI::newDelegate(this, &InteractiveMessageBox::mousePressed);
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mButtons.push_back(button);
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2014-08-16 15:31:36 +00:00
|
|
|
if (buttonsWidth != 0)
|
|
|
|
buttonsWidth += buttonLeftPadding;
|
|
|
|
|
2017-09-18 19:03:47 +00:00
|
|
|
int buttonWidth = button->getTextSize().width + 2*buttonLabelLeftPadding;
|
2013-04-17 22:56:48 +00:00
|
|
|
buttonsWidth += buttonWidth;
|
2014-08-16 15:31:36 +00:00
|
|
|
|
2017-09-18 19:03:47 +00:00
|
|
|
buttonHeight = button->getTextSize().height + 2*buttonLabelTopPadding;
|
2014-08-16 15:31:36 +00:00
|
|
|
|
|
|
|
if (buttonsHeight != 0)
|
|
|
|
buttonsHeight += buttonTopPadding;
|
|
|
|
buttonsHeight += buttonHeight;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
if(buttonWidth > biggestButtonWidth)
|
|
|
|
{
|
|
|
|
biggestButtonWidth = buttonWidth;
|
|
|
|
}
|
2011-07-12 17:17:07 +00:00
|
|
|
}
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MyGUI::IntSize mainWidgetSize;
|
2014-08-16 15:31:36 +00:00
|
|
|
if(buttonsWidth < textSize.width)
|
2014-08-16 15:24:18 +00:00
|
|
|
{
|
|
|
|
// on one line
|
2014-08-16 15:31:36 +00:00
|
|
|
mainWidgetSize.width = textSize.width + 3*textPadding;
|
|
|
|
mainWidgetSize.height = textPadding + textSize.height + textButtonPadding + buttonHeight + buttonMainPadding;
|
|
|
|
|
|
|
|
MyGUI::IntSize realSize = mainWidgetSize +
|
|
|
|
// To account for borders
|
|
|
|
(mMainWidget->getSize() - mMainWidget->getClientWidget()->getSize());
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2014-08-16 15:24:18 +00:00
|
|
|
MyGUI::IntPoint absPos;
|
2014-08-16 15:31:36 +00:00
|
|
|
absPos.left = (gameWindowSize.width - realSize.width)/2;
|
|
|
|
absPos.top = (gameWindowSize.height - realSize.height)/2;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2014-08-16 15:24:18 +00:00
|
|
|
mMainWidget->setPosition(absPos);
|
2014-08-16 15:31:36 +00:00
|
|
|
mMainWidget->setSize(realSize);
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2014-08-16 15:24:18 +00:00
|
|
|
MyGUI::IntCoord messageWidgetCoord;
|
|
|
|
messageWidgetCoord.left = (mainWidgetSize.width - textSize.width)/2;
|
|
|
|
messageWidgetCoord.top = textPadding;
|
|
|
|
mMessageWidget->setCoord(messageWidgetCoord);
|
|
|
|
|
|
|
|
mMessageWidget->setSize(textSize);
|
|
|
|
|
|
|
|
MyGUI::IntCoord buttonCord;
|
|
|
|
MyGUI::IntSize buttonSize(0, buttonHeight);
|
2014-08-16 15:31:36 +00:00
|
|
|
int left = (mainWidgetSize.width - buttonsWidth)/2;
|
2014-08-16 15:24:18 +00:00
|
|
|
|
2019-03-02 09:27:59 +00:00
|
|
|
for(MyGUI::Button* button : mButtons)
|
2014-08-16 15:24:18 +00:00
|
|
|
{
|
|
|
|
buttonCord.left = left;
|
2014-08-16 15:31:36 +00:00
|
|
|
buttonCord.top = messageWidgetCoord.top + textSize.height + textButtonPadding;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2019-03-02 09:27:59 +00:00
|
|
|
buttonSize.width = button->getTextSize().width + 2*buttonLabelLeftPadding;
|
|
|
|
buttonSize.height = button->getTextSize().height + 2*buttonLabelTopPadding;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2019-03-02 09:27:59 +00:00
|
|
|
button->setCoord(buttonCord);
|
|
|
|
button->setSize(buttonSize);
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2014-08-16 15:24:18 +00:00
|
|
|
left += buttonSize.width + buttonLeftPadding;
|
|
|
|
}
|
2014-06-06 00:24:51 +00:00
|
|
|
}
|
2014-08-16 15:24:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// among each other
|
|
|
|
if(biggestButtonWidth > textSize.width) {
|
2014-08-16 15:31:36 +00:00
|
|
|
mainWidgetSize.width = biggestButtonWidth + buttonTopPadding*2;
|
2014-08-16 15:24:18 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mainWidgetSize.width = textSize.width + 3*textPadding;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyGUI::IntCoord buttonCord;
|
|
|
|
MyGUI::IntSize buttonSize(0, buttonHeight);
|
|
|
|
|
2014-08-16 15:31:36 +00:00
|
|
|
int top = textPadding + textSize.height + textButtonPadding;
|
2014-08-16 15:24:18 +00:00
|
|
|
|
2019-03-02 09:27:59 +00:00
|
|
|
for(MyGUI::Button* button : mButtons)
|
2014-08-16 15:24:18 +00:00
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
buttonSize.width = button->getTextSize().width + buttonLabelLeftPadding*2;
|
|
|
|
buttonSize.height = button->getTextSize().height + buttonLabelTopPadding*2;
|
2014-08-16 15:24:18 +00:00
|
|
|
|
|
|
|
buttonCord.top = top;
|
2014-08-16 15:31:36 +00:00
|
|
|
buttonCord.left = (mainWidgetSize.width - buttonSize.width)/2;
|
2012-03-20 09:15:22 +00:00
|
|
|
|
2019-03-02 09:27:59 +00:00
|
|
|
button->setCoord(buttonCord);
|
|
|
|
button->setSize(buttonSize);
|
2014-08-16 15:24:18 +00:00
|
|
|
|
2014-08-16 15:31:36 +00:00
|
|
|
top += buttonSize.height + buttonTopPadding;
|
2014-08-16 15:24:18 +00:00
|
|
|
}
|
2014-01-23 11:24:06 +00:00
|
|
|
|
2014-08-16 15:31:36 +00:00
|
|
|
mainWidgetSize.height = textPadding + textSize.height + textButtonPadding + buttonsHeight + buttonMainPadding;
|
|
|
|
mMainWidget->setSize(mainWidgetSize +
|
|
|
|
// To account for borders
|
|
|
|
(mMainWidget->getSize() - mMainWidget->getClientWidget()->getSize()));
|
2014-01-23 11:24:06 +00:00
|
|
|
|
2014-08-16 15:24:18 +00:00
|
|
|
MyGUI::IntPoint absPos;
|
|
|
|
absPos.left = (gameWindowSize.width - mainWidgetSize.width)/2;
|
|
|
|
absPos.top = (gameWindowSize.height - mainWidgetSize.height)/2;
|
2014-01-23 11:24:06 +00:00
|
|
|
|
2014-08-16 15:24:18 +00:00
|
|
|
mMainWidget->setPosition(absPos);
|
|
|
|
|
|
|
|
MyGUI::IntCoord messageWidgetCoord;
|
|
|
|
messageWidgetCoord.left = (mainWidgetSize.width - textSize.width)/2;
|
|
|
|
messageWidgetCoord.top = textPadding;
|
|
|
|
messageWidgetCoord.width = textSize.width;
|
|
|
|
messageWidgetCoord.height = textSize.height;
|
|
|
|
mMessageWidget->setCoord(messageWidgetCoord);
|
|
|
|
}
|
2013-04-17 22:56:48 +00:00
|
|
|
|
2018-01-14 00:27:53 +00:00
|
|
|
setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
MyGUI::Widget* InteractiveMessageBox::getDefaultKeyFocus()
|
|
|
|
{
|
2017-09-22 14:13:22 +00:00
|
|
|
std::vector<std::string> keywords { "sOk", "sYes" };
|
2019-03-02 09:27:59 +00:00
|
|
|
for(MyGUI::Button* button : mButtons)
|
2013-02-10 15:41:02 +00:00
|
|
|
{
|
2017-09-22 14:13:22 +00:00
|
|
|
for (const std::string& keyword : keywords)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
if(Misc::StringUtils::ciEqual(MyGUI::LanguageManager::getInstance().replaceTags("#{" + keyword + "}"), button->getCaption()))
|
2017-09-22 14:13:22 +00:00
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
return button;
|
2017-09-22 14:13:22 +00:00
|
|
|
}
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2013-02-10 15:41:02 +00:00
|
|
|
}
|
2018-10-09 06:21:12 +00:00
|
|
|
return nullptr;
|
2014-01-10 23:24:21 +00:00
|
|
|
}
|
2013-02-10 14:58:46 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void InteractiveMessageBox::mousePressed (MyGUI::Widget* pressed)
|
|
|
|
{
|
|
|
|
buttonActivated (pressed);
|
|
|
|
}
|
2013-02-10 14:58:46 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void InteractiveMessageBox::buttonActivated (MyGUI::Widget* pressed)
|
2011-07-12 18:05:04 +00:00
|
|
|
{
|
2013-04-17 22:56:48 +00:00
|
|
|
mMarkedToDelete = true;
|
|
|
|
int index = 0;
|
2019-03-02 09:27:59 +00:00
|
|
|
for(const MyGUI::Button* button : mButtons)
|
2011-07-12 18:05:04 +00:00
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
if(button == pressed)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
mButtonPressed = index;
|
|
|
|
mMessageBoxManager.onButtonPressed(mButtonPressed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
index++;
|
2011-07-12 18:05:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
int InteractiveMessageBox::readPressedButton ()
|
|
|
|
{
|
2013-10-14 09:15:23 +00:00
|
|
|
return mButtonPressed;
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
|
|
|
|
2011-07-12 18:05:04 +00:00
|
|
|
}
|