Added support for defining an explicit back button function for GuiMsgBox

This commit is contained in:
Leon Styhre 2023-09-17 11:47:58 +02:00
parent a122774d46
commit 2adde87050
12 changed files with 59 additions and 43 deletions

View file

@ -177,7 +177,7 @@ GuiApplicationUpdater::GuiApplicationUpdater()
if (mDownloading) {
mWindow->pushGui(
new GuiMsgBox(getHelpStyle(), "DOWNLOAD ABORTED\nNO PACKAGE SAVED TO DISK", "OK",
nullptr, "", nullptr, "", nullptr, true, true,
nullptr, "", nullptr, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.70f :
0.45f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -185,7 +185,7 @@ GuiApplicationUpdater::GuiApplicationUpdater()
else if (mHasDownloaded || mReadyToInstall) {
mWindow->pushGui(new GuiMsgBox(
getHelpStyle(), "PACKAGE WAS DOWNLOADED AND\nCAN BE MANUALLY INSTALLED", "OK",
nullptr, "", nullptr, "", nullptr, true, true,
nullptr, "", nullptr, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.70f :
0.45f * (1.778f / mRenderer->getScreenAspectRatio()))));

View file

@ -672,7 +672,7 @@ void GuiMenu::openUIOptions()
false);
mWindow->invalidateCachedBackground();
},
"CANCEL", nullptr, "", nullptr, true));
"CANCEL", nullptr, "", nullptr, nullptr, true));
}
else {
LOG(LogDebug) << "GuiMenu::openUISettings(): Setting UI mode to '" << selectedMode
@ -1144,7 +1144,7 @@ void GuiMenu::openConfigInput(GuiSettings* settings)
window->pushGui(new GuiMsgBox(
getHelpStyle(), message, "PROCEED",
[window] { window->pushGui(new GuiDetectDevice(false, false, nullptr)); }, "CANCEL",
nullptr, "", nullptr, false, true,
nullptr, "", nullptr, nullptr, false, true,
(mRenderer->getIsVerticalOrientation() ?
0.84f :
0.54f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -1665,20 +1665,20 @@ void GuiMenu::openUtilities()
}
ViewController::getInstance()->rescanROMDirectory();
},
"", nullptr, "", nullptr, true));
"", nullptr, "", nullptr, nullptr, true));
}
else {
mWindow->pushGui(
new GuiMsgBox(getHelpStyle(),
"ERROR CREATING SYSTEM DIRECTORIES, PERMISSION PROBLEMS OR "
"DISK FULL?\nSEE THE LOG FILE FOR MORE DETAILS",
"OK", nullptr, "", nullptr, "", nullptr, true, true,
"OK", nullptr, "", nullptr, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.70f :
0.44f * (1.778f / mRenderer->getScreenAspectRatio()))));
}
},
"CANCEL", nullptr, "", nullptr, false, true,
"CANCEL", nullptr, "", nullptr, nullptr, false, true,
(mRenderer->getIsVerticalOrientation() ?
0.80f :
0.52f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -1712,7 +1712,7 @@ void GuiMenu::openUtilities()
}
ViewController::getInstance()->rescanROMDirectory();
},
"CANCEL", nullptr, "", nullptr, false, true,
"CANCEL", nullptr, "", nullptr, nullptr, false, true,
(mRenderer->getIsVerticalOrientation() ?
0.80f :
0.52f * (1.778f / mRenderer->getScreenAspectRatio()))));

View file

@ -997,7 +997,7 @@ void GuiMetaDataEd::close()
save();
closeFunc();
},
"NO", closeFunc, "", nullptr, true));
"NO", closeFunc, "", nullptr, nullptr, true));
}
else {
// Always save if the media files have been changed (i.e. newly scraped images).

View file

@ -1244,7 +1244,7 @@ void GuiScraperMenu::pressedStart()
mWindow->pushGui(
new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(warningString), "PROCEED",
std::bind(&GuiScraperMenu::start, this), "CANCEL", nullptr, "",
nullptr, false, true,
nullptr, nullptr, false, true,
(mRenderer->getIsVerticalOrientation() ?
0.80f :
0.50f * (1.778f / mRenderer->getScreenAspectRatio()))));

View file

