Răsfoiți Sursa

Re-added alternating GUI array backgrounds

BearishSun 10 ani în urmă
părinte
comite
79e827cd27

+ 27 - 9
MBansheeEditor/GUI/GUIListField.cs

@@ -21,6 +21,7 @@ namespace BansheeEditor
         protected GUILayoutX guiTitleLayout;
         protected GUILayoutY guiContentLayout;
         protected bool isExpanded;
+        protected int depth;
 
         /// <summary>
         /// Constructs a new GUI list.
@@ -36,10 +37,16 @@ namespace BansheeEditor
         /// <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 Update<T>(LocString title, bool empty, int numRows, GUILayout layout) where T : GUIListFieldRow, new()
+        /// <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, 
+            int depth = 0) where T : GUIListFieldRow, new()
         {
             Destroy();
 
+            this.depth = depth;
+
             if (empty)
             {
                 guiChildLayout = null;
@@ -94,14 +101,19 @@ namespace BansheeEditor
                     guiIndentLayoutX.AddSpace(IndentAmount);
                     guiChildLayout.AddSpace(IndentAmount);
 
-                    GUIPanel backgroundPanel = guiContentPanel.AddPanel(Inspector.START_BACKGROUND_DEPTH);
-                    GUITexture inspectorContentBg = new GUITexture(null, EditorStyles.InspectorContentBg);
+                    short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
+                    string bgPanelStyle = depth % 2 == 0
+                        ? EditorStyles.InspectorContentBgAlternate
+                        : EditorStyles.InspectorContentBg;
+
+                    GUIPanel backgroundPanel = guiContentPanel.AddPanel(backgroundDepth);
+                    GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                     backgroundPanel.AddElement(inspectorContentBg);
 
                     for (int i = 0; i < numRows; i++)
                     {
                         GUIListFieldRow newRow = new T();
-                        newRow.BuildGUI(this, guiContentLayout, i);
+                        newRow.BuildGUI(this, guiContentLayout, i, depth);
 
                         rows.Add(newRow);
                     }
@@ -133,7 +145,7 @@ namespace BansheeEditor
                 anythingModified |= rows[i].Refresh(out updateGUI);
 
                 if (updateGUI)
-                    rows[i].BuildGUI(this, guiContentLayout, i);
+                    rows[i].BuildGUI(this, guiContentLayout, i, depth);
             }
 
             return anythingModified;
@@ -273,16 +285,19 @@ namespace BansheeEditor
         /// <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 void Update<RowType, ElementType>(LocString title, ElementType[] array, GUILayout layout) 
+        /// <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, ElementType>(LocString title, ElementType[] array, GUILayout layout, int depth = 0) 
             where RowType : GUIListFieldRow, new() 
         {
             this.arrayType = typeof(ElementType[]);
             this.array = array;
 
             if (array != null)
-                base.Update<RowType>(title, false, array.Length, layout);
+                base.Update<RowType>(title, false, array.Length, layout, depth);
             else
-                base.Update<RowType>(title, true, 0, layout);
+                base.Update<RowType>(title, true, 0, layout, depth);
         }
 
         /// <inheritdoc/>
@@ -443,6 +458,7 @@ namespace BansheeEditor
         private GUIListFieldBase parent;
 
         protected int seqIndex;
+        protected int depth;
 
         /// <summary>
         /// Constructs a new array row object.
@@ -458,10 +474,12 @@ namespace BansheeEditor
         /// <param name="parent">Parent array GUI object that the entry is contained in.</param>
         /// <param name="parentLayout">Parent layout that row GUI elements will be added to.</param>
         /// <param name="seqIndex">Sequential index of the array entry.</param>
-        public void BuildGUI(GUIListFieldBase parent, GUILayout parentLayout, int seqIndex)
+        /// <param name="depth">Determines the depth at which the element is rendered.</param>
+        public void BuildGUI(GUIListFieldBase parent, GUILayout parentLayout, int seqIndex, int depth)
         {
             this.parent = parent;
             this.seqIndex = seqIndex;
+            this.depth = depth;
 
             if (rowLayout == null)
                 rowLayout = parentLayout.AddLayoutX();

+ 8 - 5
MBansheeEditor/Inspector/InspectableArray.cs

@@ -76,7 +76,7 @@ namespace BansheeEditor
         {
             GUILayout arrayLayout = layout.AddLayoutY(layoutIndex);
 
-            arrayGUIField.Update(title, property, arrayLayout);
+            arrayGUIField.Update(title, property, arrayLayout, depth);
         }
 
         /// <inheritdoc/>
@@ -115,7 +115,10 @@ namespace BansheeEditor
             /// <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>
-            public void Update(LocString title, SerializableProperty property, GUILayout layout)
+            /// <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)
             {
                 this.property = property;
 
@@ -123,10 +126,10 @@ namespace BansheeEditor
                 if (propertyValue != null)
                 {
                     SerializableArray array = property.GetArray();
-                    base.Update<InspectableArrayGUIRow>(title, false, array.GetLength(), layout);
+                    base.Update<InspectableArrayGUIRow>(title, false, array.GetLength(), layout, depth);
                 }
                 else
-                    base.Update<InspectableArrayGUIRow>(title, true, 0, layout);
+                    base.Update<InspectableArrayGUIRow>(title, true, 0, layout, depth);
             }
 
             /// <inheritdoc/>
@@ -262,7 +265,7 @@ namespace BansheeEditor
                 {
                     SerializableProperty property = GetValue<SerializableProperty>();
 
-                    field = CreateInspectable(seqIndex + ".", 0, 0,
+                    field = CreateInspectable(seqIndex + ".", 0, depth + 1,
                         new InspectableFieldLayout(layout), property);
                 }
 

+ 8 - 5
MBansheeEditor/Inspector/InspectableList.cs

@@ -78,7 +78,7 @@ namespace BansheeEditor
         {
             GUILayout arrayLayout = layout.AddLayoutY(layoutIndex);
 
-            listGUIField.Create(title, property, arrayLayout);
+            listGUIField.Update(title, property, arrayLayout, depth);
         }
 
         /// <inheritdoc/>
@@ -117,7 +117,10 @@ namespace BansheeEditor
             /// <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>
-            public void Create(LocString title, SerializableProperty property, GUILayout layout)
+            /// <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)
             {
                 this.property = property;
 
@@ -125,10 +128,10 @@ namespace BansheeEditor
                 if (propertyValue != null)
                 {
                     SerializableList list = property.GetList();
-                    base.Update<InspectableListGUIRow>(title, false, list.GetLength(), layout);
+                    base.Update<InspectableListGUIRow>(title, false, list.GetLength(), layout, depth);
                 }
                 else
-                    base.Update<InspectableListGUIRow>(title, true, 0, layout);
+                    base.Update<InspectableListGUIRow>(title, true, 0, layout, depth);
             }
 
             /// <inheritdoc/>
@@ -235,7 +238,7 @@ namespace BansheeEditor
                 {
                     SerializableProperty property = GetValue<SerializableProperty>();
 
-                    field = CreateInspectable(seqIndex + ".", 0, 0,
+                    field = CreateInspectable(seqIndex + ".", 0, depth + 1,
                         new InspectableFieldLayout(layout), property);
                 }