Browse Source

Added toolbar buttons and various editor icons

BearishSun 10 years ago
parent
commit
2b4dca6e54

+ 2 - 2
BansheeEditor/Source/BsGUIMenuBar.cpp

@@ -328,7 +328,7 @@ namespace BansheeEngine
 				break;
 		}
 
-		if (idx < numElements)
+		if (idx >= numElements)
 		{
 			mToolbarElements.push_back(GUIToolBarData());
 			idx = numElements;
@@ -365,7 +365,7 @@ namespace BansheeEngine
 				break;
 		}
 
-		if (idx < numElements)
+		if (idx >= numElements)
 		{
 			mToolbarElements.push_back(GUIToolBarData());
 			idx = numElements;

+ 3 - 0
MBansheeEditor/EditorApplication.cs

@@ -201,6 +201,7 @@ namespace BansheeEditor
         /// saved it is instead automatically saved at the last location.
         /// </summary>
         [MenuItem("File/Save Scene", ButtonModifier.Ctrl, ButtonCode.S, 10049)]
+        [ToolbarItem("Save Scene", ToolbarIcon.SaveScene, "", 1998)]
         private static void SaveScene()
         {
             if (!string.IsNullOrEmpty(Scene.ActiveSceneUUID))
@@ -295,6 +296,7 @@ namespace BansheeEditor
         /// Opens a Project Window allowing you to browse for or create a project.
         /// </summary>
         [MenuItem("File/Open Project", 10100)]
+        [ToolbarItem("Open Project", ToolbarIcon.OpenProject, "", 2000)]
         public static void BrowseForProject()
         {
             ProjectWindow.Open();
@@ -304,6 +306,7 @@ namespace BansheeEditor
         /// Saves all data in the currently open project.
         /// </summary>
         [MenuItem("File/Save Project", 10099)]
+        [ToolbarItem("Save Project", ToolbarIcon.SaveProject, "", 1999)]
         public static void SaveProject()
         {
             // TODO - Save dirty resources

+ 60 - 0
MBansheeEditor/GameWindow.cs

@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Displays in-game viewport in the editor.
+    /// </summary>
+    public class GameWindow : EditorWindow // TODO - Dummy class, unfinished
+    {
+        /// <summary>
+        /// Opens the game window.
+        /// </summary>
+        [MenuItem("Windows/Game", ButtonModifier.CtrlAlt, ButtonCode.G, 6000)]
+        private static void OpenGameWindow()
+        {
+            OpenWindow<GameWindow>();
+        }
+
+        /// <summary>
+        /// Starts execution of the game in the game window.
+        /// </summary>
+        [MenuItem("Tools/Play", 9300)]
+        [ToolbarItem("Play", ToolbarIcon.Play, "", 1800, true)]
+        private static void Play()
+        {
+            // TODO - Not implemented
+        }
+
+        /// <summary>
+        /// Pauses the execution of the game on the current frame.
+        /// </summary>
+        [MenuItem("Tools/Pause", 9299)]
+        [ToolbarItem("Pause", ToolbarIcon.Pause, "", 1799)]
+        private static void Pause()
+        {
+            // TODO - Not implemented
+        }
+
+        /// <summary>
+        /// Moves the execution of the game by one frame forward.
+        /// </summary>
+        [MenuItem("Tools/Step", 9298)]
+        [ToolbarItem("Step", ToolbarIcon.Step, "", 1798)]
+        private static void Step()
+        {
+            // TODO - Not implemented
+        }
+
+        /// <inheritdoc/>
+        protected override LocString GetDisplayName()
+        {
+            return new LocEdString("Game");
+        }
+    }
+}

+ 4 - 0
MBansheeEditor/Library/LibraryMenu.cs

@@ -60,6 +60,7 @@ namespace BansheeEditor
         /// Creates a new material with the default shader in the currently selected project library folder.
         /// </summary>
         [MenuItem("Resources/Create/Material", 9050, false, "IsLibraryWindowActive")]
+        [ToolbarItem("Material", ToolbarIcon.NewMat, "", 1499)]
         internal static void CreateEmptyMaterial()
         {
             LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
@@ -73,6 +74,7 @@ namespace BansheeEditor
         /// Creates a new shader containing a rough code outline in the currently selected project library folder.
         /// </summary>
         [MenuItem("Resources/Create/Shader", 9049, false, "IsLibraryWindowActive")]
+        [ToolbarItem("Shader", ToolbarIcon.NewShader, "", 1498)]
         internal static void CreateEmptyShader()
         {
             LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
@@ -86,6 +88,7 @@ namespace BansheeEditor
         /// Creates a new C# script containing a rough code outline in the currently selected project library folder.
         /// </summary>
         [MenuItem("Resources/Create/C# script", 9048, false, "IsLibraryWindowActive")]
+        [ToolbarItem("C# script", ToolbarIcon.NewCSScript, "", 1500, true)]
         internal static void CreateEmptyCSScript()
         {
             LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
@@ -99,6 +102,7 @@ namespace BansheeEditor
         /// Creates a new empty sprite texture in the currently selected project library folder.
         /// </summary>
         [MenuItem("Resources/Create/Sprite texture", 9047, false, "IsLibraryWindowActive")]
+        [ToolbarItem("Sprite texture", ToolbarIcon.NewSpriteTex, "", 1497)]
         internal static void CreateEmptySpriteTexture()
         {
             LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();

+ 1 - 0
MBansheeEditor/MBansheeEditor.csproj

@@ -47,6 +47,7 @@
     <Compile Include="DragDrop.cs" />
     <Compile Include="DropDownWindow.cs" />
     <Compile Include="FolderMonitor.cs" />
+    <Compile Include="GameWindow.cs" />
     <Compile Include="GUI\GUIEnumField.cs" />
     <Compile Include="GUI\GUIListBoxField.cs" />
     <Compile Include="GUI\GUISceneTreeView.cs" />

+ 9 - 0
MBansheeEditor/MenuItems.cs

@@ -89,6 +89,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a camera component.
         /// </summary>
         [MenuItem("Scene Objects/Camera", 8050)]
+        [ToolbarItem("Camera", ToolbarIcon.NewCamera, "", 1600, true)]
         private static void AddCameraSO()
         {
             SceneObject so = UndoRedo.CreateSO("Camera", "Created a Camera");
@@ -101,6 +102,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a renderable component.
         /// </summary>
         [MenuItem("Scene Objects/Renderable", 8049)]
+        [ToolbarItem("Renderable", ToolbarIcon.NewRenderable, "", 1599)]
         private static void AddRenderableSO()
         {
             SceneObject so = UndoRedo.CreateSO("Renderable", "Created a Renderable");
@@ -113,6 +115,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a point light component.
         /// </summary>
         [MenuItem("Scene Objects/Point light", 8048)]
+        [ToolbarItem("Point light", ToolbarIcon.NewPointLight, "", 1598)]
         private static void AddPointLightSO()
         {
             SceneObject so = UndoRedo.CreateSO("Point light", "Created a Light");
@@ -126,6 +129,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a spot light component.
         /// </summary>
         [MenuItem("Scene Objects/Spot light", 8047)]
+        [ToolbarItem("Spot light", ToolbarIcon.NewSpotLight, "", 1597)]
         private static void AddSpotLightSO()
         {
             SceneObject so = UndoRedo.CreateSO("Spot light", "Created a Light");
@@ -139,6 +143,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a directional light component.
         /// </summary>
         [MenuItem("Scene Objects/Directional light", 8046)]
+        [ToolbarItem("Directional light", ToolbarIcon.NewDirLight, "", 1596)]
         private static void AddDirectionalLightSO()
         {
             SceneObject so = UndoRedo.CreateSO("Directional light", "Created a Light");
@@ -152,6 +157,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a box primitive.
         /// </summary>
         [MenuItem("Scene Objects/3D primitives/Box", 8100)]
+        [ToolbarItem("Cube", ToolbarIcon.NewCube, "", 1700, true)]
         private static void Add3DBox()
         {
             SceneObject so = UndoRedo.CreateSO("Box", "Created a box");
@@ -165,6 +171,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a sphere primitive.
         /// </summary>
         [MenuItem("Scene Objects/3D primitives/Sphere", 8099)]
+        [ToolbarItem("Sphere", ToolbarIcon.NewSphere, "", 1699)]
         private static void Add3DSphere()
         {
             SceneObject so = UndoRedo.CreateSO("Sphere", "Created a sphere");
@@ -178,6 +185,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a cone primitive.
         /// </summary>
         [MenuItem("Scene Objects/3D primitives/Cone", 8098)]
+        [ToolbarItem("Cone", ToolbarIcon.NewCone, "", 1698)]
         private static void Add3DCone()
         {
             SceneObject so = UndoRedo.CreateSO("Cone", "Created a cone");
@@ -191,6 +199,7 @@ namespace BansheeEditor
         /// Creates a new scene object with a quad primitive.
         /// </summary>
         [MenuItem("Scene Objects/3D primitives/Quad", 8097)]
+        [ToolbarItem("Quad", ToolbarIcon.NewQuad, "", 1697)]
         private static void Add3DQuad()
         {
             SceneObject so = UndoRedo.CreateSO("Quad", "Created a quad");

+ 26 - 3
MBansheeEditor/ToolbarItem.cs

@@ -19,22 +19,45 @@ namespace BansheeEditor
         /// </summary>
         /// <param name="name">Path that determines where in the menu to add the element. All path elements must be 
         ///                    separated by /, e.g. "View/Toolbars/Find"</param>
-        /// <param name="icon">Icon to display on the toolbar entry.</param>
+        /// <param name="icon">Path to the sprite texture to display on the toolbar entry. Relative to project library 
+        ///                    resources folder.</param>
         /// <param name="tooltip">Optional tooltip to display when the user hovers over the toolbar entry.</param>
         /// <param name="priority">Priority determines the position of the toolbar item relative to its siblings.
         ///                        Higher priority means it will be placed earlier.</param>
         /// <param name="separator">Determines should a separator be inserted just before this element.</param>
-        public ToolbarItem(string name, SpriteTexture icon, LocString tooltip = null, int priority = 0, bool separator = false)
+        public ToolbarItem(string name, string icon, string tooltip = "", int priority = 0, bool separator = false)
         {
             this.name = name;
             this.icon = icon;
             this.tooltip = tooltip;
             this.priority = priority;
             this.separator = separator;
+            this.builtinIcon = -1;
+        }
+
+        /// <summary>
+        /// Creates a new toolbar item attribute. Selecting the item in the toolbar will trigger the callback.
+        /// </summary>
+        /// <param name="name">Path that determines where in the menu to add the element. All path elements must be 
+        ///                    separated by /, e.g. "View/Toolbars/Find"</param>
+        /// <param name="icon">Type of builtin icon to display on the toolbar entry.</param>
+        /// <param name="tooltip">Optional tooltip to display when the user hovers over the toolbar entry.</param>
+        /// <param name="priority">Priority determines the position of the toolbar item relative to its siblings.
+        ///                        Higher priority means it will be placed earlier.</param>
+        /// <param name="separator">Determines should a separator be inserted just before this element.</param>
+        internal ToolbarItem(string name, ToolbarIcon icon, string tooltip = "", int priority = 0, bool separator = false)
+        {
+            this.name = name;
+            this.icon = null;
+            this.tooltip = tooltip;
+            this.priority = priority;
+            this.separator = separator;
+            this.builtinIcon = (int)icon;
         }
 
         private string name;
-        private SpriteTexture icon;
+        private string icon;
+        private int builtinIcon;
         private LocString tooltip;
         private int priority;
         private bool separator;

+ 4 - 0
MBansheeEditor/UndoRedo.cs

@@ -16,6 +16,8 @@ namespace BansheeEditor
         /// <summary>
         /// Executes the last command on the undo stack, undoing its operations.
         /// </summary>
+        [MenuItem("Edit/Undo", 9500, true)]
+        [ToolbarItem("Undo", ToolbarIcon.Undo, "", 1900, true)]
         public static void Undo()
         {
             Internal_Undo();
@@ -24,6 +26,8 @@ namespace BansheeEditor
         /// <summary>
         /// Executes the last command on the redo stack (last command we called undo on), re-applying its operation.
         /// </summary>
+        [MenuItem("Edit/Redo", 9499, true)]
+        [ToolbarItem("Redo", ToolbarIcon.Redo, "", 1899)]
         public static void Redo()
         {
             Internal_Redo();

+ 9 - 1
MBansheeEngine/LocString.cs

@@ -8,11 +8,19 @@ namespace BansheeEngine
     /// </summary>
     public sealed class LocString : ScriptObject
     {
+        /// <summary>
+        /// Creates a new empty localized string.
+        /// </summary>
+        public LocString()
+        {
+            Internal_CreateInstance(this, "", 0);
+        }
+
         /// <summary>
         /// Creates a new empty localized string.
         /// </summary>
         /// <param name="tableId">Unique identifier of the string table to retrieve the string from.</param>
-        public LocString(int tableId = 0)
+        public LocString(int tableId)
         {
             Internal_CreateInstance(this, "", tableId);
         }

+ 1 - 0
SBansheeEditor/Include/BsToolbarItemManager.h

@@ -57,6 +57,7 @@ namespace BansheeEngine
 		MonoClass* mToolbarItemAttribute;
 		MonoField* mNameField;
 		MonoField* mIconField;
+		MonoField* mBuiltinIconField;
 		MonoField* mTooltipField;
 		MonoField* mPriorityField;
 		MonoField* mSeparatorField;

+ 17 - 7
SBansheeEditor/Source/BsToolbarItemManager.cpp

@@ -13,6 +13,8 @@
 #include "BsGUIContent.h"
 #include "BsScriptSpriteTexture.h"
 #include "BsScriptHString.h"
+#include "BsBuiltinEditorResources.h"
+#include "BsProjectLibrary.h"
 
 using namespace std::placeholders;
 
@@ -20,7 +22,8 @@ namespace BansheeEngine
 {
 	ToolbarItemManager::ToolbarItemManager(ScriptAssemblyManager& scriptObjectManager)
 		:mScriptObjectManager(scriptObjectManager), mToolbarItemAttribute(nullptr), mNameField(nullptr),
-		mIconField(nullptr), mPriorityField(nullptr), mTooltipField(nullptr), mSeparatorField(nullptr)
+		mIconField(nullptr), mPriorityField(nullptr), mTooltipField(nullptr), mSeparatorField(nullptr),
+		mBuiltinIconField(nullptr)
 	{
 		mDomainLoadedConn = ScriptObjectManager::instance().onRefreshDomainLoaded.connect(std::bind(&ToolbarItemManager::reloadAssemblyData, this));
 		reloadAssemblyData();
@@ -51,6 +54,7 @@ namespace BansheeEngine
 
 		mNameField = mToolbarItemAttribute->getField("name");
 		mIconField = mToolbarItemAttribute->getField("icon");
+		mBuiltinIconField = mToolbarItemAttribute->getField("builtinIcon");
 		mTooltipField = mToolbarItemAttribute->getField("tooltip");
 		mPriorityField = mToolbarItemAttribute->getField("priority");
 		mSeparatorField = mToolbarItemAttribute->getField("separator");
@@ -113,14 +117,20 @@ namespace BansheeEngine
 		mNameField->getValue(toolbarItemAttrib, &monoName);
 		name = MonoUtil::monoToString(monoName);
 
-		MonoObject* monoTexture;
-		mIconField->getValue(toolbarItemAttrib, &monoTexture);
+		int builtinIcon;
+		mBuiltinIconField->getValue(toolbarItemAttrib, &builtinIcon);
 
-		if (monoTexture != nullptr)
+		if (builtinIcon != -1)
 		{
-			ScriptSpriteTexture* scriptTexture = ScriptSpriteTexture::toNative(monoTexture);
-			if (scriptTexture != nullptr)
-				icon = scriptTexture->getInternalValue();
+			icon = BuiltinEditorResources::instance().getToolbarIcon((ToolbarIcon)builtinIcon);
+		}
+		else
+		{
+			MonoString* monoTexturePath;
+			mIconField->getValue(toolbarItemAttrib, &monoTexturePath);
+
+			Path texturePath = MonoUtil::monoToWString(monoTexturePath);
+			icon = static_resource_cast<SpriteTexture>(ProjectLibrary::instance().load(texturePath));
 		}
 
 		MonoObject* tooltipMono;