Skip to content

Commit

Permalink
Merge 2.8.0.0 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
TriggerAu committed Jun 12, 2016
2 parents 505b3b7 + 94ddb84 commit 5f75a6b
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 91 deletions.
44 changes: 25 additions & 19 deletions AlternateResourcePanel/ARP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;

using KSP;
using KSP.UI.Screens;
using UnityEngine;
using KSPPluginFramework;

Expand All @@ -24,7 +25,7 @@ private KSPAlternateResourcePanel()
internal ARPWindowSettings windowSettings;
internal ARPWindowResourceConfig windowResourceConfig;

internal Rect windowMainResetPos = new Rect(Screen.width - 298, 40, 299, 20);
internal Rect windowMainResetPos = new Rect(Screen.width - 381, 0, 299, 20);
//variables
internal PartResourceVisibleList SelectedResources;

Expand Down Expand Up @@ -152,16 +153,17 @@ internal override void Awake()
InitDebugWindow();

//plug us in to the draw queue and start the worker
RenderingManager.AddToPostDrawQueue(1, DrawGUI);
//Disabled for Unity5
//RenderingManager.AddToPostDrawQueue(1, DrawGUI);
StartRepeatingWorker(10);

//register for stage separation events - so we can cancel the noise on a sep
GameEvents.onStageActivate.Add(OnStageActivate);
GameEvents.onFlightReady.Add(OnFlightReady);

//Hook the App Launcher
OnGUIAppLauncherReady();
//GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
GameEvents.onGUIApplicationLauncherDestroyed.Add(DestroyAppLauncherButton);
GameEvents.onGUIApplicationLauncherUnreadifying.Add(OnGUIAppLauncherUnreadifying);

//do the daily version check if required
Expand All @@ -184,12 +186,14 @@ internal override void OnDestroy()
lstResourcesVessel.OnMonitorStateChanged -= lstResourcesVessel_OnMonitorStateChanged;
lstResourcesVessel.OnAlarmStateChanged -= lstResourcesVessel_OnAlarmStateChanged;

RenderingManager.RemoveFromPostDrawQueue(1, DrawGUI);
//Disabled for Unity5
//RenderingManager.RemoveFromPostDrawQueue(1, DrawGUI);

GameEvents.onStageActivate.Remove(OnStageActivate);
GameEvents.onFlightReady.Remove(OnFlightReady);

//GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
GameEvents.onGUIApplicationLauncherDestroyed.Remove(DestroyAppLauncherButton);
GameEvents.onGUIApplicationLauncherUnreadifying.Remove(OnGUIAppLauncherUnreadifying);
DestroyAppLauncherButton();

Expand Down Expand Up @@ -221,7 +225,7 @@ void OnStageActivate(Int32 StageNum)

void OnFlightReady()
{
AutoStagingMaxStage = Staging.StageCount-1;
AutoStagingMaxStage = StageManager.StageCount-1;
}

// void lstResourcesVessel_OnMonitorStateChange(ARPResource sender, ARPResource.MonitorStateEnum alarmType, bool TurnedOn,Boolean AlarmAcknowledged)
Expand Down Expand Up @@ -408,8 +412,12 @@ internal override void OnGUIOnceOnly()
//Hover Status for mouse
internal static Boolean ShowAll = false;

void DrawGUI()

