Stock sections in the Flight Engineer can now become HUDs.
Stock sections in the Flight Engineer can now become HUDs.

// //
// 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 KerbalEngineer.Extensions; using KerbalEngineer.Extensions;
using KerbalEngineer.Flight.Presets; using KerbalEngineer.Flight.Presets;
using KerbalEngineer.Flight.Readouts; using KerbalEngineer.Flight.Readouts;
using KerbalEngineer.UIControls; using KerbalEngineer.UIControls;
   
using UnityEngine; using UnityEngine;
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Sections namespace KerbalEngineer.Flight.Sections
{ {
public class SectionEditor : MonoBehaviour public class SectionEditor : MonoBehaviour
{ {
#region Constants #region Constants
   
public const float Height = 500.0f; public const float Height = 500.0f;
public const float Width = 500.0f; public const float Width = 500.0f;
   
#endregion #endregion
   
#region Fields #region Fields
   
private GUIStyle categoryButtonActiveStyle; private GUIStyle categoryButtonActiveStyle;
private GUIStyle categoryButtonStyle; private GUIStyle categoryButtonStyle;
private DropDown categoryList; private DropDown categoryList;
private GUIStyle categoryTitleButtonStyle; private GUIStyle categoryTitleButtonStyle;
private GUIStyle helpBoxStyle; private GUIStyle helpBoxStyle;
private GUIStyle helpTextStyle; private GUIStyle helpTextStyle;
private GUIStyle panelTitleStyle; private GUIStyle panelTitleStyle;
private Rect position; private Rect position;
private DropDown presetList; private DropDown presetList;
private GUIStyle readoutButtonStyle; private GUIStyle readoutButtonStyle;
private GUIStyle readoutNameStyle; private GUIStyle readoutNameStyle;
private Vector2 scrollPositionAvailable; private Vector2 scrollPositionAvailable;
private Vector2 scrollPositionInstalled; private Vector2 scrollPositionInstalled;
private GUIStyle textStyle; private GUIStyle textStyle;
private GUIStyle windowStyle; private GUIStyle windowStyle;
   
#endregion #endregion
   
#region Properties #region Properties
   
/// <summary> /// <summary>
/// Gets and sets the parent section for the section editor. /// Gets and sets the parent section for the section editor.
/// </summary> /// </summary>
public SectionModule ParentSection { get; set; } public SectionModule ParentSection { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets the window position. /// Gets and sets the window position.
/// </summary> /// </summary>
public Rect Position public Rect Position
{ {
get { return this.position; } get { return this.position; }
set { this.position = value; } set { this.position = value; }
} }
   
#endregion #endregion
   
#region Methods: protected #region Methods: protected
   
protected void Awake() protected void Awake()
{ {
try try
{ {
this.categoryList = this.gameObject.AddComponent<DropDown>(); this.categoryList = this.gameObject.AddComponent<DropDown>();
this.categoryList.DrawCallback = this.DrawCategories; this.categoryList.DrawCallback = this.DrawCategories;
this.presetList = this.gameObject.AddComponent<DropDown>(); this.presetList = this.gameObject.AddComponent<DropDown>();
this.presetList.DrawCallback = this.DrawPresets; this.presetList.DrawCallback = this.DrawPresets;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
/// <summary> /// <summary>
/// Runs when the object is destroyed. /// Runs when the object is destroyed.
/// </summary> /// </summary>
protected void OnDestroy() protected void OnDestroy()
{ {
try try
{ {
RenderingManager.RemoveFromPostDrawQueue(0, this.Draw); RenderingManager.RemoveFromPostDrawQueue(0, this.Draw);
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
/// <summary> /// <summary>
/// Initialises the object's state on creation. /// Initialises the object's state on creation.
/// </summary> /// </summary>
protected void Start() protected void Start()
{ {
try try
{ {
this.InitialiseStyles(); this.InitialiseStyles();
//ReadoutCategory.Selected = ReadoutCategory.GetCategory("Orbital"); //ReadoutCategory.Selected = ReadoutCategory.GetCategory("Orbital");
RenderingManager.AddToPostDrawQueue(0, this.Draw); RenderingManager.AddToPostDrawQueue(0, this.Draw);
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
#endregion #endregion
   
#region Methods: private #region Methods: private
   
/// <summary> /// <summary>
/// Called to draw the editor when the UI is enabled. /// Called to draw the editor when the UI is enabled.
/// </summary> /// </summary>
private void Draw() private void Draw()
{ {
this.position = GUILayout.Window(this.GetInstanceID(), this.position, this.Window, "EDIT SECTION - " + this.ParentSection.Name.ToUpper(), this.windowStyle).ClampToScreen(); this.position = GUILayout.Window(this.GetInstanceID(), this.position, this.Window, "EDIT SECTION - " + this.ParentSection.Name.ToUpper(), this.windowStyle).ClampToScreen();
this.ParentSection.EditorPositionX = this.position.x; this.ParentSection.EditorPositionX = this.position.x;
this.ParentSection.EditorPositionY = this.position.y; this.ParentSection.EditorPositionY = this.position.y;
} }
   
/// <summary> /// <summary>
/// Draws the available readouts panel. /// Draws the available readouts panel.
/// </summary> /// </summary>
private void DrawAvailableReadouts() private void DrawAvailableReadouts()
{ {
GUI.skin = HighLogic.Skin; GUI.skin = HighLogic.Skin;
this.scrollPositionAvailable = GUILayout.BeginScrollView(this.scrollPositionAvailable, false, true, GUILayout.Height(200.0f)); this.scrollPositionAvailable = GUILayout.BeginScrollView(this.scrollPositionAvailable, false, true, GUILayout.Height(200.0f));
GUI.skin = null; GUI.skin = null;
   
GUILayout.Label("AVAILABLE", this.panelTitleStyle); GUILayout.Label("AVAILABLE", this.panelTitleStyle);
   
foreach (var readout in ReadoutLibrary.GetCategory(ReadoutCategory.Selected)) foreach (var readout in ReadoutLibrary.GetCategory(ReadoutCategory.Selected))
{ {
if (!this.ParentSection.ReadoutModules.Contains(readout) || readout.Cloneable) if (!this.ParentSection.ReadoutModules.Contains(readout) || readout.Cloneable)
{ {
GUILayout.BeginHorizontal(GUILayout.Height(30.0f)); GUILayout.BeginHorizontal(GUILayout.Height(30.0f));
GUILayout.Label(readout.Name, this.readoutNameStyle); GUILayout.Label(readout.Name, this.readoutNameStyle);
readout.ShowHelp = GUILayout.Toggle(readout.ShowHelp, "?", this.readoutButtonStyle, GUILayout.Width(30.0f)); readout.ShowHelp = GUILayout.Toggle(readout.ShowHelp, "?", this.readoutButtonStyle, GUILayout.Width(30.0f));
if (GUILayout.Button("INSTALL", this.readoutButtonStyle, GUILayout.Width(125.0f))) if (GUILayout.Button("INSTALL", this.readoutButtonStyle, GUILayout.Width(125.0f)))
{ {
this.ParentSection.ReadoutModules.Add(readout); this.ParentSection.ReadoutModules.Add(readout);
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
this.ShowHelpMessage(readout); this.ShowHelpMessage(readout);
} }
} }
   
GUILayout.EndScrollView(); GUILayout.EndScrollView();
} }
   
/// <summary> /// <summary>
/// Draws the categories list drop down UI. /// Draws the categories list drop down UI.
/// </summary> /// </summary>
private void DrawCategories() private void DrawCategories()
{ {
foreach (var category in ReadoutCategory.Categories) foreach (var category in ReadoutCategory.Categories)
{ {
var description = category.Description; var description = category.Description;
if (description.Length > 50) if (description.Length > 50)
{ {
description = description.Substring(0, 50 - 1) + "..."; description = description.Substring(0, 50 - 1) + "...";
} }
   
if (GUILayout.Button("<b>" + category.Name.ToUpper() + "</b>" + (string.IsNullOrEmpty(category.Description) ? string.Empty : "\n<i>" + description + "</i>"), category == ReadoutCategory.Selected ? this.categoryButtonActiveStyle : this.categoryButtonStyle)) if (GUILayout.Button("<b>" + category.Name.ToUpper() + "</b>" + (string.IsNullOrEmpty(category.Description) ? string.Empty : "\n<i>" + description + "</i>"), category == ReadoutCategory.Selected ? this.categoryButtonActiveStyle : this.categoryButtonStyle))
{ {
ReadoutCategory.Selected = category; ReadoutCategory.Selected = category;
this.categoryList.enabled = false; this.categoryList.enabled = false;
} }
} }
} }
   
/// <summary> /// <summary>
/// Draws the readoutCategories selection list. /// Draws the readoutCategories selection list.
/// </summary> /// </summary>
private void DrawCategorySelector() private void DrawCategorySelector()
{ {
this.categoryList.enabled = GUILayout.Toggle(this.categoryList.enabled, "▼ SELECTED CATEGORY: " + ReadoutCategory.Selected.ToString().ToUpper() + " ▼", this.categoryTitleButtonStyle); this.categoryList.enabled = GUILayout.Toggle(this.categoryList.enabled, "▼ SELECTED CATEGORY: " + ReadoutCategory.Selected.ToString().ToUpper() + " ▼", this.categoryTitleButtonStyle);
if (Event.current.type == EventType.repaint) if (Event.current.type == EventType.repaint)
{ {
this.categoryList.SetPosition(GUILayoutUtility.GetLastRect().Translate(this.position)); this.categoryList.SetPosition(GUILayoutUtility.GetLastRect().Translate(this.position));
} }
} }
   
/// <summary> /// <summary>
/// Draws the options for editing custom sections. /// Draws the options for editing custom sections.
/// </summary> /// </summary>
private void DrawCustomOptions() private void DrawCustomOptions()
{ {
GUILayout.BeginHorizontal(GUILayout.Height(25.0f)); GUILayout.BeginHorizontal(GUILayout.Height(25.0f));
this.ParentSection.Name = GUILayout.TextField(this.ParentSection.Name, this.textStyle); this.ParentSection.Name = GUILayout.TextField(this.ParentSection.Name, this.textStyle);
var isShowingInControlBar = !string.IsNullOrEmpty(this.ParentSection.Abbreviation); var isShowingInControlBar = !string.IsNullOrEmpty(this.ParentSection.Abbreviation);
this.ParentSection.Abbreviation = GUILayout.TextField(this.ParentSection.Abbreviation, this.textStyle, GUILayout.Width(75.0f)); this.ParentSection.Abbreviation = GUILayout.TextField(this.ParentSection.Abbreviation, this.textStyle, GUILayout.Width(75.0f));
   
  ParentSection.IsHud = GUILayout.Toggle(this.ParentSection.IsHud, "HUD", this.readoutButtonStyle, GUILayout.Width(50.0f));
  if (ParentSection.IsHud)
  {
  this.ParentSection.IsHudBackground = GUILayout.Toggle(this.ParentSection.IsHudBackground, "BG", this.readoutButtonStyle, GUILayout.Width(50.0f));
  }
   
if (this.ParentSection.IsCustom) if (this.ParentSection.IsCustom)
{ {
if (isShowingInControlBar && string.IsNullOrEmpty(this.ParentSection.Abbreviation)) if (isShowingInControlBar && string.IsNullOrEmpty(this.ParentSection.Abbreviation))
{ {
DisplayStack.Instance.RequestResize(); DisplayStack.Instance.RequestResize();
}  
if (this.ParentSection.IsHud = GUILayout.Toggle(this.ParentSection.IsHud, "HUD", this.readoutButtonStyle, GUILayout.Width(50.0f)))  
{  
this.ParentSection.IsHudBackground = GUILayout.Toggle(this.ParentSection.IsHudBackground, "BG", this.readoutButtonStyle, GUILayout.Width(50.0f));  
} }
   
if (GUILayout.Button("DELETE SECTION", this.readoutButtonStyle, GUILayout.Width(150.0f))) if (GUILayout.Button("DELETE SECTION", this.readoutButtonStyle, GUILayout.Width(150.0f)))
{ {
this.ParentSection.IsFloating = false; this.ParentSection.IsFloating = false;
this.ParentSection.IsEditorVisible = false; this.ParentSection.IsEditorVisible = false;
SectionLibrary.CustomSections.Remove(this.ParentSection); SectionLibrary.CustomSections.Remove(this.ParentSection);
DisplayStack.Instance.RequestResize(); DisplayStack.Instance.RequestResize();
} }
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
   
/// <summary> /// <summary>
/// Draws the installed readouts panel. /// Draws the installed readouts panel.
/// </summary> /// </summary>
private void DrawInstalledReadouts() private void DrawInstalledReadouts()
{ {
GUI.skin = HighLogic.Skin; GUI.skin = HighLogic.Skin;
this.scrollPositionInstalled = GUILayout.BeginScrollView(this.scrollPositionInstalled, false, true); this.scrollPositionInstalled = GUILayout.BeginScrollView(this.scrollPositionInstalled, false, true);
GUI.skin = null; GUI.skin = null;
   
GUILayout.Label("INSTALLED", this.panelTitleStyle); GUILayout.Label("INSTALLED", this.panelTitleStyle);
var removeReadout = false; var removeReadout = false;
var removeReadoutIndex = 0; var removeReadoutIndex = 0;
   
for (var i = 0; i < this.ParentSection.ReadoutModules.Count; i++) for (var i = 0; i < this.ParentSection.ReadoutModules.Count; i++)
{ {
var readout = this.ParentSection.ReadoutModules[i]; var readout = this.ParentSection.ReadoutModules[i];
   
GUILayout.BeginHorizontal(GUILayout.Height(30.0f)); GUILayout.BeginHorizontal(GUILayout.Height(30.0f));
GUILayout.Label(readout.Name, this.readoutNameStyle); GUILayout.Label(readout.Name, this.readoutNameStyle);
if (GUILayout.Button("▲", this.readoutButtonStyle, GUILayout.Width(30.0f))) if (GUILayout.Button("▲", this.readoutButtonStyle, GUILayout.Width(30.0f)))
{ {
if (i > 0) if (i > 0)
{ {
this.ParentSection.ReadoutModules[i] = this.ParentSection.ReadoutModules[i - 1]; this.ParentSection.ReadoutModules[i] = this.ParentSection.ReadoutModules[i - 1];
this.ParentSection.ReadoutModules[i - 1] = readout; this.ParentSection.ReadoutModules[i - 1] = readout;
} }
} }
if (GUILayout.Button("▼", this.readoutButtonStyle, GUILayout.Width(30.0f))) if (GUILayout.Button("▼", this.readoutButtonStyle, GUILayout.Width(30.0f)))
{ {
if (i < this.ParentSection.ReadoutModules.Count - 1) if (i < this.ParentSection.ReadoutModules.Count - 1)
{ {
this.ParentSection.ReadoutModules[i] = this.ParentSection.ReadoutModules[i + 1]; this.ParentSection.ReadoutModules[i] = this.ParentSection.ReadoutModules[i + 1];
this.ParentSection.ReadoutModules[i + 1] = readout; this.ParentSection.ReadoutModules[i + 1] = readout;
} }
} }
readout.ShowHelp = GUILayout.Toggle(readout.ShowHelp, "?", this.readoutButtonStyle, GUILayout.Width(30.0f)); readout.ShowHelp = GUILayout.Toggle(readout.ShowHelp, "?", this.readoutButtonStyle, GUILayout.Width(30.0f));
if (GUILayout.Button("REMOVE", this.readoutButtonStyle, GUILayout.Width(125.0f))) if (GUILayout.Button("REMOVE", this.readoutButtonStyle, GUILayout.Width(125.0f)))
{ {
removeReadout = true; removeReadout = true;
removeReadoutIndex = i; removeReadoutIndex = i;
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
this.ShowHelpMessage(readout); this.ShowHelpMessage(readout);
} }
   
GUILayout.EndScrollView(); GUILayout.EndScrollView();
   
if (removeReadout) if (removeReadout)
{ {
this.ParentSection.ReadoutModules.RemoveAt(removeReadoutIndex); this.ParentSection.ReadoutModules.RemoveAt(removeReadoutIndex);
} }
} }
   
private void DrawPresetButton(Preset preset) private void DrawPresetButton(Preset preset)
{ {
if (!GUILayout.Button("<b>" + preset.Name.ToUpper() + "</b>", this.categoryButtonStyle)) if (!GUILayout.Button("<b>" + preset.Name.ToUpper() + "</b>", this.categoryButtonStyle))
{ {
return; return;
} }
   
this.ParentSection.Name = preset.Name; this.ParentSection.Name = preset.Name;
this.ParentSection.Abbreviation = preset.Abbreviation; this.ParentSection.Abbreviation = preset.Abbreviation;
this.ParentSection.ReadoutModuleNames = preset.ReadoutNames; this.ParentSection.ReadoutModuleNames = preset.ReadoutNames;
this.ParentSection.IsHud = preset.IsHud; this.ParentSection.IsHud = preset.IsHud;
this.ParentSection.IsHudBackground = preset.IsHudBackground; this.ParentSection.IsHudBackground = preset.IsHudBackground;
this.presetList.enabled = false; this.presetList.enabled = false;
} }
   
private void DrawPresetSaveButton() private void DrawPresetSaveButton()
{ {
if (!GUILayout.Button("<b>SAVE PRESET</b>", this.categoryButtonStyle)) if (!GUILayout.Button("<b>SAVE PRESET</b>", this.categoryButtonStyle))
{ {
return; return;
} }
   
this.SavePreset(PresetLibrary.Presets.Find(p => String.Equals(p.Name, this.ParentSection.Name, StringComparison.CurrentCultureIgnoreCase))); this.SavePreset(PresetLibrary.Presets.Find(p => String.Equals(p.Name, this.ParentSection.Name, StringComparison.CurrentCultureIgnoreCase)));
} }
   
/// <summary> /// <summary>
/// Draws the presetsList selection list. /// Draws the presetsList selection list.
/// </summary> /// </summary>
private void DrawPresetSelector() private void DrawPresetSelector()
{ {
this.presetList.enabled = GUILayout.Toggle(this.presetList.enabled, "▼ PRESETS ▼", this.categoryTitleButtonStyle, GUILayout.Width(150.0f)); this.presetList.enabled = GUILayout.Toggle(this.presetList.enabled, "▼ PRESETS ▼", this.categoryTitleButtonStyle, GUILayout.Width(150.0f));
if (Event.current.type == EventType.repaint) if (Event.current.type == EventType.repaint)
{ {
this.presetList.SetPosition(GUILayoutUtility.GetLastRect().Translate(this.position)); this.presetList.SetPosition(GUILayoutUtility.GetLastRect().Translate(this.position));
} }
} }
   
/// <summary> /// <summary>
/// Draws the preset list drop down UI. /// Draws the preset list drop down UI.
/// </summary> /// </summary>
private void DrawPresets() private void DrawPresets()
{ {
Preset removePreset = null; Preset removePreset = null;
foreach (var preset in PresetLibrary.Presets) foreach (var preset in PresetLibrary.Presets)
{ {
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
this.DrawPresetButton(preset); this.DrawPresetButton(preset);
if (GUILayout.Button("<b>X</b>", this.categoryButtonStyle, GUILayout.Width(30.0f))) if (GUILayout.Button("<b>X</b>", this.categoryButtonStyle, GUILayout.Width(30.0f)))
{ {
removePreset = preset; removePreset = preset;
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
if (removePreset != null && PresetLibrary.Remove(removePreset)) if (removePreset != null && PresetLibrary.Remove(removePreset))
{ {
this.presetList.Resize = true; this.presetList.Resize = true;
} }
   
this.DrawPresetSaveButton(); this.DrawPresetSaveButton();
} }
   
/// <summary> /// <summary>
/// Initialises all the styles required for this object. /// Initialises all the styles required for this object.
/// </summary> /// </summary>
private void InitialiseStyles() private void InitialiseStyles()
{ {
this.windowStyle = new GUIStyle(HighLogic.Skin.window); this.windowStyle = new GUIStyle(HighLogic.Skin.window);
   
this.categoryButtonStyle = new GUIStyle(HighLogic.Skin.button) this.categoryButtonStyle = new GUIStyle(HighLogic.Skin.button)
{ {
normal = normal =
{ {
textColor = Color.white textColor = Color.white
}, },
margin = new RectOffset(0, 0, 2, 0), margin = new RectOffset(0, 0, 2, 0),
padding = new RectOffset(5, 5, 5, 5), padding = new RectOffset(5, 5, 5, 5),
alignment = TextAnchor.MiddleCenter, alignment = TextAnchor.MiddleCenter,
fontSize = 12, fontSize = 12,
fontStyle = FontStyle.Normal, fontStyle = FontStyle.Normal,
richText = true richText = true
}; };
   
this.categoryButtonActiveStyle = new GUIStyle(this.categoryButtonStyle) this.categoryButtonActiveStyle = new GUIStyle(this.categoryButtonStyle)
{ {
normal = this.categoryButtonStyle.onNormal, normal = this.categoryButtonStyle.onNormal,
hover = this.categoryButtonStyle.onHover hover = this.categoryButtonStyle.onHover
}; };
   
this.panelTitleStyle = new GUIStyle(HighLogic.Skin.label) this.panelTitleStyle = new GUIStyle(HighLogic.Skin.label)
{ {
normal = normal =
{ {
textColor = Color.white textColor = Color.white
}, },
margin = new RectOffset(), margin = new RectOffset(),
padding = new RectOffset(), padding = new RectOffset(),
alignment = TextAnchor.MiddleLeft, alignment = TextAnchor.MiddleLeft,
fontSize = 12, fontSize = 12,
fontStyle = FontStyle.Bold, fontStyle = FontStyle.Bold,
fixedHeight = 30.0f, fixedHeight = 30.0f,
stretchWidth = true stretchWidth = true
}; };
   
this.textStyle = new GUIStyle(HighLogic.Skin.textField) this.textStyle = new GUIStyle(HighLogic.Skin.textField)
{ {
margin = new RectOffset(3, 3, 3, 3), margin = new RectOffset(3, 3, 3, 3),
alignment = TextAnchor.MiddleLeft, alignment = TextAnchor.MiddleLeft,
stretchWidth = true, stretchWidth = true,
stretchHeight = true stretchHeight = true
}; };
   
this.readoutNameStyle = new GUIStyle(HighLogic.Skin.label) this.readoutNameStyle = new GUIStyle(HighLogic.Skin.label)
{ {
normal = normal =
{ {
textColor = Color.white textColor = Color.white
}, },
margin = new RectOffset(), margin = new RectOffset(),
padding = new RectOffset(10, 0, 0, 0), padding = new RectOffset(10, 0, 0, 0),
alignment = TextAnchor.MiddleLeft, alignment = TextAnchor.MiddleLeft,
fontSize = 12, fontSize = 12,
fontStyle = FontStyle.Bold, fontStyle = FontStyle.Bold,
stretchWidth = true, stretchWidth = true,
stretchHeight = true stretchHeight = true
}; };
   
this.readoutButtonStyle = new GUIStyle(HighLogic.Skin.button) this.readoutButtonStyle = new GUIStyle(HighLogic.Skin.button)
{ {
normal = normal =
{ {
textColor = Color.white textColor = Color.white
}, },
margin = new RectOffset(2, 2, 2, 2), margin = new RectOffset(2, 2, 2, 2),
padding = new RectOffset(), padding = new RectOffset(),
alignment = TextAnchor.MiddleCenter, alignment = TextAnchor.MiddleCenter,
fontSize = 12, fontSize = 12,
fontStyle = FontStyle.Bold, fontStyle = FontStyle.Bold,
stretchHeight = true stretchHeight = true
}; };
   
this.helpBoxStyle = new GUIStyle(HighLogic.Skin.box) this.helpBoxStyle = new GUIStyle(HighLogic.Skin.box)
{ {
margin = new RectOffset(2, 2, 2, 10), margin = new RectOffset(2, 2, 2, 10),
padding = new RectOffset(10, 10, 10, 10) padding = new RectOffset(10, 10, 10, 10)
}; };
   
this.helpTextStyle = new GUIStyle(HighLogic.Skin.label) this.helpTextStyle = new GUIStyle(HighLogic.Skin.label)
{ {
normal = normal =
{ {
textColor = Color.yellow textColor = Color.yellow
}, },
margin = new RectOffset(), margin = new RectOffset(),
padding = new RectOffset(), padding = new RectOffset(),
alignment = TextAnchor.MiddleLeft, alignment = TextAnchor.MiddleLeft,
fontSize = 13, fontSize = 13,
fontStyle = FontStyle.Normal, fontStyle = FontStyle.Normal,
stretchWidth = true, stretchWidth = true,
richText = true richText = true
}; };
   
this.categoryTitleButtonStyle = new GUIStyle(this.readoutButtonStyle) this.categoryTitleButtonStyle = new GUIStyle(this.readoutButtonStyle)
{ {
fixedHeight = 30.0f, fixedHeight = 30.0f,
stretchHeight = false stretchHeight = false
}; };
} }
   
private void SavePreset(Preset preset) private void SavePreset(Preset preset)
{ {
if (preset == null) if (preset == null)
{ {
preset = new Preset(); preset = new Preset();
} }
   
preset.Name = this.ParentSection.Name; preset.Name = this.ParentSection.Name;
preset.Abbreviation = this.ParentSection.Abbreviation; preset.Abbreviation = this.ParentSection.Abbreviation;
preset.ReadoutNames = this.ParentSection.ReadoutModuleNames; preset.ReadoutNames = this.ParentSection.ReadoutModuleNames;
preset.IsHud = this.ParentSection.IsHud; preset.IsHud = this.ParentSection.IsHud;
preset.IsHudBackground = this.ParentSection.IsHudBackground; preset.IsHudBackground = this.ParentSection.IsHudBackground;
   
PresetLibrary.Save(preset); PresetLibrary.Save(preset);
} }
   
private void ShowHelpMessage(ReadoutModule readout) private void ShowHelpMessage(ReadoutModule readout)
{ {
if (!readout.ShowHelp) if (!readout.ShowHelp)
{ {
return; return;
} }
   
GUILayout.BeginVertical(this.helpBoxStyle); GUILayout.BeginVertical(this.helpBoxStyle);
GUILayout.Label(!String.IsNullOrEmpty(readout.HelpString) ? readout.HelpString : "Sorry, no help information has been provided for this readout module.", this.helpTextStyle); GUILayout.Label(!String.IsNullOrEmpty(readout.HelpString) ? readout.HelpString : "Sorry, no help information has been provided for this readout module.", this.helpTextStyle);
GUILayout.EndVertical(); GUILayout.EndVertical();
} }
   
/// <summary> /// <summary>
/// Draws the editor window. /// Draws the editor window.
/// </summary> /// </summary>
private void Window(int windowId) private void Window(int windowId)
{ {
try try
{ {
this.DrawCustomOptions(); this.DrawCustomOptions();
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
this.DrawCategorySelector(); this.DrawCategorySelector();
this.DrawPresetSelector(); this.DrawPresetSelector();
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
this.DrawAvailableReadouts(); this.DrawAvailableReadouts();
GUILayout.Space(5.0f); GUILayout.Space(5.0f);
this.DrawInstalledReadouts(); this.DrawInstalledReadouts();
   
if (GUILayout.Button("CLOSE EDITOR", this.categoryTitleButtonStyle)) if (GUILayout.Button("CLOSE EDITOR", this.categoryTitleButtonStyle))
{ {
this.ParentSection.IsEditorVisible = false; this.ParentSection.IsEditorVisible = false;
} }
   
GUI.DragWindow(); GUI.DragWindow();
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
#endregion #endregion
} }
} }
 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