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