Fixed lots of code formatting issues.

This commit is contained in:
Leon Styhre 2021-09-27 21:06:07 +02:00
parent a928142d5b
commit f6dd49071e
48 changed files with 828 additions and 556 deletions

View file

@ -550,7 +550,8 @@ bool CollectionSystemsManager::isThemeCustomCollectionCompatible(
return true; return true;
} }
std::string CollectionSystemsManager::getValidNewCollectionName(std::string inName, int index) { std::string CollectionSystemsManager::getValidNewCollectionName(std::string inName, int index)
{
std::string name = inName; std::string name = inName;
// Trim leading and trailing whitespaces. // Trim leading and trailing whitespaces.
@ -569,7 +570,8 @@ std::string CollectionSystemsManager::getValidNewCollectionName(std::string inNa
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-[]()' ")) != "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-[]()' ")) !=
std::string::npos) std::string::npos)
name.erase(remove, 1); name.erase(remove, 1);
} else { }
else {
name += " (" + std::to_string(index) + ")"; name += " (" + std::to_string(index) + ")";
} }
@ -1331,7 +1333,8 @@ void CollectionSystemsManager::addEnabledCollectionsToDisplayedSystems(
} }
} }
std::vector<std::string> CollectionSystemsManager::getSystemsFromConfig() { std::vector<std::string> CollectionSystemsManager::getSystemsFromConfig()
{
std::vector<std::string> systems; std::vector<std::string> systems;
std::vector<std::string> configPaths = SystemData::getConfigPath(false); std::vector<std::string> configPaths = SystemData::getConfigPath(false);

View file

@ -33,8 +33,15 @@ FileData::FileData(FileType type,
const std::string& path, const std::string& path,
SystemEnvironmentData* envData, SystemEnvironmentData* envData,
SystemData* system) SystemData* system)
: metadata(type == GAME ? GAME_METADATA : FOLDER_METADATA), mSourceFileData(nullptr), mParent(nullptr), : metadata(type == GAME ? GAME_METADATA : FOLDER_METADATA)
mType(type), mPath(path), mEnvData(envData), mSystem(system), mOnlyFolders(false), mDeletionFlag(false) , mSourceFileData(nullptr)
, mParent(nullptr)
, mType(type)
, mPath(path)
, mEnvData(envData)
, mSystem(system)
, mOnlyFolders(false)
, mDeletionFlag(false)
{ {
// Metadata needs at least a name field (since that's what getName() will return). // Metadata needs at least a name field (since that's what getName() will return).
if (metadata.get("name").empty()) { if (metadata.get("name").empty()) {
@ -735,7 +742,8 @@ FileData::SortType FileData::getSortTypeFromString(std::string desc)
return FileSorts::SortTypes.at(0); return FileSorts::SortTypes.at(0);
} }
void FileData::launchGame(Window *window) { void FileData::launchGame(Window* window)
{
LOG(LogInfo) << "Launching game \"" << this->metadata.get("name") << "\"..."; LOG(LogInfo) << "Launching game \"" << this->metadata.get("name") << "\"...";
SystemData* gameSystem = nullptr; SystemData* gameSystem = nullptr;

View file

@ -20,9 +20,17 @@
#define INCLUDE_UNKNOWN false; #define INCLUDE_UNKNOWN false;
FileFilterIndex::FileFilterIndex() FileFilterIndex::FileFilterIndex()
: mFilterByText(false), mTextRemoveSystem(false), mFilterByFavorites(false), mFilterByGenre(false), : mFilterByText(false)
mFilterByPlayers(false), mFilterByPubDev(false), mFilterByRatings(false), mFilterByKidGame(false), , mTextRemoveSystem(false)
mFilterByCompleted(false), mFilterByBroken(false), mFilterByHidden(false) , mFilterByFavorites(false)
, mFilterByGenre(false)
, mFilterByPlayers(false)
, mFilterByPubDev(false)
, mFilterByRatings(false)
, mFilterByKidGame(false)
, mFilterByCompleted(false)
, mFilterByBroken(false)
, mFilterByHidden(false)
{ {
clearAllFilters(); clearAllFilters();
@ -359,7 +367,8 @@ bool FileFilterIndex::showFile(FileData* game)
!(Utils::String::toUpper(game->getName().substr(0, game->getName().find_last_of("["))) !(Utils::String::toUpper(game->getName().substr(0, game->getName().find_last_of("[")))
.find(mTextFilter) != std::string::npos)) { .find(mTextFilter) != std::string::npos)) {
return false; return false;
} else if (mTextFilter != "" && }
else if (mTextFilter != "" &&
!(Utils::String::toUpper(game->getName()).find(mTextFilter) != std::string::npos)) { !(Utils::String::toUpper(game->getName()).find(mTextFilter) != std::string::npos)) {
return false; return false;
} }
@ -372,7 +381,8 @@ bool FileFilterIndex::showFile(FileData* game)
FilterDataDecl filterData = (*it); FilterDataDecl filterData = (*it);
if (filterData.primaryKey == "kidgame" && UIModeController::getInstance()->isUIModeKid()) { if (filterData.primaryKey == "kidgame" && UIModeController::getInstance()->isUIModeKid()) {
return (getIndexableKey(game, filterData.type, false) != "FALSE"); return (getIndexableKey(game, filterData.type, false) != "FALSE");
} else if (*(filterData.filteredByRef)) { }
else if (*(filterData.filteredByRef)) {
// Try to find a match. // Try to find a match.
std::string key = getIndexableKey(game, filterData.type, false); std::string key = getIndexableKey(game, filterData.type, false);
keepGoing = isKeyBeingFilteredBy(key, filterData.type); keepGoing = isKeyBeingFilteredBy(key, filterData.type);

View file

@ -227,7 +227,8 @@ namespace FileSorts
return system1.compare(system2) < 0; return system1.compare(system2) < 0;
} }
bool compareSystemDescending(const FileData *file1, const FileData *file2) { bool compareSystemDescending(const FileData* file1, const FileData* file2)
{
std::string system1 = Utils::String::toUpper(file1->getSystemName()); std::string system1 = Utils::String::toUpper(file1->getSystemName());
std::string system2 = Utils::String::toUpper(file2->getSystemName()); std::string system2 = Utils::String::toUpper(file2->getSystemName());
return system1.compare(system2) > 0; return system1.compare(system2) > 0;

View file

@ -216,7 +216,8 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window, std::st
mWindow, getHelpStyle(), "New Collection Name", "", createCollectionCall, false, mWindow, getHelpStyle(), "New Collection Name", "", createCollectionCall, false,
"CREATE", "CREATE COLLECTION?")); "CREATE", "CREATE COLLECTION?"));
}); });
} else { }
else {
row.makeAcceptInputHandler([this, createCollectionCall] { row.makeAcceptInputHandler([this, createCollectionCall] {
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), "New Collection Name", mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), "New Collection Name",
"", createCollectionCall, false, "CREATE", "", createCollectionCall, false, "CREATE",

View file

@ -21,8 +21,11 @@
GuiGameScraper::GuiGameScraper(Window* window, GuiGameScraper::GuiGameScraper(Window* window,
ScraperSearchParams params, ScraperSearchParams params,
std::function<void(const ScraperSearchResult&)> doneFunc) std::function<void(const ScraperSearchResult&)> doneFunc)
: GuiComponent(window), mClose(false), mGrid(window, glm::ivec2{1, 7}), mBox(window, ":/graphics/frame.svg"), : GuiComponent(window)
mSearchParams(params) , mClose(false)
, mGrid(window, glm::ivec2{1, 7})
, mBox(window, ":/graphics/frame.svg")
, mSearchParams(params)
{ {
addChild(&mBox); addChild(&mBox);
addChild(&mGrid); addChild(&mGrid);

View file

@ -29,7 +29,8 @@ GuiGamelistFilter::GuiGamelistFilter(Window* window,
initializeMenu(); initializeMenu();
} }
void GuiGamelistFilter::initializeMenu() { void GuiGamelistFilter::initializeMenu()
{
addChild(&mMenu); addChild(&mMenu);
// Get filters from system. // Get filters from system.
@ -93,7 +94,8 @@ void GuiGamelistFilter::resetAllFilters()
GuiGamelistFilter::~GuiGamelistFilter() { mFilterOptions.clear(); } GuiGamelistFilter::~GuiGamelistFilter() { mFilterOptions.clear(); }
void GuiGamelistFilter::addFiltersToMenu() { void GuiGamelistFilter::addFiltersToMenu()
{
ComponentListRow row; ComponentListRow row;
auto lbl = std::make_shared<TextComponent>( auto lbl = std::make_shared<TextComponent>(
@ -132,7 +134,8 @@ void GuiGamelistFilter::addFiltersToMenu() {
mTextFilterField->getValue(), updateVal, mTextFilterField->getValue(), updateVal,
false, "OK", "APPLY CHANGES?")); false, "OK", "APPLY CHANGES?"));
}); });
} else { }
else {
row.makeAcceptInputHandler([this, updateVal] { row.makeAcceptInputHandler([this, updateVal] {
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), "GAME NAME", mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), "GAME NAME",
mTextFilterField->getValue(), updateVal, false, mTextFilterField->getValue(), updateVal, false,

View file

@ -26,8 +26,14 @@
#include "views/gamelist/IGameListView.h" #include "views/gamelist/IGameListView.h"
GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system)
: GuiComponent(window), mMenu(window, "OPTIONS"), mSystem(system), mFiltersChanged(false), mCancelled(false), : GuiComponent(window)
mIsCustomCollection(false), mIsCustomCollectionGroup(false), mCustomCollectionSystem(nullptr) , mMenu(window, "OPTIONS")
, mSystem(system)
, mFiltersChanged(false)
, mCancelled(false)
, mIsCustomCollection(false)
, mIsCustomCollectionGroup(false)
, mCustomCollectionSystem(nullptr)
{ {
addChild(&mMenu); addChild(&mMenu);

View file

@ -15,8 +15,11 @@
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
GuiLaunchScreen::GuiLaunchScreen(Window* window) GuiLaunchScreen::GuiLaunchScreen(Window* window)
: GuiComponent(window), mWindow(window), mBackground(window, ":/graphics/frame.svg"), mGrid(nullptr), : GuiComponent(window)
mMarquee(nullptr) , mWindow(window)
, mBackground(window, ":/graphics/frame.svg")
, mGrid(nullptr)
, mMarquee(nullptr)
{ {
addChild(&mBackground); addChild(&mBackground);
mWindow->setLaunchScreen(this); mWindow->setLaunchScreen(this);
@ -217,7 +220,8 @@ void GuiLaunchScreen::update(int deltaTime)
mScaleUp = glm::clamp(mScaleUp + 0.07f, 0.0f, 1.0f); mScaleUp = glm::clamp(mScaleUp + 0.07f, 0.0f, 1.0f);
} }
void GuiLaunchScreen::render(const glm::mat4 & /*parentTrans*/) { void GuiLaunchScreen::render(const glm::mat4& /*parentTrans*/)
{
// Scale up animation. // Scale up animation.
if (mScaleUp < 1.0f) if (mScaleUp < 1.0f)
setScale(mScaleUp); setScale(mScaleUp);

View file

@ -37,7 +37,9 @@
#include <algorithm> #include <algorithm>
GuiMenu::GuiMenu(Window* window) GuiMenu::GuiMenu(Window* window)
: GuiComponent(window), mMenu(window, "MAIN MENU"), mVersion(window) : GuiComponent(window)
, mMenu(window, "MAIN MENU")
, mVersion(window)
{ {
bool isFullUI = UIModeController::getInstance()->isUIModeFull(); bool isFullUI = UIModeController::getInstance()->isUIModeFull();
@ -826,7 +828,8 @@ void GuiMenu::openOtherOptions()
Settings::getInstance()->getString("MediaDirectory"), updateValMediaDir, Settings::getInstance()->getString("MediaDirectory"), updateValMediaDir,
multiLineMediaDir, "SAVE", "SAVE CHANGES?", mediaDirectoryStaticText, multiLineMediaDir, "SAVE", "SAVE CHANGES?", mediaDirectoryStaticText,
defaultDirectoryText, "load default directory")); defaultDirectoryText, "load default directory"));
} else { }
else {
mWindow->pushGui(new GuiTextEditPopup( mWindow->pushGui(new GuiTextEditPopup(
mWindow, getHelpStyle(), titleMediaDir, mWindow, getHelpStyle(), titleMediaDir,
Settings::getInstance()->getString("MediaDirectory"), updateValMediaDir, Settings::getInstance()->getString("MediaDirectory"), updateValMediaDir,

View file

@ -39,10 +39,17 @@ GuiMetaDataEd::GuiMetaDataEd(Window *window,
std::function<void()> saveCallback, std::function<void()> saveCallback,
std::function<void()> clearGameFunc, std::function<void()> clearGameFunc,
std::function<void()> deleteGameFunc) std::function<void()> deleteGameFunc)
: GuiComponent(window), mBackground(window, ":/graphics/frame.svg"), mGrid(window, glm::ivec2{1, 3}), : GuiComponent(window)
mScraperParams(scraperParams), mMetaDataDecl(mdd), mMetaData(md), mSavedCallback(saveCallback), , mBackground(window, ":/graphics/frame.svg")
mClearGameFunc(clearGameFunc), mDeleteGameFunc(deleteGameFunc), mMediaFilesUpdated(false), , mGrid(window, glm::ivec2{1, 3})
mInvalidEmulatorEntry(false) , mScraperParams(scraperParams)
, mMetaDataDecl(mdd)
, mMetaData(md)
, mSavedCallback(saveCallback)
, mClearGameFunc(clearGameFunc)
, mDeleteGameFunc(deleteGameFunc)
, mMediaFilesUpdated(false)
, mInvalidEmulatorEntry(false)
{ {
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);
@ -356,7 +363,8 @@ GuiMetaDataEd::GuiMetaDataEd(Window *window,
ed->setColor(DEFAULT_TEXTCOLOR); ed->setColor(DEFAULT_TEXTCOLOR);
else else
ed->setColor(TEXTCOLOR_USERMARKED); ed->setColor(TEXTCOLOR_USERMARKED);
} else { }
else {
ed->setValue(newVal); ed->setValue(newVal);
if (newVal == originalValue) if (newVal == originalValue)
ed->setColor(DEFAULT_TEXTCOLOR); ed->setColor(DEFAULT_TEXTCOLOR);
@ -371,7 +379,8 @@ GuiMetaDataEd::GuiMetaDataEd(Window *window,
mWindow, getHelpStyle(), title, ed->getValue(), updateVal, multiLine, mWindow, getHelpStyle(), title, ed->getValue(), updateVal, multiLine,
"apply", "APPLY CHANGES?", "", "")); "apply", "APPLY CHANGES?", "", ""));
}); });
} else { }
else {
row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] { row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] {
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), title, mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), title,
ed->getValue(), updateVal, multiLine, ed->getValue(), updateVal, multiLine,

View file

@ -14,8 +14,10 @@
#include "views/ViewController.h" #include "views/ViewController.h"
GuiOfflineGenerator::GuiOfflineGenerator(Window* window, const std::queue<FileData*>& gameQueue) GuiOfflineGenerator::GuiOfflineGenerator(Window* window, const std::queue<FileData*>& gameQueue)
: GuiComponent(window), mGameQueue(gameQueue), mBackground(window, ":/graphics/frame.svg"), : GuiComponent(window)
mGrid(window, glm::ivec2{6, 13}) , mGameQueue(gameQueue)
, mBackground(window, ":/graphics/frame.svg")
, mGrid(window, glm::ivec2{6, 13})
{ {
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);

View file

@ -38,8 +38,14 @@
#define FAILED_VERIFICATION_RETRIES 8 #define FAILED_VERIFICATION_RETRIES 8
GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int scrapeCount) GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int scrapeCount)
: GuiComponent(window), mGrid(window, glm::ivec2{4, 3}), mSearchType(type), mScrapeCount(scrapeCount), : GuiComponent(window)
mRefinedSearch(false), mFoundGame(false), mScrapeRatings(false), mBusyAnim(window) , mGrid(window, glm::ivec2{4, 3})
, mSearchType(type)
, mScrapeCount(scrapeCount)
, mRefinedSearch(false)
, mFoundGame(false)
, mScrapeRatings(false)
, mBusyAnim(window)
{ {
addChild(&mGrid); addChild(&mGrid);
@ -784,7 +790,8 @@ void GuiScraperSearch::updateThumbnail()
} }
} }
void GuiScraperSearch::openInputScreen(ScraperSearchParams &params) { void GuiScraperSearch::openInputScreen(ScraperSearchParams& params)
{
auto searchForFunc = [&](std::string name) { auto searchForFunc = [&](std::string name) {
// Trim leading and trailing whitespaces. // Trim leading and trailing whitespaces.
name.erase(name.begin(), std::find_if(name.begin(), name.end(), [](char c) { name.erase(name.begin(), std::find_if(name.begin(), name.end(), [](char c) {
@ -810,7 +817,8 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams &params) {
// regardless of whether the entry is an arcade game and TheGamesDB is used. // regardless of whether the entry is an arcade game and TheGamesDB is used.
if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) { if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) {
searchString = Utils::String::removeParenthesis(params.game->metadata.get("name")); searchString = Utils::String::removeParenthesis(params.game->metadata.get("name"));
} else { }
else {
// If searching based on the actual file name, then expand to the full game name // If searching based on the actual file name, then expand to the full game name
// in case the scraper is set to TheGamesDB and it's an arcade game. This is // in case the scraper is set to TheGamesDB and it's an arcade game. This is
// required as TheGamesDB does not support searches using the short MAME names. // required as TheGamesDB does not support searches using the short MAME names.
@ -820,7 +828,8 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams &params) {
else else
searchString = params.game->getCleanName(); searchString = params.game->getCleanName();
} }
} else { }
else {
searchString = params.nameOverride; searchString = params.nameOverride;
} }
@ -828,7 +837,8 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams &params) {
mWindow->pushGui(new GuiTextEditKeyboardPopup(mWindow, getHelpStyle(), "REFINE SEARCH", mWindow->pushGui(new GuiTextEditKeyboardPopup(mWindow, getHelpStyle(), "REFINE SEARCH",
searchString, searchForFunc, false, "SEARCH", searchString, searchForFunc, false, "SEARCH",
"SEARCH USING REFINED NAME?")); "SEARCH USING REFINED NAME?"));
} else { }
else {
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), "REFINE SEARCH", mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), "REFINE SEARCH",
searchString, searchForFunc, false, "SEARCH", searchString, searchForFunc, false, "SEARCH",
"SEARCH USING REFINED NAME?")); "SEARCH USING REFINED NAME?"));
@ -918,7 +928,8 @@ bool GuiScraperSearch::saveMetadata(const ScraperSearchResult& result,
return metadataUpdated; return metadataUpdated;
} }
std::vector<HelpPrompt> GuiScraperSearch::getHelpPrompts() { std::vector<HelpPrompt> GuiScraperSearch::getHelpPrompts()
{
std::vector<HelpPrompt> prompts; std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("y", "refine search")); prompts.push_back(HelpPrompt("y", "refine search"));

View file

@ -64,11 +64,13 @@ public:
mAcceptCallback = acceptCallback; mAcceptCallback = acceptCallback;
} }
void setSkipCallback(const std::function<void()> &skipCallback) { void setSkipCallback(const std::function<void()>& skipCallback)
{
mSkipCallback = skipCallback; mSkipCallback = skipCallback;
} }
void setCancelCallback(const std::function<void()> &cancelCallback) { void setCancelCallback(const std::function<void()>& cancelCallback)
{
mCancelCallback = cancelCallback; mCancelCallback = cancelCallback;
} }
@ -84,7 +86,8 @@ public:
void onSizeChanged() override; void onSizeChanged() override;
void decreaseScrapeCount() { void decreaseScrapeCount()
{
if (mScrapeCount > 0) if (mScrapeCount > 0)
mScrapeCount--; mScrapeCount--;
} }

