예제 #1
0
        private void Node(TreeNode_Editor node, int indentLevel, int openMask)
        {
            if (node.nodeType == EditTreeNodeType.TerminalValue)
            {
                node.DoSpecialPreElements(this);
                OpenCloseWidget(node, indentLevel, openMask);
                NodeLabelLeft(node, indentLevel);
                WidgetRow widgetRow = new WidgetRow(LabelWidth, curY);
                ControlButtonsRight(node, widgetRow);
                ValueEditWidgetRight(node, widgetRow.FinalX);
                EndLine();
                return;
            }
            OpenCloseWidget(node, indentLevel, openMask);
            NodeLabelLeft(node, indentLevel);
            WidgetRow widgetRow2 = new WidgetRow(LabelWidth, curY);

            ControlButtonsRight(node, widgetRow2);
            ExtraInfoText(node, widgetRow2);
            EndLine();
            if (node.IsOpen(openMask))
            {
                ContentLines(node, indentLevel + 1);
            }
            if (node.nodeType == EditTreeNodeType.ListRoot)
            {
                node.CheckLatentDelete();
            }
        }
        public override void DoWindowContents(Rect inRect)
        {
            if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Escape))
            {
                UI.UnfocusCurrentControl();
            }
            Rect rect = new Rect(0f, 0f, inRect.width, 16f);

            this.labelColumnWidth = Widgets.HorizontalSlider(rect, this.labelColumnWidth, 0f, inRect.width, false, null, null, null, -1f);
            Rect outRect = inRect.AtZero();

            outRect.yMin += 16f;
            Rect rect2 = new Rect(0f, 0f, outRect.width - 16f, this.viewHeight);

            Widgets.BeginScrollView(outRect, ref this.scrollPosition, rect2, true);
            Listing_TreeDefs listing_TreeDefs = new Listing_TreeDefs(this.labelColumnWidth);

            listing_TreeDefs.Begin(rect2);
            TreeNode_Editor node = EditTreeNodeDatabase.RootOf(this.def);

            listing_TreeDefs.ContentLines(node, 0);
            listing_TreeDefs.End();
            if (Event.current.type == EventType.Layout)
            {
                this.viewHeight = listing_TreeDefs.CurHeight + 200f;
            }
            Widgets.EndScrollView();
        }
예제 #3
0
 private void ControlButtonsRight(TreeNode_Editor node, WidgetRow widgetRow)
 {
     if (node.HasNewButton && widgetRow.ButtonIcon(TexButton.NewItem))
     {
         Action <object> addAction = delegate(object o)
         {
             node.owningField.SetValue(node.ParentObj, o);
             ((TreeNode_Editor)node.parentNode).RebuildChildNodes();
         };
         MakeCreateNewObjectMenu(node, node.owningField, node.owningField.FieldType, addAction);
     }
     if (node.nodeType == EditTreeNodeType.ListRoot && widgetRow.ButtonIcon(TexButton.Add))
     {
         Type            baseType   = node.obj.GetType().GetGenericArguments()[0];
         Action <object> addAction2 = delegate(object o)
         {
             node.obj.GetType().GetMethod("Add").Invoke(node.obj, new object[1]
             {
                 o
             });
         };
         MakeCreateNewObjectMenu(node, node.owningField, baseType, addAction2);
     }
     if (node.HasDeleteButton && widgetRow.ButtonIcon(TexButton.DeleteX, null, GenUI.SubtleMouseoverColor))
     {
         node.Delete();
     }
 }
예제 #4
0
 private void Node(TreeNode_Editor node, int indentLevel, int openMask)
 {
     if (node.nodeType == EditTreeNodeType.TerminalValue)
     {
         node.DoSpecialPreElements(this);
         base.OpenCloseWidget(node, indentLevel, openMask);
         this.NodeLabelLeft(node, indentLevel);
         WidgetRow widgetRow = new WidgetRow(this.LabelWidth, this.curY, UIDirection.RightThenUp, 99999f, 4f);
         this.ControlButtonsRight(node, widgetRow);
         this.ValueEditWidgetRight(node, widgetRow.FinalX);
         base.EndLine();
     }
     else
     {
         base.OpenCloseWidget(node, indentLevel, openMask);
         this.NodeLabelLeft(node, indentLevel);
         WidgetRow widgetRow2 = new WidgetRow(this.LabelWidth, this.curY, UIDirection.RightThenUp, 99999f, 4f);
         this.ControlButtonsRight(node, widgetRow2);
         this.ExtraInfoText(node, widgetRow2);
         base.EndLine();
         if (node.IsOpen(openMask))
         {
             this.ContentLines(node, indentLevel + 1);
         }
         if (node.nodeType == EditTreeNodeType.ListRoot)
         {
             node.CheckLatentDelete();
         }
     }
 }
