Skip to content

Commit

Permalink
Added new Flight HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
jwvanderbeck committed Jan 8, 2015
1 parent 3395d5d commit 16f8c85
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions TestFlightCore/TestFlightCore/TestFlightCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="StylesAndSkins.cs" />
<Compile Include="Resources.cs" />
<Compile Include="Framework\PartModuleExtended.cs" />
<Compile Include="TestFlightHUD.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
Expand Down
123 changes: 123 additions & 0 deletions TestFlightCore/TestFlightCore/TestFlightHUD.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

using UnityEngine;

using KSPPluginFramework;

namespace TestFlightCore
{
public class TestFlightHUD : MonoBehaviourWindowPlus
{
private TestFlightManagerScenario tfScenario;
private TestFlightWindow parentWindow;
private Settings settings;
private int lastPartCount = 0;

internal override void Start()
{
onWindowMoveComplete += Window_OnWindowMoveComplete;
}

internal TestFlightHUD Startup(TestFlightWindow parent)
{
LogFormatted_DebugOnly("TestFlightHUD Startup()");
parentWindow = parent;
tfScenario = parent.tfScenario;
settings = parent.settings;
LogFormatted_DebugOnly("TestFlightHUD WindowRect " + settings.flightHUDPosition.xMin + "," + settings.flightHUDPosition.yMin);
WindowMoveEventsEnabled = true;
onWindowMoveComplete += Window_OnWindowMoveComplete;
return this;
}

internal void Shutdown()
{
Visible = false;
onWindowMoveComplete -= Window_OnWindowMoveComplete;
WindowMoveEventsEnabled = false;
}

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

internal override void OnGUIOnceOnly()
{
// Default position and size -- will get proper bounds calculated when needed
WindowRect = new Rect(settings.flightHUDPosition.xMin, settings.flightHUDPosition.yMin, 50f, 50f);
DragEnabled = true;
ClampToScreen = true;
TooltipsEnabled = true;
TooltipMouseOffset = new Vector2d(10, 10);
TooltipStatic = true;
WindowCaption = "";
WindowStyle = SkinsLibrary.CurrentSkin.GetStyle("HUD");
Visible = true;
onWindowMoveComplete += Window_OnWindowMoveComplete;
}

internal void CalculateWindowBounds()
{
LogFormatted_DebugOnly("TestFlightHUD Calculating Window Bounds");
WindowRect = new Rect(settings.flightHUDPosition.xMin, settings.flightHUDPosition.yMin, 50f, 50f);
}

internal override void DrawWindow(Int32 id)
{
GUILayout.BeginVertical();
Dictionary<Guid, MasterStatusItem> masterStatus = tfScenario.GetMasterStatus();

if (masterStatus == null || masterStatus.Count <= 0)
return;

// Display information on active vessel
Guid currentVessl = FlightGlobals.ActiveVessel.id;
if (masterStatus[currentVessl].allPartsStatus.Count(ps => ps.activeFailure != null) < lastPartCount)
{
LogFormatted_DebugOnly("TestFlightHUD less parts to display than last time. Need to recalculate window bounds");
CalculateWindowBounds();
}
lastPartCount = masterStatus[currentVessl].allPartsStatus.Count(ps => ps.activeFailure != null);

foreach (PartStatus status in masterStatus[currentVessl].allPartsStatus)
{
// We only show failed parts in Flight HUD
if (status.activeFailure == null)
continue;

GUILayout.BeginHorizontal();
// Part Name
string tooltip = status.repairRequirements;
if (status.activeFailure.GetFailureDetails().severity == "minor")
GUILayout.Label(new GUIContent(String.Format("<color=#859900ff>{0}</color>", status.partName), tooltip), GUILayout.Width(200));
else if (status.activeFailure.GetFailureDetails().severity == "failure")
GUILayout.Label(new GUIContent(String.Format("<color=#b58900ff>{0}</color>", status.partName), tooltip), GUILayout.Width(200));
else if (status.activeFailure.GetFailureDetails().severity == "major")
GUILayout.Label(new GUIContent(String.Format("<color=#dc322fff>{0}</color>", status.partName), tooltip), GUILayout.Width(200));
GUILayout.Space(10);
if (status.activeFailure != null)
{
if (GUILayout.Button("R", GUILayout.Width(38)))
{
// attempt repair
bool repairSuccess = status.flightCore.AttemptRepair();
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}

// GUI EVent Handlers
void Window_OnWindowMoveComplete(MonoBehaviourWindow sender)
{
LogFormatted_DebugOnly("TestFlightHUD Saving window position");
settings.flightHUDPosition = WindowRect;
settings.Save();
}
}
}

0 comments on commit 16f8c85

Please sign in to comment.