Jelajahi Sumber

Finished implementation of changing tabs between scene and game when the play button is pressed

Carlos Marti 9 tahun lalu
induk
melakukan
c50e7d7df2

+ 7 - 2
Source/BansheeEditor/Include/BsEditorWidget.h

@@ -57,7 +57,7 @@ namespace BansheeEngine
 		bool hasFocus() const { return mHasFocus; }
 
 		// sets the widget active or non active
-		void setActive(bool active);
+		void setActive(UINT32 widgetIndx);
 
 		/** 
 		 * Checks is the widget the currently active widget in its container. This means the widget's tab is active or
@@ -65,6 +65,10 @@ namespace BansheeEngine
 		 */
 		bool isActive() const { return mIsActive; }
 
+		void setIndex(UINT32 index);
+
+		UINT32 getIndex();
+
 		/**
 		 * Gets the parent editor window this widget is docked in. Can be null (for example when widget is in the process of
 		 * dragging and not visible).
@@ -108,7 +112,7 @@ namespace BansheeEngine
 		 * Changes the parent container of the widget (for example when re-docking or moving a widget to another window). 
 		 * Parent can be null (for example when widget is in the process of dragging and not visible).
 		 */
-		void _changeParent(EditorWidgetContainer* parent);
+		void _changeParent(EditorWidgetContainer* parent, UINT32 indx);
 
 		/**	Sets or removes focus for this widget. */
 		void _setHasFocus(bool focus);
@@ -151,6 +155,7 @@ namespace BansheeEngine
 		INT32 mX, mY;
 		UINT32 mWidth, mHeight;
 		UINT32 mDefaultWidth, mDefaultHeight;
+		UINT32 mIndex = 0;
 		GUIPanel* mContent;
 		bool mHasFocus;
 		bool mIsActive;

+ 14 - 3
Source/BansheeEditor/Source/BsEditorWidget.cpp

@@ -35,6 +35,16 @@ namespace BansheeEngine
 			return nullptr;
 	}
 
+	void EditorWidgetBase::setIndex(UINT32 index)
+	{
+		mIndex = index;
+	}
+
+	UINT32 EditorWidgetBase::getIndex()
+	{
+		return mIndex;
+	}
+
 	void EditorWidgetBase::setHasFocus(bool focus)
 	{
 		EditorWidgetContainer* parentContainer = _getParent();
@@ -54,13 +64,13 @@ namespace BansheeEngine
 		_setHasFocus(focus);
 	}
 
-	void EditorWidgetBase::setActive(bool active)
+	void EditorWidgetBase::setActive(UINT32 widgetIndx)
 	{
 		EditorWidgetContainer* parentContainer = _getParent();
 		if (parentContainer == nullptr)
 			return;
 
-		parentContainer->setActiveWidget();
+		parentContainer->setActiveWidget(widgetIndx);
 	}
 
 	void EditorWidgetBase::close()
@@ -161,7 +171,7 @@ namespace BansheeEngine
 	}
 
 	// Note: Must not be virtual as parent container uses it in constructor
