Browse Source

GUISceneTreeView fixes:
- Fixed an issue with GUIInputBox where multiple input boxes were using the caret input tool at once
- Fixed an issue where renaming an element didn't properly apply the name
- Fixed an issue where starting a rename the input box didn't have the original name displayed
- Don't select element if users clicks on an element currently being renamed
- Don't try to drag an element if used tries to drag inside an input box for the currently renamed element
- Clear focus from rename input box when disabling rename
Added undo/redo command for instantiating a prefab

Marko Pintera 10 years ago
parent
commit
1b8b8a2129

+ 2 - 0
BansheeEditor/BansheeEditor.vcxproj

@@ -271,6 +271,7 @@
     <ClInclude Include="Include\BsCmdCreateSO.h" />
     <ClInclude Include="Include\BsCmdDeleteSO.h" />
     <ClInclude Include="Include\BsCmdInputFieldValueChange.h" />
+    <ClInclude Include="Include\BsCmdInstantiateSO.h" />
     <ClInclude Include="Include\BsCmdRecordSO.h" />
     <ClInclude Include="Include\BsCmdReparentSO.h" />
     <ClInclude Include="Include\BsCmdUtility.h" />
@@ -350,6 +351,7 @@
     <ClCompile Include="Source\BsBuildManager.cpp" />
     <ClCompile Include="Source\BsCmdCloneSO.cpp" />
     <ClCompile Include="Source\BsCmdCreateSO.cpp" />
+    <ClCompile Include="Source\BsCmdInstantiateSO.cpp" />
     <ClCompile Include="Source\BsCmdRecordSO.cpp" />
     <ClCompile Include="Source\BsCmdReparentSO.cpp" />
     <ClCompile Include="Source\BsCmdUtility.cpp" />

+ 6 - 0
BansheeEditor/BansheeEditor.vcxproj.filters

@@ -270,6 +270,9 @@
     <ClInclude Include="Include\BsCmdCloneSO.h">
       <Filter>Header Files\Commands</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsCmdInstantiateSO.h">
+      <Filter>Header Files\Commands</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsEditorCommand.cpp">
@@ -488,5 +491,8 @@
     <ClCompile Include="Source\BsCmdCloneSO.cpp">
       <Filter>Source Files\Commands</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsCmdInstantiateSO.cpp">
+      <Filter>Source Files\Commands</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 48 - 0
BansheeEditor/Include/BsCmdInstantiateSO.h

@@ -0,0 +1,48 @@
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+#include "BsEditorCommand.h"
+#include "BsUndoRedo.h"
+#include "BsCmdUtility.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	A command used for undo/redo purposes. Instantiates scene object(s)
+	 *			from a prefab and removes them as an undo operation.
+	 */
+	class CmdInstantiateSO : public EditorCommand
+	{
+	public:
+		~CmdInstantiateSO();
+
+		/**
+		 * @brief	Instantiates the specified prefab.
+		 *			Automatically registers the command with undo/redo system.
+		 *
+		 * @param	prefab			Prefab to instantiate.
+		 * @param	description		Optional description of what exactly the command does.
+		 *
+		 * @return	Instantiated object.
+		 */
+		static HSceneObject execute(const HPrefab& prefab, const WString& description = StringUtil::WBLANK);
+
+		/**
+		 * @copydoc	EditorCommand::commit
+		 */
+		void commit() override;
+
+		/**
+		 * @copydoc	EditorCommand::revert
+		 */
+		void revert() override;
+
+	private:
+		friend class UndoRedo;
+
+		CmdInstantiateSO(const WString& description, const HPrefab& prefab);
+
+		HPrefab mPrefab;
+		HSceneObject mSceneObject;
+	};
+}

+ 40 - 0
BansheeEditor/Source/BsCmdInstantiateSO.cpp

@@ -0,0 +1,40 @@
+#include "BsCmdInstantiateSO.h"
+#include "BsSceneObject.h"
+#include "BsPrefab.h"
+
+namespace BansheeEngine
+{
+	CmdInstantiateSO::CmdInstantiateSO(const WString& description, const HPrefab& prefab)
+		:EditorCommand(description), mPrefab(prefab)
+	{
+
+	}
+
+	CmdInstantiateSO::~CmdInstantiateSO()
+	{
+
+	}
+
+	HSceneObject CmdInstantiateSO::execute(const HPrefab& prefab, const WString& description)
+	{
+		// Register command and commit it
+		CmdInstantiateSO* command = new (bs_alloc<CmdInstantiateSO>()) CmdInstantiateSO(description, prefab);
+		UndoRedo::instance().registerCommand(command);
+		command->commit();
+
+		return command->mSceneObject;
+	}
+
+	void CmdInstantiateSO::commit()
+	{
+		mSceneObject = mPrefab->instantiate();
+	}
+
+	void CmdInstantiateSO::revert()
+	{
+		if (!mSceneObject.isDestroyed())
+			mSceneObject->destroy(true);
+
+		mSceneObject = nullptr;
+	}
+}

+ 6 - 2
BansheeEditor/Source/BsGUISceneTreeView.cpp

@@ -7,6 +7,7 @@
 #include "BsCmdDeleteSO.h"
 #include "BsCmdCloneSO.h"
 #include "BsCmdCreateSO.h"
