Ejemplo n.º 1
0
        //a IEnumberable entry
        public InspectorInfo(IList <object> masterList, InspectorInfo parentItem, object obj) //obj = null
        {
            this.whitespace = "|";
            if (parentItem != null)
            {
                this.whitespace += parentItem.whitespace;
            }
            this.parentItem = parentItem;
            this.obj        = obj;
            this.masterList = masterList;
            this.fpinfo     = null;
            this.children   = new List <InspectorInfo>();
            //this.inspectorArea = parentItem.inspectorArea;
            this.showValueToString = parentItem.showValueToString;
            Type t = parentItem.obj.GetType();

            if (t.GetInterfaces()
                .Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
            {
                //Console.WriteLine("IEnumerable : {0}", obj.GetType());
                membertype = member_type.collectionentry;
                CheckItemType();
                prefix = "" + ((char)164);
            }
            else
            {
                System.Console.WriteLine("Unexpected: InspectorInfo with no obj reference was not a collection entry");
                membertype = member_type.unimplemented;
            }
        }
Ejemplo n.º 2
0
        //a dictionary entry
        public InspectorInfo(IList <object> masterList, InspectorInfo parentItem, object obj, object key) //obj = null
        {
            this.whitespace = "|";
            if (parentItem != null)
            {
                this.whitespace += parentItem.whitespace;
            }
            this.parentItem = parentItem;
            this.obj        = obj;
            this.masterList = masterList;
            this.fpinfo     = null;
            this.children   = new List <InspectorInfo>();
            //this.inspectorArea = parentItem.inspectorArea;
            this.showValueToString = parentItem.showValueToString;
            Type t = parentItem.obj.GetType();

            if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary <,>))
            {
                membertype = member_type.dictentry;
                this.key   = key;
                CheckItemType();
                prefix = "" + ((char)164);
                //System.Console.WriteLine(this);
                //children = GenerateList(obj, whitespace, this);
            }
            else
            {
                System.Console.WriteLine("Unexpected: InspectorInfo with no obj reference was not a dictionary entry");
                membertype = member_type.unimplemented;
            }
        }
Ejemplo n.º 3
0
        public void BuildItemsPath(InspectorInfo item, List <InspectorInfo> itemspath)
        {
            InspectorInfo temp = item;

            itemspath.Insert(0, temp);
            while (temp.parentItem != null)
            {
                temp = temp.parentItem;
                itemspath.Insert(0, temp);
            }
        }
Ejemplo n.º 4
0
 public bool ReferenceExists(InspectorInfo parent, object reference)
 {
     if (parent == null)
     {
         return(false);
     }
     if (parent.obj == reference)
     {
         return(true);
     }
     return(ReferenceExists(parent.parentItem, reference));
 }
Ejemplo n.º 5
0
 public void AddChildrenToMasterDeep()
 {
     foreach (object child in children.ToList())
     {
         InspectorInfo item = (InspectorInfo)child;
         if (masterList != null)
         {
             masterList.Add(child);
         }
         if (item.children.Count > 0 && item.extended)
         {
             item.AddChildrenToMasterDeep();
         }
     }
 }
Ejemplo n.º 6
0
 private void FieldOrPropertyInitilize(IList <object> masterList, InspectorInfo parentItem, object obj)
 {
     this.whitespace = "|";
     if (parentItem != null)
     {
         this.whitespace += parentItem.whitespace;
     }
     this.obj               = obj;
     this.parentItem        = parentItem;
     this.masterList        = masterList;
     this.children          = new List <InspectorInfo>();
     this.showValueToString = parentItem.showValueToString;
     CheckItemType();
     prefix = "" + ((char)164);
     //this.inspectorArea = parentItem.inspectorArea;
 }
Ejemplo n.º 7
0
 //method
 public InspectorInfo(IList <object> masterList, InspectorInfo parentItem, MethodInfo methodInfo)
 {
     this.membertype = member_type.method;
     this.methodInfo = methodInfo;
     this.whitespace = "|";
     if (parentItem != null)
     {
         this.whitespace += parentItem.whitespace;
     }
     this.obj               = null;
     this.parentItem        = parentItem;
     this.masterList        = masterList;
     this.children          = new List <InspectorInfo>();
     this.showValueToString = parentItem.showValueToString;
     CheckItemType();
     prefix = "" + ((char)164);
     //this.inspectorArea = parentItem.inspectorArea;
 }
