示例#1
0
	void SkinExportSerializer::writeStateText(pugi::xml_node _parent, DataPtr _data, const MyGUI::IntCoord& _value)
	{
		pugi::xml_node node = _parent.append_child("State");
		node.append_attribute("name").set_value(convertEditorToExportStateName(_data->getPropertyValue("Name")).c_str());
		node.append_attribute("colour").set_value(_data->getPropertyValue("TextColour").c_str());
		node.append_attribute("shift").set_value(_data->getPropertyValue("TextShift").c_str());
	}
	void FontExportSerializer::generateFont(DataPtr _data)
	{
		std::string fontName = _data->getPropertyValue("FontName");
		removeFont(fontName);

		std::string resourceCategory = MyGUI::ResourceManager::getInstance().getCategoryName();
		MyGUI::ResourceTrueTypeFont* font = MyGUI::FactoryManager::getInstance().createObject<MyGUI::ResourceTrueTypeFont>(resourceCategory);

		font->setResourceName(fontName);

		font->setSource(_data->getPropertyValue("Source"));
		font->setSize(_data->getPropertyValue<float>("Size"));
		font->setResolution(_data->getPropertyValue<int>("Resolution"));
		font->setHinting(_data->getPropertyValue("Hinting"));
		font->setAntialias(_data->getPropertyValue<bool>("Antialias"));
		font->setTabWidth(_data->getPropertyValue<float>("TabWidth"));
		font->setOffsetHeight(_data->getPropertyValue<int>("OffsetHeight"));
		font->setSubstituteCode(_data->getPropertyValue<int>("SubstituteCode"));
		font->setDistance(_data->getPropertyValue<int>("Distance"));

		std::string ranges = _data->getPropertyValue("FontCodeRanges");
		std::vector<std::string> values = MyGUI::utility::split(ranges, "|");
		for (size_t index = 0; index < values.size(); index ++)
		{
			MyGUI::IntSize size = MyGUI::IntSize::parse(values[index]);
			font->addCodePointRange(size.width, size.height); // о да
		}

		font->initialise();

		MyGUI::ResourceManager::getInstance().addResource(font);
	}
示例#3
0
	void ImageExportSerializer::writeFrame(pugi::xml_node _parent, DataPtr _data)
	{
		pugi::xml_node node = _parent.append_child("Frame");
		node.append_attribute("point").set_value(_data->getPropertyValue("Point").c_str());

		size_t count = MyGUI::utility::parseValue<size_t>(_data->getPropertyValue("Count"));
		if (count > 1)
			node.append_attribute("count").set_value(MyGUI::utility::toString(count).c_str());
	}
示例#4
0
	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));
	}
示例#5
0
	pugi::xml_node SkinExportSerializer::writeState(pugi::xml_node _parent, DataPtr _data, const MyGUI::IntCoord& _value)
	{
		MyGUI::IntPoint point = MyGUI::IntPoint::parse(_data->getPropertyValue("Point"));
		MyGUI::IntCoord coord = _value + point;

		pugi::xml_node node = _parent.append_child("State");
		node.append_attribute("name").set_value(convertEditorToExportStateName(_data->getPropertyValue("Name")).c_str());
		node.append_attribute("offset").set_value(coord.print().c_str());

		return node;
	}
示例#6
0
	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));
	}
示例#7
0
	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);
	}
示例#8
0
	void FontTryControl::updateFont()
	{
		DataPtr data = DataUtility::getSelectedDataByType("Font");
		if (data != nullptr)
			mEdit->setFontName(data->getPropertyValue("FontName"));
		else
			mEdit->setFontName("");
	}
示例#9
0
	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));
	}
