| | 1 | | using System.Collections; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | namespace DCL.Huds.QuestsTracker |
| | 8 | | { |
| | 9 | | public class QuestNotification_RewardObtained : MonoBehaviour, IQuestNotification |
| | 10 | | { |
| | 11 | | [SerializeField] internal TextMeshProUGUI rewardName; |
| | 12 | | [SerializeField] internal RawImage rewardImage; |
| | 13 | | [SerializeField] internal Button okButton; |
| | 14 | | [SerializeField] internal AudioEvent rewardObtainedAudioEvent; |
| | 15 | |
|
| | 16 | | private AssetPromise_Texture imagePromise; |
| | 17 | | private bool okPressed = false; |
| | 18 | |
|
| 0 | 19 | | private void Awake() { okButton.onClick.AddListener(() => okPressed = true); } |
| | 20 | |
|
| | 21 | | public void Populate(QuestReward reward) |
| | 22 | | { |
| 0 | 23 | | this.rewardName.text = reward.name; |
| 0 | 24 | | SetImage(reward.imageUrl); |
| 0 | 25 | | } |
| | 26 | |
|
| | 27 | | internal void SetImage(string itemImageURL) |
| | 28 | | { |
| 0 | 29 | | if (imagePromise != null) |
| | 30 | | { |
| 0 | 31 | | imagePromise.ClearEvents(); |
| 0 | 32 | | AssetPromiseKeeper_Texture.i.Forget(imagePromise); |
| | 33 | | } |
| | 34 | |
|
| 0 | 35 | | if (string.IsNullOrEmpty(itemImageURL)) |
| 0 | 36 | | return; |
| | 37 | |
|
| 0 | 38 | | imagePromise = new AssetPromise_Texture(itemImageURL); |
| 0 | 39 | | imagePromise.OnSuccessEvent += OnImageReady; |
| 0 | 40 | | imagePromise.OnFailEvent += (x, error) => { Debug.Log($"Error downloading reward image: {itemImageURL}, Exce |
| | 41 | |
|
| 0 | 42 | | AssetPromiseKeeper_Texture.i.Keep(imagePromise); |
| 0 | 43 | | } |
| | 44 | |
|
| 0 | 45 | | private void OnImageReady(Asset_Texture assetTexture) { rewardImage.texture = assetTexture.texture; } |
| | 46 | |
|
| | 47 | | public void Show() |
| | 48 | | { |
| 0 | 49 | | gameObject.SetActive(true); |
| 0 | 50 | | rewardObtainedAudioEvent.Play(); |
| 0 | 51 | | Utils.UnlockCursor(); |
| 0 | 52 | | } |
| | 53 | |
|
| 0 | 54 | | public void Dispose() { Destroy(gameObject); } |
| 0 | 55 | | public IEnumerator Waiter() { yield return new WaitUntil(() => okPressed); } |
| | 56 | | } |
| | 57 | | } |