tasklist scrollbinds; remember scroll position; remember open quest

This commit is contained in:
Tyfon
2024-07-01 11:01:37 -07:00
parent a3ae04b32a
commit 3c93de0be9
2 changed files with 85 additions and 1 deletions

View File

@@ -77,7 +77,6 @@ namespace UIFixes
RectTransform parentView = initialGridView.transform.parent.RectTransform();
Vector2 parentPosition = parentView.pivot.y == 1 ? parentView.position : new Vector2(parentView.position.x, parentView.position.y + parentView.sizeDelta.y);
Vector2 gridSize = new(64f * parentView.lossyScale.x, 64f * parentView.lossyScale.y);
foreach (GridView gridView in parentView.GetComponentsInChildren<GridView>())

View File

@@ -25,6 +25,9 @@ namespace UIFixes
new EnhanceMailScrollingPatch().Enable();
new MouseScrollingSpeedPatch().Enable();
new EnhanceHideoutScrollingPatch().Enable();
new EnhanceTaskListScrollingPatch().Enable();
new RememberTaskListScrollPositionPatch().Enable();
new OpenLastTaskPatch().Enable();
}
private static bool HandleInput(ScrollRect scrollRect)
@@ -302,5 +305,87 @@ namespace UIFixes
data.scrollDelta *= multi;
}
}
public class EnhanceTaskListScrollingPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(TasksScreen), nameof(TasksScreen.Awake));
}
[PatchPostfix]
public static void Postfix(ScrollRect ____scrollRect)
{
var keyScroller = ____scrollRect.GetOrAddComponent<KeyScroller>();
keyScroller.Init(____scrollRect);
}
}
public class KeyScroller : MonoBehaviour
{
ScrollRect scrollRect;
public void Init(ScrollRect scrollRect)
{
this.scrollRect = scrollRect;
}
public void Update()
{
HandleInput(scrollRect);
}
}
public class RememberTaskListScrollPositionPatch : ModulePatch
{
private static float ScrollPosition = 1f;
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(TasksScreen), nameof(TasksScreen.Show));
}
[PatchPostfix]
public static void Postfix(TasksScreen __instance, ScrollRect ____scrollRect)
{
____scrollRect.verticalNormalizedPosition = ScrollPosition;
____scrollRect.onValueChanged.AddListener(UpdateScrollPosition);
__instance.R().UI.AddDisposable(() => ____scrollRect.onValueChanged.RemoveListener(UpdateScrollPosition));
}
private static void UpdateScrollPosition(Vector2 position)
{
ScrollPosition = position.y;
}
}
public class OpenLastTaskPatch : ModulePatch
{
private static string LastQuestId = null;
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(NotesTask), nameof(NotesTask.Show));
}
[PatchPostfix]
public static void Postfix(NotesTask __instance, GClass1249 quest)
{
void OnTaskSelected(bool open)
{
LastQuestId = open ? quest.Id : null;
}
Toggle toggle = __instance.GetComponent<Toggle>();
toggle.onValueChanged.AddListener(OnTaskSelected);
__instance.R().UI.AddDisposable(() => toggle.onValueChanged.RemoveListener(OnTaskSelected));
if (quest.Id == LastQuestId)
{
toggle.isOn = true;
}
}
}
}
}