MyGUI
3.2.0
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
MyGUIEngine
src
MyGUI_SkinManager.cpp
Go to the documentation of this file.
1
6
/*
7
This file is part of MyGUI.
8
9
MyGUI is free software: you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
13
14
MyGUI is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public License
20
along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21
*/
22
#include "
MyGUI_Precompiled.h
"
23
#include "
MyGUI_SkinManager.h
"
24
#include "
MyGUI_LanguageManager.h
"
25
#include "
MyGUI_ResourceSkin.h
"
26
#include "
MyGUI_XmlDocument.h
"
27
#include "
MyGUI_SubWidgetManager.h
"
28
#include "
MyGUI_Gui.h
"
29
#include "
MyGUI_DataManager.h
"
30
#include "
MyGUI_FactoryManager.h
"
31
#include "
MyGUI_IStateInfo.h
"
32
#include "
MyGUI_LayoutManager.h
"
33
#include "
MyGUI_BackwardCompatibility.h
"
34
35
namespace
MyGUI
36
{
37
38
const
std::string
XML_TYPE
(
"Skin"
);
39
const
std::string
XML_TYPE_RESOURCE
(
"Resource"
);
40
const
std::string
RESOURCE_DEFAULT_NAME
(
"Default"
);
41
42
template
<> SkinManager* Singleton<SkinManager>::msInstance =
nullptr
;
43
template
<>
const
char
*
Singleton<SkinManager>::mClassTypeName
(
"SkinManager"
);
44
45
SkinManager::SkinManager
() :
46
mIsInitialise(false)
47
{
48
}
49
50
void
SkinManager::initialise
()
51
{
52
MYGUI_ASSERT
(!mIsInitialise,
getClassTypeName
() <<
" initialised twice"
);
53
MYGUI_LOG
(Info,
"* Initialise: "
<<
getClassTypeName
());
54
55
ResourceManager::getInstance
().
registerLoadXmlDelegate
(
XML_TYPE
) =
newDelegate
(
this
, &SkinManager::_load);
56
FactoryManager::getInstance
().
registerFactory
<
ResourceSkin
>(
XML_TYPE_RESOURCE
);
57
58
mDefaultName =
"skin_Default"
;
59
createDefault(mDefaultName);
60
61
MYGUI_LOG
(Info,
getClassTypeName
() <<
" successfully initialized"
);
62
mIsInitialise =
true
;
63
}
64
65
void
SkinManager::shutdown
()
66
{
67
MYGUI_ASSERT
(mIsInitialise,
getClassTypeName
() <<
" is not initialised"
);
68
MYGUI_LOG
(Info,
"* Shutdown: "
<<
getClassTypeName
());
69
70
ResourceManager::getInstance
().
unregisterLoadXmlDelegate
(
XML_TYPE
);
71
FactoryManager::getInstance
().
unregisterFactory
<
ResourceSkin
>(
XML_TYPE_RESOURCE
);
72
73
MYGUI_LOG
(Info,
getClassTypeName
() <<
" successfully shutdown"
);
74
mIsInitialise =
false
;
75
}
76
77
void
SkinManager::_load(
xml::ElementPtr
_node,
const
std::string& _file,
Version
_version)
78
{
79
// берем детей и крутимся, основной цикл со скинами
80
xml::ElementEnumerator
skin = _node->
getElementEnumerator
();
81
while
(skin.
next
(
XML_TYPE
))
82
{
83
/*std::string name = */
skin->
findAttribute
(
"name"
);
84
std::string type = skin->
findAttribute
(
"type"
);
85
if
(type.empty())
86
type =
"ResourceSkin"
;
87
88
IObject
*
object
=
FactoryManager::getInstance
().
createObject
(
XML_TYPE_RESOURCE
, type);
89
if
(
object
!=
nullptr
)
90
{
91
ResourceSkin
* data =
object
->
castType
<
ResourceSkin
>();
92
data->
deserialization
(skin.
current
(), _version);
93
94
ResourceManager::getInstance
().
addResource
(data);
95
}
96
}
97
}
98
99
void
SkinManager::createDefault(
const
std::string& _value)
100
{
101
xml::Document doc;
102
xml::ElementPtr
root = doc.createRoot(
"MyGUI"
);
103
xml::ElementPtr
newnode = root->
createChild
(
"Resource"
);
104
newnode->
addAttribute
(
"type"
,
ResourceSkin::getClassTypeName
());
105
newnode->addAttribute(
"name"
, _value);
106
107
ResourceManager::getInstance
().
loadFromXmlNode
(root,
""
, Version());
108
}
109
110
ResourceSkin
*
SkinManager::getByName
(
const
std::string& _name)
const
111
{
112
std::string skinName =
BackwardCompatibility::getSkinRename
(_name);
113
IResource
* result =
nullptr
;
114
if
(!skinName.empty() && skinName !=
RESOURCE_DEFAULT_NAME
)
115
result =
ResourceManager::getInstance
().
getByName
(skinName,
false
);
116
117
if
(result ==
nullptr
)
118
{
119
result =
ResourceManager::getInstance
().
getByName
(mDefaultName,
false
);
120
if
(!skinName.empty() && skinName !=
RESOURCE_DEFAULT_NAME
)
121
{
122
MYGUI_LOG
(Error,
"Skin '"
<< skinName <<
"' not found. Replaced with default skin."
<<
" ["
<<
LayoutManager::getInstance
().getCurrentLayout() <<
"]"
);
123
}
124
}
125
126
return
result ? result->
castType
<
ResourceSkin
>(
false
) :
nullptr
;
127
}
128
129
bool
SkinManager::isExist
(
const
std::string& _name)
const
130
{
131
std::string skinName =
BackwardCompatibility::getSkinRename
(_name);
132
IResource
* result =
ResourceManager::getInstance
().
getByName
(skinName,
false
);
133
return
(result !=
nullptr
) && (result->
isType
<
ResourceSkin
>());
134
}
135
136
void
SkinManager::setDefaultSkin
(
const
std::string& _value)
137
{
138
mDefaultName = _value;
139
}
140
141
const
std::string
SkinManager::getDefaultSkin
()
const
142
{
143
return
mDefaultName;
144
}
145
146
}
// namespace MyGUI
Generated on Tue Apr 30 2013 23:15:05 for MyGUI by
1.8.3.1