| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | | using UnityEngine.UI; |
| | 6 | | using TMPro; |
| | 7 | |
|
| | 8 | | public class NFTIconComponentView : BaseComponentView, INFTIconComponentView, IComponentModelConfig<NFTIconComponentMode |
| | 9 | | { |
| | 10 | |
|
| | 11 | | [SerializeField] internal ButtonComponentView marketplaceButton; |
| | 12 | | [SerializeField] internal TMP_Text nftName; |
| | 13 | | [SerializeField] internal TMP_Text nftNameMarketPlace; |
| | 14 | | [SerializeField] internal GameObject marketplaceSection; |
| | 15 | | [SerializeField] internal ImageComponentView nftImage; |
| | 16 | | [SerializeField] internal ImageComponentView typeImage; |
| | 17 | | [SerializeField] internal Image backgroundImage; |
| | 18 | | [SerializeField] internal Image rarityBackgroundImage; |
| | 19 | | [SerializeField] internal NFTTypeIconsAndColors nftTypesIcons; |
| | 20 | |
|
| | 21 | | [SerializeField] internal NFTIconComponentModel model; |
| | 22 | |
|
| 0 | 23 | | public Button.ButtonClickedEvent onMarketplaceButtonClick => marketplaceButton?.onClick; |
| | 24 | |
|
| | 25 | | public void Configure(NFTIconComponentModel newModel) |
| | 26 | | { |
| 0 | 27 | | if (model == newModel) |
| 0 | 28 | | return; |
| | 29 | |
|
| 0 | 30 | | model = newModel; |
| 0 | 31 | | RefreshControl(); |
| 0 | 32 | | } |
| | 33 | |
|
| | 34 | | public override void RefreshControl() |
| | 35 | | { |
| 0 | 36 | | if (model == null) |
| 0 | 37 | | return; |
| | 38 | |
|
| 0 | 39 | | SetName(model.name); |
| 0 | 40 | | SetShowMarketplaceButton(model.showMarketplaceButton); |
| 0 | 41 | | SetMarketplaceURI(model.marketplaceURI); |
| 0 | 42 | | SetImageURI(model.imageURI); |
| 0 | 43 | | SetShowType(model.showType); |
| 0 | 44 | | SetType(model.type); |
| 0 | 45 | | SetRarity(model.rarity); |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | public void SetName(string name) |
| | 49 | | { |
| 1 | 50 | | model.name = name; |
| | 51 | |
|
| 1 | 52 | | if (nftName != null) |
| 1 | 53 | | nftName.text = name; |
| | 54 | |
|
| 1 | 55 | | if(nftNameMarketPlace != null) |
| 1 | 56 | | nftNameMarketPlace.text = name; |
| 1 | 57 | | } |
| | 58 | |
|
| | 59 | | public void SetMarketplaceURI(string marketplaceURI) |
| | 60 | | { |
| 1 | 61 | | model.marketplaceURI = marketplaceURI; |
| 1 | 62 | | } |
| | 63 | |
|
| | 64 | | public void SetImageURI(string imageURI) |
| | 65 | | { |
| 0 | 66 | | model.imageURI = imageURI; |
| | 67 | |
|
| 0 | 68 | | nftImage.SetImage(imageURI); |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | public void SetShowType(bool showType) |
| | 72 | | { |
| 0 | 73 | | model.showType = showType; |
| | 74 | |
|
| 0 | 75 | | typeImage.gameObject.SetActive(showType); |
| 0 | 76 | | rarityBackgroundImage.gameObject.SetActive(showType); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | public void SetType(string type) |
| | 80 | | { |
| 0 | 81 | | model.type = type; |
| | 82 | |
|
| 0 | 83 | | typeImage.SetImage(nftTypesIcons.GetTypeImage(type)); |
| 0 | 84 | | } |
| | 85 | |
|
| | 86 | | public void SetRarity(string rarity) |
| | 87 | | { |
| 0 | 88 | | model.rarity = rarity; |
| 0 | 89 | | backgroundImage.color = nftTypesIcons.GetColor(rarity); |
| 0 | 90 | | rarityBackgroundImage.color = nftTypesIcons.GetColor(rarity); |
| 0 | 91 | | } |
| | 92 | |
|
| | 93 | | public void SetShowMarketplaceButton(bool showMarketplaceButton) |
| | 94 | | { |
| 2 | 95 | | model.showMarketplaceButton = showMarketplaceButton; |
| 2 | 96 | | } |
| | 97 | |
|
| | 98 | | public override void OnFocus() |
| | 99 | | { |
| 1 | 100 | | base.OnFocus(); |
| | 101 | |
|
| 1 | 102 | | if (!model.showMarketplaceButton) |
| 0 | 103 | | return; |
| | 104 | |
|
| 1 | 105 | | marketplaceSection.SetActive(true); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | public override void OnLoseFocus() |
| | 109 | | { |
| 5 | 110 | | base.OnLoseFocus(); |
| | 111 | |
|
| 5 | 112 | | if (!model.showMarketplaceButton) |
| 2 | 113 | | return; |
| | 114 | |
|
| 3 | 115 | | marketplaceSection.SetActive(false); |
| 3 | 116 | | } |
| | 117 | |
|
| | 118 | | } |