| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public interface IExtraActionsView |
| | 7 | | { |
| | 8 | | event Action OnControlsClicked, |
| | 9 | | OnHideUIClicked, |
| | 10 | | OnTutorialClicked, |
| | 11 | | OnResetClicked, |
| | 12 | | OnResetCameraClicked; |
| | 13 | |
|
| | 14 | | void OnControlsClick(DCLAction_Trigger action); |
| | 15 | | void OnHideUIClick(DCLAction_Trigger action); |
| | 16 | | void OnTutorialClick(); |
| | 17 | | void SetActive(bool isActive); |
| | 18 | | void OnResetClick(DCLAction_Trigger action); |
| | 19 | | void OnResetCameraClick(DCLAction_Trigger action); |
| | 20 | | void SetResetButtonInteractable(bool isInteractable); |
| | 21 | | } |
| | 22 | |
|
| | 23 | | public class ExtraActionsView : MonoBehaviour, IExtraActionsView |
| | 24 | | { |
| | 25 | | public event Action OnControlsClicked, |
| | 26 | | OnHideUIClicked, |
| | 27 | | OnTutorialClicked, |
| | 28 | | OnResetClicked, |
| | 29 | | OnResetCameraClicked; |
| | 30 | |
|
| | 31 | | [Header("Buttons")] |
| | 32 | | [SerializeField] internal Button hideUIBtn; |
| | 33 | | [SerializeField] internal Button controlsBtn; |
| | 34 | | [SerializeField] internal Button tutorialBtn; |
| | 35 | | [SerializeField] internal Button resetBtn; |
| | 36 | | [SerializeField] internal TMP_Text resetBtnText; |
| | 37 | | [SerializeField] internal Button resetCameraBtn; |
| | 38 | |
|
| | 39 | | [Header("Input Actions")] |
| | 40 | | [SerializeField] internal InputAction_Trigger toggleUIVisibilityInputAction; |
| | 41 | | [SerializeField] internal InputAction_Trigger toggleControlsVisibilityInputAction; |
| | 42 | | [SerializeField] internal InputAction_Trigger toggleResetInputAction; |
| | 43 | | [SerializeField] internal InputAction_Trigger toggleResetCameraInputAction; |
| | 44 | |
|
| | 45 | | [Header("Other Configurations")] |
| | 46 | | [SerializeField] internal Color disabledButtonTextColor; |
| | 47 | |
|
| | 48 | | private DCLAction_Trigger dummyActionTrigger = new DCLAction_Trigger(); |
| | 49 | | private Color originalResetBtnColor; |
| | 50 | |
|
| | 51 | | private const string VIEW_PATH = "GodMode/TopActionsButtons/ExtraActionsView"; |
| | 52 | |
|
| | 53 | | internal static ExtraActionsView Create() |
| | 54 | | { |
| 9 | 55 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<ExtraActionsView>(); |
| 9 | 56 | | view.gameObject.name = "_ExtraActionsView"; |
| | 57 | |
|
| 9 | 58 | | return view; |
| | 59 | | } |
| | 60 | |
|
| | 61 | | private void Awake() |
| | 62 | | { |
| 47 | 63 | | hideUIBtn.onClick.AddListener(() => OnHideUIClick(dummyActionTrigger)); |
| 47 | 64 | | controlsBtn.onClick.AddListener(() => OnControlsClick(dummyActionTrigger)); |
| 47 | 65 | | resetBtn.onClick.AddListener(() => OnResetClick(dummyActionTrigger)); |
| 47 | 66 | | resetCameraBtn.onClick.AddListener(() => OnResetCameraClick(dummyActionTrigger)); |
| 47 | 67 | | tutorialBtn.onClick.AddListener(OnTutorialClick); |
| | 68 | |
|
| 47 | 69 | | toggleUIVisibilityInputAction.OnTriggered += OnHideUIClick; |
| 47 | 70 | | toggleControlsVisibilityInputAction.OnTriggered += OnControlsClick; |
| 47 | 71 | | toggleResetInputAction.OnTriggered += OnResetClick; |
| 47 | 72 | | toggleResetCameraInputAction.OnTriggered += OnResetCameraClick; |
| | 73 | |
|
| 47 | 74 | | originalResetBtnColor = resetBtnText.color; |
| 47 | 75 | | SetResetButtonInteractable(true); |
| 47 | 76 | | } |
| | 77 | |
|
| | 78 | | private void OnDestroy() |
| | 79 | | { |
| 47 | 80 | | hideUIBtn.onClick.RemoveAllListeners(); |
| 47 | 81 | | controlsBtn.onClick.RemoveAllListeners(); |
| 47 | 82 | | resetBtn.onClick.RemoveAllListeners(); |
| 47 | 83 | | resetCameraBtn.onClick.RemoveAllListeners(); |
| 47 | 84 | | tutorialBtn.onClick.RemoveListener(OnTutorialClick); |
| | 85 | |
|
| 47 | 86 | | toggleUIVisibilityInputAction.OnTriggered -= OnHideUIClick; |
| 47 | 87 | | toggleControlsVisibilityInputAction.OnTriggered -= OnControlsClick; |
| 47 | 88 | | toggleResetInputAction.OnTriggered -= OnResetClick; |
| 47 | 89 | | toggleResetCameraInputAction.OnTriggered -= OnResetCameraClick; |
| 47 | 90 | | } |
| | 91 | |
|
| | 92 | | public void SetActive(bool isActive) |
| | 93 | | { |
| 2 | 94 | | if (gameObject.activeSelf != isActive) |
| 2 | 95 | | gameObject.SetActive(isActive); |
| 2 | 96 | | } |
| | 97 | |
|
| 2 | 98 | | public void OnControlsClick(DCLAction_Trigger action) { OnControlsClicked?.Invoke(); } |
| | 99 | |
|
| 2 | 100 | | public void OnHideUIClick(DCLAction_Trigger action) { OnHideUIClicked?.Invoke(); } |
| | 101 | |
|
| 2 | 102 | | public void OnTutorialClick() { OnTutorialClicked?.Invoke(); } |
| | 103 | |
|
| 2 | 104 | | public void OnResetClick(DCLAction_Trigger action) { OnResetClicked?.Invoke(); } |
| | 105 | |
|
| 2 | 106 | | public void OnResetCameraClick(DCLAction_Trigger action) { OnResetCameraClicked?.Invoke(); } |
| | 107 | |
|
| | 108 | | public void SetResetButtonInteractable(bool isInteractable) |
| | 109 | | { |
| 49 | 110 | | resetBtn.interactable = isInteractable; |
| 49 | 111 | | resetBtnText.color = isInteractable ? originalResetBtnColor : disabledButtonTextColor; |
| 49 | 112 | | } |
| | 113 | | } |