Jelajahi Sumber

Texture field working
Properly turn off drop button when drag operation leaves it
Deselect resource if scene object is selected and vice versa
ProjectWindow drag and drop now properly includes resource paths even when there is no previous selection
TextureField and ResourceField now properly query the ProjectLibrary for resource meta-data and UUID

Marko Pintera 10 tahun lalu
induk
melakukan
acb9baa212

+ 1 - 0
BansheeEditor/Include/BsBuiltinEditorResources.h

@@ -332,6 +332,7 @@ namespace BansheeEngine
 		static const WString SelectionAreaTex;
 
 		static const WString TextureDropTex;
+		static const WString TextureDropOnTex;
 
 		static const WString XButtonNormalTex;
 		static const WString XButtonHoverTex;

+ 5 - 0
BansheeEditor/Include/BsSelection.h

@@ -70,6 +70,11 @@ namespace BansheeEngine
 		 */
 		void resourceSelectionChanged();
 
+		/**
+		 * @brief	Updates scene and resource tree views with new selection.
+		 */
+		void updateTreeViews();
+
 		Vector<HSceneObject> mSelectedSceneObjects;
 		Vector<Path> mSelectedResourcePaths;
 

+ 15 - 2
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -223,6 +223,7 @@ namespace BansheeEngine
 	const WString BuiltinEditorResources::SelectionAreaTex = L"SelectionHighlight.psd";
 
 	const WString BuiltinEditorResources::TextureDropTex = L"TextureDrop.psd";
+	const WString BuiltinEditorResources::TextureDropOnTex = L"TextureDropOn.psd";
 
 	const WString BuiltinEditorResources::XButtonNormalTex = L"XBtnNormal.psd";
 	const WString BuiltinEditorResources::XButtonHoverTex = L"XBtnHover.psd";
@@ -1026,8 +1027,20 @@ namespace BansheeEngine
 		textureDropStyle.textVertAlign = TVA_Center;
 		textureDropStyle.normal.textColor = Color(95 / 255.0f, 95 / 255.0f, 95 / 255.0f, 1.0f);
 		textureDropStyle.normal.texture = getGUITexture(TextureDropTex);
-		textureDropStyle.minHeight = 15;
-		textureDropStyle.minWidth = 15;
+		textureDropStyle.hover.textColor = textureDropStyle.normal.textColor;
+		textureDropStyle.hover.texture = textureDropStyle.normal.texture;
+		textureDropStyle.active.textColor = textureDropStyle.normal.textColor;
+		textureDropStyle.active.texture = textureDropStyle.normal.texture;
+		textureDropStyle.normalOn.textColor = Color(95 / 255.0f, 95 / 255.0f, 95 / 255.0f, 1.0f);
+		textureDropStyle.normalOn.texture = getGUITexture(TextureDropOnTex);
+		textureDropStyle.hoverOn.textColor = textureDropStyle.normalOn.textColor;
+		textureDropStyle.hoverOn.texture = textureDropStyle.normalOn.texture;
+		textureDropStyle.activeOn.textColor = textureDropStyle.normalOn.textColor;
+		textureDropStyle.activeOn.texture = textureDropStyle.normalOn.texture;
+		textureDropStyle.height = 82;
+		textureDropStyle.width = 82;
+		textureDropStyle.fixedHeight = true;
+		textureDropStyle.fixedWidth = true;
 		textureDropStyle.border.left = 2;
 		textureDropStyle.border.right = 2;
 		textureDropStyle.border.top = 2;

+ 5 - 0
BansheeEditor/Source/BsGUIDropButton.cpp

@@ -77,6 +77,11 @@ namespace BansheeEngine
 					onDataDropped(DragAndDropManager::instance().getDragData());
 			}
 		}
+		else if (ev.getType() == GUIMouseEventType::MouseDragAndDropLeft)
+		{
+			if (_isOn())
+				_setOn(false);
+		}
 
 		return processed;
 	}

+ 30 - 6
BansheeEditor/Source/BsSelection.cpp

