Преглед изворни кода

Added toggle for scene object active/inactive state
Scene tree view renders inactive and prefab instances in a different tint
Fixed an issue with breaking prefab links
Selection overlay no longer renders when object is disabled

BearishSun пре 10 година
родитељ
комит
87a15985b5

+ 1 - 1
BansheeCore/Source/BsSceneObject.cpp

@@ -139,7 +139,7 @@ namespace BansheeEngine
 		while (rootObj != nullptr)
 		{
 			if (!rootObj->mPrefabLinkUUID.empty())
-				return;
+				break;
 
 			if (rootObj->mParent != nullptr)
 				rootObj = rootObj->mParent.get();

+ 4 - 1
BansheeEditor/Include/BsGUISceneTreeView.h

@@ -32,11 +32,12 @@ namespace BansheeEngine
 		struct SceneTreeElement : public GUITreeView::TreeElement
 		{
 			SceneTreeElement()
-				:mId(0)
+				:mId(0), mIsPrefabInstance(false)
 			{ }
 
 			HSceneObject mSceneObject;
 			UINT64 mId;
+			bool mIsPrefabInstance;
 		};
 
 	public:
@@ -240,6 +241,8 @@ namespace BansheeEngine
 
 		Vector<HSceneObject> mCopyList;
 		bool mCutFlag;
+
+		static const Color PREFAB_TINT;
 	};
 
 	typedef ServiceLocator<GUISceneTreeView> SceneTreeViewLocator;

+ 4 - 2
BansheeEditor/Include/BsGUITreeView.h

@@ -55,7 +55,8 @@ namespace BansheeEngine
 			bool mIsSelected;
 			bool mIsHighlighted;
 			bool mIsVisible;
-			bool mIsGrayedOut;
+			bool mIsCut;
+			bool mIsDisabled;
 			Color mTint;
 
 			bool isParentRec(TreeElement* element) const;
@@ -410,6 +411,7 @@ namespace BansheeEngine
 		static const float AUTO_EXPAND_DELAY_SEC;
 		static const float SCROLL_AREA_HEIGHT_PCT;
 		static const UINT32 SCROLL_SPEED_PX_PER_SEC;
-		static const Color GRAYED_OUT_COLOR;
+		static const Color CUT_COLOR;
+		static const Color DISABLED_COLOR;
 	};
 }

+ 1 - 1
BansheeEditor/Source/BsCmdBreakPrefab.cpp

@@ -35,7 +35,7 @@ namespace BansheeEngine
 		while (rootObj != nullptr)
 		{
 			if (!rootObj->_getPrefabLinkUUID().empty())
-				return;
+				break;
 
 			if (rootObj->getParent() != nullptr)
 				rootObj = rootObj->getParent();

+ 26 - 3
BansheeEditor/Source/BsGUISceneTreeView.cpp

@@ -20,6 +20,7 @@
 namespace BansheeEngine
 {
 	const MessageId GUISceneTreeView::SELECTION_CHANGED_MSG = MessageId("SceneTreeView_SelectionChanged");
+	const Color GUISceneTreeView::PREFAB_TINT = Color(1.0f, (168.0f / 255.0f), 0.0f, 1.0f);
 
 	DraggedSceneObjects::DraggedSceneObjects(UINT32 numObjects)
 		:numObjects(numObjects)
@@ -129,6 +130,7 @@ namespace BansheeEngine
 			{
 				HSceneObject currentSOChild = currentSO->getChild(i);
 				bool isInternal = currentSOChild->hasFlag(SOF_Internal);
+				bool isPrefabInstance = !currentSOChild->getPrefabLink().empty();
 
 #if BS_DEBUG_MODE == 0
 				if (isInternal)
@@ -162,7 +164,8 @@ namespace BansheeEngine
 					newChild->mName = currentSOChild->getName();
 					newChild->mSortedIdx = (UINT32)newChildren.size();
 					newChild->mIsVisible = element->mIsVisible && element->mIsExpanded;
-					newChild->mTint = isInternal ? Color::Red : Color::White;
+					newChild->mTint = isInternal ? Color::Red : (isPrefabInstance ? PREFAB_TINT : Color::White);
+					newChild->mIsPrefabInstance = isPrefabInstance;
 
 					newChildren.push_back(newChild);
 
@@ -192,6 +195,26 @@ namespace BansheeEngine
 			needsUpdate = true;	
 		}
 
+		// Check if active state needs updating
+		bool isDisabled = !element->mSceneObject->getActive();
+		if(element->mIsDisabled != isDisabled)
+		{
+			element->mIsDisabled = isDisabled;
+			needsUpdate = true;
+		}
+
+		// Check if prefab instance state needs updating
+		bool isPrefabInstance = !element->mSceneObject->getPrefabLink().empty();
+		if (element->mIsPrefabInstance != isPrefabInstance)
+		{
+			element->mIsPrefabInstance = isPrefabInstance;
+
+			bool isInternal = element->mSceneObject->hasFlag(SOF_Internal);
+			element->mTint = isInternal ? Color::Red : (isPrefabInstance ? PREFAB_TINT : Color::White);
+
+			needsUpdate = true;
+		}
+
 		if(needsUpdate)
 			updateElementGUI(element);
 
@@ -496,7 +519,7 @@ namespace BansheeEngine
 			SceneTreeElement* sceneElement = static_cast<SceneTreeElement*>(selectedElem.element);
 			mCopyList.push_back(sceneElement->mSceneObject);
 
-			sceneElement->mIsGrayedOut = true;
+			sceneElement->mIsCut = true;
 			updateElementGUI(sceneElement);
 		}
 
@@ -556,7 +579,7 @@ namespace BansheeEngine
 
 			if (treeElem != nullptr)
 			{
-				treeElem->mIsGrayedOut = false;
+				treeElem->mIsCut = false;
 				updateElementGUI(treeElem);
 			}
 		}

