Exemplo n.º 1
0
        //Creates ellement
        public UIEllementMeta Make(UI ui, XmlNode node, Transform parent, object context)
        {
            //Filter Attributes
            string tags = this._name;
            Dictionary<string, string> attrs = new Dictionary<string, string> ();
            foreach (XmlAttribute field in node.Attributes) {

                if(field.Name.ToLower() == "id")
                {
                    tags += " "+field.Value;
                }else if (this._fields.Contains (field.Name)) {
                    if (!attrs.ContainsKey (field.Name)) {
                        attrs.Add (field.Name, field.Value);
                    }
                }
            }

            //Creating object.
            GameObject g = new GameObject (this._name);
            g.transform.parent = parent;

            UIEllementMeta meta  = new UIEllementMeta (g,node, tags);

            if (this.Builder != null) {
                this.Builder (ui, g, meta, attrs, context);
            }

            return meta;
        }
Exemplo n.º 2
0
		/* Start Binding */ 
		protected void attachView (UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (context.GetType ().GetInterfaces ().Contains (typeof(IUIBindable)) && meta.Node.ParentNode == null) {
				IUIBindable bindable = (IUIBindable)context;
				bindable.View = meta;
			}
		}
Exemplo n.º 3
0
		protected void bindDiv(UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes ["bind"] != null) {	

				UIElementBinding bind = ()=>{
				if(meta.BindPath != null)
				{
					string propName = null;
					int propIndex = -1;
					
					//Array indexed values are refed using #name:#index
					int pos = meta.BindPath.IndexOf (":");
					if (pos != -1) {
						propName = meta.BindPath.Substring (0, pos);
						propIndex = Convert.ToInt32 (meta.BindPath.Substring (pos+1, meta.BindPath.Length - (pos + 1)));
					} else {
						propName = meta.BindPath;
					}
					
					Type type = context.GetType ();
					PropertyInfo info = type.GetProperty (propName);
					if (info != null) {
						 if (info.PropertyType.GetInterfaces ().Contains (typeof(IList)) && propIndex != -1) { // Because I'm lazey, currently only implementing for lists
							IList value = (IList)info.GetValue (context, null);
							meta.Data = value [propIndex];
							return;
						}
					} 

					meta.Data = null;
				}
				};
				meta.UpdateBinding += bind;
			}
		}
Exemplo n.º 4
0
        protected void bindText(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
        {
            if (attributes.ContainsKey ("bind")) {
                Text txt = this.getText (self, meta.Node);

                string bind = attributes ["bind"];

                //If the bind is set to value, we presume the super structure contianing the ellement is handling the setting of the bindpath. Otherwise we pull the bind path.
                if (bind != "value") {
                    meta.BindPath = bind;
                }

                UIEllementBinding binding = () => {

                    if(meta.BindPath != null)
                    {
                    string propName = null;
                    int propIndex = -1;

                    //Array indexed values are refed using #name:#index
                    int pos = meta.BindPath.IndexOf (":");
                    if (pos != -1) {
                        propName = meta.BindPath.Substring (0, pos);
                        propIndex = Convert.ToInt32 (meta.BindPath.Substring (pos+1, meta.BindPath.Length - (pos + 1)));
                    } else {
                        propName = meta.BindPath;
                    }

                    Type type = context.GetType ();
                    PropertyInfo info = type.GetProperty (propName);
                    if (info != null) {
                        if (propIndex == -1) {
                            txt.text = info.GetValue (context, null).ToString ();
                        } else if (info.PropertyType.GetInterfaces ().Contains (typeof(IList))) { // Because I'm lazey, currently only implementing for lists
                            IList value = (IList)info.GetValue (context, null);
                            txt.text = value [propIndex].ToString ();
                        } else {
                            txt.text = meta.Node.Value;
                        }
                    } else {
                        txt.text = meta.Node.Value;
                    }
                    }
                };

                binding.Invoke ();
                meta.UpdateBinding += binding;
            }
        }
Exemplo n.º 5
0
		//Creates ellement
		public UIElementMeta Make (UI ui, XmlNode node, Transform parent, object context)
		{
			//Filter Attributes
			string tags = this._name;

			//Creating object.
			GameObject g = new GameObject (this._name);
			g.transform.parent = parent;

			UIElementMeta meta  = new UIElementMeta (g,node, tags);

			if (this.Builder != null) {
				this.Builder (ui, g, meta, context);
			}

			return meta;
		}
Exemplo n.º 6
0
		protected void imageRenderMode (UI render, GameObject self, UIElementMeta meta, object context)
		{

			if (meta.Node.Attributes["renderMode"] != null) {
				meta.Image.type = (Image.Type)Enum.Parse (typeof(Image.Type), meta.Node.Attributes["renderMode"].Value);
			}
		}
Exemplo n.º 7
0
		protected void imgMaterial (UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes["material"] != null && UIAssets.Self != null) {
				Material m = UIAssets.Self.Materials.Find (x => x.name == meta.Node.Attributes ["material"].Value);
				if (m != null) {
					meta.Image.material = m;
				}
			}
		}
