Example #1
0
// inline functions
static inline void addTextNode(ticpp::Element& parent, const char* title, const char* value)
{
	if (!value) {
		return;
	}

	ticpp::Text myText(value);
	if (!title) {
		parent.SetText(myText);
	} else {
		ticpp::Element myTitle(title);
		myTitle.LinkEndChild(&myText);
		parent.LinkEndChild(&myTitle);
	}
}
Example #2
0
static inline void setAttr(ticpp::Element& element, const char* attr, const T& value)
{
	if (!attr) {
		return;
	}
	element.SetAttribute(attr, value);
}
Example #3
0
//Save parameters of sprite in an xml element
void SpriteBuilder::SaveSprite(SpritePointer thesprite, ticpp::Element& xmlelement)
{
	/*XML DEFINITION EXPECTED FOR SPRITE ELEMENT:
	Element: SPRITE Atts: Id (string) x(number) y(number) h(number) w(number) Layer(number)
					 [Element: Image Atts: Id(string) [CollisionPath(string)]]
					 [Element: Font Atts: Id(string) [LineSpacing(number)] [CharSpacing(number)] [Align(string)] Text(string)]
					 [Element: Animation Atts: Id(string)] 
	*/
	
	//Get needed values from GFX system for calculations
	float globalscale = SingletonIndieLib::Instance()->GetGeneralScale();

	//-------Get attributes to save from entity---------
	float h,w; //Later is initialized
	float x = thesprite->GetPosX();
	float y = thesprite->GetPosY();
	Vector2 coordpos = SingletonIndieLib::Instance()->FromPixToCoord(Vector2(x,y));
	int z = thesprite->GetPosZ();
	float rotation = thesprite->GetAngleZ();
	int transparency = thesprite->GetTransparency();
	bool mirrorx = thesprite->GetMirrorX();
	bool mirrory = thesprite->GetMirrorY();
	bool wrap = thesprite->IfWrap();
	int wrapx = thesprite->GetRegionWidth();
	int wrapy = thesprite->GetRegionHeight();
	int layer = thesprite->GetLayer();

	//----Get elements associated with entity and remaining attributes------
	//Only one element can be associated to an entity: Image,Font,Animation
	//IF - Sprite is an image
	if(thesprite->GetSurface() != NULL)
	{
		IND_Surface* thesurface = thesprite->GetSurface();
		//Get Id of related surface
		std::string surfaceid = SingletonResourceMgr::Instance()->GetSurfaceId(thesurface);
		//Create "Image" element inside sprite
		ticpp::Element imageelement("Image");
		imageelement.SetAttribute("Id",surfaceid);
		xmlelement.InsertEndChild(imageelement);

		//Set remaining attributes from sprite
		w = (thesurface->GetWidth() * thesprite->GetScaleX()) / globalscale; 
		h = (thesurface->GetHeight() * thesprite->GetScaleY()) / globalscale;
	}//ELSE IF - Sprite is an animation
	else if(thesprite->GetAnimation() != NULL)
	{
		IND_Animation* theanimation = thesprite->GetAnimation();
		//Get Id of related animation
		std::string animationid = SingletonResourceMgr::Instance()->GetAnimationId(theanimation);
		//Create "Animation" element inside sprite
		ticpp::Element animationelement("Animation");
		animationelement.SetAttribute("Id",animationid);
		xmlelement.InsertEndChild(animationelement);

		//Find higher Width and Height in all sequences to calculate h and w
		int numsequences = theanimation->GetNumSequences();
		int hightwidth, highheight; 
		hightwidth = highheight = 0;
		//LOOP  Find bigger x and y to scale
		for(int i = 0;i<numsequences;i++)
		{
			int animwidth = theanimation->GetHighWidth(i);  //Bigger width of this sequence
			int animheight = theanimation->GetHighHeight(i); //Bigger heigth of this sequence

			//Assignment if it is bigger
			if(animwidth > hightwidth)
				hightwidth =  animwidth;
			if(animheight > highheight)
				highheight =  animheight;
		}//LOOP END

		//Set remaining attributes from sprite
		w = (hightwidth * thesprite->GetScaleX()) / globalscale; 
		h = (highheight * thesprite->GetScaleY()) / globalscale;
	}
	//TODO: SAVE FONT SETTINGS
	/*else if(////CODE \\\\\ IS A FONT)
	{

	}*/

	//Set all attributes of entity in order (to ease reading of file)
	xmlelement.SetAttribute("x",coordpos.x);
	xmlelement.SetAttribute("y",coordpos.y);
	xmlelement.SetAttribute("z",z);
	xmlelement.SetAttribute("w",w);
	xmlelement.SetAttribute("h",h);
	xmlelement.SetAttribute("Rotation",rotation);
	xmlelement.SetAttribute("Transp",transparency);
	xmlelement.SetAttribute("FlipX",mirrorx);
	xmlelement.SetAttribute("FlipY",mirrory);
	xmlelement.SetAttribute("Wrap",wrap);
	xmlelement.SetAttribute("WrapX",wrapx);
	xmlelement.SetAttribute("WrapY",wrapy);
	xmlelement.SetAttribute("Layer",layer);

}
Example #4
0
std::string cLed::parse(ticpp::Element& who, std::string fname) {
	using namespace ticpp;
	Iterator<Attribute> attr;
	Iterator<Node> node;
	std::string name, id;
	int width = 0, height = 0;
	bool foundTop = false, foundLeft = false; // requireds
	rectangle frame;
	if(parent->getBg() == cDialog::BG_DARK)
		setColour(sf::Color::White);
	for(attr = attr.begin(&who); attr != attr.end(); attr++){
		attr->GetName(&name);
		if(name == "name")
			attr->GetValue(&id);
		else if(name == "state"){
			std::string val;
			attr->GetValue(&val);
			if(val == "red") setState(led_red);
			else if(val == "green") setState(led_green);
			else if(val == "off") setState(led_off);
			else throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
//		}else if(name == "fromlist"){
//			attr->GetValue(&fromList);
		}else if(name == "font"){
			std::string val;
			attr->GetValue(&val);
			if(val == "dungeon")
				setFormat(TXT_FONT, FONT_DUNGEON);
			else if(val == "plain")
				setFormat(TXT_FONT, FONT_PLAIN);
			else if(val == "bold")
				setFormat(TXT_FONT, FONT_BOLD);
			else if(val == "maidenword")
				setFormat(TXT_FONT, FONT_MAIDWORD);
			else throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
		}else if(name == "size"){
			std::string val;
			attr->GetValue(&val);
			if(val == "large")
				setFormat(TXT_SIZE, 12);
			else if(val == "small")
				setFormat(TXT_SIZE, 10);
			else if(val == "title")
				setFormat(TXT_SIZE, 18);
			else throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
		}else if(name == "color" || name == "colour"){
			std::string val;
			attr->GetValue(&val);
			sf::Color clr;
			try{
				clr = parseColor(val);
			}catch(int){
				throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
			}
			setColour(clr);
		} else if(name == "wrap") {
			std::string val;
			attr->GetValue(&val);
			if(val == "true")
				setFormat(TXT_WRAP, true);
			else setFormat(TXT_WRAP, false);
		}else if(name == "top"){
			attr->GetValue(&frame.top), foundTop = true;
		}else if(name == "left"){
			attr->GetValue(&frame.left), foundLeft = true;
		}else if(name == "width"){
			attr->GetValue(&width);
		}else if(name == "height"){
			attr->GetValue(&height);
		}else throw xBadAttr("led",name,attr->Row(),attr->Column(),fname);
	}
	if(!foundTop) throw xMissingAttr("led","top",who.Row(),who.Column(),fname);
	if(!foundLeft) throw xMissingAttr("led","left",who.Row(),who.Column(),fname);
	if(width > 0) {
		frame.right = frame.left + width;
	}else{
		frame.right = frame.left + 14;
	}
	if(height > 0) {
		frame.bottom = frame.top + height;
	}else{
		frame.bottom = frame.top + 10;
	}
	setBounds(frame);
	std::string content;
	for(node = node.begin(&who); node != node.end(); node++){
		std::string val;
		int type = node->Type();
		node->GetValue(&val);
		if(type == TiXmlNode::TEXT)
			content += dlogStringFilter(val);
		else if(type != TiXmlNode::COMMENT) {
			val = '<' + val + '>';
			throw xBadVal("led",xBadVal::CONTENT,content + val,node->Row(),node->Column(),fname);
		}
	}
	setText(content);
	return id;
}
Example #5
0
std::string cButton::parse(ticpp::Element& who, std::string fname) {
	using namespace ticpp;
	Iterator<Attribute> attr;
	Iterator<Node> node;
	std::string name, id;
	int width = 0, height = 0;
	bool foundType = false, foundTop = false, foundLeft = false; // required attributes
	rectangle frame;
	for(attr = attr.begin(&who); attr != attr.end(); attr++){
		attr->GetName(&name);
		if(name == "name")
			attr->GetValue(&id);
		else if(name == "wrap"){
			std::string val;
			attr->GetValue(&val);
			if(val == "true") setFormat(TXT_WRAP, true);
		}else if(name == "type"){
			std::string val;
			foundType = true;
			attr->GetValue(&val);
			if(val == "small")
				setBtnType(BTN_SM);
			else if(val == "regular")
				setBtnType(BTN_REG);
			else if(val == "large")
				setBtnType(BTN_LG);
			else if(val == "help")
				setBtnType(BTN_HELP);
			else if(val == "left")
				setBtnType(BTN_LEFT);
			else if(val == "right")
				setBtnType(BTN_RIGHT);
			else if(val == "up")
				setBtnType(BTN_UP);
			else if(val == "down")
				setBtnType(BTN_DOWN);
			else if(val == "tiny")
				setBtnType(BTN_TINY);
			else if(val == "done")
				setBtnType(BTN_DONE);
			else if(val == "tall")
				setBtnType(BTN_TALL);
			else if(val == "trait")
				setBtnType(BTN_TRAIT);
			else if(val == "push")
				setBtnType(BTN_PUSH);
		}else if(name == "color" || name == "colour"){
			std::string val;
			attr->GetValue(&val);
			sf::Color clr;
			try{
				clr = parseColor(val);
			}catch(int){
				throw xBadVal("button",name,val,attr->Row(),attr->Column(),fname);
			}
			setColour(clr);
		}else if(name == "def-key"){
			std::string val;
			attr->GetValue(&val);
			try{
				attachKey(parseKey(val));
			}catch(int){
				throw xBadVal("button",name,val,attr->Row(),attr->Column(),fname);
			}
//		}else if(name == "fromlist"){
//			attr->GetValue(&fromList);
		}else if(name == "top"){
			attr->GetValue(&frame.top), foundTop = true;
		}else if(name == "left"){
			attr->GetValue(&frame.left), foundLeft = true;
		}else if(name == "width"){
			attr->GetValue(&width);
		}else if(name == "height"){
			attr->GetValue(&height);
		}else throw xBadAttr("button",name,attr->Row(),attr->Column(),fname);
	}
	if(parent->getBg() == cDialog::BG_DARK && (getBtnType() == BTN_TINY || getBtnType() == BTN_PUSH))
		setColour(sf::Color::White);
	if(!foundType) throw xMissingAttr("button","type",who.Row(),who.Column(),fname);
	if(!foundTop) throw xMissingAttr("button","top",who.Row(),who.Column(),fname);
	if(!foundLeft) throw xMissingAttr("button","left",who.Row(),who.Column(),fname);
	switch(getBtnType()){
		case BTN_SM:
			frame.right = frame.left + 23;
			frame.bottom = frame.top + 23;
			break;
		case BTN_LG:
			frame.right = frame.left + 102;
			frame.bottom = frame.top + 23;
			break;
		case BTN_HELP:
			frame.right = frame.left + 16;
			frame.bottom = frame.top + 13;
			break;
		case BTN_TINY:
		case BTN_LED: // this should never happen
			frame.right = frame.left + 14;
			frame.bottom = frame.top + 10;
			break;
		case BTN_TALL:
		case BTN_TRAIT:
			frame.right = frame.left + 63;
			frame.bottom = frame.top + 40;
			break;
		case BTN_PUSH:
			frame.right = frame.left + 30;
			frame.bottom = frame.top + 30;
			break;
		default:
			frame.right = frame.left + 63;
			frame.bottom = frame.top + 23;
	}
	if(width > 0)
		frame.right = frame.left + width;
	if(height > 0)
		frame.bottom = frame.top + height;
	setBounds(frame);
	std::string content;
	for(node = node.begin(&who); node != node.end(); node++){
		std::string val;
		int type = node->Type();
		node->GetValue(&val);
		if(type == TiXmlNode::ELEMENT && val == "key"){
			// TODO: There's surely a better way to do this
			if(content.length() > 0) throw xBadVal("button",xBadVal::CONTENT,content + val,node->Row(),node->Column(),fname);
//			labelWithKey = true;
		}else if(type == TiXmlNode::TEXT)
			content += dlogStringFilter(val);
		else if(type != TiXmlNode::COMMENT) {
			val = '<' + val + '>';
			throw xBadVal("button",xBadVal::CONTENT,val,node->Row(),node->Column(),fname);
		}
	}
	setText(content);
	return id;
}
Example #6
0
std::string cScrollPane::parse(ticpp::Element& who, std::string fname) {
	using namespace ticpp;
	Iterator<Attribute> attr;
	Iterator<Element> node;
	std::string name, id;
	rectangle frame;
	int width = 0, height = 0;
	bool foundTop = false, foundLeft = false;
	scroll.setStyle(SCROLL_LED);
	for(attr = attr.begin(&who); attr != attr.end(); attr++) {
		attr->GetName(&name);
		if(name == "name")
			attr->GetValue(&id);
		else if(name == "top")
			attr->GetValue(&frame.top), foundTop = true;
		else if(name == "left")
			attr->GetValue(&frame.left), foundLeft = true;
		else if(name == "width")
			attr->GetValue(&width);
		else if(name == "height")
			attr->GetValue(&height);
		else if(name == "framed") {
			std::string val;
			attr->GetValue(&val);
			if(val == "true") setFormat(TXT_FRAME, true);
			else setFormat(TXT_FRAME, false);
		}else if(name == "outline") {
			std::string val;
			attr->GetValue(&val);
			if(val == "solid") setFormat(TXT_FRAMESTYLE, FRM_SOLID);
			else if(val == "inset") setFormat(TXT_FRAMESTYLE, FRM_INSET);
			else if(val == "outset") setFormat(TXT_FRAMESTYLE, FRM_OUTSET);
			else if(val == "double") setFormat(TXT_FRAMESTYLE, FRM_DOUBLE);
		}else if(name == "style"){
			std::string val;
			attr->GetValue(&val);
			if(val == "white") setStyle(SCROLL_WHITE);
			else if(val == "led") setStyle(SCROLL_LED);
			else throw xBadVal("slider", name, val, attr->Row(), attr->Column(), fname);
		} else throw xBadAttr("pane",name,attr->Row(),attr->Column(),fname);
	}
	if(!foundTop) throw xMissingAttr("pane","top",who.Row(),who.Column(),fname);
	if(!foundLeft) throw xMissingAttr("pane","left",who.Row(),who.Column(),fname);
	if(width > 0) {
		frame.width() = width;
	}else{
		throw xMissingAttr("pane","width",who.Row(),who.Column(),fname);
	}
	if(height > 0) {
		frame.height() = height;
	}else{
		frame.height() = 10;
	}
	setBounds(frame);
	for(node = node.begin(&who); node != node.end(); node++) {
		std::string val;
		int type = node->Type();
		node->GetValue(&val);
		if(type == TiXmlNode::ELEMENT) {
			if(val == "field") {
				auto field = parent->parse<cTextField>(*node);
				contents.insert(field);
				// TODO: Add field to tab order
				//tabOrder.push_back(field);
			} else if(val == "text") {
				auto text = parent->parse<cTextMsg>(*node);
				contents.insert(text);
			} else if(val == "pict") {
				auto pict = parent->parse<cPict>(*node);
				contents.insert(pict);
			} else if(val == "slider") {
				auto slide = parent->parse<cScrollbar>(*node);
				contents.insert(slide);
			} else if(val == "button") {
				auto button = parent->parse<cButton>(*node);
				contents.insert(button);
			} else if(val == "led") {
				auto led = parent->parse<cLed>(*node);
				contents.insert(led);
			} else if(val == "group") {
				auto group = parent->parse<cLedGroup>(*node);
				contents.insert(group);
			} else throw xBadNode(val,node->Row(),node->Column(),fname);
		} else if(type != TiXmlNode::COMMENT)
			throw xBadVal("pane",xBadVal::CONTENT,val,node->Row(),node->Column(),fname);
	}
	recalcRect();
	return id;
}
Example #7
0
std::string cScrollbar::parse(ticpp::Element& who, std::string fname) {
	using namespace ticpp;
	Iterator<Attribute> attr;
	std::string name, id;
	bool foundTop = false, foundLeft = false, foundMax = false; // required attributes
	bool foundVertical = false;
	rectangle frame;
	int width = 0, height = 0;
	style = SCROLL_LED; // Dialog scrollbars have a different default.
	for(attr = attr.begin(&who); attr != attr.end(); attr++){
		attr->GetName(&name);
		if(name == "name")
			attr->GetValue(&id);
		else if(name == "vertical"){
			std::string val;
			attr->GetValue(&val);
			if(val == "true") vert = true;
			else vert = false;
			foundVertical = true;
		}else if(name == "style"){
			std::string val;
			attr->GetValue(&val);
			if(val == "white") style = SCROLL_WHITE;
			else if(val == "led") style = SCROLL_LED;
			else throw xBadVal("slider", name, val, attr->Row(), attr->Column(), fname);
		}else if(name == "link"){
			attr->GetValue(&link);
		}else if(name == "initial"){
			attr->GetValue(&pos);
		}else if(name == "max"){
			attr->GetValue(&max);
			foundMax = true;
		}else if(name == "page-size"){
			attr->GetValue(&pgsz);
		}else if(name == "top"){
			attr->GetValue(&frame.top), foundTop = true;
		}else if(name == "left"){
			attr->GetValue(&frame.left), foundLeft = true;
		}else if(name == "width"){
			attr->GetValue(&width);
		}else if(name == "height"){
			attr->GetValue(&height);
		}else throw xBadAttr("slider",name,attr->Row(),attr->Column(),fname);
	}
	if(!foundMax) throw xMissingAttr("slider","num",who.Row(),who.Column(),fname);
	if(!foundTop) throw xMissingAttr("slider","top",who.Row(),who.Column(),fname);
	if(!foundLeft) throw xMissingAttr("slider","left",who.Row(),who.Column(),fname);
	if(pos > max) throw xBadAttr("slider","initial",who.Row(),who.Column(),fname);
	int thickness = vert ? up_rect[style][VERT].width() : up_rect[style][HORZ].height();
	if(width > 0) {
		frame.right = frame.left + width;
		if(height == 0 && !foundVertical)
			vert = false;
	}else{
		if(vert) frame.width() = thickness;
		else frame.width() = 25;
	}
	if(height > 0) {
		frame.bottom = frame.top + height;
		if(width == 0 && !foundVertical)
			vert = true;
	}else{
		frame.bottom = frame.top + 10;
		if(vert) frame.height() = 25;
		else frame.height() = thickness;
	}
	setBounds(frame);
	if(parent->hasControl(link))
		parent->getControl(link).setTextToNum(pos);
	return id;
}