Browse Source

Rebuilding the GUI list or dictionary will now preserve existing rows

BearishSun 10 years ago
parent
commit
6987176cc0

+ 23 - 10
MBansheeEditor/GUI/GUIDictionaryField.cs

@@ -33,7 +33,7 @@ namespace BansheeEditor
         { }
 
         /// <summary>
-        /// Updates the GUI dictionary contents. Must be called at least once in order for the contents to be populated.
+        /// Builds the dictionary GUI elements. 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 dictionary elements.</typeparam>
         /// <param name="title">Label to display on the dictionary GUI title.</param>
@@ -43,7 +43,7 @@ namespace BansheeEditor
         /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
         ///                     nested containers whose backgrounds are overlaping. Also determines background style,
         ///                     depths divisible by two will use an alternate style.</param>
-        protected void Update<T>(LocString title, bool empty, int numRows, GUILayout layout,
+        protected void BuildGUI<T>(LocString title, bool empty, int numRows, GUILayout layout,
             int depth = 0) where T : GUIDictionaryFieldRow, new()
         {
             Destroy();
@@ -54,6 +54,8 @@ namespace BansheeEditor
 
             if (empty)
             {
+                rows.Clear();
+
                 guiChildLayout = null;
                 guiContentLayout = null;
                 guiTitleLayout = layout.AddLayoutX();
@@ -109,13 +111,18 @@ namespace BansheeEditor
 
                 // Hidden dependency: BuildGUI must be called after all elements are 
                 // in the dictionary so we do it in two steps
-                for (int i = 0; i < numRows; i++)
+                for (int i = rows.Count; i < numRows; i++)
                 {
                     GUIDictionaryFieldRow newRow = new T();
                     rows.Add(i, newRow);
                 }
 
-                editRow = new T();
+                for (int i = numRows; i < rows.Count; i++)
+                    rows.Remove(i);
+
+                if(editRow == null)
+                    editRow = new T();
+
                 editRow.BuildGUI(this, guiContentLayout, numRows, depth + 1);
                 editRow.Enabled = false;
 
@@ -178,8 +185,6 @@ namespace BansheeEditor
             for (int i = 0; i < rows.Count; i++)
                 rows[i].Destroy();
 
-            rows.Clear();
-
             if (editRow != null)
                 editRow.Destroy();
         }
@@ -623,7 +628,7 @@ namespace BansheeEditor
         { }
 
         /// <summary>
-        /// Updates the GUI dictionary contents. Must be called at least once in order for the contents to be populated.
+        /// Builds the dictionary GUI elements. 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 dictionary elements.</typeparam>
         /// <param name="title">Label to display on the list GUI title.</param>
@@ -632,7 +637,7 @@ namespace BansheeEditor
         /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
         ///                     nested containers whose backgrounds are overlaping. Also determines background style,
         ///                     depths divisible by two will use an alternate style.</param>
-        public void Update<RowType>(LocString title, Dictionary<Key, Value> dictionary, 
+        public void BuildGUI<RowType>(LocString title, Dictionary<Key, Value> dictionary, 
             GUILayout layout, int depth = 0)
             where RowType : GUIDictionaryFieldRow, new()
         {
@@ -640,9 +645,9 @@ namespace BansheeEditor
             UpdateKeys();
 
             if (dictionary != null)
-                base.Update<RowType>(title, false, dictionary.Count, layout, depth);
+                base.BuildGUI<RowType>(title, false, dictionary.Count, layout, depth);
             else
-                base.Update<RowType>(title, true, 0, layout, depth);
+                base.BuildGUI<RowType>(title, true, 0, layout, depth);
         }
 
         /// <summary>
@@ -958,6 +963,14 @@ namespace BansheeEditor
                 rowLayout.Destroy();
                 rowLayout = null;
             }
+
+            keyRowLayout = null;
+            keyLayout = null;
+            valueLayout = null;
+            titleLayout = null;
+            deleteBtn = null;
+            editBtn = null;
+            localTitleLayout = false;
         }
     }
 }

