diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-03-27 13:25:04 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-03-27 13:25:24 +0100 |
commit | dd05447445dc1766e532130318af2cb6bb72a994 (patch) | |
tree | c8b2cbac64ccf9545a39c143088b57fe2cb8e678 /src/gui/skin.cpp | |
parent | 05e753294c1a603252d2eed4b1731c3f50543a7e (diff) | |
parent | 2aab736bc5d77ffda789d7de56cef100fac207e1 (diff) | |
download | mana-dd05447445dc1766e532130318af2cb6bb72a994.tar.gz mana-dd05447445dc1766e532130318af2cb6bb72a994.tar.bz2 mana-dd05447445dc1766e532130318af2cb6bb72a994.tar.xz mana-dd05447445dc1766e532130318af2cb6bb72a994.zip |
Merge branch 'aethyra/master'
Conflicts:
src/beingmanager.cpp
src/gui/confirm_dialog.cpp
src/gui/inventorywindow.cpp
src/gui/inventorywindow.h
src/gui/label.cpp
src/gui/label.h
src/gui/popup.cpp
src/gui/popup.h
src/gui/scrollarea.cpp
src/gui/skin.cpp
src/gui/skin.h
src/gui/speechbubble.cpp
src/gui/window.cpp
src/gui/window.h
src/localplayer.h
src/main.cpp
src/net/ea/playerhandler.cpp
src/resources/ambientoverlay.h
src/resources/dye.cpp
src/resources/imagewriter.cpp
src/resources/itemdb.cpp
src/shopitem.cpp
Diffstat (limited to 'src/gui/skin.cpp')
-rw-r--r-- | src/gui/skin.cpp | 99 |
1 files changed, 80 insertions, 19 deletions
diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index f7cc8ba1..0d62fea5 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -19,20 +19,36 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <algorithm> + #include "skin.h" +#include "../configuration.h" +#include "../configlistener.h" #include "../log.h" #include "../resources/image.h" #include "../resources/resourcemanager.h" #include "../utils/dtor.h" +#include "../utils/strprintf.h" #include "../utils/xml.h" SkinLoader *skinLoader = NULL; +ConfigListener *SkinLoader::skinConfigListener = NULL; + +class SkinConfigListener : public ConfigListener +{ + void optionChanged(const std::string &) + { + if (skinLoader) + skinLoader->updateAlpha(); + } +}; -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) @@ -51,6 +67,15 @@ Skin::~Skin() closeImage->decRef(); } +void Skin::updateAlpha() +{ + const float alpha = config.getValue("guialpha", 0.8); + + for_each(border.grid, border.grid + 9, + std::bind2nd(std::mem_fun(&Image::setAlpha), alpha)); + closeImage->setAlpha(alpha); +} + int Skin::getMinWidth() const { return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + @@ -63,32 +88,47 @@ int Skin::getMinHeight() const 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", ""); @@ -171,21 +211,42 @@ Skin *SkinLoader::load(const std::string &filename) logger->log("Finished loading Skin."); + delete doc; + // 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; + + updateAlpha(); + return skin; } -SkinLoader::SkinLoader() +SkinLoader::SkinLoader() : + mSkins() { + skinConfigListener = new SkinConfigListener(); + // Send GUI alpha changed for initialization + skinConfigListener->optionChanged("guialpha"); + config.addListener("guialpha", skinConfigListener); } SkinLoader::~SkinLoader() { delete_all(mSkins); + config.removeListener("guialpha", skinConfigListener); + delete skinConfigListener; + skinConfigListener = NULL; +} + +void SkinLoader::updateAlpha() +{ + for (SkinIterator iter = mSkins.begin(); iter != mSkins.end(); ++iter) + { + iter->second->updateAlpha(); + } } |