Skip to content

Commit ca1b93b

Browse files
committed
ShoC style texture description reading
1 parent 9396cc2 commit ca1b93b

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/xrGame/ScriptXMLInit.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ void _attach_child(CUIWindow* _child, CUIWindow* _parent)
3939
}
4040

4141
void CScriptXmlInit::ParseFile(LPCSTR xml_file) { m_xml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, xml_file); }
42+
43+
void CScriptXmlInit::ParseShTexInfo(pcstr xml_file)
44+
{
45+
CUITextureMaster::ParseShTexInfo(xml_file);
46+
}
47+
4248
void CScriptXmlInit::InitWindow(LPCSTR path, int index, CUIWindow* pWnd)
4349
{
4450
CUIXmlInit::InitWindow(m_xml, path, index, pWnd);
@@ -251,6 +257,7 @@ SCRIPT_EXPORT(CScriptXmlInit, (), {
251257
module(luaState)[class_<CScriptXmlInit>("CScriptXmlInit")
252258
.def(constructor<>())
253259
.def("ParseFile", &CScriptXmlInit::ParseFile)
260+
.def("ParseShTexInfo", &CScriptXmlInit::ParseShTexInfo)
254261
.def("InitWindow", &CScriptXmlInit::InitWindow)
255262
.def("InitFrame", &CScriptXmlInit::InitFrame)
256263
.def("InitFrameLine", &CScriptXmlInit::InitFrameLine)

src/xrGame/ScriptXMLInit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CScriptXmlInit
3333
{
3434
public:
3535
void ParseFile(LPCSTR xml_file);
36+
void ParseShTexInfo(pcstr xml_file);
3637
void InitWindow(LPCSTR path, int index, CUIWindow* pWnd);
3738
CUIFrameWindow* InitFrame(LPCSTR path, CUIWindow* parent);
3839
CUIFrameLineWnd* InitFrameLine(LPCSTR path, CUIWindow* parent);

src/xrUICore/XML/UITextureMaster.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ void CUITextureMaster::ParseShTexInfo(pcstr path, pcstr xml_file)
7070
}
7171
}
7272

73+
void CUITextureMaster::ParseShTexInfo(pcstr xml_file)
74+
{
75+
CUIXml xml;
76+
xml.Load(CONFIG_PATH, UI_PATH, xml_file);
77+
const shared_str file = xml.Read("file_name", 0, "");
78+
79+
const int num = xml.GetNodesNum("", 0, "texture");
80+
for (int i = 0; i < num; i++)
81+
{
82+
TEX_INFO info;
83+
84+
info.file = file;
85+
86+
info.rect.x1 = xml.ReadAttribFlt("texture", i, "x");
87+
info.rect.x2 = xml.ReadAttribFlt("texture", i, "width") + info.rect.x1;
88+
info.rect.y1 = xml.ReadAttribFlt("texture", i, "y");
89+
info.rect.y2 = xml.ReadAttribFlt("texture", i, "height") + info.rect.y1;
90+
shared_str id = xml.ReadAttrib("texture", i, "id");
91+
92+
if (m_textures.find(id) == m_textures.end())
93+
m_textures.emplace(id, info);
94+
else
95+
m_textures[id] = info;
96+
}
97+
}
98+
7399
bool CUITextureMaster::IsSh(const shared_str& texture_name)
74100
{
75101
return strstr(texture_name.c_str(), DELIMITER) ? false : true;

src/xrUICore/XML/UITextureMaster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct sh_pair
3636
class XRUICORE_API CUITextureMaster
3737
{
3838
public:
39+
static void ParseShTexInfo(pcstr xml_file);
3940
static void ParseShTexInfo(pcstr path, pcstr xml_file);
4041
static void FreeTexInfo();
4142
static void FreeCachedShaders();

0 commit comments

Comments
 (0)