Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions DevHelper/DevHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,28 +17,40 @@ public partial class DevHelper : MonoBehaviour
public bool autoLoadScene = true;
public string autoLoadSceneName = "VAB";

private void log(string msg)
{
Debug.Log("[DevHelper] " + msg);
}

private List<string> 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();
}

//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();
Expand Down Expand Up @@ -91,16 +102,21 @@ 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;
break;
case "Space Center":
HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER;
break;
case "Flight":
HighLogic.CurrentGame.startScene = GameScenes.FLIGHT;
break;
default:
HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER;
break;
Expand All @@ -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;
Expand All @@ -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;
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions DevHelper/GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down