Skip to content

Commit

Permalink
Merge 2.5.0.0 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
TriggerAu committed Aug 1, 2014
2 parents 9599056 + 201218f commit 5c16393
Show file tree
Hide file tree
Showing 192 changed files with 302 additions and 52 deletions.
20 changes: 14 additions & 6 deletions AlternateResourcePanel/ARP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private KSPAlternateResourcePanel()
internal ARPWindowSettings windowSettings;
internal ARPWindowResourceConfig windowResourceConfig;

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

Expand Down Expand Up @@ -273,9 +274,11 @@ private void InitMainWindow()
windowMain = AddComponent<ARPWindow>();
windowMain.mbARP = this;
windowMain.WindowRect = settings.WindowPosition;
windowMain.DragEnabled = !settings.LockLocation;
windowMain.DragEnabled = (settings.ButtonStyleChosen== ARPWindowSettings.ButtonStyleEnum.StockReplace ? false : !settings.LockLocation);
windowMain.ClampToScreenOffset = new RectOffset(-1, -1, -1, -1);
windowMain.TooltipsEnabled = true;

windowMain.WindowMoveEventsEnabled = true;
}

private void InitSettingsWindow()
Expand Down Expand Up @@ -371,7 +374,7 @@ void DrawGUI()
windowMain.Visible = true;
if (blnResetWindow)
{
windowMain.WindowRect = new Rect(Screen.width - 298, 40, 299, 20);
windowMain.WindowRect = new Rect(windowMainResetPos);
blnResetWindow = false;
settings.WindowPosition = windowMain.WindowRect;
settings.Save();
Expand All @@ -393,12 +396,14 @@ internal Boolean IsMouseOver()
if (settings.ButtonStyleToDisplay==ARPWindowSettings.ButtonStyleEnum.Toolbar)
//return MouseOverToolbarBtn || (windowMain.Visible && windowMain.WindowRect.Contains(Event.current.mousePosition));
return (MouseOverToolbarBtn && !settings.DisableHover) ||
(windowMain.Visible && windowMain.WindowRect.Contains(Event.current.mousePosition));
(windowMain.Visible && windowMain.WindowRect.Contains(Event.current.mousePosition)) ||
(windowSettings.Visible && windowSettings.WindowRect.Contains(Event.current.mousePosition));

//App Launcher version
if (settings.ButtonStyleToDisplay==ARPWindowSettings.ButtonStyleEnum.Launcher && MouseOverAppLauncherBtn)
//App Launcher version's
if (settings.ButtonStyleToDisplay == ARPWindowSettings.ButtonStyleEnum.Launcher || settings.ButtonStyleToDisplay == ARPWindowSettings.ButtonStyleEnum.StockReplace)
return (MouseOverAppLauncherBtn && !settings.DisableHover) ||
(windowMain.Visible && windowMain.WindowRect.Contains(Event.current.mousePosition));
(windowMain.Visible && windowMain.WindowRect.Contains(Event.current.mousePosition)) ||
(windowSettings.Visible && windowSettings.WindowRect.Contains(Event.current.mousePosition));

//are we painting?
Boolean blnRet = Event.current.type == EventType.Repaint;
Expand All @@ -425,6 +430,9 @@ internal Boolean IsMouseOver()
/// </summary>
internal override void RepeatingWorker()
{
if (StockAppToBeHidden)
ReplaceStockAppButton();

Vessel active = FlightGlobals.ActiveVessel;
LastStage = GetLastStage(active.parts);

Expand Down
72 changes: 66 additions & 6 deletions AlternateResourcePanel/ARPAppLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ void OnGUIAppLauncherReady()
MonoBehaviourExtended.LogFormatted_DebugOnly("AppLauncherReady");
if (ApplicationLauncher.Ready)
{
if (KSPAlternateResourcePanel.settings.ButtonStyleChosen==ARPWindowSettings.ButtonStyleEnum.Launcher)
if (KSPAlternateResourcePanel.settings.ButtonStyleChosen==ARPWindowSettings.ButtonStyleEnum.Launcher ||
KSPAlternateResourcePanel.settings.ButtonStyleChosen==ARPWindowSettings.ButtonStyleEnum.StockReplace )
{
btnAppLauncher = InitAppLauncherButton();

if (KSPAlternateResourcePanel.settings.ButtonStyleChosen == ARPWindowSettings.ButtonStyleEnum.StockReplace)
{
ReplaceStockAppButton();
}
}
}
else { MonoBehaviourExtended.LogFormatted("App Launcher-Not Actually Ready"); }
Expand All @@ -30,6 +36,7 @@ void OnGameSceneLoadRequestedForAppLauncher(GameScenes SceneToLoad)
DestroyAppLauncherButton();
}
internal ApplicationLauncherButton btnAppLauncher = null;
internal Boolean SceneChangeRequiredToRestoreResourcesApp=false;

internal ApplicationLauncherButton InitAppLauncherButton()
{
Expand All @@ -44,8 +51,7 @@ internal ApplicationLauncherButton InitAppLauncherButton()
ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW,
(Texture)Resources.texAppLaunchIcon);


ApplicationLauncher.Instance.EnableMutuallyExclusive(retButton);
AppLauncherButtonMutuallyExclusive(settings.AppLauncherMutuallyExclusive);

//appButton = ApplicationLauncher.Instance.AddApplication(
// onAppLaunchToggleOn, onAppLaunchToggleOff,
Expand All @@ -54,9 +60,6 @@ internal ApplicationLauncherButton InitAppLauncherButton()
// (Texture)Resources.texAppLaunchIcon);
//appButton.VisibleInScenes = ApplicationLauncher.AppScenes.FLIGHT;


if (KSPAlternateResourcePanel.settings.ToggleOn)
retButton.toggleButton.SetTrue();
}
catch (Exception ex)
{
Expand All @@ -66,6 +69,21 @@ internal ApplicationLauncherButton InitAppLauncherButton()
return retButton;
}

