advanced setting for multiselect in raid; unload ammo more places

This commit is contained in:
Tyfon
2024-06-23 15:20:34 -07:00
parent 1654e8741e
commit bd004aea9f
7 changed files with 112 additions and 5 deletions

View File

@@ -49,7 +49,7 @@ namespace UIFixes
public void Update()
{
if (!Settings.EnableMultiSelect.Value)
if (!MultiSelect.Enabled)
{
return;
}

View File

@@ -18,6 +18,14 @@ namespace UIFixes
private static ItemContextTaskSerializer UnloadSerializer = null;
public static bool Enabled
{
get
{
return Settings.EnableMultiSelect.Value && (!Plugin.InRaid() || Settings.EnableMultiSelectInRaid.Value);
}
}
public static void Initialize()
{
// Grab the selection objects from ragfair as templates

View File

@@ -13,7 +13,7 @@ namespace UIFixes
public void OnGUI()
{
if (!Settings.EnableMultiSelect.Value || !Settings.ShowMultiSelectDebug.Value)
if (!MultiSelect.Enabled || !Settings.ShowMultiSelectDebug.Value)
{
return;
}

View File

@@ -92,7 +92,7 @@ namespace UIFixes
[PatchPostfix]
public static void Postfix(CommonUI __instance)
{
if (!Settings.EnableMultiSelect.Value)
if (!MultiSelect.Enabled)
{
return;
}
@@ -131,7 +131,7 @@ namespace UIFixes
[PatchPostfix]
public static void Postfix(MenuUI __instance)
{
if (!Settings.EnableMultiSelect.Value)
if (!MultiSelect.Enabled)
{
return;
}
@@ -150,7 +150,7 @@ namespace UIFixes
[PatchPostfix]
public static void Postfix(ItemView __instance, PointerEventData eventData)
{
if (!Settings.EnableMultiSelect.Value || __instance is RagfairNewOfferItemView || __instance is InsuranceItemView)
if (!MultiSelect.Enabled || __instance is RagfairNewOfferItemView || __instance is InsuranceItemView)
{
return;
}

View File

@@ -0,0 +1,50 @@
using Aki.Reflection.Patching;
using EFT.InventoryLogic;
using HarmonyLib;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace UIFixes
{
public static class UnloadAmmoPatches
{
public static void Enable()
{
new TradingPlayerPatch().Enable();
new TransferPlayerPatch().Enable();
}
public class TradingPlayerPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.DeclaredProperty(typeof(GClass3032), nameof(GClass3032.AvailableInteractions)).GetMethod;
}
[PatchPostfix]
public static void Postfix(ref IEnumerable<EItemInfoButton> __result)
{
var list = __result.ToList();
list.Insert(list.IndexOf(EItemInfoButton.Repair), EItemInfoButton.UnloadAmmo);
__result = list;
}
}
public class TransferPlayerPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.DeclaredProperty(typeof(GClass3035), nameof(GClass3035.AvailableInteractions)).GetMethod;
}
[PatchPostfix]
public static void Postfix(ref IEnumerable<EItemInfoButton> __result)
{
var list = __result.ToList();
list.Insert(list.IndexOf(EItemInfoButton.Fold), EItemInfoButton.UnloadAmmo);
__result = list;
}
}
}
}

View File

@@ -52,6 +52,7 @@ namespace UIFixes
MultiSelectPatches.Enable();
new FixUnloadLastBulletPatch().Enable();
StackMoveGreedyPatches.Enable();
UnloadAmmoPatches.Enable();
}
public static bool InRaid()

View File

@@ -66,6 +66,7 @@ namespace UIFixes
// Inventory
public static ConfigEntry<bool> EnableMultiSelect { get; set; }
public static ConfigEntry<bool> EnableMultiSelectInRaid { get; set; }
public static ConfigEntry<KeyboardShortcut> SelectionBoxKey { get; set; }
public static ConfigEntry<MultiSelectStrategy> MultiSelectStrat { get; set; }
public static ConfigEntry<bool> ShowMultiSelectDebug { get; set; } // Advanced
@@ -306,6 +307,15 @@ namespace UIFixes
null,
new ConfigurationManagerAttributes { })));
configEntries.Add(EnableMultiSelectInRaid = config.Bind(
InventorySection,
"Enable Multiselect In Raid",
true,
new ConfigDescription(
"Enable multiselect functionality in raid.",
null,
new ConfigurationManagerAttributes { IsAdvanced = true })));
configEntries.Add(SelectionBoxKey = config.Bind(
InventorySection,
"Selection Box Key",
@@ -564,6 +574,9 @@ namespace UIFixes
RecalcOrder(configEntries);
MakeExclusive(EnableMultiSelect, AutoOpenSortingTable);
MakeDependent(EnableMultiSelect, EnableMultiSelectInRaid);
MakeDependent(EnableMultiSelect, ShowMultiSelectDebug, false);
}
private static void RecalcOrder(List<ConfigEntryBase> configEntries)
@@ -604,5 +617,40 @@ namespace UIFixes
}
};
}
private static void MakeDependent(ConfigEntry<bool> primaryConfig, ConfigEntry<bool> dependentConfig, bool primaryEnablesDependent = true)
{
if (!primaryConfig.Value)
{
dependentConfig.Value = false;
if (dependentConfig.Description.Tags[0] is ConfigurationManagerAttributes attributes)
{
attributes.ReadOnly = true;
}
}
primaryConfig.SettingChanged += (_, _) =>
{
if (primaryConfig.Value)
{
if (primaryEnablesDependent)
{
dependentConfig.Value = true;
}
}
else
{
dependentConfig.Value = false;
}
};
dependentConfig.SettingChanged += (_, _) =>
{
if (!primaryConfig.Value)
{
dependentConfig.Value = false;
}
};
}
}
}