Added feature to quickly show the Skip buttons when holding the hotkey

This commit is contained in:
Terkoiz 2024-04-19 21:03:12 +03:00
parent 9c9403e901
commit 35f87c9b4c
3 changed files with 62 additions and 7 deletions

View File

@ -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)
{
@ -48,12 +49,14 @@ namespace Terkoiz.Skipper
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<UnityEngine.UI.LayoutElement>().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(

View File

@ -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<bool> ModEnabled;
internal static ConfigEntry<bool> AlwaysDisplay;
internal static ConfigEntry<KeyboardShortcut> 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<DefaultUIButton>(includeInactive: true))
{
if (button.name != SkipButtonName) continue;
button.gameObject.SetActive(setVisibilityTo);
}
}
}
}

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<Authors>Terkoiz</Authors>
</PropertyGroup>