Esempio n. 1
0
        /// <summary>
        /// Reads the component metadata and extracts key/value pairs
        /// </summary>
        /// <returns></returns>
        public StyleTable Produce()
        {
            //Debug.Log(string.Format("DefaultValuesFactory->Produce [{0}]", _componentType));

            if (null == _cached)
            {
                _cached = new StyleTable();

                var attributes = StyleReflector.GetStyleAttributes(_componentType);

#if DEBUG
                if (null != StyleProtoChain.TYPE_TO_MONITOR)
                {
                    if (_componentType == StyleProtoChain.TYPE_TO_MONITOR)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (StyleAttribute attribute in attributes)
                        {
                            sb.AppendLine(string.Format("[{0}, {1}]", attribute.Name, attribute.GetDefault()));
                        }
                        Debug.Log(string.Format(@"DefaultValuesFactory->Produced [{0}]
{1}", _componentType, sb));
                    }
                }
#endif

                foreach (StyleAttribute attribute in attributes)
                {
                    /**
                     * 1. Validate proxy
                     * */
                    ValidateAttribute(attribute);

                    /**
                     * 2. Extract possible value
                     * */
                    var def = attribute.GetDefault(); // ovdje je bio bug kod boja - nije se koristilo GetDefault(), već samo Default
                    if (null != def)
                    {
                        _cached.Add(attribute.Name, def);
                    }
                }
            }

            return((StyleTable)_cached.Clone());
        }
// ReSharper restore UnassignedField.Global
#endif

        internal static void Load()
        {
            //Debug.Log("##### Loading default styles #####");

            var styleManager = StyleManager.Instance;

            if (null == _styleableClasses)
            {
                _styleableClasses = StyleReflector.GetAllStyleableClasses();
            }

#if DEBUG
            if (DebugMode)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Type type in _styleableClasses)
                {
                    sb.AppendLine(type.FullName);
                }
                Debug.Log(string.Format(@"Default style declarations from styleable types ({0}):
{1}", _styleableClasses.Count, sb));
            }
#endif

#if DEBUG
            if (DebugMode)
            {
                _time = DateTime.Now;
            }
#endif

            foreach (Type type in _styleableClasses)
            {
                //var selector = StyleSelector.FormatType(type.FullName);
                var    fullName    = type.FullName; // string.Format("[{0}]", type.FullName);
                object selector    = new Selector(fullName, null);
                var    mergedStyle = styleManager.GetMergedStyleDeclaration(fullName);

                /*if (null != mergedStyle)
                 *  Debug.Log("mergedStyle for " + type.FullName + " is:" + mergedStyle);*/

                /**
                 * Creating style declaration
                 * */
                var declaration = new StyleDeclaration(selector, mergedStyle == null); // {IsReflected = true};

                if (declaration.Set1 == null)
                {
                    declaration.Set1 = new DefaultValuesFactory(type);
                }

                if (mergedStyle != null &&
                    (null == mergedStyle.Set1 ||
                     //ObjectUtil.compare(new style.defaultFactory(), new mergedStyle.defaultFactory())))
                     declaration.Set1.Produce().Equals(mergedStyle.Set1.Produce())))
                {
                    //Debug.Log("*** Setting for " + style.SelectorString);
                    styleManager.SetStyleDeclaration(declaration.SelectorString, declaration, false);
                }
                //Debug.Log("   -> " + StyleManager.Instance.GetStyleDeclaration(selector));
            }

#if DEBUG
            if (DebugMode)
            {
                var diff = DateTime.Now.Subtract(_time);
                Debug.Log("It took " + diff.TotalMilliseconds + " ms.");
            }
#endif
        }