fix bsg bug that loses context on search, fixing multiselect drawing when mouse starts over unsearched item that becomes searched

This commit is contained in:
Tyfon
2024-07-13 15:54:28 -07:00
parent 1170037614
commit 0277490e8a
4 changed files with 91 additions and 10 deletions

View File

@@ -54,6 +54,7 @@ public static class MultiSelectPatches
// Workarounds
new DisableSplitPatch().Enable();
new DisableSplitTargetPatch().Enable();
new FixSearchedContextPatch().Enable();
// Actions
new ItemViewClickPatch().Enable();
@@ -425,6 +426,71 @@ public static class MultiSelectPatches
}
}
public class FixSearchedContextPatch : ModulePatch
{
private static string CurrentContextSearchingId = null;
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GridView), nameof(GridView.OnItemAdded));
}
[PatchPrefix]
public static void Prefix(GridView __instance, GEventArgs2 eventArgs, TraderControllerClass ___traderControllerClass, ItemUiContext ___itemUiContext_0)
{
if (eventArgs.To.Container != __instance.Grid || eventArgs.Status != CommandStatus.Begin)
{
return;
}
Item item = eventArgs.Item;
if (___itemUiContext_0.ItemContextAbstractClass?.Item != eventArgs.Item)
{
return;
}
LocationInGrid locationInGrid = ((GridItemAddress)eventArgs.To).LocationInGrid;
bool searchable = !(___traderControllerClass != null && ___traderControllerClass.CanSearch && ___traderControllerClass.ID != eventArgs.OwnerId);
if (!searchable || !locationInGrid.isSearched)
{
return;
}
ItemView itemView = __instance.method_9(item, iv => !iv.IsSearched);
if (itemView != null)
{
CurrentContextSearchingId = item.Id;
}
}
[PatchPostfix]
public static void Postfix(GridView __instance, GEventArgs2 eventArgs, ItemUiContext ___itemUiContext_0, Dictionary<string, ItemView> ___dictionary_0)
{
if (eventArgs.To.Container != __instance.Grid)
{
return;
}
if (CurrentContextSearchingId == eventArgs.Item.Id)
{
if (eventArgs.Status == CommandStatus.Succeed)
{
if (___dictionary_0.TryGetValue(eventArgs.Item.Id, out ItemView itemView))
{
___itemUiContext_0.RegisterCurrentItemContext(itemView.ItemContext);
}
CurrentContextSearchingId = null;
}
else if (eventArgs.Status == CommandStatus.Failed)
{
CurrentContextSearchingId = null;
}
}
}
}
public class GridViewCanAcceptPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()