View file

@ -22,10 +22,20 @@
#include "views/gamelist/IGameListView.h" #include "views/gamelist/IGameListView.h"
GuiSettings::GuiSettings(Window* window, std::string title) GuiSettings::GuiSettings(Window* window, std::string title)
: GuiComponent(window), mMenu(window, title), mGoToSystem(nullptr), mNeedsSaving(false), : GuiComponent(window)
mNeedsReloadHelpPrompts(false), mNeedsCollectionsUpdate(false), mNeedsSorting(false), , mMenu(window, title)
mNeedsSortingCollections(false), mNeedsResetFilters(false), mNeedsReloading(false), mNeedsGoToStart(false), , mGoToSystem(nullptr)
mNeedsGoToSystem(false), mNeedsGoToGroupedCollections(false), mInvalidateCachedBackground(false) , mNeedsSaving(false)
, mNeedsReloadHelpPrompts(false)
, mNeedsCollectionsUpdate(false)
, mNeedsSorting(false)
, mNeedsSortingCollections(false)
, mNeedsResetFilters(false)
, mNeedsReloading(false)
, mNeedsGoToStart(false)
, mNeedsGoToSystem(false)
, mNeedsGoToGroupedCollections(false)
, mInvalidateCachedBackground(false)
{ {
addChild(&mMenu); addChild(&mMenu);
mMenu.addButton("BACK", "back", [this] { delete this; }); mMenu.addButton("BACK", "back", [this] { delete this; });
@ -174,10 +184,12 @@ void GuiSettings::addEditableTextComponent(const std::string label,
else if (isPassword && newVal == "") { else if (isPassword && newVal == "") {
ed->setValue(""); ed->setValue("");
ed->setHiddenValue(""); ed->setHiddenValue("");
} else if (isPassword) { }
else if (isPassword) {
ed->setValue("********"); ed->setValue("********");
ed->setHiddenValue(newVal); ed->setHiddenValue(newVal);
} else { }
else {
ed->setValue(newVal); ed->setValue(newVal);
} }
}; };
@ -193,7 +205,8 @@ void GuiSettings::addEditableTextComponent(const std::string label,
ed->getValue(), updateVal, false, ed->getValue(), updateVal, false,
"SAVE", "SAVE CHANGES?")); "SAVE", "SAVE CHANGES?"));
}); });
} else { }
else {
row.makeAcceptInputHandler([this, label, ed, updateVal, isPassword] { row.makeAcceptInputHandler([this, label, ed, updateVal, isPassword] {
if (isPassword) if (isPassword)
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), label, "", updateVal, mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(), label, "", updateVal,

View file

@ -147,7 +147,8 @@ void thegamesdb_generate_json_scraper_requests(
// using this regardless of whether the entry is an arcade game. // using this regardless of whether the entry is an arcade game.
if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) { if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) {
cleanName = Utils::String::removeParenthesis(params.game->metadata.get("name")); cleanName = Utils::String::removeParenthesis(params.game->metadata.get("name"));
} else { }
else {
// If not searching based on the metadata name, then check whether it's an // If not searching based on the metadata name, then check whether it's an
// arcade game and if so expand to the full game name. This is required as // arcade game and if so expand to the full game name. This is required as
// TheGamesDB has issues with searching using the short MAME names. // TheGamesDB has issues with searching using the short MAME names.

View file

@ -17,12 +17,32 @@
#define FADE_IN_TIME 650 #define FADE_IN_TIME 650
DetailedGameListView::DetailedGameListView(Window* window, FileData* root) DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
: BasicGameListView(window, root), mThumbnail(window), mMarquee(window), mImage(window), mLblRating(window), : BasicGameListView(window, root)
mLblReleaseDate(window), mLblDeveloper(window), mLblPublisher(window), mLblGenre(window), mLblPlayers(window), , mThumbnail(window)
mLblLastPlayed(window), mLblPlayCount(window), mBadges(window), mRating(window), mReleaseDate(window), , mMarquee(window)
mDeveloper(window), , mImage(window)
mPublisher(window), mGenre(window), mPlayers(window), mLastPlayed(window), mPlayCount(window), mName(window), , mLblRating(window)
mDescContainer(window), mDescription(window), mGamelistInfo(window), mLastUpdated(nullptr) , mLblReleaseDate(window)
, mLblDeveloper(window)
, mLblPublisher(window)
, mLblGenre(window)
, mLblPlayers(window)
, mLblLastPlayed(window)
, mLblPlayCount(window)
, mBadges(window)
, mRating(window)
, mReleaseDate(window)
, mDeveloper(window)
, mPublisher(window)
, mGenre(window)
, mPlayers(window)
, mLastPlayed(window)
, mPlayCount(window)
, mName(window)
, mDescContainer(window)
, mDescription(window)
, mGamelistInfo(window)
, mLastUpdated(nullptr)
{ {
const float padding = 0.01f; const float padding = 0.01f;
@ -111,7 +131,8 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
initMDValues(); initMDValues();
} }
void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme) { void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
{
BasicGameListView::onThemeChanged(theme); BasicGameListView::onThemeChanged(theme);
using namespace ThemeFlags; using namespace ThemeFlags;
@ -402,7 +423,8 @@ void DetailedGameListView::updateInfoPanel()
mLastPlayed.setValue(file->metadata.get("lastplayed")); mLastPlayed.setValue(file->metadata.get("lastplayed"));
mPlayCount.setValue(file->metadata.get("playcount")); mPlayCount.setValue(file->metadata.get("playcount"));
} }
} else if (file->getType() == FOLDER) { }
else if (file->getType() == FOLDER) {
if (!hideMetaDataFields) { if (!hideMetaDataFields) {
mLastPlayed.setValue(file->metadata.get("lastplayed")); mLastPlayed.setValue(file->metadata.get("lastplayed"));
mLblPlayCount.setVisible(false); mLblPlayCount.setVisible(false);

View file

@ -20,12 +20,31 @@
#define FADE_IN_TIME 650 #define FADE_IN_TIME 650
GridGameListView::GridGameListView(Window* window, FileData* root) GridGameListView::GridGameListView(Window* window, FileData* root)
: ISimpleGameListView(window, root), mGrid(window), mMarquee(window), mImage(window), mLblRating(window), : ISimpleGameListView(window, root)
mLblReleaseDate(window), mLblDeveloper(window), mLblPublisher(window), mLblGenre(window), mLblPlayers(window), , mGrid(window)
mLblLastPlayed(window), mLblPlayCount(window), mBadges(window), mRating(window), mReleaseDate(window), , mMarquee(window)
mDeveloper(window), , mImage(window)
mPublisher(window), mGenre(window), mPlayers(window), mLastPlayed(window), mPlayCount(window), mName(window), , mLblRating(window)
mDescContainer(window), mDescription(window), mGamelistInfo(window) , mLblReleaseDate(window)
, mLblDeveloper(window)
, mLblPublisher(window)
, mLblGenre(window)
, mLblPlayers(window)
, mLblLastPlayed(window)
, mLblPlayCount(window)
, mBadges(window)
, mRating(window)
, mReleaseDate(window)
, mDeveloper(window)
, mPublisher(window)
, mGenre(window)
, mPlayers(window)
, mLastPlayed(window)
, mPlayCount(window)
, mName(window)
, mDescContainer(window)
, mDescription(window)
, mGamelistInfo(window)
{ {
const float padding = 0.01f; const float padding = 0.01f;

View file

@ -17,10 +17,21 @@
#include <algorithm> #include <algorithm>
GuiComponent::GuiComponent(Window* window) GuiComponent::GuiComponent(Window* window)
: mWindow(window), mParent(nullptr), mOpacity(255), mColor(0), mSaturation(1.0f), mColorShift(0), : mWindow(window)
mColorShiftEnd(0), , mParent(nullptr)
mPosition({}), mOrigin({}), mRotationOrigin(0.5f, 0.5f), mSize({}), mIsProcessing(false), mVisible(true), , mOpacity(255)
mEnabled(true), mTransform(Renderer::getIdentity()) , mColor(0)
, mSaturation(1.0f)
, mColorShift(0)
, mColorShiftEnd(0)
, mPosition({})
, mOrigin({})
, mRotationOrigin(0.5f, 0.5f)
, mSize({})
, mIsProcessing(false)
, mVisible(true)
, mEnabled(true)
, mTransform(Renderer::getIdentity())
{ {
for (unsigned char i = 0; i < MAX_ANIMATIONS; i++) for (unsigned char i = 0; i < MAX_ANIMATIONS; i++)
mAnimationMap[i] = nullptr; mAnimationMap[i] = nullptr;

View file

@ -14,11 +14,12 @@
#include "resources/TextureResource.h" #include "resources/TextureResource.h"
// Available slot definitions. // Available slot definitions.
std::vector<std::string> BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN, std::vector<std::string> BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS,
SLOT_ALTERNATIVE_EMULATOR}; SLOT_BROKEN, SLOT_ALTERNATIVE_EMULATOR};
BadgesComponent::BadgesComponent(Window* window) BadgesComponent::BadgesComponent(Window* window)
: FlexboxComponent(window) { : FlexboxComponent(window)
{
mBadgeIcons = std::map<std::string, std::string>(); mBadgeIcons = std::map<std::string, std::string>();
mBadgeIcons[SLOT_FAVORITE] = ":/graphics/badge_favorite.svg"; mBadgeIcons[SLOT_FAVORITE] = ":/graphics/badge_favorite.svg";
@ -45,7 +46,8 @@ BadgesComponent::BadgesComponent(Window *window)
mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmu}); mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmu});
} }
BadgesComponent::~BadgesComponent() noexcept { BadgesComponent::~BadgesComponent() noexcept
{
for (GuiComponent* c : mChildren) for (GuiComponent* c : mChildren)
c->clearChildren(); c->clearChildren();
clearChildren(); clearChildren();
@ -53,8 +55,8 @@ BadgesComponent::~BadgesComponent() noexcept {
mImageComponents.clear(); mImageComponents.clear();
} }
void BadgesComponent::setValue(const std::string& value)
void BadgesComponent::setValue(const std::string &value) { {
mChildren.clear(); mChildren.clear();
if (!value.empty()) { if (!value.empty()) {
std::string temp; std::string temp;
@ -94,7 +96,8 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
bool imgChanged = false; bool imgChanged = false;
for (auto& slot : mSlots) { for (auto& slot : mSlots) {
if (properties & PATH && elem->has(slot) && mBadgeIcons[slot] != elem->get<std::string>(slot)) { if (properties & PATH && elem->has(slot) &&
mBadgeIcons[slot] != elem->get<std::string>(slot)) {
mBadgeIcons[slot] = elem->get<std::string>(slot); mBadgeIcons[slot] = elem->get<std::string>(slot);
mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot], false, true, true); mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot], false, true, true);
imgChanged = true; imgChanged = true;

View file

@ -18,9 +18,18 @@ ButtonComponent::ButtonComponent(Window *window,
const std::function<void()>& func, const std::function<void()>& func,
bool upperCase, bool upperCase,
bool flatStyle) bool flatStyle)
: GuiComponent{window}, mBox{window, ":/graphics/button.svg"}, mFont{Font::get(FONT_SIZE_MEDIUM)}, mPadding{{}}, : GuiComponent{window}
mFocused{false}, mEnabled{true}, mFlatStyle{flatStyle}, mTextColorFocused{0xFFFFFFFF}, , mBox{window, ":/graphics/button.svg"}
mTextColorUnfocused{0x777777FF}, mFlatColorFocused{0x878787FF}, mFlatColorUnfocused{0x60606025} { , mFont{Font::get(FONT_SIZE_MEDIUM)}
, mPadding{{}}
, mFocused{false}
, mEnabled{true}
, mFlatStyle{flatStyle}
, mTextColorFocused{0xFFFFFFFF}
, mTextColorUnfocused{0x777777FF}
, mFlatColorFocused{0x878787FF}
, mFlatColorUnfocused{0x60606025}
{
setPressedFunc(func); setPressedFunc(func);
setText(text, helpText, upperCase); setText(text, helpText, upperCase);
@ -28,7 +37,8 @@ ButtonComponent::ButtonComponent(Window *window,
updateImage(); updateImage();
} }
void ButtonComponent::onSizeChanged() { void ButtonComponent::onSizeChanged()
{
if (mFlatStyle) if (mFlatStyle)
return; return;
@ -39,19 +49,22 @@ void ButtonComponent::onSizeChanged() {
glm::vec2{-cornerSize.x * 2.0f, -cornerSize.y * 2.0f}); glm::vec2{-cornerSize.x * 2.0f, -cornerSize.y * 2.0f});
} }
void ButtonComponent::onFocusGained() { void ButtonComponent::onFocusGained()
{
mFocused = true; mFocused = true;
if (!mFlatStyle) if (!mFlatStyle)
updateImage(); updateImage();
} }
void ButtonComponent::onFocusLost() { void ButtonComponent::onFocusLost()
{
mFocused = false; mFocused = false;
if (!mFlatStyle) if (!mFlatStyle)
updateImage(); updateImage();
} }
void ButtonComponent::setText(const std::string &text, const std::string &helpText, bool upperCase) { void ButtonComponent::setText(const std::string& text, const std::string& helpText, bool upperCase)
{
mText = upperCase ? Utils::String::toUpper(text) : text; mText = upperCase ? Utils::String::toUpper(text) : text;
mHelpText = helpText; mHelpText = helpText;
@ -66,13 +79,15 @@ void ButtonComponent::setText(const std::string &text, const std::string &helpTe
updateHelpPrompts(); updateHelpPrompts();
} }
void ButtonComponent::setEnabled(bool state) { void ButtonComponent::setEnabled(bool state)
{
mEnabled = state; mEnabled = state;
if (!mFlatStyle) if (!mFlatStyle)
updateImage(); updateImage();
} }
void ButtonComponent::setPadding(const glm::vec4 padding) { void ButtonComponent::setPadding(const glm::vec4 padding)
{
if (mPadding == padding) if (mPadding == padding)
return; return;
@ -80,7 +95,8 @@ void ButtonComponent::setPadding(const glm::vec4 padding) {
onSizeChanged(); onSizeChanged();
} }
bool ButtonComponent::input(InputConfig *config, Input input) { bool ButtonComponent::input(InputConfig* config, Input input)
{
if (config->isMappedTo("a", input) && input.value != 0) { if (config->isMappedTo("a", input) && input.value != 0) {
if (mPressedFunc && mEnabled) if (mPressedFunc && mEnabled)
mPressedFunc(); mPressedFunc();
@ -90,7 +106,8 @@ bool ButtonComponent::input(InputConfig *config, Input input) {
return GuiComponent::input(config, input); return GuiComponent::input(config, input);
} }
void ButtonComponent::render(const glm::mat4 &parentTrans) { void ButtonComponent::render(const glm::mat4& parentTrans)
{
glm::mat4 trans{parentTrans * getTransform()}; glm::mat4 trans{parentTrans * getTransform()};
if (mFlatStyle) { if (mFlatStyle) {
@ -99,13 +116,15 @@ void ButtonComponent::render(const glm::mat4 &parentTrans) {
Renderer::drawRect(mPadding.x, mPadding.y, mSize.x - mPadding.x - mPadding.z, Renderer::drawRect(mPadding.x, mPadding.y, mSize.x - mPadding.x - mPadding.z,
mSize.y - mPadding.y - mPadding.w, mFlatColorFocused, mSize.y - mPadding.y - mPadding.w, mFlatColorFocused,
mFlatColorFocused); mFlatColorFocused);
} else { }
else {
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
Renderer::drawRect(mPadding.x, mPadding.y, mSize.x - mPadding.x - mPadding.z, Renderer::drawRect(mPadding.x, mPadding.y, mSize.x - mPadding.x - mPadding.z,
mSize.y - mPadding.y - mPadding.w, mFlatColorUnfocused, mSize.y - mPadding.y - mPadding.w, mFlatColorUnfocused,
mFlatColorUnfocused); mFlatColorUnfocused);
} }
} else { }
else {
mBox.render(trans); mBox.render(trans);
} }
@ -131,20 +150,23 @@ void ButtonComponent::render(const glm::mat4 &parentTrans) {
renderChildren(trans); renderChildren(trans);
} }
std::vector<HelpPrompt> ButtonComponent::getHelpPrompts() { std::vector<HelpPrompt> ButtonComponent::getHelpPrompts()
{
std::vector<HelpPrompt> prompts; std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("a", mHelpText.empty() ? mText.c_str() : mHelpText.c_str())); prompts.push_back(HelpPrompt("a", mHelpText.empty() ? mText.c_str() : mHelpText.c_str()));
return prompts; return prompts;
} }
unsigned int ButtonComponent::getCurTextColor() const { unsigned int ButtonComponent::getCurTextColor() const
{
if (!mFocused) if (!mFocused)
return mTextColorUnfocused; return mTextColorUnfocused;
else else
return mTextColorFocused; return mTextColorFocused;
} }
void ButtonComponent::updateImage() { void ButtonComponent::updateImage()
{
if (!mEnabled || !mPressedFunc) { if (!mEnabled || !mPressedFunc) {
mBox.setImagePath(":/graphics/button_filled.svg"); mBox.setImagePath(":/graphics/button_filled.svg");
mBox.setCenterColor(0x770000FF); mBox.setCenterColor(0x770000FF);

View file

@ -14,7 +14,8 @@
class TextCache; class TextCache;
class ButtonComponent : public GuiComponent { class ButtonComponent : public GuiComponent
{
public: public:
ButtonComponent(Window* window, ButtonComponent(Window* window,
const std::string& text = "", const std::string& text = "",

View file

@ -287,7 +287,8 @@ void ComponentGrid::resetCursor()
} }
} }
bool ComponentGrid::moveCursor(glm::ivec2 dir) { bool ComponentGrid::moveCursor(glm::ivec2 dir)
{
assert(dir.x || dir.y); assert(dir.x || dir.y);
const glm::ivec2 origCursor{mCursor}; const glm::ivec2 origCursor{mCursor};
@ -367,7 +368,8 @@ bool ComponentGrid::moveCursor(glm::ivec2 dir) {
return false; return false;
} }
void ComponentGrid::moveCursorTo(int xPos, int yPos, bool selectLeftCell) { void ComponentGrid::moveCursorTo(int xPos, int yPos, bool selectLeftCell)
{
const glm::ivec2 origCursor{mCursor}; const glm::ivec2 origCursor{mCursor};
if (xPos != -1) if (xPos != -1)
@ -384,13 +386,15 @@ void ComponentGrid::moveCursorTo(int xPos, int yPos, bool selectLeftCell) {
onCursorMoved(origCursor, mCursor); onCursorMoved(origCursor, mCursor);
} }
void ComponentGrid::onFocusLost() { void ComponentGrid::onFocusLost()
{
const GridEntry* cursorEntry = getCellAt(mCursor); const GridEntry* cursorEntry = getCellAt(mCursor);
if (cursorEntry) if (cursorEntry)
cursorEntry->component->onFocusLost(); cursorEntry->component->onFocusLost();
} }
void ComponentGrid::onFocusGained() { void ComponentGrid::onFocusGained()
{
const GridEntry* cursorEntry = getCellAt(mCursor); const GridEntry* cursorEntry = getCellAt(mCursor);
if (cursorEntry) if (cursorEntry)
cursorEntry->component->onFocusGained(); cursorEntry->component->onFocusGained();

View file

@ -30,7 +30,8 @@ namespace GridFlags
} // namespace GridFlags } // namespace GridFlags
// Provides basic layout of components in an X*Y grid. // Provides basic layout of components in an X*Y grid.
class ComponentGrid : public GuiComponent { class ComponentGrid : public GuiComponent
{
public: public:
ComponentGrid(Window* window, const glm::ivec2& gridDimensions); ComponentGrid(Window* window, const glm::ivec2& gridDimensions);
@ -46,7 +47,8 @@ public:
unsigned int border = GridFlags::BORDER_NONE, unsigned int border = GridFlags::BORDER_NONE,
GridFlags::UpdateType updateType = GridFlags::UPDATE_ALWAYS); GridFlags::UpdateType updateType = GridFlags::UPDATE_ALWAYS);
void setPastBoundaryCallback(const std::function<bool(InputConfig *config, Input input)> &func) { void setPastBoundaryCallback(const std::function<bool(InputConfig* config, Input input)>& func)
{
mPastBoundaryCallback = func; mPastBoundaryCallback = func;
} }
@ -82,7 +84,8 @@ public:
void setCursorTo(const std::shared_ptr<GuiComponent>& comp); void setCursorTo(const std::shared_ptr<GuiComponent>& comp);
std::shared_ptr<GuiComponent> getSelectedComponent() { std::shared_ptr<GuiComponent> getSelectedComponent()
{
const GridEntry* e = getCellAt(mCursor); const GridEntry* e = getCellAt(mCursor);
if (e) if (e)
return e->component; return e->component;

View file

@ -71,7 +71,8 @@ bool ComponentList::input(InputConfig* config, Input input)
if (mEntries.at(mCursor).data.input_handler) { if (mEntries.at(mCursor).data.input_handler) {
if (mEntries.at(mCursor).data.input_handler(config, input)) if (mEntries.at(mCursor).data.input_handler(config, input))
return true; return true;
} else { }
else {
// No input handler assigned, do the default, which is to give it // No input handler assigned, do the default, which is to give it
// to the rightmost element in the row. // to the rightmost element in the row.
auto& row = mEntries.at(mCursor).data; auto& row = mEntries.at(mCursor).data;

View file

@ -13,9 +13,16 @@
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
DateTimeEditComponent::DateTimeEditComponent(Window* window, bool alignRight, DisplayMode dispMode) DateTimeEditComponent::DateTimeEditComponent(Window* window, bool alignRight, DisplayMode dispMode)
: GuiComponent(window), mEditing(false), mEditIndex(0), mDisplayMode(dispMode), mRelativeUpdateAccumulator(0), : GuiComponent(window)
mColor(0x777777FF), mFont(Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT)), mAlignRight(alignRight), , mEditing(false)
mUppercase(false), mAutoSize(true) , mEditIndex(0)
, mDisplayMode(dispMode)
, mRelativeUpdateAccumulator(0)
, mColor(0x777777FF)
, mFont(Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT))
, mAlignRight(alignRight)
, mUppercase(false)
, mAutoSize(true)
{ {
updateTextCache(); updateTextCache();
} }

View file

@ -60,9 +60,7 @@ void FlexboxComponent::setItemWidth(float value)
} }
float FlexboxComponent::getItemWidth() { return mItemWidth; } float FlexboxComponent::getItemWidth() { return mItemWidth; }
void FlexboxComponent::onSizeChanged() { void FlexboxComponent::onSizeChanged() { mLayoutValid = false; }
mLayoutValid = false;
}
void FlexboxComponent::computeLayout() void FlexboxComponent::computeLayout()
{ {
@ -106,7 +104,8 @@ void FlexboxComponent::computeLayout()
if (mDirection == "row") { if (mDirection == "row") {
totalSize.x += (mItemMargin.x + mItemWidth) * mItemsPerLine; totalSize.x += (mItemMargin.x + mItemWidth) * mItemsPerLine;
totalSize.y += (mItemMargin.y + maxItemSize.y) * nLines; totalSize.y += (mItemMargin.y + maxItemSize.y) * nLines;
} else { }
else {
totalSize.x += (mItemMargin.x + mItemWidth) * nLines; totalSize.x += (mItemMargin.x + mItemWidth) * nLines;
totalSize.y += (mItemMargin.y + maxItemSize.y) * mItemsPerLine; totalSize.y += (mItemMargin.y + maxItemSize.y) * mItemsPerLine;
} }
@ -132,10 +131,12 @@ void FlexboxComponent::computeLayout()
if (mAlign == ITEM_ALIGN_END) { if (mAlign == ITEM_ALIGN_END) {
x += directionLine.x == 0 ? (maxItemSize.x - size.x) : 0; x += directionLine.x == 0 ? (maxItemSize.x - size.x) : 0;
y += directionLine.y == 0 ? (maxItemSize.y - size.y) : 0; y += directionLine.y == 0 ? (maxItemSize.y - size.y) : 0;
} else if (mAlign == ITEM_ALIGN_CENTER) { }
else if (mAlign == ITEM_ALIGN_CENTER) {
x += directionLine.x == 0 ? (maxItemSize.x - size.x) / 2 : 0; x += directionLine.x == 0 ? (maxItemSize.x - size.x) / 2 : 0;
y += directionLine.y == 0 ? (maxItemSize.y - size.y) / 2 : 0; y += directionLine.y == 0 ? (maxItemSize.y - size.y) / 2 : 0;
} else if (mAlign == ITEM_ALIGN_STRETCH && mDirection == "row") { }
else if (mAlign == ITEM_ALIGN_STRETCH && mDirection == "row") {
child->setSize(child->getSize().x, maxItemSize.y); child->setSize(child->getSize().x, maxItemSize.y);
} }
@ -159,7 +160,8 @@ void FlexboxComponent::computeLayout()
if (directionRow.x == 0) { if (directionRow.x == 0) {
anchorY += lineWidth * directionRow.y; anchorY += lineWidth * directionRow.y;
anchorX = anchorXStart; anchorX = anchorXStart;
} else { }
else {
anchorX += lineWidth * directionRow.x; anchorX += lineWidth * directionRow.x;
anchorY = anchorYStart; anchorY = anchorYStart;
} }
@ -169,7 +171,8 @@ void FlexboxComponent::computeLayout()
mLayoutValid = true; mLayoutValid = true;
} }
void FlexboxComponent::render(const glm::mat4& parentTrans) { void FlexboxComponent::render(const glm::mat4& parentTrans)
{
if (!isVisible()) if (!isVisible())
return; return;

View file

@ -28,10 +28,22 @@ glm::vec2 ImageComponent::getSize() const
} }
ImageComponent::ImageComponent(Window* window, bool forceLoad, bool dynamic) ImageComponent::ImageComponent(Window* window, bool forceLoad, bool dynamic)
: GuiComponent(window), mTargetSize({}), mFlipX(false), mFlipY(false), mTargetIsMax(false), mTargetIsMin(false), : GuiComponent(window)
mColorShift(0xFFFFFFFF), mColorShiftEnd(0xFFFFFFFF), mColorGradientHorizontal(true), mFadeOpacity(0), , mTargetSize({})
mFading(false), mForceLoad(forceLoad), mDynamic(dynamic), mRotateByTargetSize(false), mTopLeftCrop({}), , mFlipX(false)
mBottomRightCrop(1.0f, 1.0f) , mFlipY(false)
, mTargetIsMax(false)
, mTargetIsMin(false)
, mColorShift(0xFFFFFFFF)
, mColorShiftEnd(0xFFFFFFFF)
, mColorGradientHorizontal(true)
, mFadeOpacity(0)
, mFading(false)
, mForceLoad(forceLoad)
, mDynamic(dynamic)
, mRotateByTargetSize(false)
, mTopLeftCrop({})
, mBottomRightCrop(1.0f, 1.0f)
{ {
updateColors(); updateColors();
} }
@ -126,7 +138,8 @@ void ImageComponent::resize()
onSizeChanged(); onSizeChanged();
} }
void ImageComponent::setImage(std::string path, bool tile, bool linearMagnify, bool cacheImage) { void ImageComponent::setImage(std::string path, bool tile, bool linearMagnify, bool cacheImage)
{
// Always load bundled graphic resources statically, unless mForceLoad has been set. // Always load bundled graphic resources statically, unless mForceLoad has been set.
// This eliminates annoying texture pop-in problems that would otherwise occur. // This eliminates annoying texture pop-in problems that would otherwise occur.
if (!mForceLoad && (path[0] == ':') && (path[1] == '/')) { if (!mForceLoad && (path[0] == ':') && (path[1] == '/')) {
@ -137,11 +150,12 @@ void ImageComponent::setImage(std::string path, bool tile, bool linearMagnify, b
if (mDefaultPath.empty() || !ResourceManager::getInstance()->fileExists(mDefaultPath)) if (mDefaultPath.empty() || !ResourceManager::getInstance()->fileExists(mDefaultPath))
mTexture.reset(); mTexture.reset();
else else
mTexture = mTexture = TextureResource::get(mDefaultPath, tile, mForceLoad, mDynamic, linearMagnify,
TextureResource::get(mDefaultPath, tile, mForceLoad, mDynamic, linearMagnify, 1.0f, cacheImage); 1.0f, cacheImage);
} }
else { else {
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, linearMagnify, 1.0f, cacheImage); mTexture =
TextureResource::get(path, tile, mForceLoad, mDynamic, linearMagnify, 1.0f, cacheImage);
} }
resize(); resize();

View file

@ -14,7 +14,8 @@
class TextureResource; class TextureResource;
class ImageComponent : public GuiComponent { class ImageComponent : public GuiComponent
{
public: public:
ImageComponent(Window* window, bool forceLoad = false, bool dynamic = true); ImageComponent(Window* window, bool forceLoad = false, bool dynamic = true);
@ -24,7 +25,10 @@ public:
// Loads the image at the given filepath. Will tile if tile is true (retrieves texture // Loads the image at the given filepath. Will tile if tile is true (retrieves texture
// as tiling, creates vertices accordingly). // as tiling, creates vertices accordingly).
void setImage(std::string path, bool tile = false, bool linearMagnify = false, bool cacheSVG = false); void setImage(std::string path,
bool tile = false,
bool linearMagnify = false,
bool cacheSVG = false);
// Loads an image from memory. // Loads an image from memory.
void setImage(const char* data, size_t length, bool tile = false); void setImage(const char* data, size_t length, bool tile = false);

View file

@ -25,8 +25,12 @@ GuiMsgBox::GuiMsgBox(Window* window,
const std::function<void()>& func3, const std::function<void()>& func3,
bool disableBackButton, bool disableBackButton,
bool deleteOnButtonPress) bool deleteOnButtonPress)
: GuiComponent(window), mBackground(window, ":/graphics/frame.svg"), mGrid(window, glm::ivec2{1, 2}), : GuiComponent(window)
mHelpStyle(helpstyle), mDisableBackButton(disableBackButton), mDeleteOnButtonPress(deleteOnButtonPress) , mBackground(window, ":/graphics/frame.svg")
, mGrid(window, glm::ivec2{1, 2})
, mHelpStyle(helpstyle)
, mDisableBackButton(disableBackButton)
, mDeleteOnButtonPress(deleteOnButtonPress)
{ {
// Adjust the width relative to the aspect ratio of the screen to make the GUI look coherent // Adjust the width relative to the aspect ratio of the screen to make the GUI look coherent
// regardless of screen type. The 1.778 aspect ratio value is the 16:9 reference. // regardless of screen type. The 1.778 aspect ratio value is the 16:9 reference.

View file

@ -87,13 +87,27 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
const std::string& loadBtnHelpText, const std::string& loadBtnHelpText,
const std::string& clearBtnHelpText, const std::string& clearBtnHelpText,
const std::string& cancelBtnHelpText) const std::string& cancelBtnHelpText)
: GuiComponent{window}, mBackground{window, ":/graphics/frame.svg"}, : GuiComponent{window}
mGrid{window, glm::ivec2{1, (infoString != "" && defaultValue != "" ? 8 : 6)}}, mHelpStyle{helpstyle}, , mBackground{window, ":/graphics/frame.svg"}
mInitValue{initValue}, mAcceptBtnHelpText{acceptBtnHelpText}, mSaveConfirmationText{saveConfirmationText}, , mGrid{window, glm::ivec2{1, (infoString != "" && defaultValue != "" ? 8 : 6)}}
mLoadBtnHelpText{loadBtnHelpText}, mClearBtnHelpText{clearBtnHelpText}, mCancelBtnHelpText{cancelBtnHelpText}, , mHelpStyle{helpstyle}
mOkCallback{okCallback}, mMultiLine{multiLine}, mComplexMode{(infoString != "" && defaultValue != "")}, , mInitValue{initValue}
mDeleteRepeat{false}, mShift{false}, mAlt{false}, mDeleteRepeatTimer{0}, mNavigationRepeatTimer{0}, , mAcceptBtnHelpText{acceptBtnHelpText}
mNavigationRepeatDirX{0}, mNavigationRepeatDirY{0} { , mSaveConfirmationText{saveConfirmationText}
, mLoadBtnHelpText{loadBtnHelpText}
, mClearBtnHelpText{clearBtnHelpText}
, mCancelBtnHelpText{cancelBtnHelpText}
, mOkCallback{okCallback}
, mMultiLine{multiLine}
, mComplexMode{(infoString != "" && defaultValue != "")}
, mDeleteRepeat{false}
, mShift{false}
, mAlt{false}
, mDeleteRepeatTimer{0}
, mNavigationRepeatTimer{0}
, mNavigationRepeatDirX{0}
, mNavigationRepeatDirY{0}
{
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);
@ -164,17 +178,20 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
upper = DELETE_SYMBOL; upper = DELETE_SYMBOL;
alted = DELETE_SYMBOL; alted = DELETE_SYMBOL;
altshifted = DELETE_SYMBOL; altshifted = DELETE_SYMBOL;
} else if (lower == "OK") { }
else if (lower == "OK") {
lower = OK_SYMBOL; lower = OK_SYMBOL;
upper = OK_SYMBOL; upper = OK_SYMBOL;
alted = OK_SYMBOL; alted = OK_SYMBOL;
altshifted = OK_SYMBOL; altshifted = OK_SYMBOL;
} else if (lower == "SPACE") { }
else if (lower == "SPACE") {
lower = " "; lower = " ";
upper = " "; upper = " ";
alted = " "; alted = " ";
altshifted = " "; altshifted = " ";
} else if (lower != "SHIFT" && lower.length() > 1) { }
else if (lower != "SHIFT" && lower.length() > 1) {
lower = (lower.c_str()); lower = (lower.c_str());
upper = (upper.c_str()); upper = (upper.c_str());
alted = (alted.c_str()); alted = (alted.c_str());
@ -185,11 +202,13 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
mShiftButton = std::make_shared<ButtonComponent>( mShiftButton = std::make_shared<ButtonComponent>(
mWindow, (SHIFT_SYMBOL), ("SHIFT"), [this] { shiftKeys(); }, false, true); mWindow, (SHIFT_SYMBOL), ("SHIFT"), [this] { shiftKeys(); }, false, true);
button = mShiftButton; button = mShiftButton;
} else if (lower == "ALT") { }
else if (lower == "ALT") {
mAltButton = std::make_shared<ButtonComponent>( mAltButton = std::make_shared<ButtonComponent>(
mWindow, (ALT_SYMBOL), ("ALT"), [this] { altKeys(); }, false, true); mWindow, (ALT_SYMBOL), ("ALT"), [this] { altKeys(); }, false, true);
button = mAltButton; button = mAltButton;
} else { }
else {
button = makeButton(lower, upper, alted, altshifted); button = makeButton(lower, upper, alted, altshifted);
} }
@ -239,7 +258,8 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
mKeyboardGrid->moveCursorTo(mHorizontalKeyCount - 1, -1, true); mKeyboardGrid->moveCursorTo(mHorizontalKeyCount - 1, -1, true);
return true; return true;
} }
} else if (config->isMappedLike("right", input)) { }
else if (config->isMappedLike("right", input)) {
if (mGrid.getSelectedComponent() == mKeyboardGrid) { if (mGrid.getSelectedComponent() == mKeyboardGrid) {
mKeyboardGrid->moveCursorTo(0, -1); mKeyboardGrid->moveCursorTo(0, -1);
return true; return true;
@ -259,7 +279,8 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
setPosition((static_cast<float>(Renderer::getScreenWidth()) - mSize.x) / 2.0f, setPosition((static_cast<float>(Renderer::getScreenWidth()) - mSize.x) / 2.0f,
(static_cast<float>(Renderer::getScreenHeight()) - mSize.y) / 2.0f); (static_cast<float>(Renderer::getScreenHeight()) - mSize.y) / 2.0f);
} else { }
else {
if (mComplexMode) if (mComplexMode)
setSize(width, KEYBOARD_HEIGHT + mDefaultValue->getSize().y * 3.0f); setSize(width, KEYBOARD_HEIGHT + mDefaultValue->getSize().y * 3.0f);
else else
@ -270,7 +291,8 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
} }
} }
void GuiTextEditKeyboardPopup::onSizeChanged() { void GuiTextEditKeyboardPopup::onSizeChanged()
{
mBackground.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f}); mBackground.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
mText->setSize(mSize.x - KEYBOARD_PADDINGX - KEYBOARD_PADDINGX, mText->getSize().y); mText->setSize(mSize.x - KEYBOARD_PADDINGX - KEYBOARD_PADDINGX, mText->getSize().y);
@ -281,7 +303,8 @@ void GuiTextEditKeyboardPopup::onSizeChanged() {
mGrid.setRowHeightPerc(1, (mInfoString->getSize().y * 0.6f) / mSize.y); mGrid.setRowHeightPerc(1, (mInfoString->getSize().y * 0.6f) / mSize.y);
mGrid.setRowHeightPerc(2, (mDefaultValue->getSize().y * 1.6f) / mSize.y); mGrid.setRowHeightPerc(2, (mDefaultValue->getSize().y * 1.6f) / mSize.y);
mGrid.setRowHeightPerc(1, (mText->getSize().y * 1.0f) / mSize.y); mGrid.setRowHeightPerc(1, (mText->getSize().y * 1.0f) / mSize.y);
} else if (mMultiLine) { }
else if (mMultiLine) {
mGrid.setRowHeightPerc(1, (mText->getSize().y * 1.15f) / mSize.y); mGrid.setRowHeightPerc(1, (mText->getSize().y * 1.15f) / mSize.y);
} }
@ -296,7 +319,8 @@ void GuiTextEditKeyboardPopup::onSizeChanged() {
mKeyboardGrid->setPosition(KEYBOARD_PADDINGX, pos.y); mKeyboardGrid->setPosition(KEYBOARD_PADDINGX, pos.y);
} }
bool GuiTextEditKeyboardPopup::input(InputConfig *config, Input input) { bool GuiTextEditKeyboardPopup::input(InputConfig* config, Input input)
{
// Enter/return key or numpad enter key accepts the changes. // Enter/return key or numpad enter key accepts the changes.
if (config->getDeviceId() == DEVICE_KEYBOARD && mText->isEditing() && !mMultiLine && if (config->getDeviceId() == DEVICE_KEYBOARD && mText->isEditing() && !mMultiLine &&
input.value && (input.id == SDLK_RETURN || input.id == SDLK_KP_ENTER)) { input.value && (input.id == SDLK_RETURN || input.id == SDLK_KP_ENTER)) {
@ -341,7 +365,8 @@ bool GuiTextEditKeyboardPopup::input(InputConfig *config, Input input) {
delete this; delete this;
return true; return true;
})); }));
} else { }
else {
delete this; delete this;
return true; return true;
} }
@ -374,7 +399,8 @@ bool GuiTextEditKeyboardPopup::input(InputConfig *config, Input input) {
if (!editing) if (!editing)
mText->stopEditing(); mText->stopEditing();
} else { }
else {
mDeleteRepeat = false; mDeleteRepeat = false;
} }
return true; return true;
@ -400,7 +426,8 @@ bool GuiTextEditKeyboardPopup::input(InputConfig *config, Input input) {
if (input.value) { if (input.value) {
mNavigationRepeatDirX = -1; mNavigationRepeatDirX = -1;
mNavigationRepeatTimer = -(NAVIGATION_REPEAT_START_DELAY - NAVIGATION_REPEAT_SPEED); mNavigationRepeatTimer = -(NAVIGATION_REPEAT_START_DELAY - NAVIGATION_REPEAT_SPEED);
} else { }
else {
mNavigationRepeatDirX = 0; mNavigationRepeatDirX = 0;
} }
} }
@ -409,7 +436,8 @@ bool GuiTextEditKeyboardPopup::input(InputConfig *config, Input input) {
if (input.value) { if (input.value) {
mNavigationRepeatDirX = 1; mNavigationRepeatDirX = 1;
mNavigationRepeatTimer = -(NAVIGATION_REPEAT_START_DELAY - NAVIGATION_REPEAT_SPEED); mNavigationRepeatTimer = -(NAVIGATION_REPEAT_START_DELAY - NAVIGATION_REPEAT_SPEED);
} else { }
else {
mNavigationRepeatDirX = 0; mNavigationRepeatDirX = 0;
} }
} }
@ -418,7 +446,8 @@ bool GuiTextEditKeyboardPopup::input(InputConfig *config, Input input) {
if (input.value) { if (input.value) {
mNavigationRepeatDirY = -1; mNavigationRepeatDirY = -1;
mNavigationRepeatTimer = -(NAVIGATION_REPEAT_START_DELAY - NAVIGATION_REPEAT_SPEED); mNavigationRepeatTimer = -(NAVIGATION_REPEAT_START_DELAY - NAVIGATION_REPEAT_SPEED);
} else { }
else {
mNavigationRepeatDirY = 0; mNavigationRepeatDirY = 0;
} }
} }
@ -427,7 +456,8 @@ bool GuiTextEditKeyboardPopup::input(InputConfig *config, Input input) {
if (input.value) { if (input.value) {
mNavigationRepeatDirY = 1; mNavigationRepeatDirY = 1;
mNavigationRepeatTimer = -(NAVIGATION_REPEAT_START_DELAY - NAVIGATION_REPEAT_SPEED); mNavigationRepeatTimer = -(NAVIGATION_REPEAT_START_DELAY - NAVIGATION_REPEAT_SPEED);
} else { }
else {
mNavigationRepeatDirY = 0; mNavigationRepeatDirY = 0;
} }
} }
@ -438,19 +468,22 @@ bool GuiTextEditKeyboardPopup::input(InputConfig *config, Input input) {
return false; return false;
} }
void GuiTextEditKeyboardPopup::update(int deltaTime) { void GuiTextEditKeyboardPopup::update(int deltaTime)
{
updateNavigationRepeat(deltaTime); updateNavigationRepeat(deltaTime);
updateDeleteRepeat(deltaTime); updateDeleteRepeat(deltaTime);
GuiComponent::update(deltaTime); GuiComponent::update(deltaTime);
} }
std::vector<HelpPrompt> GuiTextEditKeyboardPopup::getHelpPrompts() { std::vector<HelpPrompt> GuiTextEditKeyboardPopup::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts(); std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
if (!mText->isEditing()) { if (!mText->isEditing()) {
prompts.push_back(HelpPrompt("lt", "shift")); prompts.push_back(HelpPrompt("lt", "shift"));
prompts.push_back(HelpPrompt("rt", "alt")); prompts.push_back(HelpPrompt("rt", "alt"));
} else { }
else {
prompts.push_back(HelpPrompt("a", mAcceptBtnHelpText)); prompts.push_back(HelpPrompt("a", mAcceptBtnHelpText));
} }
@ -480,7 +513,8 @@ std::vector<HelpPrompt> GuiTextEditKeyboardPopup::getHelpPrompts() {
return prompts; return prompts;
} }
void GuiTextEditKeyboardPopup::updateDeleteRepeat(int deltaTime) { void GuiTextEditKeyboardPopup::updateDeleteRepeat(int deltaTime)
{
if (!mDeleteRepeat) if (!mDeleteRepeat)
return; return;
@ -500,7 +534,8 @@ void GuiTextEditKeyboardPopup::updateDeleteRepeat(int deltaTime) {
} }
} }
void GuiTextEditKeyboardPopup::updateNavigationRepeat(int deltaTime) { void GuiTextEditKeyboardPopup::updateNavigationRepeat(int deltaTime)
{
if (mNavigationRepeatDirX == 0 && mNavigationRepeatDirY == 0) if (mNavigationRepeatDirX == 0 && mNavigationRepeatDirY == 0)
return; return;
@ -527,13 +562,15 @@ void GuiTextEditKeyboardPopup::updateNavigationRepeat(int deltaTime) {
} }
} }
void GuiTextEditKeyboardPopup::shiftKeys() { void GuiTextEditKeyboardPopup::shiftKeys()
{
mShift = !mShift; mShift = !mShift;
if (mShift) { if (mShift) {
mShiftButton->setFlatColorFocused(0xFF2222FF); mShiftButton->setFlatColorFocused(0xFF2222FF);
mShiftButton->setFlatColorUnfocused(0xFF2222FF); mShiftButton->setFlatColorUnfocused(0xFF2222FF);
} else { }
else {
mShiftButton->setFlatColorFocused(0x878787FF); mShiftButton->setFlatColorFocused(0x878787FF);
mShiftButton->setFlatColorUnfocused(0x60606025); mShiftButton->setFlatColorUnfocused(0x60606025);
} }
@ -547,7 +584,8 @@ void GuiTextEditKeyboardPopup::shiftKeys() {
if (mAlt) { if (mAlt) {
altKeys(); altKeys();
altKeys(); altKeys();
} else { }
else {
for (auto& kb : mKeyboardButtons) { for (auto& kb : mKeyboardButtons) {
const std::string& text = mShift ? kb.shiftedKey : kb.key; const std::string& text = mShift ? kb.shiftedKey : kb.key;
auto sz = kb.button->getSize(); auto sz = kb.button->getSize();
@ -557,13 +595,15 @@ void GuiTextEditKeyboardPopup::shiftKeys() {
} }
} }
void GuiTextEditKeyboardPopup::altKeys() { void GuiTextEditKeyboardPopup::altKeys()
{
mAlt = !mAlt; mAlt = !mAlt;
if (mAlt) { if (mAlt) {
mAltButton->setFlatColorFocused(0xFF2222FF); mAltButton->setFlatColorFocused(0xFF2222FF);
mAltButton->setFlatColorUnfocused(0xFF2222FF); mAltButton->setFlatColorUnfocused(0xFF2222FF);
} else { }
else {
mAltButton->setFlatColorFocused(0x878787FF); mAltButton->setFlatColorFocused(0x878787FF);
mAltButton->setFlatColorUnfocused(0x60606025); mAltButton->setFlatColorUnfocused(0x60606025);
} }
@ -577,7 +617,8 @@ void GuiTextEditKeyboardPopup::altKeys() {
if (mShift) { if (mShift) {
shiftKeys(); shiftKeys();
shiftKeys(); shiftKeys();
} else { }
else {
for (auto& kb : mKeyboardButtons) { for (auto& kb : mKeyboardButtons) {
const std::string& text = mAlt ? kb.altedKey : kb.key; const std::string& text = mAlt ? kb.altedKey : kb.key;
auto sz = kb.button->getSize(); auto sz = kb.button->getSize();
@ -587,7 +628,8 @@ void GuiTextEditKeyboardPopup::altKeys() {
} }
} }
void GuiTextEditKeyboardPopup::altShiftKeys() { void GuiTextEditKeyboardPopup::altShiftKeys()
{
for (auto& kb : mKeyboardButtons) { for (auto& kb : mKeyboardButtons) {
const std::string& text = kb.altshiftedKey; const std::string& text = kb.altshiftedKey;
auto sz = kb.button->getSize(); auto sz = kb.button->getSize();
@ -600,7 +642,8 @@ std::shared_ptr<ButtonComponent> GuiTextEditKeyboardPopup::makeButton(
const std::string& key, const std::string& key,
const std::string& shiftedKey, const std::string& shiftedKey,
const std::string& altedKey, const std::string& altedKey,
const std::string &altshiftedKey) { const std::string& altshiftedKey)
{
std::shared_ptr<ButtonComponent> button = std::make_shared<ButtonComponent>( std::shared_ptr<ButtonComponent> button = std::make_shared<ButtonComponent>(
mWindow, key, key, mWindow, key, key,
[this, key, shiftedKey, altedKey, altshiftedKey] { [this, key, shiftedKey, altedKey, altshiftedKey] {
@ -608,24 +651,29 @@ std::shared_ptr<ButtonComponent> GuiTextEditKeyboardPopup::makeButton(
mOkCallback(mText->getValue()); mOkCallback(mText->getValue());
delete this; delete this;
return; return;
} else if (key == (DELETE_SYMBOL) || key == "DEL") { }
else if (key == (DELETE_SYMBOL) || key == "DEL") {
mText->startEditing(); mText->startEditing();
mText->textInput("\b"); mText->textInput("\b");
mText->stopEditing(); mText->stopEditing();
return; return;
} else if (key == "SPACE" || key == " ") { }
else if (key == "SPACE" || key == " ") {
mText->startEditing(); mText->startEditing();
mText->textInput(" "); mText->textInput(" ");
mText->stopEditing(); mText->stopEditing();
return; return;
} else if (key == "LOAD") { }
else if (key == "LOAD") {
mText->setValue(mDefaultValue->getValue()); mText->setValue(mDefaultValue->getValue());
mText->setCursor(mDefaultValue->getValue().size()); mText->setCursor(mDefaultValue->getValue().size());
return; return;
} else if (key == "CLEAR") { }
else if (key == "CLEAR") {
mText->setValue(""); mText->setValue("");
return; return;
} else if (key == "CANCEL") { }
else if (key == "CANCEL") {
delete this; delete this;
return; return;
} }

View file

@ -15,7 +15,8 @@
#include "components/ComponentGrid.h" #include "components/ComponentGrid.h"
#include "components/TextEditComponent.h" #include "components/TextEditComponent.h"
class GuiTextEditKeyboardPopup : public GuiComponent { class GuiTextEditKeyboardPopup : public GuiComponent
{
public: public:
GuiTextEditKeyboardPopup(Window* window, GuiTextEditKeyboardPopup(Window* window,
const HelpStyle& helpstyle, const HelpStyle& helpstyle,
@ -42,7 +43,8 @@ public:
HelpStyle getHelpStyle() override { return mHelpStyle; } HelpStyle getHelpStyle() override { return mHelpStyle; }
private: private:
class KeyboardButton { class KeyboardButton
{
public: public:
std::shared_ptr<ButtonComponent> button; std::shared_ptr<ButtonComponent> button;
const std::string key; const std::string key;
@ -55,7 +57,11 @@ private:
const std::string& sk, const std::string& sk,
const std::string& ak, const std::string& ak,
const std::string& ask) const std::string& ask)
: button{b}, key{k}, shiftedKey{sk}, altedKey{ak}, altshiftedKey{ask} {}; : button{b}
, key{k}
, shiftedKey{sk}
, altedKey{ak}
, altshiftedKey{ask} {};
}; };
void updateDeleteRepeat(int deltaTime); void updateDeleteRepeat(int deltaTime);

View file

@ -28,12 +28,22 @@ GuiTextEditPopup::GuiTextEditPopup(Window *window,
const std::string& loadBtnHelpText, const std::string& loadBtnHelpText,
const std::string& clearBtnHelpText, const std::string& clearBtnHelpText,
const std::string& cancelBtnHelpText) const std::string& cancelBtnHelpText)
: GuiComponent{window}, mBackground{window, ":/graphics/frame.svg"}, : GuiComponent{window}
mGrid{window, glm::ivec2{1, (infoString != "" && defaultValue != "" ? 5 : 3)}}, mHelpStyle{helpstyle}, , mBackground{window, ":/graphics/frame.svg"}
mInitValue{initValue}, mAcceptBtnText{acceptBtnText}, mSaveConfirmationText{saveConfirmationText}, , mGrid{window, glm::ivec2{1, (infoString != "" && defaultValue != "" ? 5 : 3)}}
mLoadBtnHelpText{loadBtnHelpText}, mClearBtnHelpText{clearBtnHelpText}, mCancelBtnHelpText{cancelBtnHelpText}, , mHelpStyle{helpstyle}
mOkCallback{okCallback}, mMultiLine{multiLine}, mComplexMode{(infoString != "" && defaultValue != "")}, , mInitValue{initValue}
mDeleteRepeat{false}, mDeleteRepeatTimer{0} { , mAcceptBtnText{acceptBtnText}
, mSaveConfirmationText{saveConfirmationText}
, mLoadBtnHelpText{loadBtnHelpText}
, mClearBtnHelpText{clearBtnHelpText}
, mCancelBtnHelpText{cancelBtnHelpText}
, mOkCallback{okCallback}
, mMultiLine{multiLine}
, mComplexMode{(infoString != "" && defaultValue != "")}
, mDeleteRepeat{false}
, mDeleteRepeatTimer{0}
{
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);
@ -109,7 +119,8 @@ GuiTextEditPopup::GuiTextEditPopup(Window *window,
mButtonGrid->getSize().y + mButtonGrid->getSize().y * 1.85f); mButtonGrid->getSize().y + mButtonGrid->getSize().y * 1.85f);
setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f,
(Renderer::getScreenHeight() - mSize.y) / 2.0f); (Renderer::getScreenHeight() - mSize.y) / 2.0f);
} else { }
else {
float width = glm::clamp(0.54f * aspectValue, 0.20f, 0.70f) * Renderer::getScreenWidth(); float width = glm::clamp(0.54f * aspectValue, 0.20f, 0.70f) * Renderer::getScreenWidth();
setSize(width, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y + setSize(width, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y +
@ -124,7 +135,8 @@ GuiTextEditPopup::GuiTextEditPopup(Window *window,
mText->startEditing(); mText->startEditing();
} }
void GuiTextEditPopup::onSizeChanged() { void GuiTextEditPopup::onSizeChanged()
{
mBackground.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f}); mBackground.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
mText->setSize(mSize.x - 40.0f * Renderer::getScreenHeightModifier(), mText->getSize().y); mText->setSize(mSize.x - 40.0f * Renderer::getScreenHeightModifier(), mText->getSize().y);
@ -138,7 +150,8 @@ void GuiTextEditPopup::onSizeChanged() {
mGrid.setSize(mSize); mGrid.setSize(mSize);
} }
bool GuiTextEditPopup::input(InputConfig *config, Input input) { bool GuiTextEditPopup::input(InputConfig* config, Input input)
{
// Enter key (main key or via numpad) accepts the changes. // Enter key (main key or via numpad) accepts the changes.
if (config->getDeviceId() == DEVICE_KEYBOARD && mText->isEditing() && !mMultiLine && if (config->getDeviceId() == DEVICE_KEYBOARD && mText->isEditing() && !mMultiLine &&
input.value && (input.id == SDLK_RETURN || input.id == SDLK_KP_ENTER)) { input.value && (input.id == SDLK_RETURN || input.id == SDLK_KP_ENTER)) {
@ -177,7 +190,8 @@ bool GuiTextEditPopup::input(InputConfig *config, Input input) {
delete this; delete this;
return true; return true;
})); }));
} else { }
else {
delete this; delete this;
return true; return true;
} }
@ -202,7 +216,8 @@ bool GuiTextEditPopup::input(InputConfig *config, Input input) {
if (!editing) if (!editing)
mText->stopEditing(); mText->stopEditing();
} else { }
else {
mDeleteRepeat = false; mDeleteRepeat = false;
} }
return true; return true;
@ -228,12 +243,14 @@ bool GuiTextEditPopup::input(InputConfig *config, Input input) {
return false; return false;
} }
void GuiTextEditPopup::update(int deltaTime) { void GuiTextEditPopup::update(int deltaTime)
{
updateDeleteRepeat(deltaTime); updateDeleteRepeat(deltaTime);
GuiComponent::update(deltaTime); GuiComponent::update(deltaTime);
} }
std::vector<HelpPrompt> GuiTextEditPopup::getHelpPrompts() { std::vector<HelpPrompt> GuiTextEditPopup::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts(); std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
if (mText->isEditing()) if (mText->isEditing())
@ -245,7 +262,8 @@ std::vector<HelpPrompt> GuiTextEditPopup::getHelpPrompts() {
return prompts; return prompts;
} }
void GuiTextEditPopup::updateDeleteRepeat(int deltaTime) { void GuiTextEditPopup::updateDeleteRepeat(int deltaTime)
{
if (!mDeleteRepeat) if (!mDeleteRepeat)
return; return;

View file

@ -15,7 +15,8 @@
#include "components/ComponentGrid.h" #include "components/ComponentGrid.h"
#include "components/TextEditComponent.h" #include "components/TextEditComponent.h"
class GuiTextEditPopup : public GuiComponent { class GuiTextEditPopup : public GuiComponent
{
public: public:
GuiTextEditPopup(Window* window, GuiTextEditPopup(Window* window,
const HelpStyle& helpstyle, const HelpStyle& helpstyle,