From ee1a1c73ac89c4f6bdd0c6594f4132a3efcb7661 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Thu, 13 Jun 2019 19:20:46 -0500 Subject: [PATCH] Enable/Disable button now hidden by default behind settings option --- BSIPA-ModList/DownloadController.cs | 4 +-- BSIPA-ModList/Plugin.cs | 25 ++++++++++++++++++- .../ViewControllers/ModInfoViewController.cs | 14 +++++++++++ .../ViewControllers/SettingsViewController.cs | 23 ++++++++++++----- BSIPA-ModList/manifest.json | 2 +- 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/BSIPA-ModList/DownloadController.cs b/BSIPA-ModList/DownloadController.cs index 437d8f46..cc3cf405 100644 --- a/BSIPA-ModList/DownloadController.cs +++ b/BSIPA-ModList/DownloadController.cs @@ -41,7 +41,7 @@ namespace BSIPA_ModList public static DownloadController Create() { var inst = new GameObject("BSIPA Modlist Download Controller").AddComponent(); - if (SelfConfig.SelfConfigRef.Value.Updates.AutoCheckUpdates) + if (IPA.Config.SelfConfig.SelfConfigRef.Value.Updates.AutoCheckUpdates) inst.StartCoroutine(inst.StartUpdateCheck()); return inst; } @@ -149,7 +149,7 @@ namespace BSIPA_ModList if (downloads.Count == 0) OnAllDownloadsCompleted(false); - else if (SelfConfig.SelfConfigRef.Value.Updates.AutoUpdate) + else if (IPA.Config.SelfConfig.SelfConfigRef.Value.Updates.AutoUpdate) StartDownloads(); } diff --git a/BSIPA-ModList/Plugin.cs b/BSIPA-ModList/Plugin.cs index b0a2c217..ac141662 100644 --- a/BSIPA-ModList/Plugin.cs +++ b/BSIPA-ModList/Plugin.cs @@ -7,6 +7,9 @@ using IPA.Logging; using BSIPA_ModList.UI.ViewControllers; using System.Collections; using IPA.Loader; +using IPA.Config; +using IPA.Utilities; +using System; namespace BSIPA_ModList { @@ -17,20 +20,40 @@ namespace BSIPA_ModList internal static IPALogger md => log.GetChildLogger("MarkDown"); } + internal class SelfConfig + { + public bool Regenerate = true; + public bool ShowEnableDisable = false; + } + /// /// The main plugin type for the in-game mod list mod. /// internal class Plugin : IBeatSaberPlugin { + internal static IConfigProvider provider; + internal static Ref config; + + internal static event Action OnConfigChaned; + /// /// Initializes the plugin with certain parameters. Is only called once. /// /// This is called by the plugin loader in BSIPA, and thus must be . /// /// a logger to initialize the plugin with - public void Init(IPALogger logger) + public void Init(IPALogger logger, IConfigProvider provider) { Logger.log = logger; + Plugin.provider = provider; + + config = provider.MakeLink((p, r) => + { + if (r.Value.Regenerate) + p.Store(r.Value = new SelfConfig { Regenerate = false }); + + OnConfigChaned?.Invoke(r.Value); + }); IPA.Updating.BeatMods.Updater.ModListPresent = true; diff --git a/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs b/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs index 2d396b4b..295d7a91 100644 --- a/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs +++ b/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs @@ -45,6 +45,7 @@ namespace BSIPA_ModList.UI public void Init(Sprite icon, string name, string version, string author, string description, PluginLoader.PluginMetadata updateInfo, PluginManifest.LinksObject links = null, bool showEnDis = false, ModListFlowCoordinator mlfc = null) { showEnableDisable = showEnDis; + Plugin.OnConfigChaned -= OptHideButton; Icon = icon; Name = name; @@ -85,11 +86,24 @@ namespace BSIPA_ModList.UI enableDisableButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(33, 32), new Vector2(25, 10), ToggleEnable); enableDisableButton.GetComponentInChildren().SetMiddleSprite(); UpdateButtonText(); + + Plugin.OnConfigChaned += OptHideButton; + OptHideButton(Plugin.config.Value); } SetupLinks(links); } + ~ModInfoViewController() + { + Plugin.OnConfigChaned -= OptHideButton; + } + + private void OptHideButton(SelfConfig cfg) + { + enableDisableButton?.gameObject.SetActive(cfg.ShowEnableDisable); + } + private Action setAction = () => { }; private void ToggleEnable() { diff --git a/BSIPA-ModList/UI/ViewControllers/SettingsViewController.cs b/BSIPA-ModList/UI/ViewControllers/SettingsViewController.cs index b8ec60f1..89c20d1e 100644 --- a/BSIPA-ModList/UI/ViewControllers/SettingsViewController.cs +++ b/BSIPA-ModList/UI/ViewControllers/SettingsViewController.cs @@ -9,6 +9,7 @@ namespace BSIPA_ModList.UI private static SubMenu menu; private static BoolViewController autoUpdate; private static BoolViewController autoCheck; + private static BoolViewController showEnableDisable; public static VRUIViewController Create() { @@ -16,25 +17,35 @@ namespace BSIPA_ModList.UI autoCheck = menu.AddBool("Auto Update Check", "If enabled, automatically checks for updates on game start."); autoUpdate = menu.AddBool("Auto Update", "If enabled, automatically installs updates after checking for them."); + showEnableDisable = menu.AddBool("Show Enable/Disable Button", "If enabled, BSIPA mods will have a button to enable or disable them."); autoCheck.applyImmediately = true; - autoCheck.GetValue += () => SelfConfig.SelfConfigRef.Value.Updates.AutoCheckUpdates; + autoCheck.GetValue += () => IPA.Config.SelfConfig.SelfConfigRef.Value.Updates.AutoCheckUpdates; autoCheck.SetValue += val => { - SelfConfig.SelfConfigRef.Value.Updates.AutoCheckUpdates = val; - SelfConfig.LoaderConfig.Store(SelfConfig.SelfConfigRef.Value); + IPA.Config.SelfConfig.SelfConfigRef.Value.Updates.AutoCheckUpdates = val; + IPA.Config.SelfConfig.LoaderConfig.Store(IPA.Config.SelfConfig.SelfConfigRef.Value); }; autoUpdate.applyImmediately = true; - autoUpdate.GetValue += () => SelfConfig.SelfConfigRef.Value.Updates.AutoUpdate; + autoUpdate.GetValue += () => IPA.Config.SelfConfig.SelfConfigRef.Value.Updates.AutoUpdate; autoUpdate.SetValue += val => { - SelfConfig.SelfConfigRef.Value.Updates.AutoUpdate = val; - SelfConfig.LoaderConfig.Store(SelfConfig.SelfConfigRef.Value); + IPA.Config.SelfConfig.SelfConfigRef.Value.Updates.AutoUpdate = val; + IPA.Config.SelfConfig.LoaderConfig.Store(IPA.Config.SelfConfig.SelfConfigRef.Value); + }; + + showEnableDisable.applyImmediately = true; + showEnableDisable.GetValue += () => Plugin.config.Value.ShowEnableDisable; + showEnableDisable.SetValue += val => + { + Plugin.config.Value.ShowEnableDisable = val; + Plugin.provider.Store(Plugin.config.Value); }; autoCheck.Init(); autoUpdate.Init(); + showEnableDisable.Init(); return menu.viewController; } diff --git a/BSIPA-ModList/manifest.json b/BSIPA-ModList/manifest.json index 16fba717..72dbdef2 100644 --- a/BSIPA-ModList/manifest.json +++ b/BSIPA-ModList/manifest.json @@ -14,7 +14,7 @@ "version": "1.2.5", "icon": "BSIPA_ModList.Icons.self.png", "dependsOn": { - "BSIPA": "^3.12.19", + "BSIPA": "^3.12.22", "CustomUI": "^1.5.4" }, "features": [],