Simplified the code for info popups.

This commit is contained in:
Leon Styhre 2021-10-07 18:31:40 +02:00
parent 2bd4c163b1
commit 93950cf4de
10 changed files with 77 additions and 109 deletions

View file

@ -30,7 +30,6 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGamelistFilter.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGamelistOptions.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGameScraper.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInfoPopup.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiLaunchScreen.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMediaViewerOptions.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMenu.h
@ -81,7 +80,6 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGamelistFilter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGamelistOptions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiGameScraper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInfoPopup.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiLaunchScreen.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMenu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMediaViewerOptions.cpp

View file

@ -27,7 +27,7 @@
#include "Settings.h"
#include "SystemData.h"
#include "ThemeData.h"
#include "guis/GuiInfoPopup.h"
#include "Window.h"
#include "utils/FileSystemUtil.h"
#include "utils/StringUtil.h"
#include "utils/TimeUtil.h"
@ -385,14 +385,12 @@ void CollectionSystemsManager::updateCollectionSystem(FileData* file, Collection
parentRootFolder->sort(parentRootFolder->getSortTypeFromString(
parentRootFolder->getSortTypeString()),
mFavoritesSorting);
GuiInfoPopup* s = new GuiInfoPopup(
mWindow,
mWindow->queueInfoPopup(
"DISABLED '" +
Utils::String::toUpper(
Utils::String::removeParenthesis(file->getName())) +
"' IN '" + Utils::String::toUpper(sysData.system->getName()) + "'",
4000);
mWindow->setInfoPopup(s);
}
else {
ViewController::get()->getGameListView(curSys).get()->remove(collectionEntry,
@ -621,24 +619,18 @@ void CollectionSystemsManager::setEditMode(std::string collectionName, bool show
mEditingCollectionSystemData = sysData;
if (showPopup) {
GuiInfoPopup* s = new GuiInfoPopup(mWindow,
"EDITING '" + Utils::String::toUpper(collectionName) +
"' COLLECTION, ADD/REMOVE GAMES WITH 'Y'",
10000);
mWindow->setInfoPopup(s);
mWindow->queueInfoPopup("EDITING '" + Utils::String::toUpper(collectionName) +
"' COLLECTION, ADD/REMOVE GAMES WITH 'Y'",
10000);
}
}
void CollectionSystemsManager::exitEditMode(bool showPopup)
{
if (showPopup) {
GuiInfoPopup* s = new GuiInfoPopup(
mWindow,
"FINISHED EDITING '" + Utils::String::toUpper(mEditingCollection) + "' COLLECTION",
4000);
mWindow->setInfoPopup(s);
mWindow->queueInfoPopup("FINISHED EDITING '" + Utils::String::toUpper(mEditingCollection) +
"' COLLECTION",
4000);
}
mIsEditingCustom = false;
@ -669,7 +661,6 @@ bool CollectionSystemsManager::inCustomCollection(const std::string& collectionN
bool CollectionSystemsManager::toggleGameInCollection(FileData* file)
{
if (file->getType() == GAME) {
GuiInfoPopup* s;
bool adding = true;
std::string name = file->getName();
std::string sysName = mEditingCollection;
@ -743,20 +734,17 @@ bool CollectionSystemsManager::toggleGameInCollection(FileData* file)
mAutoCollectionSystemsData["favorites"].system);
}
if (adding) {
s = new GuiInfoPopup(
mWindow,
mWindow->queueInfoPopup(
"ADDED '" + Utils::String::toUpper(Utils::String::removeParenthesis(name)) +
"' TO '" + Utils::String::toUpper(sysName) + "'",
4000);
}
else {
s = new GuiInfoPopup(
mWindow,
mWindow->queueInfoPopup(
"REMOVED '" + Utils::String::toUpper(Utils::String::removeParenthesis(name)) +
"' FROM '" + Utils::String::toUpper(sysName) + "'",
4000);
}
mWindow->setInfoPopup(s);
return true;
}
return false;
@ -952,9 +940,8 @@ void CollectionSystemsManager::deleteCustomCollection(std::string collectionName
"configuration file '"
<< configFile << "'.";
GuiInfoPopup* s = new GuiInfoPopup(
mWindow, "DELETED COLLECTION '" + Utils::String::toUpper(collectionName) + "'", 5000);
mWindow->setInfoPopup(s);
mWindow->queueInfoPopup(
"DELETED COLLECTION '" + Utils::String::toUpper(collectionName) + "'", 5000);
}
else {
LOG(LogError) << "Attempted to delete custom collection '" + collectionName + "' " +

View file

@ -20,7 +20,6 @@
#include "Scripting.h"
#include "SystemData.h"
#include "Window.h"
#include "guis/GuiInfoPopup.h"
#include "utils/FileSystemUtil.h"
#include "utils/StringUtil.h"
#include "utils/TimeUtil.h"
@ -856,9 +855,8 @@ void FileData::launchGame(Window* window)
LOG(LogError) << "Raw emulator launch command:";
LOG(LogError) << commandRaw;
GuiInfoPopup* s = new GuiInfoPopup(
window, "ERROR: MISSING EMULATOR CONFIGURATION FOR '" + emulatorEntry + "'", 6000);
window->setInfoPopup(s);
window->queueInfoPopup("ERROR: MISSING EMULATOR CONFIGURATION FOR '" + emulatorEntry + "'",
6000);
return;
}
else if (binaryPath.empty()) {
@ -866,11 +864,8 @@ void FileData::launchGame(Window* window)
LOG(LogError) << "Raw emulator launch command:";
LOG(LogError) << commandRaw;
GuiInfoPopup* s = new GuiInfoPopup(window,
"ERROR: COULDN'T FIND EMULATOR, HAS IT "
"BEEN PROPERLY INSTALLED?",
6000);
window->setInfoPopup(s);
window->queueInfoPopup("ERROR: COULDN'T FIND EMULATOR, HAS IT BEEN PROPERLY INSTALLED?",
6000);
return;
}
else {
@ -914,12 +909,10 @@ void FileData::launchGame(Window* window)
LOG(LogError) << "Raw emulator launch command:";
LOG(LogError) << commandRaw;
GuiInfoPopup* s = new GuiInfoPopup(
window,
window->queueInfoPopup(
"ERROR: COULDN'T FIND EMULATOR CORE FILE '" +
Utils::String::toUpper(Utils::FileSystem::getFileName(coreFile)) + "'",
6000);
window->setInfoPopup(s);
return;
}
else {
@ -937,11 +930,7 @@ void FileData::launchGame(Window* window)
LOG(LogError) << "Raw emulator launch command:";
LOG(LogError) << commandRaw;
GuiInfoPopup* s = new GuiInfoPopup(window,
"ERROR: INVALID ENTRY IN SYSTEMS "
"CONFIGURATION FILE",
6000);
window->setInfoPopup(s);
window->queueInfoPopup("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE", 6000);
return;
}
}
@ -953,9 +942,7 @@ void FileData::launchGame(Window* window)
LOG(LogError) << "Raw emulator launch command:";
LOG(LogError) << commandRaw;
GuiInfoPopup* s = new GuiInfoPopup(
window, "ERROR: MISSING CORE CONFIGURATION FOR '" + coreEntry + "'", 6000);
window->setInfoPopup(s);
window->queueInfoPopup("ERROR: MISSING CORE CONFIGURATION FOR '" + coreEntry + "'", 6000);
return;
}
@ -1024,11 +1011,7 @@ void FileData::launchGame(Window* window)
LOG(LogError) << "Raw emulator launch command:";
LOG(LogError) << commandRaw;
GuiInfoPopup* s = new GuiInfoPopup(window,
"ERROR: INVALID ENTRY IN SYSTEMS "
"CONFIGURATION FILE",
6000);
window->setInfoPopup(s);
window->queueInfoPopup("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE", 6000);
return;
}
}
@ -1041,12 +1024,10 @@ void FileData::launchGame(Window* window)
<< "Tried to find the core file using these paths as defined by es_find_rules.xml:";
LOG(LogError) << Utils::String::vectorToDelimitedString(emulatorCorePaths, ", ");
GuiInfoPopup* s =
new GuiInfoPopup(window,
"ERROR: COULDN'T FIND EMULATOR CORE FILE '" +
Utils::String::toUpper(coreName.substr(0, coreName.size()) + "'"),
6000);
window->setInfoPopup(s);
window->queueInfoPopup(
"ERROR: COULDN'T FIND EMULATOR CORE FILE '" +
Utils::String::toUpper(coreName.substr(0, coreName.size()) + "'"),
6000);
return;
}
@ -1087,12 +1068,10 @@ void FileData::launchGame(Window* window)
if (returnValue != 0) {
LOG(LogWarning) << "...launch terminated with nonzero return value " << returnValue;
GuiInfoPopup* s = new GuiInfoPopup(
window,
"ERROR LAUNCHING GAME '" + Utils::String::toUpper(metadata.get("name")) +
"' (ERROR CODE " + Utils::String::toUpper(std::to_string(returnValue) + ")"),
6000);
window->setInfoPopup(s);
window->queueInfoPopup("ERROR LAUNCHING GAME '" +
Utils::String::toUpper(metadata.get("name")) + "' (ERROR CODE " +
Utils::String::toUpper(std::to_string(returnValue) + ")"),
6000);
}
else {
// Stop showing the game launch notification.

View file

@ -24,7 +24,6 @@
#include "animations/Animation.h"
#include "animations/LambdaAnimation.h"
#include "animations/MoveCameraAnimation.h"
#include "guis/GuiInfoPopup.h"
#include "guis/GuiMenu.h"
#include "guis/GuiTextEditKeyboardPopup.h"
#include "guis/GuiTextEditPopup.h"
@ -700,10 +699,8 @@ void ViewController::launch(FileData* game)
if (durationString == "disabled") {
// If the game launch screen has been set as disabled, show a simple info popup
// notification instead.
GuiInfoPopup* s = new GuiInfoPopup(
mWindow, "LAUNCHING GAME '" + Utils::String::toUpper(game->metadata.get("name") + "'"),
10000);
mWindow->setInfoPopup(s);
mWindow->queueInfoPopup(
"LAUNCHING GAME '" + Utils::String::toUpper(game->metadata.get("name") + "'"), 10000);
duration = 1700;
}
else if (durationString == "brief") {

View file

@ -13,7 +13,7 @@
#include "Settings.h"
#include "Sound.h"
#include "SystemData.h"
#include "guis/GuiInfoPopup.h"
#include "Window.h"
#include "utils/StringUtil.h"
#include "views/UIModeController.h"
#include "views/ViewController.h"
@ -273,18 +273,13 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
mRoot->getSystem()->isGameSystem() && getCursor()->getType() != PLACEHOLDER &&
getCursor()->getParent()->getPath() == "collections") {
NavigationSounds::getInstance()->playThemeNavigationSound(FAVORITESOUND);
GuiInfoPopup* s;
s = new GuiInfoPopup(mWindow, "CAN'T ADD CUSTOM COLLECTIONS TO CUSTOM COLLECTIONS",
4000);
mWindow->setInfoPopup(s);
mWindow->queueInfoPopup("CAN'T ADD CUSTOM COLLECTIONS TO CUSTOM COLLECTIONS", 4000);
}
// Notify the user if attempting to add a placeholder to a custom collection.
if (CollectionSystemsManager::get()->isEditing() &&
mRoot->getSystem()->isGameSystem() && getCursor()->getType() == PLACEHOLDER) {
NavigationSounds::getInstance()->playThemeNavigationSound(FAVORITESOUND);
GuiInfoPopup* s;
s = new GuiInfoPopup(mWindow, "CAN'T ADD PLACEHOLDERS TO CUSTOM COLLECTIONS", 4000);
mWindow->setInfoPopup(s);
mWindow->queueInfoPopup("CAN'T ADD PLACEHOLDERS TO CUSTOM COLLECTIONS", 4000);
}
else if (mRoot->getSystem()->isGameSystem() && getCursor()->getType() != PLACEHOLDER &&
getCursor()->getParent()->getPath() != "collections") {
@ -394,17 +389,14 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
// so it makes more sense to handle it here than to add the function to
// CollectionSystemsManager.
if (entryToUpdate->getType() == FOLDER) {
GuiInfoPopup* s;
if (isEditing) {
s = new GuiInfoPopup(mWindow, "CAN'T ADD FOLDERS TO CUSTOM COLLECTIONS",
4000);
mWindow->queueInfoPopup("CAN'T ADD FOLDERS TO CUSTOM COLLECTIONS", 4000);
}
else {
MetaDataList* md = &entryToUpdate->getSourceFileData()->metadata;
if (md->get("favorite") == "false") {
md->set("favorite", "true");
s = new GuiInfoPopup(
mWindow,
mWindow->queueInfoPopup(
"MARKED FOLDER '" +
Utils::String::toUpper(Utils::String::removeParenthesis(
entryToUpdate->getName())) +
@ -413,8 +405,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
}
else {
md->set("favorite", "false");
s = new GuiInfoPopup(
mWindow,
mWindow->queueInfoPopup(
"REMOVED FAVORITE MARKING FOR FOLDER '" +
Utils::String::toUpper(Utils::String::removeParenthesis(
entryToUpdate->getName())) +
@ -423,7 +414,6 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
}
}
mWindow->setInfoPopup(s);
entryToUpdate->getSourceFileData()->getSystem()->onMetaDataSavePoint();
getCursor()->getParent()->sort(
@ -445,11 +435,9 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
return true;
}
else if (isEditing && entryToUpdate->metadata.get("nogamecount") == "true") {
GuiInfoPopup* s = new GuiInfoPopup(mWindow,
"CAN'T ADD ENTRIES THAT ARE NOT COUNTED "
"AS GAMES TO CUSTOM COLLECTIONS",
4000);
mWindow->setInfoPopup(s);
mWindow->queueInfoPopup("CAN'T ADD ENTRIES THAT ARE NOT COUNTED "
"AS GAMES TO CUSTOM COLLECTIONS",
4000);
}
else if (CollectionSystemsManager::get()->toggleGameInCollection(entryToUpdate)) {
// As the toggling of the game destroyed this object, we need to get the view

View file

@ -61,6 +61,7 @@ set(CORE_HEADERS
# GUIs
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiDetectDevice.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInfoPopup.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMsgBox.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiTextEditKeyboardPopup.h
@ -131,6 +132,7 @@ set(CORE_SOURCES
# GUIs
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiDetectDevice.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInfoPopup.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMsgBox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiTextEditKeyboardPopup.cpp

View file

@ -11,6 +11,7 @@
#include "components/HelpComponent.h"
#include "components/ImageComponent.h"
#include "guis/GuiInfoPopup.h"
#if defined(BUILD_VLC_PLAYER)
#include "components/VideoVlcComponent.h"
#endif
@ -338,6 +339,24 @@ void Window::update(int deltaTime)
mTimeSinceLastInput += deltaTime;
// If there is a popup notification queued, then display it.
if (mInfoPopupQueue.size() > 0) {
bool popupIsRunning = false;
// If uncommenting the following, new popups will not be displayed until the one
// currently shown has reached its display duration. This will be used later when
// support for multiple GuiInfoPopup notifications is implemented.
// if (mInfoPopup != nullptr && mInfoPopup->isRunning())
// popupIsRunning = true;
if (!popupIsRunning) {
delete mInfoPopup;
mInfoPopup = new GuiInfoPopup(this, mInfoPopupQueue.front().first,
mInfoPopupQueue.front().second);
mInfoPopupQueue.pop();
}
}
if (peekGui())
peekGui()->update(deltaTime);
@ -689,16 +708,13 @@ void Window::reloadHelpPrompts()
}
}
void Window::setInfoPopup(InfoPopup* infoPopup)
{
delete mInfoPopup;
mInfoPopup = infoPopup;
}
void Window::stopInfoPopup()
{
if (mInfoPopup)
mInfoPopup->stop();
if (mInfoPopupQueue.size() > 0)
std::queue<std::pair<std::string, int>>().swap(mInfoPopupQueue);
}
void Window::startScreensaver()

View file

@ -18,10 +18,12 @@
#include <memory>
#include <mutex>
#include <queue>
class FileData;
class Font;
class GuiComponent;
class GuiInfoPopup;
class HelpComponent;
class ImageComponent;
class InputConfig;
@ -73,14 +75,6 @@ public:
virtual void render(const glm::mat4& parentTrans) = 0;
};
class InfoPopup
{
public:
virtual void render(const glm::mat4& parentTrans) = 0;
virtual void stop() = 0;
virtual ~InfoPopup() {}
};
Window();
~Window();
@ -113,7 +107,11 @@ public:
void setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpStyle& style);
void reloadHelpPrompts();
void setInfoPopup(InfoPopup* infoPopup);
// GuiInfoPopup notifications.
void queueInfoPopup(const std::string& message, const int& duration)
{
mInfoPopupQueue.emplace(std::make_pair(message, duration));
}
void stopInfoPopup();
void startScreensaver();
@ -165,7 +163,9 @@ private:
Screensaver* mScreensaver;
MediaViewer* mMediaViewer;
GuiLaunchScreen* mLaunchScreen;
InfoPopup* mInfoPopup;
GuiInfoPopup* mInfoPopup;
std::queue<std::pair<std::string, int>> mInfoPopupQueue;
std::string mListScrollText;
std::shared_ptr<Font> mListScrollFont;

View file

@ -15,14 +15,15 @@
class ComponentGrid;
class NinePatchComponent;
class GuiInfoPopup : public GuiComponent, public Window::InfoPopup
class GuiInfoPopup : public GuiComponent
{
public:
GuiInfoPopup(Window* window, std::string message, int duration);
~GuiInfoPopup();
void render(const glm::mat4& parentTrans) override;
void stop() override { mRunning = false; }
void render(const glm::mat4& parentTrans);
void stop() { mRunning = false; }
bool isRunning() { return mRunning; }
private:
bool updateState();