| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public class NFTItemToggle : ItemToggle |
| | 6 | | { |
| | 7 | | [SerializeField] internal NFTItemInfo nftItemInfo; |
| | 8 | | [SerializeField] internal Image rarityImage; |
| | 9 | | [SerializeField] internal Button infoButton; |
| | 10 | | [SerializeField] internal Button closeInfoButton; |
| | 11 | | [SerializeField] internal Button sellButton; |
| | 12 | | [SerializeField] internal GameObject smartItemBadge; |
| | 13 | |
|
| | 14 | | private static event Action OnHideAllInfos; |
| | 15 | |
|
| | 16 | | protected override void Awake() |
| | 17 | | { |
| 846 | 18 | | base.Awake(); |
| | 19 | |
|
| 846 | 20 | | OnHideAllInfos += HideInfo; |
| | 21 | |
|
| 846 | 22 | | HideInfo(); |
| 846 | 23 | | infoButton.onClick.AddListener(ToggleInfo); |
| 846 | 24 | | closeInfoButton.onClick.AddListener(HideInfo); |
| 846 | 25 | | sellButton.onClick.AddListener(CallOnSellClicked); |
| 846 | 26 | | } |
| | 27 | |
|
| | 28 | | public override void Initialize(WearableItem w, bool isSelected, int amount, NFTItemToggleSkin skin) |
| | 29 | | { |
| 6447 | 30 | | base.Initialize(w, isSelected, amount, skin); |
| | 31 | |
|
| 6447 | 32 | | nftItemInfo.SetModel(NFTItemInfo.Model.FromWearableItem(wearableItem)); |
| 6447 | 33 | | smartItemBadge.SetActive(w.IsSmart()); |
| | 34 | |
|
| 6447 | 35 | | nftItemInfo.SetSkin(w.rarity, skin); |
| 6447 | 36 | | rarityImage.color = skin.backgroundColor; |
| 6447 | 37 | | rarityImage.gameObject.SetActive(!skin.isBase); |
| 6447 | 38 | | infoButton.gameObject.SetActive(w.IsCollectible()); |
| | 39 | |
|
| 6447 | 40 | | HideInfo(); |
| 6447 | 41 | | } |
| | 42 | |
|
| | 43 | | protected override void SetSelection(bool isSelected) |
| | 44 | | { |
| 11327 | 45 | | base.SetSelection(isSelected); |
| 11327 | 46 | | OnHideAllInfos?.Invoke(); |
| 10011 | 47 | | } |
| | 48 | |
|
| | 49 | | protected override void OnDestroy() |
| | 50 | | { |
| 846 | 51 | | OnHideAllInfos -= HideInfo; |
| 846 | 52 | | base.OnDestroy(); |
| 846 | 53 | | } |
| | 54 | |
|
| | 55 | | private void ShowInfo() |
| | 56 | | { |
| 0 | 57 | | if (!nftItemInfo.gameObject.activeSelf) |
| 0 | 58 | | AudioScriptableObjects.dialogOpen.Play(true); |
| | 59 | |
|
| 0 | 60 | | OnHideAllInfos?.Invoke(); |
| 0 | 61 | | nftItemInfo.SetActive(true); |
| 0 | 62 | | } |
| | 63 | |
|
| | 64 | | private void HideInfo() |
| | 65 | | { |
| 187491 | 66 | | if (nftItemInfo.gameObject.activeSelf) |
| 0 | 67 | | AudioScriptableObjects.dialogClose.Play(true); |
| | 68 | |
|
| 187491 | 69 | | nftItemInfo.SetActive(false); |
| 187491 | 70 | | } |
| | 71 | |
|
| | 72 | | private void ToggleInfo() |
| | 73 | | { |
| 0 | 74 | | if (nftItemInfo.gameObject.activeSelf) |
| | 75 | | { |
| 0 | 76 | | HideInfo(); |
| 0 | 77 | | } |
| | 78 | | else |
| | 79 | | { |
| 0 | 80 | | ShowInfo(); |
| | 81 | | } |
| 0 | 82 | | } |
| | 83 | | } |