示例#10
0
	void SkinExportSerializer::writeSkin(pugi::xml_node _parent, DataPtr _data)
	{
		pugi::xml_node node = _parent.append_child("Resource");
		node.append_attribute("type").set_value("ResourceSkin");
		node.append_attribute("name").set_value(_data->getPropertyValue("Name").c_str());
		node.append_attribute("size").set_value(MyGUI::IntCoord::parse(_data->getPropertyValue("Size")).size().print().c_str());
		std::string textureName = _data->getPropertyValue("Texture");
		if (!textureName.empty())
			node.append_attribute("texture").set_value(textureName.c_str());

		Data::VectorData childs = DataUtility::getChildsByType(_data, "Region", false);
		sortByAlign(childs);
		for (Data::VectorData::const_iterator child = childs.begin(); child != childs.end(); child ++)
			writeRegion(node, _data, (*child), false);

		childs = DataUtility::getChildsByType(_data, "RegionText", false);
		for (Data::VectorData::const_iterator child = childs.begin(); child != childs.end(); child ++)
			writeRegion(node, _data, (*child), true);
	}
示例#11
0
	void ListBoxDataControl::notifyChangeProperty(PropertyPtr _sender)
	{
		if (mParentData == nullptr)
			return;
		if (mParentData != _sender->getOwner()->getParent())
			return;

		for (size_t index = 0; index < mListBox->getItemCount(); index ++)
		{
			DataPtr data = *mListBox->getItemDataAt<DataPtr>(index);
			if (data == _sender->getOwner())
			{
				bool unique = isDataEnabled(data);
				if (unique)
					mListBox->setItemNameAt(index, data->getPropertyValue(mPropertyForName));
				else
					mListBox->setItemNameAt(index, replaceTags(mColourName) + data->getPropertyValue(mPropertyForName));
			}
		}
	}
示例#12
0
	void ListBoxDataControl::invalidateList()
	{
		mLastIndex = MyGUI::ITEM_NONE;
		mListBox->setIndexSelected(MyGUI::ITEM_NONE);

		if (mParentData != nullptr)
		{
			for (size_t index = 0; index < mListBox->getItemCount(); index ++)
				mListBox->setItemDataAt(index, nullptr);

			const Data::VectorData& childs = DataUtility::getChildsByType(mParentData, mThisType);

			while (mListBox->getItemCount() > childs.size())
				mListBox->removeItemAt(mListBox->getItemCount() - 1);

			while (mListBox->getItemCount() < childs.size())
				mListBox->addItem("", nullptr);

			for (size_t index = 0; index < childs.size(); index ++)
			{
				DataPtr child = childs.at(index);

				bool unique = isDataEnabled(child);
				if (unique)
					mListBox->setItemNameAt(index, child->getPropertyValue(mPropertyForName));
				else
					mListBox->setItemNameAt(index, replaceTags(mColourName) + child->getPropertyValue(mPropertyForName));

				mListBox->setItemDataAt(index, child);

				connectToProperty(child);
			}
		}
		else
		{
			mListBox->removeAllItems();
		}

		if (mHelpPanel != nullptr)
			mHelpPanel->setVisible(mListBox->getItemCount() == 0);
	}
	void FontExportSerializer::generateFontManualXml(MyGUI::xml::ElementPtr _root, const MyGUI::UString& _folderName, DataPtr _data)
	{
		MyGUI::IFont* resource = MyGUI::FontManager::getInstance().getByName(_data->getPropertyValue("FontName"));
		MyGUI::ResourceTrueTypeFont* font = resource != nullptr ? resource->castType<MyGUI::ResourceTrueTypeFont>(false) : nullptr;

		if (font != nullptr)
		{
			std::string textureName = _data->getPropertyValue("Name") + ".png";
			MyGUI::ITexture* texture = font->getTextureFont();
			if (texture == nullptr)
				return;
			texture->saveToFile(MyGUI::UString(common::concatenatePath(_folderName, MyGUI::UString(textureName))).asUTF8());

			MyGUI::xml::ElementPtr node = _root->createChild("Resource");
			node->addAttribute("type", "ResourceManualFont");
			node->addAttribute("name", _data->getPropertyValue("Name"));

			addProperty(node, "Source", textureName);
			addProperty(node, "SourceSize", MyGUI::IntSize(texture->getWidth(), texture->getHeight()));
			addProperty(node, "DefaultHeight", font->getDefaultHeight());

			MyGUI::xml::Element* codes = node->createChild("Codes");

			std::vector<std::pair<MyGUI::Char, MyGUI::Char> > codePointRanges = font->getCodePointRanges();
			MyGUI::Char substituteCodePoint = font->getSubstituteCodePoint();
			bool isCustomSubstituteCodePoint = substituteCodePoint != MyGUI::FontCodeType::NotDefined;

			// Add all of the code points. Skip over the substitute code point -- unless it's been customized, in which case it
			// needs to be added here as a regular code point and then at the end as a substitute code point.
			for (std::vector<std::pair<MyGUI::Char, MyGUI::Char> >::const_iterator iter = codePointRanges.begin() ; iter != codePointRanges.end(); ++iter)
				for (MyGUI::Char code = iter->first; code <= iter->second && code >= iter->first; ++code)
					if (code != substituteCodePoint || isCustomSubstituteCodePoint)
						addCode(codes, code, font, false);

			// Always add the substitute code point last, even if it isn't the last one in the range.
			addCode(codes, substituteCodePoint, font, true);
		}
	}
	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");
	}
