Skip to content

Commit

Permalink
Original state of the darkfog toggle is now restored, the toggle is n…
Browse files Browse the repository at this point in the history
…ow only disabled in release builds and adjusted the wording of the popup a bit
  • Loading branch information
mmjr-x committed Dec 31, 2023
1 parent 91b51fb commit 6641a91
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions NebulaPatcher/Patches/Dynamic/UIGalaxySelect_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ internal class UIGalaxySelect_Patch
{
private static int MainMenuStarID = -1;

private static Toggle? DFToggle;
private static bool? OriginalDFToggleIsOn;
private static bool? OriginalDFToggleInteractable;
private static Color? OriginalDFToggleDisabledColor;
private static Tooltip? DFToggleTooltip;
private static Toggle DFToggle;
private static bool OriginalDFToggleIsOn;
private static bool OriginalDFToggleInteractable;
private static Color OriginalDFToggleDisabledColor;
private static Tooltip DFToggleTooltip;

[HarmonyPostfix]
[HarmonyPatch(nameof(UIGalaxySelect._OnOpen))]
Expand Down Expand Up @@ -80,7 +80,9 @@ public static void _OnOpen_Postfix(UIGalaxySelect __instance)
MainMenuStarID = GameMain.localStar.id;
}

#if !DEBUG
DisableDarkFogToggle();
#endif

var button = GameObject.Find("UI Root/Overlay Canvas/Galaxy Select/start-button").GetComponent<Button>();
button.interactable = true;
Expand Down Expand Up @@ -156,7 +158,7 @@ public static void _OnClose_Prefix(UIGalaxySelect __instance)
childObject.SetActive(true);
}

//RestoreDarkFogToggleState();
RestoreDarkFogToggleState();
}

[HarmonyPrefix]
Expand Down Expand Up @@ -247,31 +249,28 @@ private static void DisableDarkFogToggle()
DFToggle.interactable = false;

// fixes the color scheme so disabled state is acctualy visible
OriginalDFToggleDisabledColor = DFToggle.colors.m_DisabledColor;
OriginalDFToggleDisabledColor = DFToggle.colors.disabledColor;
var colors = DFToggle.colors;
colors.m_DisabledColor = new Color(1, 1, 1, colors.m_DisabledColor.a);
colors.disabledColor = new Color(1, 1, 1, colors.disabledColor.a);
DFToggle.colors = colors;

DFToggleTooltip = DFToggle.gameObject.AddComponent<Tooltip>();
DFToggleTooltip.Title = "Not supported in Multiplayer";
DFToggleTooltip.Text = "Dark Fog is currently not supported in multiplayer.";
DFToggleTooltip.Title = "Not supported in multiplayer";
DFToggleTooltip.Text = "Enabling enemy forces is currently not supported in multiplayer.";
}

private static void RestoreDarkFogToggleState()
{
if (DFToggle is Toggle dFToggle
&& OriginalDFToggleIsOn is bool originalDFToggleIsOn
&& OriginalDFToggleInteractable is bool originalDFToggleInteractable
&& OriginalDFToggleDisabledColor is Color originalDFToggleDisabledColor
//&& DFToggleTooltip is Tooltip tooltip
)

if (DFToggle != null)
{
dFToggle.isOn = originalDFToggleIsOn;
dFToggle.interactable = originalDFToggleInteractable;
// we are setting the (originally) private m_IsOn here since setting the public isOn will fire an event which leads to a NRE
DFToggle.m_IsOn = OriginalDFToggleIsOn;
DFToggle.interactable = OriginalDFToggleInteractable;
var colors = DFToggle.colors;
colors.m_DisabledColor = originalDFToggleDisabledColor;
dFToggle.colors = colors;
//Object.Destroy(tooltip);
colors.disabledColor = OriginalDFToggleDisabledColor;
DFToggle.colors = colors;
Object.Destroy(DFToggleTooltip);
}
}
}

0 comments on commit 6641a91

Please sign in to comment.