@ -319,10 +319,18 @@ void GuiScraperMulti::finish()
<< mTotalSkipped << " GAME" << ((mTotalSkipped > 1) ? "S" : "") << " SKIPPED";
}
mWindow->pushGui(new GuiMsgBox(getHelpStyle(), ss.str()));
mIsProcessing = false;
delete this;
// Pressing either OK or using the back button should delete us.
mWindow->pushGui(new GuiMsgBox(
getHelpStyle(), ss.str(), "OK",
[&] {
mIsProcessing = false;
delete this;
},
"", nullptr, "", nullptr,
[&] {
mIsProcessing = false;
delete this;
}));
}
std::vector<HelpPrompt> GuiScraperMulti::getHelpPrompts()

View file

@ -571,13 +571,14 @@ void GuiScraperSearch::onSearchError(const std::string& error,
LOG(LogError) << "GuiScraperSearch: " << Utils::String::replace(error, "\n", "");
mWindow->pushGui(new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(error), "RETRY",
std::bind(&GuiScraperSearch::search, this, mLastSearch),
"SKIP", mSkipCallback, "CANCEL", mCancelCallback, true));
"SKIP", mSkipCallback, "CANCEL", mCancelCallback, nullptr,
true));
}
else {
LOG(LogError) << "GuiScraperSearch: " << Utils::String::replace(error, "\n", "");
mWindow->pushGui(new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(error), "RETRY",
std::bind(&GuiScraperSearch::search, this, mLastSearch),
"CANCEL", mCancelCallback, "", nullptr, true));
"CANCEL", mCancelCallback, "", nullptr, nullptr, true));
}
}

View file

@ -548,7 +548,7 @@ bool GuiThemeDownloader::renameDirectory(const std::string& path, const std::str
if (renameStatus) {
mWindow->pushGui(new GuiMsgBox(
getHelpStyle(), "COULDN'T RENAME DIRECTORY \"" + path + "\", PERMISSION PROBLEMS?",
"OK", [] { return; }, "", nullptr, "", nullptr, true));
"OK", [] { return; }, "", nullptr, "", nullptr, nullptr, true));
return true;
}
else {
@ -571,7 +571,7 @@ void GuiThemeDownloader::parseThemesList()
LOG(LogError) << "GuiThemeDownloader: No themes.json file found";
mWindow->pushGui(new GuiMsgBox(
getHelpStyle(), "COULDN'T FIND THE THEMES LIST CONFIGURATION FILE", "OK",
[] { return; }, "", nullptr, "", nullptr, true));
[] { return; }, "", nullptr, "", nullptr, nullptr, true));
mGrid.removeEntry(mCenterGrid);
mGrid.setCursorTo(mButtons);
return;
@ -587,7 +587,7 @@ void GuiThemeDownloader::parseThemesList()
getHelpStyle(),
"COULDN'T PARSE THE THEMES LIST CONFIGURATION FILE, MAYBE THE LOCAL REPOSITORY IS "
"CORRUPT?",
"OK", [] { return; }, "", nullptr, "", nullptr, true));
"OK", [] { return; }, "", nullptr, "", nullptr, nullptr, true));
mGrid.removeEntry(mCenterGrid);
mGrid.setCursorTo(mButtons);
return;
@ -602,7 +602,7 @@ void GuiThemeDownloader::parseThemesList()
getHelpStyle(),
"IT SEEMS AS IF YOU'RE NOT RUNNING THE LATEST ES-DE RELEASE, PLEASE UPGRADE BEFORE "
"PROCEEDING AS THESE THEMES MAY NOT BE COMPATIBLE WITH YOUR VERSION",
"OK", [] { return; }, "", nullptr, "", nullptr, true));
"OK", [] { return; }, "", nullptr, "", nullptr, nullptr, true));
}
}
@ -724,7 +724,7 @@ void GuiThemeDownloader::populateGUI()
mStatusType = StatusType::STATUS_DOWNLOADING;
mStatusText = "DOWNLOADING THEME";
},
"CANCEL", [] { return; }, "", nullptr, true, true,
"CANCEL", [] { return; }, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.75f :
0.46f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -752,7 +752,7 @@ void GuiThemeDownloader::populateGUI()
mStatusType = StatusType::STATUS_DOWNLOADING;
mStatusText = "DOWNLOADING THEME";
},
"CANCEL", [] { return; }, "", nullptr, true, true,
"CANCEL", [] { return; }, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.75f :
0.46f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -779,7 +779,7 @@ void GuiThemeDownloader::populateGUI()
mStatusType = StatusType::STATUS_DOWNLOADING;
mStatusText = "DOWNLOADING THEME";
},
"CANCEL", [] { return; }, "", nullptr, true, true,
"CANCEL", [] { return; }, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.75f :
0.46f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -799,7 +799,7 @@ void GuiThemeDownloader::populateGUI()
mStatusType = StatusType::STATUS_UPDATING;
mStatusText = "UPDATING THEME";
},
"CANCEL", [] { return; }, "", nullptr, true, true,
"CANCEL", [] { return; }, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.75f :
0.45f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -978,7 +978,7 @@ void GuiThemeDownloader::update(int deltaTime)
errorMessage.append(Utils::String::toUpper(mMessage));
mWindow->pushGui(new GuiMsgBox(
getHelpStyle(), errorMessage, "OK", [] { return; }, "", nullptr, "",
nullptr, true));
nullptr, nullptr, true));
mMessage = "";
getHelpPrompts();
}
@ -1164,7 +1164,7 @@ bool GuiThemeDownloader::input(InputConfig* config, Input input)
if (!Utils::FileSystem::removeDirectory(themeDirectory.string(), true)) {
mWindow->pushGui(new GuiMsgBox(
getHelpStyle(), "COULDN'T DELETE THEME, PERMISSION PROBLEMS?", "OK",
[] { return; }, "", nullptr, "", nullptr, true));
[] { return; }, "", nullptr, "", nullptr, nullptr, true));
}
else {
mMessage = "THEME WAS DELETED";
@ -1173,7 +1173,7 @@ bool GuiThemeDownloader::input(InputConfig* config, Input input)
makeInventory();
updateGUI();
},
"CANCEL", nullptr, "", nullptr, true, true,
"CANCEL", nullptr, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.70f :
0.44f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -1247,7 +1247,7 @@ bool GuiThemeDownloader::fetchThemesList()
delete this;
return false;
},
"", nullptr, true, true,
"", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.75f :
0.50f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -1285,7 +1285,7 @@ bool GuiThemeDownloader::fetchThemesList()
delete this;
return false;
},
"", nullptr, true, true,
"", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.85f :
0.54f * (1.778f / mRenderer->getScreenAspectRatio()))));