예제 #5
0
        public void RebuildChildNodes()
        {
            if (obj == null)
            {
                return;
            }
            children = new List <TreeNode>();
            Type objType = obj.GetType();

            if (objType.IsGenericType && objType.GetGenericTypeDefinition() == typeof(List <>))
            {
                int num = (int)objType.GetProperty("Count").GetValue(obj, null);
                for (int i = 0; i < num; i++)
                {
                    TreeNode_Editor item = NewChildNodeFromListItem(this, i);
                    children.Add(item);
                }
                return;
            }
            foreach (FieldInfo item3 in from f in obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                     orderby InheritanceDistanceBetween(objType, f.DeclaringType) descending
                     select f)
            {
                if (item3.GetCustomAttributes(typeof(UnsavedAttribute), inherit: true).Length == 0 && item3.GetCustomAttributes(typeof(EditorHiddenAttribute), inherit: true).Length == 0)
                {
                    TreeNode_Editor item2 = NewChildNodeFromField(this, item3);
                    children.Add(item2);
                }
            }
        }
예제 #6
0
        protected void MakeCreateNewObjectMenu(TreeNode_Editor owningNode, FieldInfo owningField, Type baseType, Action <object> addAction)
        {
            List <Type>            list  = baseType.InstantiableDescendantsAndSelf().ToList <Type>();
            List <FloatMenuOption> list2 = new List <FloatMenuOption>();

            foreach (Type current in list)
            {
                Type   creatingType = current;
                Action action       = delegate
                {
                    owningNode.SetOpen(-1, true);
                    object obj;
                    if (creatingType == typeof(string))
                    {
                        obj = string.Empty;
                    }
                    else
                    {
                        obj = Activator.CreateInstance(creatingType);
                    }
                    addAction(obj);
                    if (owningNode != null)
                    {
                        owningNode.RebuildChildNodes();
                    }
                };
                list2.Add(new FloatMenuOption(current.ToString(), action, MenuOptionPriority.Default, null, null, 0f, null, null));
            }
            Find.WindowStack.Add(new FloatMenu(list2));
        }
예제 #7
0
 public void ContentLines(TreeNode_Editor node, int indentLevel)
 {
     node.DoSpecialPreElements(this);
     if (node.children == null)
     {
         Log.Error(node + " children is null.");
         return;
     }
     for (int i = 0; i < node.children.Count; i++)
     {
         Node((TreeNode_Editor)node.children[i], indentLevel, 64);
     }
 }
        public static TreeNode_Editor RootOf(object obj)
        {
            for (int i = 0; i < EditTreeNodeDatabase.roots.Count; i++)
            {
                if (EditTreeNodeDatabase.roots[i].obj == obj)
                {
                    return(EditTreeNodeDatabase.roots[i]);
                }
            }
            TreeNode_Editor treeNode_Editor = TreeNode_Editor.NewRootNode(obj);

            EditTreeNodeDatabase.roots.Add(treeNode_Editor);
            return(treeNode_Editor);
        }
예제 #9
0
        protected void NodeLabelLeft(TreeNode_Editor node, int indentLevel)
        {
            string tipText = "";

            if (node.owningField != null)
            {
                DescriptionAttribute[] array = (DescriptionAttribute[])node.owningField.GetCustomAttributes(typeof(DescriptionAttribute), inherit: true);
                if (array.Length != 0)
                {
                    tipText = array[0].description;
                }
            }
            LabelLeft(node.LabelText, tipText, indentLevel);
        }
예제 #10
0
        public static TreeNode_Editor NewChildNodeFromField(TreeNode_Editor parent, FieldInfo fieldInfo)
        {
            TreeNode_Editor treeNode_Editor = new TreeNode_Editor();

            treeNode_Editor.parentNode  = parent;
            treeNode_Editor.nestDepth   = parent.nestDepth + 1;
            treeNode_Editor.owningField = fieldInfo;
            if (!fieldInfo.FieldType.IsValueEditable())
            {
                treeNode_Editor.obj = fieldInfo.GetValue(parent.obj);
                treeNode_Editor.RebuildChildNodes();
            }
            treeNode_Editor.InitiallyCacheData();
            return(treeNode_Editor);
        }
