| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | internal interface IUnpublishPopupView : IDisposable |
| | 7 | | { |
| | 8 | | event Action OnConfirmPressed; |
| | 9 | | event Action OnCancelPressed; |
| | 10 | | void Show(string title, string info); |
| | 11 | | void Hide(); |
| | 12 | | void SetProgress(string title, float progress); |
| | 13 | | void SetError(string title, string error); |
| | 14 | | void SetSuccess(string title, string info); |
| | 15 | | } |
| | 16 | |
|
| | 17 | | internal class UnpublishPopupView : MonoBehaviour, IUnpublishPopupView |
| | 18 | | { |
| | 19 | | [SerializeField] internal TextMeshProUGUI titleText; |
| | 20 | | [SerializeField] internal TextMeshProUGUI infoText; |
| | 21 | | [SerializeField] internal TextMeshProUGUI errorText; |
| | 22 | | [SerializeField] internal Button cancelButton; |
| | 23 | | [SerializeField] internal Button unpublishButton; |
| | 24 | | [SerializeField] internal Button doneButton; |
| | 25 | | [SerializeField] internal Button closeButton; |
| | 26 | | [SerializeField] internal GameObject loadingBarContainer; |
| | 27 | | [SerializeField] internal RectTransform loadingImageRT; |
| | 28 | | [SerializeField] internal TextMeshProUGUI loadingText; |
| | 29 | |
|
| | 30 | | public event Action OnConfirmPressed; |
| | 31 | | public event Action OnCancelPressed; |
| | 32 | |
|
| | 33 | | internal enum State |
| | 34 | | { |
| | 35 | | NONE, |
| | 36 | | CONFIRM_UNPUBLISH, |
| | 37 | | UNPUBLISHING, |
| | 38 | | DONE_UNPUBLISH, |
| | 39 | | ERROR_UNPUBLISH |
| | 40 | | } |
| | 41 | |
|
| 0 | 42 | | internal State state { private set; get; } = State.NONE; |
| | 43 | |
|
| | 44 | | private bool isDestroyed = false; |
| | 45 | | private float loadingImageFullWidth; |
| | 46 | |
|
| | 47 | | private void Awake() |
| | 48 | | { |
| 10 | 49 | | unpublishButton.onClick.AddListener(() => { OnConfirmPressed?.Invoke(); }); |
| 6 | 50 | | cancelButton.onClick.AddListener(() => { OnCancelPressed?.Invoke(); }); |
| 6 | 51 | | closeButton.onClick.AddListener(() => { OnCancelPressed?.Invoke(); }); |
| 6 | 52 | | doneButton.onClick.AddListener(() => { OnCancelPressed?.Invoke(); }); |
| 6 | 53 | | loadingImageFullWidth = loadingImageRT.rect.size.x; |
| 6 | 54 | | } |
| | 55 | |
|
| 12 | 56 | | private void OnDestroy() { isDestroyed = true; } |
| | 57 | |
|
| | 58 | | public void Dispose() |
| | 59 | | { |
| 23 | 60 | | if (gameObject == null) |
| 0 | 61 | | return; |
| | 62 | |
|
| 23 | 63 | | if (isDestroyed) |
| 0 | 64 | | return; |
| | 65 | |
|
| 23 | 66 | | Destroy(gameObject); |
| 23 | 67 | | } |
| | 68 | |
|
| | 69 | | void IUnpublishPopupView.Show(string title, string info) |
| | 70 | | { |
| 3 | 71 | | titleText.text = title; |
| 3 | 72 | | infoText.text = info; |
| 3 | 73 | | SetState(State.CONFIRM_UNPUBLISH); |
| 3 | 74 | | gameObject.SetActive(true); |
| 3 | 75 | | } |
| | 76 | |
|
| 46 | 77 | | void IUnpublishPopupView.Hide() { gameObject.SetActive(false); } |
| | 78 | |
|
| | 79 | | void IUnpublishPopupView.SetProgress(string title, float progress) |
| | 80 | | { |
| 4 | 81 | | titleText.text = title; |
| 4 | 82 | | loadingText.text = $"{Mathf.FloorToInt(100 * progress)}%"; |
| 4 | 83 | | loadingImageRT.sizeDelta = new Vector2(loadingImageFullWidth * progress, loadingImageRT.sizeDelta.y); |
| 4 | 84 | | SetState(State.UNPUBLISHING); |
| 4 | 85 | | } |
| | 86 | |
|
| | 87 | | void IUnpublishPopupView.SetError(string title, string error) |
| | 88 | | { |
| 2 | 89 | | titleText.text = title; |
| 2 | 90 | | errorText.text = error; |
| 2 | 91 | | SetState(State.ERROR_UNPUBLISH); |
| 2 | 92 | | } |
| | 93 | |
|
| | 94 | | void IUnpublishPopupView.SetSuccess(string title, string info) |
| | 95 | | { |
| 2 | 96 | | titleText.text = title; |
| 2 | 97 | | infoText.text = info; |
| 2 | 98 | | SetState(State.DONE_UNPUBLISH); |
| 2 | 99 | | } |
| | 100 | |
|
| | 101 | | private void SetState(State newState) |
| | 102 | | { |
| 11 | 103 | | if (state == newState) |
| 1 | 104 | | return; |
| | 105 | |
|
| 10 | 106 | | state = newState; |
| 10 | 107 | | switch (state) |
| | 108 | | { |
| | 109 | | case State.CONFIRM_UNPUBLISH: |
| 3 | 110 | | cancelButton.gameObject.SetActive(true); |
| 3 | 111 | | unpublishButton.gameObject.SetActive(true); |
| 3 | 112 | | doneButton.gameObject.SetActive(false); |
| 3 | 113 | | infoText.gameObject.SetActive(true); |
| 3 | 114 | | errorText.gameObject.SetActive(false); |
| 3 | 115 | | loadingBarContainer.SetActive(false); |
| 3 | 116 | | closeButton.gameObject.SetActive(true); |
| 3 | 117 | | break; |
| | 118 | | case State.UNPUBLISHING: |
| 3 | 119 | | cancelButton.gameObject.SetActive(false); |
| 3 | 120 | | unpublishButton.gameObject.SetActive(false); |
| 3 | 121 | | doneButton.gameObject.SetActive(false); |
| 3 | 122 | | infoText.gameObject.SetActive(false); |
| 3 | 123 | | errorText.gameObject.SetActive(false); |
| 3 | 124 | | loadingBarContainer.SetActive(true); |
| 3 | 125 | | closeButton.gameObject.SetActive(false); |
| 3 | 126 | | break; |
| | 127 | | case State.DONE_UNPUBLISH: |
| 2 | 128 | | cancelButton.gameObject.SetActive(false); |
| 2 | 129 | | unpublishButton.gameObject.SetActive(false); |
| 2 | 130 | | doneButton.gameObject.SetActive(true); |
| 2 | 131 | | infoText.gameObject.SetActive(true); |
| 2 | 132 | | errorText.gameObject.SetActive(false); |
| 2 | 133 | | loadingBarContainer.SetActive(false); |
| 2 | 134 | | closeButton.gameObject.SetActive(true); |
| 2 | 135 | | break; |
| | 136 | | case State.ERROR_UNPUBLISH: |
| 2 | 137 | | cancelButton.gameObject.SetActive(false); |
| 2 | 138 | | unpublishButton.gameObject.SetActive(false); |
| 2 | 139 | | doneButton.gameObject.SetActive(true); |
| 2 | 140 | | infoText.gameObject.SetActive(false); |
| 2 | 141 | | errorText.gameObject.SetActive(true); |
| 2 | 142 | | loadingBarContainer.SetActive(false); |
| 2 | 143 | | closeButton.gameObject.SetActive(true); |
| | 144 | | break; |
| | 145 | | } |
| 2 | 146 | | } |
| | 147 | | } |