Skip to content

Commit

Permalink
fix NRE on switch to flight from editor
Browse files Browse the repository at this point in the history
  • Loading branch information
BahamutoD committed Feb 11, 2016
1 parent a2d524f commit 377e278
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions BahaTurret/ModuleWingCommander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,51 +238,55 @@ void LoadWingmen()
GUIStyle wingmanButtonSelectedStyle;
void OnGUI()
{
if(HighLogic.LoadedSceneIsFlight && showGUI && vessel.isActiveVessel && BDArmorySettings.GAME_UI_ENABLED)
if(HighLogic.LoadedSceneIsFlight && vessel && vessel.isActiveVessel && !vessel.packed)
{
if(!rectInit)
if(BDArmorySettings.GAME_UI_ENABLED)
{
guiWindowRect = new Rect(45, 75, 240, 800);
buttonWidth = guiWindowRect.width - (2*margin);
buttonEndY = buttonStartY;
wingmanButtonStyle = new GUIStyle(HighLogic.Skin.button);
wingmanButtonStyle.alignment = TextAnchor.MiddleLeft;
wingmanButtonStyle.wordWrap = false;
wingmanButtonStyle.fontSize = 11;
wingmanButtonSelectedStyle = new GUIStyle(HighLogic.Skin.box);
wingmanButtonSelectedStyle.alignment = TextAnchor.MiddleLeft;
wingmanButtonSelectedStyle.wordWrap = false;
wingmanButtonSelectedStyle.fontSize = 11;
rectInit = true;
}
guiWindowRect = GUI.Window(1293293, guiWindowRect, WingmenWindow, "WingCommander", HighLogic.Skin.window);
if(showGUI)
{
if(!rectInit)
{
guiWindowRect = new Rect(45, 75, 240, 800);
buttonWidth = guiWindowRect.width - (2 * margin);
buttonEndY = buttonStartY;
wingmanButtonStyle = new GUIStyle(HighLogic.Skin.button);
wingmanButtonStyle.alignment = TextAnchor.MiddleLeft;
wingmanButtonStyle.wordWrap = false;
wingmanButtonStyle.fontSize = 11;
wingmanButtonSelectedStyle = new GUIStyle(HighLogic.Skin.box);
wingmanButtonSelectedStyle.alignment = TextAnchor.MiddleLeft;
wingmanButtonSelectedStyle.wordWrap = false;
wingmanButtonSelectedStyle.fontSize = 11;
rectInit = true;
}
guiWindowRect = GUI.Window(1293293, guiWindowRect, WingmenWindow, "WingCommander", HighLogic.Skin.window);

if(showAGWindow)
{
AGWindow();
}
}
if(showAGWindow)
{
AGWindow();
}
}

if(HighLogic.LoadedSceneIsFlight && vessel.isActiveVessel)
{
float diamondSize = 24;
foreach(var comPos in commandedPositions)
{
BDGUIUtils.DrawTextureOnWorldPos(comPos.worldPos, BDArmorySettings.Instance.greenDiamondTexture, new Vector2(diamondSize, diamondSize), 0);
Vector2 labelPos;
if(BDGUIUtils.WorldToGUIPos(comPos.worldPos, out labelPos))
//command position diamonds
float diamondSize = 24;
foreach(var comPos in commandedPositions)
{
labelPos.x += diamondSize/2;
labelPos.y -= 10;
GUI.Label(new Rect(labelPos.x, labelPos.y, 300, 20), comPos.name);
BDGUIUtils.DrawTextureOnWorldPos(comPos.worldPos, BDArmorySettings.Instance.greenDiamondTexture, new Vector2(diamondSize, diamondSize), 0);
Vector2 labelPos;
if(BDGUIUtils.WorldToGUIPos(comPos.worldPos, out labelPos))
{
labelPos.x += diamondSize/2;
labelPos.y -= 10;
GUI.Label(new Rect(labelPos.x, labelPos.y, 300, 20), comPos.name);
}
}
}

if(drawMouseDiamond)
{
Vector2 mouseDiamondPos = Input.mousePosition;
Rect mouseDiamondRect = new Rect(mouseDiamondPos.x - (diamondSize / 2), Screen.height-mouseDiamondPos.y - (diamondSize / 2), diamondSize, diamondSize);
GUI.DrawTexture(mouseDiamondRect, BDArmorySettings.Instance.greenDiamondTexture, ScaleMode.StretchToFill, true);
if(drawMouseDiamond)
{
Vector2 mouseDiamondPos = Input.mousePosition;
Rect mouseDiamondRect = new Rect(mouseDiamondPos.x - (diamondSize / 2), Screen.height-mouseDiamondPos.y - (diamondSize / 2), diamondSize, diamondSize);
GUI.DrawTexture(mouseDiamondRect, BDArmorySettings.Instance.greenDiamondTexture, ScaleMode.StretchToFill, true);
}
}
}
}
Expand Down
Binary file modified BahaTurret/bin/Release/BahaTurret.dll
Binary file not shown.
Binary file modified BahaTurret/obj/x86/Release/BahaTurret.dll
Binary file not shown.

0 comments on commit 377e278

Please sign in to comment.