예제 #11
0
        public static TreeNode_Editor NewRootNode(object rootObj)
        {
            if (rootObj.GetType().IsValueEditable())
            {
                throw new ArgumentException();
            }
            TreeNode_Editor treeNode_Editor = new TreeNode_Editor();

            treeNode_Editor.owningField = null;
            treeNode_Editor.obj         = rootObj;
            treeNode_Editor.nestDepth   = 0;
            treeNode_Editor.RebuildChildNodes();
            treeNode_Editor.InitiallyCacheData();
            return(treeNode_Editor);
        }
예제 #12
0
        private void ExtraInfoText(TreeNode_Editor node, WidgetRow widgetRow)
        {
            string extraInfoText = node.ExtraInfoText;

            if (extraInfoText != "")
            {
                if (extraInfoText == "null")
                {
                    GUI.color = new Color(1f, 0.6f, 0.6f, 0.5f);
                }
                else
                {
                    GUI.color = new Color(1f, 1f, 1f, 0.5f);
                }
                widgetRow.Label(extraInfoText);
                GUI.color = Color.white;
            }
        }
예제 #13
0
        private static TreeNode_Editor NewChildNodeFromListItem(TreeNode_Editor parent, int listIndex)
        {
            TreeNode_Editor treeNode_Editor = new TreeNode_Editor();

            treeNode_Editor.parentNode  = parent;
            treeNode_Editor.nestDepth   = parent.nestDepth + 1;
            treeNode_Editor.owningIndex = listIndex;
            object obj  = parent.obj;
            Type   type = obj.GetType();

            if (!type.GetGenericArguments()[0].IsValueEditable())
            {
                object obj2 = (treeNode_Editor.obj = type.GetProperty("Item").GetValue(obj, new object[1]
                {
                    listIndex
                }));
                treeNode_Editor.RebuildChildNodes();
            }
            treeNode_Editor.InitiallyCacheData();
            return(treeNode_Editor);
        }
예제 #14
0
        protected void MakeCreateNewObjectMenu(TreeNode_Editor owningNode, FieldInfo owningField, Type baseType, Action <object> addAction)
        {
            List <Type>            list  = baseType.InstantiableDescendantsAndSelf().ToList();
            List <FloatMenuOption> list2 = new List <FloatMenuOption>();

            foreach (Type item in list)
            {
                Type   creatingType = item;
                Action action       = delegate
                {
                    owningNode.SetOpen(-1, val: true);
                    object obj = (!(creatingType == typeof(string))) ? Activator.CreateInstance(creatingType) : "";
                    addAction(obj);
                    if (owningNode != null)
                    {
                        owningNode.RebuildChildNodes();
                    }
                };
                list2.Add(new FloatMenuOption(item.ToString(), action));
            }
            Find.WindowStack.Add(new FloatMenu(list2));
        }
예제 #15
0
        protected void ValueEditWidgetRight(TreeNode_Editor node, float leftX)
        {
            if (node.nodeType != EditTreeNodeType.TerminalValue)
            {
                throw new ArgumentException();
            }
            Rect   rect       = new Rect(leftX, curY, base.ColumnWidth - leftX, lineHeight);
            object obj        = node.Value;
            Type   objectType = node.ObjectType;

            if (objectType == typeof(string))
            {
                string text  = (string)obj;
                string text2 = text;
                if (text2 == null)
                {
                    text2 = "";
                }
                string b = text2;
                text2 = Widgets.TextField(rect, text2);
                if (text2 != b)
                {
                    text = text2;
                }
                obj = text;
            }
            else if (objectType == typeof(bool))
            {
                bool checkOn = (bool)obj;
                Widgets.Checkbox(new Vector2(rect.x, rect.y), ref checkOn, lineHeight);
                obj = checkOn;
            }
            else if (objectType == typeof(int))
            {
                rect.width = 100f;
                if (int.TryParse(Widgets.TextField(rect, obj.ToString()), out int result))
                {
                    obj = result;
                }
            }
            else if (objectType == typeof(float))
            {
                EditSliderRangeAttribute[] array = (EditSliderRangeAttribute[])node.owningField.GetCustomAttributes(typeof(EditSliderRangeAttribute), inherit: true);
                if (array.Length != 0)
                {
                    float value = (float)obj;
                    value = Widgets.HorizontalSlider(new Rect(LabelWidth + 60f + 4f, curY, base.EditAreaWidth - 60f - 8f, lineHeight), value, array[0].min, array[0].max);
                    obj   = value;
                }
                rect.width = 60f;
                string text3 = obj.ToString();
                text3 = Widgets.TextField(rect, text3);
                if (float.TryParse(text3, out float result2))
                {
                    obj = result2;
                }
            }
            else if (objectType.IsEnum)
            {
                if (Widgets.ButtonText(rect, obj.ToString()))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    foreach (object value2 in Enum.GetValues(objectType))
                    {
                        object localVal = value2;
                        list.Add(new FloatMenuOption(value2.ToString(), delegate
                        {
                            node.Value = localVal;
                        }));
                    }
                    Find.WindowStack.Add(new FloatMenu(list));
                }
            }
            else if (objectType == typeof(FloatRange))
            {
                float sliderMin = 0f;
                float sliderMax = 100f;
                EditSliderRangeAttribute[] array2 = (EditSliderRangeAttribute[])node.owningField.GetCustomAttributes(typeof(EditSliderRangeAttribute), inherit: true);
                if (array2.Length != 0)
                {
                    sliderMin = array2[0].min;
                    sliderMax = array2[0].max;
                }
                FloatRange fRange = (FloatRange)obj;
                Widgets.FloatRangeWithTypeIn(rect, rect.GetHashCode(), ref fRange, sliderMin, sliderMax);
                obj = fRange;
            }
            else
            {
                GUI.color = new Color(1f, 1f, 1f, 0.4f);
                Widgets.Label(rect, "uneditable value type");
                GUI.color = Color.white;
            }
            node.Value = obj;
        }
