| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public interface IBuildModeConfirmationModalView |
| | 6 | | { |
| | 7 | | event Action OnCancelExit; |
| | 8 | | event Action OnConfirmExit; |
| | 9 | |
|
| | 10 | | bool IsActive(); |
| | 11 | | void SetActive(bool isActive); |
| | 12 | | void SetTitle(string text); |
| | 13 | | void SetSubTitle(string text); |
| | 14 | | void SetCancelButtonText(string text); |
| | 15 | | void SetConfirmButtonText(string text); |
| | 16 | | void CancelExit(); |
| | 17 | | void ConfirmExit(); |
| | 18 | | } |
| | 19 | |
|
| | 20 | | public class BuildModeConfirmationModalView : MonoBehaviour, IBuildModeConfirmationModalView |
| | 21 | | { |
| | 22 | | public event Action OnCancelExit; |
| | 23 | | public event Action OnConfirmExit; |
| | 24 | |
|
| | 25 | | [SerializeField] internal TMPro.TMP_Text title; |
| | 26 | | [SerializeField] internal TMPro.TMP_Text subTitle; |
| | 27 | | [SerializeField] internal TMPro.TMP_Text cancelButtonText; |
| | 28 | | [SerializeField] internal TMPro.TMP_Text confirmButtonText; |
| | 29 | | [SerializeField] internal Button closeButton; |
| | 30 | | [SerializeField] internal Button cancelButton; |
| | 31 | | [SerializeField] internal Button confirmButton; |
| | 32 | |
|
| | 33 | | private const string VIEW_PATH = "Common/BuildModeConfirmationModalView"; |
| | 34 | |
|
| | 35 | | internal static BuildModeConfirmationModalView Create() |
| | 36 | | { |
| 10 | 37 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<BuildModeConfirmationModalView>(); |
| 10 | 38 | | view.gameObject.name = "_ExitFromBiWModalView"; |
| | 39 | |
|
| 10 | 40 | | return view; |
| | 41 | | } |
| | 42 | |
|
| | 43 | | private void Awake() |
| | 44 | | { |
| 10 | 45 | | closeButton.onClick.AddListener(CancelExit); |
| 10 | 46 | | cancelButton.onClick.AddListener(CancelExit); |
| 10 | 47 | | confirmButton.onClick.AddListener(ConfirmExit); |
| 10 | 48 | | } |
| | 49 | |
|
| | 50 | | private void OnDestroy() |
| | 51 | | { |
| 10 | 52 | | closeButton.onClick.RemoveListener(CancelExit); |
| 10 | 53 | | cancelButton.onClick.RemoveListener(CancelExit); |
| 10 | 54 | | confirmButton.onClick.RemoveListener(ConfirmExit); |
| 10 | 55 | | } |
| | 56 | |
|
| 2 | 57 | | public bool IsActive() { return gameObject.activeSelf; } |
| | 58 | |
|
| 4 | 59 | | public void SetActive(bool isActive) { gameObject.SetActive(isActive); } |
| | 60 | |
|
| 2 | 61 | | public void SetTitle(string text) { title.text = text; } |
| | 62 | |
|
| 2 | 63 | | public void SetSubTitle(string text) { subTitle.text = text; } |
| | 64 | |
|
| 2 | 65 | | public void SetCancelButtonText(string text) { cancelButtonText.text = text; } |
| | 66 | |
|
| 2 | 67 | | public void SetConfirmButtonText(string text) { confirmButtonText.text = text; } |
| | 68 | |
|
| 2 | 69 | | public void CancelExit() { OnCancelExit?.Invoke(); } |
| | 70 | |
|
| 2 | 71 | | public void ConfirmExit() { OnConfirmExit?.Invoke(); } |
| | 72 | | } |