| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Builder; |
| | 5 | | using DCL.Interface; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | internal class UnpublishPopupController : IDisposable |
| | 9 | | { |
| | 10 | | private const string TITLE = "Unpublish Scene"; |
| | 11 | | private const string DESCRIPTION = "Are you sure you want to unpublish this scene?"; |
| | 12 | | private const string SUCCESS_DESCRIPTION = "Scene unpublished"; |
| | 13 | | private const string ERROR_TITLE = "Error"; |
| | 14 | | private const string PROGRESS_TITLE = "Unpublishing..."; |
| | 15 | |
|
| | 16 | | private IUnpublishPopupView view; |
| | 17 | | private Vector2Int coordinates; |
| | 18 | | private Scene.Source source; |
| | 19 | | private Coroutine fakeProgressRoutine = null; |
| | 20 | |
|
| 23 | 21 | | public UnpublishPopupController(IUnpublishPopupView view) |
| | 22 | | { |
| 23 | 23 | | this.view = view; |
| 23 | 24 | | view.OnCancelPressed += OnCancel; |
| 23 | 25 | | view.OnConfirmPressed += OnConfirmUnpublish; |
| 23 | 26 | | view.Hide(); |
| 23 | 27 | | } |
| | 28 | |
|
| | 29 | | public void Dispose() |
| | 30 | | { |
| 23 | 31 | | DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished; |
| 23 | 32 | | CoroutineStarter.Stop(fakeProgressRoutine); |
| 23 | 33 | | if (view != null) |
| | 34 | | { |
| 23 | 35 | | view.OnCancelPressed -= OnCancel; |
| 23 | 36 | | view.OnConfirmPressed -= OnConfirmUnpublish; |
| 23 | 37 | | view.Dispose(); |
| | 38 | | } |
| 23 | 39 | | } |
| | 40 | |
|
| | 41 | | public void Show(Vector2Int coordinates, Scene.Source source = Scene.Source.BUILDER_IN_WORLD) |
| | 42 | | { |
| 3 | 43 | | this.coordinates = coordinates; |
| 3 | 44 | | this.source = source; |
| 3 | 45 | | view.Show(TITLE, DESCRIPTION); |
| 3 | 46 | | } |
| | 47 | |
|
| | 48 | | void OnConfirmUnpublish() |
| | 49 | | { |
| 2 | 50 | | BIWAnalytics.PlayerUnpublishScene(source.ToString(), coordinates); |
| 2 | 51 | | DataStore.i.builderInWorld.unpublishSceneResult.OnChange += OnSceneUnpublished; |
| 2 | 52 | | WebInterface.UnpublishScene(coordinates); |
| 2 | 53 | | fakeProgressRoutine = CoroutineStarter.Start(ProgressRoutine()); |
| 2 | 54 | | } |
| | 55 | |
|
| | 56 | | void OnCancel() |
| | 57 | | { |
| 0 | 58 | | view.Hide(); |
| 0 | 59 | | CoroutineStarter.Stop(fakeProgressRoutine); |
| 0 | 60 | | } |
| | 61 | |
|
| | 62 | | IEnumerator ProgressRoutine() |
| | 63 | | { |
| 2 | 64 | | float progress = 0; |
| 0 | 65 | | while (true) |
| | 66 | | { |
| 2 | 67 | | progress = Mathf.Clamp(progress + UnityEngine.Random.Range(0.01f, 0.03f), 0, 0.99f); |
| 2 | 68 | | view.SetProgress(PROGRESS_TITLE, progress); |
| 2 | 69 | | yield return new WaitForSeconds(UnityEngine.Random.Range(0f, 0.5f)); |
| | 70 | | } |
| | 71 | | } |
| | 72 | |
|
| | 73 | | private void OnSceneUnpublished(PublishSceneResultPayload current, PublishSceneResultPayload previous) |
| | 74 | | { |
| 2 | 75 | | DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished; |
| 2 | 76 | | CoroutineStarter.Stop(fakeProgressRoutine); |
| | 77 | |
|
| 2 | 78 | | if (current.ok) |
| | 79 | | { |
| 1 | 80 | | view.SetSuccess(TITLE, SUCCESS_DESCRIPTION); |
| 1 | 81 | | } |
| | 82 | | else |
| | 83 | | { |
| 1 | 84 | | view.SetError(ERROR_TITLE, current.error); |
| | 85 | | } |
| 1 | 86 | | } |
| | 87 | | } |