ui loader and some refactoring

This commit is contained in:
Eduardo Bart
2011-04-10 17:40:44 -03:00
parent 1f78f93096
commit 992e0a8a6b
36 changed files with 646 additions and 425 deletions

View File

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

View File

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

View File

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