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