| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.EventSystems; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public interface IInspectorBtnView |
| | 7 | | { |
| | 8 | | event Action OnHideTooltip; |
| | 9 | | event Action OnInspectorButtonClick; |
| | 10 | | event Action<BaseEventData, string> OnShowTooltip; |
| | 11 | |
|
| | 12 | | void OnPointerClick(DCLAction_Trigger action); |
| | 13 | | void OnPointerEnter(PointerEventData eventData); |
| | 14 | | void OnPointerExit(); |
| | 15 | | } |
| | 16 | |
|
| | 17 | | public class InspectorBtnView : MonoBehaviour, IInspectorBtnView |
| | 18 | | { |
| | 19 | | public event Action OnInspectorButtonClick; |
| | 20 | | public event Action<BaseEventData, string> OnShowTooltip; |
| | 21 | | public event Action OnHideTooltip; |
| | 22 | |
|
| | 23 | | [SerializeField] internal Button mainButton; |
| 24 | 24 | | [SerializeField] internal string tooltipText = "Open Entity List (Q)"; |
| | 25 | | [SerializeField] internal EventTrigger inspectorButtonEventTrigger; |
| | 26 | | [SerializeField] internal InputAction_Trigger toggleOpenEntityListInputAction; |
| | 27 | |
|
| | 28 | | private DCLAction_Trigger dummyActionTrigger = new DCLAction_Trigger(); |
| | 29 | |
|
| | 30 | | private const string VIEW_PATH = "GodMode/Inspector/InspectorBtnView"; |
| | 31 | |
|
| | 32 | | internal static InspectorBtnView Create() |
| | 33 | | { |
| 3 | 34 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<InspectorBtnView>(); |
| 3 | 35 | | view.gameObject.name = "_InspectorBtnView"; |
| | 36 | |
|
| 3 | 37 | | return view; |
| | 38 | | } |
| | 39 | |
|
| | 40 | | private void Awake() |
| | 41 | | { |
| 22 | 42 | | mainButton.onClick.AddListener(() => OnPointerClick(dummyActionTrigger)); |
| 22 | 43 | | toggleOpenEntityListInputAction.OnTriggered += OnPointerClick; |
| 22 | 44 | | BIWUtils.ConfigureEventTrigger(inspectorButtonEventTrigger, EventTriggerType.PointerEnter, (eventData) => OnPoin |
| 22 | 45 | | BIWUtils.ConfigureEventTrigger(inspectorButtonEventTrigger, EventTriggerType.PointerExit, (eventData) => OnPoint |
| 22 | 46 | | } |
| | 47 | |
|
| | 48 | | private void OnDestroy() |
| | 49 | | { |
| 22 | 50 | | mainButton.onClick.RemoveAllListeners(); |
| 22 | 51 | | toggleOpenEntityListInputAction.OnTriggered -= OnPointerClick; |
| 22 | 52 | | BIWUtils.RemoveEventTrigger(inspectorButtonEventTrigger, EventTriggerType.PointerEnter); |
| 22 | 53 | | BIWUtils.RemoveEventTrigger(inspectorButtonEventTrigger, EventTriggerType.PointerExit); |
| 22 | 54 | | } |
| | 55 | |
|
| 2 | 56 | | public void OnPointerClick(DCLAction_Trigger action) { OnInspectorButtonClick?.Invoke(); } |
| | 57 | |
|
| 2 | 58 | | public void OnPointerEnter(PointerEventData eventData) { OnShowTooltip?.Invoke(eventData, tooltipText); } |
| | 59 | |
|
| 2 | 60 | | public void OnPointerExit() { OnHideTooltip?.Invoke(); } |
| | 61 | | } |