mirror of
https://github.com/TheJordanDev/PEAK-JordanMod.git
synced 2026-06-06 03:23:29 +02:00
0.1.3 | Added: EasyBackpack
This commit is contained in:
@@ -13,3 +13,8 @@
|
||||
|
||||
- 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.
|
||||
|
||||
# v0.1.3 | Easy Backpack
|
||||
|
||||
- Added EasyBackpackModule and EasyBackpackPatch
|
||||
- EasyBackpackPatch adds a new keybind to open the backpack UI whilst wearing it.
|
||||
@@ -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<KeyCode> 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")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<!-- This is the display name of your mod. Example: BepInEx Template -->
|
||||
<AssemblyTitle>JordanMod</AssemblyTitle>
|
||||
<!-- This is the version number of your mod. -->
|
||||
<Version>0.1.2</Version>
|
||||
<Version>0.1.3</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
61
src/JordanMod/modules/easy_backpack/EasyBackpackModule.cs
Normal file
61
src/JordanMod/modules/easy_backpack/EasyBackpackModule.cs
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
38
src/JordanMod/patches/EasyBackpackPatch.cs
Normal file
38
src/JordanMod/patches/EasyBackpackPatch.cs
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user