| | 1 | | using DCL.Quests; |
| | 2 | | using System; |
| | 3 | | using System.Text; |
| | 4 | | using TMPro; |
| | 5 | | using UIComponents.Scripts.Components; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | |
|
| | 9 | | public class QuestRewardComponentView : BaseComponentView<QuestRewardComponentModel>, IQuestRewardComponentView |
| | 10 | | { |
| | 11 | | private const string MESSAGE = "{0} remaining"; |
| | 12 | |
|
| | 13 | | [SerializeField] internal TMP_Text rewardName; |
| | 14 | | [SerializeField] internal TMP_Text rewardQuantity; |
| | 15 | | [SerializeField] internal Image typeImage; |
| | 16 | | [SerializeField] internal ImageComponentView nftImage; |
| | 17 | | [SerializeField] internal NFTTypeIconsAndColors nftTypesIcons; |
| | 18 | | [SerializeField] private Image backgroundImage; |
| | 19 | | [SerializeField] private Image rarityBackgroundImage; |
| | 20 | |
|
| 92 | 21 | | private readonly StringBuilder sb = new StringBuilder(); |
| | 22 | |
|
| | 23 | | public override void RefreshControl() |
| | 24 | | { |
| 6 | 25 | | SetName(model.name); |
| 6 | 26 | | SetQuantity(model.quantity); |
| 6 | 27 | | SetType(model.type); |
| 6 | 28 | | SetRarity(model.rarity); |
| 6 | 29 | | SetImage(model.imageUri); |
| 6 | 30 | | } |
| | 31 | |
|
| | 32 | | public void SetName(string name) |
| | 33 | | { |
| 7 | 34 | | model.name = name; |
| 7 | 35 | | rewardName.text = name; |
| 7 | 36 | | } |
| | 37 | |
|
| | 38 | | public void SetQuantity(int quantity) |
| | 39 | | { |
| 8 | 40 | | model.quantity = quantity; |
| 8 | 41 | | sb.Clear(); |
| 8 | 42 | | sb.AppendFormat(MESSAGE, quantity); |
| 8 | 43 | | rewardQuantity.text = quantity <= 999 ? sb.ToString() : ">999 remaining"; |
| 8 | 44 | | } |
| | 45 | |
|
| | 46 | | public void SetType(string type) |
| | 47 | | { |
| 6 | 48 | | model.type = type; |
| 6 | 49 | | typeImage.sprite = nftTypesIcons.GetTypeImage(type); |
| 6 | 50 | | } |
| | 51 | |
|
| | 52 | | public void SetRarity(string rarity) |
| | 53 | | { |
| 6 | 54 | | model.rarity = rarity; |
| 6 | 55 | | Color rarityColor = nftTypesIcons.GetColor(rarity); |
| 6 | 56 | | backgroundImage.color = new Color(rarityColor.r, rarityColor.g, rarityColor.b, 1f); |
| 6 | 57 | | rarityBackgroundImage.color = rarityColor; |
| 6 | 58 | | } |
| | 59 | |
|
| | 60 | | public void SetImage(string imageUri) |
| | 61 | | { |
| 6 | 62 | | model.imageUri = imageUri; |
| 6 | 63 | | nftImage.SetImage(imageUri); |
| 6 | 64 | | } |
| | 65 | | } |