| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using System; |
| | 3 | | using TMPro; |
| | 4 | | using UIComponents.Scripts.Components; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | | using DG.Tweening; |
| | 8 | | using System.Threading; |
| | 9 | |
|
| | 10 | | namespace DCL.Quests |
| | 11 | | { |
| | 12 | | public class QuestStartedPopupComponentView : BaseComponentView<QuestStartedPopupComponentModel>, IQuestStartedPopup |
| | 13 | | { |
| | 14 | | private const float FADE_DURATION = 0.167f; |
| | 15 | | private const float SHOW_HUD_TIME = 10f; |
| | 16 | |
|
| | 17 | | [SerializeField] internal TMP_Text questNameText; |
| | 18 | | [SerializeField] internal Button openQuestLogButton; |
| | 19 | | [SerializeField] internal CanvasGroup container; |
| | 20 | |
|
| | 21 | | public event Action OnOpenQuestLog; |
| | 22 | | internal bool visible = false; |
| | 23 | | private CancellationTokenSource cts; |
| | 24 | |
|
| | 25 | | public override void Awake() |
| | 26 | | { |
| 3 | 27 | | openQuestLogButton.onClick.RemoveAllListeners(); |
| 3 | 28 | | openQuestLogButton.onClick.AddListener(()=> |
| | 29 | | { |
| 1 | 30 | | SetVisible(false); |
| 1 | 31 | | OnOpenQuestLog?.Invoke(); |
| 1 | 32 | | }); |
| 3 | 33 | | container.alpha = 0; |
| 3 | 34 | | } |
| | 35 | |
|
| | 36 | | public override void RefreshControl() => |
| 0 | 37 | | SetQuestName(model.questName); |
| | 38 | |
|
| | 39 | | public void SetQuestName(string questName) |
| | 40 | | { |
| 1 | 41 | | model.questName = questName; |
| 1 | 42 | | questNameText.text = questName; |
| 1 | 43 | | } |
| | 44 | |
|
| | 45 | | public void SetVisible(bool setVisible) |
| | 46 | | { |
| 3 | 47 | | visible = setVisible; |
| | 48 | |
|
| 3 | 49 | | if (setVisible) |
| | 50 | | { |
| 1 | 51 | | Show(); |
| 1 | 52 | | cts?.Cancel(); |
| 1 | 53 | | cts?.Dispose(); |
| 1 | 54 | | cts = new CancellationTokenSource(); |
| 1 | 55 | | WaitAndHide(cts).Forget(); |
| | 56 | | } |
| | 57 | | else |
| 2 | 58 | | Hide(); |
| 2 | 59 | | } |
| | 60 | |
|
| | 61 | | private void Show() => |
| 1 | 62 | | container.DOFade(1, FADE_DURATION).SetEase(Ease.InOutQuad); |
| | 63 | |
|
| | 64 | | private void Hide() => |
| 2 | 65 | | container.DOFade(0, FADE_DURATION).SetEase(Ease.InOutQuad); |
| | 66 | |
|
| | 67 | | private async UniTaskVoid WaitAndHide(CancellationTokenSource ct) |
| | 68 | | { |
| 3 | 69 | | await UniTask.Delay(TimeSpan.FromSeconds(SHOW_HUD_TIME), cancellationToken: cts.Token); |
| 0 | 70 | | Hide(); |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | public override void Dispose() |
| | 74 | | { |
| 6 | 75 | | cts?.Cancel(); |
| 6 | 76 | | cts?.Dispose(); |
| 6 | 77 | | cts = null; |
| 6 | 78 | | } |
| | 79 | | } |
| | 80 | | } |