Added support for per-game launch string override (emulator override), configurable in the game meta data edit screen

This commit is contained in:
Leon Styhre 2020-05-19 17:52:11 +02:00
parent fbec408dfa
commit f806285e06
9 changed files with 201 additions and 27 deletions

View file

@ -344,7 +344,17 @@ void FileData::launchGame(Window* window)
// window->deinit();
std::string command = mEnvData->mLaunchCommand;
std::string command = "";
// Check if there is a launch string override for the game and the corresponding option has been set
if(Settings::getInstance()->getBool("LaunchstringOverride") && !metadata.get("launchstring").empty())
{
command = metadata.get("launchstring");
}
else
{
command = mEnvData->mLaunchCommand;
}
const std::string rom = Utils::FileSystem::getEscapedPath(getPath());
const std::string basename = Utils::FileSystem::getStem(getPath());

View file

@ -19,7 +19,7 @@ MetaDataDecl gameDecls[] = {
{"completed", MD_BOOL, "false", false, "completed", "enter completed off/on"},
{"hidden", MD_BOOL, "false", false, "hidden", "enter hidden off/on"},
{"kidgame", MD_BOOL, "false", false, "kidgame", "enter kidgame off/on"},
{"launcher", MD_STRING, "", false, "launcher", "enter launcher override"},
{"launchstring", MD_LAUNCHSTRING, "", false, "launch string", "enter game launch string (emulator override)"},
{"playcount", MD_INT, "0", false, "play count", "enter number of times played"},
{"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"}

View file

@ -17,6 +17,7 @@ enum MetaDataType
//specialized types
MD_MULTILINE_STRING,
MD_LAUNCHSTRING,
MD_PATH,
MD_RATING,
MD_DATE,

View file

@ -470,6 +470,12 @@ void GuiMenu::openOtherSettings()
s->addWithLabel("SEARCH FOR LOCAL ART", local_art);
s->addSaveFunc([local_art] { Settings::getInstance()->setBool("LocalArt", local_art->getState()); });
// Allow overriding of the launch string per game (the option to disable this is intended primarily for testing purposes)
auto launchstring_override = std::make_shared<SwitchComponent>(mWindow);
launchstring_override->setState(Settings::getInstance()->getBool("LaunchstringOverride"));
s->addWithLabel("PER GAME OVERRIDE OF LAUNCH STRING", launchstring_override);
s->addSaveFunc([launchstring_override] { Settings::getInstance()->setBool("LaunchstringOverride", launchstring_override->getState()); });
// hidden files
auto hidden_files = std::make_shared<SwitchComponent>(mWindow);
hidden_files->setState(Settings::getInstance()->getBool("ShowHiddenFiles"));

View file

@ -10,6 +10,7 @@
#include "guis/GuiGameScraper.h"
#include "guis/GuiMsgBox.h"
#include "guis/GuiTextEditPopup.h"
#include "guis/GuiComplexTextEditPopup.h"
#include "resources/Font.h"
#include "utils/StringUtil.h"
#include "views/ViewController.h"
@ -55,6 +56,17 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector
if(iter->isStatistic)
continue;
// Don't show the launch string override entry if this option has been disabled in the settings
if(!Settings::getInstance()->getBool("LaunchstringOverride") && iter->type == MD_LAUNCHSTRING)
{
ed = std::make_shared<TextComponent>(window, "", Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT), 0x777777FF, ALIGN_RIGHT);
assert(ed);
ed->setValue(mMetaData->get(iter->key));
mEditors.push_back(ed);
continue;
}
// create ed and add it (and any related components) to mMenu
// ed's value will be set below
ComponentListRow row;
@ -105,6 +117,32 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector
row.addElement(ed, false);
break;
}
case MD_LAUNCHSTRING:
{
ed = std::make_shared<TextComponent>(window, "", Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT), 0x777777FF, ALIGN_RIGHT);
row.addElement(ed, true);
auto spacer = std::make_shared<GuiComponent>(mWindow);
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0);
row.addElement(spacer, false);
auto bracket = std::make_shared<ImageComponent>(mWindow);
bracket->setImage(":/arrow.svg");
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
row.addElement(bracket, false);
bool multiLine = false;
const std::string title = iter->displayPrompt;
auto updateVal = [ed](const std::string& newVal) { ed->setValue(newVal); }; // ok callback (apply new value to ed)
std::string staticTextString = "Default value from es_systems.cfg:";
std::string defaultLaunchString = scraperParams.system->getSystemEnvData()->mLaunchCommand;
row.makeAcceptInputHandler([this, title, staticTextString, defaultLaunchString, ed, updateVal, multiLine] {
mWindow->pushGui(new GuiComplexTextEditPopup(mWindow, title, staticTextString, defaultLaunchString, ed->getValue(), updateVal, multiLine));
});
break;
}
case MD_MULTILINE_STRING:
default:
{
@ -188,6 +226,7 @@ void GuiMetaDataEd::save()
{
if(mMetaDataDecl.at(i).isStatistic)
continue;
mMetaData->set(mMetaDataDecl.at(i).key, mEditors.at(i)->getValue());
}

View file

@ -54,6 +54,7 @@ set(CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMsgBox.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiTextEditPopup.h
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiComplexTextEditPopup.h
# Math
${CMAKE_CURRENT_SOURCE_DIR}/src/math/Misc.h
@ -128,6 +129,7 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiInputConfig.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiMsgBox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiTextEditPopup.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiComplexTextEditPopup.cpp
# Math
${CMAKE_CURRENT_SOURCE_DIR}/src/math/Misc.cpp

View file

@ -143,6 +143,7 @@ void Settings::setDefaults()
mBoolMap["UseCustomCollectionsSystem"] = true;
mBoolMap["FavoritesFirst"] = true;
mBoolMap["LaunchstringOverride"] = true;
mBoolMap["LocalArt"] = false;

View file

@ -0,0 +1,80 @@
#include "guis/GuiComplexTextEditPopup.h"
#include "components/ButtonComponent.h"
#include "components/MenuComponent.h"
#include "components/TextEditComponent.h"
GuiComplexTextEditPopup::GuiComplexTextEditPopup(Window* window, const std::string& title, const std::string& infoString1, const std::string& infoString2,
const std::string& initValue, const std::function<void(const std::string&)>& okCallback, bool multiLine, const char* acceptBtnText)
: GuiComponent(window), mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 5)), mMultiLine(multiLine)
{
addChild(&mBackground);
addChild(&mGrid);
mTitle = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(title), Font::get(FONT_SIZE_MEDIUM), 0x555555FF, ALIGN_CENTER);
mInfoString1 = std::make_shared<TextComponent>(mWindow, infoString1, Font::get(FONT_SIZE_SMALL), 0x555555FF, ALIGN_CENTER);
mInfoString2 = std::make_shared<TextComponent>(mWindow, infoString2, Font::get(FONT_SIZE_SMALL), 0x555555FF, ALIGN_CENTER);
mText = std::make_shared<TextEditComponent>(mWindow);
mText->setValue(initValue);
if(!multiLine)
mText->setCursor(initValue.size());
std::vector< std::shared_ptr<ButtonComponent> > buttons;
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, acceptBtnText, acceptBtnText, [this, okCallback] { okCallback(mText->getValue()); delete this; }));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "LOAD", "load default string", [this, infoString2] { mText->setValue(infoString2); }));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CLEAR", "clear string", [this] { mText->setValue(""); }));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "discard changes", [this] { delete this; }));
mButtonGrid = makeButtonGrid(mWindow, buttons);
mGrid.setEntry(mTitle, Vector2i(0, 0), false, true);
mGrid.setEntry(mInfoString1, Vector2i(0, 1), false, true);
mGrid.setEntry(mInfoString2, Vector2i(0, 2), false, true);
mGrid.setEntry(mText, Vector2i(0, 3), true, false, Vector2i(1, 1), GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM);
mGrid.setEntry(mButtonGrid, Vector2i(0, 4), true, false);
mGrid.setRowHeightPerc(1, 0.15, true);
float textHeight = mText->getFont()->getHeight();
if(multiLine)
textHeight *= 6;
mText->setSize(0, textHeight);
setSize(Renderer::getScreenWidth() * 0.75f, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y() + 220);
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2);
}
void GuiComplexTextEditPopup::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
mText->setSize(mSize.x() - 40, mText->getSize().y());
// update grid
mGrid.setRowHeightPerc(0, mTitle->getFont()->getHeight() / mSize.y());
mGrid.setRowHeightPerc(2, mButtonGrid->getSize().y() / mSize.y());
mGrid.setSize(mSize);
}
bool GuiComplexTextEditPopup::input(InputConfig* config, Input input)
{
if(GuiComponent::input(config, input))
return true;
// pressing back when not text editing closes us
if(config->isMappedTo("b", input) && input.value)
{
delete this;
return true;
}
return false;
}
std::vector<HelpPrompt> GuiComplexTextEditPopup::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "back"));
return prompts;
}

View file

@ -0,0 +1,35 @@
#pragma once
#ifndef ES_CORE_GUIS_GUI_COMPLEX_TEXT_EDIT_POPUP_H
#define ES_CORE_GUIS_GUI_COMPLEX_TEXT_EDIT_POPUP_H
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
#include "GuiComponent.h"
class TextComponent;
class TextEditComponent;
class GuiComplexTextEditPopup : public GuiComponent
{
public:
GuiComplexTextEditPopup(Window* window, const std::string& title, const std::string& infoString1, const std::string& infoString2,
const std::string& initValue, const std::function<void(const std::string&)>& okCallback, bool multiLine, const char* acceptBtnText = "OK");
bool input(InputConfig* config, Input input);
void onSizeChanged();
std::vector<HelpPrompt> getHelpPrompts() override;
private:
NinePatchComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;
std::shared_ptr<TextComponent> mInfoString1;
std::shared_ptr<TextComponent> mInfoString2;
std::shared_ptr<TextEditComponent> mText;
std::shared_ptr<ComponentGrid> mButtonGrid;
bool mMultiLine;
};
#endif // ES_CORE_GUIS_GUI_COMPLEX_TEXT_EDIT_POPUP_H