Skip to content

Commit

Permalink
Update to 1.2, performance enhancements, bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
CliftonMarien committed Oct 9, 2016
1 parent 52d5f19 commit 0183011
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 56 deletions.
13 changes: 8 additions & 5 deletions AnyRes/AnyRes.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -33,7 +33,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="KSPAssets">
<HintPath>..\..\..\Desktop\KSPData\KSPAssets.dll</HintPath>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\KSPAssets.dll</HintPath>
</Reference>
<Reference Include="KSPCore">
<HintPath>..\..\..\Desktop\KSPData\KSPCore.dll</HintPath>
Expand All @@ -42,13 +42,16 @@
<HintPath>..\..\..\Desktop\KSPData\KSPUtil.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\Desktop\KSPData\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\Desktop\KSPData\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\Desktop\KSPData\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
123 changes: 73 additions & 50 deletions AnyRes/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace AnyRes
{

[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class AnyRes : MonoBehaviour
{

Expand All @@ -23,72 +23,81 @@ public class AnyRes : MonoBehaviour
public bool fullScreen = true;
public bool reloadScene = false;

private static ApplicationLauncherButton appLauncherButton;
private static ApplicationLauncherButton appLauncherButton = null;

Presets presets;



void Start() {

Debug.Log ("[AnyRes] Loaded");
if (HighLogic.LoadedScene == GameScenes.SETTINGS)
{

presets = gameObject.AddComponent<Presets> () as Presets;
windowEnabled = true;
anyresWinRect.x = 7;
anyresWinRect.y = 231;

//Thanks bananashavings http://forum.kerbalspaceprogram.com/index.php?/profile/156147-bananashavings/ - https://gist.github.com/bananashavings/e698f4359e1628b5d6ef
//Also thanks to Crzyrndm for the fix to that code!
if (appLauncherButton == null) {

appLauncherButton = ApplicationLauncher.Instance.AddModApplication(
() => { windowEnabled = true; },
() => { presets.newEnabled = false; presets.loadEnabled = false; presets.windowEnabled = false; windowEnabled = false; },
() => { },
() => { },
() => { },
() => { },
ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW | ApplicationLauncher.AppScenes.SPACECENTER | ApplicationLauncher.AppScenes.SPH | ApplicationLauncher.AppScenes.TRACKSTATION | ApplicationLauncher.AppScenes.VAB,
(Texture)GameDatabase.Instance.GetTexture("AnyRes/textures/toolbar", false));

}
Debug.Log("[AnyRes] 1");

xString = GameSettings.SCREEN_RESOLUTION_WIDTH.ToString ();
yString = GameSettings.SCREEN_RESOLUTION_HEIGHT.ToString ();
fullScreen = GameSettings.FULLSCREEN;
Debug.Log("[AnyRes] 2");

if (HighLogic.LoadedScene == GameScenes.SETTINGS) {
}
else if (HighLogic.LoadedScene == GameScenes.EDITOR)
{

windowEnabled = true;
anyresWinRect.x = 35;
anyresWinRect.y = 99;
anyresWinRect.x = Screen.width - 272;
anyresWinRect.y = Screen.height - 231;

} else if (HighLogic.LoadedScene == GameScenes.EDITOR) {
}

anyresWinRect.x = 1008;
anyresWinRect.y = 489;
Debug.Log ("[AnyRes] Loaded");

} else {
presets = gameObject.AddComponent<Presets> () as Presets;

anyresWinRect.x = 35;
anyresWinRect.y = 99;

//Debug.Log("[AnyRes] 1");

xString = GameSettings.SCREEN_RESOLUTION_WIDTH.ToString ();
yString = GameSettings.SCREEN_RESOLUTION_HEIGHT.ToString ();
fullScreen = GameSettings.FULLSCREEN;
//Debug.Log("[AnyRes] 2");

}
DontDestroyOnLoad(this);
//DontDestroyOnLoad(this);

}

public void OnDisable ()
{

//Destroy the button in order to create a new one. It's required with multiple scene handling, unfortunately.
ApplicationLauncher.Instance.RemoveModApplication (appLauncherButton);
appLauncherButton = null;
Debug.Log ("[AnyRes] Remove application button");
//Destroy the button in order to create a new one. It's required with multiple scene handling, unfortunately.
if (appLauncherButton != null)
{
ApplicationLauncher.Instance.RemoveModApplication(appLauncherButton);
appLauncherButton = null;
Debug.Log("[AnyRes] Remove application button");
}

}

void Update() {

if ((GameSettings.MODIFIER_KEY.GetKey() ) && Input.GetKeyDown (KeyCode.Slash)) {
//Thanks bananashavings http://forum.kerbalspaceprogram.com/index.php?/profile/156147-bananashavings/ - https://gist.github.com/bananashavings/e698f4359e1628b5d6ef
//Also thanks to Crzyrndm for the fix to that code!
//(HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.EDITOR)
if (appLauncherButton == null && (HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.EDITOR))
{

appLauncherButton = ApplicationLauncher.Instance.AddModApplication(
() => { windowEnabled = true; },
() => { presets.newEnabled = false; presets.loadEnabled = false; presets.windowEnabled = false; windowEnabled = false; },
() => { },
() => { },
() => { },
() => { },
ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW | ApplicationLauncher.AppScenes.SPACECENTER | ApplicationLauncher.AppScenes.SPH | ApplicationLauncher.AppScenes.TRACKSTATION | ApplicationLauncher.AppScenes.VAB,
(Texture)GameDatabase.Instance.GetTexture("AnyRes/textures/toolbar", false));

}

if ((GameSettings.MODIFIER_KEY.GetKey() ) && Input.GetKeyDown (KeyCode.Slash)) {

windowEnabled = !windowEnabled;
if (ApplicationLauncher.Ready) {
Expand All @@ -108,14 +117,21 @@ void Update() {
}

}

presets.windowRect.x = anyresWinRect.xMin + anyresWinRect.width;
presets.windowRect.y = anyresWinRect.yMin;
presets.loadRect.x = presets.windowRect.xMin + presets.windowRect.width;
presets.loadRect.y = presets.windowRect.yMin;
presets.newRect.x = presets.windowRect.xMin + presets.windowRect.width;
presets.newRect.y = anyresWinRect.yMin;

// Meant for debugging
// Debug.Log ("X: " + windowRect.x.ToString ());
// Debug.Log ("Y: " + windowRect.y.ToString ());
// Meant for debugging
// Debug.Log ("X: " + anyresWinRect.x.ToString ());
// Debug.Log ("Y: " + anyresWinRect.y.ToString ());



}
}

void OnGUI() {

Expand All @@ -140,9 +156,16 @@ void GUIActive(int windowID) {
}
else
{
presets.windowRect = new Rect(anyresWinRect.xMin + anyresWinRect.width, anyresWinRect.yMin, 200, 100);
presets.loadRect = new Rect(presets.windowRect.xMin + presets.windowRect.width, anyresWinRect.yMin, 200, 400);
presets.newRect = new Rect(presets.windowRect.xMin + presets.windowRect.width, anyresWinRect.yMin, 200, 230);
//presets.windowRect = new Rect(anyresWinRect.xMin + anyresWinRect.width, anyresWinRect.yMin, 200, 100);
presets.windowRect.x = anyresWinRect.xMin + anyresWinRect.width;
presets.windowRect.y = anyresWinRect.yMin;
//presets.loadRect = new Rect(presets.windowRect.xMin + presets.windowRect.width, anyresWinRect.yMin, 200, 400);
presets.loadRect.x = presets.windowRect.xMin + presets.windowRect.width;
presets.loadRect.y = presets.windowRect.yMin;
//presets.newRect = new Rect(presets.windowRect.xMin + presets.windowRect.width, anyresWinRect.yMin, 200, 230);
presets.newRect.x = presets.windowRect.xMin + presets.windowRect.width;
presets.newRect.y = anyresWinRect.yMin;

}
}

Expand Down
2 changes: 1 addition & 1 deletion AnyRes/Presets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void OnGUI () {

if (loadEnabled) {

loadRect = GUI.Window (09273, loadRect, onLoad, "Load Preset");
loadRect = GUI.Window (09274, loadRect, onLoad, "Load Preset");

}

Expand Down

0 comments on commit 0183011

Please sign in to comment.