89 lines
3.0 KiB
C#
89 lines
3.0 KiB
C#
using Aki.Reflection.Patching;
|
|
using EFT.UI.Ragfair;
|
|
using HarmonyLib;
|
|
using JetBrains.Annotations;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UIFixes
|
|
{
|
|
public static class AddOfferClickablePricesPatches
|
|
{
|
|
public static void Enable()
|
|
{
|
|
new AddButtonPatch().Enable();
|
|
}
|
|
|
|
public class AddButtonPatch : ModulePatch
|
|
{
|
|
protected override MethodBase GetTargetMethod()
|
|
{
|
|
return AccessTools.Method(typeof(AddOfferWindow), nameof(AddOfferWindow.Show));
|
|
}
|
|
|
|
[PatchPostfix]
|
|
public static void Postfix(ItemMarketPricesPanel ____pricesPanel, RequirementView[] ____requirementViews)
|
|
{
|
|
var panel = ____pricesPanel.R();
|
|
|
|
var rublesRequirement = ____requirementViews.First(rv => rv.name == "Requirement (RUB)");
|
|
|
|
Button lowestButton = panel.LowestLabel.GetOrAddComponent<HighlightButton>();
|
|
lowestButton.onClick.AddListener(() => rublesRequirement.method_0(____pricesPanel.Minimum.ToString("F0")));
|
|
____pricesPanel.AddDisposable(lowestButton.onClick.RemoveAllListeners);
|
|
|
|
Button averageButton = panel.AverageLabel.GetOrAddComponent<HighlightButton>();
|
|
averageButton.onClick.AddListener(() => rublesRequirement.method_0(____pricesPanel.Average.ToString("F0")));
|
|
____pricesPanel.AddDisposable(averageButton.onClick.RemoveAllListeners);
|
|
|
|
Button maximumButton = panel.MaximumLabel.GetOrAddComponent<HighlightButton>();
|
|
maximumButton.onClick.AddListener(() => rublesRequirement.method_0(____pricesPanel.Maximum.ToString("F0")));
|
|
____pricesPanel.AddDisposable(maximumButton.onClick.RemoveAllListeners);
|
|
}
|
|
}
|
|
|
|
public class HighlightButton : Button
|
|
{
|
|
private Color originalColor;
|
|
bool originalOverrideColorTags;
|
|
|
|
private TextMeshProUGUI _text;
|
|
private TextMeshProUGUI Text
|
|
{
|
|
get
|
|
{
|
|
if (_text == null)
|
|
{
|
|
_text = GetComponent<TextMeshProUGUI>();
|
|
}
|
|
|
|
return _text;
|
|
}
|
|
}
|
|
|
|
public override void OnPointerEnter([NotNull] PointerEventData eventData)
|
|
{
|
|
base.OnPointerEnter(eventData);
|
|
|
|
originalColor = Text.color;
|
|
originalOverrideColorTags = Text.overrideColorTags;
|
|
|
|
Text.overrideColorTags = true;
|
|
Text.color = Color.white;
|
|
}
|
|
|
|
public override void OnPointerExit([NotNull] PointerEventData eventData)
|
|
{
|
|
base.OnPointerExit(eventData);
|
|
|
|
Text.overrideColorTags = originalOverrideColorTags;
|
|
Text.color = originalColor;
|
|
}
|
|
}
|
|
}
|
|
}
|