mirror of
https://github.com/edubart/otclient.git
synced 2025-10-20 06:23:26 +02:00
replace YAML with custom made library for reading text files named FML
This commit is contained in:
@@ -27,24 +27,22 @@
|
||||
#include <ui/uibuttonskin.h>
|
||||
#include <ui/uibutton.h>
|
||||
|
||||
void UIButtonSkin::load(const YAML::Node& node)
|
||||
void UIButtonSkin::load(FML::Node* node)
|
||||
{
|
||||
UIElementSkin::load(node);
|
||||
|
||||
m_buttonDownTextColor = getFontColor();
|
||||
m_buttonHoverTextColor = getFontColor();
|
||||
|
||||
if(yamlHasValue(node, "down state")) {
|
||||
const YAML::Node& cnode = node["down state"];
|
||||
if(FML::Node* cnode = node->at("down state")) {
|
||||
m_buttonDownImage = loadImage(cnode);
|
||||
m_buttonDownTranslate = yamlRead(cnode, "text translate", Point());
|
||||
m_buttonDownTextColor = yamlRead(cnode, "font color", getFontColor());
|
||||
m_buttonDownTranslate = cnode->readAt("text translate", Point());
|
||||
m_buttonDownTextColor = cnode->readAt("font color", getFontColor());
|
||||
}
|
||||
|
||||
if(yamlHasValue(node, "hover state")) {
|
||||
const YAML::Node& cnode = node["hover state"];
|
||||
if(FML::Node* cnode = node->at("hover state")) {
|
||||
m_buttonHoverImage = loadImage(cnode);
|
||||
m_buttonHoverTextColor = yamlRead(cnode, "font color", getFontColor());
|
||||
m_buttonHoverTextColor = cnode->readAt("font color", getFontColor());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -37,7 +37,7 @@ public:
|
||||
UIButtonSkin(const std::string& name) :
|
||||
UIElementSkin(name, UI::Button) { }
|
||||
|
||||
void load(const YAML::Node& node);
|
||||
void load(FML::Node* node);
|
||||
void draw(UIElement *element);
|
||||
|
||||
private:
|
||||
|
@@ -30,12 +30,12 @@
|
||||
#include <graphics/textures.h>
|
||||
#include <graphics/fonts.h>
|
||||
|
||||
void UIElementSkin::load(const YAML::Node& node)
|
||||
void UIElementSkin::load(FML::Node* node)
|
||||
{
|
||||
m_defaultSize = yamlRead(node, "default size", Size());
|
||||
m_defaultSize = node->readAt("default size", Size());
|
||||
m_defaultImage = loadImage(node);
|
||||
m_font = loadFont(node);
|
||||
m_fontColor = yamlRead(node, "font color", g_uiSkins.getDefaultFontColor());
|
||||
m_fontColor = node->readAt("font color", g_uiSkins.getDefaultFontColor());
|
||||
}
|
||||
|
||||
void UIElementSkin::apply(UIElement* element)
|
||||
@@ -50,23 +50,22 @@ void UIElementSkin::draw(UIElement *element)
|
||||
m_defaultImage->draw(element->getRect());
|
||||
}
|
||||
|
||||
ImagePtr UIElementSkin::loadImage(const YAML::Node& node)
|
||||
ImagePtr UIElementSkin::loadImage(FML::Node* node)
|
||||
{
|
||||
ImagePtr image;
|
||||
TexturePtr texture;
|
||||
|
||||
if(yamlHasValue(node, "bordered image")) {
|
||||
const YAML::Node& cnode = node["bordered image"];
|
||||
Rect left = yamlRead(cnode, "left border", Rect());
|
||||
Rect right = yamlRead(cnode, "right border", Rect());
|
||||
Rect top = yamlRead(cnode, "top border", Rect());
|
||||
Rect bottom = yamlRead(cnode, "bottom border", Rect());
|
||||
Rect topLeft = yamlRead(cnode, "top left corner", Rect());
|
||||
Rect topRight = yamlRead(cnode, "top right corner", Rect());
|
||||
Rect bottomLeft = yamlRead(cnode, "bottom left corner", Rect());
|
||||
Rect bottomRight = yamlRead(cnode, "bottom right corner", Rect());
|
||||
Rect center = yamlRead(cnode, "center", Rect());
|
||||
std::string textureName = yamlRead(cnode, "source", std::string());
|
||||
if(FML::Node* cnode = node->at("bordered image")) {
|
||||
Rect left = cnode->readAt("left border", Rect());
|
||||
Rect right = cnode->readAt("right border", Rect());
|
||||
Rect top = cnode->readAt("top border", Rect());
|
||||
Rect bottom = cnode->readAt("bottom border", Rect());
|
||||
Rect topLeft = cnode->readAt("top left corner", Rect());
|
||||
Rect topRight = cnode->readAt("top right corner", Rect());
|
||||
Rect bottomLeft = cnode->readAt("bottom left corner", Rect());
|
||||
Rect bottomRight = cnode->readAt("bottom right corner", Rect());
|
||||
Rect center = cnode->readAt("center", Rect());
|
||||
std::string textureName = cnode->readAt("source", std::string());
|
||||
|
||||
if(!textureName.empty())
|
||||
texture = g_textures.get(textureName);
|
||||
@@ -87,20 +86,20 @@ ImagePtr UIElementSkin::loadImage(const YAML::Node& node)
|
||||
}
|
||||
|
||||
if(!image)
|
||||
logError(yamlErrorDesc(cnode, "failed to load bordered image"));
|
||||
} else if(yamlHasValue(node, "image")) {
|
||||
texture = g_textures.get(yamlRead<std::string>(node, "image"));
|
||||
logError(node->generateErrorMessage("failed to load bordered image"));
|
||||
} else if(FML::Node* cnode = node->at("image")) {
|
||||
texture = g_textures.get(cnode->value());
|
||||
if(texture)
|
||||
image = ImagePtr(new Image(texture));
|
||||
if(!m_defaultSize.isValid())
|
||||
m_defaultSize = texture->getSize();
|
||||
|
||||
if(!image)
|
||||
logError(yamlErrorDesc(node["image"], "failed to load image"));
|
||||
logError(cnode->generateErrorMessage("failed to load image"));
|
||||
}
|
||||
|
||||
if(texture) {
|
||||
bool antialised = yamlRead(node, "antialised", false);
|
||||
bool antialised = node->readAt("antialised", false);
|
||||
if(antialised)
|
||||
texture->enableBilinearFilter();
|
||||
}
|
||||
@@ -108,11 +107,11 @@ ImagePtr UIElementSkin::loadImage(const YAML::Node& node)
|
||||
return image;
|
||||
}
|
||||
|
||||
FontPtr UIElementSkin::loadFont(const YAML::Node& node)
|
||||
FontPtr UIElementSkin::loadFont(FML::Node* node)
|
||||
{
|
||||
FontPtr font;
|
||||
if(yamlHasValue(node, "font"))
|
||||
font = g_fonts.get(yamlRead<std::string>(node, "font"));
|
||||
if(FML::Node* cnode = node->at("font"))
|
||||
font = g_fonts.get(cnode->value());
|
||||
if(!font)
|
||||
font = g_uiSkins.getDefaultFont();
|
||||
return font;
|
||||
|
@@ -41,8 +41,8 @@ public:
|
||||
UIElementSkin() : m_elementType(UI::Element) { }
|
||||
virtual ~UIElementSkin() { }
|
||||
|
||||
/// Load the skin from a YAML node
|
||||
virtual void load(const YAML::Node& node);
|
||||
/// Load the skin from a FML node
|
||||
virtual void load(FML::Node* node);
|
||||
/// Apply the skin to an element
|
||||
virtual void apply(UIElement *element);
|
||||
/// Draw the skinned element
|
||||
@@ -56,8 +56,8 @@ public:
|
||||
Color getFontColor() const { return m_fontColor; }
|
||||
|
||||
protected:
|
||||
ImagePtr loadImage(const YAML::Node& node);
|
||||
FontPtr loadFont(const YAML::Node &node);
|
||||
ImagePtr loadImage(FML::Node* node);
|
||||
FontPtr loadFont(FML::Node* node);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include <ui/uilabelskin.h>
|
||||
#include <ui/uilabel.h>
|
||||
|
||||
void UILabelSkin::load(const YAML::Node& node)
|
||||
void UILabelSkin::load(FML::Node* node)
|
||||
{
|
||||
UIElementSkin::load(node);
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ public:
|
||||
UILabelSkin(const std::string& name) :
|
||||
UIElementSkin(name, UI::Label) { }
|
||||
|
||||
void load(const YAML::Node& node);
|
||||
void load(FML::Node* node);
|
||||
void apply(UIElement *element);
|
||||
void draw(UIElement *element);
|
||||
};
|
||||
|
@@ -67,93 +67,81 @@ UIElementPtr UILoader::createElementFromId(const std::string& id)
|
||||
return element;
|
||||
}
|
||||
|
||||
UIElementPtr UILoader::loadFromYAML(std::string filePath, const UIContainerPtr& parent)
|
||||
UIElementPtr UILoader::loadFromFile(std::string filePath, const UIContainerPtr& parent)
|
||||
{
|
||||
std::stringstream fin;
|
||||
if(!g_resources.loadFile(filePath, fin)) {
|
||||
flogError("ERROR: Could not load ui file \"%s", filePath.c_str());
|
||||
flogError("ERROR: Could not load ui file \"%s", filePath.c_str());
|
||||
return UIElementPtr();
|
||||
}
|
||||
|
||||
m_currentFile = filePath;
|
||||
|
||||
try {
|
||||
YAML::Parser parser(fin);
|
||||
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
FML::Parser parser(fin);
|
||||
if(!parser.hasError()) {
|
||||
FML::Node* doc = parser.getDocument();
|
||||
|
||||
// get element id
|
||||
std::string elementId;
|
||||
doc.begin().first() >> elementId;
|
||||
std::string elementId = doc->front()->tag();
|
||||
|
||||
// first we should populate all elements
|
||||
// only after that we can load anchors
|
||||
|
||||
// create element interpreting it's id
|
||||
UIElementPtr element = createElementFromId(elementId);
|
||||
if(!element)
|
||||
yamlThrowError(doc.begin().first(), "invalid element type");
|
||||
if(!element) {
|
||||
logError(doc->front()->generateErrorMessage("invalid root element type"));
|
||||
return element;
|
||||
}
|
||||
parent->addChild(element);
|
||||
|
||||
// populete it
|
||||
if(element->asUIContainer())
|
||||
populateContainer(element->asUIContainer(), doc.begin().second());
|
||||
populateContainer(element->asUIContainer(), doc->front());
|
||||
|
||||
// now do the real load
|
||||
loadElements(element, doc.begin().second());
|
||||
loadElements(element, doc->front());
|
||||
|
||||
// report onLoad events
|
||||
element->onLoad();
|
||||
return element;
|
||||
} catch (YAML::Exception& e) {
|
||||
flogError("ERROR: Failed to load ui file \"%s\":\n %s", filePath.c_str() % e.what());
|
||||
} else {
|
||||
flogError("ERROR: Failed to load ui file \"%s\":\n %s", filePath.c_str() % parser.getErrorMessage());
|
||||
}
|
||||
|
||||
return UIElementPtr();
|
||||
}
|
||||
|
||||
void UILoader::populateContainer(const UIContainerPtr& parent, const YAML::Node& node)
|
||||
void UILoader::populateContainer(const UIContainerPtr& parent, FML::Node* node)
|
||||
{
|
||||
// order nodes
|
||||
std::map<int, std::string> orderedNodes;
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
std::string id;
|
||||
it.first() >> id;
|
||||
|
||||
// check if it's an element id
|
||||
if(id.find("#") != std::string::npos)
|
||||
orderedNodes[it.first().GetMark().pos] = id;
|
||||
}
|
||||
|
||||
// populate ordered elements
|
||||
foreach(auto pair, orderedNodes) {
|
||||
std::string id = pair.second;
|
||||
const YAML::Node& cnode = node[id];
|
||||
foreach(FML::Node* cnode, *node) {
|
||||
std::string id = cnode->tag();
|
||||
if(id.find("#") != std::string::npos) {
|
||||
UIElementPtr element = createElementFromId(id);
|
||||
if(!element) {
|
||||
logError(cnode->generateErrorMessage("invalid element type"));
|
||||
continue;
|
||||
}
|
||||
parent->addChild(element);
|
||||
|
||||
UIElementPtr element = createElementFromId(id);
|
||||
if(!element) {
|
||||
logError(yamlErrorDesc(cnode, "invalid element type"));
|
||||
continue;
|
||||
// also populate this element if it's a parent
|
||||
if(element->asUIContainer())
|
||||
populateContainer(element->asUIContainer(), cnode);
|
||||
}
|
||||
parent->addChild(element);
|
||||
|
||||
// also populate this element if it's a parent
|
||||
if(element->asUIContainer())
|
||||
populateContainer(element->asUIContainer(), cnode);
|
||||
}
|
||||
}
|
||||
|
||||
void UILoader::loadElements(const UIElementPtr& parent, const YAML::Node& node)
|
||||
void UILoader::loadElements(const UIElementPtr& parent, FML::Node* node)
|
||||
{
|
||||
loadElement(parent, node);
|
||||
|
||||
if(UIContainerPtr container = parent->asUIContainer()) {
|
||||
foreach(const UIElementPtr& element, container->getChildren()) {
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
foreach(FML::Node* cnode, *node) {
|
||||
// node found, load it
|
||||
if(boost::ends_with(yamlRead<std::string>(it.first()), "#" + element->getId())) {
|
||||
loadElements(element, it.second());
|
||||
if(boost::ends_with(cnode->tag(), "#" + element->getId())) {
|
||||
loadElements(element, cnode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -161,13 +149,12 @@ void UILoader::loadElements(const UIElementPtr& parent, const YAML::Node& node)
|
||||
}
|
||||
}
|
||||
|
||||
void UILoader::loadElement(const UIElementPtr& element, const YAML::Node& node)
|
||||
void UILoader::loadElement(const UIElementPtr& element, FML::Node* node)
|
||||
{
|
||||
// set element skin
|
||||
if(yamlHasValue(node, "skin")) {
|
||||
const YAML::Node& cnode = node["skin"];
|
||||
if(cnode.Type() == YAML::NodeType::Scalar) {
|
||||
element->setSkin(g_uiSkins.getElementSkin(element->getElementType(), yamlRead<std::string>(cnode)));
|
||||
if(FML::Node* cnode = node->at("skin")) {
|
||||
if(cnode->hasValue()) {
|
||||
element->setSkin(g_uiSkins.getElementSkin(element->getElementType(), cnode->value()));
|
||||
} else {
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UIElementSkin());
|
||||
skin->load(cnode);
|
||||
@@ -177,46 +164,45 @@ void UILoader::loadElement(const UIElementPtr& element, const YAML::Node& node)
|
||||
element->setSkin(g_uiSkins.getElementSkin(element->getElementType(), "default"));
|
||||
|
||||
// load elements common proprieties
|
||||
if(yamlHasValue(node, "size"))
|
||||
element->setSize(yamlRead<Size>(node, "size"));
|
||||
element->setMarginLeft(yamlRead(node, "margin.left", 0));
|
||||
element->setMarginRight(yamlRead(node, "margin.right", 0));
|
||||
element->setMarginTop(yamlRead(node, "margin.top", 0));
|
||||
element->setMarginBottom(yamlRead(node, "margin.bottom", 0));
|
||||
if(node->hasNode("size"))
|
||||
element->setSize(node->readAt<Size>("size"));
|
||||
|
||||
if(yamlHasValue(node, "anchors.left"))
|
||||
loadElementAnchor(element, UI::AnchorLeft, node["anchors.left"]);
|
||||
element->setMarginLeft(node->readAt("margin.left", 0));
|
||||
element->setMarginRight(node->readAt("margin.right", 0));
|
||||
element->setMarginTop(node->readAt("margin.top", 0));
|
||||
element->setMarginBottom(node->readAt("margin.bottom", 0));
|
||||
|
||||
if(yamlHasValue(node, "anchors.right"))
|
||||
loadElementAnchor(element, UI::AnchorRight, node["anchors.right"]);
|
||||
if(node->hasNode("anchors.left"))
|
||||
loadElementAnchor(element, UI::AnchorLeft, node->at("anchors.left"));
|
||||
|
||||
if(yamlHasValue(node, "anchors.top"))
|
||||
loadElementAnchor(element, UI::AnchorTop, node["anchors.top"]);
|
||||
if(node->hasNode("anchors.right"))
|
||||
loadElementAnchor(element, UI::AnchorRight, node->at("anchors.right"));
|
||||
|
||||
if(yamlHasValue(node, "anchors.bottom"))
|
||||
loadElementAnchor(element, UI::AnchorBottom, node["anchors.bottom"]);
|
||||
if(node->hasNode("anchors.top"))
|
||||
loadElementAnchor(element, UI::AnchorTop, node->at("anchors.top"));
|
||||
|
||||
if(yamlHasValue(node, "anchors.horizontalCenter"))
|
||||
loadElementAnchor(element, UI::AnchorHorizontalCenter, node["anchors.horizontalCenter"]);
|
||||
if(node->hasNode("anchors.bottom"))
|
||||
loadElementAnchor(element, UI::AnchorBottom, node->at("anchors.bottom"));
|
||||
|
||||
if(yamlHasValue(node, "anchors.verticalCenter"))
|
||||
loadElementAnchor(element, UI::AnchorVerticalCenter, node["anchors.verticalCenter"]);
|
||||
if(node->hasNode("anchors.horizontalCenter"))
|
||||
loadElementAnchor(element, UI::AnchorHorizontalCenter, node->at("anchors.horizontalCenter"));
|
||||
|
||||
if(node->hasNode("anchors.verticalCenter"))
|
||||
loadElementAnchor(element, UI::AnchorVerticalCenter, node->at("anchors.verticalCenter"));
|
||||
|
||||
// load events
|
||||
if(yamlHasValue(node, "onLoad")) {
|
||||
const YAML::Node& cnode = node["onLoad"];
|
||||
if(g_lua.loadBufferAsFunction(yamlRead<std::string>(cnode), getElementSourceDesc(element, "onLoad")))
|
||||
if(FML::Node* cnode = node->at("onLoad")) {
|
||||
if(g_lua.loadBufferAsFunction(cnode->value(), getElementSourceDesc(element, "onLoad")))
|
||||
g_lua.setScriptableField(element, "onLoad");
|
||||
else
|
||||
logError(yamlErrorDesc(cnode, "failed to parse inline lua script"));
|
||||
logError(cnode->generateErrorMessage("failed to parse inline lua script"));
|
||||
}
|
||||
|
||||
if(yamlHasValue(node, "onDestroy")) {
|
||||
const YAML::Node& cnode = node["onDestroy"];
|
||||
if(g_lua.loadBufferAsFunction(yamlRead<std::string>(cnode), getElementSourceDesc(element, "onDestroy")))
|
||||
if(FML::Node* cnode = node->at("onDestroy")) {
|
||||
if(g_lua.loadBufferAsFunction(cnode->value(), getElementSourceDesc(element, "onDestroy")))
|
||||
g_lua.setScriptableField(element, "onDestroy");
|
||||
else
|
||||
logError(yamlErrorDesc(cnode, "failed to parse inline lua script"));
|
||||
logError(cnode->generateErrorMessage("failed to parse inline lua script"));
|
||||
}
|
||||
|
||||
// load specific element type
|
||||
@@ -224,30 +210,29 @@ void UILoader::loadElement(const UIElementPtr& element, const YAML::Node& node)
|
||||
loadButton(boost::static_pointer_cast<UIButton>(element), node);
|
||||
else if(element->getElementType() == UI::Window) {
|
||||
UIWindowPtr window = boost::static_pointer_cast<UIWindow>(element);
|
||||
window->setTitle(yamlRead(node, "title", std::string()));
|
||||
window->setTitle(node->readAt("title", std::string()));
|
||||
}
|
||||
else if(element->getElementType() == UI::Label) {
|
||||
UILabelPtr label = boost::static_pointer_cast<UILabel>(element);
|
||||
label->setText(yamlRead(node, "text", std::string()));
|
||||
label->setAlign(parseAlignment(yamlRead(node, "align", std::string("left"))));
|
||||
label->setText(node->readAt("text", std::string()));
|
||||
label->setAlign(parseAlignment(node->readAt("align", std::string("left"))));
|
||||
}
|
||||
}
|
||||
|
||||
void UILoader::loadElementAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, const YAML::Node& node)
|
||||
void UILoader::loadElementAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, FML::Node* node)
|
||||
{
|
||||
UIAnchorLayoutPtr layout = boost::dynamic_pointer_cast<UIAnchorLayout>(anchoredElement->getLayout());
|
||||
if(!layout) {
|
||||
logError(yamlErrorDesc(node, "could not add anchor, because this element does not participate of an anchor layout"));
|
||||
logError(node->generateErrorMessage("could not add anchor, because this element does not participate of an anchor layout"));
|
||||
return;
|
||||
}
|
||||
|
||||
std::string anchorDescription;
|
||||
node >> anchorDescription;
|
||||
std::string anchorDescription = node->value();
|
||||
|
||||
std::vector<std::string> split;
|
||||
boost::split(split, anchorDescription, boost::is_any_of(std::string(".")));
|
||||
if(split.size() != 2) {
|
||||
logError(yamlErrorDesc(node, "invalid anchor"));
|
||||
logError(node->generateErrorMessage("invalid anchor"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -255,25 +240,24 @@ void UILoader::loadElementAnchor(const UIElementPtr& anchoredElement, UI::Anchor
|
||||
UI::AnchorPoint anchorLineEdge = UIAnchorLayout::parseAnchorPoint(split[1]);
|
||||
|
||||
if(anchorLineEdge == UI::AnchorNone) {
|
||||
logError(yamlErrorDesc(node, "invalid anchor type"));
|
||||
logError(node->generateErrorMessage("invalid anchor type"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!layout->addAnchor(anchoredElement, anchoredEdge, AnchorLine(anchorLineElementId, anchorLineEdge)))
|
||||
logError(yamlErrorDesc(node, "anchoring failed"));
|
||||
logError(node->generateErrorMessage("anchoring failed"));
|
||||
}
|
||||
|
||||
void UILoader::loadButton(const UIButtonPtr& button, const YAML::Node& node)
|
||||
void UILoader::loadButton(const UIButtonPtr& button, FML::Node* node)
|
||||
{
|
||||
button->setText(yamlRead<std::string>(node["text"]));
|
||||
button->setText(node->valueAt("text"));
|
||||
|
||||
// set on click event
|
||||
if(yamlHasValue(node, "onClick")) {
|
||||
const YAML::Node& cnode = node["onClick"];
|
||||
if(g_lua.loadBufferAsFunction(yamlRead<std::string>(cnode), getElementSourceDesc(button, "onClick")))
|
||||
if(FML::Node* cnode = node->at("onClick")) {
|
||||
if(g_lua.loadBufferAsFunction(cnode->value(), getElementSourceDesc(button, "onClick")))
|
||||
g_lua.setScriptableField(button, "onClick");
|
||||
else
|
||||
logError(yamlErrorDesc(cnode, "failed to parse inline lua script"));
|
||||
logError(cnode->generateErrorMessage("failed to parse inline lua script"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,27 +33,27 @@
|
||||
class UILoader
|
||||
{
|
||||
public:
|
||||
/// Loads an UIElement and it's children from a YAML file
|
||||
UIElementPtr loadFromYAML(std::string filePath, const UIContainerPtr& parent = UIContainer::getRoot());
|
||||
/// Loads an UIElement and it's children from a FML file
|
||||
UIElementPtr loadFromFile(std::string filePath, const UIContainerPtr& parent = UIContainer::getRoot());
|
||||
|
||||
private:
|
||||
/// Detect element type and create it
|
||||
UIElementPtr createElementFromId(const std::string& id);
|
||||
|
||||
/// Populate container children from a YAML node
|
||||
void populateContainer(const UIContainerPtr& parent, const YAML::Node& node);
|
||||
/// Populate container children from a FML node
|
||||
void populateContainer(const UIContainerPtr& parent, FML::Node* node);
|
||||
|
||||
/// Load element and its children from a YAML node
|
||||
void loadElements(const UIElementPtr& parent, const YAML::Node& node);
|
||||
/// Load element and its children from a FML node
|
||||
void loadElements(const UIElementPtr& parent, FML::Node* node);
|
||||
|
||||
/// Load element proprieties from a YAML node
|
||||
void loadElement(const UIElementPtr& element, const YAML::Node& node);
|
||||
/// Load element proprieties from a FML node
|
||||
void loadElement(const UIElementPtr& element, FML::Node* node);
|
||||
|
||||
/// Load anchor from a YAML node
|
||||
void loadElementAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, const YAML::Node& node);
|
||||
/// Load anchor from a FML node
|
||||
void loadElementAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, FML::Node* node);
|
||||
|
||||
// specific elements loading
|
||||
void loadButton(const UIButtonPtr& button, const YAML::Node& node);
|
||||
void loadButton(const UIButtonPtr& button, FML::Node* node);
|
||||
|
||||
std::string getElementSourceDesc(const UIElementPtr& element, const std::string& key = "");
|
||||
|
||||
|
@@ -43,97 +43,62 @@ void UISkins::load(const std::string& skinName)
|
||||
if(!g_resources.loadFile(skinName + ".yml", fin))
|
||||
flogFatal("FATAL ERROR: Could not load skin \"%s", skinName.c_str());
|
||||
|
||||
try {
|
||||
YAML::Parser parser(fin);
|
||||
FML::Parser parser(fin);
|
||||
if(!parser.hasError()) {
|
||||
FML::Node* doc = parser.getDocument();
|
||||
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
|
||||
m_defaultFont = g_fonts.get(yamlRead<std::string>(doc, "default font"));
|
||||
m_defaultFont = g_fonts.get(doc->readAt<std::string>("default font"));
|
||||
if(!m_defaultFont)
|
||||
logFatal("FATAL ERROR: Could not load skin default font");
|
||||
|
||||
m_defaultFontColor = yamlRead(doc, "default font color", Color::white);
|
||||
m_defaultFontColor = doc->readAt("default font color", Color::white);
|
||||
|
||||
std::string defaultTextureName = yamlRead(doc, "default texture", std::string());
|
||||
std::string defaultTextureName = doc->readAt("default texture", std::string());
|
||||
if(!defaultTextureName.empty())
|
||||
m_defaultTexture = g_textures.get(defaultTextureName);
|
||||
|
||||
{
|
||||
const YAML::Node& node = doc["buttons"];
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
std::string name;
|
||||
it.first() >> name;
|
||||
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UIButtonSkin(name));
|
||||
skin->load(it.second());
|
||||
if(FML::Node* node = doc->at("buttons")) {
|
||||
foreach(FML::Node* cnode, *node) {
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UIButtonSkin(cnode->tag()));
|
||||
skin->load(cnode);
|
||||
m_elementSkins.push_back(skin);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const YAML::Node& node = doc["panels"];
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
std::string name;
|
||||
it.first() >> name;
|
||||
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UIElementSkin(name, UI::Panel));
|
||||
skin->load(it.second());
|
||||
if(FML::Node* node = doc->at("panels")) {
|
||||
foreach(FML::Node* cnode, *node) {
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UIElementSkin(cnode->tag(), UI::Panel));
|
||||
skin->load(cnode);
|
||||
m_elementSkins.push_back(skin);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const YAML::Node& node = doc["windows"];
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
std::string name;
|
||||
it.first() >> name;
|
||||
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UIWindowSkin(name));
|
||||
skin->load(it.second());
|
||||
if(FML::Node* node = doc->at("windows")) {
|
||||
foreach(FML::Node* cnode, *node) {
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UIWindowSkin(cnode->tag()));
|
||||
skin->load(cnode);
|
||||
m_elementSkins.push_back(skin);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const YAML::Node& node = doc["labels"];
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
std::string name;
|
||||
it.first() >> name;
|
||||
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UILabelSkin(name));
|
||||
skin->load(it.second());
|
||||
if(FML::Node* node = doc->at("labels")) {
|
||||
foreach(FML::Node* cnode, *node) {
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UILabelSkin(cnode->tag()));
|
||||
skin->load(cnode);
|
||||
m_elementSkins.push_back(skin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
const YAML::Node& node = doc["text edits"];
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
std::string name;
|
||||
it.first() >> name;
|
||||
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UITextEditSkin(name));
|
||||
skin->load(it.second());
|
||||
if(FML::Node* node = doc->at("text edits")) {
|
||||
foreach(FML::Node* cnode, *node) {
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UITextEditSkin(cnode->tag()));
|
||||
skin->load(cnode);
|
||||
m_elementSkins.push_back(skin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
const YAML::Node& node = doc["line decorations"];
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
std::string name;
|
||||
it.first() >> name;
|
||||
|
||||
UIElementSkinPtr skin = UIElementSkinPtr(new UIElementSkin(name, UI::LineDecoration));
|
||||
skin->load(it.second());
|
||||
m_elementSkins.push_back(skin);
|
||||
}
|
||||
}
|
||||
} catch (YAML::Exception& e) {
|
||||
flogFatal("FATAL ERROR: Malformed skin file \"%s\":\n %s", skinName.c_str() % e.what());
|
||||
} else {
|
||||
flogFatal("FATAL ERROR: Malformed skin file \"%s\":\n %s", skinName.c_str() % parser.getErrorMessage());
|
||||
}
|
||||
|
||||
g_resources.popCurrentPath();
|
||||
|
@@ -27,10 +27,10 @@
|
||||
#include <ui/uitexteditskin.h>
|
||||
#include <ui/uitextedit.h>
|
||||
|
||||
void UITextEditSkin::load(const YAML::Node& node)
|
||||
void UITextEditSkin::load(FML::Node* node)
|
||||
{
|
||||
UIElementSkin::load(node);
|
||||
m_textMargin = yamlRead(node, "text margin", 2);
|
||||
m_textMargin = node->readAt("text margin", 2);
|
||||
}
|
||||
|
||||
void UITextEditSkin::apply(UIElement* element)
|
||||
|
@@ -36,7 +36,7 @@ public:
|
||||
UITextEditSkin(const std::string& name) :
|
||||
UIElementSkin(name, UI::TextEdit) { }
|
||||
|
||||
void load(const YAML::Node& node);
|
||||
void load(FML::Node* node);
|
||||
void apply(UIElement *element);
|
||||
void draw(UIElement *element);
|
||||
|
||||
|
@@ -26,17 +26,17 @@
|
||||
#include <ui/uiwindowskin.h>
|
||||
#include <ui/uiwindow.h>
|
||||
|
||||
void UIWindowSkin::load(const YAML::Node& node)
|
||||
void UIWindowSkin::load(FML::Node* node)
|
||||
{
|
||||
UIElementSkin::load(node);
|
||||
|
||||
const YAML::Node& headNode = node["head"];
|
||||
const YAML::Node& bodyNode = node["body"];
|
||||
FML::Node* headNode = node->at("head");
|
||||
FML::Node* bodyNode = node->at("body");
|
||||
|
||||
m_headImage = boost::dynamic_pointer_cast<BorderedImage>(loadImage(headNode));
|
||||
m_headHeight = yamlRead(headNode, "height", m_headImage->getDefaultSize().height());
|
||||
m_headMargin = yamlRead(headNode, "margin", 0);
|
||||
m_titleAlign = parseAlignment(yamlRead(headNode, "text align", std::string("center")));
|
||||
m_headHeight = headNode->readAt("height", m_headImage->getDefaultSize().height());
|
||||
m_headMargin = headNode->readAt("margin", 0);
|
||||
m_titleAlign = parseAlignment(headNode->readAt("text align", std::string("center")));
|
||||
m_bodyImage = loadImage(bodyNode);
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,7 @@ public:
|
||||
UIWindowSkin(const std::string& name) :
|
||||
UIElementSkin(name, UI::Window) { }
|
||||
|
||||
void load(const YAML::Node& node);
|
||||
void load(FML::Node* node);
|
||||
void draw(UIElement *element);
|
||||
|
||||
int getHeadHeight() const { return m_headHeight; }
|
||||
|
Reference in New Issue
Block a user