Pārlūkot izejas kodu

Do not allow editor to be active without a project loaded

BearishSun 10 gadi atpakaļ
vecāks
revīzija
648eefad79

+ 13 - 3
MBansheeEditor/EditorApplication.cs

@@ -368,8 +368,7 @@ namespace BansheeEditor
         }
 
         /// <summary>
-        /// Loads the project at the specified path. This method executes asynchronously and will trigger 
-        /// <see cref="OnProjectLoaded"/> when done.
+        /// Loads the project at the specified path. This method executes asynchronously.
         /// </summary>
         /// <param name="path">Absolute path to the project's root folder.</param>
         public static void LoadProject(string path)
@@ -386,7 +385,15 @@ namespace BansheeEditor
             if (IsProjectLoaded)
                 UnloadProject();
 
-            Internal_LoadProject(path); // Triggers OnProjectLoaded when done
+            Internal_LoadProject(path); // Triggers Internal_OnProjectLoaded when done
+        }
+
+        /// <summary>
+        /// Closes the editor.
+        /// </summary>
+        public static void Quit()
+        {
+            Internal_Quit();
         }
 
         /// <summary>
@@ -682,5 +689,8 @@ namespace BansheeEditor
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_RunUnitTests();
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Quit();
     }
 }

+ 24 - 7
MBansheeEditor/ProjectWindow.cs

@@ -30,7 +30,7 @@ namespace BansheeEditor
         /// Constructs a new project window.
         /// </summary>
         protected ProjectWindow()
-            : base(true)
+            : base(false)
         {
 
         }
@@ -40,7 +40,7 @@ namespace BansheeEditor
             Title = "Project Manager";
 
             Width = 500;
-            Height = 300;
+            Height = 290;
 
             GUILayout vertLayout = GUI.AddLayoutY();
             
@@ -78,7 +78,13 @@ namespace BansheeEditor
 
             thirdRow.AddSpace(5);
             GUIPanel recentProjectsPanel = thirdRow.AddPanel();
-            thirdRow.AddSpace(15 + 5 + 75);
+            thirdRow.AddSpace(15);
+            GUILayoutY thirdRowVertical = thirdRow.AddLayoutY();
+            GUIButton createBtn = new GUIButton(new LocEdString("Create new"), GUIOption.FixedWidth(75));
+            createBtn.OnClick += CreateClicked;
+            thirdRowVertical.AddElement(createBtn);
+            thirdRowVertical.AddFlexibleSpace();
+            thirdRow.AddSpace(5);
 
             recentProjectsArea = new GUIScrollArea(GUIOption.FixedWidth(385), GUIOption.FixedHeight(170));
             GUILayoutX recentProjectsLayout = recentProjectsPanel.AddLayoutX();
@@ -98,14 +104,14 @@ namespace BansheeEditor
 
             GUILabel autoLoadLabel = new GUILabel(new LocEdString("Automatically load last open project"));
 
-            GUIButton createBtn = new GUIButton(new LocEdString("Create new"), GUIOption.FixedWidth(75));
-            createBtn.OnClick += CreateClicked;
+            GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"), GUIOption.FixedWidth(75));
+            cancelBtn.OnClick += CancelClicked;
 
             fourthRow.AddSpace(5);
             fourthRow.AddElement(autoLoadToggle);
             fourthRow.AddElement(autoLoadLabel);
             fourthRow.AddFlexibleSpace();
-            fourthRow.AddElement(createBtn);
+            fourthRow.AddElement(cancelBtn);
             fourthRow.AddSpace(5);
 
             RefreshRecentProjects();
@@ -177,7 +183,7 @@ namespace BansheeEditor
 
         /// <summary>
         /// Triggered when the user clicks on the create buttons. Opens a browse dialog that allows the user to select
-        /// a folde to a new project to create. Project data will be initialized in the chosen folder and new project
+        /// a folder to a new project to create. Project data will be initialized in the chosen folder and new project
         /// will be opened.
         /// </summary>
         void CreateClicked()
@@ -196,6 +202,17 @@ namespace BansheeEditor
             }
         }
 
+        /// <summary>
+        /// Triggered when the user clicks the cancel button.
+        /// </summary>
+        void CancelClicked()
+        {
+            if (EditorApplication.IsProjectLoaded)
+                Close(); // Just close the window
+            else
+                EditorApplication.Quit(); // Close the application, we cannot do anything without a project
+        }
+
         /// <summary>
         /// Updates GUI for the recent projects list.
         /// </summary>

+ 1 - 0
SBansheeEditor/Include/BsScriptEditorApplication.h

@@ -67,6 +67,7 @@ namespace BansheeEngine
 		static void internal_ReloadAssemblies();
 		static void internal_OpenExternally(MonoString* path);
 		static void internal_RunUnitTests();
+		static void internal_Quit();
 
 		typedef void(__stdcall *OnProjectLoadedThunkDef)(MonoException**);
 		typedef void(__stdcall *OnStatusBarClickedThunkDef) (MonoException**);

+ 6 - 0
SBansheeEditor/Source/BsScriptEditorApplication.cpp

@@ -64,6 +64,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_ReloadAssemblies", &ScriptEditorApplication::internal_ReloadAssemblies);
 		metaData.scriptClass->addInternalCall("Internal_OpenExternally", &ScriptEditorApplication::internal_OpenExternally);
 		metaData.scriptClass->addInternalCall("Internal_RunUnitTests", &ScriptEditorApplication::internal_RunUnitTests);
+		metaData.scriptClass->addInternalCall("Internal_Quit", &ScriptEditorApplication::internal_Quit);
 
 		onProjectLoadedThunk = (OnProjectLoadedThunkDef)metaData.scriptClass->getMethod("Internal_OnProjectLoaded")->getThunk();
 		onStatusBarClickedThunk = (OnStatusBarClickedThunkDef)metaData.scriptClass->getMethod("Internal_OnStatusBarClicked")->getThunk();
@@ -275,4 +276,9 @@ namespace BansheeEngine
 		testSuite->run(testOutput);
 #endif
 	}
+
+	void ScriptEditorApplication::internal_Quit()
+	{
+		gApplication().stopMainLoop();
+	}
 }

+ 2 - 1
SBansheeEditor/Source/BsScriptModalWindow.cpp

@@ -145,7 +145,8 @@ namespace BansheeEngine
 
 	ManagedModalWindow::~ManagedModalWindow()
 	{
-		assert(mGCHandle == 0); // We expect "close" to be called either from C++ or C# before destruction
+		if (mGCHandle != 0)
+			close();
 	}
 
 	bool ManagedModalWindow::createManagedInstance()