From 35f87c9b4c11771254eca7af1bcd4b74b8e25b18 Mon Sep 17 00:00:00 2001 From: Terkoiz Date: Fri, 19 Apr 2024 21:03:12 +0300 Subject: [PATCH] Added feature to quickly show the Skip buttons when holding the hotkey --- .../QuestObjectiveViewPatch.cs | 11 ++-- project/Terkoiz.Skipper/SkipperPlugin.cs | 56 ++++++++++++++++++- .../Terkoiz.Skipper/Terkoiz.Skipper.csproj | 2 +- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/project/Terkoiz.Skipper/QuestObjectiveViewPatch.cs b/project/Terkoiz.Skipper/QuestObjectiveViewPatch.cs index d4a3895..dacfa00 100644 --- a/project/Terkoiz.Skipper/QuestObjectiveViewPatch.cs +++ b/project/Terkoiz.Skipper/QuestObjectiveViewPatch.cs @@ -13,6 +13,7 @@ namespace Terkoiz.Skipper public class QuestObjectiveViewPatch : ModulePatch { private static string UnderlyingQuestControllerClassName; + internal static GameObject LastSeenObjectivesBlock; protected override MethodBase GetTargetMethod() { @@ -20,7 +21,7 @@ namespace Terkoiz.Skipper } [PatchPostfix] - private static void PatchPostfix([CanBeNull]DefaultUIButton ____handoverButton, AbstractQuestControllerClass questController, Condition condition, IConditionCounter quest) + private static void PatchPostfix([CanBeNull]DefaultUIButton ____handoverButton, AbstractQuestControllerClass questController, Condition condition, IConditionCounter quest, QuestObjectiveView __instance) { if (!SkipperPlugin.ModEnabled.Value) { @@ -47,13 +48,15 @@ namespace Terkoiz.Skipper UnderlyingQuestControllerClassName = type.Name.Split('`')[0]; SkipperPlugin.Logger.LogDebug($"Resolved {nameof(UnderlyingQuestControllerClassName)} to be {UnderlyingQuestControllerClassName}"); } - + + LastSeenObjectivesBlock = __instance.transform.parent.gameObject; + var skipButton = Object.Instantiate(____handoverButton, ____handoverButton.transform.parent.transform); skipButton.SetRawText("SKIP", 22); - skipButton.gameObject.name = "SkipButton"; + skipButton.gameObject.name = SkipperPlugin.SkipButtonName; skipButton.gameObject.GetComponent().minWidth = 100f; - skipButton.gameObject.SetActive(!quest.IsConditionDone(condition)); + skipButton.gameObject.SetActive(SkipperPlugin.AlwaysDisplay.Value && !quest.IsConditionDone(condition)); skipButton.OnClick.RemoveAllListeners(); skipButton.OnClick.AddListener(() => ItemUiContext.Instance.ShowMessageWindow( diff --git a/project/Terkoiz.Skipper/SkipperPlugin.cs b/project/Terkoiz.Skipper/SkipperPlugin.cs index ba57b12..2da0ada 100644 --- a/project/Terkoiz.Skipper/SkipperPlugin.cs +++ b/project/Terkoiz.Skipper/SkipperPlugin.cs @@ -1,17 +1,23 @@ using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; +using EFT.UI; using JetBrains.Annotations; +using UnityEngine; namespace Terkoiz.Skipper { - [BepInPlugin("com.terkoiz.skipper", "Terkoiz.Skipper", "1.0.0")] + [BepInPlugin("com.terkoiz.skipper", "Terkoiz.Skipper", "1.1.0")] public class SkipperPlugin : BaseUnityPlugin { + internal const string SkipButtonName = "SkipButton"; + internal new static ManualLogSource Logger { get; private set; } private const string MainSectionName = "Main"; internal static ConfigEntry ModEnabled; + internal static ConfigEntry AlwaysDisplay; + internal static ConfigEntry DisplayHotkey; [UsedImplicitly] internal void Start() @@ -26,9 +32,55 @@ namespace Terkoiz.Skipper { ModEnabled = Config.Bind( MainSectionName, - "Enabled", + "1. Enabled", true, "Global mod toggle. Will need to re-open the quest window for the setting change to take effect."); + + AlwaysDisplay = Config.Bind( + MainSectionName, + "2. Always display Skip button", + false, + "If enabled, the Skip button will always be visible."); + + DisplayHotkey = Config.Bind( + MainSectionName, + "3. Display hotkey", + new KeyboardShortcut(KeyCode.LeftControl), + "Holding down this key will make the Skip buttons appear."); + } + + [UsedImplicitly] + internal void Update() + { + if (!ModEnabled.Value || AlwaysDisplay.Value) + { + return; + } + + if (QuestObjectiveViewPatch.LastSeenObjectivesBlock == null || !QuestObjectiveViewPatch.LastSeenObjectivesBlock.activeSelf) + { + return; + } + + if (DisplayHotkey.Value.IsDown()) + { + ChangeButtonVisibility(true); + } + + if (DisplayHotkey.Value.IsUp()) + { + ChangeButtonVisibility(false); + } + } + + private static void ChangeButtonVisibility(bool setVisibilityTo) + { + foreach (var button in QuestObjectiveViewPatch.LastSeenObjectivesBlock.GetComponentsInChildren(includeInactive: true)) + { + if (button.name != SkipButtonName) continue; + + button.gameObject.SetActive(setVisibilityTo); + } } } } diff --git a/project/Terkoiz.Skipper/Terkoiz.Skipper.csproj b/project/Terkoiz.Skipper/Terkoiz.Skipper.csproj index 07c3c56..cd38329 100644 --- a/project/Terkoiz.Skipper/Terkoiz.Skipper.csproj +++ b/project/Terkoiz.Skipper/Terkoiz.Skipper.csproj @@ -2,7 +2,7 @@ net471 - 1.0.0 + 1.1.0 Terkoiz