Browse Source

No longer show GUI background for empty inspectors and complex objects

BearishSun 10 years ago
parent
commit
eaec84330f

+ 25 - 22
MBansheeEditor/GUI/GUIArray.cs

@@ -81,30 +81,33 @@ namespace BansheeEditor
 
                 guiSizeField.Value = list.Count;
 
-                guiChildLayout = layout.AddLayoutX();
-                guiChildLayout.AddSpace(IndentAmount);
-                guiChildLayout.Visible = isExpanded;
-
-                GUIPanel guiContentPanel = guiChildLayout.AddPanel();
-                GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
-                guiIndentLayoutX.AddSpace(IndentAmount);
-                GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
-                guiIndentLayoutY.AddSpace(IndentAmount);
-                GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
-                guiIndentLayoutY.AddSpace(IndentAmount);
-                guiIndentLayoutX.AddSpace(IndentAmount);
-                guiChildLayout.AddSpace(IndentAmount);
-
-                GUIPanel backgroundPanel = guiContentPanel.AddPanel(Inspector.START_BACKGROUND_DEPTH);
-                GUITexture inspectorContentBg = new GUITexture(null, EditorStyles.InspectorContentBg);
-                backgroundPanel.AddElement(inspectorContentBg);
-
-                for (int i = 0; i < list.Count; i++)
+                if (list.Count > 0)
                 {
-                    GUIListRow newRow = new T();
-                    newRow.Update(this, guiContentLayout, i);
+                    guiChildLayout = layout.AddLayoutX();
+                    guiChildLayout.AddSpace(IndentAmount);
+                    guiChildLayout.Visible = isExpanded;
+
+                    GUIPanel guiContentPanel = guiChildLayout.AddPanel();
+                    GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
+                    guiIndentLayoutX.AddSpace(IndentAmount);
+                    GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
+                    guiIndentLayoutY.AddSpace(IndentAmount);
+                    GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
+                    guiIndentLayoutY.AddSpace(IndentAmount);
+                    guiIndentLayoutX.AddSpace(IndentAmount);
+                    guiChildLayout.AddSpace(IndentAmount);
+
+                    GUIPanel backgroundPanel = guiContentPanel.AddPanel(Inspector.START_BACKGROUND_DEPTH);
+                    GUITexture inspectorContentBg = new GUITexture(null, EditorStyles.InspectorContentBg);
+                    backgroundPanel.AddElement(inspectorContentBg);
+
+                    for (int i = 0; i < list.Count; i++)
+                    {
+                        GUIListRow newRow = new T();
+                        newRow.Update(this, guiContentLayout, i);
 
-                    rows.Add(newRow);
+                        rows.Add(newRow);
+                    }
                 }
             }
         }

+ 8 - 1
MBansheeEditor/Inspector/GenericInspector.cs

@@ -14,6 +14,7 @@ namespace BansheeEditor
     internal sealed class GenericInspector : Inspector
     {
         private bool isInitialized;
+        private bool isEmpty = true;
         private List<InspectableField> inspectableFields = new List<InspectableField>();
 
         /// <summary>
@@ -24,13 +25,13 @@ namespace BansheeEditor
             if (referencedObject != null)
             {
                 SerializableObject serializableObject = new SerializableObject(referencedObject.GetType(), referencedObject);
-
                 foreach (var field in serializableObject.Fields)
                 {
                     if (!field.Inspectable)
                         continue;
 
                     inspectableFields.Add(InspectableField.CreateInspectable(field.Name, 0, new InspectableFieldLayout(layout), field.GetProperty()));
+                    isEmpty = false;
                 }
             }
 
@@ -54,5 +55,11 @@ namespace BansheeEditor
 
             return anythingModified;
         }
+
+        /// <inheritdoc/>
+        internal override void SetVisible(bool visible)
+        {
+            RootGUI.Visible = !isEmpty && visible;
+        }
     }
 }

+ 36 - 29
MBansheeEditor/Inspector/InspectableArray.cs

