TO SQUASH: started menu callback calling

This commit is contained in:
2026-07-31 01:35:31 -04:00
parent 011fc467b8
commit 744e53f63f
7 changed files with 204 additions and 50 deletions
+93 -6
View File
@@ -17,6 +17,16 @@ public class MenuButton : MonoBehaviour
private static Color opaque = new Color(1f, 1f, 1f, 1f);
private const float holdThreshold = 0.15f;
private bool pointerDownOnButton = false;
private bool holdInteraction = false;
private bool pointerInsideDuringHold = false;
private float pointerDownTime = 0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
@@ -27,18 +37,83 @@ public class MenuButton : MonoBehaviour
// Update is called once per frame
void Update()
{
if (Mouse.current == null)
{
return;
}
// Check for mouse button press to request key translation and handle hold interactions
if (Mouse.current.leftButton.wasPressedThisFrame)
{
Vector2 mousePosition = Mouse.current.position.ReadValue();
Vector2 worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
if (boxCollider.OverlapPoint(worldMousePosition))
if (IsPointerInsideButton())
{
isButtonPressed = true;
key.TranslateTo(row);
} else {
isButtonPressed = false;
pointerDownOnButton = true;
holdInteraction = false;
pointerInsideDuringHold = true;
pointerDownTime = Time.unscaledTime;
}
else
{
isButtonPressed = false;
pointerDownOnButton = false;
holdInteraction = false;
}
}
if (pointerDownOnButton && Mouse.current.leftButton.isPressed)
{
bool pointerInside = IsPointerInsideButton();
if (!holdInteraction && (Time.unscaledTime - pointerDownTime) >= holdThreshold)
{
holdInteraction = true;
key.OpenKey(false);
pointerInsideDuringHold = pointerInside;
if (!pointerInside)
{
key.CloseKey();
}
}
if (holdInteraction)
{
if (pointerInside && !pointerInsideDuringHold)
{
key.OpenKey(false);
}
else if (!pointerInside && pointerInsideDuringHold)
{
key.CloseKey();
}
pointerInsideDuringHold = pointerInside;
}
}
if (pointerDownOnButton && Mouse.current.leftButton.wasReleasedThisFrame)
{
bool pointerInside = IsPointerInsideButton();
if (holdInteraction)
{
if (pointerInside)
{
key.InvokeCallback();
}
key.ReleaseKey();
}
else
{
key.OpenKey(true);
}
pointerDownOnButton = false;
holdInteraction = false;
pointerInsideDuringHold = false;
}
if (isButtonPressed)
@@ -50,4 +125,16 @@ public class MenuButton : MonoBehaviour
spriteRenderer.color = transparent;
}
}
private bool IsPointerInsideButton()
{
if (Camera.main == null)
{
return false;
}
Vector2 mousePosition = Mouse.current.position.ReadValue();
Vector2 worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
return boxCollider.OverlapPoint(worldMousePosition);
}
}