mirror of
https://github.com/edubart/otclient.git
synced 2025-10-18 21:43:26 +02:00
ui loader and some refactoring
This commit is contained in:
@@ -35,7 +35,7 @@ bool Configs::load(const std::string& fileName)
|
||||
return false;
|
||||
|
||||
std::string fileContents = g_resources.loadTextFile(fileName);
|
||||
if(fileContents.size() == 0)
|
||||
if(fileContents.size())
|
||||
return false;
|
||||
|
||||
std::istringstream fin(fileContents);
|
||||
@@ -52,8 +52,8 @@ bool Configs::load(const std::string& fileName)
|
||||
it.second() >> value;
|
||||
m_confsMap[key] = value;
|
||||
}
|
||||
} catch (YAML::ParserException& e) {
|
||||
logError("Malformed configuration file!");
|
||||
} catch (YAML::Exception& e) {
|
||||
logError("Malformed config file: %s", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -37,7 +37,7 @@ void Engine::init()
|
||||
{
|
||||
// initialize stuff
|
||||
g_graphics.init();
|
||||
g_fonts.init();
|
||||
g_fonts.init("tibia-12px-rounded");
|
||||
}
|
||||
|
||||
void Engine::terminate()
|
||||
@@ -52,6 +52,7 @@ void Engine::terminate()
|
||||
|
||||
void Engine::run()
|
||||
{
|
||||
Font *defaultFont = g_fonts.getDefaultFont();
|
||||
int ticks = Platform::getTicks();
|
||||
int lastFpsTicks = ticks;
|
||||
int frameCount = 0;
|
||||
@@ -87,8 +88,8 @@ void Engine::run()
|
||||
// render fps
|
||||
if(m_calculateFps) {
|
||||
std::string fpsText = format("FPS: %d", fps);
|
||||
Size textSize = g_defaultFont->calculateTextRectSize(fpsText);
|
||||
g_defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - textSize.width() - 10, 10));
|
||||
Size textSize = defaultFont->calculateTextRectSize(fpsText);
|
||||
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - textSize.width() - 10, 10));
|
||||
}
|
||||
|
||||
// swap buffers
|
||||
@@ -119,7 +120,7 @@ void Engine::render()
|
||||
g_graphics.beginRender();
|
||||
if(m_currentState)
|
||||
m_currentState->render();
|
||||
g_ui->render();
|
||||
UIContainer::getRootContainer()->render();
|
||||
g_graphics.endRender();
|
||||
}
|
||||
|
||||
@@ -132,7 +133,7 @@ void Engine::onClose()
|
||||
void Engine::onResize(const Size& size)
|
||||
{
|
||||
g_graphics.resize(size);
|
||||
g_ui->setSize(size);
|
||||
UIContainer::getRootContainer()->setSize(size);
|
||||
|
||||
if(m_currentState)
|
||||
m_currentState->onResize(size);
|
||||
@@ -141,7 +142,7 @@ void Engine::onResize(const Size& size)
|
||||
void Engine::onInputEvent(const InputEvent& event)
|
||||
{
|
||||
// inputs goest to gui first
|
||||
if(!g_ui->onInputEvent(event)) {
|
||||
if(!UIContainer::getRootContainer()->onInputEvent(event)) {
|
||||
// if gui didnt capture the input then goes to the state
|
||||
if(m_currentState)
|
||||
m_currentState->onInputEvent(event);
|
||||
|
@@ -43,7 +43,7 @@ bool Resources::setWriteDir(const std::string& path)
|
||||
bool ret = (bool)PHYSFS_setWriteDir(path.c_str());
|
||||
|
||||
if(!ret)
|
||||
logError("Could not set the path \"%s\" as write directory, file write will not work.", path.c_str());
|
||||
logError("Could not set the path \"%s\" as write directory, file write will not work correctly.", path.c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user