bool ISetting::Deserialize(const TiXmlNode *node, bool update /* = false */) { if (node == nullptr) return false; bool value; if (XMLUtils::GetBoolean(node, SETTING_XML_ELM_VISIBLE, value)) m_visible = value; auto element = node->ToElement(); if (element == nullptr) return false; int iValue = -1; if (element->QueryIntAttribute(SETTING_XML_ATTR_LABEL, &iValue) == TIXML_SUCCESS && iValue > 0) m_label = iValue; if (element->QueryIntAttribute(SETTING_XML_ATTR_HELP, &iValue) == TIXML_SUCCESS && iValue > 0) m_help = iValue; auto requirementNode = node->FirstChild(SETTING_XML_ELM_REQUIREMENT); if (requirementNode == nullptr) return true; return m_requirementCondition.Deserialize(requirementNode); }
int TiXmlElement::QueryLongAttribute( const char* name, long* value ) const { int dummy(static_cast<int>(*value)); int retVal = QueryIntAttribute(name, &dummy); *value = static_cast<long>(dummy); return retVal; }
int TiXmlElement::QueryDwordAttribute(const char* name, unsigned int* value ) const { int dummy(static_cast<int>(*value)); int retVal = QueryIntAttribute(name, &dummy); *value = static_cast<unsigned int>(dummy); return retVal; }
bool TmxObjectGroup::parseElement(void* p) { _x = 0; _y = 0; _width = 0; _height = 0; _opacity = 1.0f; _visible = true; _name = ""; _properties.clear(); _objects.clear(); auto element = static_cast<tinyxml2::XMLElement*>(p); if(!element) { return false; } if(element->Attribute("name")) { _name = element->Attribute("name"); } element->QueryIntAttribute("x", &_x); element->QueryIntAttribute("y", &_y); element->QueryIntAttribute("width", &_width); element->QueryIntAttribute("height", &_height); element->QueryFloatAttribute("opacity", &_opacity); element->QueryBoolAttribute("visible", &_visible); auto propertiesElement = element->FirstChildElement("properties"); _properties.parseElement(propertiesElement); auto objectElement = element->FirstChildElement("object"); while(objectElement) { _objects.push_back(TmxObject()); _objects.back().parseElement(objectElement); objectElement = objectElement->NextSiblingElement("object"); } return true; }
NS_KAIRY_BEGIN //============================================================================= bool TmxImage::parseElement(void* p) { _width = 0; _height = 0; _filename = ""; _format = ""; _transColor = Color::Transparent; auto element = static_cast<tinyxml2::XMLElement*>(p); if (!element) { return false; } if (!element->Attribute("source")) { return false; } _filename = element->Attribute("source"); if (element->Attribute("format")) { _format = element->Attribute("format"); } element->QueryIntAttribute("width", &_width); element->QueryIntAttribute("height", &_height); if (element->Attribute("trans")) { std::stringstream ss; ss << std::hex << element->Attribute("trans"); Uint32 colorValue = 0; ss >> colorValue; _transColor = Color(colorValue); }
bool CSettingControlFormattedRange::Deserialize(const TiXmlNode *node, bool update /* = false */) { if (!ISettingControl::Deserialize(node, update)) return false; if (m_format == "string") { XMLUtils::GetInt(node, SETTING_XML_ELM_CONTROL_FORMATLABEL, m_formatLabel); // get the minimum label from <setting><constraints><minimum label="X" /> auto settingNode = node->Parent(); if (settingNode != nullptr) { auto constraintsNode = settingNode->FirstChild(SETTING_XML_ELM_CONSTRAINTS); if (constraintsNode != nullptr) { auto minimumNode = constraintsNode->FirstChild(SETTING_XML_ELM_MINIMUM); if (minimumNode != nullptr) { auto minimumElem = minimumNode->ToElement(); if (minimumElem != nullptr) { if (minimumElem->QueryIntAttribute(SETTING_XML_ATTR_LABEL, &m_minimumLabel) != TIXML_SUCCESS) m_minimumLabel = -1; } } } } if (m_minimumLabel < 0) { std::string strFormat; if (XMLUtils::GetString(node, SETTING_XML_ATTR_FORMAT, strFormat) && !strFormat.empty()) m_formatString = strFormat; } } return true; }
void Input::LoadInput(const std::string& file) { TiXmlDocument doc; doc.LoadFile(file.c_str()); auto parent = doc.FirstChildElement(); int i = 0; for (auto e = parent->FirstChildElement(); e; e = e->NextSiblingElement()) { int code; auto name = e->Value(); e->QueryIntAttribute("code", &code); m_keysAndCode[name] = code; m_keysAndIndex[name] = i++; } m_lastState = std::vector<bool>(m_keysAndCode.size(), false); m_currentState = std::vector<bool>(m_keysAndCode.size(), false); }
void DialogSystem::receive(const MouseClickEvent &mce) { game::entities.each<Position, Solid, Dialog, Name>( [&](entityx::Entity e, Position &pos, Solid &dim, Dialog &d, Name &name) { static std::atomic_bool dialogRun; (void)e; (void)d; if (((mce.position.x > pos.x) & (mce.position.x < pos.x + dim.width)) && ((mce.position.y > pos.y) & (mce.position.y < pos.y + dim.height))) { if (!dialogRun.load()) { std::thread([&] { std::string questAssignedText; int newIndex; auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog"); dialogRun.store(true); if (e.has_component<Direction>()) d.talking = true; if (d.index == 9999) { ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]); ui::waitForDialog(); } else if (exml != nullptr) { while (exml->StrAttribute("name") != name.name) exml = exml->NextSiblingElement(); exml = exml->FirstChildElement("text"); while (exml->IntAttribute("id") != d.index) exml = exml->NextSiblingElement(); auto oxml = exml->FirstChildElement("set"); if (oxml != nullptr) { do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value")); while ((oxml = oxml->NextSiblingElement())); game::briceUpdate(); } auto qxml = exml->FirstChildElement("quest"); if (qxml != nullptr) { const char *qname; auto qsys = game::engine.getSystem<QuestSystem>(); do { // assign quest qname = qxml->Attribute("assign"); if (qname != nullptr) { questAssignedText = qname; auto req = qxml->GetText(); qsys->assign(qname, qxml->StrAttribute("desc"), req ? req : ""); } // check / finish quest else { qname = qxml->Attribute("check"); if (qname != nullptr) { if (qname != nullptr && qsys->hasQuest(qname) && qsys->finish(qname) == 0) { d.index = 9999; } else { ui::dialogBox(name.name, "", false, "Finish my quest u nug"); ui::waitForDialog(); return; } // oldidx = d.index; // d.index = qxml->UnsignedAttribute("fail"); // goto COMMONAIFUNC; } } } while((qxml = qxml->NextSiblingElement())); } auto cxml = exml->FirstChildElement("content"); const char *content; if (cxml == nullptr) { content = randomDialog[d.rindex % randomDialog.size()].c_str(); } else { content = cxml->GetText() - 1; while (*++content && isspace(*content)); } ui::dialogBox(name.name, "", false, content); ui::waitForDialog(); if (!questAssignedText.empty()) ui::passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str()); if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR) d.index = newIndex; } d.talking = false; dialogRun.store(false); }).detach(); } } }); }
bool TmxTileset::parseElement(void* p, const std::string& path) { _terrainTypes.clear(); _tiles.clear(); auto element = static_cast<tinyxml2::XMLElement*>(p); if(!element) { return false; } _path = ""; tinyxml2::XMLDocument tsxDocument; if(element->Attribute("source")) { _source = element->Attribute("source"); std::string tsxPath = path + _source; if(tsxDocument.LoadFile(tsxPath.c_str()) != tinyxml2::XML_NO_ERROR) { return false; } element = tsxDocument.FirstChildElement("tileset"); auto separatorPos = tsxPath.find_last_of("/\\"); if (separatorPos != std::string::npos) { _path = tsxPath.substr(0, separatorPos + 1); } } else { _source = ""; } if(element->Attribute("name")) { _name = element->Attribute("name"); } else { _name = ""; } _firstGid = 1; _tileWidth = 0; _tileHeight = 0; _spacing = 0; _margin = 0; _offsetX = 0; _offsetY = 0; _tileCount = 0; element->QueryIntAttribute("firstgid", &_firstGid); element->QueryIntAttribute("tilewidth", &_tileWidth); element->QueryIntAttribute("tileheight", &_tileHeight); element->QueryIntAttribute("spacing", &_spacing); element->QueryIntAttribute("margin", &_margin); element->QueryIntAttribute("tilecount", &_tileCount); auto propertiesElement = element->FirstChildElement("properties"); auto imageElement = element->FirstChildElement("image"); auto terrainTypesElement = element->FirstChildElement("terraintypes"); auto tileElement = element->FirstChildElement("tile"); auto tileOffsetElement = element->FirstChildElement("tileoffset"); if(tileOffsetElement) { tileOffsetElement->QueryIntAttribute("x", &_offsetX); tileOffsetElement->QueryIntAttribute("y", &_offsetY); } _image.parseElement(imageElement); _properties.parseElement(propertiesElement); while(tileElement) { _tiles.push_back(TmxTilesetTile()); _tiles.back().parseElement(tileElement); tileElement = tileElement->NextSiblingElement("tile"); } if(terrainTypesElement) { auto terrainTypeElement = terrainTypesElement->FirstChildElement("terrain"); while(terrainTypeElement) { _terrainTypes.push_back(TmxTerrainType()); _terrainTypes.back().parseElement(terrainTypeElement); terrainTypeElement = terrainTypeElement->NextSiblingElement("terraintype"); } } return true; }