Thermal section is now set as custom.
Thermal section is now set as custom.

// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2015 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 #region Using Directives
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Sections namespace KerbalEngineer.Flight.Sections
{ {
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Readouts; using Readouts;
using Settings; using Settings;
using UnityEngine; using UnityEngine;
   
public static class SectionLibrary public static class SectionLibrary
{ {
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Sets up and populates the library with the stock sections on creation. /// Sets up and populates the library with the stock sections on creation.
/// </summary> /// </summary>
static SectionLibrary() static SectionLibrary()
{ {
StockSections = new List<SectionModule>(); StockSections = new List<SectionModule>();
CustomSections = new List<SectionModule>(); CustomSections = new List<SectionModule>();
   
StockSections.Add(new SectionModule StockSections.Add(new SectionModule
{ {
Name = "ORBITAL", Name = "ORBITAL",
Abbreviation = "ORBT", Abbreviation = "ORBT",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Orbital")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Orbital")).Where(r => r.IsDefault).ToList()
}); });
   
StockSections.Add(new SectionModule StockSections.Add(new SectionModule
{ {
Name = "SURFACE", Name = "SURFACE",
Abbreviation = "SURF", Abbreviation = "SURF",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Surface")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Surface")).Where(r => r.IsDefault).ToList()
}); });
   
StockSections.Add(new SectionModule StockSections.Add(new SectionModule
{ {
Name = "VESSEL", Name = "VESSEL",
Abbreviation = "VESL", Abbreviation = "VESL",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Vessel")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Vessel")).Where(r => r.IsDefault).ToList()
}); });
   
StockSections.Add(new SectionModule StockSections.Add(new SectionModule
{ {
Name = "RENDEZVOUS", Name = "RENDEZVOUS",
Abbreviation = "RDZV", Abbreviation = "RDZV",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Rendezvous")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Rendezvous")).Where(r => r.IsDefault).ToList()
}); });
   
CustomSections.Add(new SectionModule CustomSections.Add(new SectionModule
{ {
Name = "THERMAL", Name = "THERMAL",
Abbreviation = "HEAT", Abbreviation = "HEAT",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Thermal")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Thermal")).Where(r => r.IsDefault).ToList(),
}); IsCustom = true
  });
   
SectionModule hud1 = new SectionModule SectionModule hud1 = new SectionModule
{ {
Name = "HUD 1", Name = "HUD 1",
Abbreviation = "HUD 1", Abbreviation = "HUD 1",
IsCustom = true, IsCustom = true,
IsVisible = true, IsVisible = true,
ReadoutModules = new List<ReadoutModule> ReadoutModules = new List<ReadoutModule>
{ {
ReadoutLibrary.GetReadout("ApoapsisHeight"), ReadoutLibrary.GetReadout("ApoapsisHeight"),
ReadoutLibrary.GetReadout("TimeToApoapsis"), ReadoutLibrary.GetReadout("TimeToApoapsis"),
ReadoutLibrary.GetReadout("PeriapsisHeight"), ReadoutLibrary.GetReadout("PeriapsisHeight"),
ReadoutLibrary.GetReadout("TimeToPeriapsis") ReadoutLibrary.GetReadout("TimeToPeriapsis")
}, },
}; };
hud1.FloatingPositionX = Screen.width * 0.25f - (hud1.ReadoutModules.First().ContentWidth * 0.5f); hud1.FloatingPositionX = Screen.width * 0.25f - (hud1.ReadoutModules.First().ContentWidth * 0.5f);
hud1.FloatingPositionY = 0.0f; hud1.FloatingPositionY = 0.0f;
hud1.IsHud = true; hud1.IsHud = true;
CustomSections.Add(hud1); CustomSections.Add(hud1);
   
SectionModule hud2 = new SectionModule SectionModule hud2 = new SectionModule
{ {
Name = "HUD 2", Name = "HUD 2",
Abbreviation = "HUD 2", Abbreviation = "HUD 2",
IsCustom = true, IsCustom = true,
IsVisible = true, IsVisible = true,
ReadoutModules = new List<ReadoutModule> ReadoutModules = new List<ReadoutModule>
{ {
ReadoutLibrary.GetReadout("AltitudeTerrain"), ReadoutLibrary.GetReadout("AltitudeTerrain"),
ReadoutLibrary.GetReadout("VerticalSpeed"), ReadoutLibrary.GetReadout("VerticalSpeed"),
ReadoutLibrary.GetReadout("HorizontalSpeed"), ReadoutLibrary.GetReadout("HorizontalSpeed"),
ReadoutLibrary.GetReadout("Biome"), ReadoutLibrary.GetReadout("Biome"),
ReadoutLibrary.GetReadout("MachNumber") ReadoutLibrary.GetReadout("MachNumber")
}, },
}; };
hud2.FloatingPositionX = Screen.width * 0.75f - (hud2.ReadoutModules.First().ContentWidth * 0.5f); hud2.FloatingPositionX = Screen.width * 0.75f - (hud2.ReadoutModules.First().ContentWidth * 0.5f);
hud2.FloatingPositionY = 0.0f; hud2.FloatingPositionY = 0.0f;
hud2.IsHud = true; hud2.IsHud = true;
CustomSections.Add(hud2); CustomSections.Add(hud2);
} }
#endregion #endregion
   
