diff --git a/MultiSelect.cs b/MultiSelect.cs index 5a5e9bf..e33b0ac 100644 --- a/MultiSelect.cs +++ b/MultiSelect.cs @@ -10,8 +10,8 @@ namespace UIFixes { public class MultiSelect { - private static GameObject SelectedMarkTemplate; - private static GameObject SelectedBackgroundTemplate; + private static GameObject SelectedMarkTemplate = null; + private static GameObject SelectedBackgroundTemplate = null; private static readonly Dictionary SelectedItems = []; private static readonly Dictionary SecondaryItems = []; @@ -31,11 +31,18 @@ namespace UIFixes // Grab the selection objects from ragfair as templates RagfairNewOfferItemView ragfairNewOfferItemView = ItemViewFactory.CreateFromPool("ragfair_layout"); - SelectedMarkTemplate = UnityEngine.Object.Instantiate(ragfairNewOfferItemView.R().SelectedMark, null, false); - UnityEngine.Object.DontDestroyOnLoad(SelectedMarkTemplate); - SelectedBackgroundTemplate = UnityEngine.Object.Instantiate(ragfairNewOfferItemView.R().SelectedBackground, null, false); - UnityEngine.Object.DontDestroyOnLoad(SelectedBackgroundTemplate); + if (SelectedMarkTemplate == null) + { + SelectedMarkTemplate = UnityEngine.Object.Instantiate(ragfairNewOfferItemView.R().SelectedMark, null, false); + UnityEngine.Object.DontDestroyOnLoad(SelectedMarkTemplate); + } + + if (SelectedBackgroundTemplate == null) + { + SelectedBackgroundTemplate = UnityEngine.Object.Instantiate(ragfairNewOfferItemView.R().SelectedBackground, null, false); + UnityEngine.Object.DontDestroyOnLoad(SelectedBackgroundTemplate); + } ragfairNewOfferItemView.ReturnToPool(); } diff --git a/Patches/AddOfferRememberAutoselectPatches.cs b/Patches/AddOfferRememberAutoselectPatches.cs index a6b4771..12b7e11 100644 --- a/Patches/AddOfferRememberAutoselectPatches.cs +++ b/Patches/AddOfferRememberAutoselectPatches.cs @@ -16,13 +16,13 @@ namespace UIFixes new RememberAutoselectPatch().Enable(); new RestoreAutoselectPatch().Enable(); - Settings.RememberAutoselectSimilar.SettingChanged += (sender, args) => + Settings.RememberAutoselectSimilar.Subscribe(enabled => { - if (!Settings.RememberAutoselectSimilar.Value) + if (!enabled) { PlayerPrefs.DeleteKey(PlayerPrefKey); } - }; + }); } public class RememberAutoselectPatch : ModulePatch diff --git a/Patches/FleaPrevSearchPatches.cs b/Patches/FleaPrevSearchPatches.cs index 36e53a4..2b0ca8a 100644 --- a/Patches/FleaPrevSearchPatches.cs +++ b/Patches/FleaPrevSearchPatches.cs @@ -33,15 +33,15 @@ namespace UIFixes new OfferViewListDoneLoadingPatch().Enable(); new ChangedViewListTypePatch().Enable(); - Settings.EnableFleaHistory.SettingChanged += (object sender, EventArgs args) => + Settings.EnableFleaHistory.Subscribe(enabled => { - if (!Settings.EnableFleaHistory.Value && PreviousFilterButton.Instance != null) + if (!enabled && PreviousFilterButton.Instance != null) { UnityEngine.Object.Destroy(PreviousFilterButton.Instance.gameObject); PreviousFilterButton.Instance = null; History.Clear(); } - }; + }); } public class PreviousFilterButton : MonoBehaviour diff --git a/Patches/MultiSelectPatches.cs b/Patches/MultiSelectPatches.cs index 54b86ac..4a1ba00 100644 --- a/Patches/MultiSelectPatches.cs +++ b/Patches/MultiSelectPatches.cs @@ -92,21 +92,22 @@ namespace UIFixes [PatchPostfix] public static void Postfix(CommonUI __instance) { - if (!MultiSelect.Enabled) + Settings.EnableMultiSelect.Bind(enabled => { - return; - } + if (enabled) + { + MultiSelect.Initialize(); + } - MultiSelect.Initialize(); + __instance.InventoryScreen.transform.Find("Items Panel").gameObject.GetOrAddComponent().enabled = enabled; + __instance.TransferItemsInRaidScreen.GetOrAddComponent().enabled = enabled; + __instance.TransferItemsScreen.GetOrAddComponent().enabled = enabled; + __instance.ScavengerInventoryScreen.GetOrAddComponent().enabled = enabled; + }); - __instance.InventoryScreen.transform.Find("Items Panel").gameObject.GetOrAddComponent(); - __instance.TransferItemsInRaidScreen.GetOrAddComponent(); - __instance.TransferItemsScreen.GetOrAddComponent(); - __instance.ScavengerInventoryScreen.GetOrAddComponent(); - - static void ToggleDebug() + Settings.ShowMultiSelectDebug.Bind(enabled => { - if (Settings.ShowMultiSelectDebug.Value) + if (enabled) { Singleton.Instance.GetOrAddComponent(); } @@ -115,9 +116,7 @@ namespace UIFixes var debug = Singleton.Instance.GetComponent(); UnityEngine.Object.Destroy(debug); } - }; - ToggleDebug(); - Settings.ShowMultiSelectDebug.SettingChanged += (s, a) => ToggleDebug(); + }); } } @@ -131,12 +130,10 @@ namespace UIFixes [PatchPostfix] public static void Postfix(MenuUI __instance) { - if (!MultiSelect.Enabled) + Settings.EnableMultiSelect.Bind(enabled => { - return; - } - - __instance.TraderScreensGroup.transform.Find("Deal Screen").gameObject.GetOrAddComponent(); + __instance.TraderScreensGroup.transform.Find("Deal Screen").gameObject.GetOrAddComponent().enabled = enabled; + }); } } diff --git a/Settings.cs b/Settings.cs index 5efb857..7a88c12 100644 --- a/Settings.cs +++ b/Settings.cs @@ -1,4 +1,5 @@ using BepInEx.Configuration; +using System; using System.Collections.Generic; using System.ComponentModel; using UnityEngine; @@ -623,10 +624,6 @@ namespace UIFixes if (!primaryConfig.Value) { dependentConfig.Value = false; - if (dependentConfig.Description.Tags[0] is ConfigurationManagerAttributes attributes) - { - attributes.ReadOnly = true; - } } primaryConfig.SettingChanged += (_, _) => @@ -653,4 +650,19 @@ namespace UIFixes }; } } + + public static class SettingExtensions + { + public static void Subscribe(this ConfigEntry configEntry, Action onChange) + { + configEntry.SettingChanged += (_, _) => onChange(configEntry.Value); + } + + + public static void Bind(this ConfigEntry configEntry, Action onChange) + { + configEntry.Subscribe(onChange); + onChange(configEntry.Value); + } + } }