diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf44f1..d34e309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,4 +12,9 @@ # v0.1.2 | Bags for Everyone - Added BagsForEveryoneModule and BagsForEveryonePatch -- BagsForEveryonePatch adds a postfix to SingleItemSpawner.TrySpawnItems that checks if the spawner is the first one in the biome, and if so, it spawns extra bags based on the player count. \ No newline at end of file +- BagsForEveryonePatch adds a postfix to SingleItemSpawner.TrySpawnItems that checks if the spawner is the first one in the biome, and if so, it spawns extra bags based on the player count. + +# v0.1.3 | Easy Backpack + +- Added EasyBackpackModule and EasyBackpackPatch +- EasyBackpackPatch adds a new keybind to open the backpack UI whilst wearing it. \ No newline at end of file diff --git a/src/JordanMod/ConfigHandler.cs b/src/JordanMod/ConfigHandler.cs index 79c1b38..e86ca5b 100644 --- a/src/JordanMod/ConfigHandler.cs +++ b/src/JordanMod/ConfigHandler.cs @@ -1,4 +1,5 @@ using BepInEx.Configuration; +using UnityEngine; namespace JordanMod; @@ -6,9 +7,20 @@ public static class ConfigHandler { public static ConfigFile Config { get; private set; } = null!; + // Easy Backpack + public static ConfigEntry OpenBackpack { get; private set; } = null!; + public static void Initialize(ConfigFile configFile) { Config = configFile; + + // Easy Backpack settings + OpenBackpack = Config.Bind( + "Key Bindings", + "OpenBackpack", + KeyCode.B, + new ConfigDescription("Open Easy Backpack UI") + ); } } \ No newline at end of file diff --git a/src/JordanMod/JordanMod.csproj b/src/JordanMod/JordanMod.csproj index 25d3644..a3912fb 100644 --- a/src/JordanMod/JordanMod.csproj +++ b/src/JordanMod/JordanMod.csproj @@ -8,7 +8,7 @@ JordanMod - 0.1.2 + 0.1.3 diff --git a/src/JordanMod/modules/easy_backpack/EasyBackpackModule.cs b/src/JordanMod/modules/easy_backpack/EasyBackpackModule.cs new file mode 100644 index 0000000..8806d62 --- /dev/null +++ b/src/JordanMod/modules/easy_backpack/EasyBackpackModule.cs @@ -0,0 +1,61 @@ +using System; +using UnityEngine; + +namespace JordanMod.Modules.EasyBackpack; + +[Module(Enabled = true)] +class EasyBackpackModule : Module +{ + public static EasyBackpackModule? Instance { get; private set; } + + public override string ModuleName => "Easy Backpack Module"; + + public bool _isBackpackOpen = false; + + public override Type[] GetPatches() + { + return [typeof(EasyBackpackPatch)]; + } + + public override void Initialize() + { + if (Instance != null) return; + Instance = this; + base.Initialize(); + } + + public override void Update() + { + if (!_isBackpackOpen && Input.GetKeyDown(ConfigHandler.OpenBackpack.Value)) OpenBackpack(); + else if (_isBackpackOpen && (Input.GetKeyUp(ConfigHandler.OpenBackpack.Value) || Input.GetKeyDown(KeyCode.Escape))) CloseBackpack(); + } + + private void OpenBackpack() + { + if (!Application.isFocused) return; + if (_isBackpackOpen) return; + + Character localCharacter = Character.localCharacter; + if (localCharacter == null) return; + + bool hasBackpack = localCharacter.player.backpackSlot.hasBackpack; + Character carriedCharacter = localCharacter.data.carriedPlayer; + bool carriedHasBackpack = carriedCharacter != null && carriedCharacter.player.backpackSlot.hasBackpack; + + BackpackReference backpackRefs; + if (hasBackpack) backpackRefs = BackpackReference.GetFromEquippedBackpack(localCharacter); + else if (carriedHasBackpack) backpackRefs = BackpackReference.GetFromEquippedBackpack(carriedCharacter); + else return; + + GUIManager.instance.OpenBackpackWheel(backpackRefs); + _isBackpackOpen = true; + } + + private void CloseBackpack() + { + if (!Application.isFocused) return; + if (!_isBackpackOpen) return; + _isBackpackOpen = false; + } + +} \ No newline at end of file diff --git a/src/JordanMod/patches/EasyBackpackPatch.cs b/src/JordanMod/patches/EasyBackpackPatch.cs new file mode 100644 index 0000000..930b34f --- /dev/null +++ b/src/JordanMod/patches/EasyBackpackPatch.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using UnityEngine; + +namespace JordanMod.Modules.EasyBackpack; + +class EasyBackpackPatch +{ + [HarmonyPatch(typeof(BackpackWheel), "Update")] + [HarmonyPrefix] + static bool BackpackWheelUpdatePrefix(BackpackWheel __instance) + { + bool isBackPackOpen = EasyBackpackModule.Instance?._isBackpackOpen ?? false; + + if (!Character.localCharacter.input.interactIsPressed && !isBackPackOpen) + { + __instance.Choose(); + GUIManager.instance.CloseBackpackWheel(); + return false; + } + + if (__instance.backpack.locationTransform != null && Vector3.Distance(__instance.backpack.locationTransform.position, Character.localCharacter.Center) > 6f) + { + GUIManager.instance.CloseBackpackWheel(); + return false; + } + + if (__instance.chosenSlice.IsSome && !__instance.chosenSlice.Value.isBackpackWear && !__instance.slices[__instance.chosenSlice.Value.slotID + 1].image.enabled) + { + __instance.currentlyHeldItem.transform.position = Vector3.Lerp(__instance.currentlyHeldItem.transform.position, __instance.slices[__instance.chosenSlice.Value.slotID + 1].transform.GetChild(0).GetChild(0).position, Time.deltaTime * 20f); + } + else + { + __instance.currentlyHeldItem.transform.localPosition = Vector3.Lerp(__instance.currentlyHeldItem.transform.localPosition, Vector3.zero, Time.deltaTime * 20f); + } + return false; + } + +} \ No newline at end of file