Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GUI code to work with KSP 1.1 and Unity 5 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Update GUI code to work with KSP 1.1 and Unity 5
jwvanderbeck committed Apr 3, 2016
commit f6878af6d660c7b69ca8ee6c79471a91cd70d7e4
57 changes: 42 additions & 15 deletions KSPPluginFramework/MonoBehaviourWindow.cs
Original file line number Diff line number Diff line change
@@ -81,7 +81,29 @@ internal override void Awake()
//just some debugging stuff here
LogFormatted_DebugOnly("New MBWindow Awakened");

//base.Awake();
base.Awake();

GameEvents.onShowUI.Add(ShowUI);
GameEvents.onHideUI.Add(HideUI);
GameEvents.onGUIAdministrationFacilitySpawn.Add(HideUI);
GameEvents.onGUIAdministrationFacilityDespawn.Add(ShowUI);
GameEvents.onGUIMissionControlSpawn.Add(HideUI);
GameEvents.onGUIMissionControlDespawn.Add(HideUI);
GameEvents.onGUIKSPediaSpawn.Add(HideUI);
GameEvents.onGUIKSPediaSpawn.Add(ShowUI);
}

internal bool bHideUI = false;
public void ShowUI()
{
LogFormatted_DebugOnly("Setting HideUI = False");
bHideUI = false;
}

public void HideUI()
{
LogFormatted_DebugOnly("Setting HideUI = True");
bHideUI = true;
}

/// <summary>
@@ -124,6 +146,13 @@ internal override void Awake()
/// </summary>
internal RectOffset ClampToScreenOffset = new RectOffset(0, 0, 0, 0);

internal override void OnGUIEvery()
{
if (bHideUI)
return;
DrawGUI(); // Your current on postDrawQueue code
}

private Boolean _Visible;
/// <summary>
/// Whether the Window is visible or not. Changing this value will add/remove the window from the RenderingManager.PostDrawQueue
@@ -135,18 +164,12 @@ internal Boolean Visible
{
if (_Visible != value)
{
if (value)
{
LogFormatted_DebugOnly("Adding Window to PostDrawQueue-{0}", WindowID);
RenderingManager.AddToPostDrawQueue(5, this.DrawGUI);
}
else
{
LogFormatted_DebugOnly("Removing Window from PostDrawQueue", WindowID);
RenderingManager.RemoveFromPostDrawQueue(5, this.DrawGUI);
}
//raise event if theres one registered
if (onWindowVisibleChanged != null)
onWindowVisibleChanged(this, value);
}
_Visible = value;

}
}

@@ -156,6 +179,9 @@ internal Boolean Visible
/// </summary>
private void DrawGUI()
{
if (!_Visible)
return;

//this sets the skin on each draw loop
GUI.skin = SkinsLibrary.CurrentSkin;

@@ -199,6 +225,7 @@ private void DrawWindowInternal(Int32 id)

DrawWindowPost(id);


//Set the Tooltip variable based on whats in this window
if (TooltipsEnabled)
SetTooltipText();
@@ -339,10 +366,10 @@ private void DrawToolTip()
TooltipShown = false;
}

//if we've moved to a diffn tooltip then reset the counter
if (strToolTipText != strLastTooltipText) fltTooltipTime = 0f;
//make sure the last text is correct
//if we've moved to a diffn tooltip then reset the counter
if (strToolTipText != strLastTooltipText) fltTooltipTime = 0f;
//make sure the last text is correct
strLastTooltipText = strToolTipText;
}