Skip to content

Commit

Permalink
Add isSelected to VioletButton
Browse files Browse the repository at this point in the history
  • Loading branch information
neilsarkar committed Dec 23, 2020
1 parent 8cf697f commit 671d081
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Editor/VioletButtonEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ namespace VioletUI {
[CustomEditor(typeof(VioletButton))]
public class VioletButtonEditor : ButtonEditor {
public override void OnInspectorGUI() {
base.OnInspectorGUI();
VioletButton button = (VioletButton)target;

button.visitScreen = (ScreenId)EditorGUILayout.EnumPopup("Visit Screen", button.visitScreen);
base.OnInspectorGUI();
}
}
}
28 changes: 22 additions & 6 deletions Runtime/Navigation/VioletButton.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEngine;
using UnityEngine.EventSystems;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
Expand All @@ -8,6 +9,8 @@ namespace VioletUI {
[ExecuteAlways]
public class VioletButton : UnityEngine.UI.Button {
public ScreenId visitScreen;
[NonSerialized]
public bool isSelected;

protected Navigator navigator;
protected override void Awake() {
Expand All @@ -16,6 +19,14 @@ protected override void Awake() {
Violet.LogVerbose($"Button awoken. navigator={navigator}");
}

protected virtual void Submit() {
Violet.LogVerbose($"Button {name} clicked");
if (visitScreen != ScreenId.None) {
Violet.LogVerbose($"Visiting {visitScreen} navigator={navigator}");
_ = navigator.Visit(visitScreen);
}
}

protected override void OnEnable() {
base.OnEnable();
this.onClick.AddListener(Submit);
Expand All @@ -24,19 +35,22 @@ protected override void OnEnable() {
protected override void OnDisable() {
base.OnDisable();
this.onClick.RemoveListener(Submit);
isSelected = false;
}

protected override void OnDestroy() {
base.OnDestroy();
this.onClick.RemoveListener(Submit);
}

protected virtual void Submit() {
Violet.LogVerbose($"Button {name} clicked");
if (visitScreen != ScreenId.None) {
Violet.LogVerbose($"Visiting {visitScreen} navigator={navigator}");
navigator.Visit(visitScreen);
}
public override void OnSelect(BaseEventData eventData) {
base.OnSelect(eventData);
isSelected = true;
}

public override void OnDeselect(BaseEventData eventData) {
base.OnDeselect(eventData);
isSelected = false;
}

#if UNITY_EDITOR
Expand Down Expand Up @@ -65,6 +79,8 @@ void OnGUI() {
Violet.LogVerbose($"transform.position={transform.position} topLeft={topLeft} bottomRight={bottomRight} mousePosition={mousePosition}");
}
}

#endif
}

}

0 comments on commit 671d081

Please sign in to comment.