[Change] Changed gui.xml to use a cleaner format.

This commit is contained in:
Allanis 2014-03-19 21:48:10 +00:00
parent 5ab3eafc4d
commit 8f96995c8f
2 changed files with 43 additions and 107 deletions

View File

@ -1,70 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<GUIs> <GUIs>
<gui gfx="minimal" name="minimal"> <gui gfx="minimal" name="minimal">
<offset> <offset x="-65" y="0" />
<x>-65</x> <radar type="circle" w="70" x="72" y="72" />
<y>0</y> <nav x="40" y="151" w="112" h="42" />
</offset>
<radar type="circle">
<w>70</w>
<x>72</x>
<y>72</y>
</radar>
<nav>
<x>40</x>
<y>151</y>
<w>112</w>
<h>42</h>
</nav>
<health> <health>
<shield> <shield w="98" h="8" x="52" y="201" />
<w>98</w> <armour w="98" h="8" x="52" y="212" />
<h>8</h> <energy w="98" h="8" x="52" y="223" />
<x>52</x>
<y>201</y>
</shield>
<armour>
<w>98</w>
<h>8</h>
<x>52</x>
<y>212</y>
</armour>
<energy>
<w>98</w>
<h>8</h>
<x>52</x>
<y>223</y>
</energy>
</health> </health>
<weapon> <weapon x="40" y="239" w="112" h="42" />
<x>40</x>
<y>239</y>
<w>112</w>
<h>42</h>
</weapon>
<target> <target>
<gfx> <gfx x="34" y="312" />
<x>34</x> <name x="40" y="291" />
<y>312</y> <faction x="40" y="304" />
</gfx> <health x="40" y="401" />
<name>
<x>40</x>
<y>291</y>
</name>
<faction>
<x>40</x>
<y>304</y>
</faction>
<health>
<x>40</x>
<y>401</y>
</health>
</target> </target>
<misc> <misc x="40" y="424" w="112" h="100" />
<x>40</x>
<y>424</y>
<w>112</w>
<h>100</h>
</misc>
</gui> </gui>
</GUIs> </GUIs>

View File

@ -1321,55 +1321,40 @@ int gui_load(const char* name) {
return 0; return 0;
} }
static void rect_parse(const xmlNodePtr parent, double* x, double* y, /**
double* w, double* h) { * @brief Parse a parameter of the rect node.
xmlNodePtr cur; */
int param; static void rect_parseParam(const xmlNodePtr parent, char* name, double* param) {
char* buf;
param = 0; /* Get the attribute. */
xmlr_attr(parent, name, buf);
cur = parent->children; /* Wants attribute. */
if(param != NULL) {
if(buf == NULL)
WARN("Node '%s' missing 'x' parameter.", parent->name);
else if(buf != NULL)
*param = atoi(buf);
}
/* Doesn't want it. */
else if(buf != NULL)
WARN("Node '%s' has superfluous 'x' parameter.", parent->name);
do { /* Clean up. */
if(xml_isNode(cur, "x")) { if(buf != NULL)
if(x != NULL) { free(buf);
*x = xml_getFloat(cur); }
param |= (1<<0);
} else
WARN("Extra parameter 'x' found for GUI node '%s'", parent->name);
}
else if(xml_isNode(cur, "y")) {
if(y != NULL) {
*y = xml_getFloat(cur);
param |= (1<<1);
} else
WARN("Extra parameter 'y' found for GUI node '%s'", parent->name);
}
else if(xml_isNode(cur, "w")) {
if(w != NULL) {
*w = xml_getFloat(cur);
param |= (1<<2);
} else
WARN("Extra parameter 'w' found for GUI node '%s'", parent->name);
}
else if(xml_isNode(cur, "h")) {
if(h != NULL) {
*h = xml_getFloat(cur);
param |= (1<<3);
} else
WARN("Extra parameter 'h' found for GUI node '%s'", parent->name);
}
} while((cur = cur->next));
/* Check to see if we got everything we asked for. */ /**
if(x && !(param & (1<<0))) * @brief Used to pull out a rect from an xml node.
WARN("Missing parameter 'x' for GUI node '%s'", parent->name); */
else if(y && !(param & (1<<1))) static void rect_parse(const xmlNodePtr parent,
WARN("Missing parameter 'y' for GUI node '%s'", parent->name); double* x, double* y, double* w, double* h) {
else if(w && !(param & (1<<2))) rect_parseParam(parent, "w", w);
WARN("Missing parameter 'w' for GUI node '%s'", parent->name); rect_parseParam(parent, "h", h);
else if(h && !(param & (1<<3))) rect_parseParam(parent, "x", x);
WARN("Missing parameter 'h' for GUI node '%s'", parent->name); rect_parseParam(parent, "y", y);
} }
/* Parse a gui node. */ /* Parse a gui node. */