00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_SkinManager.h"
00025 #include "MyGUI_LanguageManager.h"
00026 #include "MyGUI_ResourceSkin.h"
00027 #include "MyGUI_XmlDocument.h"
00028 #include "MyGUI_SubWidgetManager.h"
00029 #include "MyGUI_Gui.h"
00030 #include "MyGUI_DataManager.h"
00031 #include "MyGUI_FactoryManager.h"
00032 #include "MyGUI_IStateInfo.h"
00033
00034 namespace MyGUI
00035 {
00036 const std::string XML_TYPE("Skin");
00037 const std::string XML_TYPE_RESOURCE("Resource");
00038 const std::string XML_TYPE_PROPERTY("Property");
00039 const std::string RESOURCE_DEFAULT_NAME("Default");
00040
00041 MYGUI_INSTANCE_IMPLEMENT( SkinManager )
00042
00043 void SkinManager::initialise()
00044 {
00045 MYGUI_ASSERT(!mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
00046 MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);
00047
00048 ResourceManager::getInstance().registerLoadXmlDelegate(XML_TYPE) = newDelegate(this, &SkinManager::_load);
00049 FactoryManager::getInstance().registerFactory<ResourceSkin>(XML_TYPE_RESOURCE);
00050
00051 mDefaultName = "Default";
00052 createDefault(mDefaultName);
00053
00054 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
00055 mIsInitialise = true;
00056 }
00057
00058 void SkinManager::shutdown()
00059 {
00060 if (!mIsInitialise) return;
00061 MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME);
00062
00063 ResourceManager::getInstance().unregisterLoadXmlDelegate(XML_TYPE);
00064 FactoryManager::getInstance().unregisterFactory<ResourceSkin>(XML_TYPE_RESOURCE);
00065
00066 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown");
00067 mIsInitialise = false;
00068 }
00069
00070 bool SkinManager::load(const std::string& _file)
00071 {
00072 return ResourceManager::getInstance()._loadImplement(_file, true, XML_TYPE, INSTANCE_TYPE_NAME);
00073 }
00074
00075 void SkinManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version)
00076 {
00077
00078 xml::ElementEnumerator skin = _node->getElementEnumerator();
00079 while (skin.next())
00080 {
00081 if (skin->getName() == XML_TYPE)
00082 {
00083 std::string name = skin->findAttribute("name");
00084 std::string type = skin->findAttribute("type");
00085 if (type.empty()) type = "ResourceSkin";
00086
00087 IObject* object = FactoryManager::getInstance().createObject(XML_TYPE_RESOURCE, type);
00088 if (object != nullptr)
00089 {
00090 ResourceSkin* data = object->castType<ResourceSkin>();
00091 data->deserialization(skin.current(), _version);
00092
00093 ResourceManager::getInstance().addResource(data);
00094 }
00095 }
00096 else if (skin->getName() == XML_TYPE_PROPERTY)
00097 {
00098 const std::string& key = skin->findAttribute("key");
00099 const std::string& value = skin->findAttribute("value");
00100 if (key == "Default")
00101 mDefaultName = value;
00102 }
00103 }
00104 }
00105
00106 void SkinManager::createDefault(const std::string& _value)
00107 {
00108 xml::Document doc;
00109 xml::ElementPtr root = doc.createRoot("MyGUI");
00110 xml::ElementPtr newnode = root->createChild("Resource");
00111 newnode->addAttribute("type", ResourceSkin::getClassTypeName());
00112 newnode->addAttribute("name", _value);
00113
00114 ResourceManager::getInstance()._load(root, "", Version());
00115 }
00116
00117 ResourceSkin* SkinManager::getByName(const std::string& _name) const
00118 {
00119 IResource* result = nullptr;
00120 if (!_name.empty() && _name != RESOURCE_DEFAULT_NAME)
00121 result = ResourceManager::getInstance().getByName(_name, false);
00122
00123 if (result == nullptr)
00124 result = ResourceManager::getInstance().getByName(mDefaultName, false);
00125
00126 return result ? result->castType<ResourceSkin>(false) : nullptr;
00127 }
00128
00129 bool SkinManager::isExist(const std::string& _name) const
00130 {
00131 return ResourceManager::getInstance().isExist(_name);
00132 }
00133
00134 void SkinManager::setDefaultSkin(const std::string& _value)
00135 {
00136 mDefaultName = _value;
00137 }
00138
00139 }