Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions SmartSASMod/GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,47 @@ public static void SpawnGUI()
Vector2Int pos = SettingsManager.settings.windowPosition;
Window window = Builder.CreateWindow(holder.transform, MainWindowID, 360, 290, pos.x, pos.y, true, true, 0.95f, "Smart SAS");

window.gameObject.GetComponent<DraggableWindowModule>().OnDropAction += () =>
window.CreateLayoutGroup(SFS.UI.ModGUI.Type.Vertical, UnityEngine.TextAnchor.MiddleCenter,10f);
window.gameObject.GetComponent<DraggableWindowModule>().OnDropAction += () =>
{
SettingsManager.settings.windowPosition = Vector2Int.RoundToInt(window.Position);
SettingsManager.Save();
};

buttons = new Dictionary<DirectionMode, SFS.UI.ModGUI.Button>
{
{DirectionMode.Prograde, Builder.CreateButton(window, 160, 50, -85, -25, () => ToggleDirection(DirectionMode.Prograde), "Prograde")},
{DirectionMode.Target, Builder.CreateButton(window, 160, 50, 85, -25, () => ToggleDirection(DirectionMode.Target), "Target")},
{DirectionMode.Surface, Builder.CreateButton(window, 160, 50, -85, -80, () => ToggleDirection(DirectionMode.Surface), "Surface")},
{DirectionMode.None, Builder.CreateButton(window, 160, 50, 85, -80, () => ToggleDirection(DirectionMode.None), "None")}
};
buttons = new Dictionary<DirectionMode, SFS.UI.ModGUI.Button>();

SFS.UI.ModGUI.Container buttonsTop_Container = SFS.UI.ModGUI.Builder.CreateContainer(window);
buttonsTop_Container.CreateLayoutGroup(SFS.UI.ModGUI.Type.Horizontal, UnityEngine.TextAnchor.MiddleCenter,5f);
buttons.Add(DirectionMode.Prograde, Builder.CreateButton(buttonsTop_Container, 160, 50, 0,0, () => ToggleDirection(DirectionMode.Prograde), "Prograde"));
buttons.Add(DirectionMode.Target, Builder.CreateButton(buttonsTop_Container, 160, 50, 0, 0, () => ToggleDirection(DirectionMode.Target), "Target"));

SFS.UI.ModGUI.Container buttonsBottom_Container = SFS.UI.ModGUI.Builder.CreateContainer(window);
buttonsBottom_Container.CreateLayoutGroup(SFS.UI.ModGUI.Type.Horizontal, UnityEngine.TextAnchor.MiddleCenter,5f);
buttons.Add(DirectionMode.Surface, Builder.CreateButton(buttonsBottom_Container, 160, 50, 0, 0, () => ToggleDirection(DirectionMode.Surface), "Surface"));
buttons.Add(DirectionMode.None, Builder.CreateButton(buttonsBottom_Container, 160, 50, 0, 0, () => ToggleDirection(DirectionMode.None), "None"));

Builder.CreateLabel(window, 180, 50, 0, -145, "Angle Offset");
angleInput = Builder.CreateTextInput(window, 110, 50, 0, -200, "0.00");
//~ angleInput = Builder.CreateTextInput(window, 110, 50, 0, -200, "0.00");
//~ angleInput.field.onEndEdit.AddListener(VerifyOffsetInput);

//~ Builder.CreateButton(window, 50, 50, -140, -200, () => AddOffsetValue(-10), "<<");
//~ Builder.CreateButton(window, 50, 50, -85, -200, () => AddOffsetValue(-1), "<");
//~ Builder.CreateButton(window, 50, 50, 140, -200, () => AddOffsetValue(10), ">>");
//~ Builder.CreateButton(window, 50, 50, 85, -200, () => AddOffsetValue(1), ">");

SFS.UI.ModGUI.Container offset_Container = SFS.UI.ModGUI.Builder.CreateContainer(window);
offset_Container.CreateLayoutGroup(SFS.UI.ModGUI.Type.Horizontal, UnityEngine.TextAnchor.MiddleCenter,5f);

Builder.CreateButton(offset_Container, 40, 30, 0, 0, () => AddOffsetValue(-90), "<<<");
Builder.CreateButton(offset_Container, 30, 30, 0, 0, () => AddOffsetValue(-10), "<<");
Builder.CreateButton(offset_Container, 30, 30, 0, 0, () => AddOffsetValue(-1), "<");