@@ -30,10 +30,9 @@ namespace BansheeEngine
 	void Selection::setSceneObjects(const Vector<HSceneObject>& sceneObjects)
 	{
 		mSelectedSceneObjects = sceneObjects;
+		mSelectedResourcePaths.clear();
 
-		GUISceneTreeView* sceneTreeView = SceneTreeViewLocator::instance();
-		if (sceneTreeView != nullptr)
-			sceneTreeView->setSelection(sceneObjects);
+		updateTreeViews();
 
 		onSelectionChanged(mSelectedSceneObjects, Vector<Path>());
 	}
@@ -46,6 +45,9 @@ namespace BansheeEngine
 	void Selection::setResourcePaths(const Vector<Path>& paths)
 	{
 		mSelectedResourcePaths = paths;
+		mSelectedSceneObjects.clear();
+
+		updateTreeViews();
 
 		onSelectionChanged(Vector<HSceneObject>(), mSelectedResourcePaths);
 	}
@@ -76,9 +78,8 @@ namespace BansheeEngine
 				mSelectedResourcePaths.push_back(path);
 		}
 
-		GUIResourceTreeView* resourceTreeView = ResourceTreeViewLocator::instance();
-		if (resourceTreeView != nullptr)
-			resourceTreeView->setSelection(mSelectedResourcePaths);
+		mSelectedSceneObjects.clear();
+		updateTreeViews();
 
 		onSelectionChanged(Vector<HSceneObject>(), mSelectedResourcePaths);
 	}
@@ -99,6 +100,7 @@ namespace BansheeEngine
 		if (sceneTreeView != nullptr)
 		{
 			mSelectedSceneObjects = sceneTreeView->getSelection();
+			mSelectedResourcePaths.clear();
 
 			onSelectionChanged(mSelectedSceneObjects, Vector<Path>());
 		}
@@ -110,8 +112,30 @@ namespace BansheeEngine
 		if (resourceTreeView != nullptr)
 		{
 			mSelectedResourcePaths = resourceTreeView->getSelection();
+			mSelectedSceneObjects.clear();
 
 			onSelectionChanged(Vector<HSceneObject>(), mSelectedResourcePaths);
 		}
 	}
+
+	void Selection::updateTreeViews()
+	{
+		GUIResourceTreeView* resourceTreeView = ResourceTreeViewLocator::instance();
+		if (resourceTreeView != nullptr)
+		{
+			// Copy in case setSelection modifies the original.
+			Vector<Path> copy = mSelectedResourcePaths;
+
+			resourceTreeView->setSelection(copy);
+		}
+
+		GUISceneTreeView* sceneTreeView = SceneTreeViewLocator::instance();
+		if (sceneTreeView != nullptr)
+		{
+			// Copy in case setSelection modifies the original.
+			Vector<HSceneObject> copy = mSelectedSceneObjects;
+
+			sceneTreeView->setSelection(copy);
+		}
+	}
 }

+ 1 - 0
MBansheeEditor/DragDrop.cs

@@ -70,6 +70,7 @@ namespace BansheeEditor
     {
         public string[] Paths { get { return Internal_GetPaths(mCachedPtr); } }
 
+        // Paths must be absolute
         public ResourceDragDropData(string[] paths)
         {
             this.type = DragDropType.Resource;

+ 0 - 9
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -345,12 +345,10 @@ namespace BansheeEditor
             }
             else if (objects.Length == 1)
             {
-                Debug.Log("Object selected: " + objects[0].Name);
                 SetObjectToInspect(objects[0]);
             }
             else if (paths.Length == 1)
             {
-                Debug.Log("Path selected: " + paths[0]);
                 SetObjectToInspect(paths[0]);
             }
         }
@@ -435,13 +433,6 @@ namespace BansheeEditor
                 Vector3 angles = activeSO.LocalRotation.ToEuler();
                 angles[idx] = value;
                 activeSO.LocalRotation = Quaternion.FromEuler(angles);
-
-                Debug.Log("ROTATION CHANGED: " + idx + " - " + value + " - " + angles + " - " + activeSO.LocalRotation + " - " + activeSO.LocalRotation.ToEuler());
-
-                Quaternion dbg = Quaternion.FromEuler(angles);
-
-                Debug.Log("LOCAL CHECK: " + angles + " - " + dbg + " - " + dbg.ToEuler());
-                
             }
         }
 

+ 48 - 9
MBansheeEditor/ProjectWindow.cs