internal void AppLauncherButtonMutuallyExclusive(Boolean Enable)
{
if (btnAppLauncher == null) return;
if (Enable)
{
MonoBehaviourExtended.LogFormatted("Setting Mutually Exclusive");
ApplicationLauncher.Instance.EnableMutuallyExclusive(btnAppLauncher);
}
else
{
MonoBehaviourExtended.LogFormatted("Clearing Mutually Exclusive");
ApplicationLauncher.Instance.DisableMutuallyExclusive(btnAppLauncher);
}
}

//internal ApplicationLauncherButton btnAppLauncher2 = null;

//internal ApplicationLauncherButton InitAppLauncherButton2()
Expand Down Expand Up @@ -111,6 +129,48 @@ internal void DestroyAppLauncherButton()
}
}

internal Boolean StockAppToBeHidden = false;
internal DateTime StockAppToBeHiddenAttemptDate;
internal void ReplaceStockAppButton()
{
if (ResourceDisplay.Instance.appLauncherButton == null)
{
if (!StockAppToBeHidden)
StockAppToBeHiddenAttemptDate = DateTime.Now;
StockAppToBeHidden = true;

if (StockAppToBeHiddenAttemptDate.AddSeconds(5) < DateTime.Now)
{
StockAppToBeHidden = false;
LogFormatted("Unable to Swap the ARP App for the Stock Resource App - tried for 5 secs");
}
}
else
{
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.SetTexture(Resources.texAppLaunchIcon);

try
{
ApplicationLauncher.Instance.RemoveModApplication(btnAppLauncher);
}
catch (Exception)
{

}
windowMain.DragEnabled = false;
windowMain.WindowRect = new Rect(windowMainResetPos);
}
}

void onAppLaunchToggleOn() {
MonoBehaviourExtended.LogFormatted_DebugOnly("TOn");
KSPAlternateResourcePanel.settings.ToggleOn = true;
Expand Down
14 changes: 14 additions & 0 deletions AlternateResourcePanel/ARPWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ class ARPWindow: MonoBehaviourWindowPlus
internal override void Awake()
{
TooltipMouseOffset = new Vector2d(-10, 10);

onWindowMoveComplete += ARPWindow_onWindowMoveComplete;
}
internal override void OnDestroy()
{
base.OnDestroy();

onWindowMoveComplete -= ARPWindow_onWindowMoveComplete;
}

void ARPWindow_onWindowMoveComplete()
{
settings.WindowPosition = WindowRect;
settings.Save();
}

private void SetLocalVariables()
Expand Down
39 changes: 33 additions & 6 deletions AlternateResourcePanel/ARPWindowDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal class ARPWindowDebug: MonoBehaviourWindowPlus
public Int32 intTest4 = 60;
public Int32 intTest5 = 50;


ApplicationLauncherButton origResButton=null;
//Boolean Clicked = false;
internal override void DrawWindow(int id)
{
Expand Down Expand Up @@ -76,15 +78,40 @@ internal override void DrawWindow(int id)
GUILayout.Label(String.Format("Draw Main Duration: {0:0.00}ms", mbARP.windowMain.DrawWindowInternalDuration.TotalMilliseconds));


//if(GUILayout.Button("Remove"))
//if (GUILayout.Button("SetTrue"))
//{
// mbARP.btnAppLauncher.toggleButton.onTrue();
//}
//if (GUILayout.Button("SetFalse"))
//{
// mbARP.btnAppLauncher.toggleButton.onFalse();
// //if (origResButton==null)
//}


//if(GUILayout.Button("Replace"))
//{
// ResourceDisplay.Instance.appLauncherButton.VisibleInScenes = ApplicationLauncher.AppScenes.NEVER;
// mbARP.btnAppLauncher2 = mbARP.InitAppLauncherButton2();
// //if (origResButton==null)
// // origResButton = (ApplicationLauncherButton)Instantiate(ResourceDisplay.Instance.appLauncherButton);

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

//}
//if (GUILayout.Button("Add"))
//if (GUILayout.Button("Revert"))
//{
// ResourceDisplay.Instance.appLauncherButton.VisibleInScenes = ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW;
// mbARP.btnAppLauncher2.VisibleInScenes = ApplicationLauncher.AppScenes.NEVER;
// ResourceDisplay.Instance.appLauncherButton.toggleButton.onHover = origResButton.toggleButton.onHover;
// ResourceDisplay.Instance.appLauncherButton.toggleButton.onHoverOut = origResButton.toggleButton.onHoverOut;
// ResourceDisplay.Instance.appLauncherButton.toggleButton.onTrue = origResButton.toggleButton.onTrue;
// ResourceDisplay.Instance.appLauncherButton.toggleButton.onFalse = origResButton.toggleButton.onFalse;
// ResourceDisplay.Instance.appLauncherButton.toggleButton.onEnable = origResButton.toggleButton.onEnable;
// ResourceDisplay.Instance.appLauncherButton.toggleButton.onDisable = origResButton.toggleButton.onDisable;
//}
//ApplicationLauncherButton[] lstButtons = KSPAlternateResourcePanel.FindObjectsOfType<ApplicationLauncherButton>();
//if (lstButtons!=null){
Expand Down
Loading

0 comments on commit 5c16393

Please sign in to comment.