diff --git a/LethalProgression/Extensions/ExtensionsMethods.cs b/LethalProgression/Extensions/ExtensionsMethods.cs new file mode 100644 index 0000000..7e8552a --- /dev/null +++ b/LethalProgression/Extensions/ExtensionsMethods.cs @@ -0,0 +1,35 @@ +using UnityEngine; + +namespace LethalProgression.Extensions +{ + internal static class ExtensionsMethods + { + public static T GetOrAddComponent(this GameObject go) where T : Component + { + T component = go.GetComponent(); + if (component == null) + { + component = go.AddComponent(); + } + return component; + } + public static T GetOrAddComponentInChildren(this GameObject go) where T : Component + { + T component = go.GetComponentInChildren(); + if (component == null) + { + component = go.AddComponent(); + } + return component; + } + public static T GetOrAddComponentInParent(this GameObject go) where T : Component + { + T component = go.GetComponentInParent(); + if (component == null) + { + component = go.AddComponent(); + } + return component; + } + } +} diff --git a/LethalProgression/GUIUpdate.cs b/LethalProgression/GUIUpdate.cs new file mode 100644 index 0000000..d014305 --- /dev/null +++ b/LethalProgression/GUIUpdate.cs @@ -0,0 +1,90 @@ +using HarmonyLib; +using LethalProgression.Config; +using TMPro; +using UnityEngine; +using UnityEngine.InputSystem; + +namespace LethalProgression.GUI +{ + [HarmonyPatch] + internal class GUIUpdate + { + public static bool isMenuOpen = false; + public static SkillsGUI guiInstance; + + [HarmonyPostfix] + [HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Update))] + private static void SkillMenuUpdate(QuickMenuManager __instance) + { + if (guiInstance == null || !guiInstance.mainPanel) + { + return; + } + + // If the menu is open, activate mainPanel. + if (!isMenuOpen) + { + guiInstance.mainPanel.SetActive(false); + return; + } + + if (bool.Parse(SkillConfig.hostConfig["Unspec in Ship Only"]) && !bool.Parse(SkillConfig.hostConfig["Disable Unspec"])) + { + // Check if you are in the ship right now + guiInstance.SetUnspec(GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom); + } + + if (bool.Parse(SkillConfig.hostConfig["Unspec in Orbit Only"])) + { + // Check if you are in orbit right now + + guiInstance.SetUnspec(StartOfRound.Instance.inShipPhase); + } + + if (bool.Parse(SkillConfig.hostConfig["Disable Unspec"])) + { + guiInstance.SetUnspec(false); + } + GameObject pointsPanel = guiInstance.mainPanel.transform.GetChild(2).gameObject; + GameObject toolTip = pointsPanel.transform.GetChild(2).gameObject; + // If the mouse is on the points panel, show the tooltip. + toolTip.SetActive(IsHovering()); + + guiInstance.mainPanel.SetActive(true); + GameObject mainButtons = GameObject.Find("Systems/UI/Canvas/QuickMenu/MainButtons"); + mainButtons.SetActive(false); + + GameObject playerList = GameObject.Find("Systems/UI/Canvas/QuickMenu/PlayerList"); + playerList.SetActive(false); + + RealTimeUpdateInfo(); + } + public static bool IsHovering() + { + Vector2 mousePos = Mouse.current.position.ReadValue(); + // If the mouse is currently on the PointsPanel + GameObject pointsPanel = guiInstance.mainPanel.transform.GetChild(2).gameObject; + float xLeast = pointsPanel.transform.position.x - pointsPanel.GetComponent().rect.width; + float xMost = pointsPanel.transform.position.x + pointsPanel.GetComponent().rect.width; + float yLeast = pointsPanel.transform.position.y - pointsPanel.GetComponent().rect.height; + float yMost = pointsPanel.transform.position.y + pointsPanel.GetComponent().rect.height; + + return mousePos.x >= xLeast && mousePos.x <= xMost && mousePos.y >= yLeast && mousePos.y <= yMost; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.CloseQuickMenu))] + private static void SkillMenuClose(QuickMenuManager __instance) + { + isMenuOpen = false; + } + private static void RealTimeUpdateInfo() + { + GameObject tempObj = guiInstance.mainPanel.transform.GetChild(2).gameObject; + tempObj = tempObj.transform.GetChild(1).gameObject; + + TextMeshProUGUI points = tempObj.GetComponent(); + points.text = LP_NetworkManager.xpInstance.GetSkillPoints().ToString(); + } + } +} \ No newline at end of file diff --git a/LethalProgression/XP.cs b/LethalProgression/LC_XP.cs similarity index 90% rename from LethalProgression/XP.cs rename to LethalProgression/LC_XP.cs index 14b9fa2..02896fa 100644 --- a/LethalProgression/XP.cs +++ b/LethalProgression/LC_XP.cs @@ -1,23 +1,15 @@ -using HarmonyLib; -using System; +using System.Collections; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Text; -using Unity.Netcode; -using Unity.Networking; -using UnityEngine; -using System.IO; -using UnityEngine.SceneManagement; -using System.Collections; +using System.Linq; using GameNetcodeStuff; using LethalProgression.Config; -using LethalProgression.Skills; using LethalProgression.GUI; using LethalProgression.Patches; using LethalProgression.Saving; +using LethalProgression.Skills; using Newtonsoft.Json; -using Steamworks; -using System.Linq; +using Unity.Netcode; +using UnityEngine; namespace LethalProgression { @@ -41,7 +33,7 @@ public void Start() LethalPlugin.Log.LogInfo("XP Network Behavior Made!"); PlayerConnect_ServerRpc(); } - public void LoadSharedData() + public void LoadSharedSaveData() { SaveSharedData sharedData = SaveManager.LoadShared(); @@ -77,18 +69,6 @@ public void LoadLocalData(string data) skillCheck += skill.Value; } LethalPlugin.Log.LogInfo(GetXPRequirement().ToString()); - - // Sanity check: If skillCheck goes over amount of skill points, reset all skills. - //if (skillCheck > skillPoints) - //{ - // LethalPlugin.Log.LogInfo("Skill check is greater than skill points, resetting skills."); - // foreach (KeyValuePair skill in skillList.skills) - // { - // skill.Value.Reset(); - // } - //} - - // if the skill check is less than the current level plus five, add the difference if ((skillCheck + skillPoints) < xpLevel.Value + 5) { LethalPlugin.Log.LogInfo($"Skill check is less than current level, adding {((xpLevel.Value + 5) - (skillCheck + skillPoints))} skill points."); @@ -220,7 +200,7 @@ public void Givepoint_ClientRPC() ///////////////////////////////////////////////// /// Team Loot Upgrade Sync ///////////////////////////////////////////////// - public void TeamLootValueUpdate(float update, int newValue) + public void TeamLootValueUpdate(float update) { TeamLootValueUpdate_ServerRpc(update); } @@ -229,8 +209,13 @@ public void TeamLootValueUpdate(float update, int newValue) public void TeamLootValueUpdate_ServerRpc(float updatedValue) { float mult = LP_NetworkManager.xpInstance.skillList.skills[UpgradeType.Value].GetMultiplier(); - float newvalue = updatedValue * mult; - teamLootValue.Value += newvalue; + float value = updatedValue * mult; + + teamLootValue.Value += value; + if (value == 0) + { + teamLootValue.Value = value; + } LethalPlugin.Log.LogInfo($"Changed team loot value by {updatedValue * mult} turning into {teamLootValue.Value}."); } @@ -307,10 +292,7 @@ public void SetHandSlot(ulong playerID, int newSlots) [ServerRpc(RequireOwnership = false)] public void GetEveryoneHandSlots_ServerRpc() { - if (LethalPlugin.ReservedSlots) - return; - - if (!LP_NetworkManager.xpInstance.skillList.IsSkillValid(UpgradeType.HandSlot)) + if (LethalPlugin.ReservedSlots || !LP_NetworkManager.xpInstance.skillList.IsSkillValid(UpgradeType.HandSlot)) { return; } @@ -361,7 +343,7 @@ public void SendEveryoneConfigs_ClientRpc(string serializedConfig) if (GameNetworkManager.Instance.isHostingGame) { - LoadSharedData(); + LoadSharedSaveData(); } guiObj = new SkillsGUI(); @@ -376,16 +358,21 @@ public void SendEveryoneConfigs_ClientRpc(string serializedConfig) } // Saving - [ServerRpc (RequireOwnership = false)] - public void SaveData_ServerRpc(ulong steamID, string saveData) + [ServerRpc(RequireOwnership = false)] + public void SaveData_ServerRpc(ulong steamID, string saveData, SaveType type = SaveType.PlayerPrefs) { + if (type == SaveType.Json) + { + SaveMigrator.MigrateSaves(); + return; + } SaveManager.Save(steamID, saveData); SaveManager.SaveShared(xpPoints.Value, xpLevel.Value, profit.Value); } // Loading [ServerRpc(RequireOwnership = false)] - public void RequestSavedData_ServerRpc(ulong steamID) + public void RequestSavedData_ServerRpc(ulong? steamID) { string saveData = SaveManager.Load(steamID); SendSavedData_ClientRpc(saveData); diff --git a/LethalProgression/LP_NetworkManager.cs b/LethalProgression/LP_NetworkManager.cs index 04e92bb..7901c36 100644 --- a/LethalProgression/LP_NetworkManager.cs +++ b/LethalProgression/LP_NetworkManager.cs @@ -1,7 +1,4 @@ using HarmonyLib; -using System; -using System.Collections.Generic; -using System.Text; using Unity.Netcode; using UnityEngine; using Object = UnityEngine.Object; @@ -11,12 +8,16 @@ namespace LethalProgression [HarmonyPatch] internal class LP_NetworkManager { + public static LC_XP xpInstance; + [HarmonyPostfix] - [HarmonyPatch(typeof(GameNetworkManager), "Start")] + [HarmonyPatch(typeof(GameNetworkManager), nameof(GameNetworkManager.Start))] public static void Init() { if (xpNetworkObject != null) + { return; + } xpNetworkObject = (GameObject)LethalPlugin.skillBundle.LoadAsset("LP_XPHandler"); xpNetworkObject.AddComponent(); @@ -26,18 +27,17 @@ public static void Init() public static GameObject xpNetworkObject; [HarmonyPostfix] - [HarmonyPatch(typeof(StartOfRound), "Awake")] + [HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.Awake))] static void SpawnNetworkHandler() { - if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer) + if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer) { - var networkHandlerHost = Object.Instantiate(xpNetworkObject, Vector3.zero, Quaternion.identity); - networkHandlerHost.GetComponent().Spawn(); - xpInstance = networkHandlerHost.GetComponent(); - LethalPlugin.Log.LogInfo("XPHandler Initialized."); + return; } + var networkHandlerHost = Object.Instantiate(xpNetworkObject, Vector3.zero, Quaternion.identity); + networkHandlerHost.GetComponent().Spawn(); + xpInstance = networkHandlerHost.GetComponent(); + LethalPlugin.Log.LogInfo("XPHandler Initialized."); } - - public static LC_XP xpInstance; } } diff --git a/LethalProgression/LethalProgression.csproj b/LethalProgression/LethalProgression.csproj index 2266b7b..0379457 100644 --- a/LethalProgression/LethalProgression.csproj +++ b/LethalProgression/LethalProgression.csproj @@ -14,6 +14,7 @@ + @@ -23,80 +24,85 @@ - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\0Harmony.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\0Harmony.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Assembly-CSharp.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Assembly-CSharp.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\BepInEx.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\BepInEx.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\ClientNetworkTransform.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\ClientNetworkTransform.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Facepunch.Steamworks.Win64.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Facepunch.Steamworks.Win64.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\HarmonyXInterop.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\HarmonyXInterop.dll + + + C:\Users\bergm_69gfgdx\AppData\Roaming\r2modmanPlus-local\LethalCompany\profiles\Default\BepInEx\plugins\AinaVT-LethalConfig\LethalConfig\LethalConfig.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\Mono.Cecil.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\Mono.Cecil.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\Mono.Cecil.Mdb.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\Mono.Cecil.Mdb.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\Mono.Cecil.Pdb.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\Mono.Cecil.Pdb.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\Mono.Cecil.Rocks.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\Mono.Cecil.Rocks.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\MonoMod.RuntimeDetour.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\MonoMod.RuntimeDetour.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\BepInEx\core\MonoMod.Utils.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\MonoMod.Utils.dll - ..\..\..\Libraries\Newtonsoft.Json.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Newtonsoft.Json.dll + + + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.TextMeshPro.dll + + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.UI.dll + + - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.InputSystem.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.InputSystem.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.InputSystem.ForUI.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.InputSystem.ForUI.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Netcode.Components.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Netcode.Components.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Netcode.Runtime.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Netcode.Runtime.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Networking.Transport.dll - - - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.TextMeshPro.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Networking.Transport.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.AnimationModule.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.AnimationModule.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.AssetBundleModule.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.AssetBundleModule.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.AudioModule.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.AudioModule.dll - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.CoreModule.dll - - - ..\..\..\..\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.UI.dll + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.CoreModule.dll + @@ -113,12 +119,4 @@ Resources.Designer.cs - - - - - - - - diff --git a/LethalProgression/Patches/Config.cs b/LethalProgression/Patches/Config.cs index 3b771e5..469a71f 100644 --- a/LethalProgression/Patches/Config.cs +++ b/LethalProgression/Patches/Config.cs @@ -1,16 +1,37 @@ -using System; -using System.Collections.Generic; -using System.Text; -using HarmonyLib; -using BepInEx.Configuration; +using System.Collections.Generic; +using LethalConfig; +using LethalConfig.ConfigItems; +using Steamworks; namespace LethalProgression.Config { internal class SkillConfig { public static IDictionary hostConfig = new Dictionary(); + public static bool DeleteJsonSaves; + public static void LethalConfigButtons() + { + if (!LethalPlugin.LethalConfig) + { + return; + } + string IDesc = "Caution this may override your current save files use carfuly"; + string ItemName = "Import Saves"; + var ImportSaves = new GenericButtonConfigItem("Saving", ItemName, IDesc, ItemName, () => + LP_NetworkManager.xpInstance.SaveData_ServerRpc(SteamClient.SteamId, string.Empty, SaveType.Json)); + + LethalConfigManager.AddConfigItem(ImportSaves); + } + private const string Caution = $"\n{nameof(Caution)},This may require a restart to apply"; public static void InitConfig() { + LethalConfigButtons(); + DeleteJsonSaves = LethalPlugin.Instance.BindConfig( + "Saving", + "DeleteJsonSavesOnLoad", + false, + $"Deletes all the old json files and replaces them with the newer saving system{Caution}" + ).Value; LethalPlugin.Instance.BindConfig( "General", "Person Multiplier", diff --git a/LethalProgression/Patches/HudManagerPatch.cs b/LethalProgression/Patches/HudManagerPatch.cs index 7538410..e70241e 100644 --- a/LethalProgression/Patches/HudManagerPatch.cs +++ b/LethalProgression/Patches/HudManagerPatch.cs @@ -1,14 +1,11 @@ -using HarmonyLib; -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.UI; + namespace LethalProgression.Patches { [HarmonyPatch] @@ -33,19 +30,14 @@ internal class HUDManagerPatch { "Puffer (EnemyType)", 15 }, }; - //[HarmonyPostfix] - //[HarmonyPatch(typeof(HUDManager), "PingScan_performed")] - //private static void DebugScan() - //{ - // LethalProgression.XPHandler.xpInstance.AddXPServerRPC(10); - //} - [HarmonyPrefix] - [HarmonyPatch(typeof(HUDManager), "AddNewScrapFoundToDisplay")] + [HarmonyPatch(typeof(HUDManager), nameof(HUDManager.AddNewScrapFoundToDisplay))] private static void GiveXPForScrap(GrabbableObject GObject) { if (!GameNetworkManager.Instance.isHostingGame) + { return; + } // Now we got the loot list that's about to be displayed, we add XP for each one that gets shown. int scrapCost = GObject.scrapValue; @@ -54,11 +46,11 @@ private static void GiveXPForScrap(GrabbableObject GObject) LP_NetworkManager.xpInstance.AddXPServerRPC(scrapCost); } [HarmonyPostfix] - [HarmonyPatch(typeof(EnemyAI), "KillEnemy")] + [HarmonyPatch(typeof(EnemyAI), nameof(EnemyAI.KillEnemy))] private static void GiveXPForKill(EnemyAI __instance) { string enemyType = __instance.enemyType.ToString(); - LethalPlugin.Log.LogInfo("Enemy type: " + enemyType); + LethalPlugin.Log.LogInfo($"Enemy type: {enemyType}"); // Give XP for the amount of money this scrap costs. int enemyReward = 30; if (_enemyReward.ContainsKey(enemyType)) @@ -71,12 +63,14 @@ public static void ShowXPUpdate(int oldXP, int newXP, int xp) { // Makes one if it doesn't exist on screen yet. if (!_tempBar) + { MakeBar(); + } GameObject _tempprogress = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/XPUpdate/XPBarProgress"); _tempprogress.GetComponent().fillAmount = newXP / (float)LP_NetworkManager.xpInstance.GetXPRequirement(); - _tempText.text = newXP + " / " + (float)LP_NetworkManager.xpInstance.GetXPRequirement(); + _tempText.text = $"{newXP} / {(float)LP_NetworkManager.xpInstance.GetXPRequirement()}"; _tempBarTime = 2f; @@ -101,12 +95,17 @@ private static IEnumerator XPBarCoroutine() public static void ShowLevelUp() { if (!levelText) + { MakeLevelUp(); + } levelTextTime = 5f; - if (!levelText.gameObject.activeSelf) - GameNetworkManager.Instance.StartCoroutine(LevelUpCoroutine()); + if (levelText.gameObject.activeSelf) + { + return; + } + GameNetworkManager.Instance.StartCoroutine(LevelUpCoroutine()); } public static void MakeLevelUp() @@ -133,9 +132,8 @@ private static IEnumerator LevelUpCoroutine() private static void MakeBar() { - GameObject _xpBar = GameObject.Find("/Systems/UI/Canvas/QuickMenu/XPBar"); QuickMenuManagerPatch.MakeNewXPBar(); - _xpBar = GameObject.Find("/Systems/UI/Canvas/QuickMenu/XPBar"); + GameObject _xpBar = GameObject.Find("/Systems/UI/Canvas/QuickMenu/XPBar"); _tempBar = GameObject.Instantiate(_xpBar); _tempBar.name = "XPUpdate"; diff --git a/LethalProgression/Patches/QuickMenuManagerPatch.cs b/LethalProgression/Patches/QuickMenuManagerPatch.cs index cc836ac..c1e561a 100644 --- a/LethalProgression/Patches/QuickMenuManagerPatch.cs +++ b/LethalProgression/Patches/QuickMenuManagerPatch.cs @@ -1,68 +1,61 @@ using HarmonyLib; -using BepInEx.Configuration; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO; -using System.Xml.Linq; +using LethalProgression.Extensions; using TMPro; using UnityEngine; using UnityEngine.UI; -using Object = UnityEngine.Object; namespace LethalProgression.Patches { [HarmonyPatch] internal class QuickMenuManagerPatch { + private static GameObject skillTreeButton; private static GameObject _xpBar; + private static GameObject _xpInfoContainer; private static GameObject _xpBarProgress; private static TextMeshProUGUI _xpText; private static TextMeshProUGUI _xpLevel; private static TextMeshProUGUI _profit; [HarmonyPostfix] - [HarmonyPatch(typeof(QuickMenuManager), "OpenQuickMenu")] + [HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.OpenQuickMenu))] private static void QuickMenuXPBar(QuickMenuManager __instance) { // Check if menucontainer is active if (!__instance.isMenuOpen) + { return; + } if (!_xpBar || !_xpBarProgress) + { MakeNewXPBar(); + } _xpBar.SetActive(true); _xpBarProgress.SetActive(true); } [HarmonyPostfix] - [HarmonyPatch(typeof(QuickMenuManager), "Update")] + [HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Update))] private static void XPMenuUpdate(QuickMenuManager __instance) { - if (!_xpBar || !_xpBarProgress) + if (!_xpInfoContainer || !_xpBar || !_xpBarProgress) + { return; + } // If the settings menu or exit game menu is open, we don't want to show the XP bar. - if (__instance.mainButtonsPanel.activeSelf) - { - _xpBar.SetActive(true); - _xpBarProgress.SetActive(true); - } - else - { - _xpBar.SetActive(false); - _xpBarProgress.SetActive(false); - } + bool activeState = __instance.mainButtonsPanel.activeSelf; + _xpInfoContainer.SetActive(activeState); + // Set actual XP: // XP Text. Values of how much XP you need to level up. // XP Level, which is just the level you're on. // Profit, which is how much money you've made. - _xpText.text = LP_NetworkManager.xpInstance.GetXP().ToString() + " / " + LP_NetworkManager.xpInstance.xpReq.Value.ToString(); - _xpLevel.text = "Level: " + LP_NetworkManager.xpInstance.GetLevel().ToString(); - _profit.text = "You've made.. " + LP_NetworkManager.xpInstance.GetProfit().ToString() + "$"; + _xpText.text = $"{LP_NetworkManager.xpInstance.GetXP()} / {LP_NetworkManager.xpInstance.xpReq.Value}"; + _xpLevel.text = $"Level: {LP_NetworkManager.xpInstance.GetLevel()}"; + _profit.text = $"You've made.. {LP_NetworkManager.xpInstance.GetProfit().ToString()}$"; // Set the bar fill _xpBarProgress.GetComponent().fillAmount = LP_NetworkManager.xpInstance.GetXP() / (float)LP_NetworkManager.xpInstance.xpReq.Value; } @@ -70,76 +63,85 @@ private static void XPMenuUpdate(QuickMenuManager __instance) public static void MakeNewXPBar() { GameObject _pauseMenu = GameObject.Find("/Systems/UI/Canvas/QuickMenu"); + GameObject _gameXPText = GameObject.Find("/Systems/UI/Canvas/EndgameStats/LevelUp/Total"); + //Container => [XpBar => BarProgression], [Profit,Level] + if (!_xpInfoContainer) + { + _xpInfoContainer = new GameObject("XpInfoContainer"); + //setlocal pos to be the same as old one + _xpInfoContainer.transform.SetParent(_pauseMenu.transform, false); + _xpInfoContainer.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f); + _xpInfoContainer.transform.Translate(-1.7f, 0.9f, 0f); + } if (!_xpBar) { ////// XP Bar ////// GameObject _gameXPBar = GameObject.Find("/Systems/UI/Canvas/EndgameStats/LevelUp/LevelUpBox"); _xpBar = GameObject.Instantiate(_gameXPBar); + _xpBar.transform.SetParent(_xpInfoContainer.transform, false); _xpBar.name = "XPBar"; - _xpBar.transform.SetParent(_pauseMenu.transform, false); - - _xpBar.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f); - _xpBar.transform.Translate(-2f, 1f, 0f); - } - - if (!_xpBarProgress) - { - ////// XP Progress ////// - GameObject _gameXPBarProgress = GameObject.Find("/Systems/UI/Canvas/EndgameStats/LevelUp/LevelUpMeter"); - _xpBarProgress = GameObject.Instantiate(_gameXPBarProgress); - _xpBarProgress.name = "XPBarProgress"; - - _xpBarProgress.transform.SetParent(_xpBar.transform, false); - _xpBarProgress.GetComponent().fillAmount = 0f; - _xpBarProgress.transform.localScale = new Vector3(0.597f, 5.21f, 1f); - _xpBarProgress.transform.Translate(-0.8f, 0.2f, 0f); - Vector3 pos = _xpBarProgress.transform.localPosition; - - _xpBarProgress.transform.localPosition = new Vector3(pos.x + 7, pos.y - 3.5f, 0f); ////// XP Text ////// - GameObject _gameXPText = GameObject.Find("/Systems/UI/Canvas/EndgameStats/LevelUp/Total"); _xpText = GameObject.Instantiate(_gameXPText).GetComponent(); + _xpText.transform.SetParent(_xpBar.transform, false); + _xpText.transform.Translate(-0.75f, 0.21f, 0f); _xpText.name = "XPText"; _xpText.alignment = TextAlignmentOptions.Center; _xpText.SetText("0/1000"); - _xpText.transform.SetParent(_xpBar.transform, false); _xpText.color = new Color(1f, 0.6f, 0f, 1f); - _xpText.transform.Translate(-0.75f, 0.21f, 0f); - ////// Level Text ///// _xpLevel = GameObject.Instantiate(_gameXPText).GetComponent(); + _xpLevel.transform.SetParent(_xpInfoContainer.transform, false); + _xpLevel.transform.position = new Vector3(_xpBar.transform.position.x, + _xpBar.transform.position.y, _xpBar.transform.position.z); + _xpLevel.transform.Translate(-0.3f, 0.2f, 0f);//x +.7, y -.2 _xpLevel.name = "XPLevel"; _xpLevel.alignment = TextAlignmentOptions.Center; _xpLevel.SetText("Level: 0"); - _xpLevel.transform.SetParent(_xpBar.transform, false); _xpLevel.color = new Color(1f, 0.6f, 0f, 1f); - - _xpLevel.transform.Translate(-1f, 0.4f, 0f); - + //Level x.7 y.2 + //Profit x.7 -y.2 ///// PROFIT! ///// _profit = GameObject.Instantiate(_gameXPText).GetComponent(); + _profit.transform.SetParent(_xpInfoContainer.transform, false); + _profit.transform.position = new Vector3(_xpBar.transform.position.x, + _xpBar.transform.position.y, _xpBar.transform.position.z); + _profit.transform.Translate(-0.10f, -0.2f, 0f);//x +.7, y -.2 _profit.name = "XPProfit"; _profit.alignment = TextAlignmentOptions.Center; _profit.SetText("You've made.. 0$."); - _profit.transform.SetParent(_xpBar.transform, false); _profit.color = new Color(1f, 0.6f, 0f, 1f); + } - _profit.transform.Translate(-0.8f, 0f, 0f); + if (!_xpBarProgress) + { + ////// XP Progress ////// + GameObject _gameXPBarProgress = GameObject.Find("/Systems/UI/Canvas/EndgameStats/LevelUp/LevelUpMeter"); + _xpBarProgress = GameObject.Instantiate(_gameXPBarProgress); + _xpBarProgress.transform.SetParent(_xpBar.transform, false); + _xpBarProgress.transform.localScale = new Vector3(0.597f, 5.21f, 1f); + _xpBarProgress.transform.Translate(-0.8f, 0.2f, 0f); + Vector3 pos = _xpBarProgress.transform.localPosition; + _xpBarProgress.transform.localPosition = new Vector3(pos.x + 7f, pos.y - 3.5f, 0f); + _xpBarProgress.name = "XPBarProgress"; + _xpBarProgress.GetComponent().fillAmount = 0f; } } - private static GameObject skillTreeButton; [HarmonyPostfix] - [HarmonyPatch(typeof(QuickMenuManager), "OpenQuickMenu")] + [HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.OpenQuickMenu))] private static void SkillTreeAwake(QuickMenuManager __instance) { // Check if menucontainer is active if (!__instance.isMenuOpen) + { return; + } if (!skillTreeButton) + { MakeSkillTreeButton(); + } } private static void MakeSkillTreeButton() @@ -149,15 +151,24 @@ private static void MakeSkillTreeButton() GameObject MainButtons = GameObject.Find("Systems/UI/Canvas/QuickMenu/MainButtons"); skillTreeButton.transform.SetParent(MainButtons.transform, false); - + Vector3 position = _xpBar.transform.position; + skillTreeButton.transform.position = new Vector3(0.55f + position.x, 1.09f + position.y, position.z); skillTreeButton.name = "Skills"; skillTreeButton.GetComponentInChildren().text = "> Skills"; + position = _xpBar.transform.position; + skillTreeButton.transform.localPosition = new Vector3(position.x, position.y, position.z); + // Change the onClick event to our own. + skillTreeButton.transform.position += new Vector3(-0.15f, 1.056f); + Button.ButtonClickedEvent OnClickEvent = new Button.ButtonClickedEvent(); + OnClickEvent.AddListener(OpenSkillTree); + skillTreeButton.GetComponent