Various fixes.
[VesselSimulator.git] / KerbalEngineer / Flight / Readouts / ReadoutLibrary.cs
blob:a/KerbalEngineer/Flight/Readouts/ReadoutLibrary.cs -> blob:b/KerbalEngineer/Flight/Readouts/ReadoutLibrary.cs
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2015 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives namespace KerbalEngineer.Flight.Readouts
  {
using System.Collections.Generic; using System;
using System.Linq; using System.Collections.Generic;
  using System.Linq;
using KerbalEngineer.Flight.Readouts.Misc; using Miscellaneous;
using KerbalEngineer.Flight.Readouts.Orbital; using Orbital;
using KerbalEngineer.Flight.Readouts.Rendezvous; using Orbital.ManoeuvreNode;
using KerbalEngineer.Flight.Readouts.Surface; using Rendezvous;
using KerbalEngineer.Flight.Readouts.Vessel; using Settings;
using KerbalEngineer.Settings; using Surface;
  using Thermal;
using AltitudeSeaLevel = KerbalEngineer.Flight.Readouts.Surface.AltitudeSeaLevel; using Vessel;
using ApoapsisHeight = KerbalEngineer.Flight.Readouts.Orbital.ApoapsisHeight; using AltitudeSeaLevel = Surface.AltitudeSeaLevel;
using OrbitalPeriod = KerbalEngineer.Flight.Readouts.Orbital.OrbitalPeriod; using ApoapsisHeight = Orbital.ApoapsisHeight;
using PeriapsisHeight = KerbalEngineer.Flight.Readouts.Orbital.PeriapsisHeight; using OrbitalPeriod = Orbital.OrbitalPeriod;
using TimeToApoapsis = KerbalEngineer.Flight.Readouts.Orbital.TimeToApoapsis; using PeriapsisHeight = Orbital.PeriapsisHeight;
using TimeToPeriapsis = KerbalEngineer.Flight.Readouts.Orbital.TimeToPeriapsis; using SemiMajorAxis = Orbital.SemiMajorAxis;
  using SemiMinorAxis = Orbital.SemiMinorAxis;
#endregion using TimeToApoapsis = Orbital.TimeToApoapsis;
  using TimeToPeriapsis = Orbital.TimeToPeriapsis;
namespace KerbalEngineer.Flight.Readouts  
{ public static class ReadoutLibrary
public class ReadoutLibrary {
{ private static List<ReadoutModule> readouts = new List<ReadoutModule>();
#region Instance  
  /// <summary>
private static readonly ReadoutLibrary instance = new ReadoutLibrary(); /// Sets up and populates the readout library with the stock readouts.
  /// </summary>
/// <summary> static ReadoutLibrary()
/// Gets the current instance of the readout library. {
/// </summary> try
public static ReadoutLibrary Instance {
{ ReadoutCategory.SetCategory("Orbital", "Readout for orbital manovoeures.");
get { return instance; } ReadoutCategory.SetCategory("Surface", "Surface and atmospheric readouts.");
} ReadoutCategory.SetCategory("Vessel", "Vessel performance statistics.");
  ReadoutCategory.SetCategory("Rendezvous", "Readouts for rendezvous manovoeures.");
#endregion ReadoutCategory.SetCategory("Thermal", "Thermal characteristics readouts.");
  ReadoutCategory.SetCategory("Miscellaneous", "Miscellaneous readouts.");
#region Fields ReadoutCategory.Selected = ReadoutCategory.GetCategory("Orbital");
   
private List<ReadoutModule> readoutModules = new List<ReadoutModule>(); // Orbital
  readouts.Add(new ApoapsisHeight());
#endregion readouts.Add(new PeriapsisHeight());
  readouts.Add(new TimeToApoapsis());
#region Constructors readouts.Add(new TimeToPeriapsis());
  readouts.Add(new Inclination());
/// <summary> readouts.Add(new TimeToEquatorialAscendingNode());
/// Sets up and populates the readout library with the stock readouts. readouts.Add(new TimeToEquatorialDescendingNode());
/// </summary> readouts.Add(new AngleToEquatorialAscendingNode());
private ReadoutLibrary() readouts.Add(new AngleToEquatorialDescendingNode());
{ readouts.Add(new Eccentricity());
// Orbital readouts.Add(new OrbitalSpeed());
this.readoutModules.Add(new ApoapsisHeight()); readouts.Add(new OrbitalPeriod());
this.readoutModules.Add(new PeriapsisHeight()); readouts.Add(new CurrentSoi());
this.readoutModules.Add(new TimeToApoapsis()); readouts.Add(new LongitudeOfAscendingNode());
this.readoutModules.Add(new TimeToPeriapsis()); readouts.Add(new LongitudeOfPeriapsis());
this.readoutModules.Add(new Inclination()); readouts.Add(new ArgumentOfPeriapsis());
this.readoutModules.Add(new Eccentricity()); readouts.Add(new TrueAnomaly());
this.readoutModules.Add(new OrbitalSpeed()); readouts.Add(new MeanAnomaly());
this.readoutModules.Add(new OrbitalPeriod()); readouts.Add(new MeanAnomalyAtEpoc());
this.readoutModules.Add(new LongitudeOfAscendingNode()); readouts.Add(new EccentricAnomaly());
this.readoutModules.Add(new LongitudeOfPeriapsis()); readouts.Add(new SemiMajorAxis());
this.readoutModules.Add(new SemiMajorAxis()); readouts.Add(new SemiMinorAxis());
this.readoutModules.Add(new SemiMinorAxis()); readouts.Add(new AngleToPrograde());
  readouts.Add(new AngleToRetrograde());
// Surface readouts.Add(new NodeProgradeDeltaV());
this.readoutModules.Add(new AltitudeSeaLevel()); readouts.Add(new NodeNormalDeltaV());
this.readoutModules.Add(new AltitudeTerrain()); readouts.Add(new NodeRadialDeltaV());
this.readoutModules.Add(new VerticalSpeed()); readouts.Add(new NodeTotalDeltaV());
this.readoutModules.Add(new HorizontalSpeed()); readouts.Add(new NodeBurnTime());
this.readoutModules.Add(new Longitude()); readouts.Add(new NodeHalfBurnTime());
this.readoutModules.Add(new Latitude()); readouts.Add(new NodeTimeToManoeuvre());
this.readoutModules.Add(new GeeForce()); readouts.Add(new NodeTimeToHalfBurn());
this.readoutModules.Add(new TerminalVelocity()); readouts.Add(new NodeAngleToPrograde());
this.readoutModules.Add(new AtmosphericEfficiency()); readouts.Add(new NodeAngleToRetrograde());
this.readoutModules.Add(new Biome());  
this.readoutModules.Add(new Slope()); // Surface
this.readoutModules.Add(new ImpactTime()); readouts.Add(new AltitudeSeaLevel());
this.readoutModules.Add(new ImpactLongitude()); readouts.Add(new AltitudeTerrain());
this.readoutModules.Add(new ImpactLatitude()); readouts.Add(new VerticalSpeed());
this.readoutModules.Add(new ImpactAltitude()); readouts.Add(new VerticalAcceleration());
this.readoutModules.Add(new ImpactBiome()); readouts.Add(new HorizontalSpeed());
  readouts.Add(new HorizontalAcceleration());
// Vessel readouts.Add(new MachNumber());
this.readoutModules.Add(new DeltaVStaged()); readouts.Add(new Latitude());
this.readoutModules.Add(new DeltaVTotal()); readouts.Add(new Longitude());
this.readoutModules.Add(new SpecificImpulse()); readouts.Add(new GeeForce());
this.readoutModules.Add(new Mass()); readouts.Add(new TerminalVelocity());
this.readoutModules.Add(new Thrust()); readouts.Add(new AtmosphericEfficiency());
this.readoutModules.Add(new ThrustToWeight()); readouts.Add(new Biome());
this.readoutModules.Add(new SimulationDelay()); readouts.Add(new Situation());
  readouts.Add(new Slope());
// Rendezvous readouts.Add(new ImpactTime());
this.readoutModules.Add(new TargetSelector()); readouts.Add(new ImpactLongitude());
this.readoutModules.Add(new PhaseAngle()); readouts.Add(new ImpactLatitude());
this.readoutModules.Add(new InterceptAngle()); readouts.Add(new ImpactAltitude());
this.readoutModules.Add(new RelativeInclination()); readouts.Add(new ImpactBiome());
this.readoutModules.Add(new AngleToAscendingNode());  
this.readoutModules.Add(new AngleToDescendingNode()); // Vessel
this.readoutModules.Add(new Rendezvous.AltitudeSeaLevel()); readouts.Add(new DeltaVStaged());
this.readoutModules.Add(new Rendezvous.ApoapsisHeight()); readouts.Add(new DeltaVCurrent());
this.readoutModules.Add(new Rendezvous.PeriapsisHeight()); readouts.Add(new DeltaVTotal());
this.readoutModules.Add(new Rendezvous.TimeToApoapsis()); readouts.Add(new DeltaVCurrentTotal());
this.readoutModules.Add(new Rendezvous.TimeToPeriapsis()); readouts.Add(new SpecificImpulse());
this.readoutModules.Add(new Distance()); readouts.Add(new Mass());
this.readoutModules.Add(new Rendezvous.OrbitalPeriod()); readouts.Add(new Thrust());
  readouts.Add(new ThrustToWeight());
// Misc readouts.Add(new ThrustOffsetAngle());
this.readoutModules.Add(new ChangeGuiSize()); readouts.Add(new ThrustTorque());
  readouts.Add(new SurfaceThrustToWeight());
this.LoadHelpStrings(); readouts.Add(new Acceleration());
} readouts.Add(new SuicideBurnAltitude());
  readouts.Add(new SuicideBurnDistance());
#endregion readouts.Add(new SuicideBurnDeltaV());
  readouts.Add(new IntakeAirUsage());
#region Properties readouts.Add(new IntakeAirDemand());
  readouts.Add(new IntakeAirSupply());
/// <summary> readouts.Add(new IntakeAirDemandSupply());
/// Gets and sets the available readout modules. readouts.Add(new PartCount());
/// </summary> readouts.Add(new Heading());
public List<ReadoutModule> ReadoutModules readouts.Add(new Pitch());
{ readouts.Add(new Roll());
get { return this.readoutModules; } readouts.Add(new HeadingRate());
set { this.readoutModules = value; } readouts.Add(new PitchRate());
} readouts.Add(new RollRate());
   
#endregion // Rendezvous
  readouts.Add(new TargetSelector());
#region Public Methods readouts.Add(new PhaseAngle());
  readouts.Add(new InterceptAngle());
/// <summary> readouts.Add(new RelativeVelocity());
/// Gets a readout module with the specified name or class name. (Returns null if not found.) readouts.Add(new RelativeSpeed());
/// </summary> readouts.Add(new RelativeInclination());
public ReadoutModule GetReadoutModule(string name) readouts.Add(new TimeToRelativeAscendingNode());
{ readouts.Add(new TimeToRelativeDescendingNode());
return this.readoutModules.FirstOrDefault(r => r.Name == name || r.GetType().Name == name || r.Category + "." + r.GetType().Name == name); readouts.Add(new AngleToRelativeAscendingNode());
} readouts.Add(new AngleToRelativeDescendingNode());
  readouts.Add(new Rendezvous.AltitudeSeaLevel());
/// <summary> readouts.Add(new Rendezvous.ApoapsisHeight());
/// Gets a list of readout modules which are associated with the specified category. readouts.Add(new Rendezvous.PeriapsisHeight());
/// </summary> readouts.Add(new Rendezvous.TimeToApoapsis());
public List<ReadoutModule> GetCategory(ReadoutCategory category) readouts.Add(new Rendezvous.TimeToPeriapsis());
{ readouts.Add(new Distance());
return this.readoutModules.Where(r => r.Category == category).ToList(); readouts.Add(new Rendezvous.OrbitalPeriod());
} readouts.Add(new Rendezvous.SemiMajorAxis());
  readouts.Add(new Rendezvous.SemiMinorAxis());
/// <summary>  
/// Resets all the readout modules. // Thermal
/// </summary> readouts.Add(new InternalFlux());
public void Reset() readouts.Add(new ConvectionFlux());
{ readouts.Add(new RadiationFlux());
foreach (var readout in this.readoutModules) readouts.Add(new CriticalPart());
{ readouts.Add(new CriticalTemperature());
readout.Reset(); readouts.Add(new CriticalPercentage());
} readouts.Add(new HottestPart());
} readouts.Add(new HottestTemperature());
  readouts.Add(new CoolestPart());
#endregion readouts.Add(new CoolestTemperature());
   
#region Private Methods // Misc
  readouts.Add(new Separator());
/// <summary> readouts.Add(new GuiSizeAdjustor());
/// Loads the help strings from file. readouts.Add(new SimulationDelay());
/// </summary> readouts.Add(new TimeReference());
private void LoadHelpStrings() readouts.Add(new VectoredThrustToggle());
{ readouts.Add(new SystemTime());
var handler = SettingHandler.Load("HelpStrings.xml");  
foreach (var readout in this.readoutModules) LoadHelpStrings();
{ }
readout.HelpString = handler.GetSet(readout.Category + "." + readout.GetType().Name, readout.HelpString); catch (Exception ex)
} {
handler.Save("HelpStrings.xml"); Logger.Exception(ex);
} }
  }
#endregion  
} /// <summary>
  /// Gets and sets the available readout modules.
  /// </summary>
  public static List<ReadoutModule> Readouts
  {
  get
  {
  return readouts;
  }
  set
  {
  readouts = value;
  }
  }
   
  /// <summary>
  /// Gets a list of readout modules which are associated with the specified category.
  /// </summary>
  public static List<ReadoutModule> GetCategory(ReadoutCategory category)
  {
  return readouts.Where(r => r.Category == category).ToList();
  }
   
  /// <summary>
  /// Gets a readout module with the specified name or class name. (Returns null if not found.)
  /// </summary>
  public static ReadoutModule GetReadout(string name)
  {
  return readouts.FirstOrDefault(r => r.Name == name || r.GetType().Name == name || r.Category + "." + r.GetType().Name == name);
  }
   
  /// <summary>
  /// Resets all the readout modules.
  /// </summary>
  public static void Reset()
  {
  foreach (ReadoutModule readout in readouts)
  {
  readout.Reset();
  }
  }
   
  /// <summary>
  /// Loads the help strings from file.
  /// </summary>
  private static void LoadHelpStrings()
  {
  try
  {
  SettingHandler handler = SettingHandler.Load("HelpStrings.xml");
  foreach (ReadoutModule readout in readouts)
  {
  readout.HelpString = handler.GetSet(readout.Category + "." + readout.GetType().Name, readout.HelpString);
  }
  handler.Save("HelpStrings.xml");
  }
  catch (Exception ex)
  {
  Logger.Exception(ex);
  }
  }
  }
} }