Exemplo n.º 8
0
 protected void textFontSize(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
 {
     if (attributes.ContainsKey ("size")) {
         Text txt = this.getText (self, meta.Node);
         txt.fontSize = Convert.ToInt32 (attributes ["size"]);
     }
 }
Exemplo n.º 9
0
		protected void imgBackground (UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes["image"] != null && UIAssets.Self != null) {
				if (meta.Node.Attributes ["image"].Value.IndexOf ("$") == 0) {
					
				} else {
					
					Sprite s = UIAssets.Self.Images.Find (x => x.name == meta.Node.Attributes ["image"].Value);
					if (s != null) {
						meta.Image.sprite = s;
					}
				}
			}
		}
Exemplo n.º 10
0
		protected void foreachChild (UI render, GameObject self, UIElementMeta meta, object context)
		{

			if (meta.Node.Attributes["foreach"] != null) {

				UIElementBinding binding = () => {

					meta.ContinueRenderChildren = false;

					string propName = meta.Node.Attributes ["foreach"].Value;
					Type t = context.GetType ();
					PropertyInfo prop = t.GetProperty (propName);
			
					if (prop != null) {
						if (prop.PropertyType.GetInterfaces ().Contains (typeof(IList))) {
							IList data = (IList)prop.GetValue (context, null);

							/* Create needed ellements */
							if (meta.Object.transform.childCount < data.Count) {
								int needed = data.Count - meta.Object.transform.childCount;
								for(int i = 0; i< needed; i++){
									foreach (XmlNode child in meta.Node.ChildNodes) {
										meta.AddChild (render.Render (child, self.transform, context));
									}
								}
							}

							//Toggle on ellements that we'll be using, disable the ones we won't be using
							int ellementsNeeded = 0;
							List<UIElementMeta> active = new List<UIElementMeta> ();
							foreach (UIElementMeta child in meta) {
								//Enable ellements 
								if (ellementsNeeded < data.Count) {
									child.Object.SetActive (true);
									child.BindPath = propName;
									active.Add (child);
								} else { //Disable elements
									child.Object.SetActive (false);
								}
								ellementsNeeded++;
							}

							//Layout enabled ellements
							this.groupLayout (active);
						}
					}
			
			
				};

				binding.Invoke ();
				meta.UpdateBinding += binding;
			}
		}