Ejemplo n.º 8
0
        public static void InsertItemSorted(List <InspectorInfo> itemList, InspectorInfo item)
        {
            int length = itemList.Count;
            int weight = (int)item.datatype;

            if (weight == 0)
            {
                itemList.Add(item);
                return;
            }
            for (int i = 0; i < length; i++)
            {
                int itemweight = (int)((InspectorInfo)itemList.ElementAt(i)).datatype;
                if (weight < itemweight)
                {
                    itemList.Insert(i, item);
                    return;
                }
            }
            itemList.Add(item);
        }
Ejemplo n.º 9
0
        public static List <InspectorInfo> GenerateList(object parent, InspectorInfo parentItem = null,
                                                        bool GenerateFields = false, UserLevel?userLevel = null)
        {
            UserLevel userlevel = UserLevel.Debug;

            if (userLevel != null)
            {
                userlevel = (UserLevel)userLevel;
            }

            List <InspectorInfo> list = new List <InspectorInfo>();
            //char a = (char)164;
            //System.Console.WriteLine(a);
            //string space = "|";
            //if (parentItem != null) space += parentItem.whitespace;
            //List<FieldInfo> fieldInfos = o.GetType().GetFields().ToList(); //just supporting properties for now
            data_type dt = data_type.obj;

            //if this item is the root, we should give it it's real type in.steam of assuming it's an object
            if (parentItem != null)
            {
                dt = parentItem.datatype;
            }

            if (dt == data_type.collection)
            {
                dynamic collection = parent;
                foreach (object o in collection)
                {
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, o);
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
            }
            else if (dt == data_type.array)
            {
                dynamic array = parent;
                foreach (object o in array)
                {
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, o);
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
            }
            else if (dt == data_type.dict)
            {
                //dynamic dict = iitem.fpinfo.GetValue(iitem.parentItem);
                dynamic dict = parent;
                foreach (dynamic key in dict.Keys)
                {
                    //System.Console.WriteLine(key.ToString());
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, dict[key], key);
                    //iitem.GenerateChildren();
                    //list.Add(iitem);
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
            }
            else if (dt == data_type.obj)
            {
                ///// PROPERTIES
                List <PropertyInfo> propertyInfos;
                //if the object isn't a component, then we only want to see the 'declared' properties (not inherited)
                if (!(parent is Component || parent is Player)) // || parent is Process))
                {
                    propertyInfos =
                        parent.GetType()
                        .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                        .ToList();
                }
                else
                {
                    propertyInfos = parent.GetType().GetProperties().ToList();
                }

                foreach (PropertyInfo pinfo in propertyInfos)
                {
                    string   tooltip      = "";
                    object[] attributes   = pinfo.GetCustomAttributes(false);
                    var      abstractions = pinfo.GetCustomAttributes(typeof(Info), false);
                    if (abstractions.Length > 0)
                    {
                        Info info = (Info)abstractions[0];
                        if ((int)info.userLevel > (int)userlevel)
                        {
                            continue;
                        }
                        tooltip = info.summary;
                    }
                    else if (userlevel != UserLevel.Debug)
                    {
                        continue;
                    }
                    //if (pinfo.Name.Equals("Item")) continue;
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, pinfo.GetValue(parent, null), pinfo);
                    if (tooltip.Length > 0)
                    {
                        iitem.ToolTip = tooltip;
                    }
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
                ////// FIELDS
                List <FieldInfo> fieldInfos;
                //if the object isn't a component, then we only want to see the 'declared' properties (not inherited)
                if (!(parent is Component || parent is Player)) // || parent is Process))
                {
                    fieldInfos =
                        parent.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList();
                }
                else
                {
                    fieldInfos = parent.GetType().GetFields().ToList();
                }

                foreach (FieldInfo finfo in fieldInfos)
                {
                    //if (finfo.GetCustomAttributes(typeof(DoNotInspect), false).Length > 0) continue;
                    var abstractions = finfo.GetCustomAttributes(typeof(Info), false);
                    if (abstractions.Length > 0)
                    {
                        if ((int)(abstractions[0] as Info).userLevel > (int)userlevel)
                        {
                            continue;
                        }
                    }
                    else if (userlevel != UserLevel.Debug)
                    {
                        continue;
                    }
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, finfo.GetValue(parent), finfo);
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
                ////METHODS
                List <MethodInfo> methodInfos;
                //if the object isn't a component, then we only want to see the 'declared' properties (not inherited)
                if (!(parent is Component || parent is Player)) // || parent is Process))
                {
                    methodInfos =
                        parent.GetType()
                        .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                        .ToList();
                }
                else
                {
                    methodInfos = parent.GetType().GetMethods().ToList();
                }

                foreach (MethodInfo minfo in methodInfos)
                {
                    //if (finfo.GetCustomAttributes(typeof(DoNotInspect), false).Length > 0) continue;
                    var abstractions = minfo.GetCustomAttributes(typeof(Clickable), false);
                    if (abstractions.Length == 0)
                    {
                        continue;
                    }
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, minfo);
                    InsertItemSorted(list, iitem);
                }
            }
            //if it's just a normal primitive, it will return an empty list
            if (list.Count > 0)
            {
                parentItem.prefix = "+";
            }
            return(list);
        }
