Changes throughout to avoid dirtying the cache unnecessarily.
[VOID.git] / VOID_EditorHUD.cs
blob:a/VOID_EditorHUD.cs -> blob:b/VOID_EditorHUD.cs
// // VOID
// VOID_Hud.cs //
// // VOID_EditorHUD.cs
// Author: //
// toadicus <> // Copyright © 2014, toadicus
// // All rights reserved.
// Copyright (c) 2013 toadicus //
// // Redistribution and use in source and binary forms, with or without modification,
// This program is free software: you can redistribute it and/or modify // are permitted provided that the following conditions are met:
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or // 1. Redistributions of source code must retain the above copyright notice,
// (at your option) any later version. // this list of conditions and the following disclaimer.
// //
// This program is distributed in the hope that it will be useful, // 2. Redistributions in binary form must reproduce the above copyright notice,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // this list of conditions and the following disclaimer in the documentation and/or other
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // materials provided with the distribution.
// GNU General Public License for more details. //
// // 3. Neither the name of the copyright holder nor the names of its contributors may be used
// You should have received a copy of the GNU General Public License // to endorse or promote products derived from this software without specific prior written permission.
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
// // 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 Engineer.VesselSimulator;
using KSP; using KSP;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using ToadicusTools;
using UnityEngine; using UnityEngine;
   
namespace VOID namespace VOID
{ {
public class VOID_EditorHUD : VOID_Module, IVOID_EditorModule public class VOID_EditorHUD : VOID_Module, IVOID_EditorModule
{ {
/* /*
* Fields * Fields
* */ * */
[AVOID_SaveValue("colorIndex")] [AVOID_SaveValue("colorIndex")]
protected VOID_SaveValue<int> _colorIndex = 0; protected VOID_SaveValue<int> _colorIndex = 0;
   
protected List<Color> textColors = new List<Color>(); protected List<Color> textColors = new List<Color>();
   
protected GUIStyle labelStyle; protected GUIStyle labelStyle;
   
  protected EditorVesselOverlays _vesselOverlays;
   
/* /*
* Properties * Properties
* */ * */
public int ColorIndex public int ColorIndex
{ {
get get
{ {
return this._colorIndex; return this._colorIndex;
} }
set set
{ {
if (this._colorIndex >= this.textColors.Count - 1) if (this._colorIndex >= this.textColors.Count - 1)
{ {
this._colorIndex = 0; this._colorIndex = 0;
return; return;
} }
   
this._colorIndex = value; this._colorIndex = value;
} }
} }
   
  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 * Methods
* */ * */
public VOID_EditorHUD() : base() public VOID_EditorHUD() : base()
{ {
this._Name = "Heads-Up Display"; this._Name = "Heads-Up Display";
   
this._Active.value = true; this.toggleActive = true;
   
this.textColors.Add(Color.green); this.textColors.Add(Color.green);
this.textColors.Add(Color.black); this.textColors.Add(Color.black);
this.textColors.Add(Color.white); this.textColors.Add(Color.white);
this.textColors.Add(Color.red); this.textColors.Add(Color.red);
this.textColors.Add(Color.blue); this.textColors.Add(Color.blue);
this.textColors.Add(Color.yellow); this.textColors.Add(Color.yellow);
this.textColors.Add(Color.gray); this.textColors.Add(Color.gray);
this.textColors.Add(Color.cyan); this.textColors.Add(Color.cyan);
this.textColors.Add(Color.magenta); this.textColors.Add(Color.magenta);
   
this.labelStyle = new GUIStyle (); this.labelStyle = new GUIStyle ();
// this.labelStyle.alignment = TextAnchor.UpperRight; // this.labelStyle.alignment = TextAnchor.UpperRight;
this.labelStyle.normal.textColor = this.textColors [this.ColorIndex]; this.labelStyle.normal.textColor = this.textColors [this.ColorIndex];
   
Tools.PostDebugMessage (this.GetType().Name + ": Constructed."); Tools.PostDebugMessage (this.GetType().Name + ": Constructed.");
} }
   
public override void DrawGUI() public override void DrawGUI()
{ {
SimManager.Instance.RequestSimulation(); SimManager.RequestSimulation();
   
if (SimManager.Instance.LastStage == null) if (this.core.LastStage == null)
{ {
return; return;
} }
   
float hudLeft; float hudLeft;
  StringBuilder hudString;
   
if (EditorLogic.fetch.editorScreen == EditorLogic.EditorScreen.Parts) if (EditorLogic.fetch.editorScreen == EditorLogic.EditorScreen.Parts)
{ {
hudLeft = EditorPanels.Instance.partsPanelWidth + 10; hudLeft = EditorPanels.Instance.partsPanelWidth + 10;
} }
else if (EditorLogic.fetch.editorScreen == EditorLogic.EditorScreen.Actions) else if (EditorLogic.fetch.editorScreen == EditorLogic.EditorScreen.Actions)
{ {
hudLeft = EditorPanels.Instance.actionsPanelWidth + 10; hudLeft = EditorPanels.Instance.actionsPanelWidth + 10;
} }
else else
{ {
return; return;
} }
   
  GUI.skin = this.core.Skin;
   
Rect hudPos = new Rect (hudLeft, 48, 300, 32); Rect hudPos = new Rect (hudLeft, 48, 300, 32);
   
  hudString = new StringBuilder();
   
// GUI.skin = AssetBase.GetGUISkin("KSP window 2"); // GUI.skin = AssetBase.GetGUISkin("KSP window 2");
   
labelStyle.normal.textColor = textColors [ColorIndex]; labelStyle.normal.textColor = textColors [ColorIndex];
   
  hudString.Append("Total Mass: ");
  hudString.Append(this.core.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(this.core.LastStage.totalDeltaV));
  hudString.Append("m/s");
   
  hudString.Append('\n');
   
  hudString.Append("Bottom Stage Delta-V");
  hudString.Append(Tools.MuMech_ToSI(this.core.LastStage.deltaV));
  hudString.Append("m/s");
   
  hudString.Append('\n');
   
  hudString.Append("Bottom Stage T/W Ratio: ");
  hudString.Append(this.core.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 ( GUI.Label (
hudPos, hudPos,
"Total Mass: " + SimManager.Instance.LastStage.totalMass.ToString("F3") + "t" + hudString.ToString(),
" 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"),  
labelStyle); labelStyle);
} }
   
public override void DrawConfigurables() public override void DrawConfigurables()
{ {
if (GUILayout.Button ("Change HUD color", GUILayout.ExpandWidth (false))) if (GUILayout.Button ("Change HUD color", GUILayout.ExpandWidth (false)))
{ {
++this.ColorIndex; ++this.ColorIndex;
} }
} }
} }
} }