Ejemplo n.º 1
0
        /// <summary>
        /// Apply the provided attributes to this XmlElement. If no attributes are provided, then this function will use this XmlElement's attribute collection instead.
        /// </summary>
        /// <param name="_attributes"></param>
        public void ApplyAttributes(AttributeDictionary _attributes = null)
        {
            if (_attributes != null)
            {
                if (this.attributes != null)
                {
                    // merge attribute dictionaries
                    var temp = this.attributes.Clone();

                    foreach (var attribute in _attributes)
                    {
                        if (temp.ContainsKey(attribute.Key))
                        {
                            temp[attribute.Key] = attribute.Value;
                        }
                        else
                        {
                            temp.Add(attribute.Key, attribute.Value);
                        }
                    }

                    this.attributes = temp;
                }
                else
                {
                    this.attributes = _attributes;
                }
            }
            else
            {
                _attributes = this.attributes;
            }

            if (_attributes.ContainsKey("internalid"))
            {
                this.m_internalId = _attributes["internalid"];
            }

            if (_attributes.ContainsKey("id"))
            {
                this.m_id = _attributes["id"];
            }

            tagHandler.SetInstance(rectTransform, xmlLayout);
            tagHandler.ApplyAttributes(_attributes);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns true if the current xml element has the specified attribute, or if it is contained in the list of attributes that are being applied
        /// </summary>
        /// <param name="attributeName"></param>
        /// <param name="attributesToApply"></param>
        /// <returns></returns>
        protected bool ElementHasAttribute(string attributeName, AttributeDictionary attributesToApply, XmlElement element = null)
        {
            if (element == null)
            {
                element = currentXmlElement;
            }

            return(attributesToApply.ContainsKey(attributeName) || element.HasAttribute(attributeName));
        }
        public void HandleAnimationNode(AttributeDictionary attributes)
        {
            if (!attributes.ContainsKey("name"))
            {
                return;
            }

            animations.SetValue(attributes["name"], new XmlLayoutAnimation(attributes));
        }
Ejemplo n.º 4
0
 public bool HasAttribute(string name)
 {
     return(attributes.ContainsKey(name));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Apply the specified attributes to the XmlElement (and its other relevant components)
        /// </summary>
        /// <param name="attributesToApply"></param>
        public virtual void ApplyAttributes(AttributeDictionary attributesToApply)
        {
            if (currentInstanceTransform == null || currentXmlLayoutInstance == null)
            {
                Debug.LogWarning("[XmlLayout][Warning] Please call ElementTagHandler.SetInstance() before using XmlElement.ApplyAttributes()");
                return;
            }

            //var startTime = DateTime.Now;
            attributesToApply = HandleCustomAttributes(attributesToApply);
            var _primaryComponent = primaryComponent;

            // the vast majority of events require the element to block raycasts, so rather than expecting the users to set this value every time,
            // lets set it here
            if (attributesToApply.Any(a => !String.Equals("onValueChanged", a.Key, StringComparison.OrdinalIgnoreCase) && eventAttributeNames.Contains(a.Key, StringComparer.OrdinalIgnoreCase)))
            {
                attributesToApply.AddIfKeyNotExists("raycastTarget", "true");
            }
            else if (!String.IsNullOrEmpty(attributesToApply.GetValue("tooltip")))
            {
                attributesToApply.AddIfKeyNotExists("raycastTarget", "true");
            }

            if (attributesToApply.ContainsKey("allowDragging") && attributesToApply["allowDragging"].ToBoolean())
            {
                var dragEventHandler = currentXmlElement.GetComponent <XmlLayoutDragEventHandler>();
                if (dragEventHandler == null)
                {
                    currentXmlElement.gameObject.AddComponent <XmlLayoutDragEventHandler>();
                }
            }

            foreach (var attribute in attributesToApply)
            {
                string name  = attribute.Key.ToLower();
                string value = attribute.Value;

                if (eventAttributeNames.Contains(name, StringComparer.OrdinalIgnoreCase))
                {
                    // As it happens, events don't work anyway unless they are processed at runtime (which is why we have 'ForceRebuildOnAwake')
                    // so we may as well not process any event attributes at all in edit mode
                    // (this also helps avoid triggering event handlers in edit mode)
                    // Note: we set these at the end of the frame so that any internal event-handlers (such as for MVVM) will take precedence
                    // and be executed first
                    var _xmlLayoutInstance = currentXmlLayoutInstance;
                    var _transform         = currentInstanceTransform;

                    if (Application.isPlaying)
                    {
                        XmlLayoutTimer.AtEndOfFrame(() =>
                        {
                            if (_transform == null || _xmlLayoutInstance == null)
                            {
                                return;
                            }

                            SetInstance(_transform, _xmlLayoutInstance);
                            HandleEventAttribute(name, value);
                        }, null, true);
                    }

                    continue;
                }

                var propertySetOnComponent = _primaryComponent != null?SetPropertyValue(_primaryComponent, name, value) : false;

                // if we failed to set the property on the component, perhaps it is a transform value instead
                if (!propertySetOnComponent)
                {
                    var propertySetOnTransform = SetPropertyValue(currentInstanceTransform, name, value);

                    // perhaps it is a layout value
                    if (!propertySetOnTransform)
                    {
                        var propertySetOnLayoutComponent = SetPropertyValue(layoutElement, name, value);

                        // or, perhaps it is an image value
                        if (!propertySetOnLayoutComponent)
                        {
                            // lastly, check the XmlElement
                            var propertySetOnXmlElement = SetPropertyValue(currentXmlElement, name, value);

                            if (!propertySetOnXmlElement)
                            {
                                var _imageComponent = imageComponent;
                                if (_imageComponent != null)
                                {
                                    SetPropertyValue(imageComponent, name, value);
                                }
                            }
                        }
                    }
                }
            }

#if !ENABLE_IL2CPP && MVVM_ENABLED
            if (!dontCallHandleDataSourceAttributeAutomatically && attributesToApply.ContainsKey("vm-dataSource"))
            {
                HandleDataSourceAttribute(attributesToApply["vm-dataSource"]);
            }

            // If this element is associated with a data source, but has no vm-dataSource attribute
            // (perhaps it was removed)
            // then remove the association
            if (!currentXmlElement.attributes.ContainsKey("vm-dataSource"))
            {
                currentXmlLayoutInstance.ElementDataSources.RemoveAll(ed => ed.XmlElement == currentXmlElement);
            }
#endif
        }
 public override bool ContainsKey(string key)
 {
     return(dictionary.ContainsKey(key));
 }
Ejemplo n.º 7
0
        public XmlLayoutAnimation(AttributeDictionary attributes)
        {
            if (attributes.ContainsKey("type"))
            {
                type = (eAnimationType)Enum.Parse(typeof(eAnimationType), attributes["type"]);
            }

            if (attributes.ContainsKey("attribute"))
            {
                attribute = attributes["attribute"];
            }

            if (attributes.ContainsKey("duration"))
            {
                duration = attributes["duration"].ToFloat();
            }

            if (attributes.ContainsKey("animations"))
            {
                animations = attributes["animations"].ToClassList();
            }

            if (!attributes.ContainsKey("valueType"))
            {
                attributes.Add("valueType", "float");
            }

            switch (attributes["valueType"])
            {
            case "float":
                valueType = typeof(float);
                break;

            case "Vector2":
                valueType = typeof(Vector2);
                break;

            case "Vector3":
                valueType = typeof(Vector3);
                break;

            case "Color":
                valueType = typeof(Color);
                break;
            }

            if (attributes.ContainsKey("to"))
            {
                valueTo = attributes["to"].ChangeToType(valueType);
            }

            if (attributes.ContainsKey("from"))
            {
                valueFrom    = attributes["from"].ChangeToType(valueType);
                hasValueFrom = true;
            }

            if (attributes.ContainsKey("curve"))
            {
                curve = attributes["curve"];
            }
        }
Ejemplo n.º 8
0
        public void LoadAttributes(AttributeDictionary attributes)
        {
            if (!started)
            {
                Start();
            }

#if TEXTMESHPRO_PRESENT
            if (attributes.ContainsKey("tooltipUseTextMeshPro"))
            {
                ToggleTextMeshPro(attributes["tooltipUseTextMeshPro"].ToBoolean());
            }
#endif

            if (attributes.ContainsKey("tooltipTextColor"))
            {
                SetTextColor(attributes["tooltipTextColor"].ToColor(xmlLayout));
            }
            if (attributes.ContainsKey("tooltipBackgroundColor"))
            {
                SetBackgroundColor(attributes["tooltipBackgroundColor"].ToColor(xmlLayout));
            }
            if (attributes.ContainsKey("tooltipBorderColor"))
            {
                SetBorderColor(attributes["tooltipBorderColor"].ToColor(xmlLayout));
            }

            if (attributes.ContainsKey("tooltipBackgroundImage"))
            {
                SetBackgroundImage(attributes["tooltipBackgroundImage"].ToSprite());
            }
            if (attributes.ContainsKey("tooltipBorderImage"))
            {
                SetBorderImage(attributes["tooltipBorderImage"].ToSprite());
            }

            if (attributes.ContainsKey("tooltipFontSize"))
            {
                SetFontSize(int.Parse(attributes["tooltipfontsize"]));
            }
            if (attributes.ContainsKey("tooltipPadding"))
            {
                SetTooltipPadding(attributes["tooltipPadding"].ToRectOffset());
            }

            if (attributes.ContainsKey("tooltipTextOutlineColor"))
            {
                SetTextOutlineColor(attributes["tooltipTextOutlineColor"].ToColor(xmlLayout));
            }
            if (attributes.ContainsKey("tooltipFont"))
            {
                SetFont(attributes["tooltipFont"]);
            }

            if (attributes.ContainsKey("tooltipPosition"))
            {
                tooltipPosition = (TooltipPosition)Enum.Parse(typeof(TooltipPosition), attributes["tooltipPosition"]);
            }
            if (attributes.ContainsKey("tooltipFollowMouse"))
            {
                followMouse = attributes["tooltipFollowMouse"].ToBoolean();
            }
            if (attributes.ContainsKey("tooltipOffset"))
            {
                offsetDistance = float.Parse(attributes["tooltipOffset"]);
            }

            if (attributes.ContainsKey("tooltipFadeTime"))
            {
                fadeTime = attributes["tooltipFadeTime"].ToFloat();
            }
            if (attributes.ContainsKey("tooltipDelayTime"))
            {
                showDelayTime = attributes["tooltipDelayTime"].ToFloat();
            }

            if (attributes.ContainsKey("tooltipWidth"))
            {
                width = attributes["tooltipWidth"].ToFloat();
            }
            else
            {
                width = 0;
            }
        }
Ejemplo n.º 9
0
        public void LoadAttributes(AttributeDictionary attributes)
        {
            if (attributes.ContainsKey("tooltipTextColor"))
            {
                SetTextColor(attributes["tooltipTextColor"].ToColor());
            }
            if (attributes.ContainsKey("tooltipBackgroundColor"))
            {
                SetBackgroundColor(attributes["tooltipBackgroundColor"].ToColor());
            }
            if (attributes.ContainsKey("tooltipBorderColor"))
            {
                SetBorderColor(attributes["tooltipBorderColor"].ToColor());
            }

            if (attributes.ContainsKey("tooltipBackgroundImage"))
            {
                SetBackgroundImage(attributes["tooltipBackgroundImage"].ToSprite());
            }
            if (attributes.ContainsKey("tooltipBorderImage"))
            {
                SetBorderImage(attributes["tooltipBorderImage"].ToSprite());
            }

            if (attributes.ContainsKey("tooltipFontSize"))
            {
                SetFontSize(int.Parse(attributes["tooltipfontsize"]));
            }
            if (attributes.ContainsKey("tooltipPadding"))
            {
                SetTooltipPadding(attributes["tooltipPadding"].ToRectOffset());
            }

            if (attributes.ContainsKey("tooltipTextOutlineColor"))
            {
                SetTextOutlineColor(attributes["tooltipTextOutlineColor"].ToColor());
            }
            if (attributes.ContainsKey("tooltipFont"))
            {
                SetFont(attributes["tooltipFont"].ToFont());
            }

            if (attributes.ContainsKey("tooltipPosition"))
            {
                tooltipPosition = (TooltipPosition)Enum.Parse(typeof(TooltipPosition), attributes["tooltipPosition"]);
            }
            if (attributes.ContainsKey("tooltipFollowMouse"))
            {
                followMouse = attributes["tooltipFollowMouse"].ToBoolean();
            }
            if (attributes.ContainsKey("tooltipOffset"))
            {
                offsetDistance = float.Parse(attributes["tooltipOffset"]);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Apply the specified attributes to the XmlElement (and its other relevant components)
        /// </summary>
        /// <param name="attributesToApply"></param>
        public virtual void ApplyAttributes(AttributeDictionary attributesToApply)
        {
            if (currentInstanceTransform == null || currentXmlLayoutInstance == null)
            {
                Debug.LogWarning("[XmlLayout][Warning] Please call ElementTagHandler.SetInstance() before using XmlElement.ApplyAttributes()");
                return;
            }

            //var startTime = DateTime.Now;
            attributesToApply = HandleCustomAttributes(attributesToApply);
            var _primaryComponent = primaryComponent;

            // the vast majority of events require the element to block raycasts, so rather than expecting the users to set this value every time,
            // lets set it here
            if (attributesToApply.Any(a => !String.Equals("onValueChanged", a.Key, StringComparison.OrdinalIgnoreCase) && eventAttributeNames.Contains(a.Key, StringComparer.OrdinalIgnoreCase)))
            {
                attributesToApply.AddIfKeyNotExists("raycastTarget", "true");
            }

            if (attributesToApply.ContainsKey("allowDragging") && attributesToApply["allowDragging"].ToBoolean())
            {
                var dragEventHandler = currentXmlElement.GetComponent <XmlLayoutDragEventHandler>();
                if (dragEventHandler == null)
                {
                    currentXmlElement.gameObject.AddComponent <XmlLayoutDragEventHandler>();
                }
            }

            foreach (var attribute in attributesToApply)
            {
                string name  = attribute.Key;
                string value = attribute.Value;

                if (eventAttributeNames.Contains(name, StringComparer.OrdinalIgnoreCase))
                {
                    // As it happens, events don't work anyway unless they are processed at runtime (which is why we have 'ForceRebuildOnAwake')
                    // so we may as well not process any event attributes at all in edit mode
                    // (this also helps avoid triggering event handlers in edit mode)
                    if (Application.isPlaying)
                    {
                        HandleEventAttribute(name, value);
                    }
                    continue;
                }

                var propertySetOnComponent = _primaryComponent != null?SetPropertyValue(_primaryComponent, name, value) : false;

                // if we failed to set the property on the component, perhaps it is a transform value instead
                if (!propertySetOnComponent)
                {
                    var propertySetOnTransform = SetPropertyValue(currentInstanceTransform, name, value);

                    // perhaps it is a layout value
                    if (!propertySetOnTransform)
                    {
                        var propertySetOnLayoutComponent = SetPropertyValue(layoutElement, name, value);

                        // or, perhaps it is an image value
                        if (!propertySetOnLayoutComponent)
                        {
                            // lastly, check the XmlElement
                            var propertySetOnXmlElement = SetPropertyValue(currentXmlElement, name, value);

                            if (!propertySetOnXmlElement)
                            {
                                var _imageComponent = imageComponent;
                                if (_imageComponent != null)
                                {
                                    SetPropertyValue(imageComponent, name, value);
                                }
                            }
                        }
                    }
                }
            }

#if !ENABLE_IL2CPP
            if (!dontCallHandleDataSourceAttributeAutomatically && attributesToApply.ContainsKey("vm-dataSource"))
            {
                HandleDataSourceAttribute(attributesToApply["vm-dataSource"]);
            }
#endif
        }