Simplified the back button logic in GuiMsgBox

This commit is contained in:
Leon Styhre 2023-09-10 14:02:48 +02:00
parent 27cd86a2aa
commit a9d99a04c6
3 changed files with 6 additions and 31 deletions

View file

@ -319,10 +319,10 @@ void GuiScraperMulti::finish()
<< mTotalSkipped << " GAME" << ((mTotalSkipped > 1) ? "S" : "") << " SKIPPED";
}
mWindow->pushGui(new GuiMsgBox(getHelpStyle(), ss.str(), "OK", [&] {
mIsProcessing = false;
delete this;
}));
mWindow->pushGui(new GuiMsgBox(getHelpStyle(), ss.str()));
mIsProcessing = false;
delete this;
}
std::vector<HelpPrompt> GuiScraperMulti::getHelpPrompts()

View file

@ -60,20 +60,6 @@ GuiMsgBox::GuiMsgBox(const HelpStyle& helpstyle,
mButtons.push_back(std::make_shared<ButtonComponent>(
name3, name3, std::bind(&GuiMsgBox::deleteMeAndCall, this, func3)));
// Set accelerator automatically (button to press when "B" is pressed).
if (mButtons.size() == 1) {
mAcceleratorFunc = mButtons.front()->getPressedFunc();
}
else {
for (auto it = mButtons.cbegin(); it != mButtons.cend(); ++it) {
if (Utils::String::toUpper((*it)->getText()) == "OK" ||
Utils::String::toUpper((*it)->getText()) == "NO") {
mAcceleratorFunc = (*it)->getPressedFunc();
break;
}
}
}
// Put the buttons into a ComponentGrid.
mButtonGrid = MenuComponent::makeButtonGrid(mButtons);
mGrid.setEntry(mButtonGrid, glm::ivec2 {0, 1}, true, false, glm::ivec2 {1, 1},
@ -146,21 +132,11 @@ void GuiMsgBox::changeText(const std::string& newText)
bool GuiMsgBox::input(InputConfig* config, Input input)
{
// Special case for when GuiMsgBox comes up to report errors before
// anything has been configured.
if (config->getDeviceId() == DEVICE_KEYBOARD && !config->isConfigured() && input.value &&
(input.id == SDLK_RETURN || input.id == SDLK_ESCAPE || input.id == SDLK_SPACE)) {
mAcceleratorFunc();
if (!mDisableBackButton && config->isMappedTo("b", input) && input.value != 0) {
delete this;
return true;
}
if (!mDisableBackButton) {
if (mAcceleratorFunc && config->isMappedTo("b", input) && input.value != 0) {
mAcceleratorFunc();
return true;
}
}
return GuiComponent::input(config, input);
}

View file

@ -51,7 +51,6 @@ private:
std::shared_ptr<TextComponent> mMsg;
std::vector<std::shared_ptr<ButtonComponent>> mButtons;
std::shared_ptr<ComponentGrid> mButtonGrid;
std::function<void()> mAcceleratorFunc;
bool mDisableBackButton;
bool mDeleteOnButtonPress;
float mMaxWidthMultiplier;