#region Properties #region Properties
/// <summary> /// <summary>
/// Gets and sets a list of custom sections. /// Gets and sets a list of custom sections.
/// </summary> /// </summary>
public static List<SectionModule> CustomSections { get; set; } public static List<SectionModule> CustomSections { get; set; }
   
/// <summary> /// <summary>
/// Gets the number of total sections that are stored in the library. /// Gets the number of total sections that are stored in the library.
/// </summary> /// </summary>
public static int NumberOfSections { get; private set; } public static int NumberOfSections { get; private set; }
   
/// <summary> /// <summary>
/// Gets the number of sections that are being drawn on the display stack. /// Gets the number of sections that are being drawn on the display stack.
/// </summary> /// </summary>
public static int NumberOfStackSections { get; private set; } public static int NumberOfStackSections { get; private set; }
   
/// <summary> /// <summary>
/// Gets and sets a list of stock sections /// Gets and sets a list of stock sections
/// </summary> /// </summary>
public static List<SectionModule> StockSections { get; set; } public static List<SectionModule> StockSections { get; set; }
#endregion #endregion
   
#region Updating #region Updating
   
#region Methods: public #region Methods: public
/// <summary> /// <summary>
/// Fixed update all of the sections. /// Fixed update all of the sections.
/// </summary> /// </summary>
public static void FixedUpdate() public static void FixedUpdate()
{ {
FixedUpdateSections(StockSections); FixedUpdateSections(StockSections);
FixedUpdateSections(CustomSections); FixedUpdateSections(CustomSections);
} }
   
/// <summary> /// <summary>
/// Update all of the sections and process section counts. /// Update all of the sections and process section counts.
/// </summary> /// </summary>
public static void Update() public static void Update()
{ {
NumberOfStackSections = 0; NumberOfStackSections = 0;
NumberOfSections = 0; NumberOfSections = 0;
   
UpdateSections(StockSections); UpdateSections(StockSections);
UpdateSections(CustomSections); UpdateSections(CustomSections);
} }
#endregion #endregion
   
#region Methods: private #region Methods: private
/// <summary> /// <summary>
/// Fixed updates a list of sections. /// Fixed updates a list of sections.
/// </summary> /// </summary>
private static void FixedUpdateSections(IEnumerable<SectionModule> sections) private static void FixedUpdateSections(IEnumerable<SectionModule> sections)
{ {
foreach (SectionModule section in sections) foreach (SectionModule section in sections)
{ {
if (section.IsVisible) if (section.IsVisible)
{ {
section.FixedUpdate(); section.FixedUpdate();
} }
} }
} }
   
/// <summary> /// <summary>
/// Updates a list of sections and increments the section counts. /// Updates a list of sections and increments the section counts.
/// </summary> /// </summary>
private static void UpdateSections(IEnumerable<SectionModule> sections) private static void UpdateSections(IEnumerable<SectionModule> sections)
{ {
foreach (SectionModule section in sections) foreach (SectionModule section in sections)
{ {
if (section.IsVisible) if (section.IsVisible)
{ {
if (!section.IsFloating) if (!section.IsFloating)
{ {
foreach (ReadoutModule readout in section.ReadoutModules) foreach (ReadoutModule readout in section.ReadoutModules)
{ {
if (readout.ResizeRequested) if (readout.ResizeRequested)
{ {
DisplayStack.Instance.RequestResize(); DisplayStack.Instance.RequestResize();
readout.ResizeRequested = false; readout.ResizeRequested = false;
} }
} }
   
NumberOfStackSections++; NumberOfStackSections++;
} }
else else
{ {
foreach (ReadoutModule readout in section.ReadoutModules) foreach (ReadoutModule readout in section.ReadoutModules)
{ {
if (readout.ResizeRequested) if (readout.ResizeRequested)
{ {
section.Window.RequestResize(); section.Window.RequestResize();
readout.ResizeRequested = false; readout.ResizeRequested = false;
} }
} }
} }
section.Update(); section.Update();
} }
   
NumberOfSections++; NumberOfSections++;
} }
} }
#endregion #endregion
   
