From d0261dcc5a1d5bbcaa8fd4ae80ba1a5d5cf6d2b8 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 22 Mar 2014 11:44:57 -0500 Subject: [PATCH] Added "fade" transition between views in ViewController. You can change the "transition style" in the UI options. Added "string" type to "Settings". Fixed problems with loading settings when --home-path was not the exactly first argument supplied. --- src/Log.cpp | 4 +++- src/Settings.cpp | 13 +++++++++++++ src/Settings.h | 3 +++ src/guis/GuiMenu.cpp | 10 ++++++++++ src/main.cpp | 32 +++++++++++++++++++++++--------- src/views/ViewController.cpp | 25 ++++++++++++++++++++++--- 6 files changed, 74 insertions(+), 13 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 0e8522601..643aef16a 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -58,7 +58,9 @@ Log::~Log() if(getOutput() == NULL) { - std::cerr << "ERROR - tried to write to log file before it was open!\n"; + // not open yet, print to stdout + std::cerr << "ERROR - tried to write to log file before it was open! The following won't be logged:\n"; + std::cerr << os.str(); return; } diff --git a/src/Settings.cpp b/src/Settings.cpp index 62e282a7e..13e342a82 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -41,6 +41,8 @@ void Settings::setDefaults() mIntMap["GameListSortIndex"] = 0; + mStringMap["TransitionStyle"] = "fade"; + mScraper = std::shared_ptr(new GamesDBScraper()); } @@ -65,6 +67,14 @@ void Settings::saveFile() saveMap(doc, mIntMap, "int"); saveMap(doc, mFloatMap, "float"); + //saveMap(doc, mStringMap, "string"); + for(auto iter = mStringMap.begin(); iter != mStringMap.end(); iter++) + { + pugi::xml_node node = doc.append_child("string"); + node.append_attribute("name").set_value(iter->first.c_str()); + node.append_attribute("value").set_value(iter->second.c_str()); + } + pugi::xml_node scraperNode = doc.append_child("scraper"); scraperNode.append_attribute("value").set_value(mScraper->getName()); @@ -92,6 +102,8 @@ void Settings::loadFile() setInt(node.attribute("name").as_string(), node.attribute("value").as_int()); for(pugi::xml_node node = doc.child("float"); node; node = node.next_sibling("float")) setFloat(node.attribute("name").as_string(), node.attribute("value").as_float()); + for(pugi::xml_node node = doc.child("string"); node; node = node.next_sibling("string")) + setString(node.attribute("name").as_string(), node.attribute("value").as_string()); if(doc.child("scraper")) { @@ -128,3 +140,4 @@ void Settings::setMethodName(const std::string& name, type value) \ SETTINGS_GETSET(bool, mBoolMap, getBool, setBool); SETTINGS_GETSET(int, mIntMap, getInt, setInt); SETTINGS_GETSET(float, mFloatMap, getFloat, setFloat); +SETTINGS_GETSET(const std::string&, mStringMap, getString, setString); \ No newline at end of file diff --git a/src/Settings.h b/src/Settings.h index 1ea193572..d4670801f 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -18,10 +18,12 @@ public: bool getBool(const std::string& name); int getInt(const std::string& name); float getFloat(const std::string& name); + const std::string& getString(const std::string& name); void setBool(const std::string& name, bool value); void setInt(const std::string& name, int value); void setFloat(const std::string& name, float value); + void setString(const std::string& name, const std::string& value); std::shared_ptr getScraper(); void setScraper(std::shared_ptr scraper); @@ -37,6 +39,7 @@ private: std::map mBoolMap; std::map mIntMap; std::map mFloatMap; + std::map mStringMap; std::shared_ptr mScraper; std::string mHomePathOverride; diff --git a/src/guis/GuiMenu.cpp b/src/guis/GuiMenu.cpp index a9a0b5c97..9491a1162 100644 --- a/src/guis/GuiMenu.cpp +++ b/src/guis/GuiMenu.cpp @@ -118,6 +118,16 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN s->addWithLabel("ON-SCREEN HELP", show_help); s->addSaveFunc([show_help] { Settings::getInstance()->setBool("ShowHelpPrompts", show_help->getState()); }); + // transition style + auto transition_style = std::make_shared< OptionListComponent >(mWindow, "TRANSITION STYLE", false); + std::vector transitions; + transitions.push_back("fade"); + transitions.push_back("slide"); + for(auto it = transitions.begin(); it != transitions.end(); it++) + transition_style->add(*it, *it, Settings::getInstance()->getString("TransitionStyle") == *it); + s->addWithLabel("TRANSITION STYLE", transition_style); + s->addSaveFunc([transition_style] { Settings::getInstance()->setString("TransitionStyle", transition_style->getSelected()); }); + mWindow->pushGui(s); }); diff --git a/src/main.cpp b/src/main.cpp index 548f6dc19..73534ad33 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,26 @@ namespace fs = boost::filesystem; bool scrape_cmdline = false; +// we do this separately from the other args because the other args might call Settings::getInstance() +// which will load the file getHomePath() + "/.emulationstation/es_settings.cfg", and getHomePath() needs to be accurate by then +bool parseArgsForHomeDir(int argc, char* argv[]) +{ + for(int i = 1; i < argc; i++) + { + if(strcmp(argv[i], "--home-path") == 0) + { + if(i >= argc - 1) + { + std::cerr << "No home path specified!\n"; + return false; + } + setHomePathOverride(argv[i + 1]); + } + } + + return true; +} + bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height) { for(int i = 1; i < argc; i++) @@ -59,15 +79,6 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height }else if(strcmp(argv[i], "--scrape") == 0) { scrape_cmdline = true; - }else if(strcmp(argv[i], "--home-path") == 0) - { - if(i >= argc - 1) - { - std::cerr << "No home path specified!\n"; - return false; - } - - setHomePathOverride(argv[i + 1]); }else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { std::cout << "EmulationStation, a graphical front-end for ROM browsing.\n"; @@ -121,6 +132,9 @@ int main(int argc, char* argv[]) unsigned int width = 0; unsigned int height = 0; + if(!parseArgsForHomeDir(argc, argv)) // returns false if an invalid path was specified + return 1; + if(!parseArgs(argc, argv, &width, &height)) return 0; diff --git a/src/views/ViewController.cpp b/src/views/ViewController.cpp index c5f904964..6246553e8 100644 --- a/src/views/ViewController.cpp +++ b/src/views/ViewController.cpp @@ -1,6 +1,7 @@ #include "ViewController.h" #include "../Log.h" #include "../SystemData.h" +#include "../Settings.h" #include "gamelist/BasicGameListView.h" #include "gamelist/DetailedGameListView.h" @@ -13,8 +14,6 @@ ViewController::ViewController(Window* window) : GuiComponent(window), mCurrentView(nullptr), mCamera(Eigen::Affine3f::Identity()), mFadeOpacity(0), mLockInput(false) { - // slot 1 so the fade carries over - setAnimation(new LambdaAnimation([&] (float t) { mFadeOpacity = lerp(1.0f, 0.0f, t); }, 900), nullptr, false, 1); mState.viewing = NOTHING; } @@ -69,7 +68,27 @@ void ViewController::playViewTransition() Eigen::Vector3f target(Eigen::Vector3f::Identity()); if(mCurrentView) target = mCurrentView->getPosition(); - setAnimation(new MoveCameraAnimation(mCamera, target)); + + if(Settings::getInstance()->getString("TransitionStyle") == "fade") + { + // fade animation + auto fadeAnim = [this, target](float t) { + float fadeStart = lerp(0, 1, t / 0.3f); + float fadeEnd = lerp(1, 0, (t - 0.7f) / 0.3f); + + if(t <= 0.3f) + { + mFadeOpacity = fadeStart; + }else{ + this->mCamera.translation() = -target; + mFadeOpacity = fadeEnd; + } + }; + setAnimation(new LambdaAnimation(fadeAnim, 800)); + }else{ + // slide + setAnimation(new MoveCameraAnimation(mCamera, target)); + } } void ViewController::onFileChanged(FileData* file, FileChangeType change)