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