示例#1
0
        /// <summary>
        /// Returns true if the skin fits to component<br/>
        /// The skin fits to component if it contains all the required parts (being of required types)
        /// </summary>
        /// <param name="skinType"></param>
        /// <param name="componentType"></param>
        /// <returns></returns>
        public static bool SkinFitsComponent(Type skinType, Type componentType)
        {
            var parts = SkinPartCache.Instance.Get(componentType);

            /**
             * 1. Must have all the required skin parts
             * */
            foreach (var id in parts.Keys)
            {
                if (!parts[id]) // if part not required, continue
                    continue;

                var cmpMember = GlobalMemberCache.Instance.Get(componentType, id);
                if (null == cmpMember)
                {
                    cmpMember = new MemberWrapper(componentType, id);
                    GlobalMemberCache.Instance.Put(componentType, id, cmpMember);
                }

                var skinMember = GlobalMemberCache.Instance.Get(componentType, id);
                if (null == skinMember)
                {
                    /* TODO: undirty this */
                    try
                    {
                        skinMember = new MemberWrapper(skinType, id);
                        GlobalMemberCache.Instance.Put(componentType, id, skinMember);
                    }
                    catch (MemberNotFoundException ex)
                    {
                        // ignore because the member doesn't exist
                    }
                }

                if (null == skinMember || skinMember.GetType() != cmpMember.GetType())
                {
                    return false;
                }
            }

            /**
             * 2. Must have the same set of states
             * */
            // TODO:
            var skinStates = GuiReflector.GetSkinStates(componentType);

            var hostComponentType = GetHostComponent(skinType);
            var componentStates = GuiReflector.GetSkinStates(hostComponentType);

            // in current impl. the states have to be in the same order
            var sameStates = ListUtil<string>.Equals(skinStates, componentStates);
            return sameStates;
            //return true;
        }
示例#2
0
        private void Initialize()
        {
            if (null == _target)
            {
                throw new Exception("Target cannot be null");
            }

            if (string.IsNullOrEmpty(_variable))
            {
                throw new Exception("Variable not set");
            }

            _type = _target.GetType();

            // get it from cache
            Combo.Type     = _type;
            Combo.Variable = _variable;

            if (DoCacheMembers)
            {
                _setter = SetterCache.Get(Combo);

                if (null == _setter) // if nothing cached yet
                {
                    // cache it
                    _setter = new MemberWrapper(_type, _variable);
                    SetterCache.Put(Combo, _setter);
                }
            }
            else
            {
                _setter = new MemberWrapper(_type, _variable);
            }

            _memberType = _setter.MemberType;

            _initialized = true;
        }
示例#3
0
        private void Initialize()
        {
            if (null == _target)
                throw new Exception("Target cannot be null");

            if (string.IsNullOrEmpty(_variable))
                throw new Exception("Variable not set");

            _type = _target.GetType();

            if (DoCacheMembers)
            {
                _setter = SetterCache.Get(_type, _variable);

                if (null == _setter) // if nothing cached yet
                {
                    // cache it
                    _setter = new MemberWrapper(_type, _variable);
                    SetterCache.Put(_type, _variable, _setter);
                }
            }
            else
            {
                _setter = new MemberWrapper(_type, _variable);
            }

            _memberType = _setter.MemberType;

            _initialized = true;
        }
