diff --git a/DevHelper/DevHelper.cs b/DevHelper/DevHelper.cs index 7e48cdd..64ca776 100644 --- a/DevHelper/DevHelper.cs +++ b/DevHelper/DevHelper.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Xml.Serialization; using UnityEngine; +using UnityEngine.SceneManagement; using KSP.IO; //using MuMech; @@ -18,10 +17,15 @@ public partial class DevHelper : MonoBehaviour public bool autoLoadScene = true; public string autoLoadSceneName = "VAB"; + private void log(string msg) + { + Debug.Log("[DevHelper] " + msg); + } + private List saveNames; private void FindSaves() { - print("FindSaves"); + log("FindSaves"); var dirs = Directory.GetDirectories(KSPUtil.ApplicationRootPath + "saves\\"); saveNames = dirs.Where(x => System.IO.File.Exists(x + "\\persistent.sfs")).Select(x => x.Split(new[] { '\\' })[1]).ToList(); } @@ -29,17 +33,24 @@ private void FindSaves() //IButton DHReloadDatabase; private void Awake() { - print("Injector awake"); + log("Injector awake"); DontDestroyOnLoad(this); } + + void OnEnable() + { + log("Injector enabled"); + SceneManager.sceneLoaded += OnSceneLoaded; + } + private void Start() { - print("DevHelper Starting"); + log("DevHelper Starting"); if (ToolbarManager.ToolbarAvailable) { DHButtons(); - Debug.Log("buttons loaded"); + log("buttons loaded"); } loadConfigXML(); @@ -91,9 +102,11 @@ private void Update() { case "VAB": HighLogic.CurrentGame.startScene = GameScenes.EDITOR; + HighLogic.CurrentGame.editorFacility = EditorFacility.VAB; break; case "SPH": - HighLogic.CurrentGame.startScene = GameScenes.SPH; + HighLogic.CurrentGame.startScene = GameScenes.EDITOR; + HighLogic.CurrentGame.editorFacility = EditorFacility.SPH; break; case "Tracking Station": HighLogic.CurrentGame.startScene = GameScenes.TRACKSTATION; @@ -101,6 +114,9 @@ private void Update() case "Space Center": HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER; break; + case "Flight": + HighLogic.CurrentGame.startScene = GameScenes.FLIGHT; + break; default: HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER; break; @@ -127,7 +143,7 @@ internal void DHButtons() DHReloadDatabase = ToolbarManager.Instance.add("DevHelper", "DHReloadGD"); DHReloadDatabase.TexturePath = "DevHelper/Textures/icon_buttonReload"; DHReloadDatabase.ToolTip = "Reload Game Database"; - DHReloadDatabase.Visibility = new GameScenesVisibility(GameScenes.EDITOR, GameScenes.SPH, GameScenes.SPACECENTER); + DHReloadDatabase.Visibility = new GameScenesVisibility(GameScenes.EDITOR); DHReloadDatabase.OnClick += (e) => { GameDatabase.Instance.Recompile = true; @@ -144,18 +160,17 @@ void OnDestroy() DHReloadDatabase.Destroy(); } } - - - private bool isTooLateToLoad = false; - - public void OnLevelWasLoaded(int level) + private bool isTooLateToLoad = false; + void OnSceneLoaded(Scene scene, LoadSceneMode mode) { - print("OnLevelWasLoaded:" + level); - + log("OnSceneLoaded for Scene " + scene.name); if (PSystemManager.Instance != null && ScaledSpace.Instance == null) { isTooLateToLoad = true; + log("It's now too late to load"); + // we no longer need this callback + SceneManager.sceneLoaded -= OnSceneLoaded; } } } diff --git a/DevHelper/GUI.cs b/DevHelper/GUI.cs index b970835..10040c4 100644 --- a/DevHelper/GUI.cs +++ b/DevHelper/GUI.cs @@ -39,11 +39,14 @@ private void InitComboBox() private void InitComboBoxScenes() { - comboBoxSelectedList = new GUIContent[4]; - comboBoxSelectedList[0] = new GUIContent("VAB"); - comboBoxSelectedList[1] = new GUIContent("SPH"); - comboBoxSelectedList[2] = new GUIContent("Tracking Station"); - comboBoxSelectedList[3] = new GUIContent("Space Center"); + comboBoxSelectedList = new GUIContent[] + { + new GUIContent("VAB"), + new GUIContent("SPH"), + new GUIContent("Tracking Station"), + new GUIContent("Space Center"), + new GUIContent("Flight"), + }; comboBoxControlSpecificScene.SelectedItemIndex = comboBoxSelectedList.ToList().FindIndex(x => x.text == autoLoadSceneName); //Debug.Log("scene index: " + comboBoxControlSpecificScene.SelectedItemIndex); listStyle.normal.textColor = Color.white;