void SkinExportSerializer::parseSkin(pugi::xml_node _node) { DataPtr data = Data::CreateInstance(); data->setType(DataTypeManager::getInstance().getType("Skin")); data->setPropertyValue("Name", _node.attribute("name").value()); data->setPropertyValue("Texture", _node.attribute("texture").value()); DataManager::getInstance().getRoot()->addChild(data); SkinDataUtility::CreateSkinData(data); fillStateData(data, _node); DataPtr state = getChildData(data, "State", "Normal"); std::string value = state != nullptr ? state->getPropertyValue("Point") : ""; MyGUI::IntPoint point = MyGUI::IntPoint::parse(value); MyGUI::IntSize size = MyGUI::IntSize::parse(_node.attribute("size").value()); data->setPropertyValue("Size", MyGUI::IntCoord(point.left, point.top, size.width, size.height).print()); fillSeparatorData(data, _node); MyGUI::IntRect separators = SkinDataUtility::getSeparatorsOffset(data); SkinDataUtility::VectorCoord coords = SkinDataUtility::getRegions(size, separators); SkinDataUtility::fillRegionCoords(data, coords); SkinDataUtility::RectVisible visible = SkinDataUtility::getSeparatorsVisible(data); SkinDataUtility::fillRegionEnable(data, visible); fillRegionData(data, _node); }
void ImageExportSerializer::parseFrame(pugi::xml_node _node, DataPtr _parent) { DataPtr data = Data::CreateInstance(); data->setType(DataTypeManager::getInstance().getType("Frame")); data->setPropertyValue("Point", _node.attribute("point").value()); std::string value = _node.attribute("count").value(); if (value.empty()) value = "1"; data->setPropertyValue("Count", value); _parent->addChild(data); }
void SkinExportSerializer::fillSeparatorData(DataPtr _data, pugi::xml_node _node) { pugi::xpath_node_set regions = _node.select_nodes("BasisSkin[@type=\"SubSkin\"or@type=\"TileRect\"]"); for (pugi::xpath_node_set::const_iterator region = regions.begin(); region != regions.end(); region ++) { MyGUI::IntCoord offset = MyGUI::IntCoord::parse((*region).node().attribute("offset").value()); MyGUI::Align align = MyGUI::Align::parse((*region).node().attribute("align").value()); if (align.isLeft()) { DataPtr data = getChildData(_data, "Separator", "Left"); data->setPropertyValue("Visible", "True"); data->setPropertyValue("Offset", MyGUI::utility::toString(offset.width)); } else if (align.isRight()) { DataPtr data = getChildData(_data, "Separator", "Right"); data->setPropertyValue("Visible", "True"); data->setPropertyValue("Offset", MyGUI::utility::toString(offset.width)); } if (align.isTop()) { DataPtr data = getChildData(_data, "Separator", "Top"); data->setPropertyValue("Visible", "True"); data->setPropertyValue("Offset", MyGUI::utility::toString(offset.height)); } else if (align.isBottom()) { DataPtr data = getChildData(_data, "Separator", "Bottom"); data->setPropertyValue("Visible", "True"); data->setPropertyValue("Offset", MyGUI::utility::toString(offset.height)); } } }
void ImageExportSerializer::parseIndex(pugi::xml_node _node, DataPtr _parent) { DataPtr data = Data::CreateInstance(); data->setType(DataTypeManager::getInstance().getType("Index")); std::string value = _node.attribute("name").value(); if (value.empty()) value = "unnamed"; data->setPropertyValue("Name", value); data->setPropertyValue("Rate", _node.attribute("rate").value()); _parent->addChild(data); pugi::xpath_node_set nodes = _node.select_nodes("Frame"); for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++) parseFrame((*node).node(), data); }
void FontTextureController::updateResultPropery(DataPtr _data) { MyGUI::IResource* resource = MyGUI::ResourceManager::getInstance().findByName(_data->getPropertyValue("FontName")); MyGUI::ResourceTrueTypeFont* font = resource != nullptr ? resource->castType<MyGUI::ResourceTrueTypeFont>(false) : nullptr; MyGUI::ITexture* texture = font != nullptr ? font->getTextureFont() : nullptr; if (texture != nullptr) _data->setPropertyValue("TextureSizeResult", MyGUI::utility::toString(texture->getWidth(), " ", texture->getHeight())); else _data->setPropertyValue("TextureSizeResult", "0 0"); if (font != nullptr) _data->setPropertyValue("FontHeightPix", font->getDefaultHeight()); else _data->setPropertyValue("FontHeightPix", "0"); }
void ImageExportSerializer::parseGroup(pugi::xml_node _node, DataPtr _parent) { DataPtr data = Data::CreateInstance(); data->setType(DataTypeManager::getInstance().getType("Group")); std::string value = _node.attribute("name").value(); if (value.empty()) value = "unnamed"; data->setPropertyValue("Name", value); data->setPropertyValue("Texture", _node.attribute("texture").value()); MyGUI::IntSize size = MyGUI::IntSize::parse(_node.attribute("size").value()); data->setPropertyValue("Size", MyGUI::IntCoord(0, 0, size.width, size.height).print()); _parent->addChild(data); pugi::xpath_node_set nodes = _node.select_nodes("Index"); for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++) parseIndex((*node).node(), data); }
void ImageExportSerializer::parseImage(pugi::xml_node _node) { DataPtr data = Data::CreateInstance(); data->setType(DataTypeManager::getInstance().getType("Image")); data->setPropertyValue("Name", _node.attribute("name").value()); DataManager::getInstance().getRoot()->addChild(data); pugi::xpath_node_set nodes = _node.select_nodes("Group"); for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++) parseGroup((*node).node(), data); }
void ImageExportSerializer::updateIndexProperty(DataPtr _data) { const Data::VectorData& childs = _data->getChilds(); for (Data::VectorData::const_iterator child = childs.begin(); child != childs.end(); child++) { bool unique = PropertyUtility::isUniqueName((*child), "Name"); (*child)->setPropertyValue("UniqueName", unique); } MyGUI::IntPoint point = getFirstFramePoint(_data); MyGUI::IntSize size = _data->getPropertyValue<MyGUI::IntCoord>("Size").size(); MyGUI::IntCoord coord(point, size); _data->setPropertyValue("Size", coord); }
void FontExportSerializer::parseFont(pugi::xml_node _node) { DataPtr data = Data::CreateInstance(); data->setType(DataTypeManager::getInstance().getType("Font")); data->setPropertyValue("Name", _node.attribute("name").value()); std::string value = _node.select_single_node("Property[@key=\"Source\"]/@value").attribute().value(); data->setPropertyValue("Source", value); value = _node.select_single_node("Property[@key=\"Size\"]/@value").attribute().value(); data->setPropertyValue("Size", MyGUI::utility::parseValue<float>(value)); value = _node.select_single_node("Property[@key=\"Hinting\"]/@value").attribute().value(); if (value.empty()) value = "use_native"; data->setPropertyValue("Hinting", value); value = _node.select_single_node("Property[@key=\"Resolution\"]/@value").attribute().value(); if (!value.empty()) data->setPropertyValue("Resolution", MyGUI::utility::parseValue<int>(value)); value = _node.select_single_node("Property[@key=\"Antialias\"]/@value").attribute().value(); if (!value.empty()) data->setPropertyValue("Antialias", MyGUI::utility::parseValue<bool>(value)); value = _node.select_single_node("Property[@key=\"TabWidth\"]/@value").attribute().value(); if (!value.empty()) data->setPropertyValue("TabWidth", MyGUI::utility::parseValue<float>(value)); value = _node.select_single_node("Property[@key=\"OffsetHeight\"]/@value").attribute().value(); if (!value.empty()) data->setPropertyValue("OffsetHeight", MyGUI::utility::parseValue<int>(value)); value = _node.select_single_node("Property[@key=\"SubstituteCode\"]/@value").attribute().value(); if (!value.empty()) data->setPropertyValue("SubstituteCode", MyGUI::utility::parseValue<int>(value)); value = _node.select_single_node("Property[@key=\"Distance\"]/@value").attribute().value(); if (!value.empty()) data->setPropertyValue("Distance", MyGUI::utility::parseValue<int>(value)); value = ""; pugi::xpath_node_set codes = _node.select_nodes("Codes/Code/@range"); for (pugi::xpath_node_set::const_iterator code = codes.begin(); code != codes.end(); code ++) { if (!value.empty()) value += "|"; std::vector<std::string> values = MyGUI::utility::split((*code).attribute().value()); if (values.size() == 1) value += MyGUI::utility::toString(values[0], " ", values[0]); else if (values.size() == 2) value += MyGUI::utility::toString(values[0], " ", values[1]); } data->setPropertyValue("FontCodeRanges", value); DataManager::getInstance().getRoot()->addChild(data); }
void SkinExportSerializer::fillRegionData(DataPtr _data, pugi::xml_node _node) { pugi::xpath_node_set regions = _node.select_nodes("BasisSkin[@type=\"SubSkin\"or@type=\"TileRect\"]"); for (pugi::xpath_node_set::const_iterator region = regions.begin(); region != regions.end(); region ++) { DataPtr regionData = NULL; MyGUI::Align align = MyGUI::Align::parse((*region).node().attribute("align").value()); if (align.isLeft() && align.isTop()) regionData = getChildData(_data, "Region", "Left Top"); else if (align.isLeft() && align.isVStretch()) regionData = getChildData(_data, "Region", "Left"); else if (align.isLeft() && align.isBottom()) regionData = getChildData(_data, "Region", "Left Bottom"); else if (align.isHStretch() && align.isTop()) regionData = getChildData(_data, "Region", "Top"); else if (align.isHStretch() && align.isVStretch()) regionData = getChildData(_data, "Region", "Center"); else if (align.isHStretch() && align.isBottom()) regionData = getChildData(_data, "Region", "Bottom"); else if (align.isRight() && align.isTop()) regionData = getChildData(_data, "Region", "Right Top"); else if (align.isRight() && align.isVStretch()) regionData = getChildData(_data, "Region", "Right"); else if (align.isRight() && align.isBottom()) regionData = getChildData(_data, "Region", "Right Bottom"); if (regionData == nullptr) continue; regionData->setPropertyValue("Visible", "True"); std::string type = (*region).node().attribute("type").value(); if (type == "TileRect") { bool vert = MyGUI::utility::parseValue<bool>((*region).node().select_single_node("State/Property[@key=\"TileV\"]/@value").attribute().value()); bool horz = MyGUI::utility::parseValue<bool>((*region).node().select_single_node("State/Property[@key=\"TileH\"]/@value").attribute().value()); if (vert && !horz) type = "TileRect Vert"; else if (!vert && horz) type = "TileRect Horz"; } regionData->setPropertyValue("Type", type); } pugi::xpath_node regionText = _node.select_single_node("BasisSkin[@type=\"SimpleText\"or@type=\"EditText\"]"); if (!regionText.node().empty()) { DataPtr regionData = getChildData(_data, "RegionText", "Text"); if (regionData != nullptr) { regionData->setPropertyValue("Visible", "True"); std::string type = regionText.node().attribute("type").value(); regionData->setPropertyValue("Type", type); MyGUI::IntCoord offset = MyGUI::IntCoord::parse(regionText.node().attribute("offset").value()); regionData->setPropertyValue("Coord", offset); MyGUI::Align align = MyGUI::Align::parse(regionText.node().attribute("align").value()); regionData->setPropertyValue("Align", align); } } }
void SkinExportSerializer::fillStateData(DataPtr _data, pugi::xml_node _node) { typedef std::map<std::string, MyGUI::IntPoint> MapPoint; MapPoint values; pugi::xpath_node_set states = _node.select_nodes("BasisSkin/State"); for (pugi::xpath_node_set::const_iterator state = states.begin(); state != states.end(); state ++) { MyGUI::IntCoord coord((std::numeric_limits<int>::max)(), (std::numeric_limits<int>::max)(), 0, 0); pugi::xml_attribute attribute = (*state).node().attribute("offset"); if (!attribute.empty()) coord = MyGUI::IntCoord::parse(attribute.value()); std::string name = (*state).node().attribute("name").value(); MapPoint::iterator valuesIterator = values.find(name); if (valuesIterator != values.end()) { (*valuesIterator).second = MyGUI::IntPoint( (std::min)((*valuesIterator).second.left, coord.left), (std::min)((*valuesIterator).second.top, coord.top)); } else { values[name] = coord.point(); } // create, if there is no data name = convertExportToEditorStateName(name); DataPtr childData = getChildData(_data, "State", name); if (childData == nullptr) { childData = Data::CreateInstance(); childData->setType(DataTypeManager::getInstance().getType("State")); childData->setPropertyValue("Name", name); _data->addChild(childData); } } for (Data::VectorData::const_iterator child = _data->getChilds().begin(); child != _data->getChilds().end(); child ++) { if ((*child)->getType()->getName() != "State") continue; DataPtr childData = (*child); MapPoint::iterator result = values.find(convertEditorToExportStateName(childData->getPropertyValue("Name"))); if (result != values.end()) { childData->setPropertyValue("Visible", "True"); if ((*result).second.left != (std::numeric_limits<int>::max)() && (*result).second.top != (std::numeric_limits<int>::max)()) childData->setPropertyValue("Point", (*result).second); } } states = _node.select_nodes("BasisSkin/State[@colour]"); for (pugi::xpath_node_set::const_iterator state = states.begin(); state != states.end(); state ++) { std::string name = (*state).node().attribute("name").value(); int textShift = MyGUI::utility::parseValue<int>((*state).node().attribute("shift").value()); MyGUI::Colour textColour = MyGUI::utility::parseValue<MyGUI::Colour>((*state).node().attribute("colour").value()); for (Data::VectorData::const_iterator child = _data->getChilds().begin(); child != _data->getChilds().end(); child ++) { if ((*child)->getType()->getName() != "State") continue; DataPtr childData = (*child); if (convertEditorToExportStateName(childData->getPropertyValue("Name")) == name) { childData->setPropertyValue("TextShift", textShift); childData->setPropertyValue("TextColour", MyGUI::utility::toString(textColour.red, " ", textColour.green, " ", textColour.blue)); } } } }
void DataUtility::copyProperty(DataPtr _target, DataPtr _prototype) { for (Data::MapProperty::const_iterator property = _prototype->getProperties().begin(); property != _prototype->getProperties().end(); property ++) _target->setPropertyValue((*property).first, (*property).second->getValue()); }