show GP coins

This commit is contained in:
Tyfon
2024-07-09 22:55:58 -07:00
parent 6f3b66c6e3
commit 85b9a45493
3 changed files with 142 additions and 0 deletions

131
Patches/GPCoinPatches.cs Normal file
View File

@@ -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<Item> 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<Image>();
icon.sprite = EFTHardSettings.Instance.StaticIcons.GetSmallCurrencySign(ECurrencyType.GP);
LayoutElement imageLayout = icon.GetComponent<LayoutElement>();
imageLayout.preferredHeight = -1f;
imageLayout.preferredWidth = -1f;
Settings.ShowGPCurrency.Subscribe(enabled =>
{
if (!enabled && gpCoinsTransform != null)
{
UnityEngine.Object.Destroy(gpCoinsTransform);
}
});
}
TextMeshProUGUI gpCoins = gpCoinsTransform.Find("Label").GetComponent<TextMeshProUGUI>();
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<Item> 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<TextMeshProUGUI>();
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;
}
}
}
}

View File

@@ -60,6 +60,7 @@ namespace UIFixes
AimToggleHoldPatches.Enable();
new ReorderGridsPatch().Enable();
NoRandomGrenadesPatch.Init();
GPCoinPatches.Enable();
}
public static bool InRaid()

View File

@@ -84,6 +84,7 @@ namespace UIFixes
public static ConfigEntry<bool> MergeFIROther { get; set; }
public static ConfigEntry<bool> AutoOpenSortingTable { get; set; }
public static ConfigEntry<bool> ContextMenuOnRight { get; set; }
public static ConfigEntry<bool> ShowGPCurrency { get; set; }
public static ConfigEntry<bool> 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",