void ImageExportSerializer::writeImage(pugi::xml_node _parent, DataPtr _data) { pugi::xml_node node = _parent.append_child("Resource"); node.append_attribute("type").set_value("ResourceImageSet"); node.append_attribute("name").set_value(_data->getPropertyValue("Name").c_str()); for (Data::VectorData::const_iterator child = _data->getChilds().begin(); child != _data->getChilds().end(); child ++) writeGroup(node, (*child)); }
void FontExportSerializer::serialization(pugi::xml_document& _doc) { pugi::xml_node root = _doc.append_child("MyGUI"); root.append_attribute("type").set_value("Resource"); root.append_attribute("version").set_value("1.1"); DataPtr data = DataManager::getInstance().getRoot(); for (Data::VectorData::const_iterator child = data->getChilds().begin(); child != data->getChilds().end(); child ++) writeFont(root, (*child)); }
void ImageExportSerializer::writeGroup(pugi::xml_node _parent, DataPtr _data) { pugi::xml_node node = _parent.append_child("Group"); node.append_attribute("name").set_value(_data->getPropertyValue("Name").c_str()); node.append_attribute("texture").set_value(_data->getPropertyValue("Texture").c_str()); node.append_attribute("size").set_value(MyGUI::IntCoord::parse(_data->getPropertyValue("Size")).size().print().c_str()); for (Data::VectorData::const_iterator child = _data->getChilds().begin(); child != _data->getChilds().end(); child ++) writeIndex(node, (*child)); }
DataPtr SkinExportSerializer::getChildData(DataPtr _data, const std::string& _dataType, const std::string& _name) { for (Data::VectorData::const_iterator child = _data->getChilds().begin(); child != _data->getChilds().end(); child ++) { if ((*child)->getType()->getName() == _dataType && (*child)->getPropertyValue("Name") == _name) return (*child); } return NULL; }
void ImageExportSerializer::writeIndex(pugi::xml_node _parent, DataPtr _data) { pugi::xml_node node = _parent.append_child("Index"); node.append_attribute("name").set_value(_data->getPropertyValue("Name").c_str()); std::string value = _data->getPropertyValue("Rate"); if (!value.empty()) node.append_attribute("rate").set_value(value.c_str()); for (Data::VectorData::const_iterator child = _data->getChilds().begin(); child != _data->getChilds().end(); child ++) writeFrame(node, (*child)); }
Data::VectorData DataUtility::getChildsByType(DataPtr _parent, const std::string& _type, bool _friend) { Data::VectorData result; result.reserve(_parent->getChilds().size()); for (Data::VectorData::const_iterator child = _parent->getChilds().begin(); child != _parent->getChilds().end(); child ++) { if ((*child)->getType()->getName() == _type || (_friend && (*child)->getType()->getFriend() == _type)) result.push_back((*child)); } return result; }
bool FontExportSerializer::exportData(const MyGUI::UString& _folderName, const MyGUI::UString& _fileName) { MyGUI::xml::Document document; document.createDeclaration(); MyGUI::xml::ElementPtr root = document.createRoot("MyGUI"); root->addAttribute("type", "Resource"); root->addAttribute("version", "1.1"); DataPtr data = DataManager::getInstance().getRoot(); for (Data::VectorData::const_iterator child = data->getChilds().begin(); child != data->getChilds().end(); child ++) { generateFont((*child)); generateFontManualXml(root, _folderName, (*child)); } return document.save(common::concatenatePath(_folderName, _fileName)); }
MyGUI::IntPoint ImageExportSerializer::getFirstFramePoint(DataPtr _data) { if (_data->getType()->getName() != "Group") return MyGUI::IntPoint(); if (_data->getChilds().size() != 0) { DataPtr child = _data->getChildByIndex(0); if (child->getChilds().size() != 0) { return child->getChildByIndex(0)->getPropertyValue<MyGUI::IntPoint>("Point"); } } return MyGUI::IntPoint(); }
void DataUtility::cloneData(DataPtr _target, DataPtr _prototype) { MYGUI_ASSERT(_target != _prototype, "Error clone self"); MYGUI_ASSERT(_target->getType() == _prototype->getType(), "Error clone different types"); MYGUI_ASSERT(_target->getChilds().size() == 0, "Target not empty"); copyProperty(_target, _prototype); for (Data::VectorData::const_iterator child = _prototype->getChilds().begin(); child != _prototype->getChilds().end(); child ++) { DataPtr data = Data::CreateInstance(); data->setType((*child)->getType()); _target->addChild(data); cloneData(data, *child); } }
void ImageExportSerializer::updateGroupProperty(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); updateIndexProperty(*child); } }
bool DataUtility::checkUniqueName(DataPtr _parent, const std::string& _name) { for (Data::VectorData::const_iterator child = _parent->getChilds().begin(); child != _parent->getChilds().end(); child ++) { if ((*child)->getPropertyValue("Name") == _name) return false; } return true; }
void ChangeSkinSizeAction::storeRegionValues(DataPtr _skinData, VectorPairProperty& _store) { const Data::VectorData& childs = _skinData->getChilds(); for (Data::VectorData::const_iterator child = childs.begin(); child != childs.end(); child++) { if ((*child)->getType()->getName() != "Region") continue; PropertyPtr property = (*child)->getProperty("Coord"); _store.push_back(std::make_pair(property, property->getValue())); } }
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 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 SkinExportSerializer::writeRegion(pugi::xml_node _parent, DataPtr _parentData, DataPtr _data, bool _text) { bool isVisible = MyGUI::utility::parseValue<bool>(_data->getPropertyValue("Visible")) && MyGUI::utility::parseValue<bool>(_data->getPropertyValue("Enable")); if (!isVisible) return; MyGUI::IntCoord coord = MyGUI::IntCoord::parse(_data->getPropertyValue("Coord")); std::string type = _data->getPropertyValue("Type"); bool tileVert = true; bool tileHorz = true; if (type == "TileRect Vert") { type = "TileRect"; tileHorz = false; } else if (type == "TileRect Horz") { type = "TileRect"; tileVert = false; } pugi::xml_node node = _parent.append_child("BasisSkin"); node.append_attribute("type").set_value(type.c_str()); node.append_attribute("offset").set_value(coord.print().c_str()); node.append_attribute("align").set_value(convertEditorToExportAlign(_data->getPropertyValue("Name")).c_str()); for (Data::VectorData::const_iterator child = _parentData->getChilds().begin(); child != _parentData->getChilds().end(); child ++) { if ((*child)->getType()->getName() != "State") continue; bool visible = MyGUI::utility::parseValue<bool>((*child)->getPropertyValue("Visible")); if (!visible) continue; if (_text) { writeStateText(node, (*child), coord); } else { pugi::xml_node stateNode = writeState(node, (*child), coord); if (type == "TileRect") { pugi::xml_node propertyNode = stateNode.append_child("Property"); propertyNode.append_attribute("key").set_value("TileSize"); propertyNode.append_attribute("value").set_value(coord.size().print().c_str()); propertyNode = stateNode.append_child("Property"); propertyNode.append_attribute("key").set_value("TileH"); propertyNode.append_attribute("value").set_value(MyGUI::utility::toString(tileHorz).c_str()); propertyNode = stateNode.append_child("Property"); propertyNode.append_attribute("key").set_value("TileV"); propertyNode.append_attribute("value").set_value(MyGUI::utility::toString(tileVert).c_str()); } } } }