Forráskód Böngészése

Modifying GUI array/list now persist its expanded/collapsed state

BearishSun 10 éve
szülő
commit
3e9e8eb1c6

+ 12 - 14
MBansheeEditor/GUI/GUIListField.cs

@@ -29,15 +29,17 @@ namespace BansheeEditor
         { }
 
         /// <summary>
-        /// Constructs a new GUI list with the specified row types. Must be called right after the constructor.
+        /// Updates the GUI list contents. Must be called at least once in order for the contents to be populated.
         /// </summary>
         /// <typeparam name="T">Type of rows that are used to handle GUI for individual list elements.</typeparam>
         /// <param name="title">Label to display on the list GUI title.</param>
         /// <param name="empty">Should the created field represent a null object.</param>
         /// <param name="numRows">Number of rows to create GUI for. Only matters for a non-empty list.</param>
         /// <param name="layout">Layout to which to append the list GUI elements to.</param>
-        protected void Construct<T>(LocString title, bool empty, int numRows, GUILayout layout) where T : GUIListFieldRow, new()
+        protected void Update<T>(LocString title, bool empty, int numRows, GUILayout layout) where T : GUIListFieldRow, new()
         {
+            Destroy();
+
             if (empty)
             {
                 guiChildLayout = null;
@@ -258,33 +260,29 @@ namespace BansheeEditor
         protected Type arrayType;
 
         /// <summary>
-        /// Constructs a new GUI array.
+        /// Constructs a new empty GUI array.
         /// </summary>
-        private GUIArrayField()
+        public GUIArrayField()
         { }
 
         /// <summary>
-        /// Creates a new GUI array.
+        /// Updates the GUI array contents. Must be called at least once in order for the contents to be populated.
         /// </summary>
         /// <typeparam name="RowType">Type of rows that are used to handle GUI for individual list elements.</typeparam>
         /// <typeparam name="ElementType">Type of elements stored in the array.</typeparam>
         /// <param name="title">Label to display on the list GUI title.</param>
         /// <param name="array">Object containing the list data. Cannot be null.</param>
         /// <param name="layout">Layout to which to append the list GUI elements to.</param>
-        public static GUIArrayField Create<RowType, ElementType>(LocString title, ElementType[] array, GUILayout layout) 
+        public void Update<RowType, ElementType>(LocString title, ElementType[] array, GUILayout layout) 
             where RowType : GUIListFieldRow, new() 
         {
-            GUIArrayField newArrayField = new GUIArrayField();
+            this.arrayType = typeof(ElementType[]);
+            this.array = array;
 
             if (array != null)
-                newArrayField.Construct<RowType>(title, false, array.Length, layout);
+                base.Update<RowType>(title, false, array.Length, layout);
             else
-                newArrayField.Construct<RowType>(title, true, 0, layout);
-
-            newArrayField.arrayType = typeof (ElementType[]);
-            newArrayField.array = array;
-
-            return newArrayField;
+                base.Update<RowType>(title, true, 0, layout);
         }
 
         /// <inheritdoc/>

+ 11 - 16
MBansheeEditor/Inspector/InspectableArray.cs

@@ -11,7 +11,7 @@ namespace BansheeEditor
     {
         private object propertyValue; // TODO - This will unnecessarily hold references to the object
         private int numArrayElements;
-        private InspectableArrayGUI arrayGUIField;
+        private InspectableArrayGUI arrayGUIField = new InspectableArrayGUI();
 
         /// <summary>
         /// Creates a new inspectable array GUI for the specified property.
@@ -76,7 +76,7 @@ namespace BansheeEditor
         {
             GUILayout arrayLayout = layout.AddLayoutY(layoutIndex);
 
-            arrayGUIField = InspectableArrayGUI.Create(title, property, arrayLayout);
+            arrayGUIField.Update(title, property, arrayLayout);
         }
 
         /// <inheritdoc/>
@@ -103,35 +103,30 @@ namespace BansheeEditor
             private SerializableProperty property;
 
             /// <summary>
-            /// Constructs an inspectable array GUI.
+            /// Constructs a new empty inspectable array GUI.
             /// </summary>
-            /// <param name="property">Serializable property referencing a single-dimensional array.</param>
-            private InspectableArrayGUI(SerializableProperty property)
-            {
-                this.property = property;
-            }
+            public InspectableArrayGUI()
+            { }
 
             /// <summary>
-            /// Creates a new inspectable GUI array.
+            /// Updates the contents of the inspectable GUI array. Must be called at least once in order for the contents 
+            /// to be populated.
             /// </summary>
             /// <param name="title">Label to display on the list GUI title.</param>
             /// <param name="property">Serializable property referencing a single-dimensional array.</param>
             /// <param name="layout">Layout to which to append the list GUI elements to.</param>
-            /// <returns>Newly created inspectable GUI array object.</returns>
-            public static InspectableArrayGUI Create(LocString title, SerializableProperty property, GUILayout layout)
+            public void Update(LocString title, SerializableProperty property, GUILayout layout)
             {
-                InspectableArrayGUI newArrayField = new InspectableArrayGUI(property);
+                this.property = property;
 
                 object propertyValue = property.GetValue<object>();
                 if (propertyValue != null)
                 {
                     SerializableArray array = property.GetArray();
-                    newArrayField.Construct<InspectableArrayGUIRow>(title, false, array.GetLength(), layout);
+                    base.Update<InspectableArrayGUIRow>(title, false, array.GetLength(), layout);
                 }
                 else
-                    newArrayField.Construct<InspectableArrayGUIRow>(title, true, 0, layout);
-
-                return newArrayField;
+                    base.Update<InspectableArrayGUIRow>(title, true, 0, layout);
             }
 
             /// <inheritdoc/>

+ 11 - 16
MBansheeEditor/Inspector/InspectableList.cs

@@ -13,7 +13,7 @@ namespace BansheeEditor
     {
         private object propertyValue; // TODO - This will unnecessarily hold references to the object
         private int numArrayElements;
-        private InspectableListGUI listGUIField;
+        private InspectableListGUI listGUIField = new InspectableListGUI();
 
         /// <summary>
         /// Creates a new inspectable list GUI for the specified property.
@@ -78,7 +78,7 @@ namespace BansheeEditor
         {
             GUILayout arrayLayout = layout.AddLayoutY(layoutIndex);
 
-            listGUIField = InspectableListGUI.Create(title, property, arrayLayout);
+            listGUIField.Create(title, property, arrayLayout);
         }
 
         /// <inheritdoc/>
@@ -105,35 +105,30 @@ namespace BansheeEditor
             private SerializableProperty property;
 
             /// <summary>
-            /// Constructs an inspectable list GUI.
+            /// Constructs a new empty inspectable list GUI.
             /// </summary>
-            /// <param name="property">Serializable property referencing a list.</param>
-            private InspectableListGUI(SerializableProperty property)
-            {
-                this.property = property;
-            }
+            public InspectableListGUI()
+            { }
             
             /// <summary>
-            /// Creates a new inspectable GUI list.
+            /// Updates the contents of the inspectable GUI list. Must be called at least once in order for the contents 
+            /// to be populated.
             /// </summary>
             /// <param name="title">Label to display on the list GUI title.</param>
             /// <param name="property">Serializable property referencing a list.</param>
             /// <param name="layout">Layout to which to append the list GUI elements to.</param>
-            /// <returns>Newly created inspectable GUI list object.</returns>
-            public static InspectableListGUI Create(LocString title, SerializableProperty property, GUILayout layout)
+            public void Create(LocString title, SerializableProperty property, GUILayout layout)
             {
-                InspectableListGUI newArrayField = new InspectableListGUI(property);
+                this.property = property;
 
                 object propertyValue = property.GetValue<object>();
                 if (propertyValue != null)
                 {
                     SerializableList list = property.GetList();
-                    newArrayField.Construct<InspectableListGUIRow>(title, false, list.GetLength(), layout);
+                    base.Update<InspectableListGUIRow>(title, false, list.GetLength(), layout);
                 }
                 else
-                    newArrayField.Construct<InspectableListGUIRow>(title, true, 0, layout);
-
-                return newArrayField;
+                    base.Update<InspectableListGUIRow>(title, true, 0, layout);
             }
 
             /// <inheritdoc/>

+ 4 - 4
MBansheeEditor/Inspectors/FontInspector.cs

@@ -10,8 +10,8 @@ namespace BansheeEditor
     [CustomInspector(typeof(Font))]
     internal class FontInspector : Inspector
     {
-        private GUIArrayField fontSizes;
-        private GUIArrayField charRanges;
+        private GUIArrayField fontSizes = new GUIArrayField();
+        private GUIArrayField charRanges = new GUIArrayField();
         private GUIToggleField antialiasingField;
         private GUIIntField dpiField;
         private GUIButton reimportButton;
@@ -88,7 +88,7 @@ namespace BansheeEditor
         {
             layout.Clear();
 
-            fontSizes = GUIArrayField.Create<FontSizeArrayRow, int>(
+            fontSizes.Update<FontSizeArrayRow, int>(
                 new LocEdString("Font sizes"), importOptions.FontSizes, layout);
             fontSizes.OnChanged += x =>
             {
@@ -99,7 +99,7 @@ namespace BansheeEditor
                 Refresh();
             };
 
-            charRanges = GUIArrayField.Create<CharRangeArrayRow, CharRange>(
+            charRanges.Update<CharRangeArrayRow, CharRange>(
                 new LocEdString("Character ranges"), importOptions.CharRanges, layout);
             charRanges.OnChanged += x =>
             {

+ 2 - 2
MBansheeEditor/Inspectors/RenderableInspector.cs

@@ -12,7 +12,7 @@ namespace BansheeEditor
     {
         private GUIResourceField meshField;
         private GUIListBoxField layersField;
-        private GUIArrayField materialsField;
+        private GUIArrayField materialsField = new GUIArrayField();
         private List<MaterialParamGUI[]> materialParams = new List<MaterialParamGUI[]>();
 
         private ulong layersValue = 0;
@@ -115,7 +115,7 @@ namespace BansheeEditor
 
             layersValue = 0;
             materials = renderable.Materials;
-            materialsField = GUIArrayField.Create<MaterialArrayRow, Material>(new LocEdString("Materials"), materials, layout);
+            materialsField.Update<MaterialArrayRow, Material>(new LocEdString("Materials"), materials, layout);
 
             materialsField.OnChanged += x =>
             {