示例#4
0
        private static string GetSignals(Type componentType)
        {
            var memberNames = CoreReflector.GetFieldAndPropertyNames(componentType);
            //memberNames.Sort(MemberInfoSort);
            List<MemberInfo> infos = new List<MemberInfo>();
            foreach (var name in memberNames)
            {
                MemberWrapper mw = new MemberWrapper(componentType, name);
                if (mw.MemberType == typeof(Signal))
                    infos.Add(mw.MemberInfo);
            }

            infos.Sort(MemberInfoSort);

            StringBuilder sb = new StringBuilder();
            foreach (var memberInfo in infos)
            {
                sb.AppendLine(memberInfo.Name);
            }

            return string.Format(@"Signals ({0}):
{1}
{2}", infos.Count, Line, sb) + NewLine/* + NewLine*/;
        }
示例#5
0
        /// <summary>
        /// Describes mulricast delegates
        /// </summary>
        /// <param name="componentType"></param>
        /// <returns></returns>
        public static string GetMulticastDelegates(Type componentType)
        {
            var memberNames = CoreReflector.GetFieldAndPropertyNames(componentType);
            //memberNames.Sort(MemberInfoSort);
            List<string> data = new List<string>();
            foreach (var name in memberNames)
            {
                MemberWrapper mw = new MemberWrapper(componentType, name);
                if (mw.MemberType == typeof (Core.Events.MulticastDelegate))
                {
                    var output = mw.MemberInfo.Name;

                    /*var clazz = mw.MemberInfo.DeclaringType;
                    if (null != clazz)
                    {
                        var types = 


                        var instance = Activator.CreateInstance(clazz);
                        var value = mw.GetValue(instance);
                        if (null != value)
                            output = string.Format(@"{0} [{1}]", output, value.GetType().FullName);
                    }*/
                    
                    var attributes = CoreReflector.GetMemberAttributes<EventAttribute>(mw.MemberInfo);
                    if (attributes.Count > 0)
                    {
                        var eventAttribute = attributes[0];
                        output = string.Format(@"{0} → {1}", output, eventAttribute);
                    }

                    data.Add(output);
                }
            }

            data.Sort();

            StringBuilder sb = new StringBuilder();
            foreach (var item in data)
            {
                sb.AppendLine(item);
            }

            return string.Format(@"Multicast delegates ({0}):
{1}
{2}", data.Count, Line, sb) + NewLine/* + NewLine*/;
        }
示例#6
0
        /*private static int ClassNameSort(Type x, Type y)
        {
            return String.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase);
        }*/

        #endregion

        #region Skin parts
        
        /// <summary>
        /// Describes skin parts
        /// </summary>
        /// <param name="componentType"></param>
        /// <returns></returns>
        public static string GetSkinParts(Type componentType)
        {
            if (!typeof(SkinnableComponent).IsAssignableFrom(componentType))
            {
                return string.Format(@"Skin parts: Not a skinnable component." + NewLine + NewLine);
            }

            var dict = GuiReflector.GetSkinParts(componentType); // string->bool

            var list = new List<string>();
            foreach (string key in dict.Keys)
            {
                list.Add(key);
            }
            list.Sort();

            StringBuilder sb = new StringBuilder();
            foreach (var name in list)
            {
                MemberWrapper mw = new MemberWrapper(componentType, name);
                sb.AppendLine(string.Format("{0} [Type: {1}, Required: {2}]", name, mw.MemberType, dict[name]));
            }

            return string.Format(@"Skin parts ({0}):
{1}
{2}", list.Count, Line, sb) + NewLine/* + NewLine*/;
        }
示例#7
0
        private void FindSkinParts()
        {
            if (null == _thisType)
                _thisType = GetType();

            var parts = SkinParts.Keys;

            foreach (var id in parts)
            {
                object part = null;

                /**
                 * 1. If this is a mapper skin, 
                 * */
                if (_isMapperSkin)
                {
                    part = Skin.GetChildComponent(id);
                    //if (null != part)
                    //    Debug.Log("Found mapper skin part: " + part);
                    //else
                    //    Debug.Log(Skin + " -> Couldn't find mapper skin part: " + id);
                }

                else
                {
                    if (CoreReflector.HasMember(Skin, id))
                    {
                        try
                        {
                            part = CoreReflector.GetValue(Skin, id);
                        }
                        catch (InvalidCastException/* ex*/)
                        {
                            Debug.LogError(string.Format("Cannot cast the skin part to InteractiveComponent. Skin: {0}; Part: {1}", Skin, id));
                        }
                    }
                        
                    //else
                    //    Debug.LogWarning("Couldn't find member: " + id);
                }

                if (SkinParts[id]) // == true (required part)
                {
                    if (null == part)
                        throw new Exception("Required skin part not found: " + id);
                }

                if (null != part)
                {
                    /**
                     * Note: we've been having a hard-core bug here (20131216)!
                     * The system FREEZED when using Panel with children in designer
                     * For instance, a panel had a single button child as a content child (not tool or control bar child)
                     * This is also the source of bug whereever we add a child prior to adding itself to the display list (both designer and code)
                     * I think it might be related to styles and StyleProtoChain process (?)
                     * This shoould - of course - be fixed
                     * The problem with designer was in ComponentAdapter ("Produce" method):
                     * _component.AddEventListener(FrameworkEvent.PREINITIALIZE, InitializeHandler)
                     * During the PREINITILIZE, child components have not yet been created - so the skin wasn't created
                     * When I changed it to INITILIZE, it started to work properly:
                     * _component.AddEventListener(FrameworkEvent.INITIALIZE, InitializeHandler)                     * 
                     * */

                    /*if (id == "ContentGroup")
                        Debug.LogWarning("ContentGroup: " + part);*/

                    //CoreReflector.SetValue(this, id, part);
                    MemberWrapper wrapper = new MemberWrapper(GetType(), id);
                    wrapper.SetValue(this, part);

                    // If the assigned part has already been instantiated, call partAdded() here,
                    // but only for static parts.

                    try
                    {
                        /* Note: this fails, because the wrapper wraps around the Skin's property, not the Panel's */
                        //var p = CoreReflector.GetValue(this, id);
                        wrapper = new MemberWrapper(GetType(), id);
                        var p = wrapper.GetValue(this);

                        // TODO: we should get the value silently here, because not to disturb the DoubleGroup.Modified flag
                        //Debug.Log("Just added: " + p);

                        // If the assigned part has already been instantiated, call partAdded() here,
                        // but only for static parts.
                        if (null != p && !(p is IFactory))
                            PartAdded(id, p);
                    }
                    catch (ArgumentException ex)
                    {
                        throw ex;
                    }
                }
            }
        }