예제 #16
0
        protected void ValueEditWidgetRight(TreeNode_Editor node, float leftX)
        {
            if (node.nodeType != EditTreeNodeType.TerminalValue)
            {
                throw new ArgumentException();
            }
            Rect   rect       = new Rect(leftX, this.curY, base.ColumnWidth - leftX, this.lineHeight);
            object obj        = node.Value;
            Type   objectType = node.ObjectType;

            if (objectType == typeof(string))
            {
                string text  = (string)obj;
                string text2 = text;
                if (text2 == null)
                {
                    text2 = string.Empty;
                }
                string b = text2;
                text2 = Widgets.TextField(rect, text2);
                if (text2 != b)
                {
                    text = text2;
                }
                obj = text;
            }
            else if (objectType == typeof(bool))
            {
                bool flag = (bool)obj;
                Widgets.Checkbox(new Vector2(rect.x, rect.y), ref flag, this.lineHeight, false, false, null, null);
                obj = flag;
            }
            else if (objectType == typeof(int))
            {
                rect.width = 100f;
                string s = Widgets.TextField(rect, obj.ToString());
                int    num;
                if (int.TryParse(s, out num))
                {
                    obj = num;
                }
            }
            else if (objectType == typeof(float))
            {
                EditSliderRangeAttribute[] array = (EditSliderRangeAttribute[])node.owningField.GetCustomAttributes(typeof(EditSliderRangeAttribute), true);
                if (array.Length > 0)
                {
                    float num2  = (float)obj;
                    Rect  rect2 = new Rect(this.LabelWidth + 60f + 4f, this.curY, base.EditAreaWidth - 60f - 8f, this.lineHeight);
                    num2 = Widgets.HorizontalSlider(rect2, num2, array[0].min, array[0].max, false, null, null, null, -1f);
                    obj  = num2;
                }
                rect.width = 60f;
                string text3 = obj.ToString();
                text3 = Widgets.TextField(rect, text3);
                float num3;
                if (float.TryParse(text3, out num3))
                {
                    obj = num3;
                }
            }
            else if (objectType.IsEnum)
            {
                if (Widgets.ButtonText(rect, obj.ToString(), true, false, true))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    foreach (object current in Enum.GetValues(objectType))
                    {
                        object localVal = current;
                        list.Add(new FloatMenuOption(current.ToString(), delegate
                        {
                            node.Value = localVal;
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    Find.WindowStack.Add(new FloatMenu(list));
                }
            }
            else if (objectType == typeof(FloatRange))
            {
                float sliderMin = 0f;
                float sliderMax = 100f;
                EditSliderRangeAttribute[] array2 = (EditSliderRangeAttribute[])node.owningField.GetCustomAttributes(typeof(EditSliderRangeAttribute), true);
                if (array2.Length > 0)
                {
                    sliderMin = array2[0].min;
                    sliderMax = array2[0].max;
                }
                FloatRange floatRange = (FloatRange)obj;
                Widgets.FloatRangeWithTypeIn(rect, node.owningIndex, ref floatRange, sliderMin, sliderMax, ToStringStyle.FloatTwo, null);
                obj = floatRange;
            }
            else
            {
                GUI.color = new Color(1f, 1f, 1f, 0.4f);
                Widgets.Label(rect, "uneditable value type");
                GUI.color = Color.white;
            }
            node.Value = obj;
        }