diff --git a/Patches/GPCoinPatches.cs b/Patches/GPCoinPatches.cs new file mode 100644 index 0000000..162e818 --- /dev/null +++ b/Patches/GPCoinPatches.cs @@ -0,0 +1,131 @@ +using EFT.InventoryLogic; +using EFT.UI; +using HarmonyLib; +using SPT.Reflection.Patching; +using System.Collections.Generic; +using System.Globalization; +using System.Reflection; +using TMPro; +using UnityEngine; +using UnityEngine.UI; + +namespace UIFixes +{ + public static class GPCoinPatches + { + public static void Enable() + { + new MoneyPanelPatch().Enable(); + new MoneyPanelTMPTextPatch().Enable(); + } + + public class MoneyPanelPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(DisplayMoneyPanel), nameof(DisplayMoneyPanel.Show)); + } + + [PatchPrefix] + public static bool Prefix(DisplayMoneyPanel __instance, IEnumerable inventoryItems, TextMeshProUGUI ____roubles, TextMeshProUGUI ____euros, TextMeshProUGUI ____dollars) + { + if (!Settings.ShowGPCurrency.Value) + { + return true; + } + + __instance.ShowGameObject(); + + Transform gpCoinsTransform = __instance.transform.Find("GPCoins"); + if (gpCoinsTransform == null) + { + Transform dollars = __instance.transform.Find("Dollars"); + gpCoinsTransform = UnityEngine.Object.Instantiate(dollars, __instance.transform, false); + gpCoinsTransform.name = "GPCoins"; + + Image icon = gpCoinsTransform.Find("Image").GetComponent(); + icon.sprite = EFTHardSettings.Instance.StaticIcons.GetSmallCurrencySign(ECurrencyType.GP); + + LayoutElement imageLayout = icon.GetComponent(); + imageLayout.preferredHeight = -1f; + imageLayout.preferredWidth = -1f; + + Settings.ShowGPCurrency.Subscribe(enabled => + { + if (!enabled && gpCoinsTransform != null) + { + UnityEngine.Object.Destroy(gpCoinsTransform); + } + }); + } + + TextMeshProUGUI gpCoins = gpCoinsTransform.Find("Label").GetComponent(); + + var sums = R.Money.GetMoneySums(inventoryItems); + + NumberFormatInfo numberFormatInfo = new NumberFormatInfo + { + NumberGroupSeparator = " " + }; + + ____roubles.text = sums[ECurrencyType.RUB].ToString("N0", numberFormatInfo); + ____euros.text = sums[ECurrencyType.EUR].ToString("N0", numberFormatInfo); + ____dollars.text = sums[ECurrencyType.USD].ToString("N0", numberFormatInfo); + gpCoins.text = sums[ECurrencyType.GP].ToString("N0", numberFormatInfo); + + return false; + } + } + + public class MoneyPanelTMPTextPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(DisplayMoneyPanelTMPText), nameof(DisplayMoneyPanelTMPText.Show)); + } + + [PatchPrefix] + public static bool Prefix(DisplayMoneyPanelTMPText __instance, IEnumerable inventoryItems, TMP_Text ____roubles, TMP_Text ____euros, TMP_Text ____dollars) + { + if (!Settings.ShowGPCurrency.Value) + { + return true; + } + + __instance.ShowGameObject(); + + Transform gpCoinsTransform = __instance.transform.Find("GP"); + if (gpCoinsTransform == null) + { + Transform dollars = __instance.transform.Find("USD"); + gpCoinsTransform = UnityEngine.Object.Instantiate(dollars, __instance.transform, false); + gpCoinsTransform.name = "GP"; + + Settings.ShowGPCurrency.Subscribe(enabled => + { + if (!enabled && gpCoinsTransform != null) + { + UnityEngine.Object.Destroy(gpCoinsTransform); + } + }); + } + + TextMeshProUGUI gpCoins = gpCoinsTransform.GetComponent(); + + var sums = R.Money.GetMoneySums(inventoryItems); + + NumberFormatInfo numberFormatInfo = new NumberFormatInfo + { + NumberGroupSeparator = " " + }; + + ____roubles.text = GClass2531.GetCurrencyChar(ECurrencyType.RUB) + " " + sums[ECurrencyType.RUB].ToString("N0", numberFormatInfo); + ____euros.text = GClass2531.GetCurrencyChar(ECurrencyType.EUR) + " " + sums[ECurrencyType.EUR].ToString("N0", numberFormatInfo); + ____dollars.text = GClass2531.GetCurrencyChar(ECurrencyType.USD) + " " + sums[ECurrencyType.USD].ToString("N0", numberFormatInfo); + gpCoins.text = "GP " + sums[ECurrencyType.GP].ToString("N0", numberFormatInfo); + + return false; + } + } + } +} \ No newline at end of file diff --git a/Plugin.cs b/Plugin.cs index 3e900d7..831b5eb 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -60,6 +60,7 @@ namespace UIFixes AimToggleHoldPatches.Enable(); new ReorderGridsPatch().Enable(); NoRandomGrenadesPatch.Init(); + GPCoinPatches.Enable(); } public static bool InRaid() diff --git a/Settings.cs b/Settings.cs index 113fdd8..657636e 100644 --- a/Settings.cs +++ b/Settings.cs @@ -84,6 +84,7 @@ namespace UIFixes public static ConfigEntry MergeFIROther { get; set; } public static ConfigEntry AutoOpenSortingTable { get; set; } public static ConfigEntry ContextMenuOnRight { get; set; } + public static ConfigEntry ShowGPCurrency { get; set; } public static ConfigEntry LoadMagPresetOnBullets { get; set; } // Advanced // Inspect Panels @@ -468,6 +469,15 @@ namespace UIFixes null, new ConfigurationManagerAttributes { }))); + configEntries.Add(ShowGPCurrency = config.Bind( + InventorySection, + "Show GP Coins in Currency", + true, + new ConfigDescription( + "Show your GP coins wherever your currency is displayed", + null, + new ConfigurationManagerAttributes { }))); + configEntries.Add(LoadMagPresetOnBullets = config.Bind( InventorySection, "Mag Presets Context Menu on Bullets",