#endregion #endregion
   
#region Saving and Loading #region Saving and Loading
/// <summary> /// <summary>
/// Loads the state of all stored sections. /// Loads the state of all stored sections.
/// </summary> /// </summary>
public static void Load() public static void Load()
{ {
if (!SettingHandler.Exists("SectionLibrary.xml")) if (!SettingHandler.Exists("SectionLibrary.xml"))
{ {
return; return;
} }
   
GetAllSections().ForEach(s => GetAllSections().ForEach(s =>
{ {
if (s.Window != null) if (s.Window != null)
{ {
Object.Destroy(s.Window); Object.Destroy(s.Window);
} }
}); });
   
SettingHandler handler = SettingHandler.Load("SectionLibrary.xml", new[] { typeof(List<SectionModule>) }); SettingHandler handler = SettingHandler.Load("SectionLibrary.xml", new[] { typeof(List<SectionModule>) });
StockSections = handler.Get("StockSections", StockSections); StockSections = handler.Get("StockSections", StockSections);
CustomSections = handler.Get("CustomSections", CustomSections); CustomSections = handler.Get("CustomSections", CustomSections);
   
foreach (SectionModule section in GetAllSections()) foreach (SectionModule section in GetAllSections())
{ {
section.ClearNullReadouts(); section.ClearNullReadouts();
} }
} }
   
/// <summary> /// <summary>
/// Saves the state of all the stored sections. /// Saves the state of all the stored sections.
/// </summary> /// </summary>
public static void Save() public static void Save()
{ {
SettingHandler handler = new SettingHandler(); SettingHandler handler = new SettingHandler();
handler.Set("StockSections", StockSections); handler.Set("StockSections", StockSections);
handler.Set("CustomSections", CustomSections); handler.Set("CustomSections", CustomSections);
handler.Save("SectionLibrary.xml"); handler.Save("SectionLibrary.xml");
} }
#endregion #endregion
   
#region Methods #region Methods
/// <summary> /// <summary>
/// Gets a list containing all section modules. /// Gets a list containing all section modules.
/// </summary> /// </summary>
public static List<SectionModule> GetAllSections() public static List<SectionModule> GetAllSections()
{ {
List<SectionModule> sections = new List<SectionModule>(); List<SectionModule> sections = new List<SectionModule>();
sections.AddRange(StockSections); sections.AddRange(StockSections);
sections.AddRange(CustomSections); sections.AddRange(CustomSections);
return sections; return sections;
} }
   
/// <summary> /// <summary>
/// Gets a custom section that has the specified name. /// Gets a custom section that has the specified name.
/// </summary> /// </summary>
public static SectionModule GetCustomSection(string name) public static SectionModule GetCustomSection(string name)
{ {
return CustomSections.FirstOrDefault(s => s.Name == name); return CustomSections.FirstOrDefault(s => s.Name == name);
} }
   
/// <summary> /// <summary>
/// Gets a section that has the specified name. /// Gets a section that has the specified name.
/// </summary> /// </summary>
public static SectionModule GetSection(string name) public static SectionModule GetSection(string name)
{ {
return GetStockSection(name) ?? GetCustomSection(name); return GetStockSection(name) ?? GetCustomSection(name);
} }
   
/// <summary> /// <summary>
/// Gets a stock section that has the specified name. /// Gets a stock section that has the specified name.
/// </summary> /// </summary>
public static SectionModule GetStockSection(string name) public static SectionModule GetStockSection(string name)
{ {
return StockSections.FirstOrDefault(s => s.Name == name); return StockSections.FirstOrDefault(s => s.Name == name);
} }
   
/// <summary> /// <summary>
/// Removes a custom section witht he specified name. /// Removes a custom section witht he specified name.
/// </summary> /// </summary>
public static bool RemoveCustomSection(string name) public static bool RemoveCustomSection(string name)
{ {
return CustomSections.Remove(GetCustomSection(name)); return CustomSections.Remove(GetCustomSection(name));
} }
   
/// <summary> /// <summary>
/// Removes a section with the specified name. /// Removes a section with the specified name.
/// </summary> /// </summary>
public static bool RemoveSection(string name) public static bool RemoveSection(string name)
{ {
return RemoveStockSection(name) || RemoveCustomSection(name); return RemoveStockSection(name) || RemoveCustomSection(name);
} }
   
/// <summary> /// <summary>
/// Removes a stock section with the specified name. /// Removes a stock section with the specified name.
/// </summary> /// </summary>
public static bool RemoveStockSection(string name) public static bool RemoveStockSection(string name)
{ {
return StockSections.Remove(GetStockSection(name)); return StockSections.Remove(GetStockSection(name));
} }
#endregion #endregion
} }
} }
 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