Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private static void HookOnSelect(ILManipulationInfo info)
private static void HookOnDeselect(ILManipulationInfo info)
{
ILCursor cursor = new(info.Context);

int locIndex = 1;
while (
cursor.TryGotoNext(
Expand Down
3 changes: 3 additions & 0 deletions Silksong.ModMenu/Elements/TextInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public TextInput(LocalizedText label, ITextModel<T> model, LocalizedText descrip
InputField.contentType = InputField.ContentType.IntegerNumber;
else if (floatTypes.Contains(typeof(T)))
InputField.contentType = InputField.ContentType.DecimalNumber;

input.AddComponent<DescriptionAnimationHelper>().DescriptionAnimator =
DescriptionText.gameObject.GetComponent<Animator>();
}

/// <summary>
Expand Down
83 changes: 83 additions & 0 deletions Silksong.ModMenu/Internal/DescriptionAnimationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Silksong.ModMenu.Internal;

internal class DescriptionAnimationHelper
: MonoBehaviour,
ISelectHandler,
IDeselectHandler,
ICancelHandler
{
private Selectable _selectable;
public Animator? DescriptionAnimator { get; set; }

void Awake()
{
_selectable = GetComponent<Selectable>();
}

public void OnDeselect(BaseEventData eventData)
{
StartCoroutine(ValidateDeselect(eventData, false));
}

// My best attempt to imitate the code from MenuSelectable.ValidateDeselect
private IEnumerator ValidateDeselect(BaseEventData eventData, bool force)
{
if (DescriptionAnimator == null)
{
yield break;
}

GameObject? prevSelectedObject = EventSystem.current.currentSelectedGameObject;

yield return new WaitForEndOfFrame();

if (!(EventSystem.current.currentSelectedGameObject != null || force))
{
InputHandler ih = ManagerSingleton<InputHandler>.Instance;
if (ih && !ih.acceptingInput)
{
while (!ih.acceptingInput)
{
yield return null;
}
}
yield return null;
}

if (EventSystem.current.currentSelectedGameObject != null || force)
{
DescriptionAnimator.ResetTrigger(MenuSelectable._showPropId);
DescriptionAnimator.SetTrigger(MenuSelectable._hidePropId);
}
else if (prevSelectedObject != null && prevSelectedObject.activeInHierarchy)
{
EventSystem.current.SetSelectedGameObject(prevSelectedObject);
}
}

public void OnSelect(BaseEventData eventData)
{
if (DescriptionAnimator == null)
{
return;
}

if (!_selectable.interactable)
{
return;
}

DescriptionAnimator.ResetTrigger(MenuSelectable._hidePropId);
DescriptionAnimator.SetTrigger(MenuSelectable._showPropId);
}

public void OnCancel(BaseEventData eventData)
{
StartCoroutine(ValidateDeselect(eventData, true));
}
}