Added in-ES messagebox when es_systems.cfg errors occur.

Fixed an error being caused by HelpStyle initializing before the renderer leading to a Font::get(0) command.
Fixed a bug that caused unconfigured inputs to be inserted into InputConfig.
This commit is contained in:
Aloshi 2014-05-31 18:00:42 -05:00
parent e1d75941e0
commit eac8a07794
5 changed files with 84 additions and 26 deletions

View file

@ -8,7 +8,11 @@ HelpStyle::HelpStyle()
position = Eigen::Vector2f(12.0f, Renderer::getScreenHeight() * 0.9515f); position = Eigen::Vector2f(12.0f, Renderer::getScreenHeight() * 0.9515f);
iconColor = 0x777777FF; iconColor = 0x777777FF;
textColor = 0x777777FF; textColor = 0x777777FF;
font = Font::get(FONT_SIZE_SMALL);
if(FONT_SIZE_SMALL != 0)
font = Font::get(FONT_SIZE_SMALL);
else
font = nullptr;
} }
void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view) void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view)

View file

@ -75,15 +75,24 @@ void InputConfig::unmapInput(const std::string& name)
mNameMap.erase(it); mNameMap.erase(it);
} }
Input InputConfig::getInputByName(const std::string& name) bool InputConfig::getInputByName(const std::string& name, Input* result)
{ {
return mNameMap[toLower(name)]; auto it = mNameMap.find(toLower(name));
if(it != mNameMap.end())
{
*result = it->second;
return true;
}
return false;
} }
bool InputConfig::isMappedTo(const std::string& name, Input input) bool InputConfig::isMappedTo(const std::string& name, Input input)
{ {
Input comp = getInputByName(name); Input comp;
if(!getInputByName(name, &comp))
return false;
if(comp.configured && comp.type == input.type && comp.id == input.id) if(comp.configured && comp.type == input.type && comp.id == input.id)
{ {
if(comp.type == TYPE_HAT) if(comp.type == TYPE_HAT)

View file

@ -93,9 +93,6 @@ public:
inline const std::string& getDeviceName() { return mDeviceName; } inline const std::string& getDeviceName() { return mDeviceName; }
inline const std::string& getDeviceGUIDString() { return mDeviceGUID; } inline const std::string& getDeviceGUIDString() { return mDeviceGUID; }
//Returns the input mapped to this name.
Input getInputByName(const std::string& name);
//Returns true if Input is mapped to this name, false otherwise. //Returns true if Input is mapped to this name, false otherwise.
bool isMappedTo(const std::string& name, Input input); bool isMappedTo(const std::string& name, Input input);
@ -108,6 +105,10 @@ public:
bool isConfigured(); bool isConfigured();
private: private:
// Returns true if there is an Input mapped to this name, false otherwise.
// Writes Input mapped to this name to result if true.
bool getInputByName(const std::string& name, Input* result);
std::map<std::string, Input> mNameMap; std::map<std::string, Input> mNameMap;
const int mDeviceId; const int mDeviceId;
const std::string mDeviceName; const std::string mDeviceName;

View file

@ -4,6 +4,7 @@
#include "../components/ButtonComponent.h" #include "../components/ButtonComponent.h"
#include "../components/MenuComponent.h" // for makeButtonGrid #include "../components/MenuComponent.h" // for makeButtonGrid
#include "../Util.h" #include "../Util.h"
#include "../Log.h"
#define HORIZONTAL_PADDING_PX 20 #define HORIZONTAL_PADDING_PX 20
@ -67,6 +68,14 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
bool GuiMsgBox::input(InputConfig* config, Input input) bool GuiMsgBox::input(InputConfig* config, Input input)
{ {
// special case for when GuiMsgBox comes up to report errors before anything has been configured
if(config->getDeviceId() == DEVICE_KEYBOARD && !config->isConfigured() && input.value &&
(input.id == SDLK_RETURN || input.id == SDLK_ESCAPE || input.id == SDLK_SPACE))
{
mAcceleratorFunc();
return true;
}
if(mAcceleratorFunc && config->isMappedTo("b", input) && input.value != 0) if(mAcceleratorFunc && config->isMappedTo("b", input) && input.value != 0)
{ {
mAcceleratorFunc(); mAcceleratorFunc();

View file

@ -9,6 +9,7 @@
#include "SystemData.h" #include "SystemData.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "guis/GuiDetectDevice.h" #include "guis/GuiDetectDevice.h"
#include "guis/GuiMsgBox.h"
#include "AudioManager.h" #include "AudioManager.h"
#include "platform.h" #include "platform.h"
#include "Log.h" #include "Log.h"
@ -121,6 +122,32 @@ bool verifyHomeFolderExists()
return true; return true;
} }
// Returns true if everything is OK,
bool loadSystemConfigFile(const char** errorString)
{
*errorString = NULL;
if(!SystemData::loadConfig())
{
LOG(LogError) << "Error while parsing systems configuration file!";
*errorString = "IT LOOKS LIKE YOUR SYSTEMS CONFIGURATION FILE HAS NOT BEEN SET UP OR IS INVALID. YOU'LL NEED TO DO THIS BY HAND, UNFORTUNATELY.\n\n"
"VISIT EMULATIONSTATION.ORG FOR MORE INFORMATION.";
return false;
}
if(SystemData::sSystemVector.size() == 0)
{
LOG(LogError) << "No systems found! Does at least one system have a game present? (check that extensions match!)\n(Also, make sure you've updated your es_systems.cfg for XML!)";
*errorString = "WE CAN'T FIND ANY SYSTEMS!\n"
"CHECK THAT YOUR PATHS ARE CORRECT IN THE SYSTEMS CONFIGURATION FILE, "
"AND YOUR GAME DIRECTORY HAS AT LEAST ONE GAME WITH THE CORRECT EXTENSION.\n\n"
"VISIT EMULATIONSTATION.ORG FOR MORE INFORMATION.";
return false;
}
return true;
}
//called on exit, assuming we get far enough to have the log initialized //called on exit, assuming we get far enough to have the log initialized
void onExit() void onExit()
{ {
@ -161,22 +188,26 @@ int main(int argc, char* argv[])
window.renderLoadingScreen(); window.renderLoadingScreen();
} }
//try loading the system config file const char* errorMsg = NULL;
if(!SystemData::loadConfig()) if(!loadSystemConfigFile(&errorMsg))
{ {
LOG(LogError) << "Error parsing system config file!"; // something went terribly wrong
if(!scrape_cmdline) if(errorMsg == NULL)
Renderer::deinit(); {
return 1; LOG(LogError) << "Unknown error occured while parsing system config file.";
} if(!scrape_cmdline)
Renderer::deinit();
return 1;
}
//make sure it wasn't empty // we can't handle es_systems.cfg file problems inside ES itself, so display the error message then quit
if(SystemData::sSystemVector.size() == 0) window.pushGui(new GuiMsgBox(&window,
{ errorMsg,
LOG(LogError) << "No systems found! Does at least one system have a game present? (check that extensions match!)\n(Also, make sure you've updated your es_systems.cfg for XML!)"; "QUIT", [] {
if(!scrape_cmdline) SDL_Event* quit = new SDL_Event();
Renderer::deinit(); quit->type = SDL_QUIT;
return 1; SDL_PushEvent(quit);
}));
} }
//run the command line scraper then quit //run the command line scraper then quit
@ -193,11 +224,15 @@ int main(int argc, char* argv[])
window.getViewController()->preload(); window.getViewController()->preload();
//choose which GUI to open depending on if an input configuration already exists //choose which GUI to open depending on if an input configuration already exists
if(fs::exists(InputManager::getConfigPath()) && InputManager::getInstance()->getNumConfiguredDevices() > 0) if(errorMsg == NULL)
{ {
window.getViewController()->goToStart(); if(fs::exists(InputManager::getConfigPath()) && InputManager::getInstance()->getNumConfiguredDevices() > 0)
}else{ {
window.pushGui(new GuiDetectDevice(&window, true)); window.getViewController()->goToStart();
}
else{
window.pushGui(new GuiDetectDevice(&window, true));
}
} }
//generate joystick events since we're done loading //generate joystick events since we're done loading