1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 08:39:45 +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;
virtual void staticMessageBox(std::string_view message) = 0;
virtual void removeStaticMessageBox() = 0;
virtual void interactiveMessageBox(
std::string_view message, const std::vector<std::string>& buttons = {}, bool block = false)
virtual void interactiveMessageBox(std::string_view message, const std::vector<std::string>& buttons = {},
bool block = false, int defaultFocus = -1)
= 0;
/// 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(
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)
{
@ -134,7 +134,8 @@ namespace MWGui
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;
return true;
@ -215,12 +216,13 @@ namespace MWGui
}
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()
? "openmw_interactive_messagebox_notransp.layout"
: "openmw_interactive_messagebox.layout")
, mMessageBoxManager(parMessageBoxManager)
, mButtonPressed(-1)
, mDefaultFocus(defaultFocus)
, mImmediate(immediate)
{
int textPadding = 10; // padding between text-widget and main-widget
@ -378,6 +380,9 @@ namespace MWGui
MyGUI::Widget* InteractiveMessageBox::getDefaultKeyFocus()
{
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 (const std::string& keyword : keywords)

View file

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

View file

@ -744,9 +744,9 @@ namespace MWGui
}
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();
if (block)

View file

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

View file

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