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