-	void EditorWidgetBase::_changeParent(EditorWidgetContainer* parent)
+	void EditorWidgetBase::_changeParent(EditorWidgetContainer* parent, UINT32 indx)
 	{
 		if(mParent != parent) 
 		{
@@ -179,6 +189,7 @@ namespace BansheeEngine
 			}
 
 			mParent = parent;
+			mIndex = indx;
 
 			doOnParentChanged();
 

+ 2 - 2
Source/BansheeEditor/Source/BsEditorWidgetContainer.cpp

@@ -90,7 +90,7 @@ namespace BansheeEngine
 
 		mWidgets.erase((UINT32)tabIdx);
 		mTitleBar->removeTab((UINT32)tabIdx);
-		widget._changeParent(nullptr);
+		widget._changeParent(nullptr, tabIdx);
 
 		if(tabIdx == mActiveWidget)
 		{
@@ -111,7 +111,7 @@ namespace BansheeEngine
 
 		UINT32 tabIdx = mTitleBar->insertTab(idx, widget.getDisplayName());
 		mWidgets[tabIdx] = &widget;
-		widget._changeParent(this);
+		widget._changeParent(this, idx);
 
 		if(mActiveWidget == -1)
 			setActiveWidget(mTitleBar->getTabIdx(mTitleBar->getNumTabs() - 1));

+ 0 - 5
Source/MBansheeEditor/Window/EditorWindow.cs

@@ -83,11 +83,6 @@ namespace BansheeEditor
             get { return Internal_IsActive(mCachedPtr); }
         }
 
-        public UInt32 WidgetIndx
-        {
-            get { return Internal_GetIndex(mCachedPtr); }
-        }
-
         /// <summary>
         /// GUI panel that you may use for adding GUI elements to the window.
         /// </summary>

+ 22 - 16
Source/MBansheeEditor/Windows/GameWindow.cs

@@ -28,6 +28,7 @@ namespace BansheeEditor
         private GUIRenderTexture renderTextureGUI;
         private GUITexture renderTextureBg;
         private GUILabel noCameraLabel;
+        public static bool playBtnPressed = false;
 
         /// <summary>
         /// Opens the game window.
@@ -45,27 +46,32 @@ namespace BansheeEditor
         [ToolbarItem("Play", ToolbarIcon.Play, "Play", 1800, true)]
         private static void Play()
         {
+            if (!playBtnPressed)
+            {
+
+                GetWindow<GameWindow>().Active = true;
+                GetWindow<GameWindow>().HasFocus = true;
+
+                playBtnPressed = true;
+            }
+            else if(playBtnPressed)
+            {
+
+                GetWindow<GameWindow>().HasFocus = false;
+
+                GetWindow<SceneWindow>().Active = true;
+                GetWindow<SceneWindow>().HasFocus = true;
+                Debug.Log("Got into the scenewindow");
+                playBtnPressed = false;
+            }
+
             if (EditorApplication.IsPaused)
             {
-                if (!GetWindow<GameWindow>().HasFocus)
-                {
-                    GetWindow<GameWindow>().HasFocus = true;
-                    GetWindow<GameWindow>().Active = true;
-                }
+                
+                Debug.Log("rannin the game");
                 EditorApplication.IsPaused = false;
             }
             else
-                if(GetWindow<GameWindow>().HasFocus && GetWindow<GameWindow>().Active)
-                {
-                    
-                    GetWindow<GameWindow>().HasFocus = false;
-                    GetWindow<GameWindow>().Active = false;
-
-                
-                    GetWindow<SceneWindow>().HasFocus = true;
-                    GetWindow<SceneWindow>().Active = true;
-                    
-                }
                 EditorApplication.IsPlaying = !EditorApplication.IsPlaying;
         }
 

+ 14 - 1
Source/SBansheeEditor/Source/BsScriptEditorWindow.cpp

@@ -60,6 +60,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_GetBounds", &ScriptEditorWindow::internal_getBounds);
 		metaData.scriptClass->addInternalCall("Internal_SetFocus", &ScriptEditorWindow::internal_setFocus);
 		metaData.scriptClass->addInternalCall("Internal_HasFocus", &ScriptEditorWindow::internal_hasFocus);
+		metaData.scriptClass->addInternalCall("Internal_SetActive", &ScriptEditorWindow::internal_setActive);
 		metaData.scriptClass->addInternalCall("Internal_IsActive", &ScriptEditorWindow::internal_isActive);
 		metaData.scriptClass->addInternalCall("Internal_IsPointerHovering", &ScriptEditorWindow::internal_isPointerHovering);
 		metaData.scriptClass->addInternalCall("Internal_ScreenToWindowPos", &ScriptEditorWindow::internal_screenToWindowPos);
@@ -205,7 +206,19 @@ namespace BansheeEngine
 	{
 		//check and see if the window is destroyed before setting it to active
 		if (!thisPtr->isDestroyed())
-			return thisPtr->getEditorWidget()->setActive(active);
+		{
+			if (active)
+			{
+				thisPtr->getEditorWidget()->setActive(thisPtr->getEditorWidget()->getIndex()); 
+				return;
+			}
+			else
+			{
+				return;
+			}
+				
+		}
+			
 
 		//return if the given widget is destroyed
 		return;