angleInput = Builder.CreateTextInput(offset_Container, 110, 50, 0, 0, "0.00");
angleInput.field.onEndEdit.AddListener(VerifyOffsetInput);

Builder.CreateButton(window, 50, 50, -140, -200, () => AddOffsetValue(-10), "<<");
Builder.CreateButton(window, 50, 50, -85, -200, () => AddOffsetValue(-1), "<");
Builder.CreateButton(window, 50, 50, 140, -200, () => AddOffsetValue(10), ">>");
Builder.CreateButton(window, 50, 50, 85, -200, () => AddOffsetValue(1), ">");
Builder.CreateButton(offset_Container, 30, 30, 0, 0, () => AddOffsetValue(1), ">");
Builder.CreateButton(offset_Container, 30, 30, 0, 0, () => AddOffsetValue(10), ">>");
Builder.CreateButton(offset_Container, 40, 30, 0, 0, () => AddOffsetValue(90), ">>>");

window.gameObject.transform.localScale = new Vector3(SettingsManager.settings.windowScale, SettingsManager.settings.windowScale, 1f);

Expand Down
12 changes: 6 additions & 6 deletions SmartSASMod/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ namespace SmartSASMod
{
public class Main : Mod
{
public override string ModNameID => "smartsas";
public override string DisplayName => "Smart SAS";
public override string Author => "Astro The Rabbit";
public override string ModNameID => "smartsasdarth";
public override string DisplayName => "Smart SAS (Darthan Fork)";
public override string Author => "Astro The Rabbit, Darthan184";
public override string MinimumGameVersionNecessary => "1.5.10.2";
public override string ModVersion => "1.7";
public override string ModVersion => "1.7-Darthan184-1";
public override string Description => "Adds a variety of control options for the stability assist system (SAS).";

public override Dictionary<string, string> Dependencies { get; } = new Dictionary<string, string> { { "UITools", "1.1.5" } };
public Dictionary<string, FilePath> UpdatableFiles => new Dictionary<string, FilePath>() { { "https://github.com/AstroTheRabbit/Smart-SAS-Mod-SFS/releases/latest/download/SmartSASMod.dll", new FolderPath(ModFolder).ExtendToFile("SmartSASMod.dll") } };
//~ public Dictionary<string, FilePath> UpdatableFiles => new Dictionary<string, FilePath>() { { "https://github.com/AstroTheRabbit/Smart-SAS-Mod-SFS/releases/latest/download/SmartSASMod.dll", new FolderPath(ModFolder).ExtendToFile("SmartSASMod.dll") } };

public static Mod mod;
public static FolderPath modFolder;
Expand All @@ -44,7 +44,7 @@ public override void Load()
Assembly ANAISAssembly = Loader.main.GetLoadedMods().First(mod => mod.ModNameID == "ANAIS").GetType().Assembly;
Type velocityArrowPatch = ANAISAssembly.GetTypes().First(type => type.Name == "VelocityArrowDrawer_OnLocationChange_Patch");
ANAISTraverse = Traverse.Create(velocityArrowPatch);
}
}
catch
{
Debug.Log("Smart SAS: ANAIS is not installed/active.");
Expand Down
6 changes: 3 additions & 3 deletions SmartSASMod/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ float TargetRotationToTorque(float targetAngle)
float mass = __instance.rb2d.mass;
if (mass > 200f)
torque /= Mathf.Pow(mass / 200f, 0.35f);

float maxAcceleration = torque * Mathf.Rad2Deg / mass;
float stoppingTime = Mathf.Abs(angularVelocity / maxAcceleration);
float currentTime = Mathf.Abs(deltaAngle / angularVelocity);

if (stoppingTime > currentTime)
{
return Mathf.Sign(angularVelocity);
Expand Down Expand Up @@ -68,7 +68,7 @@ float TargetRotationToTorque(float targetAngle)
SelectableObject target = __instance == rocket ? Map.navigation.target : sas.Target; // Keeps the last selected target if the sas comp.'s rocket isn't the currently controlled rocket.
if (Main.ANAISTraverse is Traverse traverse && __instance == rocket)
{
if (traverse.Field("_navState").GetValue().ToString() == "ANAIS_TRANSFER_PLANNED")
if (traverse.Field("_navState").GetValue().ToString() != "DEFAULT")
{
Double2 dv = traverse.Field<Double2>("_relativeVelocity").Value;
targetRotation = GUI.NormaliseAngle((float)Math.Atan2(dv.y, dv.x) * Mathf.Rad2Deg);
Expand Down