Ejemplo n.º 10
0
 //a field
 public InspectorInfo(IList <object> masterList, InspectorInfo parentItem, object obj, FieldInfo fieldInfo)
 {
     this.membertype = member_type.field;
     this.fpinfo     = new FPInfo(fieldInfo);
     FieldOrPropertyInitilize(masterList, parentItem, obj);
 }
Ejemplo n.º 11
0
        public void ApplyToAllNodes(Group group)
        {
            if (group == null)
            {
                return;
            }
            List <InspectorInfo> itemspath = new List <InspectorInfo>();
            InspectorInfo        item      = this;
            object value = item.GetValue();

            BuildItemsPath(item, itemspath);

            group.ForEachAllSets(delegate(Node n) {
                if (n == itemspath.ElementAt(0).obj)
                {
                    return;
                }
                InspectorInfo temp = new InspectorInfo(null, n);
                int count          = 0;
                foreach (InspectorInfo pathitem in itemspath)
                {
                    if (temp.methodInfo != null)
                    {
                        temp.methodInfo.Invoke(temp.parentobj, null);
                        break;
                    }
                    if (temp.obj.GetType() != pathitem.obj.GetType())
                    {
                        Console.WriteLine("The paths did not match while applying to all. {0} != {1}",
                                          temp.obj.GetType(),
                                          pathitem.obj.GetType());
                        break;
                    }
                    if (count == itemspath.Count - 1)            //last item
                    {
                        if (pathitem.membertype == member_type.dictentry)
                        {
                            dynamic dict = temp.parentItem.obj;
                            dynamic key  = pathitem.key;
                            if (!dict.ContainsKey(key))
                            {
                                break;
                            }
                            if (dict[key] is Component)
                            {
                                dict[key].active = ((Component)value).active;
                            }
                            else if (temp.IsPanelType())
                            {
                                dict[key] = value;
                            }
                        }
                        else
                        {
                            if (value is Component)
                            {
                                ((Component)temp.obj).active = ((Component)value).active;
                            }
                            else if (temp.IsPanelType())
                            {
                                temp.fpinfo.SetValue(value, temp.parentItem.obj);
                                //temp.SetValue(value);
                            }
                            else if (Utils.isToggle(temp.obj))
                            {
                                temp.SetValue(value);
                            }
                        }
                    }
                    else
                    {
                        InspectorInfo next = itemspath.ElementAt(count + 1);
                        if (next.membertype == member_type.dictentry)
                        {
                            dynamic dict = temp.obj;
                            dynamic key  = next.key;
                            if (!dict.ContainsKey(key))
                            {
                                break;
                            }
                            temp = new InspectorInfo(null, temp, dict[key], key);
                        }
                        else if (next.membertype == member_type.method)
                        {
                            temp = new InspectorInfo(null, temp,
                                                     temp.obj.GetType().GetMethod(next.methodInfo.Name));
                        }
                        else
                        {
                            if (next.fpinfo.propertyInfo == null)
                            {
                                temp = new InspectorInfo(null, temp, next.fpinfo.GetValue(temp.obj),
                                                         next.fpinfo.fieldInfo);
                            }
                            else
                            {
                                temp = new InspectorInfo(null, temp, next.fpinfo.GetValue(temp.obj),
                                                         next.fpinfo.propertyInfo);
                            }
                        }
                    }
                    count++;
                }
            });
        }