@@ -226,35 +226,42 @@ namespace BansheeEditor
 
                 if (isExpanded)
                 {
-                    guiChildLayout = layout.AddLayoutX(layoutIndex);
-                    guiChildLayout.AddSpace(IndentAmount);
-
-                    GUIPanel guiContentPanel = guiChildLayout.AddPanel();
-                    GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
-                    guiIndentLayoutX.AddSpace(IndentAmount);
-                    GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
-                    guiIndentLayoutY.AddSpace(IndentAmount);
-                    GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
-                    guiIndentLayoutY.AddSpace(IndentAmount);
-                    guiIndentLayoutX.AddSpace(IndentAmount);
-                    guiChildLayout.AddSpace(IndentAmount);
-
-                    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 < numArrayElements; i++)
-                    {
-                        EntryRow newRow = new EntryRow(guiContentLayout);
-                        rows.Add(newRow);
-
-                        InspectableField childObj = CreateInspectable(i + ".", depth + 1, new InspectableFieldLayout(newRow.contentLayout), array.GetProperty(i));
-                        AddChild(childObj);
-
-                        childObj.Refresh(0);
-                        rows[i].Refresh(childObj, i, this);
+                    if (numArrayElements > 0)
+                    { 
+                        guiChildLayout = layout.AddLayoutX(layoutIndex);
+                        guiChildLayout.AddSpace(IndentAmount);
+
+                        GUIPanel guiContentPanel = guiChildLayout.AddPanel();
+                        GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
+                        guiIndentLayoutX.AddSpace(IndentAmount);
+                        GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
+                        guiIndentLayoutY.AddSpace(IndentAmount);
+                        GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
+                        guiIndentLayoutY.AddSpace(IndentAmount);
+                        guiIndentLayoutX.AddSpace(IndentAmount);
+                        guiChildLayout.AddSpace(IndentAmount);
+
+                        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 < numArrayElements; i++)
+                        {
+                            EntryRow newRow = new EntryRow(guiContentLayout);
+                            rows.Add(newRow);
+
+                            InspectableField childObj = CreateInspectable(i + ".", depth + 1, 
+                                new InspectableFieldLayout(newRow.contentLayout), array.GetProperty(i));
+                            AddChild(childObj);
+
+                            childObj.Refresh(0);
+                            rows[i].Refresh(childObj, i, this);
+                        }
                     }
                 }
                 else

+ 35 - 28
MBansheeEditor/Inspector/InspectableList.cs

@@ -226,35 +226,42 @@ namespace BansheeEditor
 
                 if (isExpanded)
                 {
-                    guiChildLayout = layout.AddLayoutX(layoutIndex);
-                    guiChildLayout.AddSpace(IndentAmount);
-
-                    GUIPanel guiContentPanel = guiChildLayout.AddPanel();
-                    GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
-                    guiIndentLayoutX.AddSpace(IndentAmount);
-                    GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
-                    guiIndentLayoutY.AddSpace(IndentAmount);
-                    GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
-                    guiIndentLayoutY.AddSpace(IndentAmount);
-                    guiIndentLayoutX.AddSpace(IndentAmount);
-                    guiChildLayout.AddSpace(IndentAmount);
-
-                    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 < numArrayElements; i++)
+                    if (numArrayElements > 0)
                     {
-                        EntryRow newRow = new EntryRow(guiContentLayout);
-                        rows.Add(newRow);
-
-                        InspectableField childObj = CreateInspectable(i + ".", depth + 1, new InspectableFieldLayout(newRow.contentLayout), list.GetProperty(i));
-                        AddChild(childObj);
-
-                        childObj.Refresh(0);
-                        rows[i].Refresh(childObj, i, this);
+                        guiChildLayout = layout.AddLayoutX(layoutIndex);
+                        guiChildLayout.AddSpace(IndentAmount);
+
+                        GUIPanel guiContentPanel = guiChildLayout.AddPanel();
+                        GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
+                        guiIndentLayoutX.AddSpace(IndentAmount);
+                        GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
+                        guiIndentLayoutY.AddSpace(IndentAmount);
+                        GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
+                        guiIndentLayoutY.AddSpace(IndentAmount);
+                        guiIndentLayoutX.AddSpace(IndentAmount);
+                        guiChildLayout.AddSpace(IndentAmount);
+
+                        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 < numArrayElements; i++)
+                        {
+                            EntryRow newRow = new EntryRow(guiContentLayout);
+                            rows.Add(newRow);
+
+                            InspectableField childObj = CreateInspectable(i + ".", depth + 1,
+                                new InspectableFieldLayout(newRow.contentLayout), list.GetProperty(i));
+                            AddChild(childObj);
+
+                            childObj.Refresh(0);
+                            rows[i].Refresh(childObj, i, this);
+                        }
                     }
                 }
                 else

+ 30 - 25
MBansheeEditor/Inspector/InspectableObject.cs