View file

@ -148,7 +148,8 @@ void ViewController::unsafeUpgradeDialog()
"README.TXT FILE THAT CAN BE FOUND IN THE EMULATIONSTATION-DE "
"DIRECTORY."};
mWindow->pushGui(new GuiMsgBox(
HelpStyle(), upgradeMessage.c_str(), "OK", [] {}, "", nullptr, "", nullptr, true, true,
HelpStyle(), upgradeMessage.c_str(), "OK", [] {}, "", nullptr, "", nullptr, nullptr, true,
true,
(mRenderer->getIsVerticalOrientation() ?
0.85f :
0.55f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -170,7 +171,7 @@ void ViewController::invalidSystemsFileDialog()
quit.type = SDL_QUIT;
SDL_PushEvent(&quit);
},
"", nullptr, "", nullptr, true, true,
"", nullptr, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.85f :
0.55f * (1.778f / mRenderer->getScreenAspectRatio()))));
@ -220,7 +221,7 @@ void ViewController::noGamesDialog()
"ROM DIRECTORY SETTING SAVED, RESTART\n"
"THE APPLICATION TO RESCAN THE SYSTEMS",
"OK", nullptr, "", nullptr, "", nullptr,
true, true));
nullptr, true, true));
}
},
false, "SAVE", "SAVE CHANGES?", "Currently configured path:",
@ -245,7 +246,7 @@ void ViewController::noGamesDialog()
"ROM DIRECTORY SETTING SAVED, RESTART\n"
"THE APPLICATION TO RESCAN THE SYSTEMS",
"OK", nullptr, "", nullptr, "", nullptr,
true));
nullptr, true));
},
false, "SAVE", "SAVE CHANGES?", "Currently configured path:",
currentROMDirectory, "LOAD CURRENTLY CONFIGURED PATH",
@ -268,7 +269,7 @@ void ViewController::noGamesDialog()
"GENERATED, EXIT THE APPLICATION AND PLACE\n"
"YOUR GAMES IN THE NEWLY CREATED FOLDERS",
"OK", nullptr, "", nullptr, "", nullptr,
true));
nullptr, true));
}
else {
mWindow->pushGui(new GuiMsgBox(HelpStyle(),
@ -276,10 +277,10 @@ void ViewController::noGamesDialog()
"PERMISSION PROBLEMS OR DISK FULL?\n\n"
"SEE THE LOG FILE FOR MORE DETAILS",
"OK", nullptr, "", nullptr, "", nullptr,
true));
nullptr, true));
}
},
"CANCEL", nullptr, "", nullptr, true));
"CANCEL", nullptr, "", nullptr, nullptr, true));
},
"QUIT",
[] {
@ -287,7 +288,7 @@ void ViewController::noGamesDialog()
quit.type = SDL_QUIT;
SDL_PushEvent(&quit);
},
true, false,
nullptr, true, false,
(mRenderer->getIsVerticalOrientation() ?
0.90f :
0.62f * (1.778f / mRenderer->getScreenAspectRatio())));
@ -305,7 +306,7 @@ void ViewController::invalidAlternativeEmulatorDialog()
"CONFIGURATION FILE, PLEASE REVIEW YOUR\n"
"SETUP USING THE 'ALTERNATIVE EMULATORS'\n"
"INTERFACE IN THE 'OTHER SETTINGS' MENU",
"OK", nullptr, "", nullptr, "", nullptr, true, true));
"OK", nullptr, "", nullptr, "", nullptr, nullptr, true, true));
}
void ViewController::updateAvailableDialog()
@ -355,20 +356,20 @@ void ViewController::updateAvailableDialog()
}
mWindow->pushGui(new GuiMsgBox(
getHelpStyle(), upgradeMessage.c_str(), "OK", [] {}, "", nullptr, "",
nullptr, true, true,
nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.85f :
0.535f * (1.778f / mRenderer->getScreenAspectRatio()))));
}
},
"CANCEL", [] { return; }, "", nullptr, true, true,
"CANCEL", [] { return; }, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.70f :
0.45f * (1.778f / mRenderer->getScreenAspectRatio()))));
}
else {
mWindow->pushGui(new GuiMsgBox(getHelpStyle(), results, "OK", nullptr, "", nullptr, "",
nullptr, true, true,
nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.70f :
0.45f * (1.778f / mRenderer->getScreenAspectRatio()))));

