Remember autoselect similar
This commit is contained in:
62
Patches/AddOfferRememberAutoselectPatches.cs
Normal file
62
Patches/AddOfferRememberAutoselectPatches.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Aki.Reflection.Patching;
|
||||
using EFT.UI;
|
||||
using EFT.UI.Ragfair;
|
||||
using HarmonyLib;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UIFixes
|
||||
{
|
||||
public static class AddOfferRememberAutoselectPatches
|
||||
{
|
||||
private static readonly string PlayerPrefKey = "UIFixes.AddOffer.AutoselectSimilar";
|
||||
|
||||
public static void Enable()
|
||||
{
|
||||
new RememberAutoselectPatch().Enable();
|
||||
new RestoreAutoselectPatch().Enable();
|
||||
|
||||
Settings.RememberAutoselectSimilar.SettingChanged += (sender, args) =>
|
||||
{
|
||||
if (!Settings.RememberAutoselectSimilar.Value)
|
||||
{
|
||||
PlayerPrefs.DeleteKey(PlayerPrefKey);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public class RememberAutoselectPatch : ModulePatch
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
return AccessTools.Method(typeof(AddOfferWindow), nameof(AddOfferWindow.method_8));
|
||||
}
|
||||
|
||||
[PatchPostfix]
|
||||
public static void Postfix(bool value)
|
||||
{
|
||||
if (Settings.RememberAutoselectSimilar.Value)
|
||||
{
|
||||
PlayerPrefs.SetInt(PlayerPrefKey, value ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RestoreAutoselectPatch : ModulePatch
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
return AccessTools.Method(typeof(AddOfferWindow), nameof(AddOfferWindow.Awake));
|
||||
}
|
||||
|
||||
[PatchPrefix]
|
||||
public static void Prefix(UpdatableToggle ____autoSelectSimilar)
|
||||
{
|
||||
if (Settings.RememberAutoselectSimilar.Value && PlayerPrefs.HasKey(PlayerPrefKey))
|
||||
{
|
||||
____autoSelectSimilar.UpdateValue(PlayerPrefs.GetInt(PlayerPrefKey) == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ namespace UIFixes
|
||||
new AutofillQuestItemsPatch().Enable();
|
||||
InsureContextMenuPatches.Enable();
|
||||
TradingAutoSwitchPatches.Enable();
|
||||
AddOfferRememberAutoselectPatches.Enable();
|
||||
}
|
||||
|
||||
public static bool InRaid()
|
||||
|
||||
10
Settings.cs
10
Settings.cs
@@ -65,6 +65,7 @@ namespace UIFixes
|
||||
public static ConfigEntry<bool> AutoExpandCategories { get; set; }
|
||||
public static ConfigEntry<bool> KeepAddOfferOpen { get; set; }
|
||||
public static ConfigEntry<bool> KeepAddOfferOpenIgnoreMaxOffers { get; set; } // Advanced
|
||||
public static ConfigEntry<bool> RememberAutoselectSimilar { get; set; } // Advanced
|
||||
|
||||
public static void Init(ConfigFile config)
|
||||
{
|
||||
@@ -310,6 +311,15 @@ namespace UIFixes
|
||||
null,
|
||||
new ConfigurationManagerAttributes { IsAdvanced = true })));
|
||||
|
||||
configEntries.Add(RememberAutoselectSimilar = config.Bind(
|
||||
FleaMarketSection,
|
||||
"Remember Add Offer Autoselect Similar",
|
||||
true,
|
||||
new ConfigDescription(
|
||||
"Remember the state of the Autoselect Similar checkbox in the Add Offer window",
|
||||
null,
|
||||
new ConfigurationManagerAttributes { IsAdvanced = true })));
|
||||
|
||||
RecalcOrder(configEntries);
|
||||
}
|
||||
private static void RecalcOrder(List<ConfigEntryBase> configEntries)
|
||||
|
||||
Reference in New Issue
Block a user