internal override void OnGUIEvery()
{
//base.OnGUIEvery();


//Draw the button - if we arent using blizzy's toolbar
//if (!(settings.BlizzyToolbarIsAvailable && settings.UseBlizzyToolbarIfAvailable))
if (settings.ButtonStyleToDisplay == ARPWindowSettings.ButtonStyleEnum.Basic)
Expand Down Expand Up @@ -523,7 +531,7 @@ internal override void RepeatingWorker()
lstResourcesLastStage.StartUpdatingList(settings.ShowRates, RatePeriod);

//sort out the per stage list
for (int i = 0; i <= Staging.StageCount; i++)
for (int i = 0; i <= StageManager.StageCount; i++)
{
if (!lstResourcesVesselPerStage.ContainsKey(i))
{
Expand Down Expand Up @@ -604,7 +612,7 @@ internal override void RepeatingWorker()
}

//Update the whole vessel list
lstResourcesVesselPerStage[p.DecoupledAt().Clamp(1, Staging.StageCount)].UpdateResource(pr);
lstResourcesVesselPerStage[p.DecoupledAt().Clamp(1, StageManager.StageCount)].UpdateResource(pr);

//is the resource in the selected list
if (SelectedResources.ContainsKey(pr.info.id) && SelectedResources[pr.info.id].AllVisible && !settings.Resources[pr.info.id].ShowReserveLevels)
Expand Down Expand Up @@ -650,7 +658,7 @@ internal override void RepeatingWorker()
lstStage.EndUpdatingList(settings.ShowRates);
}

//List<Int32> StagesToDelete = lstResourcesVesselPerStage.Select(x => x.Key).Where(x => x > Staging.StageCount).ToList();
//List<Int32> StagesToDelete = lstResourcesVesselPerStage.Select(x => x.Key).Where(x => x > StageManager.StageCount).ToList();
//foreach (Int32 stageID in StagesToDelete) {
// LogFormatted_DebugOnly("Removing Stage {0}", stageID);
// lstResourcesVesselPerStage.Remove(stageID);
Expand Down Expand Up @@ -779,7 +787,7 @@ internal override void RepeatingWorker()
//now do the autostaging stuff
lstLastStageEngineModules = lstPartsLastStageEngines.SelectMany(x => x.Modules.OfType<ModuleEngines>()).ToList();
lstLastStageEngineFXModules = lstPartsLastStageEngines.SelectMany(x => x.Modules.OfType<ModuleEnginesFX>()).ToList();
AutoStagingMaxStage = Mathf.Min(AutoStagingMaxStage, Staging.StageCount - 1);
AutoStagingMaxStage = Mathf.Min(AutoStagingMaxStage, StageManager.StageCount - 1);
AutoStagingTerminateAt = Mathf.Min(AutoStagingTerminateAt, AutoStagingMaxStage);
AutoStagingStatusColor = Color.white;
if (settings.AutoStagingEnabled)
Expand All @@ -794,7 +802,7 @@ internal override void RepeatingWorker()
if (lstLastStageEngineModules.Any(x => x.staged) || lstLastStageEngineFXModules.Any(x => x.staged))
AutoStagingRunning = true;
}
else if (Staging.CurrentStage > AutoStagingTerminateAt)
else if (StageManager.CurrentStage > AutoStagingTerminateAt)
{
//we are running, so now what
AutoStagingStatusColor = new Color32(183, 254, 0, 255);
Expand All @@ -814,9 +822,9 @@ internal override void RepeatingWorker()
} else if (AutoStagingTriggeredAt != 0){
if (Planetarium.GetUniversalTime() - AutoStagingTriggeredAt > ((Double)settings.AutoStagingDelayInTenths / 10))
{
//if (!settings.StagingIgnoreLock || Staging.stackLocked || FlightInputHandler.fetch.stageLock)
LogFormatted("Autostage Triggered: {0}->{1}", Staging.CurrentStage, Staging.CurrentStage - 1);
Staging.ActivateNextStage();
//if (!settings.StagingIgnoreLock || StageManager.stackLocked || FlightInputHandler.fetch.stageLock)
LogFormatted("Autostage Triggered: {0}->{1}", StageManager.CurrentStage, StageManager.CurrentStage - 1);
StageManager.ActivateNextStage();
AutoStagingTriggeredAt = 0;
} else {
AutoStagingStatusColor = new Color32(232, 232, 0, 255);
Expand Down Expand Up @@ -894,7 +902,7 @@ internal override void Update()
{
//Activate Stage via Space Bar in MapView if enabled and possible
if (settings.StagingEnabledSpaceInMapView && MapView.MapIsEnabled && windowMain.Visible && blnVesselIsControllable && Input.GetKey(KeyCode.Space))
Staging.ActivateNextStage();
StageManager.ActivateNextStage();
}

//internal String TestTrans;
Expand Down Expand Up @@ -1181,9 +1189,7 @@ public void Start()
first = false;
HighLogic.SaveFolder = "default";
Game game = GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);



if (game != null && game.flightState != null && game.compatible)
{
HighLogic.CurrentGame = game;
Expand Down
35 changes: 16 additions & 19 deletions AlternateResourcePanel/ARPAppLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;

using KSP;
using KSP.UI.Screens;
using UnityEngine;
using KSPPluginFramework;

Expand All @@ -17,20 +18,16 @@ public partial class KSPAlternateResourcePanel
void OnGUIAppLauncherReady()
{
MonoBehaviourExtended.LogFormatted_DebugOnly("AppLauncherReady");
if (ApplicationLauncher.Ready)
if (KSPAlternateResourcePanel.settings.ButtonStyleChosen==ARPWindowSettings.ButtonStyleEnum.Launcher ||
KSPAlternateResourcePanel.settings.ButtonStyleChosen==ARPWindowSettings.ButtonStyleEnum.StockReplace )
{
if (KSPAlternateResourcePanel.settings.ButtonStyleChosen==ARPWindowSettings.ButtonStyleEnum.Launcher ||
KSPAlternateResourcePanel.settings.ButtonStyleChosen==ARPWindowSettings.ButtonStyleEnum.StockReplace )
{
btnAppLauncher = InitAppLauncherButton();
btnAppLauncher = InitAppLauncherButton();

if (KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.StockReplace)
{
ReplaceStockAppButton();
}
if (KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.StockReplace)
{
ReplaceStockAppButton();
}
}
else { MonoBehaviourExtended.LogFormatted("App Launcher-Not Actually Ready"); }
}

void OnGUIAppLauncherUnreadifying(GameScenes SceneToLoad)
Expand Down Expand Up @@ -164,14 +161,14 @@ internal void ReplaceStockAppButton()
{
LogFormatted("AppLauncher: Swapping the ARP App for the Stock Resource App - after {0} secs", (DateTime.Now - StockAppToBeHiddenAttemptDate).TotalSeconds);
StockAppToBeHidden = false;
ResourceDisplay.Instance.appLauncherButton.toggleButton.onDisable();

ResourceDisplay.Instance.appLauncherButton.toggleButton.onHover = btnAppLauncher.toggleButton.onHover;
ResourceDisplay.Instance.appLauncherButton.toggleButton.onHoverOut = btnAppLauncher.toggleButton.onHoverOut;
ResourceDisplay.Instance.appLauncherButton.toggleButton.onTrue = btnAppLauncher.toggleButton.onTrue;
ResourceDisplay.Instance.appLauncherButton.toggleButton.onFalse = btnAppLauncher.toggleButton.onFalse;
ResourceDisplay.Instance.appLauncherButton.toggleButton.onEnable = btnAppLauncher.toggleButton.onEnable;
ResourceDisplay.Instance.appLauncherButton.toggleButton.onDisable = btnAppLauncher.toggleButton.onDisable;
ResourceDisplay.Instance.appLauncherButton.onDisable();

ResourceDisplay.Instance.appLauncherButton.onHover = btnAppLauncher.onHover;
ResourceDisplay.Instance.appLauncherButton.onHoverOut = btnAppLauncher.onHoverOut;
ResourceDisplay.Instance.appLauncherButton.onTrue = btnAppLauncher.onTrue;
ResourceDisplay.Instance.appLauncherButton.onFalse = btnAppLauncher.onFalse;
ResourceDisplay.Instance.appLauncherButton.onEnable = btnAppLauncher.onEnable;
ResourceDisplay.Instance.appLauncherButton.onDisable = btnAppLauncher.onDisable;
ResourceDisplay.Instance.appLauncherButton.SetTexture(Resources.texAppLaunchIcon);

try
Expand Down Expand Up @@ -210,7 +207,7 @@ internal void SetAppButtonToTrue()
}


if (ButtonToToggle.State != RUIToggleButton.ButtonState.TRUE)
if (ButtonToToggle.toggleButton.CurrentState != KSP.UI.UIRadioButton.State.True)
{
if (AppLauncherToBeSetTrueAttemptDate.AddSeconds(settings.AppLauncherSetTrueTimeOut) <DateTime.Now){
AppLauncherToBeSetTrue = false;
Expand Down
1 change: 1 addition & 0 deletions AlternateResourcePanel/ARPPartWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ internal override void OnGUIEvery()
Drawing.DrawLine(new Vector2((Single)PartScreenPos.x, Screen.height - (Single)PartScreenPos.y),
new Vector2(WindowEndX, Screen.height - WindowEndY), colorLineCurrent, 2);
}
base.OnGUIEvery();
}

Boolean UIHidden = false;
Expand Down
13 changes: 9 additions & 4 deletions AlternateResourcePanel/ARPWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;

using KSP;
using KSP.UI.Screens;
using UnityEngine;
using KSPPluginFramework;

Expand Down Expand Up @@ -191,9 +192,9 @@ internal override void DrawWindow(Int32 id)
if (GUILayout.Button("Stage:", Styles.styleStageTextHead, GUILayout.Width(50)))
settings.AutoStagingEnabled = !settings.AutoStagingEnabled;
GUIStyle styleStageNum = new GUIStyle(Styles.styleStageTextHead);
GUIContent contStageNum = new GUIContent(Staging.CurrentStage.ToString());
GUIContent contStageNum = new GUIContent(StageManager.CurrentStage.ToString());
//styleStageNum.normal.textColor=new Color(173,43,43);
//GUIContent contStageNum = new GUIContent(Staging.CurrentStage.ToString(),"NO Active Engines");
//GUIContent contStageNum = new GUIContent(StageManager.CurrentStage.ToString(),"NO Active Engines");
//if (THERE ARE ACTIVE ENGINES IN STAGE)
//{
//contStageNum.tooltip="Active Engines";
Expand All @@ -206,7 +207,7 @@ internal override void DrawWindow(Int32 id)
{
if (mbARP.blnVesselIsControllable) {
if (GUILayout.Button("Activate Stage", "ButtonGeneral", GUILayout.Width(100)))
Staging.ActivateNextStage();
StageManager.ActivateNextStage();
GUILayout.Space(21 + IconAlarmOffset);
//GUILayout.Space(51 + IconAlarmOffset);
}
Expand All @@ -223,7 +224,7 @@ internal override void DrawWindow(Int32 id)
{
if (GUILayout.Button("Auto:", Styles.styleStageTextHead, GUILayout.Width(50)))
settings.AutoStagingEnabled = !settings.AutoStagingEnabled;
GUILayout.Label(Staging.CurrentStage.ToString(),Styles.styleStageTextHead, GUILayout.Width(20));
GUILayout.Label(StageManager.CurrentStage.ToString(),Styles.styleStageTextHead, GUILayout.Width(20));
GUILayout.Label("to", Styles.styleStageTextHead, GUILayout.Width(30));
GUILayout.Label(mbARP.AutoStagingTerminateAt.ToString(), Styles.styleStageTextHead, GUILayout.Width(30));
DrawHorizontalSlider(ref mbARP.AutoStagingTerminateAt, 0, mbARP.AutoStagingMaxStage);
Expand Down Expand Up @@ -323,6 +324,10 @@ internal override void DrawWindow(Int32 id)
mbARP.windowSettings.UpdateWindowRect();
}

internal override void OnGUIEvery()
{
base.OnGUIEvery();
}
}

}
Loading

0 comments on commit 5f75a6b

Please sign in to comment.