Explorar el Código

More work on console

BearishSun hace 10 años
padre
commit
141adbbbbb

+ 3 - 7
BansheeEditor/Include/BsBuiltinEditorResources.h

@@ -42,8 +42,8 @@ namespace BansheeEngine
 	};
 
 	/**
-	* @brief	Types of icons that may be displayed in the library window.
-	*/
+	 * @brief	Types of icons that may be displayed in the library window.
+	 */
 	enum class LibraryWindowIcon
 	{
 		Home, Up, Clear, Options
@@ -173,7 +173,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Retrieves an icon that represents a specific log message type.
 		 */
-		HSpriteTexture getLogMessageIcon(LogMessageIcon icon) const;
+		HSpriteTexture getLogMessageIcon(LogMessageIcon icon, UINT32 size) const;
 
 		/**
 		 * @brief	Returns text contained in the default "empty" shader.
@@ -290,10 +290,6 @@ namespace BansheeEngine
 		static const WString PrefabIconTex;
 		static const WString GUISkinIconTex;
 
-		static const WString LogInfoIconTex;
-		static const WString LogWarningIconTex;
-		static const WString LogErrorIconTex;
-
 		static const WString WindowBackgroundTex;
 
 		static const WString WindowFrameNormal;

+ 23 - 12
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -102,10 +102,6 @@ namespace BansheeEngine
 	const WString BuiltinEditorResources::PrefabIconTex = L"PrefabIcon.psd";
 	const WString BuiltinEditorResources::GUISkinIconTex = L"GUISkinIcon.psd";
 
-	const WString BuiltinEditorResources::LogInfoIconTex = L"IconInfo.psd";
-	const WString BuiltinEditorResources::LogWarningIconTex = L"IconWarning.psd";
-	const WString BuiltinEditorResources::LogErrorIconTex = L"IconError.psd";
-
 	const WString BuiltinEditorResources::ButtonNormalTex = L"ButtonNormal.png";
 	const WString BuiltinEditorResources::ButtonHoverTex = L"ButtonHover.png";
 	const WString BuiltinEditorResources::ButtonActiveTex = L"ButtonActive.png";
@@ -2137,16 +2133,31 @@ namespace BansheeEngine
 		return HSpriteTexture();
 	}
 
-	HSpriteTexture BuiltinEditorResources::getLogMessageIcon(LogMessageIcon icon) const
+	HSpriteTexture BuiltinEditorResources::getLogMessageIcon(LogMessageIcon icon, UINT32 size) const
 	{
-		switch (icon)
+		if (size < 24) // Round to 16
+		{
+			switch (icon)
+			{
+			case LogMessageIcon::Info:
+				return getGUIIcon(L"IconInfo.psd");
+			case LogMessageIcon::Warning:
+				return getGUIIcon(L"IconWarning.psd");
+			case LogMessageIcon::Error:
+				return getGUIIcon(L"IconError.psd");
+			}
+		}
+		else // Round to 32
 		{
-		case LogMessageIcon::Info:
-			return getGUIIcon(LogInfoIconTex);
-		case LogMessageIcon::Warning:
-			return getGUIIcon(LogWarningIconTex);
-		case LogMessageIcon::Error:
-			return getGUIIcon(LogErrorIconTex);
+			switch (icon)
+			{
+			case LogMessageIcon::Info:
+				return getGUIIcon(L"IconInfo32.psd");
+			case LogMessageIcon::Warning:
+				return getGUIIcon(L"IconWarning32.psd");
+			case LogMessageIcon::Error:
+				return getGUIIcon(L"IconError32.psd");
+			}
 		}
 
 		return HSpriteTexture();

+ 3 - 3
BansheeEditor/Source/BsGUIStatusBar.cpp

@@ -149,14 +149,14 @@ namespace BansheeEngine
 		switch (logChannel)
 		{
 		case (UINT32)DebugChannel::Debug:
-			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Info);
+			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Info, 16);
 			break;
 		case (UINT32)DebugChannel::Warning:
-			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Warning);
+			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Warning, 16);
 			textColor = COLOR_WARNING;
 			break;
 		case (UINT32)DebugChannel::Error:
-			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Error);
+			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Error, 16);
 			textColor = COLOR_ERROR;
 			break;
 		}

+ 159 - 14
MBansheeEditor/ConsoleWindow.cs

@@ -20,12 +20,16 @@ namespace BansheeEditor
             Info = 0x01, Warning = 0x02, Error = 0x04, All = Info | Warning | Error
         }
 
-        private const int ENTRY_HEIGHT = 33;
+        private const int TITLE_HEIGHT = 21;
+        private const int ENTRY_HEIGHT = 39;
         private static int sSelectedElementIdx = -1;
 
         private GUIListView<ConsoleGUIEntry, ConsoleEntryData> listView;
         private List<ConsoleEntryData> entries = new List<ConsoleEntryData>();
+        private List<ConsoleEntryData> filteredEntries = new List<ConsoleEntryData>();
         private EntryFilter filter = EntryFilter.All;
+        private GUIScrollArea detailsArea;
+        private int dbg_disable = 0;
 
         /// <summary>
         /// Opens the console window.
@@ -47,18 +51,64 @@ namespace BansheeEditor
             Width = 300;
 
             GUILayoutY layout = GUI.AddLayoutY();
+            GUILayoutX titleLayout = layout.AddLayoutX();
 
-            listView = new GUIListView<ConsoleGUIEntry, ConsoleEntryData>(Width, Height, ENTRY_HEIGHT, layout);
+            GUIToggle infoBtn = new GUIToggle(new GUIContent(EditorBuiltin.GetLogIcon(LogIcon.Info, 16)), EditorStyles.Button);
+            GUIToggle warningBtn = new GUIToggle(new GUIContent(EditorBuiltin.GetLogIcon(LogIcon.Warning, 16)), EditorStyles.Button);
+            GUIToggle errorBtn = new GUIToggle(new GUIContent(EditorBuiltin.GetLogIcon(LogIcon.Error, 16)), EditorStyles.Button);
 
-            Debug.OnAdded += OnEntryAdded;
+            GUIToggle detailsBtn = new GUIToggle(new LocEdString("Show details"), EditorStyles.Button);
+            GUIButton clearBtn = new GUIButton(new LocEdString("Clear"));
+
+            titleLayout.AddElement(infoBtn);
+            titleLayout.AddElement(warningBtn);
+            titleLayout.AddElement(errorBtn);
+            titleLayout.AddFlexibleSpace();
+            titleLayout.AddElement(detailsBtn);
+            titleLayout.AddElement(clearBtn);
+
+            infoBtn.Value = filter.HasFlag(EntryFilter.Info);
+            warningBtn.Value = filter.HasFlag(EntryFilter.Warning);
+            errorBtn.Value = filter.HasFlag(EntryFilter.Error);
+
+            infoBtn.OnToggled += x =>
+            {
+                if (x) 
+                    SetFilter(filter | EntryFilter.Info);
+                else 
+                    SetFilter(filter & ~EntryFilter.Info);
+            };
+
+            warningBtn.OnToggled += x =>
+            {
+                if (x)
+                    SetFilter(filter | EntryFilter.Warning);
+                else
+                    SetFilter(filter & ~EntryFilter.Warning);
+            };
+
+            errorBtn.OnToggled += x =>
+            {
+                if (x)
+                    SetFilter(filter | EntryFilter.Error);
+                else
+                    SetFilter(filter & ~EntryFilter.Error);
+            };
+
+            detailsBtn.OnToggled += ToggleDetailsPanel;
+            clearBtn.OnClick += Clear;
+
+            GUILayoutX mainLayout = layout.AddLayoutX();
 
-            // TODO - Add buttons to filter info/warning/error
-            // TODO - Add button to clear console
-            // TODO - Add button that splits the window vertically and displays details about an entry + callstack
-            // TODO - On entry double-click open VS at that line
-            // TODO - On callstack entry double-click open VS at that line
+            listView = new GUIListView<ConsoleGUIEntry, ConsoleEntryData>(Width, Height - TITLE_HEIGHT, ENTRY_HEIGHT, mainLayout);
 
+            detailsArea = new GUIScrollArea();
+            mainLayout.AddElement(detailsArea);
+            detailsArea.Active = false;
 
+            Debug.OnAdded += OnEntryAdded;
+
+            // DEBUG ONLY
             for (int i = 0; i < 10; i++)
                 Debug.Log("DUMMY ENTRY #" + i);
         }
@@ -66,6 +116,8 @@ namespace BansheeEditor
         private void OnEditorUpdate()
         {
             listView.Update();
+
+            dbg_disable++;
         }
 
         private void OnDestroy()
@@ -88,6 +140,9 @@ namespace BansheeEditor
         /// <param name="message">Message string.</param>
         private void OnEntryAdded(DebugMessageType type, string message)
         {
+            if (dbg_disable > 1)
+                return;
+
             // Check if compiler message, otherwise parse it normally
             LogEntryData logEntry = ScriptCodeManager.ParseCompilerMessage(message);
             if (logEntry == null)
@@ -99,9 +154,12 @@ namespace BansheeEditor
             newEntry.message = logEntry.message;
 
             entries.Add(newEntry);
-
+            
             if (DoesFilterMatch(type))
+            {
                 listView.AddEntry(newEntry);
+                filteredEntries.Add(newEntry);
+            }
         }
 
         /// <summary>
@@ -113,14 +171,20 @@ namespace BansheeEditor
             if (this.filter == filter)
                 return;
 
+            this.filter = filter;
+
             listView.Clear();
+            filteredEntries.Clear();
             foreach (var entry in entries)
             {
                 if (DoesFilterMatch(entry.type))
+                {
                     listView.AddEntry(entry);
+                    filteredEntries.Add(entry);
+                }
             }
 
-            this.filter = filter;
+            sSelectedElementIdx = -1;
         }
 
         /// <summary>
@@ -151,6 +215,60 @@ namespace BansheeEditor
         {
             listView.Clear();
             entries.Clear();
+            filteredEntries.Clear();
+
+            sSelectedElementIdx = -1;
+        }
+
+        /// <summary>
+        /// Shows or hides the details panel.
+        /// </summary>
+        /// <param name="show">True to show, false to hide.</param>
+        private void ToggleDetailsPanel(bool show)
+        {
+            detailsArea.Active = show;
+
+            if (show)
+                RefreshDetailsPanel();
+        }
+
+        /// <summary>
+        /// Updates the contents of the details panel according to the currently selected element.
+        /// </summary>
+        private void RefreshDetailsPanel()
+        {
+            detailsArea.Layout.Clear();
+
+            if (sSelectedElementIdx != -1)
+            {
+                ConsoleEntryData entry = filteredEntries[sSelectedElementIdx];
+
+                LocString message = new LocEdString(entry.message);
+                GUILabel messageLabel = new GUILabel(message);
+                detailsArea.Layout.AddElement(messageLabel);
+                detailsArea.Layout.AddSpace(10);
+
+                if (entry.callstack != null)
+                {
+                    foreach (var call in entry.callstack)
+                    {
+                        string callMessage;
+                        if (string.IsNullOrEmpty(call.method))
+                            callMessage = "\tat " + call.file + ":" + call.line;
+                        else
+                            callMessage = "\t" + call.method + " at " + call.file + ":" + call.line;
+
+                        GUIButton callBtn = new GUIButton(new LocEdString(callMessage));
+                        detailsArea.Layout.AddElement(callBtn);
+
+                        CallStackEntry hoistedCall = call;
+                        callBtn.OnClick += () =>
+                        {
+                            CodeEditor.OpenFile(hoistedCall.file, hoistedCall.line);
+                        };
+                    }
+                }
+            }
         }
 
         /// <summary>
@@ -169,7 +287,8 @@ namespace BansheeEditor
         private class ConsoleGUIEntry : GUIListViewEntry<ConsoleEntryData>
         {
             private const int CALLER_LABEL_HEIGHT = 11;
-            private const int MESSAGE_HEIGHT = ENTRY_HEIGHT - CALLER_LABEL_HEIGHT;
+            private const int PADDING = 3;
+            private const int MESSAGE_HEIGHT = ENTRY_HEIGHT - CALLER_LABEL_HEIGHT - PADDING * 2;
             private static readonly Color BG_COLOR = Color.DarkGray;
             private static readonly Color SELECTION_COLOR = Color.DarkCyan;
 
@@ -177,6 +296,7 @@ namespace BansheeEditor
             private GUIPanel main;
             private GUIPanel underlay;
 
+            private GUITexture icon;
             private GUILabel messageLabel;
             private GUILabel functionLabel;
             private GUITexture background;
@@ -192,15 +312,24 @@ namespace BansheeEditor
                 overlay = main.AddPanel(-1, 0, 0, GUIOption.FixedHeight(ENTRY_HEIGHT));
                 underlay = main.AddPanel(1, 0, 0, GUIOption.FixedHeight(ENTRY_HEIGHT));
 
-                GUILayoutY mainLayout = main.AddLayoutY();
+                GUILayoutX mainLayout = main.AddLayoutX();
                 GUILayoutY overlayLayout = overlay.AddLayoutY();
                 GUILayoutY underlayLayout = underlay.AddLayoutY();
 
+                icon = new GUITexture(null);
                 messageLabel = new GUILabel(new LocEdString(""), EditorStyles.MultiLineLabel, GUIOption.FixedHeight(MESSAGE_HEIGHT));
                 functionLabel = new GUILabel(new LocEdString(""), GUIOption.FixedHeight(CALLER_LABEL_HEIGHT));
 
-                mainLayout.AddElement(messageLabel);
-                mainLayout.AddElement(functionLabel);
+                GUILayoutY iconLayout = mainLayout.AddLayoutY();
+                mainLayout.AddSpace(PADDING);
+                iconLayout.AddFlexibleSpace();
+                iconLayout.AddElement(icon);
+                iconLayout.AddFlexibleSpace();
+
+                GUILayoutY messageLayout = mainLayout.AddLayoutY();
+                messageLayout.AddElement(messageLabel);
+                messageLayout.AddElement(functionLabel);
+                mainLayout.AddSpace(PADDING);
 
                 background = new GUITexture(Builtin.WhiteTexture, GUIOption.FixedHeight(ENTRY_HEIGHT));
                 underlayLayout.AddElement(background);
@@ -233,6 +362,19 @@ namespace BansheeEditor
                     background.SetTint(SELECTION_COLOR);
                 }
 
+                switch (data.type)
+                {
+                    case DebugMessageType.Info:
+                        icon.SetTexture(EditorBuiltin.GetLogIcon(LogIcon.Info, 32));
+                        break;
+                    case DebugMessageType.Warning:
+                        icon.SetTexture(EditorBuiltin.GetLogIcon(LogIcon.Warning, 32));
+                        break;
+                    case DebugMessageType.Error:
+                        icon.SetTexture(EditorBuiltin.GetLogIcon(LogIcon.Error, 32));
+                        break;
+                }
+
                 messageLabel.SetContent(new LocEdString(data.message));
 
                 string method = "";
@@ -264,6 +406,9 @@ namespace BansheeEditor
             {
                 sSelectedElementIdx = entryIdx;
 
+                ConsoleWindow window = GetWindow<ConsoleWindow>();
+                window.RefreshDetailsPanel();
+
                 RefreshEntries();
             }
 

+ 22 - 0
MBansheeEditor/EditorBuiltin.cs

@@ -45,6 +45,14 @@ namespace BansheeEditor
 		Folder, Mesh, Font, Texture, PlainText, ScriptCode, SpriteTexture, Shader, ShaderInclude, Material, Prefab, GUISkin
 	};
 
+    /// <summary>
+    /// Types of icons that can be used for displaying types of log messages.
+    /// </summary>
+    public enum LogIcon // Note: Must match C++ enum LogMessageIcon
+    {
+        Info, Warning, Error
+    }
+
     /// <summary>
     /// Contains various editor-specific resources that are always available.
     /// </summary>
@@ -111,6 +119,17 @@ namespace BansheeEditor
             return Internal_GetSceneWindowIcon(icon);
         }
 
+        /// <summary>
+        /// Retrieves an icon that represents different types of log entries.
+        /// </summary>
+        /// <param name="icon">Type of icon to retrieve.</param>
+        /// <param name="size">Size of the icon in pixels. Nearest available size will be returned.</param>
+        /// <returns>Sprite texture of the icon.</returns>
+        public static SpriteTexture GetLogIcon(LogIcon icon, int size)
+        {
+            return Internal_GetLogIcon(icon, size);
+        }
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern SpriteTexture Internal_GetLibraryItemIcon(LibraryItemIcon icon, int size);
         
@@ -134,5 +153,8 @@ namespace BansheeEditor
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern SpriteTexture Internal_GetSceneWindowIcon(SceneWindowIcon icon);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern SpriteTexture Internal_GetLogIcon(LogIcon icon, int size);
     }
 }

+ 1 - 0
SBansheeEditor/Include/BsScriptEditorBuiltin.h

@@ -30,5 +30,6 @@ namespace BansheeEngine
 		static MonoObject* internal_GetLibraryWindowIcon(LibraryWindowIcon icon);
 		static MonoObject* internal_GetInspectorWindowIcon(InspectorWindowIcon icon);
 		static MonoObject* internal_GetSceneWindowIcon(SceneWindowIcon icon);
+		static MonoObject* internal_GetLogIcon(LogMessageIcon icon, int size);
 	};
 }

+ 8 - 0
SBansheeEditor/Source/BsScriptEditorBuiltin.cpp

@@ -22,6 +22,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_GetLibraryWindowIcon", &ScriptEditorBuiltin::internal_GetLibraryWindowIcon);
 		metaData.scriptClass->addInternalCall("Internal_GetInspectorWindowIcon", &ScriptEditorBuiltin::internal_GetInspectorWindowIcon);
 		metaData.scriptClass->addInternalCall("Internal_GetSceneWindowIcon", &ScriptEditorBuiltin::internal_GetSceneWindowIcon);
+		metaData.scriptClass->addInternalCall("Internal_GetLogIcon", &ScriptEditorBuiltin::internal_GetLogIcon);
 	}
 
 	MonoObject* ScriptEditorBuiltin::internal_getLibraryItemIcon(ProjectIcon icon, int size)
@@ -79,4 +80,11 @@ namespace BansheeEngine
 
 		return ScriptSpriteTexture::toManaged(tex);
 	}
+
+	MonoObject* ScriptEditorBuiltin::internal_GetLogIcon(LogMessageIcon icon, int size)
+	{
+		HSpriteTexture tex = BuiltinEditorResources::instance().getLogMessageIcon(icon, size);
+
+		return ScriptSpriteTexture::toManaged(tex);
+	}
 }