View file

@ -23,6 +23,7 @@ GuiMsgBox::GuiMsgBox(const HelpStyle& helpstyle,
const std::function<void()>& func2,
const std::string& name3,
const std::function<void()>& func3,
const std::function<void()>& backFunc,
const bool disableBackButton,
const bool deleteOnButtonPress,
const float maxWidthMultiplier)
@ -30,6 +31,7 @@ GuiMsgBox::GuiMsgBox(const HelpStyle& helpstyle,
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {1, 2}}
, mHelpStyle {helpstyle}
, mBackFunc {backFunc}
, mDisableBackButton {disableBackButton}
, mDeleteOnButtonPress {deleteOnButtonPress}
, mMaxWidthMultiplier {maxWidthMultiplier}
@ -133,6 +135,8 @@ void GuiMsgBox::changeText(const std::string& newText)
bool GuiMsgBox::input(InputConfig* config, Input input)
{
if (!mDisableBackButton && config->isMappedTo("b", input) && input.value != 0) {
if (mBackFunc)
mBackFunc();
delete this;
return true;
}

View file

@ -28,6 +28,7 @@ public:
const std::function<void()>& func2 = nullptr,
const std::string& name3 = "",
const std::function<void()>& func3 = nullptr,
const std::function<void()>& backFunc = nullptr,
const bool disableBackButton = false,
const bool deleteOnButtonPress = true,
const float maxWidthMultiplier = 0.0f);
@ -51,6 +52,7 @@ private:
std::shared_ptr<TextComponent> mMsg;
std::vector<std::shared_ptr<ButtonComponent>> mButtons;
std::shared_ptr<ComponentGrid> mButtonGrid;
const std::function<void()> mBackFunc;
bool mDisableBackButton;
bool mDeleteOnButtonPress;
float mMaxWidthMultiplier;

View file

@ -375,7 +375,7 @@ bool GuiTextEditKeyboardPopup::input(InputConfig* config, Input input)
delete this;
return true;
},
"", nullptr, true));
"", nullptr, nullptr, true));
}
else {
delete this;

View file

@ -186,7 +186,7 @@ bool GuiTextEditPopup::input(InputConfig* config, Input input)
delete this;
return true;
},
"", nullptr, true));
"", nullptr, nullptr, true));
}
else {
delete this;