Exemplo n.º 11
0
        protected void imgBackground(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
        {
            if (attributes.ContainsKey ("background") && UIAssets.Self != null) {
                Image img = this.getImage (self, meta.Node);

                if (attributes ["background"].IndexOf ("$") == 0) {

                } else {

                    Sprite s = UIAssets.Self.Images.Find (x => x.name == attributes ["background"]);
                    if (s != null) {
                        img.sprite = s;
                    }
                }
            }
        }
Exemplo n.º 12
0
		/*End Binding*/

		/*Start Slider*/
		protected void sliderInit(UI render, GameObject self, UIElementMeta meta, object context){

			meta.Slider.fillRect.anchorMin = Vector2.zero;
			meta.Slider.fillRect.anchorMax = Vector2.one;
			
			meta.Slider.fillRect.localScale = Vector3.one;
			meta.Slider.fillRect.SetSizeWithCurrentAnchors (RectTransform.Axis.Horizontal, 1);
			meta.Slider.fillRect.SetSizeWithCurrentAnchors (RectTransform.Axis.Vertical, 1);
			meta.Slider.fillRect.offsetMin = Vector2.zero;
			meta.Slider.fillRect.offsetMax = Vector2.zero;	
		}
Exemplo n.º 13
0
		protected void dragRecieveBind(UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes ["recieveDragBind"] != null) {
				string name = meta.Node.Attributes["recieveDragBind"].Value;

				UIElementBinding bind = () => {;
					DragRecieve del = (DragRecieve)Delegate.CreateDelegate(typeof(DragRecieve), context, name);
					if(del != null)
					{
						meta.DragableRecieve.Dragable += del;
					}else{
						Debug.LogError("Method "+name+" does not match delegate DragRecieve");
					}
				};

				meta.UpdateBinding += bind;
			}
		}
Exemplo n.º 14
0
		protected void bindSlider(UI render, GameObject self, UIElementMeta meta, object context)
		{

			if (meta.Node.Attributes ["bind"] != null) {
			
				meta.Data = context;
				UIElementBinding binding = ()=>{

					Type type = context.GetType();
					PropertyInfo info = type.GetProperty(meta.Node.Attributes["bind"].Value);
					if(info != null)
					{
						float value = 0;
						if(info.PropertyType == typeof(float))
						{
							value = (float)info.GetValue(context, null);
						}

						meta.Slider.normalizedValue = value;
					}

				};

				binding.Invoke();
				meta.UpdateBinding += binding;
			
			}
		}
Exemplo n.º 15
0
		protected void bindClick(UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes["onClick"] != null) {
				meta.Data = context;
				meta.Button.onClick.AddListener (() => {
					Type type = context.GetType();
					MethodInfo info = type.GetMethod(meta.Node.Attributes["onClick"].Value);
					if(info != null)
					{
						info.Invoke(context, null);	
					}
				});
			}
		}
Exemplo n.º 16
0
		protected void bindImg (UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes["bindImage"] != null) {
				meta.Data = context;
				UIElementBinding binding = ()=>{
				Type type = context.GetType();
				PropertyInfo info = type.GetProperty(meta.Node.Attributes["bindImage"].Value);

				if(info != null)
				{
					if(info.PropertyType == typeof(Sprite))
					{
						meta.Image.sprite = (Sprite)info.GetValue(context, null);

					}
				}
				};

				binding.Invoke();
				meta.UpdateBinding += binding;
			}
		}
Exemplo n.º 17
0
 protected void textColor(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
 {
     if (attributes.ContainsKey ("color")) {
         Text txt = this.getText (self, meta.Node);
         txt.color = readColor (attributes ["color"]);
     }
 }
Exemplo n.º 18
0
 /*End Binding*/
 /*Start Text*/
 protected void textMaterial(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
 {
     if (attributes.ContainsKey ("material") && UIAssets.Self != null) {
         Text txt = this.getText (self, meta.Node);
         txt.material = UIAssets.Self.Materials.Find (x => x.name == attributes ["material"]);
     }
 }
Exemplo n.º 19
0
		/*End Image*/

		/*Start Drag*/

		protected void dragInit(UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes ["dragable"] != null) {
				Dragable drag = meta.Dragable;
				drag.Meta = meta;
			}
		}
Exemplo n.º 20
0
		/*End Slider*/

		/*Start Text*/
		protected void txtDefaultValue(UI render, GameObject self, UIElementMeta meta, object context)
		{
			meta.Text.text = meta.Node.InnerText;
		}
Exemplo n.º 21
0
		protected void dragRecieveInit(UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes ["recieveDrag"] != null) {
				DragableRecieve recieve = meta.DragableRecieve;
			}
		}
