| | 1 | | using DCL; |
| | 2 | | using DCL.EmotesCustomization; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Linq; |
| | 7 | | using TMPro; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | public class NFTItemInfo : MonoBehaviour |
| | 12 | | { |
| | 13 | | [Serializable] |
| | 14 | | internal class IconToGameObjectMap |
| | 15 | | { |
| | 16 | | public string iconId; |
| | 17 | | public GameObject gameObject; |
| | 18 | | } |
| | 19 | |
|
| | 20 | | public class Model |
| | 21 | | { |
| | 22 | | public string name; |
| | 23 | | public string thumbnail; |
| | 24 | | public Sprite thumbnailSprite; |
| | 25 | | public List<string> iconIds; |
| | 26 | | public string description; |
| | 27 | | public int issuedId; |
| | 28 | | public int issuedTotal; |
| | 29 | | public bool isInL2; |
| | 30 | |
|
| | 31 | | public bool Equals(Model other) |
| | 32 | | { |
| 5089 | 33 | | return name == other.name |
| | 34 | | && thumbnail == other.thumbnail |
| | 35 | | && thumbnailSprite == other.thumbnailSprite |
| | 36 | | && iconIds.SequenceEqual(other.iconIds) |
| | 37 | | && description == other.description |
| | 38 | | && issuedId == other.issuedId |
| | 39 | | && issuedTotal == other.issuedTotal; |
| | 40 | | } |
| | 41 | |
|
| | 42 | | public static Model FromWearableItem(WearableItem wearable) |
| | 43 | | { |
| 13768 | 44 | | var iconsIds = wearable.data.representations.SelectMany(x => x.bodyShapes).ToList(); |
| 6447 | 45 | | iconsIds.Add(wearable.data.category); |
| | 46 | |
|
| 6447 | 47 | | return new Model() |
| | 48 | | { |
| | 49 | | name = wearable.GetName(), |
| | 50 | | thumbnail = wearable.baseUrl + wearable.thumbnail, |
| | 51 | | thumbnailSprite = wearable.thumbnailSprite, |
| | 52 | | iconIds = iconsIds, |
| | 53 | | description = wearable.description, |
| | 54 | | issuedId = wearable.issuedId, |
| | 55 | | issuedTotal = wearable.GetIssuedCountFromRarity(wearable.rarity), |
| | 56 | | isInL2 = wearable.IsInL2() |
| | 57 | | }; |
| | 58 | | } |
| | 59 | |
|
| | 60 | | public static Model FromEmoteItem(EmoteCardComponentModel emote) |
| | 61 | | { |
| 1 | 62 | | return new Model |
| | 63 | | { |
| | 64 | | name = emote.name, |
| | 65 | | thumbnail = emote.pictureUri, |
| | 66 | | thumbnailSprite = emote.pictureSprite, |
| | 67 | | iconIds = new List<string>(), |
| | 68 | | description = emote.description, |
| | 69 | | issuedId = 1, |
| | 70 | | issuedTotal = int.MaxValue, |
| | 71 | | isInL2 = emote.isInL2 |
| | 72 | | }; |
| | 73 | | } |
| | 74 | | } |
| | 75 | |
|
| | 76 | | [SerializeField] internal TextMeshProUGUI name; |
| | 77 | | [SerializeField] internal Image thumbnail; |
| | 78 | | [SerializeField] internal IconToGameObjectMap[] icons; |
| | 79 | | [SerializeField] internal TextMeshProUGUI description; |
| | 80 | | [SerializeField] internal TextMeshProUGUI minted; |
| | 81 | | [SerializeField] internal GameObject ethNetwork; |
| | 82 | | [SerializeField] internal GameObject l2Network; |
| | 83 | | [SerializeField] internal Image backgroundImage; |
| | 84 | | [SerializeField] internal Image gradientImage; |
| | 85 | | [SerializeField] internal TextMeshProUGUI rarityName; |
| | 86 | | [SerializeField] internal Button sellButton; |
| | 87 | | [SerializeField] internal Button closeButton; |
| | 88 | |
|
| | 89 | | private Model currentModel; |
| | 90 | | public void SetSkin(string rarityName, NFTItemToggleSkin skin) |
| | 91 | | { |
| 6447 | 92 | | this.rarityName.text = rarityName; |
| 6447 | 93 | | this.rarityName.color = skin.rarityNameColor; |
| 6447 | 94 | | backgroundImage.color = skin.backgroundColor; |
| 6447 | 95 | | gradientImage.color = skin.gradientColor; |
| | 96 | |
|
| 6447 | 97 | | } |
| | 98 | |
|
| | 99 | | public void SetModel(Model newModel) |
| | 100 | | { |
| 6448 | 101 | | if (newModel == null) |
| 0 | 102 | | return; |
| | 103 | |
|
| 6448 | 104 | | if (currentModel != null && newModel.Equals(currentModel)) |
| 5089 | 105 | | return; |
| | 106 | |
|
| 1359 | 107 | | currentModel = newModel; |
| | 108 | |
|
| 1359 | 109 | | name.text = currentModel.name; |
| | 110 | |
|
| 48924 | 111 | | foreach (var icon in icons) |
| | 112 | | { |
| 23103 | 113 | | icon.gameObject.SetActive(currentModel.iconIds.Contains(icon.iconId)); |
| | 114 | | } |
| | 115 | |
|
| 1359 | 116 | | if (!string.IsNullOrEmpty(currentModel.description)) |
| 37 | 117 | | description.text = currentModel.description; |
| | 118 | | else |
| 1322 | 119 | | description.text = "No description."; |
| | 120 | |
|
| 1359 | 121 | | minted.text = $"{currentModel.issuedId} / {currentModel.issuedTotal}"; |
| | 122 | |
|
| 1359 | 123 | | Utils.InverseTransformChildTraversal<LayoutGroup>((x) => |
| | 124 | | { |
| 12231 | 125 | | RectTransform rt = x.transform as RectTransform; |
| 12231 | 126 | | Utils.ForceRebuildLayoutImmediate(rt); |
| 12231 | 127 | | }, transform); |
| | 128 | |
|
| | 129 | |
|
| 1359 | 130 | | ethNetwork.SetActive(!currentModel.isInL2); |
| 1359 | 131 | | l2Network.SetActive(currentModel.isInL2); |
| | 132 | |
|
| 1359 | 133 | | if (gameObject.activeInHierarchy) |
| 0 | 134 | | GetThumbnail(); |
| 1359 | 135 | | } |
| | 136 | |
|
| 375026 | 137 | | public void SetActive(bool active) { gameObject.SetActive(active); } |
| | 138 | |
|
| | 139 | | public void SetBackgroundColor(Color color) |
| | 140 | | { |
| 1 | 141 | | if (backgroundImage == null) |
| 0 | 142 | | return; |
| | 143 | |
|
| 1 | 144 | | backgroundImage.color = color; |
| 1 | 145 | | } |
| | 146 | |
|
| | 147 | | public void SetRarityName(string name) |
| | 148 | | { |
| 1 | 149 | | if (rarityName == null) |
| 0 | 150 | | return; |
| | 151 | |
|
| 1 | 152 | | rarityName.text = name; |
| 1 | 153 | | } |
| | 154 | |
|
| | 155 | | private void UpdateItemThumbnail(Asset_Texture texture) |
| | 156 | | { |
| 0 | 157 | | thumbnail.sprite = ThumbnailsManager.GetOrCreateSpriteFromTexture(texture.texture, out _); |
| 0 | 158 | | thumbnail.preserveAspect = true; |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | private void GetThumbnail() |
| | 162 | | { |
| 3 | 163 | | if (currentModel == null) |
| 2 | 164 | | return; |
| | 165 | |
|
| 1 | 166 | | if (currentModel.thumbnailSprite != null) |
| | 167 | | { |
| 1 | 168 | | thumbnail.sprite = currentModel.thumbnailSprite; |
| 1 | 169 | | return; |
| | 170 | | } |
| | 171 | |
|
| 0 | 172 | | ThumbnailsManager.GetThumbnail(currentModel.thumbnail, UpdateItemThumbnail); |
| 0 | 173 | | } |
| | 174 | |
|
| 6 | 175 | | private void OnEnable() { GetThumbnail(); } |
| | 176 | | } |