diff options
author | Ira Rice <irarice@gmail.com> | 2009-03-25 11:31:02 -0600 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-03-25 11:31:02 -0600 |
commit | e0be7afc936c39e2b0e1db84a13653cfd78a6035 (patch) | |
tree | f5e99fa2f4f2d7c1c7149bd66e410798ae632735 /src/gui/skin.cpp | |
parent | f6e7a477681109aea040456e3f4ebd0f65645ecc (diff) | |
download | mana-e0be7afc936c39e2b0e1db84a13653cfd78a6035.tar.gz mana-e0be7afc936c39e2b0e1db84a13653cfd78a6035.tar.bz2 mana-e0be7afc936c39e2b0e1db84a13653cfd78a6035.tar.xz mana-e0be7afc936c39e2b0e1db84a13653cfd78a6035.zip |
Modified skin loading to save and load a skin's XML path, as well as
modified the skin loading method to take a default value, in case the
value in the configuration file fails to load for one reason or another.
While this doesn't directly expose skinning on a per window basis to the
user at the moment, it does allow people to change what skins get loaded
with which windows now without needing to modify the code.
TODO: Determine a decent approach to allowing the user to change their
window skins in game, as well as moving all widget skin loading to the
skin class (for instance, the button skins, progressbar skins, etc.) so
that different skin configurations can use different widget skins.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/skin.cpp')
-rw-r--r-- | src/gui/skin.cpp | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index ac258175..515ef01b 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -31,6 +31,7 @@ #include "../resources/resourcemanager.h" #include "../utils/dtor.h" +#include "../utils/strprintf.h" #include "../utils/xml.h" SkinLoader* skinLoader = NULL; @@ -45,8 +46,9 @@ class SkinConfigListener : public ConfigListener } }; -Skin::Skin(ImageRect skin, Image* close, std::string name): +Skin::Skin(ImageRect skin, Image* close, std::string filePath, std::string name): instances(0), + mFilePath(filePath), mName(name), border(skin), closeImage(close) @@ -86,32 +88,47 @@ unsigned int Skin::getMinHeight() border.grid[6]->getHeight(); } -Skin* SkinLoader::load(const std::string &filename) +Skin* SkinLoader::load(const std::string &filename, + const std::string &defaultPath) { - SkinIterator skinIterator = mSkins.find(filename); - - if (mSkins.end() != skinIterator) - { - skinIterator->second->instances++; - return skinIterator->second; - } + std::string filePath = filename; ResourceManager *resman = ResourceManager::getInstance(); logger->log("Loading Skin '%s'.", filename.c_str()); - if (filename.empty()) + if (filename.empty() && defaultPath.empty()) logger->error("SkinLoader::load(): Invalid File Name."); - // TODO: - // If there is an error loading the specified file, we should try to revert - // to a 'default' skin file. Only if the 'default' skin file can't be loaded - // should we have a terminating error. - XML::Document doc(filename); - xmlNodePtr rootNode = doc.rootNode(); + XML::Document *doc = new XML::Document(filePath); + xmlNodePtr rootNode = doc->rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - logger->error("Widget Skinning error"); + { + filePath = defaultPath; + + logger->log("Widget Skinning error. Loading '%s' instead.", + filePath.c_str()); + + delete doc; + + doc = new XML::Document(filePath); + rootNode = doc->rootNode(); + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) + { + logger->error(strprintf("Skinning failed. Check this skin file " + "to make sure it's valid: %s", + filePath.c_str())); + } + } + + SkinIterator skinIterator = mSkins.find(filePath); + + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + return skinIterator->second; + } std::string skinSetImage; skinSetImage = XML::getProperty(rootNode, "image", ""); @@ -197,7 +214,7 @@ Skin* SkinLoader::load(const std::string &filename) // Hard-coded for now until we update the above code to look for window buttons. Image* closeImage = resman->getImage("graphics/gui/close_button.png"); - Skin* skin = new Skin(border, closeImage); + Skin* skin = new Skin(border, closeImage, filename); mSkins[filename] = skin; |