1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-27 19:11:34 +00:00

Allow to set default focus for interactive messagebox

This commit is contained in:
Andrei Kortunov 2023-11-18 17:57:15 +04:00
parent ff418f16f2
commit 9bbb89e268
6 changed files with 21 additions and 14 deletions

View file

@ -254,8 +254,8 @@ namespace MWBase
= 0; = 0;
virtual void staticMessageBox(std::string_view message) = 0; virtual void staticMessageBox(std::string_view message) = 0;
virtual void removeStaticMessageBox() = 0; virtual void removeStaticMessageBox() = 0;
virtual void interactiveMessageBox( virtual void interactiveMessageBox(std::string_view message, const std::vector<std::string>& buttons = {},
std::string_view message, const std::vector<std::string>& buttons = {}, bool block = false) bool block = false, int defaultFocus = -1)
= 0; = 0;
/// returns the index of the pressed button or -1 if no button was pressed /// returns the index of the pressed button or -1 if no button was pressed

View file

@ -126,7 +126,7 @@ namespace MWGui
} }
bool MessageBoxManager::createInteractiveMessageBox( bool MessageBoxManager::createInteractiveMessageBox(
std::string_view message, const std::vector<std::string>& buttons, bool immediate) std::string_view message, const std::vector<std::string>& buttons, bool immediate, int defaultFocus)
{ {
if (mInterMessageBoxe != nullptr) if (mInterMessageBoxe != nullptr)
{ {
@ -134,7 +134,8 @@ namespace MWGui
mInterMessageBoxe->setVisible(false); mInterMessageBoxe->setVisible(false);
} }
mInterMessageBoxe = std::make_unique<InteractiveMessageBox>(*this, std::string{ message }, buttons, immediate); mInterMessageBoxe
= std::make_unique<InteractiveMessageBox>(*this, std::string{ message }, buttons, immediate, defaultFocus);
mLastButtonPressed = -1; mLastButtonPressed = -1;
return true; return true;
@ -215,12 +216,13 @@ namespace MWGui
} }
InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message, InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message,
const std::vector<std::string>& buttons, bool immediate) const std::vector<std::string>& buttons, bool immediate, int defaultFocus)
: 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)
, mDefaultFocus(defaultFocus)
, mImmediate(immediate) , mImmediate(immediate)
{ {
int textPadding = 10; // padding between text-widget and main-widget int textPadding = 10; // padding between text-widget and main-widget
@ -378,6 +380,9 @@ namespace MWGui
MyGUI::Widget* InteractiveMessageBox::getDefaultKeyFocus() MyGUI::Widget* InteractiveMessageBox::getDefaultKeyFocus()
{ {
std::vector<std::string> keywords{ "sOk", "sYes" }; std::vector<std::string> keywords{ "sOk", "sYes" };
if (mDefaultFocus >= 0 && mDefaultFocus < static_cast<int>(mButtons.size()))
return mButtons[mDefaultFocus];
for (MyGUI::Button* button : mButtons) for (MyGUI::Button* button : mButtons)
{ {
for (const std::string& keyword : keywords) for (const std::string& keyword : keywords)

View file

@ -25,8 +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( bool createInteractiveMessageBox(std::string_view message, const std::vector<std::string>& buttons,
std::string_view message, const std::vector<std::string>& buttons, bool immediate = false); bool immediate = false, int defaultFocus = -1);
bool isInteractiveMessageBox(); bool isInteractiveMessageBox();
int getMessagesCount(); int getMessagesCount();
@ -93,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, bool immediate); const std::vector<std::string>& buttons, bool immediate, int defaultFocus);
void mousePressed(MyGUI::Widget* _widget); void mousePressed(MyGUI::Widget* _widget);
int readPressedButton(); int readPressedButton();
@ -112,6 +112,7 @@ namespace MWGui
std::vector<MyGUI::Button*> mButtons; std::vector<MyGUI::Button*> mButtons;
int mButtonPressed; int mButtonPressed;
int mDefaultFocus;
bool mImmediate; bool mImmediate;
}; };

View file

@ -744,9 +744,9 @@ 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, int defaultFocus)
{ {
mMessageBoxManager->createInteractiveMessageBox(message, buttons, block); mMessageBoxManager->createInteractiveMessageBox(message, buttons, block, defaultFocus);
updateVisible(); updateVisible();
if (block) if (block)

View file

@ -268,8 +268,8 @@ namespace MWGui
enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) override; enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) override;
void staticMessageBox(std::string_view message) override; void staticMessageBox(std::string_view message) override;
void removeStaticMessageBox() override; void removeStaticMessageBox() override;
void interactiveMessageBox( void interactiveMessageBox(std::string_view message, const std::vector<std::string>& buttons = {},
std::string_view message, const std::vector<std::string>& buttons = {}, bool block = false) override; bool block = false, int defaultFocus = -1) override;
int readPressedButton() override; ///< returns the index of the pressed button or -1 if no button was pressed int readPressedButton() override; ///< returns the index of the pressed button or -1 if no button was pressed
///< (->MessageBoxmanager->InteractiveMessageBox) ///< (->MessageBoxmanager->InteractiveMessageBox)

View file

@ -714,11 +714,12 @@ bool MWState::StateManager::confirmLoading(const std::vector<std::string_view>&
message message
+= l10n->formatMessage("MissingContentFilesListCopy", { "files" }, { static_cast<int>(missingFiles.size()) }); += l10n->formatMessage("MissingContentFilesListCopy", { "files" }, { static_cast<int>(missingFiles.size()) });
int selectedButton = -1;
while (true) while (true)
{ {
auto windowManager = MWBase::Environment::get().getWindowManager(); auto windowManager = MWBase::Environment::get().getWindowManager();
windowManager->interactiveMessageBox(message, buttons, true); windowManager->interactiveMessageBox(message, buttons, true, selectedButton);
int selectedButton = windowManager->readPressedButton(); selectedButton = windowManager->readPressedButton();
if (selectedButton == 0) if (selectedButton == 0)
break; break;