示例#15
0
	void ListBoxDataControl::OnRenameData()
	{
		size_t index = mListBox->getIndexSelected();
		if (index != MyGUI::ITEM_NONE)
		{
			mListBox->beginToItemAt(index);
			MyGUI::Widget* widget = mListBox->getWidgetByIndex(index);
			if (widget != nullptr)
			{
				DataPtr data = *mListBox->getItemDataAt<DataPtr>(index);

				mTextFieldControl->setCaption(replaceTags("CaptionEnterName"));
				mTextFieldControl->setTextField(data->getPropertyValue(mPropertyForName));
				mTextFieldControl->setUserData(data);
				mTextFieldControl->setCoord(MyGUI::IntCoord(widget->getAbsoluteLeft(), widget->getAbsoluteTop(), widget->getWidth(), widget->getHeight()));
				mTextFieldControl->doModal();
			}
		}
	}
	void FontExportSerializer::writeFont(pugi::xml_node _parent, DataPtr _data)
	{
		pugi::xml_node node = _parent.append_child("Resource");
		node.append_attribute("type").set_value("ResourceTrueTypeFont");
		node.append_attribute("name").set_value(_data->getPropertyValue("Name").c_str());

		pugi::xml_node nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("Source");
		nodeProperty.append_attribute("value").set_value(_data->getPropertyValue("Source").c_str());

		nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("Size");
		nodeProperty.append_attribute("value").set_value(_data->getPropertyValue("Size").c_str());

		nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("Hinting");
		nodeProperty.append_attribute("value").set_value(_data->getPropertyValue("Hinting").c_str());

		nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("Resolution");
		nodeProperty.append_attribute("value").set_value(_data->getPropertyValue("Resolution").c_str());

		std::string value = MyGUI::utility::toString(MyGUI::utility::parseValue<bool>(_data->getPropertyValue("Antialias")));
		nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("Antialias");
		nodeProperty.append_attribute("value").set_value(value.c_str());

		nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("TabWidth");
		nodeProperty.append_attribute("value").set_value(_data->getPropertyValue("TabWidth").c_str());

		nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("OffsetHeight");
		nodeProperty.append_attribute("value").set_value(_data->getPropertyValue("OffsetHeight").c_str());

		nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("SubstituteCode");
		nodeProperty.append_attribute("value").set_value(_data->getPropertyValue("SubstituteCode").c_str());

		nodeProperty = node.append_child("Property");
		nodeProperty.append_attribute("key").set_value("Distance");
		nodeProperty.append_attribute("value").set_value(_data->getPropertyValue("Distance").c_str());

		pugi::xml_node nodeCodes = node.append_child("Codes");
		value = _data->getPropertyValue("FontCodeRanges");
		std::vector<std::string> values = MyGUI::utility::split(value, "|");
		for (size_t index = 0; index < values.size(); index ++)
			nodeCodes.append_child("Code").append_attribute("range").set_value(values[index].c_str());
	}
示例#17
0
	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));
				}
			}
		}
	}
示例#18
0
	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());
				}
			}
		}
	}