@@ -140,6 +140,13 @@ namespace BansheeEditor
             dropTarget.OnDropResource += DoOnResourceDragDropped;
             dropTarget.OnDropSceneObject += DoOnSceneObjectDragDropped;
             dropTarget.OnEnd += DoOnDragEnd;
+
+            Selection.OnSelectionChanged += OnSelectionChanged;
+        }
+
+        private void OnDestroy()
+        {
+            Selection.OnSelectionChanged -= OnSelectionChanged;
         }
 
         private ElementEntry FindElementAt(Vector2I windowPos)
@@ -170,13 +177,36 @@ namespace BansheeEditor
         private void DoOnDragStart(Vector2I windowPos)
         {
             ElementEntry underCursorElem = FindElementAt(windowPos);
-            if (underCursorElem == null || !selectionPaths.Contains(underCursorElem.path))
+            if (underCursorElem == null)
             {
                 StartDragSelection(windowPos);
                 return;
             }
 
-            ResourceDragDropData dragDropData = new ResourceDragDropData(selectionPaths.ToArray());
+            string resourceDir = ProjectLibrary.ResourceFolder;
+
+            string[] dragPaths = null;
+            if (selectionPaths.Count > 0)
+            {
+                foreach(var path in selectionPaths)
+                {
+                    if (path == underCursorElem.path)
+                    {
+                        dragPaths = new string[selectionPaths.Count];
+                        for (int i = 0; i < selectionPaths.Count; i++)
+                        {
+                            dragPaths[i] = Path.Combine(resourceDir, selectionPaths[i]);
+                        }
+
+                        break;
+                    }
+                }
+            }
+
+            if (dragPaths == null)
+                dragPaths = new[] { Path.Combine(resourceDir, underCursorElem.path) };
+
+            ResourceDragDropData dragDropData = new ResourceDragDropData(dragPaths);
             DragDrop.StartDrag(dragDropData);
         }
 
@@ -362,9 +392,9 @@ namespace BansheeEditor
             }
         }
 
-        private void DeselectAll()
+        private void DeselectAll(bool onlyInternal = false)
         {
-            SetSelection(new List<string>());
+            SetSelection(new List<string>(), onlyInternal);
             selectionAnchorStart = -1;
             selectionAnchorEnd = -1;
         }
@@ -499,7 +529,7 @@ namespace BansheeEditor
             }
         }
 
-        private void SetSelection(List<string> paths)
+        private void SetSelection(List<string> paths, bool onlyInternal = false)
         {
             if (selectionPaths != null)
             {
@@ -526,10 +556,13 @@ namespace BansheeEditor
             Ping(null);
             StopRename();
 
-            if (selectionPaths != null)
-                Selection.resourcePaths = selectionPaths.ToArray();
-            else
-                Selection.resourcePaths = new string[0];
+            if (!onlyInternal)
+            {
+                if (selectionPaths != null)
+                    Selection.resourcePaths = selectionPaths.ToArray();
+                else
+                    Selection.resourcePaths = new string[0];
+            }
         }
 
         private void EnterDirectory(string directory)
@@ -1133,6 +1166,12 @@ namespace BansheeEditor
             });
         }
 
