mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-17 22:55:38 +00:00
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:
parent
e1d75941e0
commit
eac8a07794
|
@ -8,7 +8,11 @@ HelpStyle::HelpStyle()
|
|||
position = Eigen::Vector2f(12.0f, Renderer::getScreenHeight() * 0.9515f);
|
||||
iconColor = 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)
|
||||
|
|
|
@ -75,14 +75,23 @@ void InputConfig::unmapInput(const std::string& name)
|
|||
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)
|
||||
{
|
||||
Input comp = getInputByName(name);
|
||||
Input comp;
|
||||
if(!getInputByName(name, &comp))
|
||||
return false;
|
||||
|
||||
if(comp.configured && comp.type == input.type && comp.id == input.id)
|
||||
{
|
||||
|
|
|
@ -93,9 +93,6 @@ public:
|
|||
inline const std::string& getDeviceName() { return mDeviceName; }
|
||||
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.
|
||||
bool isMappedTo(const std::string& name, Input input);
|
||||
|
||||
|
@ -108,6 +105,10 @@ public:
|
|||
bool isConfigured();
|
||||
|
||||
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;
|
||||
const int mDeviceId;
|
||||
const std::string mDeviceName;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "../components/ButtonComponent.h"
|
||||
#include "../components/MenuComponent.h" // for makeButtonGrid
|
||||
#include "../Util.h"
|
||||
#include "../Log.h"
|
||||
|
||||
#define HORIZONTAL_PADDING_PX 20
|
||||
|
||||
|
@ -67,6 +68,14 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text,
|
|||
|
||||
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)
|
||||
{
|
||||
mAcceleratorFunc();
|
||||
|
|
71
src/main.cpp
71
src/main.cpp
|
@ -9,6 +9,7 @@
|
|||
#include "SystemData.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "guis/GuiDetectDevice.h"
|
||||
#include "guis/GuiMsgBox.h"
|
||||
#include "AudioManager.h"
|
||||
#include "platform.h"
|
||||
#include "Log.h"
|
||||
|
@ -121,6 +122,32 @@ bool verifyHomeFolderExists()
|
|||
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
|
||||
void onExit()
|
||||
{
|
||||
|
@ -161,22 +188,26 @@ int main(int argc, char* argv[])
|
|||
window.renderLoadingScreen();
|
||||
}
|
||||
|
||||
//try loading the system config file
|
||||
if(!SystemData::loadConfig())
|
||||
const char* errorMsg = NULL;
|
||||
if(!loadSystemConfigFile(&errorMsg))
|
||||
{
|
||||
LOG(LogError) << "Error parsing system config file!";
|
||||
if(!scrape_cmdline)
|
||||
Renderer::deinit();
|
||||
return 1;
|
||||
}
|
||||
// something went terribly wrong
|
||||
if(errorMsg == NULL)
|
||||
{
|
||||
LOG(LogError) << "Unknown error occured while parsing system config file.";
|
||||
if(!scrape_cmdline)
|
||||
Renderer::deinit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
//make sure it wasn't empty
|
||||
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!)";
|
||||
if(!scrape_cmdline)
|
||||
Renderer::deinit();
|
||||
return 1;
|
||||
// we can't handle es_systems.cfg file problems inside ES itself, so display the error message then quit
|
||||
window.pushGui(new GuiMsgBox(&window,
|
||||
errorMsg,
|
||||
"QUIT", [] {
|
||||
SDL_Event* quit = new SDL_Event();
|
||||
quit->type = SDL_QUIT;
|
||||
SDL_PushEvent(quit);
|
||||
}));
|
||||
}
|
||||
|
||||
//run the command line scraper then quit
|
||||
|
@ -193,11 +224,15 @@ int main(int argc, char* argv[])
|
|||
window.getViewController()->preload();
|
||||
|
||||
//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();
|
||||
}else{
|
||||
window.pushGui(new GuiDetectDevice(&window, true));
|
||||
if(fs::exists(InputManager::getConfigPath()) && InputManager::getInstance()->getNumConfiguredDevices() > 0)
|
||||
{
|
||||
window.getViewController()->goToStart();
|
||||
}
|
||||
else{
|
||||
window.pushGui(new GuiDetectDevice(&window, true));
|
||||
}
|
||||
}
|
||||
|
||||
//generate joystick events since we're done loading
|
||||
|
|
Loading…
Reference in a new issue