diff --git a/1.5/Assemblies/IAintBuildingThat.dll b/1.5/Assemblies/IAintBuildingThat.dll index 0c0a527..83ec083 100644 Binary files a/1.5/Assemblies/IAintBuildingThat.dll and b/1.5/Assemblies/IAintBuildingThat.dll differ diff --git a/1.5/Source/I_Aint_Building_That/HarmonyPatches/AbilityPatch.cs b/1.5/Source/I_Aint_Building_That/HarmonyPatches/AbilityPatch.cs index f4dfa7e..b1aa71b 100644 --- a/1.5/Source/I_Aint_Building_That/HarmonyPatches/AbilityPatch.cs +++ b/1.5/Source/I_Aint_Building_That/HarmonyPatches/AbilityPatch.cs @@ -27,8 +27,13 @@ class AbilityRightClickPatch() { static void Postfix(Gizmo __instance, ref IEnumerable __result) { - if (__instance is Command_Ability ab) - __result = __result.AddItem(new FloatMenuOption("Taggerung_IAintBuildingThat_HideButtonText".TranslateSimple(), - () => ab.Ability.CompOfType().hidden = true)); + if (__instance is not Command_Ability ab || ab.Ability.CompOfType() 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)); } } diff --git a/1.5/Source/I_Aint_Building_That/HarmonyPatches/PatchBuildables.cs b/1.5/Source/I_Aint_Building_That/HarmonyPatches/PatchBuildables.cs index 3391d6e..4263bc4 100644 --- a/1.5/Source/I_Aint_Building_That/HarmonyPatches/PatchBuildables.cs +++ b/1.5/Source/I_Aint_Building_That/HarmonyPatches/PatchBuildables.cs @@ -35,8 +35,17 @@ static IEnumerable Postfix(IEnumerable __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: { @@ -53,7 +62,13 @@ static IEnumerable Postfix(IEnumerable __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(), @@ -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)); } } @@ -133,9 +157,18 @@ static class PatchInHideMenuOptionToFloatConstructor static bool Prefix(ref List 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)) diff --git a/1.5/Source/I_Aint_Building_That/Settings.cs b/1.5/Source/I_Aint_Building_That/Settings.cs index 1046960..b54ed92 100644 --- a/1.5/Source/I_Aint_Building_That/Settings.cs +++ b/1.5/Source/I_Aint_Building_That/Settings.cs @@ -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 cachedDef); @@ -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) {