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.
This commit is contained in:
Aloshi 2014-03-22 11:44:57 -05:00
parent 98b17bf246
commit d0261dcc5a
6 changed files with 74 additions and 13 deletions

View file

@ -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;
}

View file

@ -41,6 +41,8 @@ void Settings::setDefaults()
mIntMap["GameListSortIndex"] = 0;
mStringMap["TransitionStyle"] = "fade";
mScraper = std::shared_ptr<Scraper>(new GamesDBScraper());
}
@ -65,6 +67,14 @@ void Settings::saveFile()
saveMap<std::string, int>(doc, mIntMap, "int");
saveMap<std::string, float>(doc, mFloatMap, "float");
//saveMap<std::string, std::string>(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);

View file

@ -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<Scraper> getScraper();
void setScraper(std::shared_ptr<Scraper> scraper);
@ -37,6 +39,7 @@ private:
std::map<std::string, bool> mBoolMap;
std::map<std::string, int> mIntMap;
std::map<std::string, float> mFloatMap;
std::map<std::string, std::string> mStringMap;
std::shared_ptr<Scraper> mScraper;
std::string mHomePathOverride;

View file

@ -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<std::string> >(mWindow, "TRANSITION STYLE", false);
std::vector<std::string> 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);
});

View file

@ -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;

View file

@ -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<float>(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<float>(0, 1, t / 0.3f);
float fadeEnd = lerp<float>(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)