+ 14 - 6
BansheeEditor/Source/BsGUITreeView.cpp

@@ -26,7 +26,8 @@ namespace BansheeEngine
 	const float GUITreeView::AUTO_EXPAND_DELAY_SEC = 0.5f;
 	const float GUITreeView::SCROLL_AREA_HEIGHT_PCT = 0.1f;
 	const UINT32 GUITreeView::SCROLL_SPEED_PX_PER_SEC = 100;
-	const Color GUITreeView::GRAYED_OUT_COLOR = Color(1.0f, 1.0f, 1.0f, 0.5f);
+	const Color GUITreeView::CUT_COLOR = Color(1.0f, 1.0f, 1.0f, 0.3f);
+	const Color GUITreeView::DISABLED_COLOR = Color(1.0f, 1.0f, 1.0f, 0.6f);
 
 	VirtualButton GUITreeView::mRenameVB = VirtualButton("Rename");
 	VirtualButton GUITreeView::mDeleteVB = VirtualButton("Delete");
@@ -37,7 +38,7 @@ namespace BansheeEngine
 
 	GUITreeView::TreeElement::TreeElement()
 		:mParent(nullptr), mFoldoutBtn(nullptr), mElement(nullptr), mIsSelected(false),
-		mIsExpanded(false), mSortedIdx(0), mIsVisible(true), mIsHighlighted(false), mIsGrayedOut(false)
+		mIsExpanded(false), mSortedIdx(0), mIsVisible(true), mIsHighlighted(false), mIsCut(false), mIsDisabled(false)
 	{ }
 
 	GUITreeView::TreeElement::~TreeElement()
@@ -787,12 +788,19 @@ namespace BansheeEngine
 				_registerChildElement(element->mElement);
 			}
 
-			if (element->mIsGrayedOut)
+			if (element->mIsCut)
 			{
-				Color grayedOutTint = element->mTint;
-				grayedOutTint.a = GRAYED_OUT_COLOR.a;
+				Color cutTint = element->mTint;
+				cutTint.a = CUT_COLOR.a;
 
-				element->mElement->setTint(grayedOutTint);
+				element->mElement->setTint(cutTint);
+			}
+			else if(element->mIsDisabled)
+			{
+				Color disabledTint = element->mTint;
+				disabledTint.a = DISABLED_COLOR.a;
+
+				element->mElement->setTint(disabledTint);
 			}
 			else
 				element->mElement->setTint(element->mTint);

+ 3 - 0
BansheeEditor/Source/BsSelectionRenderer.cpp

@@ -56,6 +56,9 @@ namespace BansheeEngine
 		{
 			for (auto& so : sceneObjects)
 			{
+				if (!so->getActive())
+					continue;
+
 				if (renderable.second.sceneObject != so)
 					continue;
 

+ 17 - 0
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -62,6 +62,7 @@ namespace BansheeEditor
         private InspectableState modifyState;
         private int undoCommandIdx = -1;
         private GUITextBox soNameInput;
+        private GUIToggle soActiveToggle;
         private GUILayout soPrefabLayout;
         private bool soHasPrefab;
         private GUIFloatField soPosX;
@@ -223,6 +224,8 @@ namespace BansheeEditor
             GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1);
 
             GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX();
+            soActiveToggle = new GUIToggle("");
+            soActiveToggle.OnToggled += OnSceneObjectActiveStateToggled;
             GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50));
             soNameInput = new GUITextBox(false, GUIOption.FlexibleWidth(180));
             soNameInput.Text = activeSO.Name;
@@ -230,6 +233,8 @@ namespace BansheeEditor
             soNameInput.OnConfirmed += OnModifyConfirm;
             soNameInput.OnFocusLost += OnModifyConfirm;
 
+            nameLayout.AddElement(soActiveToggle);
+            nameLayout.AddSpace(3);
             nameLayout.AddElement(nameLbl);
             nameLayout.AddElement(soNameInput);
             nameLayout.AddFlexibleSpace();
@@ -337,6 +342,7 @@ namespace BansheeEditor
                 return;
 
             soNameInput.Text = activeSO.Name;
+            soActiveToggle.Value = activeSO.Active;
 
             bool hasPrefab = PrefabUtility.IsPrefabInstance(activeSO);
             if (soHasPrefab != hasPrefab || forceUpdate)
@@ -671,6 +677,7 @@ namespace BansheeEditor
 
             activeSO = null;
             soNameInput = null;
+            soActiveToggle = null;
             soPrefabLayout = null;
             soHasPrefab = false;
             soPosX = null;
@@ -711,6 +718,16 @@ namespace BansheeEditor
             }
         }
 
+        /// <summary>
+        /// Triggered when the user changes the active state of the scene object.
+        /// </summary>
+        /// <param name="active">True if the object is active, false otherwise.</param>
+        private void OnSceneObjectActiveStateToggled(bool active)
+        {
+            if (activeSO != null)
+                activeSO.Active = active;
+        }
+
         /// <summary>
         /// Triggered when the scene object modification is confirmed by the user.
         /// </summary>