+ 17 - 15
MBansheeEditor/GUI/GUIListField.cs

@@ -27,7 +27,7 @@ namespace BansheeEditor
         { }
 
         /// <summary>
-        /// Updates the GUI list contents. Must be called at least once in order for the contents to be populated.
+        /// Builds the list GUI elements. 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>
@@ -37,7 +37,7 @@ namespace BansheeEditor
         /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
         ///                     nested containers whose backgrounds are overlaping. Also determines background style,
         ///                     depths divisible by two will use an alternate style.</param>
-        protected void Update<T>(LocString title, bool empty, int numRows, GUILayout layout, 
+        protected void BuildGUI<T>(LocString title, bool empty, int numRows, GUILayout layout, 
             int depth = 0) where T : GUIListFieldRow, new()
         {
             Destroy();
@@ -107,13 +107,17 @@ namespace BansheeEditor
                     GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                     backgroundPanel.AddElement(inspectorContentBg);
 
-                    for (int i = 0; i < numRows; i++)
+                    for (int i = rows.Count; i < numRows; i++)
                     {
                         GUIListFieldRow newRow = new T();
-                        newRow.BuildGUI(this, guiContentLayout, i, depth);
-
                         rows.Add(newRow);
                     }
+
+                    while (rows.Count > numRows)
+                        rows.RemoveAt(rows.Count - 1);
+
+                    for (int i = 0; i < numRows; i++)
+                        rows[i].BuildGUI(this, guiContentLayout, i, depth);
                 }
             }
         }
@@ -158,8 +162,6 @@ namespace BansheeEditor
 
             for (int i = 0; i < rows.Count; i++)
                 rows[i].Destroy();
-
-            rows.Clear();
         }
 
         /// <summary>
@@ -264,7 +266,7 @@ namespace BansheeEditor
         { }
 
         /// <summary>
-        /// Updates the GUI array contents. Must be called at least once in order for the contents to be populated.
+        /// Builds the array GUI elements. 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 array elements.</typeparam>
         /// <param name="title">Label to display on the array GUI title.</param>
@@ -273,15 +275,15 @@ namespace BansheeEditor
         /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
         ///                     nested containers whose backgrounds are overlaping. Also determines background style,
         ///                     depths divisible by two will use an alternate style.</param>
-        public void Update<RowType>(LocString title, ElementType[] array, GUILayout layout, int depth = 0) 
+        public void BuildGUI<RowType>(LocString title, ElementType[] array, GUILayout layout, int depth = 0) 
             where RowType : GUIListFieldRow, new() 
         {
             this.array = array;
 
             if (array != null)
-                base.Update<RowType>(title, false, array.Length, layout, depth);
+                base.BuildGUI<RowType>(title, false, array.Length, layout, depth);
             else
-                base.Update<RowType>(title, true, 0, layout, depth);
+                base.BuildGUI<RowType>(title, true, 0, layout, depth);
         }
 
         /// <inheritdoc/>
@@ -448,7 +450,7 @@ namespace BansheeEditor
         { }
 
         /// <summary>
-        /// Updates the GUI list contents. Must be called at least once in order for the contents to be populated.
+        /// Builds the list GUI elements. 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>
         /// <param name="title">Label to display on the list GUI title.</param>
@@ -457,15 +459,15 @@ namespace BansheeEditor
         /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
         ///                     nested containers whose backgrounds are overlaping. Also determines background style,
         ///                     depths divisible by two will use an alternate style.</param>
-        public void Update<RowType>(LocString title, List<ElementType> list, GUILayout layout, int depth = 0)
+        public void BuildGUI<RowType>(LocString title, List<ElementType> list, GUILayout layout, int depth = 0)
             where RowType : GUIListFieldRow, new()
         {
             this.list = list;
 
             if (list != null)
-                base.Update<RowType>(title, false, list.Count, layout, depth);
+                base.BuildGUI<RowType>(title, false, list.Count, layout, depth);
             else
-                base.Update<RowType>(title, true, 0, layout, depth);
+                base.BuildGUI<RowType>(title, true, 0, layout, depth);
         }
 
         /// <inheritdoc/>