+#include "BsCmdInstantiateSO.h"
 #include "BsDragAndDropManager.h"
 #include "BsSelection.h"
 #include "BsGUIResourceTreeView.h"
@@ -237,7 +238,7 @@ namespace BansheeEngine
 
 		HSceneObject so = sceneTreeElement->mSceneObject;
 		CmdRecordSO::execute(so, L"Renamed \"" + toWString(so->getName()) + L"\"");
-		so->setName("mName");
+		so->setName(toString(name));
 	}
 
 	void GUISceneTreeView::deleteTreeElement(TreeElement* element)
@@ -331,7 +332,7 @@ namespace BansheeEngine
 
 						if (prefab != nullptr)
 						{
-							HSceneObject instance = prefab->instantiate();
+							HSceneObject instance = CmdInstantiateSO::execute(prefab, L"Instantiated " + prefab->getName());
 
 							if (newParent != nullptr)
 								instance->setParent(newParent);
@@ -579,6 +580,9 @@ namespace BansheeEngine
 		}
 
 		updateTreeElementHierarchy();
+
+		TreeElement* newTreeElement = findTreeElement(newSO);
+		expandToElement(newTreeElement);
 		setSelection({ newSO });
 		renameSelected();
 	}

+ 9 - 2
BansheeEditor/Source/BsGUITreeView.cpp

@@ -221,7 +221,11 @@ namespace BansheeEngine
 				if (treeElement->mFoldoutBtn != nullptr)
 					onFoldout = treeElement->mFoldoutBtn->_getClippedBounds().contains(event.getPosition());
 
-				if (!onFoldout)
+				bool onEditElement = false;
+				if (mEditElement != nullptr)
+					onEditElement = treeElement == mEditElement;
+
+				if (!onFoldout && !onEditElement)
 				{
 					if (event.isCtrlDown())
 					{
@@ -334,7 +338,7 @@ namespace BansheeEngine
 
 			if(!DragAndDropManager::instance().isDragInProgress())
 			{
-				if(dist > DRAG_MIN_DISTANCE)
+				if(dist > DRAG_MIN_DISTANCE && mEditElement == nullptr)
 				{
 					const GUITreeView::InteractableElement* element = findElementUnderCoord(mDragStartPosition);
 					TreeElement* treeElement = nullptr;
@@ -841,6 +845,7 @@ namespace BansheeEngine
 
 		mEditElement = element;
 		mNameEditBox->enableRecursively();
+		mNameEditBox->setText(toWString(element->mName));
 		mNameEditBox->setFocus(true);
 
 		if(element->mElement != nullptr)
@@ -860,7 +865,9 @@ namespace BansheeEngine
 			renameTreeElement(mEditElement, newName);
 		}
 
+		mNameEditBox->setFocus(false);
 		mNameEditBox->disableRecursively();
+		selectElement(mEditElement);
 		mEditElement = nullptr;
 	}
 

+ 12 - 9
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -80,18 +80,21 @@ namespace BansheeEngine
 			WString oldText = mText;
 			mText = text;
 
-			TEXT_SPRITE_DESC textDesc = getTextDesc();
-			Vector2I offset = getTextOffset();
+			if (mHasFocus)
+			{
+				TEXT_SPRITE_DESC textDesc = getTextDesc();
+				Vector2I offset = getTextOffset();
 
-			gGUIManager().getInputCaretTool()->updateText(this, textDesc);
-			gGUIManager().getInputSelectionTool()->updateText(this, textDesc);
+				gGUIManager().getInputCaretTool()->updateText(this, textDesc);
+				gGUIManager().getInputSelectionTool()->updateText(this, textDesc);
 
-			if(mText.size() > 0)
-				gGUIManager().getInputCaretTool()->moveCaretToChar((UINT32)mText.size() - 1, CARET_AFTER);
-			else
-				gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
+				if (mText.size() > 0)
+					gGUIManager().getInputCaretTool()->moveCaretToChar((UINT32)mText.size() - 1, CARET_AFTER);
+				else
+					gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
 
-			scrollTextToCaret();
+				scrollTextToCaret();
+			}
 
 			Vector2I newSize = mDimensions.calculateSizeRange(_getOptimalSize()).optimal;
 			if (origSize != newSize)

+ 2 - 5
TODO.txt

@@ -55,12 +55,11 @@ Code quality improvements:
 Polish
 
 SceneTreeView
+ - When having scene window in focus and then right clicking on Hierarchy the cursor becomes invisible
  - Test: 
-    - Cut/Copy/Paste/duplicate
+    - Cut/Copy/Paste/duplicate/Delete
     - Context menu
-	- Ignore shortcuts when out of focus
     - Creating new objects
-	- Clicking on an already selected element should start rename
 
 Ribek use:
  - Camera, Renderable, Material, Texture inspector
@@ -96,8 +95,6 @@ First screenshot:
 Other polish:
  - C# inspectors for Point/Spot/Directional light
  - C# interface for Font
- - Hook up ping effect so that when resource/gameobject/texture field is clicked it triggers a ping in
-   ProjectWindow or HierarchyWindow. (Likely add Selection.Ping method and Selection.OnPing callback)
  - Handle seems to lag behind the selected mesh
  - ProjectLibrary seems to import some files on every start-up
  - Crash on shutdown in mono_gchandle_free