| | 1 | | using System.Collections.Generic; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public class NFTIconComponentView : BaseComponentView, INFTIconComponentView, IComponentModelConfig<NFTIconComponentMode |
| | 7 | | { |
| | 8 | | private const string NAME_TYPE = "name"; |
| | 9 | | private const string PARCEL_TYPE = "parcel"; |
| | 10 | | private const string ESTATE_TYPE = "estate"; |
| | 11 | |
|
| | 12 | | [SerializeField] internal ButtonComponentView marketplaceButton; |
| | 13 | | [SerializeField] internal Button detailInfoButton; |
| | 14 | | [SerializeField] internal TMP_Text nftName; |
| | 15 | | [SerializeField] internal TMP_Text nftNameMarketPlace; |
| | 16 | | [SerializeField] internal GameObject marketplaceSection; |
| | 17 | | [SerializeField] internal GameObject outline; |
| | 18 | | [SerializeField] internal ImageComponentView nftImage; |
| | 19 | | [SerializeField] internal TMP_Text nftTextInsteadOfImage; |
| | 20 | | [SerializeField] internal ImageComponentView typeImage; |
| | 21 | | [SerializeField] internal Image backgroundImage; |
| | 22 | | [SerializeField] internal Image backgroundImageGradient; |
| | 23 | | [SerializeField] internal Image rarityBackgroundImage; |
| | 24 | | [SerializeField] internal NFTTypeIconsAndColors nftTypesIcons; |
| | 25 | | [SerializeField] internal NFTSkinFactory skinFactory; |
| | 26 | | [SerializeField] internal SizeOnHover sizeOnHoverComponent; |
| | 27 | | [SerializeField] internal Transform nftItemInfoPositionRightRef; |
| | 28 | | [SerializeField] internal Transform nftItemInfoPositionLeftRef; |
| | 29 | | [SerializeField] internal Sprite normalBackground; |
| | 30 | | [SerializeField] internal Sprite nameBackground; |
| | 31 | |
|
| | 32 | | [SerializeField] internal NFTIconComponentModel model; |
| | 33 | |
|
| 0 | 34 | | public Button.ButtonClickedEvent onMarketplaceButtonClick => marketplaceButton.onClick; |
| 0 | 35 | | public Button.ButtonClickedEvent onDetailInfoButtonClick => detailInfoButton.onClick; |
| | 36 | |
|
| | 37 | | private NFTItemInfo nftItemInfo; |
| | 38 | | private NFTItemInfo.Model nftItemInfoCurrentModel; |
| | 39 | | private bool showCategoryInfoOnNftItem; |
| | 40 | | private string nftItemInfoRarity; |
| 1 | 41 | | private static readonly List<string> landTypes = new () { PARCEL_TYPE, ESTATE_TYPE }; |
| 1 | 42 | | private static string nameType = NAME_TYPE; |
| 1 | 43 | | private static readonly Vector3 LAND_IMAGE_SCALE = new (5, 5, 5); |
| 1 | 44 | | private static readonly Vector3 NORMAL_IMAGE_SCALE = new (1, 1, 1); |
| | 45 | |
|
| | 46 | | public void Configure(NFTIconComponentModel newModel) |
| | 47 | | { |
| 0 | 48 | | if (model == newModel) |
| 0 | 49 | | return; |
| | 50 | |
|
| 0 | 51 | | model = newModel; |
| 0 | 52 | | RefreshControl(); |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | public override void RefreshControl() |
| | 56 | | { |
| 0 | 57 | | if (model == null) |
| 0 | 58 | | return; |
| | 59 | |
|
| 0 | 60 | | SetName(model.name); |
| 0 | 61 | | SetShowMarketplaceButton(model.showMarketplaceButton); |
| 0 | 62 | | SetMarketplaceURI(model.marketplaceURI); |
| 0 | 63 | | SetType(model.type); |
| 0 | 64 | | SetImageURI(model.imageURI); |
| 0 | 65 | | SetShowType(model.showType); |
| 0 | 66 | | SetRarity(model.rarity); |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public void SetName(string name) |
| | 70 | | { |
| 1 | 71 | | model.name = name; |
| | 72 | |
|
| 1 | 73 | | if (nftName != null) |
| 1 | 74 | | nftName.text = name; |
| | 75 | |
|
| 1 | 76 | | if(nftNameMarketPlace != null) |
| 1 | 77 | | nftNameMarketPlace.text = name; |
| 1 | 78 | | } |
| | 79 | |
|
| | 80 | | public void SetMarketplaceURI(string marketplaceURI) |
| | 81 | | { |
| 1 | 82 | | model.marketplaceURI = marketplaceURI; |
| 1 | 83 | | } |
| | 84 | |
|
| | 85 | | public void SetImageURI(string imageURI) |
| | 86 | | { |
| 0 | 87 | | model.imageURI = imageURI; |
| | 88 | |
|
| 0 | 89 | | if (nftImage != null) |
| | 90 | | { |
| 0 | 91 | | nftImage.gameObject.transform.localScale = landTypes.Contains(model.type) ? LAND_IMAGE_SCALE : NORMAL_IMAGE_ |
| | 92 | |
|
| 0 | 93 | | nftImage.SetImage(imageURI); |
| 0 | 94 | | nftImage.gameObject.SetActive(!string.IsNullOrEmpty(imageURI)); |
| | 95 | | } |
| | 96 | |
|
| 0 | 97 | | if (nftTextInsteadOfImage != null) |
| | 98 | | { |
| 0 | 99 | | nftTextInsteadOfImage.text = model.name; |
| 0 | 100 | | nftTextInsteadOfImage.gameObject.SetActive(string.IsNullOrEmpty(imageURI)); |
| | 101 | | } |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | public void SetShowType(bool showType) |
| | 105 | | { |
| 0 | 106 | | model.showType = showType; |
| | 107 | |
|
| 0 | 108 | | typeImage.gameObject.SetActive(showType); |
| 0 | 109 | | rarityBackgroundImage.gameObject.SetActive(showType); |
| 0 | 110 | | } |
| | 111 | |
|
| | 112 | | public void SetType(string type) |
| | 113 | | { |
| 0 | 114 | | model.type = type; |
| 0 | 115 | | typeImage.SetImage(nftTypesIcons.GetTypeImage(type)); |
| 0 | 116 | | } |
| | 117 | |
|
| | 118 | | public void SetRarity(string rarity) |
| | 119 | | { |
| 0 | 120 | | model.rarity = rarity; |
| 0 | 121 | | Color rarityColor = nftTypesIcons.GetColor(rarity); |
| | 122 | |
|
| 0 | 123 | | backgroundImage.sprite = model.type == nameType ? nameBackground : normalBackground; |
| 0 | 124 | | backgroundImageGradient.enabled = model.type != nameType; |
| 0 | 125 | | backgroundImage.color = model.type == nameType ? Color.white : new Color(rarityColor.r, rarityColor.g, rarityCol |
| 0 | 126 | | rarityBackgroundImage.color = rarityColor; |
| 0 | 127 | | } |
| | 128 | |
|
| | 129 | | public void SetShowMarketplaceButton(bool showMarketplaceButton) |
| | 130 | | { |
| 2 | 131 | | model.showMarketplaceButton = showMarketplaceButton; |
| 2 | 132 | | } |
| | 133 | |
|
| | 134 | | public override void OnFocus() |
| | 135 | | { |
| 1 | 136 | | if (sizeOnHoverComponent == null || !sizeOnHoverComponent.enabled) |
| 0 | 137 | | return; |
| | 138 | |
|
| 1 | 139 | | base.OnFocus(); |
| | 140 | |
|
| 1 | 141 | | SetNFTIconAsSelected(true); |
| 1 | 142 | | } |
| | 143 | |
|
| | 144 | | public override void OnLoseFocus() |
| | 145 | | { |
| 5 | 146 | | base.OnLoseFocus(); |
| | 147 | |
|
| 5 | 148 | | if (nftItemInfo == null || !nftItemInfo.gameObject.activeSelf) |
| 5 | 149 | | SetNFTIconAsSelected(false); |
| 5 | 150 | | } |
| | 151 | |
|
| | 152 | | public void ConfigureNFTItemInfo(NFTItemInfo nftItemInfoModal, WearableItem wearableItem, bool showCategoryInfo) |
| | 153 | | { |
| 0 | 154 | | nftItemInfo = nftItemInfoModal; |
| 0 | 155 | | nftItemInfo.OnCloseButtonClick.RemoveAllListeners(); |
| 0 | 156 | | nftItemInfo.OnCloseButtonClick.AddListener(() => SetNFTItemInfoActive(false)); |
| 0 | 157 | | nftItemInfoCurrentModel = NFTItemInfo.Model.FromWearableItem(wearableItem); |
| 0 | 158 | | showCategoryInfoOnNftItem = showCategoryInfo; |
| 0 | 159 | | nftItemInfoRarity = wearableItem.rarity; |
| 0 | 160 | | } |
| | 161 | |
|
| | 162 | | public void SetNFTItemInfoActive(bool isActive, bool showInLeftSide = false) |
| | 163 | | { |
| 0 | 164 | | SetNFTIconAsSelected(isActive); |
| 0 | 165 | | sizeOnHoverComponent.enabled = !isActive; |
| | 166 | |
|
| 0 | 167 | | if (nftItemInfo != null) |
| | 168 | | { |
| 0 | 169 | | nftItemInfo.SetActive(isActive); |
| | 170 | |
|
| 0 | 171 | | if (isActive) |
| | 172 | | { |
| 0 | 173 | | nftItemInfo.SetModel(nftItemInfoCurrentModel); |
| 0 | 174 | | nftItemInfo.SetSkin(nftItemInfoRarity, skinFactory.GetSkinForRarity(nftItemInfoRarity)); |
| 0 | 175 | | nftItemInfo.SetSellButtonActive(false); |
| 0 | 176 | | nftItemInfo.SetCategoryInfoActive(showCategoryInfoOnNftItem); |
| 0 | 177 | | nftItemInfo.transform.position = showInLeftSide ? nftItemInfoPositionLeftRef.position : nftItemInfoPosit |
| | 178 | | } |
| | 179 | | } |
| 0 | 180 | | } |
| | 181 | |
|
| | 182 | | private void SetNFTIconAsSelected(bool isSelected) |
| | 183 | | { |
| 6 | 184 | | if (!model.showMarketplaceButton) |
| 2 | 185 | | return; |
| | 186 | |
|
| 4 | 187 | | marketplaceSection.SetActive(isSelected); |
| 4 | 188 | | outline.SetActive(isSelected); |
| 4 | 189 | | } |
| | 190 | | } |