| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCL.Builder |
| | 9 | | { |
| | 10 | | public interface IPublishProjectProgressView |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// This action will be called when the confirm button is pressed |
| | 14 | | /// </summary> |
| | 15 | | event Action OnPublishConfirmButtonPressed; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// This action will be called when the view is closed |
| | 19 | | /// </summary> |
| | 20 | | event Action OnViewClosed; |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Show the confirm publish pop up |
| | 24 | | /// </summary> |
| | 25 | | void ShowConfirmPopUp(); |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Call this function when the publish start |
| | 29 | | /// </summary> |
| | 30 | | void PublishStarted(); |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Hide the view |
| | 34 | | /// </summary> |
| | 35 | | void Hide(); |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Shows the errors passes in a pop up |
| | 39 | | /// </summary> |
| | 40 | | /// <param name="message"></param> |
| | 41 | | void PublishError(string message); |
| | 42 | |
|
| | 43 | | /// <summary> |
| | 44 | | /// Dispose the view |
| | 45 | | /// </summary> |
| | 46 | | void Dispose(); |
| | 47 | | } |
| | 48 | |
|
| | 49 | | public class PublishProjectProgressView : BaseComponentView, IPublishProjectProgressView |
| | 50 | | { |
| | 51 | | public event Action OnPublishConfirmButtonPressed; |
| | 52 | | public event Action OnViewClosed; |
| | 53 | |
|
| | 54 | | [SerializeField] internal Button closeButton; |
| | 55 | | [SerializeField] internal Button cancelButton; |
| | 56 | | [SerializeField] internal Button publishButton; |
| | 57 | | [SerializeField] internal TMP_Text errorTextView; |
| | 58 | |
|
| | 59 | | [SerializeField] internal ModalComponentView modal; |
| | 60 | |
|
| | 61 | | [SerializeField] internal GameObject errorGameObject; |
| | 62 | | [SerializeField] internal GameObject confirmGameObject; |
| | 63 | | [SerializeField] internal GameObject progressGameObject; |
| | 64 | |
|
| | 65 | | [SerializeField] internal LoadingBar loadingBar; |
| | 66 | |
|
| | 67 | | private float currentProgress = 0; |
| | 68 | |
|
| | 69 | | private Coroutine fakeProgressCoroutine; |
| | 70 | |
|
| | 71 | | public override void Awake() |
| | 72 | | { |
| 0 | 73 | | base.Awake(); |
| 0 | 74 | | closeButton.onClick.AddListener(Close); |
| 0 | 75 | | cancelButton.onClick.AddListener(Close); |
| 0 | 76 | | publishButton.onClick.AddListener(ConfirmPublish); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | public override void Dispose() |
| | 80 | | { |
| 0 | 81 | | base.Dispose(); |
| 0 | 82 | | closeButton.onClick.RemoveAllListeners(); |
| 0 | 83 | | cancelButton.onClick.RemoveAllListeners(); |
| 0 | 84 | | publishButton.onClick.RemoveAllListeners(); |
| | 85 | |
|
| 0 | 86 | | if (fakeProgressCoroutine != null) |
| 0 | 87 | | StopCoroutine(fakeProgressCoroutine); |
| 0 | 88 | | } |
| | 89 | |
|
| 0 | 90 | | public override void RefreshControl() { } |
| | 91 | |
|
| | 92 | | public void ShowConfirmPopUp() |
| | 93 | | { |
| 0 | 94 | | modal.Show(); |
| 0 | 95 | | errorGameObject.SetActive(false); |
| 0 | 96 | | confirmGameObject.SetActive(true); |
| 0 | 97 | | progressGameObject.SetActive(false); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | public void Close() |
| | 101 | | { |
| 0 | 102 | | modal.Hide(); |
| 0 | 103 | | OnViewClosed?.Invoke(); |
| 0 | 104 | | } |
| | 105 | |
|
| 0 | 106 | | public void ConfirmPublish() { OnPublishConfirmButtonPressed?.Invoke(); } |
| | 107 | |
|
| | 108 | | public void PublishStarted() |
| | 109 | | { |
| 0 | 110 | | currentProgress = 0; |
| | 111 | |
|
| 0 | 112 | | Show(); |
| 0 | 113 | | loadingBar.SetActive(true); |
| 0 | 114 | | errorGameObject.SetActive(false); |
| 0 | 115 | | confirmGameObject.SetActive(false); |
| 0 | 116 | | if (fakeProgressCoroutine != null) |
| 0 | 117 | | StopCoroutine(fakeProgressCoroutine); |
| 0 | 118 | | fakeProgressCoroutine = StartCoroutine(FakePublishProgress()); |
| 0 | 119 | | AudioScriptableObjects.enable.Play(); |
| 0 | 120 | | } |
| | 121 | |
|
| 0 | 122 | | public void Hide() { modal.Hide(); } |
| | 123 | |
|
| | 124 | | public void PublishError(string message) |
| | 125 | | { |
| 0 | 126 | | loadingBar.SetActive(false); |
| 0 | 127 | | errorGameObject.SetActive(true); |
| 0 | 128 | | confirmGameObject.SetActive(false); |
| | 129 | |
|
| 0 | 130 | | errorTextView.text = message; |
| 0 | 131 | | } |
| | 132 | |
|
| 0 | 133 | | public void SetPercentage(float newValue) { loadingBar.SetPercentage(newValue); } |
| | 134 | |
|
| | 135 | | private IEnumerator FakePublishProgress() |
| | 136 | | { |
| 0 | 137 | | while (true) |
| | 138 | | { |
| 0 | 139 | | float newPercentage = Mathf.Clamp( |
| | 140 | | currentProgress + UnityEngine.Random.Range(1f, 10f), |
| | 141 | | currentProgress, |
| | 142 | | 99f); |
| | 143 | |
|
| 0 | 144 | | SetPercentage(newPercentage); |
| | 145 | |
|
| 0 | 146 | | yield return new WaitForSeconds(UnityEngine.Random.Range(0f, 0.5f)); |
| | 147 | | } |
| | 148 | | } |
| | 149 | | } |
| | 150 | | } |