mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-25 08:36:52 +00:00
Do not wait one frame for blocking messageboxes
This commit is contained in:
parent
f88b99201a
commit
ff418f16f2
4 changed files with 39 additions and 9 deletions
|
@ -46,6 +46,20 @@ namespace MWGui
|
||||||
mLastButtonPressed = -1;
|
mLastButtonPressed = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessageBoxManager::resetInteractiveMessageBox()
|
||||||
|
{
|
||||||
|
if (mInterMessageBoxe)
|
||||||
|
{
|
||||||
|
mInterMessageBoxe->setVisible(false);
|
||||||
|
mInterMessageBoxe.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageBoxManager::setLastButtonPressed(int index)
|
||||||
|
{
|
||||||
|
mLastButtonPressed = index;
|
||||||
|
}
|
||||||
|
|
||||||
void MessageBoxManager::onFrame(float frameDuration)
|
void MessageBoxManager::onFrame(float frameDuration)
|
||||||
{
|
{
|
||||||
for (auto it = mMessageBoxes.begin(); it != mMessageBoxes.end();)
|
for (auto it = mMessageBoxes.begin(); it != mMessageBoxes.end();)
|
||||||
|
@ -112,7 +126,7 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageBoxManager::createInteractiveMessageBox(
|
bool MessageBoxManager::createInteractiveMessageBox(
|
||||||
std::string_view message, const std::vector<std::string>& buttons)
|
std::string_view message, const std::vector<std::string>& buttons, bool immediate)
|
||||||
{
|
{
|
||||||
if (mInterMessageBoxe != nullptr)
|
if (mInterMessageBoxe != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -120,7 +134,7 @@ namespace MWGui
|
||||||
mInterMessageBoxe->setVisible(false);
|
mInterMessageBoxe->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mInterMessageBoxe = std::make_unique<InteractiveMessageBox>(*this, std::string{ message }, buttons);
|
mInterMessageBoxe = std::make_unique<InteractiveMessageBox>(*this, std::string{ message }, buttons, immediate);
|
||||||
mLastButtonPressed = -1;
|
mLastButtonPressed = -1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -200,13 +214,14 @@ namespace MWGui
|
||||||
mMainWidget->setVisible(value);
|
mMainWidget->setVisible(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
InteractiveMessageBox::InteractiveMessageBox(
|
InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message,
|
||||||
MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector<std::string>& buttons)
|
const std::vector<std::string>& buttons, bool immediate)
|
||||||
: WindowModal(MWBase::Environment::get().getWindowManager()->isGuiMode()
|
: WindowModal(MWBase::Environment::get().getWindowManager()->isGuiMode()
|
||||||
? "openmw_interactive_messagebox_notransp.layout"
|
? "openmw_interactive_messagebox_notransp.layout"
|
||||||
: "openmw_interactive_messagebox.layout")
|
: "openmw_interactive_messagebox.layout")
|
||||||
, mMessageBoxManager(parMessageBoxManager)
|
, mMessageBoxManager(parMessageBoxManager)
|
||||||
, mButtonPressed(-1)
|
, mButtonPressed(-1)
|
||||||
|
, mImmediate(immediate)
|
||||||
{
|
{
|
||||||
int textPadding = 10; // padding between text-widget and main-widget
|
int textPadding = 10; // padding between text-widget and main-widget
|
||||||
int textButtonPadding = 10; // padding between the text-widget und the button-widget
|
int textButtonPadding = 10; // padding between the text-widget und the button-widget
|
||||||
|
@ -393,6 +408,12 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
mButtonPressed = index;
|
mButtonPressed = index;
|
||||||
mMessageBoxManager.onButtonPressed(mButtonPressed);
|
mMessageBoxManager.onButtonPressed(mButtonPressed);
|
||||||
|
if (!mImmediate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mMessageBoxManager.setLastButtonPressed(mButtonPressed);
|
||||||
|
MWBase::Environment::get().getInputManager()->changeInputMode(
|
||||||
|
MWBase::Environment::get().getWindowManager()->isGuiMode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
|
|
@ -25,7 +25,8 @@ namespace MWGui
|
||||||
void onFrame(float frameDuration);
|
void onFrame(float frameDuration);
|
||||||
void createMessageBox(std::string_view message, bool stat = false);
|
void createMessageBox(std::string_view message, bool stat = false);
|
||||||
void removeStaticMessageBox();
|
void removeStaticMessageBox();
|
||||||
bool createInteractiveMessageBox(std::string_view message, const std::vector<std::string>& buttons);
|
bool createInteractiveMessageBox(
|
||||||
|
std::string_view message, const std::vector<std::string>& buttons, bool immediate = false);
|
||||||
bool isInteractiveMessageBox();
|
bool isInteractiveMessageBox();
|
||||||
|
|
||||||
int getMessagesCount();
|
int getMessagesCount();
|
||||||
|
@ -40,6 +41,10 @@ namespace MWGui
|
||||||
/// @param reset Reset the pressed button to -1 after reading it.
|
/// @param reset Reset the pressed button to -1 after reading it.
|
||||||
int readPressedButton(bool reset = true);
|
int readPressedButton(bool reset = true);
|
||||||
|
|
||||||
|
void resetInteractiveMessageBox();
|
||||||
|
|
||||||
|
void setLastButtonPressed(int index);
|
||||||
|
|
||||||
typedef MyGUI::delegates::MultiDelegate<int> EventHandle_Int;
|
typedef MyGUI::delegates::MultiDelegate<int> EventHandle_Int;
|
||||||
|
|
||||||
// Note: this delegate unassigns itself after it was fired, i.e. works once.
|
// Note: this delegate unassigns itself after it was fired, i.e. works once.
|
||||||
|
@ -88,7 +93,7 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message,
|
InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message,
|
||||||
const std::vector<std::string>& buttons);
|
const std::vector<std::string>& buttons, bool immediate);
|
||||||
void mousePressed(MyGUI::Widget* _widget);
|
void mousePressed(MyGUI::Widget* _widget);
|
||||||
int readPressedButton();
|
int readPressedButton();
|
||||||
|
|
||||||
|
@ -107,6 +112,7 @@ namespace MWGui
|
||||||
std::vector<MyGUI::Button*> mButtons;
|
std::vector<MyGUI::Button*> mButtons;
|
||||||
|
|
||||||
int mButtonPressed;
|
int mButtonPressed;
|
||||||
|
bool mImmediate;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -746,7 +746,7 @@ namespace MWGui
|
||||||
void WindowManager::interactiveMessageBox(
|
void WindowManager::interactiveMessageBox(
|
||||||
std::string_view message, const std::vector<std::string>& buttons, bool block)
|
std::string_view message, const std::vector<std::string>& buttons, bool block)
|
||||||
{
|
{
|
||||||
mMessageBoxManager->createInteractiveMessageBox(message, buttons);
|
mMessageBoxManager->createInteractiveMessageBox(message, buttons, block);
|
||||||
updateVisible();
|
updateVisible();
|
||||||
|
|
||||||
if (block)
|
if (block)
|
||||||
|
@ -779,6 +779,8 @@ namespace MWGui
|
||||||
|
|
||||||
frameRateLimiter.limit();
|
frameRateLimiter.limit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMessageBoxManager->resetInteractiveMessageBox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -716,8 +716,9 @@ bool MWState::StateManager::confirmLoading(const std::vector<std::string_view>&
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWindowManager()->interactiveMessageBox(message, buttons, true);
|
auto windowManager = MWBase::Environment::get().getWindowManager();
|
||||||
int selectedButton = MWBase::Environment::get().getWindowManager()->readPressedButton();
|
windowManager->interactiveMessageBox(message, buttons, true);
|
||||||
|
int selectedButton = windowManager->readPressedButton();
|
||||||
if (selectedButton == 0)
|
if (selectedButton == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue