Skip to content

Commit

Permalink
GuiUtils 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 31, 2023
1 parent 37b09f4 commit 6099021
Show file tree
Hide file tree
Showing 49 changed files with 628 additions and 672 deletions.
3 changes: 3 additions & 0 deletions MechJeb2.sln.DotSettings
Expand Up @@ -6,10 +6,13 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ATM/@EntryIndexedValue">ATM</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BCI/@EntryIndexedValue">BCI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BS/@EntryIndexedValue">BS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DHMS/@EntryIndexedValue">DHMS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DMS/@EntryIndexedValue">DMS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DP/@EntryIndexedValue">DP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ECC/@EntryIndexedValue">ECC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ECI/@EntryIndexedValue">ECI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ENU/@EntryIndexedValue">ENU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ETA/@EntryIndexedValue">ETA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FFS/@EntryIndexedValue">FFS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FPA/@EntryIndexedValue">FPA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HS/@EntryIndexedValue">HS</s:String>
Expand Down
60 changes: 30 additions & 30 deletions MechJeb2/AttitudeControllers/BetterController.cs
Expand Up @@ -96,22 +96,22 @@ internal class BetterController : BaseAttitudeController

private void Defaults()
{
PosKp.val = 1.98;
PosDeadband.val = 0.002;
VelKp.val = 10;
VelKi.val = 20;
VelKd.val = 0.425;
VelN.val = 84.1994541201249;
VelB.val = 0.994;
VelC.val = 0.0185;
VelDeadband.val = 0.0001;
PosKp.Val = 1.98;
PosDeadband.Val = 0.002;
VelKp.Val = 10;
VelKi.Val = 20;
VelKd.Val = 0.425;
VelN.Val = 84.1994541201249;
VelB.Val = 0.994;
VelC.Val = 0.0185;
VelDeadband.Val = 0.0001;
VelClegg = false;
VelSmoothIn.val = 1.0;
VelSmoothOut.val = 1.0;
PosSmoothIn.val = 1.0;
MaxStoppingTime.val = 2;
MinFlipTime.val = 120;
RollControlRange.val = 5;
VelSmoothIn.Val = 1.0;
VelSmoothOut.Val = 1.0;
PosSmoothIn.Val = 1.0;
MaxStoppingTime.Val = 2;
MinFlipTime.Val = 120;
RollControlRange.Val = 5;
Version = SETTINGS_VERSION;
}

