Fix bulk offers market prices multiply by count for bulk offers, v1.6.1

This commit is contained in:
Tyfon
2024-05-29 16:38:28 -07:00
parent 6c1bb5d484
commit adc8c565cd
5 changed files with 26 additions and 10 deletions

View File

@@ -26,26 +26,36 @@ namespace UIFixes
} }
[PatchPostfix] [PatchPostfix]
public static void Postfix(ItemMarketPricesPanel ____pricesPanel, RequirementView[] ____requirementViews) public static void Postfix(AddOfferWindow __instance, ItemMarketPricesPanel ____pricesPanel, RequirementView[] ____requirementViews)
{ {
var panel = ____pricesPanel.R(); var panel = ____pricesPanel.R();
var rublesRequirement = ____requirementViews.First(rv => rv.name == "Requirement (RUB)"); var rublesRequirement = ____requirementViews.First(rv => rv.name == "Requirement (RUB)");
Button lowestButton = panel.LowestLabel.GetOrAddComponent<HighlightButton>(); Button lowestButton = panel.LowestLabel.GetOrAddComponent<HighlightButton>();
lowestButton.onClick.AddListener(() => rublesRequirement.method_0(____pricesPanel.Minimum.ToString("F0"))); lowestButton.onClick.AddListener(() => SetRequirement(__instance, rublesRequirement, ____pricesPanel.Minimum));
____pricesPanel.AddDisposable(lowestButton.onClick.RemoveAllListeners); ____pricesPanel.AddDisposable(lowestButton.onClick.RemoveAllListeners);
Button averageButton = panel.AverageLabel.GetOrAddComponent<HighlightButton>(); Button averageButton = panel.AverageLabel.GetOrAddComponent<HighlightButton>();
averageButton.onClick.AddListener(() => rublesRequirement.method_0(____pricesPanel.Average.ToString("F0"))); averageButton.onClick.AddListener(() => SetRequirement(__instance, rublesRequirement, ____pricesPanel.Average));
____pricesPanel.AddDisposable(averageButton.onClick.RemoveAllListeners); ____pricesPanel.AddDisposable(averageButton.onClick.RemoveAllListeners);
Button maximumButton = panel.MaximumLabel.GetOrAddComponent<HighlightButton>(); Button maximumButton = panel.MaximumLabel.GetOrAddComponent<HighlightButton>();
maximumButton.onClick.AddListener(() => rublesRequirement.method_0(____pricesPanel.Maximum.ToString("F0"))); maximumButton.onClick.AddListener(() => SetRequirement(__instance, rublesRequirement, ____pricesPanel.Maximum));
____pricesPanel.AddDisposable(maximumButton.onClick.RemoveAllListeners); ____pricesPanel.AddDisposable(maximumButton.onClick.RemoveAllListeners);
} }
} }
private static void SetRequirement(AddOfferWindow window, RequirementView requirement, float price)
{
if (window.R().BulkOffer)
{
price *= window.Int32_0; // offer item count
}
requirement.method_0(price.ToString("F0"));
}
public class HighlightButton : Button public class HighlightButton : Button
{ {
private Color originalColor; private Color originalColor;

View File

@@ -40,13 +40,16 @@ namespace UIFixes
} }
[PatchPostfix] [PatchPostfix]
public static void Postfix(RequirementView[] ____requirementViews) public static void Postfix(RequirementView[] ____requirementViews, bool ___bool_2)
{
if (Settings.KeepAddOfferOpen.Value && ___bool_2)
{ {
// clear old prices // clear old prices
foreach(var requirementView in ____requirementViews) foreach (var requirementView in ____requirementViews)
{ {
requirementView.ResetRequirementInformation(); requirementView.ResetRequirementInformation();
} }
}
BlockClose = false; BlockClose = false;
} }

3
R.cs
View File

@@ -442,14 +442,17 @@ namespace UIFixes
{ {
public static Type Type { get; private set; } public static Type Type { get; private set; }
private static FieldInfo RagfairField; private static FieldInfo RagfairField;
private static FieldInfo BulkOfferField;
public static void InitTypes() public static void InitTypes()
{ {
Type = typeof(EFT.UI.Ragfair.AddOfferWindow); Type = typeof(EFT.UI.Ragfair.AddOfferWindow);
RagfairField = AccessTools.GetDeclaredFields(Type).First(t => t.FieldType == typeof(RagFairClass)); RagfairField = AccessTools.GetDeclaredFields(Type).First(t => t.FieldType == typeof(RagFairClass));
BulkOfferField = AccessTools.Field(Type, "bool_0");
} }
public RagFairClass Ragfair { get { return (RagFairClass)RagfairField.GetValue(Value); } } public RagFairClass Ragfair { get { return (RagFairClass)RagfairField.GetValue(Value); } }
public bool BulkOffer { get { return (bool)BulkOfferField.GetValue(Value); } }
} }
public class ItemUiContext(object value) : Wrapper(value) public class ItemUiContext(object value) : Wrapper(value)

View File

@@ -4,7 +4,7 @@
<TargetFramework>net471</TargetFramework> <TargetFramework>net471</TargetFramework>
<AssemblyName>Tyfon.UIFixes</AssemblyName> <AssemblyName>Tyfon.UIFixes</AssemblyName>
<Description>SPT UI Fixes</Description> <Description>SPT UI Fixes</Description>
<Version>1.6.1</Version> <Version>1.6.2</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Configurations>Debug;Release;Dist</Configurations> <Configurations>Debug;Release;Dist</Configurations>

View File

@@ -1,6 +1,6 @@
{ {
"name": "uifixes", "name": "uifixes",
"version": "1.6.1", "version": "1.6.2",
"main": "src/mod.js", "main": "src/mod.js",
"license": "MIT", "license": "MIT",
"author": "Tyfon", "author": "Tyfon",