Skip to content

Commit

Permalink
DisplayModule cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Oct 30, 2023
1 parent e60798f commit 4bff466
Show file tree
Hide file tree
Showing 30 changed files with 227 additions and 242 deletions.
238 changes: 111 additions & 127 deletions MechJeb2/DisplayModule.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions MechJeb2/GuiUtils.cs
Expand Up @@ -769,8 +769,8 @@ public static bool MouseIsOverWindow(MechJebCore core)
//try to check if the mouse is over any active DisplayModule
foreach (DisplayModule m in core.GetComputerModules<DisplayModule>())
{
if (m.Enabled && m.showInCurrentScene && !m.IsOverlay
&& m.windowPos.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y) / scale))
if (m.Enabled && m.ShowInCurrentScene && !m.IsOverlay
&& m.WindowPos.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y) / scale))
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebAR202.cs
Expand Up @@ -100,7 +100,7 @@ private void HandleLights()
foreach (DisplayModule display in core.GetDisplayModules(MechJebModuleMenu.DisplayOrder.instance))
{
if (display is MechJebModuleMenu) continue;
if (display.Enabled && display.showInCurrentScene)
if (display.Enabled && display.ShowInCurrentScene)
{
somethingEnabled = true;
}
Expand Down
10 changes: 5 additions & 5 deletions MechJeb2/MechJebCore.cs
Expand Up @@ -166,7 +166,7 @@ private void EngageSmartASSOrbitalControl(MechJebModuleSmartASS.Target smartassT

MechJebModuleSmartASS masterSmartASS = masterMechJeb.GetComputerModule<MechJebModuleSmartASS>();

if (masterSmartASS is { hidden: false })
if (masterSmartASS is { Hidden: false })
{
masterSmartASS.mode = MechJebModuleSmartASS.Mode.ORBITAL;
masterSmartASS.target = smartassTarget;
Expand All @@ -190,7 +190,7 @@ public void OnPanicAction(KSPActionParam param)

MechJebModuleTranslatron moduleTranslatron = masterMechJeb.GetComputerModule<MechJebModuleTranslatron>();

if (moduleTranslatron is { hidden: false })
if (moduleTranslatron is { Hidden: false })
moduleTranslatron.PanicSwitch();
}

Expand Down Expand Up @@ -218,7 +218,7 @@ public void OnTranslatronToggleHSAction(KSPActionParam param)
{
MechJebModuleTranslatron moduleTranslatron = masterMechJeb.GetComputerModule<MechJebModuleTranslatron>();

if (moduleTranslatron is { hidden: false })
if (moduleTranslatron is { Hidden: false })
{
Thrust.TransKillH = !Thrust.TransKillH;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ private void EngageTranslatronControl(MechJebModuleThrustController.TMode mode)

MechJebModuleTranslatron moduleTranslatron = masterMechJeb.GetComputerModule<MechJebModuleTranslatron>();

if (moduleTranslatron is { hidden: false })
if (moduleTranslatron is { Hidden: false })
{
if (Thrust.Users.Count > 1 && !Thrust.Users.Contains(moduleTranslatron))
return;
Expand All @@ -289,7 +289,7 @@ private void SetTranslatronSpeed(float speed, bool relative = false)

MechJebModuleTranslatron moduleTranslatron = masterMechJeb.GetComputerModule<MechJebModuleTranslatron>();

if (moduleTranslatron is { hidden: false })
if (moduleTranslatron is { Hidden: false })
Thrust.TransSpdAct = (relative ? Thrust.TransSpdAct : 0) + speed;
else
Debug.LogError("MechJeb couldn't find MechJebModuleTranslatron for translatron control via action group.");
Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleAirplaneGuidance.cs
Expand Up @@ -415,7 +415,7 @@ protected override void WindowGUI(int windowID)
base.WindowGUI(windowID);
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(300), GUILayout.Height(200) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(300), GUILayout.Height(200) };

public override string GetName() => Localizer.Format("#MechJeb_Aircraftauto_title"); //Aircraft Autopilot

Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/MechJebModuleAscentClassicPathMenu.cs
Expand Up @@ -12,7 +12,7 @@ public class MechJebModuleAscentClassicPathMenu : DisplayModule
public MechJebModuleAscentClassicPathMenu(MechJebCore core)
: base(core)
{
hidden = true;
Hidden = true;
}

private MechJebModuleAscentSettings _ascentSettings;
Expand All @@ -28,7 +28,7 @@ public override void OnStart(PartModule.StartState state)
_path = Core.GetComputerModule<MechJebModuleAscentClassicAutopilot>();
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(300), GUILayout.Height(100) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(300), GUILayout.Height(100) };

protected override void WindowGUI(int windowID)
{
Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleAscentMenu.cs
Expand Up @@ -520,7 +520,7 @@ private string PhaseString(Solution solution, double t, int pvgPhase)
return $"burn: {kspStage} {solution.Tgo(t, pvgPhase):F1}s {solution.DV(t, pvgPhase):F1}m/s ({excessDV:F1}m/s)";
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(275), GUILayout.Height(30) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(275), GUILayout.Height(30) };

public override string GetName() => CachedLocalizer.Instance.MechJebAscentTitle; //"Ascent Guidance"

Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/MechJebModuleAscentPVGSettingsMenu.cs
Expand Up @@ -11,15 +11,15 @@ public class MechJebModuleAscentPVGSettingsMenu : DisplayModule
{
public MechJebModuleAscentPVGSettingsMenu(MechJebCore core) : base(core)
{
hidden = true;
Hidden = true;
}

private MechJebModuleAscentSettings _ascentSettings => Core.AscentSettings;

private static GUIStyle _btNormal;
private static GUIStyle _btActive;

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(300), GUILayout.Height(100) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(300), GUILayout.Height(100) };

private void SetupButtonStyles()
{
Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/MechJebModuleAscentSettingsMenu.cs
Expand Up @@ -9,7 +9,7 @@ public class MechJebModuleAscentSettingsMenu : DisplayModule
{
public MechJebModuleAscentSettingsMenu(MechJebCore core) : base(core)
{
hidden = true;
Hidden = true;
}

private MechJebModuleAscentSettings _ascentSettings => Core.AscentSettings;
Expand Down Expand Up @@ -123,7 +123,7 @@ protected override void WindowGUI(int windowID)
base.WindowGUI(windowID);
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(275), GUILayout.Height(30) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(275), GUILayout.Height(30) };

public override string GetName() => "Ascent Settings";

Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleAttitudeAdjustment.cs
Expand Up @@ -154,7 +154,7 @@ protected override void WindowGUI(int windowID)
base.WindowGUI(windowID);
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(350), GUILayout.Height(150) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(350), GUILayout.Height(150) };

public override string GetName() => Localizer.Format("#MechJeb_AttitudeAdjust_title"); //Attitude Adjustment

Expand Down
28 changes: 14 additions & 14 deletions MechJeb2/MechJebModuleCustomInfoWindow.cs
Expand Up @@ -135,7 +135,7 @@ protected override void WindowGUI(int windowID)
base.WindowGUI(windowID);
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(250), GUILayout.Height(30) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(250), GUILayout.Height(30) };

public override void DrawGUI(bool inEditor)
{
Expand Down Expand Up @@ -253,7 +253,7 @@ public override void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global
bool loadedEnabled;
if (bool.TryParse(windowNode.GetValue("enabledEditor"), out loadedEnabled))
{
window.enabledEditor = loadedEnabled;
window.EnabledEditor = loadedEnabled;
useOldConfig = false;
if (HighLogic.LoadedSceneIsEditor)
window.Enabled = loadedEnabled;
Expand All @@ -265,7 +265,7 @@ public override void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global
bool loadedEnabled;
if (bool.TryParse(windowNode.GetValue("enabledFlight"), out loadedEnabled))
{
window.enabledFlight = loadedEnabled;
window.EnabledFlight = loadedEnabled;
useOldConfig = false;
if (HighLogic.LoadedSceneIsFlight)
window.Enabled = loadedEnabled;
Expand All @@ -280,13 +280,13 @@ public override void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global
if (bool.TryParse(windowNode.GetValue("enabled"), out loadedEnabled))
{
window.Enabled = loadedEnabled;
window.enabledEditor = window.Enabled;
window.enabledFlight = window.Enabled;
window.EnabledEditor = window.Enabled;
window.EnabledFlight = window.Enabled;
}
}

window.enabledEditor = window.Enabled;
window.enabledFlight = window.Enabled;
window.EnabledEditor = window.Enabled;
window.EnabledFlight = window.Enabled;
}

window.items = new List<InfoItem>();
Expand Down Expand Up @@ -320,12 +320,12 @@ public override void OnSave(ConfigNode local, ConfigNode type, ConfigNode global
var windowNode = ConfigNode.CreateConfigFromObject(window, (int)Pass.GLOBAL, null);

if (HighLogic.LoadedSceneIsEditor)
window.enabledEditor = window.Enabled;
window.EnabledEditor = window.Enabled;
if (HighLogic.LoadedSceneIsFlight)
window.enabledFlight = window.Enabled;
window.EnabledFlight = window.Enabled;

windowNode.AddValue("enabledFlight", window.enabledFlight);
windowNode.AddValue("enabledEditor", window.enabledEditor);
windowNode.AddValue("enabledFlight", window.EnabledFlight);
windowNode.AddValue("enabledEditor", window.EnabledEditor);
windowNode.CopyTo(global.AddNode(name));
window.Dirty = false;
}
Expand Down Expand Up @@ -380,7 +380,7 @@ public override void DrawGUI(bool inEditor)
{
editedWindow.Init();

Color newColor = ColorPickerRGB.DrawGUI((int)windowPos.xMax + 5, (int)windowPos.yMin, editedWindow.backgroundColor);
Color newColor = ColorPickerRGB.DrawGUI((int)WindowPos.xMax + 5, (int)WindowPos.yMin, editedWindow.backgroundColor);

if (editedWindow.backgroundColor != newColor)
{
Expand All @@ -396,7 +396,7 @@ public override void DrawGUI(bool inEditor)
{
if (editedWindow != null)
{
Color newColor = ColorPickerRGB.DrawGUI((int)windowPos.xMax + 5, (int)windowPos.yMin, editedWindow.text);
Color newColor = ColorPickerRGB.DrawGUI((int)WindowPos.xMax + 5, (int)WindowPos.yMin, editedWindow.text);
if (editedWindow.text != newColor)
{
editedWindow.text = newColor;
Expand Down Expand Up @@ -552,7 +552,7 @@ protected override void WindowGUI(int windowID)
base.WindowGUI(windowID);
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(200), GUILayout.Height(540) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(200), GUILayout.Height(540) };

public override string GetName() => CachedLocalizer.Instance.MechJebWindowEdTitle; //Custom Window Editor

Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleDockingGuidance.cs
Expand Up @@ -139,7 +139,7 @@ protected override void WindowGUI(int windowID)
base.WindowGUI(windowID);
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(300), GUILayout.Height(50) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(300), GUILayout.Height(50) };

protected override void OnModuleDisabled()
{
Expand Down
63 changes: 32 additions & 31 deletions MechJeb2/MechJebModuleFlightRecorderGraph.cs
Expand Up @@ -326,7 +326,8 @@ protected override void WindowGUI(int windowID)

GUI.color = XKCDColors.Cerise;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.STEERING_LOSSES].display = GUILayout.Toggle(
graphStates[(int)MechJebModuleFlightRecorder.RecordType.STEERING_LOSSES].display, Localizer.Format("#MechJeb_Flightrecord_checkbox17"),
graphStates[(int)MechJebModuleFlightRecorder.RecordType.STEERING_LOSSES].display,
Localizer.Format("#MechJeb_Flightrecord_checkbox17"),
GUILayout.ExpandWidth(false)); //"Steering Loss"

GUI.color = color;
Expand Down Expand Up @@ -727,40 +728,40 @@ private void UpdateScale()
private void ResetScale()
{
// Avoid min = max and set sane minimums
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ALTITUDE_ASL].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DOWN_RANGE].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ACCELERATION].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.SPEED_SURFACE].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.SPEED_ORBITAL].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.MASS].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.Q].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_A].minimum = -5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_S].minimum = -5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_D].minimum = 0; // is never negative
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ALTITUDE_TRUE].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.PITCH].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ALTITUDE_ASL].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DOWN_RANGE].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ACCELERATION].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.SPEED_SURFACE].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.SPEED_ORBITAL].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.MASS].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.Q].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_A].minimum = -5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_S].minimum = -5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_D].minimum = 0; // is never negative
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ALTITUDE_TRUE].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.PITCH].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DELTA_V_EXPENDED].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.GRAVITY_LOSSES].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DRAG_LOSSES].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.STEERING_LOSSES].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.GRAVITY_LOSSES].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DRAG_LOSSES].minimum = 0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.STEERING_LOSSES].minimum = 0;