+ 6 - 6
MBansheeEditor/Inspector/InspectableArray.cs

@@ -70,7 +70,7 @@ namespace BansheeEditor
         {
             GUILayout arrayLayout = layout.AddLayoutY(layoutIndex);
 
-            arrayGUIField.Update(title, property, arrayLayout, depth);
+            arrayGUIField.BuildGUI(title, property, arrayLayout, depth);
         }
 
         /// <inheritdoc/>
@@ -103,8 +103,8 @@ namespace BansheeEditor
             { }
 
             /// <summary>
-            /// Updates the contents of the inspectable GUI array. Must be called at least once in order for the contents 
-            /// to be populated.
+            /// Builds the inspectable array GUI elements. 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>
@@ -112,7 +112,7 @@ namespace BansheeEditor
             /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
             ///                     nested containers whose backgrounds are overlaping. Also determines background style,
             ///                     depths divisible by two will use an alternate style.</param>
-            public void Update(LocString title, SerializableProperty property, GUILayout layout, int depth)
+            public void BuildGUI(LocString title, SerializableProperty property, GUILayout layout, int depth)
             {
                 this.property = property;
 
@@ -120,10 +120,10 @@ namespace BansheeEditor
                 if (propertyValue != null)
                 {
                     SerializableArray array = property.GetArray();
-                    base.Update<InspectableArrayGUIRow>(title, false, array.GetLength(), layout, depth);
+                    base.BuildGUI<InspectableArrayGUIRow>(title, false, array.GetLength(), layout, depth);
                 }
                 else
-                    base.Update<InspectableArrayGUIRow>(title, true, 0, layout, depth);
+                    base.BuildGUI<InspectableArrayGUIRow>(title, true, 0, layout, depth);
             }
 
             /// <inheritdoc/>

+ 6 - 5
MBansheeEditor/Inspector/InspectableDictionary.cs

@@ -72,7 +72,7 @@ namespace BansheeEditor
         {
             GUILayout dictionaryLayout = layout.AddLayoutY(layoutIndex);
 
-            dictionaryGUIField.Update(title, property, dictionaryLayout, depth);
+            dictionaryGUIField.BuildGUI(title, property, dictionaryLayout, depth);
         }
 
         /// <inheritdoc/>
@@ -107,7 +107,8 @@ namespace BansheeEditor
             { }
 
             /// <summary>
-            /// Updates the GUI dictionary contents. Must be called at least once in order for the contents to be populated.
+            /// Builds the inspectable dictionary GUI elements. 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 dictionary</param>
@@ -115,7 +116,7 @@ namespace BansheeEditor
             /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
             ///                     nested containers whose backgrounds are overlaping. Also determines background style,
             ///                     depths divisible by two will use an alternate style.</param>
-            public void Update(LocString title, SerializableProperty property, GUILayout layout, int depth)
+            public void BuildGUI(LocString title, SerializableProperty property, GUILayout layout, int depth)
             {
                 this.property = property;
 
@@ -123,10 +124,10 @@ namespace BansheeEditor
                 if (propertyValue != null)
                 {
                     SerializableDictionary dictionary = property.GetDictionary();
-                    base.Update<InspectableDictionaryGUIRow>(title, false, dictionary.GetLength(), layout, depth);
+                    base.BuildGUI<InspectableDictionaryGUIRow>(title, false, dictionary.GetLength(), layout, depth);
                 }
                 else
-                    base.Update<InspectableDictionaryGUIRow>(title, true, 0, layout, depth);
+                    base.BuildGUI<InspectableDictionaryGUIRow>(title, true, 0, layout, depth);
 
                 UpdateKeys();
             }

+ 6 - 6
MBansheeEditor/Inspector/InspectableList.cs

@@ -72,7 +72,7 @@ namespace BansheeEditor
         {
             GUILayout arrayLayout = layout.AddLayoutY(layoutIndex);
 
-            listGUIField.Update(title, property, arrayLayout, depth);
+            listGUIField.BuildGUI(title, property, arrayLayout, depth);
         }
 
         /// <inheritdoc/>