Exemplo n.º 22
0
 protected void imgMaterial(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
 {
     if (attributes.ContainsKey ("material") && UIAssets.Self != null) {
         Image img = this.getImage (self, meta.Node);
         Material m = UIAssets.Self.Materials.Find (x => x.name == attributes ["material"]);
         if (m != null) {
             img.material = m;
         }
     }
 }
Exemplo n.º 23
0
		/*End Drag*/

		/*Verbs*/

		protected void show(UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes["show"] != null) {
				meta.UpdateBinding += () => {
					Type type = context.GetType();
					PropertyInfo info = type.GetProperty(meta.Node.Attributes["show"].Value);
					if(info != null)
					{
						if(info.PropertyType == typeof(bool))
						{
							self.SetActive((bool)info.GetValue(context, null));
						}
					}
				};
			}
		}
Exemplo n.º 24
0
 protected void imageRenderMode(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
 {
     if (attributes.ContainsKey ("renderMode")) {
         Image img = this.getImage (self, meta.Node);
         img.type = (Image.Type)Enum.Parse (typeof(Image.Type), attributes ["renderMode"]);
     }
 }
Exemplo n.º 25
0
		//Calculate the positioning of an ellement
		protected void position (UI renderer, GameObject self, UIElementMeta meta, object context)
		{
			Vector2 min = Vector2.zero;
			Vector2 max = Vector2.one;

			//If the min and max fields have been set use them, otherwise default to fullscreen
			if (meta.Node.Attributes["min"] != null) {
				min = readCord (meta.Node.Attributes["min"].Value);
			}

			if (meta.Node.Attributes["max"] != null) {
				max = readCord (meta.Node.Attributes ["max"].Value);
			}

			meta.Rect.anchorMin = min;
			meta.Rect.anchorMax = max;

			meta.Rect.localScale = Vector3.one;
			meta.Rect.SetSizeWithCurrentAnchors (RectTransform.Axis.Horizontal, 1);
			meta.Rect.SetSizeWithCurrentAnchors (RectTransform.Axis.Vertical, 1);
			meta.Rect.offsetMin = Vector2.zero;
			meta.Rect.offsetMax = Vector2.zero;				
		}
Exemplo n.º 26
0
		/*End Text*/

		/*Start Image*/

		protected void imageColor (UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes["color"] != null) {
				meta.Image.color = this.readColor (meta.Node.Attributes ["color"].Value);
			}
		}
Exemplo n.º 27
0
		protected void textFont (UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes["font"] != null && UIAssets.Self != null) {
				Font font = UIAssets.Self.Fonts.Find (x => x.name == meta.Node.Attributes ["font"].Value);
				if (font != null) {
					meta.Text.font = font;
				}
			}
		}
Exemplo n.º 28
0
        protected void textFont(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
        {
            if (attributes.ContainsKey ("font") && UIAssets.Self != null) {
                Text txt = this.getText (self, meta.Node);

                Font font = UIAssets.Self.Fonts.Find (x => x.name == attributes ["font"]);
                if (font != null) {

                    txt.font = font;
                }
            }
        }
Exemplo n.º 29
0
		protected void textFontSize (UI render, GameObject self, UIElementMeta meta, object context)
		{
			if (meta.Node.Attributes["size"] != null) {
				meta.Text.fontSize = Convert.ToInt32 (meta.Node.Attributes ["size"].Value);
			}
		}
Exemplo n.º 30
0
 /*End Text*/
 /*Start Image*/
 protected void imageColor(UI render, GameObject self, UIEllementMeta meta, Dictionary<string, string> attributes, object context)
 {
     if (attributes.ContainsKey ("color")) {
         Image img = this.getImage (self, meta.Node);
         img.color = this.readColor (attributes ["color"]);
     }
 }