| | 1 | | using DCL.Helpers; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UIComponents.Scripts.Components; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | |
|
| | 9 | | namespace DCL.Backpack |
| | 10 | | { |
| | 11 | | public class InfoCardComponentView : BaseComponentView<InfoCardComponentModel>, IInfoCardComponentView |
| | 12 | | { |
| | 13 | | [SerializeField] internal NftTypeIconSO typeIcons; |
| | 14 | | [SerializeField] internal NftRarityBackgroundSO rarityBackgrounds; |
| | 15 | | [SerializeField] internal NftRarityBackgroundSO rarityNftBackgrounds; |
| | 16 | | [SerializeField] internal TMP_Text wearableName; |
| | 17 | | [SerializeField] internal TMP_Text wearableDescription; |
| | 18 | | [SerializeField] internal Image categoryImage; |
| | 19 | | [SerializeField] internal Button equipButton; |
| | 20 | | [SerializeField] internal Button unEquipButton; |
| | 21 | | [SerializeField] internal Button viewMore; |
| | 22 | | [SerializeField] internal Image background; |
| | 23 | | [SerializeField] internal Image nftBackground; |
| | 24 | | [SerializeField] internal ImageComponentView nftImage; |
| | 25 | | [SerializeField] internal RectTransform dynamicSection; |
| | 26 | | [SerializeField] internal DynamicListComponentView hidesList; |
| | 27 | | [SerializeField] internal DynamicListComponentView hiddenByDynamicList; |
| | 28 | | [SerializeField] internal Image vrmBlockedTag; |
| | 29 | |
|
| | 30 | | public event Action OnEquipWearable; |
| | 31 | | public event Action OnUnEquipWearable; |
| | 32 | | public event Action OnViewMore; |
| | 33 | |
|
| 1 | 34 | | internal InfoCardComponentModel Model => model; |
| | 35 | |
|
| | 36 | | public void Start() |
| | 37 | | { |
| 2 | 38 | | equipButton.onClick.RemoveAllListeners(); |
| 2 | 39 | | equipButton.onClick.AddListener(() => OnEquipWearable?.Invoke()); |
| 2 | 40 | | unEquipButton.onClick.RemoveAllListeners(); |
| 2 | 41 | | unEquipButton.onClick.AddListener(() => OnUnEquipWearable?.Invoke()); |
| 2 | 42 | | viewMore.onClick.RemoveAllListeners(); |
| 2 | 43 | | viewMore.onClick.AddListener(() => OnViewMore?.Invoke()); |
| 2 | 44 | | } |
| | 45 | |
|
| | 46 | | public override void RefreshControl() |
| | 47 | | { |
| 1 | 48 | | if (model == null) |
| 0 | 49 | | return; |
| | 50 | |
|
| 1 | 51 | | SetName(model.name); |
| 1 | 52 | | SetDescription(model.description); |
| 1 | 53 | | SetCategory(model.category); |
| 1 | 54 | | SetRarity(model.rarity); |
| 1 | 55 | | SetIsEquipped(model.isEquipped); |
| 1 | 56 | | SetRemovesList(model.removeList); |
| 1 | 57 | | SetHidesList(model.hideList); |
| 1 | 58 | | SetHiddenBy(model.hiddenBy); |
| 1 | 59 | | SetNftImage(model.imageUri); |
| 1 | 60 | | SetWearableId(model.wearableId); |
| 1 | 61 | | SetVRMBlockedTag(model.blockVrmExport); |
| 1 | 62 | | } |
| | 63 | |
|
| | 64 | | private void SetVRMBlockedTag(bool vrmBlocked) |
| | 65 | | { |
| 1 | 66 | | vrmBlockedTag.gameObject.SetActive(vrmBlocked); |
| 1 | 67 | | } |
| | 68 | |
|
| | 69 | | public void SetName(string nameText) |
| | 70 | | { |
| 2 | 71 | | model.name = nameText; |
| 2 | 72 | | wearableName.text = nameText; |
| 2 | 73 | | } |
| | 74 | |
|
| | 75 | | public void SetDescription(string description) |
| | 76 | | { |
| 2 | 77 | | model.description = description; |
| 2 | 78 | | wearableDescription.text = description; |
| 2 | 79 | | } |
| | 80 | |
|
| | 81 | | public void SetCategory(string category) |
| | 82 | | { |
| 2 | 83 | | model.category = category; |
| | 84 | |
|
| 2 | 85 | | var categoryIcon = typeIcons.GetTypeImage(category); |
| 2 | 86 | | if (categoryIcon == null) |
| 0 | 87 | | return; |
| | 88 | |
|
| 2 | 89 | | categoryImage.sprite = categoryIcon; |
| 2 | 90 | | } |
| | 91 | |
|
| | 92 | | public void SetNftImage(string imageUri) |
| | 93 | | { |
| 1 | 94 | | model.imageUri = imageUri; |
| | 95 | |
|
| 1 | 96 | | if (string.IsNullOrEmpty(imageUri)) |
| | 97 | | { |
| 1 | 98 | | nftImage.SetImage(Texture2D.grayTexture); |
| 1 | 99 | | return; |
| | 100 | | } |
| | 101 | |
|
| 0 | 102 | | nftImage.SetImage(imageUri); |
| 0 | 103 | | } |
| | 104 | |
|
| | 105 | | public void SetRarity(string rarity) |
| | 106 | | { |
| 1 | 107 | | model.rarity = rarity; |
| 1 | 108 | | background.sprite = rarityBackgrounds.GetRarityImage(rarity); |
| 1 | 109 | | nftBackground.sprite = rarityNftBackgrounds.GetRarityImage(rarity); |
| 1 | 110 | | } |
| | 111 | |
|
| | 112 | | public void SetHidesList(List<string> hideList) |
| | 113 | | { |
| 1 | 114 | | model.hideList = hideList; |
| 1 | 115 | | hidesList.RemoveIcons(); |
| | 116 | |
|
| 1 | 117 | | hidesList.gameObject.SetActive(hideList.Count != 0); |
| 4 | 118 | | foreach (string hideCategory in hideList) |
| | 119 | | { |
| 1 | 120 | | var categoryIcon = typeIcons.GetTypeImage(hideCategory); |
| 1 | 121 | | if (categoryIcon == null) |
| | 122 | | continue; |
| | 123 | |
|
| 1 | 124 | | hidesList.AddIcon(categoryIcon); |
| | 125 | | } |
| | 126 | |
|
| 1 | 127 | | Utils.ForceRebuildLayoutImmediate(dynamicSection); |
| 1 | 128 | | } |
| | 129 | |
|
| | 130 | | public void SetRemovesList(List<string> removeList) |
| | 131 | | { |
| 1 | 132 | | model.removeList = removeList; |
| 1 | 133 | | } |
| | 134 | |
|
| | 135 | | public void SetIsEquipped(bool isEquipped) |
| | 136 | | { |
| 1 | 137 | | model.isEquipped = isEquipped; |
| | 138 | |
|
| 1 | 139 | | equipButton.gameObject.SetActive(!isEquipped); |
| 1 | 140 | | unEquipButton.gameObject.SetActive(model.unEquipAllowed && isEquipped); |
| 1 | 141 | | } |
| | 142 | |
|
| | 143 | | private void SetWearableId(string wearableId) |
| | 144 | | { |
| 1 | 145 | | model.wearableId = wearableId; |
| 1 | 146 | | } |
| | 147 | |
|
| | 148 | | public void Equip(string wearableId) |
| | 149 | | { |
| 3 | 150 | | if(model.wearableId == wearableId) |
| 0 | 151 | | SetIsEquipped(true); |
| 3 | 152 | | } |
| | 153 | |
|
| | 154 | | public void UnEquip(string wearableId) |
| | 155 | | { |
| 7 | 156 | | if(model.wearableId == wearableId) |
| 0 | 157 | | SetIsEquipped(false); |
| 7 | 158 | | } |
| | 159 | |
|
| | 160 | | public void SetHiddenBy(string hiddenBy) |
| | 161 | | { |
| 1 | 162 | | model.hiddenBy = hiddenBy; |
| | 163 | |
|
| 1 | 164 | | if (string.IsNullOrEmpty(hiddenBy)) |
| | 165 | | { |
| 0 | 166 | | hiddenByDynamicList.gameObject.SetActive(false); |
| 0 | 167 | | return; |
| | 168 | | } |
| | 169 | |
|
| 1 | 170 | | hiddenByDynamicList.gameObject.SetActive(true); |
| 1 | 171 | | hiddenByDynamicList.RemoveIcons(); |
| | 172 | |
|
| 1 | 173 | | var categoryIcon = typeIcons.GetTypeImage(hiddenBy); |
| 1 | 174 | | if (categoryIcon == null) |
| 0 | 175 | | return; |
| | 176 | |
|
| 1 | 177 | | hiddenByDynamicList.AddIcon(categoryIcon); |
| 1 | 178 | | } |
| | 179 | |
|
| | 180 | | public void SetVisible(bool visible) => |
| 40 | 181 | | gameObject.SetActive(visible); |
| | 182 | | } |
| | 183 | | } |