+        private void OnSelectionChanged(SceneObject[] sceneObjects, string[] resourcePaths)
+        {
+            if(sceneObjects.Length > 0)
+                DeselectAll(true);
+        }
+
         private void OnFolderButtonClicked(string path)
         {
             EnterDirectory(path);

+ 0 - 4
MBansheeEditor/Scene/SceneWindow.cs

@@ -166,10 +166,6 @@ namespace BansheeEditor
 
         private void OnEditorUpdate()
         {
-            // DEBUG ONLY
-            if (activeProfilerOverlay != null && Time.FrameDelta > 100.0f)
-                activeProfilerOverlay.Paused = true;
-
             if (HasFocus)
             {
                 if (VirtualInput.IsButtonUp(toggleProfilerOverlayKey))

+ 7 - 6
SBansheeEditor/Source/BsGUIResourceField.cpp

@@ -223,16 +223,17 @@ namespace BansheeEngine
 		{
 			Path path = draggedResources->resourcePaths[i];
 
-			String uuid;
-			if (!gResources().getUUIDFromFilePath(draggedResources->resourcePaths[i], uuid))
+			ProjectLibrary::LibraryEntry* libEntry = ProjectLibrary::instance().findEntry(path);
+			if (libEntry == nullptr || libEntry->type == ProjectLibrary::LibraryEntryType::Directory)
 				continue;
 
-			ProjectResourceMetaPtr meta = ProjectLibrary::instance().findResourceMeta(uuid);
-			if (meta == nullptr)
-				continue;
+			ProjectLibrary::ResourceEntry* resEntry = static_cast<ProjectLibrary::ResourceEntry*>(libEntry);
 
-			bool found = false;
+			ProjectResourceMetaPtr meta = resEntry->meta;
 			UINT32 typeId = meta->getTypeID();
+			String uuid = meta->getUUID();
+
+			bool found = false;
 			switch (typeId)
 			{
 			case TID_Texture:

+ 13 - 6
SBansheeEditor/Source/BsGUITextureField.cpp

@@ -39,7 +39,7 @@ namespace BansheeEngine
 		GUIPanel* dropTargetPanel = mLayout->addNewElement<GUIPanel>();
 		dropTargetPanel->addElement(mDropButton);
 
-		GUIPanel* closeBtnPanel = mLayout->addNewElement<GUIPanel>();
+		GUIPanel* closeBtnPanel = dropTargetPanel->addNewElement<GUIPanel>(-1);
 		GUILayoutY* closeBtnLayoutY = closeBtnPanel->addNewElement<GUILayoutY>();
 		closeBtnLayoutY->addNewElement<GUIFixedSpace>(5);
 		GUILayoutX* closeBtnLayoutX = closeBtnLayoutY->addNewElement<GUILayoutX>();
@@ -48,7 +48,12 @@ namespace BansheeEngine
 		closeBtnLayoutX->addElement(mClearButton);
 		closeBtnLayoutX->addNewElement<GUIFixedSpace>(5);
 
+		if (withLabel)
+			mLayout->addNewElement<GUIFlexibleSpace>();
+
 		mDropButton->onDataDropped.connect(std::bind(&GUITextureField::dataDropped, this, _1));
+
+		setValue(HTexture());
 	}
 
 	GUITextureField::~GUITextureField()
@@ -230,15 +235,17 @@ namespace BansheeEngine
 		{
 			Path path = draggedResources->resourcePaths[i];
 
-			String uuid;
-			if (!gResources().getUUIDFromFilePath(draggedResources->resourcePaths[i], uuid))
+			ProjectLibrary::LibraryEntry* libEntry = ProjectLibrary::instance().findEntry(draggedResources->resourcePaths[i]);
+			if (libEntry == nullptr || libEntry->type == ProjectLibrary::LibraryEntryType::Directory)
 				continue;
 
-			ProjectResourceMetaPtr meta = ProjectLibrary::instance().findResourceMeta(uuid);
-			if (meta == nullptr || meta->getTypeId() != TID_Texture)
+			ProjectLibrary::ResourceEntry* resEntry = static_cast<ProjectLibrary::ResourceEntry*>(libEntry);
+
+			ProjectResourceMetaPtr meta = resEntry->meta;
+			if (meta == nullptr || meta->getTypeID() != TID_Texture)
 				continue;
 
-			setUUID(uuid);
+			setUUID(meta->getUUID());
 			break;
 		}
 	}

+ 2 - 2
TODO.txt

@@ -57,8 +57,7 @@ Code quality improvements:
 ----------------------------------------------------------------------
 Polish stage 1
 
-Test GUITextureField
-Test GUIStatusBar
+Selecting a resource doesn't clear selection overlay
 Test inspector selection, selecting a resource and adding/removing component updates
 Showing the inspector causes a considerable slowdown (maybe stuff gets refreshed too often?)
 Crash when showing the inspector (invalid index in Layout.InsertElement)
@@ -89,6 +88,7 @@ SceneTreeView
    - Add Selection::ping method to both C++ and C# and an Event that triggers when its called
  - See if it needs other enhancements (rename, delete all work properly? etc.)
  - Add copy/cut/paste/duplicate (with context menu)
+ - Cannot deselect element by clicking on empty space
 
 Need a way to add scene objects and components (and remove them)
  - Components adding should be only done by drag and dropping scripts to inspector (undoable)