Browse Source

Refactor: Added specialized inspector area for resource previews and extended SpriteTextureInspector to use it

BearishSun 6 years ago
parent
commit
17802c9b07

+ 3 - 2
Source/EditorManaged/Inspectors/SpriteTextureInspector.cs

@@ -35,14 +35,15 @@ namespace bs.Editor
 
 
             genericDrawer = new GenericInspectorDrawer(spriteTexture, this, Layout);
             genericDrawer = new GenericInspectorDrawer(spriteTexture, this, Layout);
 
 
-            previewTitleLayout = GUILayoutWithBackground.Create<GUILayoutX>(Layout, Builtin.WhiteTexture,
+            GUILayout previewLayout = PreviewGUI.AddLayoutY();
+            previewTitleLayout = GUILayoutWithBackground.Create<GUILayoutX>(previewLayout, Builtin.WhiteTexture,
                 new Color(0.129f, 0.129f, 0.129f), new RectOffset(11, 0, 2, 0));
                 new Color(0.129f, 0.129f, 0.129f), new RectOffset(11, 0, 2, 0));
 
 
             GUILabel title = new GUILabel(new LocEdString("Preview"));
             GUILabel title = new GUILabel(new LocEdString("Preview"));
             previewTitleLayout.Layout.AddElement(title);
             previewTitleLayout.Layout.AddElement(title);
             previewTitleLayout.Layout.AddFlexibleSpace();
             previewTitleLayout.Layout.AddFlexibleSpace();
 
 
-            previewContentLayout = GUILayoutWithBackground.Create<GUILayoutX>(Layout, Builtin.WhiteTexture,
+            previewContentLayout = GUILayoutWithBackground.Create<GUILayoutX>(previewLayout, Builtin.WhiteTexture,
                 new Color(0.09f, 0.09f, 0.09f), new RectOffset(5, 5, 5, 5));
                 new Color(0.09f, 0.09f, 0.09f), new RectOffset(5, 5, 5, 5));
 
 
             previewContentLayout.MainPanel.SetHeight(250);
             previewContentLayout.MainPanel.SetHeight(250);

+ 25 - 9
Source/EditorManaged/Windows/Inspector/Inspector.cs

@@ -32,6 +32,15 @@ namespace bs.Editor
             get { return mainPanel; }
             get { return mainPanel; }
         }
         }
 
 
+        /// <summary>
+        /// Returns the secondary GUI panel. Located at the bottom of the inspector window and unlike <see cref="GUI"/> has
+        /// no padding or styling applied. Only available when inspecting resources.
+        /// </summary>
+        protected GUIPanel PreviewGUI
+        {
+            get { return previewPanel; }
+        }
+
         /// <summary>
         /// <summary>
         /// Returns the object the inspector is currently displaying. If the current object is a resource use
         /// Returns the object the inspector is currently displaying. If the current object is a resource use
         /// <see cref="InspectedResourcePath"/> instead;
         /// <see cref="InspectedResourcePath"/> instead;
@@ -60,6 +69,7 @@ namespace bs.Editor
 
 
         private GUIPanel rootGUI;
         private GUIPanel rootGUI;
         private GUIPanel mainPanel;
         private GUIPanel mainPanel;
+        private GUIPanel previewPanel;
         private GUILayoutY layout;
         private GUILayoutY layout;
         private object inspectedObject;
         private object inspectedObject;
         private string inspectedResourcePath;
         private string inspectedResourcePath;
@@ -68,15 +78,17 @@ namespace bs.Editor
         /// <summary>
         /// <summary>
         /// Common code called by both Initialize() overloads.
         /// Common code called by both Initialize() overloads.
         /// </summary>
         /// </summary>
-        /// <param name="gui">GUI panel to add the GUI elements to.</param>
+        /// <param name="mainGui">Primary GUI panel to add the GUI elements to.</param>
+        /// <param name="previewGui">Secondary GUI panel located at the bottom of the inspector window, aimed primarily for
+        /// resource previews, but can be used for any purpose.</param>
         /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even 
         /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even 
         ///                          after the inspector is closed and restored when it is re-opened.</param>
         ///                          after the inspector is closed and restored when it is re-opened.</param>
-        private void InitializeBase(GUIPanel gui, SerializableProperties persistent)
+        private void InitializeBase(GUIPanel mainGui, GUIPanel previewGui, SerializableProperties persistent)
         {
         {
-            rootGUI = gui;
+            rootGUI = mainGui;
             this.persistent = persistent;
             this.persistent = persistent;
 
 
-            GUILayout contentLayoutX = gui.AddLayoutX();
+            GUILayout contentLayoutX = mainGui.AddLayoutX();
             contentLayoutX.AddSpace(5);
             contentLayoutX.AddSpace(5);
             GUILayout contentLayoutY = contentLayoutX.AddLayoutY();
             GUILayout contentLayoutY = contentLayoutX.AddLayoutY();
             contentLayoutY.AddSpace(5);
             contentLayoutY.AddSpace(5);
@@ -84,11 +96,12 @@ namespace bs.Editor
             contentLayoutY.AddSpace(5);
             contentLayoutY.AddSpace(5);
             contentLayoutX.AddSpace(5);
             contentLayoutX.AddSpace(5);
 
 
-            GUIPanel backgroundPanel = gui.AddPanel(START_BACKGROUND_DEPTH);
+            GUIPanel backgroundPanel = mainGui.AddPanel(START_BACKGROUND_DEPTH);
             GUITexture inspectorContentBg = new GUITexture(null, EditorStylesInternal.InspectorContentBg);
             GUITexture inspectorContentBg = new GUITexture(null, EditorStylesInternal.InspectorContentBg);
             backgroundPanel.AddElement(inspectorContentBg);
             backgroundPanel.AddElement(inspectorContentBg);
 
 
             mainPanel = contentPanel;
             mainPanel = contentPanel;
+            previewPanel = previewGui;
             layout = GUI.AddLayoutY();
             layout = GUI.AddLayoutY();
         }
         }
 
 