Expand Down Expand Up @@ -306,12 +306,12 @@ public override void GUI()
{
GUILayout.BeginHorizontal();
UseStoppingTime = GUILayout.Toggle(UseStoppingTime, "Maximum Stopping Time", GUILayout.ExpandWidth(false));
MaxStoppingTime.text = GUILayout.TextField(MaxStoppingTime.text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
MaxStoppingTime.Text = GUILayout.TextField(MaxStoppingTime.Text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
UseFlipTime = GUILayout.Toggle(UseFlipTime, "Minimum Flip Time", GUILayout.ExpandWidth(false));
MinFlipTime.text = GUILayout.TextField(MinFlipTime.text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
MinFlipTime.Text = GUILayout.TextField(MinFlipTime.Text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
GUILayout.EndHorizontal();

if (!UseStoppingTime)
Expand All @@ -320,57 +320,57 @@ public override void GUI()
GUILayout.BeginHorizontal();
UseControlRange = GUILayout.Toggle(UseControlRange, Localizer.Format("#MechJeb_HybridController_checkbox2"),
GUILayout.ExpandWidth(false)); //"RollControlRange"
RollControlRange.text = GUILayout.TextField(RollControlRange.text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
RollControlRange.Text = GUILayout.TextField(RollControlRange.Text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Pos SmoothIn", GUILayout.ExpandWidth(false));
PosSmoothIn.text = GUILayout.TextField(PosSmoothIn.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
PosSmoothIn.Text = GUILayout.TextField(PosSmoothIn.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Pos Kp", GUILayout.ExpandWidth(false));
PosKp.text = GUILayout.TextField(PosKp.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
PosKp.Text = GUILayout.TextField(PosKp.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Pos Deadband", GUILayout.ExpandWidth(false));
PosDeadband.text = GUILayout.TextField(PosDeadband.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
PosDeadband.Text = GUILayout.TextField(PosDeadband.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Vel Kp", GUILayout.ExpandWidth(false));
VelKp.text = GUILayout.TextField(VelKp.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelKp.Text = GUILayout.TextField(VelKp.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Vel Ki", GUILayout.ExpandWidth(false));
VelKi.text = GUILayout.TextField(VelKi.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelKi.Text = GUILayout.TextField(VelKi.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Vel Kd", GUILayout.ExpandWidth(false));
VelKd.text = GUILayout.TextField(VelKd.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelKd.Text = GUILayout.TextField(VelKd.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Vel N", GUILayout.ExpandWidth(false));
VelN.text = GUILayout.TextField(VelN.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelN.Text = GUILayout.TextField(VelN.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Vel B", GUILayout.ExpandWidth(false));
VelB.text = GUILayout.TextField(VelB.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelB.Text = GUILayout.TextField(VelB.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Vel C", GUILayout.ExpandWidth(false));
VelC.text = GUILayout.TextField(VelC.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelC.Text = GUILayout.TextField(VelC.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Vel Deadband", GUILayout.ExpandWidth(false));
VelDeadband.text = GUILayout.TextField(VelDeadband.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelDeadband.Text = GUILayout.TextField(VelDeadband.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
Expand All @@ -379,12 +379,12 @@ public override void GUI()

GUILayout.BeginHorizontal();
GUILayout.Label("Vel SmoothIn", GUILayout.ExpandWidth(false));
VelSmoothIn.text = GUILayout.TextField(VelSmoothIn.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelSmoothIn.Text = GUILayout.TextField(VelSmoothIn.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Vel SmoothOut", GUILayout.ExpandWidth(false));
VelSmoothOut.text = GUILayout.TextField(VelSmoothOut.text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
VelSmoothOut.Text = GUILayout.TextField(VelSmoothOut.Text, GUILayout.ExpandWidth(true), GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/AttitudeControllers/HybridController.cs
Expand Up @@ -154,13 +154,13 @@ public override void GUI()

GUILayout.BeginHorizontal();
GUILayout.Label(Localizer.Format("#MechJeb_HybridController_label1"), GUILayout.ExpandWidth(false)); //"MaxStoppingTime"
MaxStoppingTime.text = GUILayout.TextField(MaxStoppingTime.text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
MaxStoppingTime.Text = GUILayout.TextField(MaxStoppingTime.Text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
UseControlRange = GUILayout.Toggle(UseControlRange, Localizer.Format("#MechJeb_HybridController_checkbox2"),
GUILayout.ExpandWidth(false)); //"RollControlRange"
RollControlRange.text = GUILayout.TextField(RollControlRange.text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
RollControlRange.Text = GUILayout.TextField(RollControlRange.Text, GUILayout.ExpandWidth(true), GUILayout.Width(60));
GUILayout.EndHorizontal();

// Not used yet
Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/AttitudeControllers/KosAttitudeController.cs
Expand Up @@ -164,13 +164,13 @@ public override void GUI()
{
GUILayout.BeginHorizontal();
GUILayout.Label("MaxStoppingTime", GUILayout.ExpandWidth(false));
MaxStoppingTime.text = GUILayout.TextField(MaxStoppingTime.text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
MaxStoppingTime.Text = GUILayout.TextField(MaxStoppingTime.Text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
GUILayout.EndHorizontal();


GUILayout.BeginHorizontal();
GUILayout.Label("RollControlRange", GUILayout.ExpandWidth(false));
RollControlRange.text = GUILayout.TextField(RollControlRange.text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
RollControlRange.Text = GUILayout.TextField(RollControlRange.Text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
Expand Down
8 changes: 5 additions & 3 deletions MechJeb2/AttitudeControllers/MJAttitudeController.cs
Expand Up @@ -3,6 +3,8 @@
using KSP.Localization;
using UnityEngine;

// ReSharper disable CompareOfFloatsByEqualityOperator

namespace MuMech.AttitudeControllers
{
internal class MJAttitudeController : BaseAttitudeController
Expand Down Expand Up @@ -257,11 +259,11 @@ public override void GUI()
GUILayout.BeginHorizontal();
GUILayout.Label(Localizer.Format("#MechJeb_AttitudeController_label2"), GUILayout.ExpandWidth(true)); //"Tf (s)"
GUILayout.Label(Localizer.Format("#MechJeb_AttitudeController_label3"), GUILayout.ExpandWidth(false)); //"P"
_uiTfX.text = GUILayout.TextField(_uiTfX.text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
_uiTfX.Text = GUILayout.TextField(_uiTfX.Text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
GUILayout.Label(Localizer.Format("#MechJeb_AttitudeController_label4"), GUILayout.ExpandWidth(false)); //"Y"
_uiTfY.text = GUILayout.TextField(_uiTfY.text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
_uiTfY.Text = GUILayout.TextField(_uiTfY.Text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
GUILayout.Label(Localizer.Format("#MechJeb_AttitudeController_label5"), GUILayout.ExpandWidth(false)); //"R"
_uiTfZ.text = GUILayout.TextField(_uiTfZ.text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
_uiTfZ.Text = GUILayout.TextField(_uiTfZ.Text, GUILayout.ExpandWidth(true), GUILayout.Width(40));
GUILayout.EndHorizontal();

_uiTfX = Math.Max(0.01, _uiTfX);
Expand Down
5 changes: 4 additions & 1 deletion MechJeb2/CelestialBodyExtensions.cs
@@ -1,4 +1,6 @@
namespace MuMech
using JetBrains.Annotations;

namespace MuMech
{
public static class CelestialBodyExtensions
{
Expand All @@ -9,6 +11,7 @@ public static class CelestialBodyExtensions
//the ship's drag coefficient. In this equation b has units of inverse length. So 1/b
//is a characteristic length: a ship that travels this distance through air will lose a significant
//fraction of its initial velocity
[UsedImplicitly]
public static double DragLength(this CelestialBody body, Vector3d pos, double dragCoeff, double mass)
{
double airDensity =
Expand Down
24 changes: 12 additions & 12 deletions MechJeb2/DisplayModule.cs
Expand Up @@ -18,26 +18,26 @@ public Rect WindowPos
protected set
{
var newPos = new Vector4(
Math.Min(Math.Max(value.x, 0), GuiUtils.scaledScreenWidth - value.width),
Math.Min(Math.Max(value.y, 0), GuiUtils.scaledScreenHeight - value.height),
Math.Min(Math.Max(value.x, 0), GuiUtils.ScaledScreenWidth - value.width),
Math.Min(Math.Max(value.y, 0), GuiUtils.ScaledScreenHeight - value.height),
value.width, value.height
);
newPos.x = Mathf.Clamp(newPos.x, 10 - value.width, GuiUtils.scaledScreenWidth - 10);
newPos.y = Mathf.Clamp(newPos.y, 10 - value.height, GuiUtils.scaledScreenHeight - 10);
newPos.x = Mathf.Clamp(newPos.x, 10 - value.width, GuiUtils.ScaledScreenWidth - 10);
newPos.y = Mathf.Clamp(newPos.y, 10 - value.height, GuiUtils.ScaledScreenHeight - 10);

if (!HighLogic.LoadedSceneIsEditor)
{
if (WindowVector != newPos)
{
Dirty = true;
Dirty = true;
WindowVector = newPos;
}
}
else
{
if (WindowVectorEditor != newPos)
{
Dirty = true;
Dirty = true;
WindowVectorEditor = newPos;
}
}
Expand Down Expand Up @@ -66,7 +66,7 @@ public bool ShowInFlight
if (ShowInFlightConfig != value)
{
ShowInFlightConfig = value;
Dirty = true;
Dirty = true;
}
}
}
Expand All @@ -82,7 +82,7 @@ public bool ShowInEditor
{
if (ShowInEditorConfig == value) return;
ShowInEditorConfig = value;
Dirty = true;
Dirty = true;
}
}

Expand All @@ -97,7 +97,7 @@ public bool IsOverlay
{
if (IsOverlayConfig == value) return;
IsOverlayConfig = value;
Dirty = true;
Dirty = true;
}
}

Expand All @@ -112,7 +112,7 @@ public bool Locked
{
if (LockedConfig == value) return;
LockedConfig = value;
Dirty = true;
Dirty = true;
}
}

Expand Down Expand Up @@ -150,8 +150,8 @@ protected void WindowGUI(int windowID, bool draggable)
bool allowDrag = !LockedConfig;
if (!LockedConfig && !IsOverlayConfig && Core.Settings.useTitlebarDragging)
{
float x = Mouse.screenPos.x / GuiUtils.scale;
float y = Mouse.screenPos.y / GuiUtils.scale;
float x = Mouse.screenPos.x / GuiUtils.Scale;
float y = Mouse.screenPos.y / GuiUtils.Scale;
allowDrag = x >= WindowPos.xMin + 3 && x <= WindowPos.xMin + WindowPos.width - 3 &&
y >= WindowPos.yMin + 3 && y <= WindowPos.yMin + 17;
}
Expand Down

0 comments on commit 6099021

Please sign in to comment.