Got the EditorHUD working, and it's not even that ugly! Need to finalize what we want, and get a config window available.
[VOID.git] / VOID_EditorHUD.cs
blob:a/VOID_EditorHUD.cs -> blob:b/VOID_EditorHUD.cs
--- a/VOID_EditorHUD.cs
+++ b/VOID_EditorHUD.cs
@@ -1,29 +1,38 @@
-//
-//  VOID_Hud.cs
-//
-//  Author:
-//       toadicus <>
-//
-//  Copyright (c) 2013 toadicus
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
+// VOID
+//
+// VOID_EditorHUD.cs
+//
+// Copyright © 2014, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+//    this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation and/or other
+//    materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+//    to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 using Engineer.VesselSimulator;
 using KSP;
 using System;
 using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ToadicusTools;
 using UnityEngine;
 
 namespace VOID
@@ -40,6 +49,8 @@
 
 		protected GUIStyle labelStyle;
 
+		protected EditorVesselOverlays _vesselOverlays;
+
 		/*
 		 * Properties
 		 * */
@@ -61,6 +72,47 @@
 			}
 		}
 
+		protected EditorVesselOverlays vesselOverlays
+		{
+			get
+			{
+				if (this._vesselOverlays == null)
+				{
+					this._vesselOverlays = (EditorVesselOverlays)Resources
+						.FindObjectsOfTypeAll(typeof(EditorVesselOverlays))
+						.FirstOrDefault();
+				}
+
+				return this._vesselOverlays;
+			}
+		}
+
+		protected EditorMarker_CoM CoMmarker
+		{
+			get
+			{
+				if (this.vesselOverlays == null)
+				{
+					return null;
+				}
+
+				return this.vesselOverlays.CoMmarker;
+			}
+		}
+
+		protected EditorMarker_CoT CoTmarker
+		{
+			get
+			{
+				if (this.vesselOverlays == null)
+				{
+					return null;
+				}
+
+				return this.vesselOverlays.CoTmarker;
+			}
+		}
+
 		/* 
 		 * Methods
 		 * */
@@ -68,7 +120,7 @@
 		{
 			this._Name = "Heads-Up Display";
 
-			this._Active = true;
+			this._Active.value = true;
 
 			this.textColors.Add(Color.green);
 			this.textColors.Add(Color.black);
@@ -81,7 +133,7 @@
 			this.textColors.Add(Color.magenta);
 
 			this.labelStyle = new GUIStyle ();
-			this.labelStyle.alignment = TextAnchor.UpperRight;
+			// this.labelStyle.alignment = TextAnchor.UpperRight;
 			this.labelStyle.normal.textColor = this.textColors [this.ColorIndex];
 
 			Tools.PostDebugMessage (this.GetType().Name + ": Constructed.");
@@ -89,24 +141,78 @@
 
 		public override void DrawGUI()
 		{
-			SimManager.Instance.RequestSimulation();
-
-			if (SimManager.Instance.LastStage == null)
+			SimManager.RequestSimulation();
+
+			if (SimManager.LastStage == null)
 			{
 				return;
 			}
 
+			float hudLeft;
+			StringBuilder hudString;
+
+			if (EditorLogic.fetch.editorScreen == EditorLogic.EditorScreen.Parts)
+			{
+				hudLeft = EditorPanels.Instance.partsPanelWidth + 10;
+			}
+			else if (EditorLogic.fetch.editorScreen == EditorLogic.EditorScreen.Actions)
+			{
+				hudLeft = EditorPanels.Instance.actionsPanelWidth + 10;
+			}
+			else
+			{
+				return;
+			}
+
+			Rect hudPos = new Rect (hudLeft, 48, 300, 32);
+
+			hudString = new StringBuilder();
+
 			// GUI.skin = AssetBase.GetGUISkin("KSP window 2");
 
 			labelStyle.normal.textColor = textColors [ColorIndex];
 
+			hudString.Append("Total Mass: ");
+			hudString.Append(SimManager.LastStage.totalMass.ToString("F3"));
+			hudString.Append('t');
+
+			hudString.Append(' ');
+
+			hudString.Append("Part Count: ");
+			hudString.Append(EditorLogic.SortedShipList.Count);
+
+			hudString.Append('\n');
+
+			hudString.Append("Total Delta-V: ");
+			hudString.Append(Tools.MuMech_ToSI(SimManager.LastStage.totalDeltaV));
+			hudString.Append("m/s");
+
+			hudString.Append('\n');
+
+			hudString.Append("Bottom Stage Delta-V");
+			hudString.Append(Tools.MuMech_ToSI(SimManager.LastStage.deltaV));
+			hudString.Append("m/s");
+
+			hudString.Append('\n');
+
+			hudString.Append("Bottom Stage T/W Ratio: ");
+			hudString.Append(SimManager.LastStage.thrustToWeight.ToString("F3"));
+
+			if (this.CoMmarker.gameObject.activeInHierarchy && this.CoTmarker.gameObject.activeInHierarchy)
+			{
+				hudString.Append('\n');
+
+				hudString.Append("Thrust Offset: ");
+				hudString.Append(
+					Vector3.Cross(
+						this.CoTmarker.dirMarkerObject.transform.forward,
+						this.CoMmarker.posMarkerObject.transform.position - this.CoTmarker.posMarkerObject.transform.position
+					).ToString("F3"));
+			}
+
 			GUI.Label (
-				new Rect (Screen.width - 310, 80, 300f, 32f),
-				"Total Mass: " + SimManager.Instance.LastStage.totalMass.ToString("F3") + "t" +
-				" Part Count: " + EditorLogic.SortedShipList.Count +
-				"\nTotal Delta-V: " + Tools.MuMech_ToSI(SimManager.Instance.LastStage.totalDeltaV) + "m/s" +
-				"\nBottom Stage Delta-V: " + Tools.MuMech_ToSI(SimManager.Instance.LastStage.deltaV) + "m/s" +
-				"\nBottom Stage T/W Ratio: " + SimManager.Instance.LastStage.thrustToWeight.ToString("F3"),
+				hudPos,
+				hudString.ToString(),
 				labelStyle);
 		}