Skip to content

Commit

Permalink
Add ability to restore if right clicking a hidden gizmo
Browse files Browse the repository at this point in the history
  • Loading branch information
feldoh committed Sep 16, 2024
1 parent 568a7b3 commit efdc0ab
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
Binary file modified 1.5/Assemblies/IAintBuildingThat.dll
Binary file not shown.
11 changes: 8 additions & 3 deletions 1.5/Source/I_Aint_Building_That/HarmonyPatches/AbilityPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ class AbilityRightClickPatch()
{
static void Postfix(Gizmo __instance, ref IEnumerable<FloatMenuOption> __result)
{
if (__instance is Command_Ability ab)
__result = __result.AddItem(new FloatMenuOption("Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple(),
() => ab.Ability.CompOfType<CompAbilityHide>().hidden = true));
if (__instance is not Command_Ability ab || ab.Ability.CompOfType<CompAbilityHide>() is not {} compAbilityHide) return;

string menuText = compAbilityHide.hidden
? "Taggerung_IAintBuildingThat_RestoreText"
: "Taggerung_IAintBuildingThat_HideButtonText";

__result = __result.AddItem(new FloatMenuOption(menuText.TranslateSimple(),
() => compAbilityHide.hidden = !compAbilityHide.hidden));
}
}
49 changes: 41 additions & 8 deletions 1.5/Source/I_Aint_Building_That/HarmonyPatches/PatchBuildables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ static IEnumerable<FloatMenuOption> Postfix(IEnumerable<FloatMenuOption> __resul
switch (__instance)
{
case Designator_Place { PlacingDef: not null } dp:
yield return new FloatMenuOption("Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple() + ": " + dp.LabelCap,
() => IAintBuildingThat.settings.HideBuildable(dp.PlacingDef));

if (IAintBuildingThat.settings.HiddenBuildables.Contains(dp.PlacingDef.defName))
{
yield return new FloatMenuOption("Taggerung_IAintBuildingThat_RestoreText".TranslateSimple() + ": " + dp.LabelCap,
() => IAintBuildingThat.settings.RestoreBuildable(dp.PlacingDef));
}
else
{
yield return new FloatMenuOption("Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple() + ": " + dp.LabelCap,
() => IAintBuildingThat.settings.HideBuildable(dp.PlacingDef));
}
break;
case Designator_Dropdown dd:
{
Expand All @@ -53,7 +62,13 @@ static IEnumerable<FloatMenuOption> Postfix(IEnumerable<FloatMenuOption> __resul
{
groupDefs.Add(ddBuildable.PlacingDef);
}
if (!alreadyGone.Add(ddBuildable.PlacingDef.defName)) continue;

if (!alreadyGone.Add(ddBuildable.PlacingDef.defName))
{
yield return new FloatMenuOption("Taggerung_IAintBuildingThat_RestoreText".TranslateSimple() + ": " + ddBuildable.LabelCap,
() => IAintBuildingThat.settings.RestoreBuildable(ddBuildable.PlacingDef));
continue;
}
yield return new FloatMenuOption("Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple() + ": " + ddBuildable.LabelCap,
() => IAintBuildingThat.settings.HideBuildable(ddBuildable.PlacingDef));
hideAll ??= new FloatMenuOption("Taggerung_IAintBuildingThat_HideAllButtonText".TranslateSimple(),
Expand Down Expand Up @@ -104,8 +119,17 @@ static void Postfix(Designator __instance, Event ev)
() => IAintBuildingThat.DropdownGroupDefs[dd].Do(IAintBuildingThat.settings.HideBuildable)));
}
}
floatMenuOptions.Add(new FloatMenuOption($"{"Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple()}: {dp.LabelCap}",
() => IAintBuildingThat.settings.HideBuildable(dp.PlacingDef)));

if (IAintBuildingThat.settings.HiddenBuildables.Contains(dp.PlacingDef.defName))
{
floatMenuOptions.Add(new FloatMenuOption("Taggerung_IAintBuildingThat_RestoreText".TranslateSimple() + ": " + dp.LabelCap,
() => IAintBuildingThat.settings.RestoreBuildable(dp.PlacingDef)));
}
else
{
floatMenuOptions.Add(new FloatMenuOption($"{"Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple()}: {dp.LabelCap}",
() => IAintBuildingThat.settings.HideBuildable(dp.PlacingDef)));
}
Find.WindowStack.Add(new FloatMenu(floatMenuOptions));
}
}
Expand Down Expand Up @@ -133,9 +157,18 @@ static class PatchInHideMenuOptionToFloatConstructor
static bool Prefix(ref List<FloatMenuOption> options)
{
if (!PatchInHideMenuOptionToDesignatorProcessInput.IsRightClicking || PatchInHideMenuOptionToBuildDesignatorProcessInput.CurrentPlacingDef is not { } dp) return true;
options.Add(new FloatMenuOption($"{"Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple()}: {dp.LabelCap}",
() => IAintBuildingThat.settings.HideBuildable(dp)));


if (IAintBuildingThat.settings.HiddenBuildables.Contains(dp.defName))
{
options.Add(new FloatMenuOption("Taggerung_IAintBuildingThat_RestoreText".TranslateSimple() + ": " + dp.LabelCap,
() => IAintBuildingThat.settings.RestoreBuildable(dp)));
}
else
{
options.Add(new FloatMenuOption($"{"Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple()}: {dp.LabelCap}",
() => IAintBuildingThat.settings.HideBuildable(dp)));
}

if (dp.designatorDropdown is {} dd)
{
if (!IAintBuildingThat.DropdownGroupDefs.TryGetValue(dd, out var groupDefs))
Expand Down
9 changes: 8 additions & 1 deletion 1.5/Source/I_Aint_Building_That/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public void HideBuildable(BuildableDef buildable)
buildable.designationCategory.DirtyCache();
}

public void RestoreBuildable(BuildableDef buildable)
{
if (buildable == null) return;
HiddenBuildables.Remove(buildable.defName);
buildable.designationCategory.DirtyCache();
}

public BuildableDef LookupDef(string buildable)
{
cachedDefs.TryGetValue(buildable, out Lazy<BuildableDef> cachedDef);
Expand Down Expand Up @@ -68,7 +75,7 @@ public void DoWindowContents(Rect wrect)
{
case Page.Buildings:
{
if (options.ButtonText("Restore All Hidden Defs"))
if (options.ButtonText("Taggerung_IAintBuildingThat_RestoreAllButtonText"))
{
foreach (var hiddenBuildable in cachedDefs)
{
Expand Down

0 comments on commit efdc0ab

Please sign in to comment.