Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/buttons behavior #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 28 additions & 2 deletions Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Lynx.UI
{
public class LynxSimpleButton : Button
public class LynxSimpleButton : Button, IPointerUpHandler, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler, IInitializePotentialDragHandler
{
#region INSPECTOR VARIABLES

Expand All @@ -38,6 +38,8 @@ public class LynxSimpleButton : Button
private bool m_isCurrentlyPressed = false; // Status of the current object.
private bool m_isInteractable = true; // Starting interactable status.

private ScrollRect scrollRect = null;

#endregion

#region UNITY API
Expand Down Expand Up @@ -193,6 +195,30 @@ protected override void DoStateTransition(SelectionState state, bool instant)
}
}

public void OnInitializePotentialDrag(PointerEventData eventData)
{
if (scrollRect == null)
scrollRect = this.gameObject.GetComponentInParent<ScrollRect>();
}

public void OnBeginDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnBeginDrag(eventData);
}

public void OnDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnDrag(eventData);
}

public void OnEndDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnEndDrag(eventData);
}

#endregion

#region PRIVATE METHODS
Expand Down Expand Up @@ -221,7 +247,7 @@ private void ResetInteractable(bool boolean)
/// <summary>
/// CallbackStopRunning is called when a button animation coroutine is complete.
/// </summary>
/// <param name="state">True to call OnUnpress, false to call OnPress.</param>
/// <param name="state">True to call OnPress, false to call OnUnpress.</param>
private void CallbackStopRunning(bool state)
{
m_isRunning = false;
Expand Down
37 changes: 32 additions & 5 deletions Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Lynx.UI
{
public class LynxSwitchButton : Button
public class LynxSwitchButton : Button, IPointerUpHandler, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler, IInitializePotentialDragHandler
{
#region INSPECTOR VARIABLES

Expand Down Expand Up @@ -48,6 +48,8 @@ public class LynxSwitchButton : Button
private Vector3 offHandlePosition;
private Vector3 onHandlePosition;

private ScrollRect scrollRect = null;

#endregion

#region UNITY API
Expand Down Expand Up @@ -220,7 +222,31 @@ protected override void DoStateTransition(SelectionState state, bool instant)
m_secondaryTargetGraphic[i].CrossFadeColor(tintColor, instant ? 0f : colors.fadeDuration, true, true);
}
}


public void OnInitializePotentialDrag(PointerEventData eventData)
{
if(scrollRect == null)
scrollRect = this.gameObject.GetComponentInParent<ScrollRect>();
}

public void OnBeginDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnBeginDrag(eventData);
}

public void OnDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnDrag(eventData);
}

public void OnEndDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnEndDrag(eventData);
}

#endregion

#region PRIVATE METHODS
Expand Down Expand Up @@ -249,18 +275,18 @@ private void ResetInteractable(bool boolean)
/// <summary>
/// CallbackStopRunning is called when a button animation coroutine is complete.
/// </summary>
/// <param name="state">True to call OnUnpress, false to call OnPress.</param>
/// <param name="state">True to call OnPress, false to call OnUnpress.</param>
private void CallbackStopRunning(bool state)
{
m_isRunning = false;

if (state)
{
OnUnpress.Invoke();
OnPress.Invoke();
}
else
{
OnPress.Invoke();
OnUnpress.Invoke();
}
}

Expand Down Expand Up @@ -385,6 +411,7 @@ public bool IsUsingTheme()
return m_useTheme;
}


#endregion
}
}
34 changes: 30 additions & 4 deletions Packages/Core/Interfaces/Scripts/LynxTimerButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Lynx.UI
{
public class LynxTimerButton : Button
public class LynxTimerButton : Button, IPointerUpHandler, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler, IInitializePotentialDragHandler
{
#region INSPECTOR VARIABLES

Expand Down Expand Up @@ -46,6 +46,8 @@ public class LynxTimerButton : Button

private IEnumerator timerCoroutine = null; // Timer coroutine reference.

private ScrollRect scrollRect = null;

#endregion

#region UNITY API
Expand Down Expand Up @@ -205,6 +207,30 @@ protected override void DoStateTransition(SelectionState state, bool instant)
}
}

public void OnInitializePotentialDrag(PointerEventData eventData)
{
if (scrollRect == null)
scrollRect = this.gameObject.GetComponentInParent<ScrollRect>();
}

public void OnBeginDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnBeginDrag(eventData);
}

public void OnDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnDrag(eventData);
}

public void OnEndDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnEndDrag(eventData);
}

#endregion

#region PRIVATE METHODS
Expand Down Expand Up @@ -233,18 +259,18 @@ private void ResetInteractable(bool boolean)
/// <summary>
/// CallbackStopRunning is called when a button animation coroutine is complete.
/// </summary>
/// <param name="state">True to call OnUnpress, false to call OnPress.</param>
/// <param name="state">True to call OnPress, false to call OnUnpress.</param>
private void CallbackStopRunning(bool state)
{
m_isRunning = false;

if (state)
{
OnUnpress.Invoke();
OnPress.Invoke();
}
else
{
OnPress.Invoke();
OnUnpress.Invoke();
}
}

Expand Down
34 changes: 30 additions & 4 deletions Packages/Core/Interfaces/Scripts/LynxToggleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Lynx.UI
{
public class LynxToggleButton : Button
public class LynxToggleButton : Button, IPointerUpHandler, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler, IInitializePotentialDragHandler
{
#region INSPECTOR VARIABLES

Expand All @@ -41,6 +41,8 @@ public class LynxToggleButton : Button
private bool m_isToggled = false; // Status of the button.
private bool m_isInteractable = true; // Starting interactable status.

private ScrollRect scrollRect = null;

#endregion

#region UNITY API
Expand Down Expand Up @@ -207,6 +209,30 @@ protected override void DoStateTransition(SelectionState state, bool instant)
}
}

public void OnInitializePotentialDrag(PointerEventData eventData)
{
if (scrollRect == null)
scrollRect = this.gameObject.GetComponentInParent<ScrollRect>();
}

public void OnBeginDrag(PointerEventData eventData)
{
if(scrollRect != null)
scrollRect.OnBeginDrag(eventData);
}

public void OnDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnDrag(eventData);
}

public void OnEndDrag(PointerEventData eventData)
{
if (scrollRect != null)
scrollRect.OnEndDrag(eventData);
}

#endregion

#region PRIVATE METHODS
Expand Down Expand Up @@ -235,18 +261,18 @@ private void ResetInteractable(bool boolean)
/// <summary>
/// CallbackStopRunning is called when a button animation coroutine is complete.
/// </summary>
/// <param name="state">True to call OnUnpress, false to call OnPress.</param>
/// <param name="state">True to call OnPress, false to call OnUnpress.</param>
private void CallbackStopRunning(bool state)
{
m_isRunning = false;

if (state)
{
OnUnpress.Invoke();
OnPress.Invoke();
}
else
{
OnPress.Invoke();
OnUnpress.Invoke();
}
}

Expand Down