graphStates[(int)MechJebModuleFlightRecorder.RecordType.ALTITUDE_ASL].maximum =
MainBody != null && MainBody.atmosphere ? MainBody.RealMaxAtmosphereAltitude() : 10000.0;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DOWN_RANGE].maximum = 500;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ACCELERATION].maximum = 2;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.SPEED_SURFACE].maximum = 300;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.SPEED_ORBITAL].maximum = 300;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.MASS].maximum = 5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.Q].maximum = 1000;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_A].maximum = 5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_S].maximum = 5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_D].maximum = 5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ALTITUDE_TRUE].maximum = 100;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.PITCH].maximum = 90;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DOWN_RANGE].maximum = 500;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ACCELERATION].maximum = 2;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.SPEED_SURFACE].maximum = 300;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.SPEED_ORBITAL].maximum = 300;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.MASS].maximum = 5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.Q].maximum = 1000;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_A].maximum = 5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_S].maximum = 5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.AO_D].maximum = 5;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.ALTITUDE_TRUE].maximum = 100;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.PITCH].maximum = 90;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DELTA_V_EXPENDED].maximum = 100;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.GRAVITY_LOSSES].maximum = 100;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DRAG_LOSSES].maximum = 100;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.STEERING_LOSSES].maximum = 100;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.GRAVITY_LOSSES].maximum = 100;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.DRAG_LOSSES].maximum = 100;
graphStates[(int)MechJebModuleFlightRecorder.RecordType.STEERING_LOSSES].maximum = 100;
}

private double heckbertNiceNum(double x, bool round)
Expand Down Expand Up @@ -795,7 +796,7 @@ private double heckbertNiceNum(double x, bool round)
return nf * Math.Pow(10.0, exp);
}

public override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(400), GUILayout.Height(300) };
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(400), GUILayout.Height(300) };

public override string GetName() => Localizer.Format("#MechJeb_Flightrecord_title"); //"Flight Recorder"

Expand Down

0 comments on commit 4bff466

Please sign in to comment.