Created dedicated drop-down UI control, integrated it and fixed some bugs.
[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) 2014 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 #region Using Directives
   
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
   
using KerbalEngineer.Flight.Readouts.Miscellaneous; using KerbalEngineer.Flight.Readouts.Miscellaneous;
using KerbalEngineer.Flight.Readouts.Orbital; using KerbalEngineer.Flight.Readouts.Orbital;
using KerbalEngineer.Flight.Readouts.Rendezvous; using KerbalEngineer.Flight.Readouts.Rendezvous;
using KerbalEngineer.Flight.Readouts.Surface; using KerbalEngineer.Flight.Readouts.Surface;
using KerbalEngineer.Flight.Readouts.Vessel; using KerbalEngineer.Flight.Readouts.Vessel;
using KerbalEngineer.Settings; using KerbalEngineer.Settings;
   
using AltitudeSeaLevel = KerbalEngineer.Flight.Readouts.Surface.AltitudeSeaLevel; using AltitudeSeaLevel = KerbalEngineer.Flight.Readouts.Surface.AltitudeSeaLevel;
using ApoapsisHeight = KerbalEngineer.Flight.Readouts.Orbital.ApoapsisHeight; using ApoapsisHeight = KerbalEngineer.Flight.Readouts.Orbital.ApoapsisHeight;
using OrbitalPeriod = KerbalEngineer.Flight.Readouts.Orbital.OrbitalPeriod; using OrbitalPeriod = KerbalEngineer.Flight.Readouts.Orbital.OrbitalPeriod;
using PeriapsisHeight = KerbalEngineer.Flight.Readouts.Orbital.PeriapsisHeight; using PeriapsisHeight = KerbalEngineer.Flight.Readouts.Orbital.PeriapsisHeight;
using TimeToApoapsis = KerbalEngineer.Flight.Readouts.Orbital.TimeToApoapsis; using TimeToApoapsis = KerbalEngineer.Flight.Readouts.Orbital.TimeToApoapsis;
using TimeToPeriapsis = KerbalEngineer.Flight.Readouts.Orbital.TimeToPeriapsis; using TimeToPeriapsis = KerbalEngineer.Flight.Readouts.Orbital.TimeToPeriapsis;
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Readouts namespace KerbalEngineer.Flight.Readouts
{ {
public static class ReadoutLibrary public static class ReadoutLibrary
{ {
#region Fields #region Fields
   
private static List<ReadoutModule> readouts = new List<ReadoutModule>(); private static List<ReadoutModule> readouts = new List<ReadoutModule>();
   
#endregion #endregion
   
#region Constructors #region Constructors
   
/// <summary> /// <summary>
/// Sets up and populates the readout library with the stock readouts. /// Sets up and populates the readout library with the stock readouts.
/// </summary> /// </summary>
static ReadoutLibrary() static ReadoutLibrary()
{ {
try try
{ {
ReadoutCategory.SetCategory("Orbital", "Readouts that help with orbital manouevers."); ReadoutCategory.SetCategory("Orbital", "Readouts for orbital manovoeures.");
ReadoutCategory.SetCategory("Surface", "Readouts that help with surface manouevers."); ReadoutCategory.SetCategory("Surface", "Readouts showing surface and atmospheric information.");
ReadoutCategory.SetCategory("Vessel", "Readouts that display information about the vessel."); ReadoutCategory.SetCategory("Vessel", "Readouts showing vessel performance statistics.");
ReadoutCategory.SetCategory("Rendezvous", "Readouts that help with orbital rendezvous."); ReadoutCategory.SetCategory("Rendezvous", "Readouts for rendezvous manovoeures.");
ReadoutCategory.SetCategory("Miscellaneous", "Readouts that do not fit into other categories."); ReadoutCategory.SetCategory("Miscellaneous", "Readouts that do not fit into other categories.");
   
// Orbital // Orbital
readouts.Add(new ApoapsisHeight()); readouts.Add(new ApoapsisHeight());
readouts.Add(new PeriapsisHeight()); readouts.Add(new PeriapsisHeight());
readouts.Add(new TimeToApoapsis()); readouts.Add(new TimeToApoapsis());
readouts.Add(new TimeToPeriapsis()); readouts.Add(new TimeToPeriapsis());
readouts.Add(new Inclination()); readouts.Add(new Inclination());
readouts.Add(new Eccentricity()); readouts.Add(new Eccentricity());
readouts.Add(new OrbitalSpeed()); readouts.Add(new OrbitalSpeed());
readouts.Add(new OrbitalPeriod()); readouts.Add(new OrbitalPeriod());
readouts.Add(new LongitudeOfAscendingNode()); readouts.Add(new LongitudeOfAscendingNode());
readouts.Add(new LongitudeOfPeriapsis()); readouts.Add(new LongitudeOfPeriapsis());
readouts.Add(new SemiMajorAxis()); readouts.Add(new SemiMajorAxis());
readouts.Add(new SemiMinorAxis()); readouts.Add(new SemiMinorAxis());
   
// Surface // Surface
readouts.Add(new AltitudeSeaLevel()); readouts.Add(new AltitudeSeaLevel());
readouts.Add(new AltitudeTerrain()); readouts.Add(new AltitudeTerrain());
readouts.Add(new VerticalSpeed()); readouts.Add(new VerticalSpeed());
readouts.Add(new HorizontalSpeed()); readouts.Add(new HorizontalSpeed());
readouts.Add(new Longitude()); readouts.Add(new Longitude());
readouts.Add(new Latitude()); readouts.Add(new Latitude());
readouts.Add(new GeeForce()); readouts.Add(new GeeForce());
readouts.Add(new TerminalVelocity()); readouts.Add(new TerminalVelocity());
readouts.Add(new AtmosphericEfficiency()); readouts.Add(new AtmosphericEfficiency());
readouts.Add(new Biome()); readouts.Add(new Biome());
readouts.Add(new Slope()); readouts.Add(new Slope());
readouts.Add(new ImpactTime()); readouts.Add(new ImpactTime());
readouts.Add(new ImpactLongitude()); readouts.Add(new ImpactLongitude());
readouts.Add(new ImpactLatitude()); readouts.Add(new ImpactLatitude());
readouts.Add(new ImpactAltitude()); readouts.Add(new ImpactAltitude());
readouts.Add(new ImpactBiome()); readouts.Add(new ImpactBiome());
   
// Vessel // Vessel
readouts.Add(new DeltaVStaged()); readouts.Add(new DeltaVStaged());
readouts.Add(new DeltaVTotal()); readouts.Add(new DeltaVTotal());
readouts.Add(new SpecificImpulse()); readouts.Add(new SpecificImpulse());
readouts.Add(new Mass()); readouts.Add(new Mass());
readouts.Add(new Thrust()); readouts.Add(new Thrust());
readouts.Add(new ThrustToWeight()); readouts.Add(new ThrustToWeight());
readouts.Add(new Acceleration()); readouts.Add(new Acceleration());
readouts.Add(new SimulationDelay()); readouts.Add(new SimulationDelay());
   
// Rendezvous // Rendezvous
readouts.Add(new TargetSelector()); readouts.Add(new TargetSelector());
readouts.Add(new PhaseAngle()); readouts.Add(new PhaseAngle());
readouts.Add(new InterceptAngle()); readouts.Add(new InterceptAngle());
readouts.Add(new RelativeInclination()); readouts.Add(new RelativeInclination());
readouts.Add(new AngleToAscendingNode()); readouts.Add(new AngleToAscendingNode());
readouts.Add(new AngleToDescendingNode()); readouts.Add(new AngleToDescendingNode());
readouts.Add(new Rendezvous.AltitudeSeaLevel()); readouts.Add(new Rendezvous.AltitudeSeaLevel());
readouts.Add(new Rendezvous.ApoapsisHeight()); readouts.Add(new Rendezvous.ApoapsisHeight());
readouts.Add(new Rendezvous.PeriapsisHeight()); readouts.Add(new Rendezvous.PeriapsisHeight());
readouts.Add(new Rendezvous.TimeToApoapsis()); readouts.Add(new Rendezvous.TimeToApoapsis());
readouts.Add(new Rendezvous.TimeToPeriapsis()); readouts.Add(new Rendezvous.TimeToPeriapsis());
readouts.Add(new Distance()); readouts.Add(new Distance());
readouts.Add(new Rendezvous.OrbitalPeriod()); readouts.Add(new Rendezvous.OrbitalPeriod());
   
// Misc // Misc
readouts.Add(new Separator()); readouts.Add(new Separator());
readouts.Add(new GuiSizeAdjustor()); readouts.Add(new GuiSizeAdjustor());
   
LoadHelpStrings(); LoadHelpStrings();
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
#endregion #endregion
   
#region Properties #region Properties
   
/// <summary> /// <summary>
/// Gets and sets the available readout modules. /// Gets and sets the available readout modules.
/// </summary> /// </summary>
public static List<ReadoutModule> Readouts public static List<ReadoutModule> Readouts
{ {
get { return readouts; } get { return readouts; }
set { readouts = value; } set { readouts = value; }
} }
   
#endregion #endregion
   
#region Public Methods #region Public Methods
   
/// <summary> /// <summary>
/// Gets a readout module with the specified name or class name. (Returns null if not found.) /// Gets a readout module with the specified name or class name. (Returns null if not found.)
/// </summary> /// </summary>
public static ReadoutModule GetReadout(string name) public static ReadoutModule GetReadout(string name)
{ {
return readouts.FirstOrDefault(r => r.Name == name || r.GetType().Name == name || r.Category + "." + r.GetType().Name == name); return readouts.FirstOrDefault(r => r.Name == name || r.GetType().Name == name || r.Category + "." + r.GetType().Name == name);
} }
   
/// <summary> /// <summary>
/// Gets a list of readout modules which are associated with the specified category. /// Gets a list of readout modules which are associated with the specified category.
/// </summary> /// </summary>
public static List<ReadoutModule> GetCategory(ReadoutCategory category) public static List<ReadoutModule> GetCategory(ReadoutCategory category)
{ {
return readouts.Where(r => r.Category == category).ToList(); return readouts.Where(r => r.Category == category).ToList();
} }
   
/// <summary> /// <summary>
/// Resets all the readout modules. /// Resets all the readout modules.
/// </summary> /// </summary>
public static void Reset() public static void Reset()
{ {
foreach (var readout in readouts) foreach (var readout in readouts)
{ {
readout.Reset(); readout.Reset();
} }
} }
   
#endregion #endregion
   
#region Private Methods #region Private Methods
   
/// <summary> /// <summary>
/// Loads the help strings from file. /// Loads the help strings from file.
/// </summary> /// </summary>
private static void LoadHelpStrings() private static void LoadHelpStrings()
{ {
try try
{ {
var handler = SettingHandler.Load("HelpStrings.xml"); var handler = SettingHandler.Load("HelpStrings.xml");
foreach (var readout in readouts) foreach (var readout in readouts)
{ {
readout.HelpString = handler.GetSet(readout.Category + "." + readout.GetType().Name, readout.HelpString); readout.HelpString = handler.GetSet(readout.Category + "." + readout.GetType().Name, readout.HelpString);
} }
handler.Save("HelpStrings.xml"); handler.Save("HelpStrings.xml");
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
#endregion #endregion
   
//#region Instance //#region Instance
   
//private static readonly ReadoutLibrary instance = new ReadoutLibrary(); //private static readonly ReadoutLibrary instance = new ReadoutLibrary();
   
///// <summary> ///// <summary>
///// Gets the current instance of the readout library. ///// Gets the current instance of the readout library.
///// </summary> ///// </summary>
//public static ReadoutLibrary Instance //public static ReadoutLibrary Instance
//{ //{
// get { return instance; } // get { return instance; }
//} //}
   
//#endregion //#endregion
} }
} }