@@ -101,7 +114,7 @@ namespace bs.Editor
         ///                          after the inspector is closed and restored when it is re-opened.</param>
         ///                          after the inspector is closed and restored when it is re-opened.</param>
         internal virtual void Initialize(GUIPanel gui, object instance, SerializableProperties persistent)
         internal virtual void Initialize(GUIPanel gui, object instance, SerializableProperties persistent)
         {
         {
-            InitializeBase(gui, persistent);
+            InitializeBase(gui, null, persistent);
 
 
             inspectedObject = instance;
             inspectedObject = instance;
 
 
@@ -112,13 +125,16 @@ namespace bs.Editor
         /// <summary>
         /// <summary>
         /// Initializes the inspector using a resource path. Must be called after construction.
         /// Initializes the inspector using a resource path. Must be called after construction.
         /// </summary>
         /// </summary>
-        /// <param name="gui">GUI panel to add the GUI elements to.</param>
+        /// <param name="mainGui">Primary GUI panel to add the GUI elements to.</param>
+        /// <param name="previewGui">Secondary GUI panel located at the bottom of the inspector window, aimed primarily for
+        /// resource previews, but can be used for any purpose.</param>
         /// <param name="path">Path to the resource for which to display GUI for.</param>
         /// <param name="path">Path to the resource for which to display GUI for.</param>
         /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even 
         /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even 
         ///                          after the inspector is closed and restored when it is re-opened.</param>
         ///                          after the inspector is closed and restored when it is re-opened.</param>
-        internal virtual void Initialize(GUIPanel gui, string path, SerializableProperties persistent)
+        internal virtual void Initialize(GUIPanel mainGui, GUIPanel previewGui, string path, 
+            SerializableProperties persistent)
         {
         {
-            InitializeBase(gui, persistent);
+            InitializeBase(mainGui, previewGui, persistent);
 
 
             inspectedResourcePath = path;
             inspectedResourcePath = path;
 
 

+ 8 - 6
Source/EditorManaged/Windows/Inspector/InspectorWindow.cs

@@ -47,7 +47,8 @@ namespace bs.Editor
         /// </summary>
         /// </summary>
         private class InspectorResource
         private class InspectorResource
         {
         {
-            public GUIPanel panel;
+            public GUIPanel mainPanel;
+            public GUIPanel previewPanel;
             public Inspector inspector;
             public Inspector inspector;
         }
         }
 
 
@@ -105,7 +106,7 @@ namespace bs.Editor
         /// Sets a resource whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
         /// Sets a resource whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
         /// </summary>
         /// </summary>
         /// <param name="resourcePath">Resource path relative to the project of the resource to inspect.</param>
         /// <param name="resourcePath">Resource path relative to the project of the resource to inspect.</param>
-        private void SetObjectToInspect(String resourcePath)
+        private void SetObjectToInspect(string resourcePath)
         {
         {
             activeResourcePath = resourcePath;
             activeResourcePath = resourcePath;
             if (!ProjectLibrary.Exists(resourcePath))
             if (!ProjectLibrary.Exists(resourcePath))
@@ -148,14 +149,15 @@ namespace bs.Editor
             inspectorLayout.AddSpace(COMPONENT_SPACING);
             inspectorLayout.AddSpace(COMPONENT_SPACING);
 
 
             inspectorResource = new InspectorResource();
             inspectorResource = new InspectorResource();
-            inspectorResource.panel = inspectorLayout.AddPanel();
+            inspectorResource.mainPanel = inspectorLayout.AddPanel();
+            inspectorLayout.AddFlexibleSpace();
+            inspectorResource.previewPanel = inspectorLayout.AddPanel();
 
 
             var persistentProperties = persistentData.GetProperties(meta.UUID.ToString());
             var persistentProperties = persistentData.GetProperties(meta.UUID.ToString());
 
 
             inspectorResource.inspector = InspectorUtility.GetInspector(resourceType);
             inspectorResource.inspector = InspectorUtility.GetInspector(resourceType);
-            inspectorResource.inspector.Initialize(inspectorResource.panel, activeResourcePath, persistentProperties);
-
-            inspectorLayout.AddFlexibleSpace();
+            inspectorResource.inspector.Initialize(inspectorResource.mainPanel, inspectorResource.previewPanel,
+                activeResourcePath, persistentProperties);
         }
         }
 
 
         /// <summary>
         /// <summary>