@@ -105,8 +105,8 @@ namespace BansheeEditor
             { }
             
             /// <summary>
-            /// Updates the contents of the inspectable GUI list. Must be called at least once in order for the contents 
-            /// to be populated.
+            /// Builds the inspectable list GUI elements. 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>
@@ -114,7 +114,7 @@ namespace BansheeEditor
             /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
             ///                     nested containers whose backgrounds are overlaping. Also determines background style,
             ///                     depths divisible by two will use an alternate style.</param>
-            public void Update(LocString title, SerializableProperty property, GUILayout layout, int depth)
+            public void BuildGUI(LocString title, SerializableProperty property, GUILayout layout, int depth)
             {
                 this.property = property;
 
@@ -122,10 +122,10 @@ namespace BansheeEditor
                 if (propertyValue != null)
                 {
                     SerializableList list = property.GetList();
-                    base.Update<InspectableListGUIRow>(title, false, list.GetLength(), layout, depth);
+                    base.BuildGUI<InspectableListGUIRow>(title, false, list.GetLength(), layout, depth);
                 }
                 else
-                    base.Update<InspectableListGUIRow>(title, true, 0, layout, depth);
+                    base.BuildGUI<InspectableListGUIRow>(title, true, 0, layout, depth);
             }
 
             /// <inheritdoc/>

+ 2 - 2
MBansheeEditor/Inspectors/FontInspector.cs

@@ -75,7 +75,7 @@ namespace BansheeEditor
         {
             Layout.Clear();
 
-            fontSizes.Update<FontSizeArrayRow>(
+            fontSizes.BuildGUI<FontSizeArrayRow>(
                 new LocEdString("Font sizes"), importOptions.FontSizes, Layout);
             fontSizes.OnChanged += x =>
             {
@@ -86,7 +86,7 @@ namespace BansheeEditor
                 Refresh();
             };
 
-            charRanges.Update<CharRangeArrayRow>(
+            charRanges.BuildGUI<CharRangeArrayRow>(
                 new LocEdString("Character ranges"), importOptions.CharRanges, Layout);
             charRanges.OnChanged += x =>
             {

+ 2 - 1
MBansheeEditor/Inspectors/GUISkinInspector.cs

@@ -42,7 +42,7 @@ namespace BansheeEditor
             foreach (var styleName in styleNames)
                 styles[styleName] = guiSkin.GetStyle(styleName);
 
-            valuesField.Update<GUIElementStyleEntry>(new LocEdString("Styles"), styles, Layout);
+            valuesField.BuildGUI<GUIElementStyleEntry>(new LocEdString("Styles"), styles, Layout);
 
             valuesField.OnChanged += x =>
             {
@@ -269,6 +269,7 @@ namespace BansheeEditor
                 foldout.OnToggled += x =>
                 {
                     panel.Active = x;
+                    isExpanded = x;
                 };
 
                 fontField.OnChanged += x => style.Font = (Font)x;

+ 1 - 1
MBansheeEditor/Inspectors/RenderableInspector.cs

@@ -105,7 +105,7 @@ namespace BansheeEditor
 
             layersValue = 0;
             materials = renderable.Materials;
-            materialsField.Update<MaterialArrayRow>(new LocEdString("Materials"), materials, Layout);
+            materialsField.BuildGUI<MaterialArrayRow>(new LocEdString("Materials"), materials, Layout);
 
             materialsField.OnChanged += x =>
             {

+ 1 - 1
MBansheeEditor/Inspectors/StringTableInspector.cs

@@ -60,7 +60,7 @@ namespace BansheeEditor
 
             Layout.AddElement(languageField);
 
-            valuesField.Update<StringTableEntry>(new LocEdString("Strings"), strings, Layout);
+            valuesField.BuildGUI<StringTableEntry>(new LocEdString("Strings"), strings, Layout);
 
             valuesField.OnChanged += x =>
             {