Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide delta V UI when the stock delta V app/calculations are disabled. #31

Merged
merged 1 commit into from
Apr 19, 2022
Merged
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
6 changes: 6 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ KSP_COMMUNITY_FIXES
// Fix deployable parts (antennas, solar panels, radiators...) always starting in the extended
// state when the model isn't exported in the retracted state. Affect parts from various mods.
ExtendedDeployableParts = true

// Fix the delta V data (and info panels) on stage UI elements showing
// when the delta V app and delta V calculations are disabled.
// Also hide extended burn time info on the navball in this case, because
// it depends on the stock delta V implementation.
DeltaVHideWhenDisabled = true

// ##########################
// Obsolete bugfixes
Expand Down
113 changes: 113 additions & 0 deletions KSPCommunityFixes/BugFixes/DeltaVHideWhenDisabled.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
using KSP.UI.Screens;
using KSP.UI.Screens.Flight;

namespace KSPCommunityFixes
{
public class DeltaVHideWhenDisabled : BasePatch
{
protected override Version VersionMin => new Version(1, 12, 0);

protected static bool extendedBurntimeCache;

protected override void ApplyPatches(ref List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(StageGroup), "Awake"),
this));

patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(StageManager), "Awake"),
this));

patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(StageGroup), "ToggleInfoPanel", new Type[] { typeof(bool) }),
this));

patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(NavBallBurnVector), "onGameSettingsApplied"),
this));

patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(NavBallBurnVector), "onGameSettingsApplied"),
this));

patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(NavBallBurnVector), "LateUpdate"),
this));

patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(NavBallBurnVector), "LateUpdate"),
this));
}

static void StageGroup_Awake_Postfix(StageGroup __instance)
{
if (GameSettings.DELTAV_APP_ENABLED == false && GameSettings.DELTAV_CALCULATIONS_ENABLED == false)
{
__instance.DisableDeltaVHeading();
}
}

static void StageManager_Awake_Postfix(StageManager __instance)
{
if (GameSettings.DELTAV_APP_ENABLED == false && GameSettings.DELTAV_CALCULATIONS_ENABLED == false)
{
// Note: not using __instance here because the singleton pattern
// destroys the new object in favor of the old, if Instance
// is non-null during Awake.
StageManager.Instance.DisableDeltaVTotal();
StageManager.Instance.deltaVTotalButton.gameObject.SetActive(false);
}
}

static bool StageGroup_ToggleInfoPanel_Prefix(ref bool showPanel, StageGroup __instance)
{
// If we don't have delta V enabled, just short-circuit any attempt to toggle the info panel.
if (showPanel && GameSettings.DELTAV_APP_ENABLED == false && GameSettings.DELTAV_CALCULATIONS_ENABLED == false)
return false;

// but Just In Case let it close.
return true;
}

static bool NavBallBurnVector_onGameSettingsApplied_Prefix(NavBallBurnVector __instance)
{
extendedBurntimeCache = GameSettings.EXTENDED_BURNTIME;

if (GameSettings.DELTAV_APP_ENABLED == false && GameSettings.DELTAV_CALCULATIONS_ENABLED == false)
GameSettings.EXTENDED_BURNTIME = false;

return true;
}

static void NavBallBurnVector_onGameSettingsApplied_Postfix(NavBallBurnVector __instance)
{
GameSettings.EXTENDED_BURNTIME = extendedBurntimeCache;
}

static bool NavBallBurnVector_LateUpdate_Prefix(NavBallBurnVector __instance)
{
extendedBurntimeCache = GameSettings.EXTENDED_BURNTIME;

if (GameSettings.DELTAV_APP_ENABLED == false && GameSettings.DELTAV_CALCULATIONS_ENABLED == false)
GameSettings.EXTENDED_BURNTIME = false;

return true;
}

static void NavBallBurnVector_LateUpdate_Postfix(NavBallBurnVector __instance)
{
GameSettings.EXTENDED_BURNTIME = extendedBurntimeCache;
}
}
}
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="BugFixes\AutoStrutDrift.cs" />
<Compile Include="BugFixes\DockingPortRotationDriftAndFixes.cs" />
<Compile Include="BugFixes\ExtendedDeployableParts.cs" />
<Compile Include="BugFixes\DeltaVHideWhenDisabled.cs" />
<Compile Include="BugFixes\KerbalTooltipMaxSustainedG.cs" />
<Compile Include="BugFixes\PackedPartsRotation.cs" />
<Compile Include="BugFixes\PartStartStability.cs" />
Expand Down