@@ -103,32 +103,37 @@ namespace BansheeEditor
 
                 if (isExpanded)
                 {
-                    guiChildLayout = layout.AddLayoutX(index);
-                    guiChildLayout.AddSpace(IndentAmount);
-
-                    GUIPanel guiContentPanel = guiChildLayout.AddPanel();
-                    GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
-                    guiIndentLayoutX.AddSpace(IndentAmount);
-                    GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
-                    guiIndentLayoutY.AddSpace(IndentAmount);
-                    GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
-                    guiIndentLayoutY.AddSpace(IndentAmount);
-                    guiIndentLayoutX.AddSpace(IndentAmount);
-                    guiChildLayout.AddSpace(IndentAmount);
-
-                    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);
-
                     SerializableObject serializableObject = property.GetObject();
-                    foreach (var field in serializableObject.Fields)
-                    {
-                        if (!field.Inspectable)
-                            continue;
-
-                        AddChild(CreateInspectable(field.Name, depth + 1, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
+                    SerializableField[] fields = serializableObject.Fields;
+
+                    if (fields.Length > 0)
+                    { 
+                        guiChildLayout = layout.AddLayoutX(index);
+                        guiChildLayout.AddSpace(IndentAmount);
+
+                        GUIPanel guiContentPanel = guiChildLayout.AddPanel();
+                        GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
+                        guiIndentLayoutX.AddSpace(IndentAmount);
+                        GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
+                        guiIndentLayoutY.AddSpace(IndentAmount);
+                        GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
+                        guiIndentLayoutY.AddSpace(IndentAmount);
+                        guiIndentLayoutX.AddSpace(IndentAmount);
+                        guiChildLayout.AddSpace(IndentAmount);
+
+                        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);
+
+                        foreach (var field in fields)
+                        {
+                            if (!field.Inspectable)
+                                continue;
+
+                            AddChild(CreateInspectable(field.Name, depth + 1, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
+                        }
                     }
                 }
                 else

+ 1 - 1
MBansheeEditor/Inspector/Inspector.cs

@@ -13,11 +13,11 @@ namespace BansheeEditor
     {
         public const short START_BACKGROUND_DEPTH = 50;
 
+        protected GUIPanel RootGUI;
         protected GUIPanel GUI;
         protected GUILayoutY layout;
         protected object referencedObject;
 
-        private GUIPanel RootGUI;
         private InspectorWindow parentWindow;
 
         /// <summary>

+ 2 - 3
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -161,6 +161,7 @@ namespace BansheeEditor
             inspectorScrollArea = new GUIScrollArea();
             scrollAreaHighlight = new GUITexture(Builtin.WhiteTexture);
             scrollAreaHighlight.SetTint(HIGHLIGHT_COLOR);
+            scrollAreaHighlight.Visible = false;
 
             GUI.AddElement(inspectorScrollArea);
             GUIPanel inspectorPanel = inspectorScrollArea.Layout.AddPanel();
@@ -191,6 +192,7 @@ namespace BansheeEditor
                 data.panel = inspectorLayout.AddPanel();
                 data.inspector = InspectorUtility.GetInspector(allComponents[i].GetType());
                 data.inspector.Initialize(this, data.panel, allComponents[i]);
+                data.inspector.SetVisible(true);
                 data.foldout.Value = true;
 
                 Type curComponentType = allComponents[i].GetType();
@@ -731,12 +733,9 @@ namespace BansheeEditor
             {
                 dropAreas[i] = new Rect2I(0, yOffset, contentBounds.width, COMPONENT_SPACING);
                 yOffset += inspectorComponents[i].title.Bounds.height + inspectorComponents[i].panel.Bounds.height + COMPONENT_SPACING;
-
-                Debug.Log(i + ". " + dropAreas[i]);
             }
 
             dropAreas[dropAreas.Length - 1] = new Rect2I(0, yOffset, contentBounds.width, contentBounds.height - yOffset);
-            Debug.Log((dropAreas.Length - 1) + ". " + dropAreas[dropAreas.Length - 1]);
         }
     }
 }

+ 1 - 0
MBansheeEditor/Inspectors/RenderableInspector.cs

@@ -36,6 +36,7 @@ namespace BansheeEditor
             layout.AddElement(meshField);
             layout.AddElement(layersField);
 
+            layersValue = 0;
             materials = renderable.Materials;
             materialsField = GUIArray.Create<MaterialArrayRow, Material>(new LocEdString("Materials"), materials, layout);