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
00037 const std::string XML_TYPE("Skin");
00038 const std::string XML_TYPE_RESOURCE("Resource");
00039 const std::string RESOURCE_DEFAULT_NAME("Default");
00040
00041 MYGUI_INSTANCE_IMPLEMENT(SkinManager);
00042
00043 void SkinManager::initialise()
00044 {
00045 MYGUI_ASSERT(false == 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().registryFactory<ResourceSkin>(XML_TYPE_RESOURCE);
00050
00051 mDefaultName = "skin_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 (false == mIsInitialise) return;
00061 MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME);
00062
00063 ResourceManager::getInstance().unregisterLoadXmlDelegate(XML_TYPE);
00064 FactoryManager::getInstance().unregistryFactory<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(XML_TYPE))
00080 {
00081 std::string name = skin->findAttribute("name");
00082 std::string type = skin->findAttribute("type");
00083 if (type.empty()) type = "ResourceSkin";
00084
00085 IObject* object = FactoryManager::getInstance().createObject(XML_TYPE_RESOURCE, type);
00086 if (object != nullptr)
00087 {
00088 ResourceSkin* data = object->castType<ResourceSkin>();
00089 data->deserialization(skin.current(), _version);
00090
00091 ResourceManager::getInstance().addResource(data);
00092 }
00093 }
00094 }
00095
00096 void SkinManager::createDefault(const std::string& _value)
00097 {
00098 xml::Document doc;
00099 xml::ElementPtr root = doc.createRoot("MyGUI");
00100 xml::ElementPtr newnode = root->createChild("Resource");
00101 newnode->addAttribute("type", ResourceSkin::getClassTypeName());
00102 newnode->addAttribute("name", _value);
00103
00104 ResourceManager::getInstance()._load(root, "", Version());
00105 }
00106
00107 ResourceSkin* SkinManager::getByName(const std::string& _name)
00108 {
00109 IResource* result = nullptr;
00110 if (!_name.empty() && _name != RESOURCE_DEFAULT_NAME)
00111 result = ResourceManager::getInstance().getByName(_name, false);
00112
00113 if (result == nullptr)
00114 result = ResourceManager::getInstance().getByName(mDefaultName, false);
00115
00116 return result ? result->castType<ResourceSkin>(false) : nullptr;
00117 }
00118
00119 bool SkinManager::isExist(const std::string& _name)
00120 {
00121 return ResourceManager::getInstance().isExist(_name);
00122 }
00123
00124 void SkinManager::setDefaultSkin(const std::string& _value)
00125 {
00126 mDefaultName = _value;
00127 }
00128
00129 }