| | 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 Button infoButton; |
| | 9 | | [SerializeField] internal Button closeInfoButton; |
| | 10 | | [SerializeField] internal Button sellButton; |
| | 11 | | [SerializeField] internal GameObject smartItemBadge; |
| | 12 | |
|
| | 13 | | private static event Action OnHideAllInfos; |
| | 14 | |
|
| | 15 | | protected override void Awake() |
| | 16 | | { |
| 18 | 17 | | base.Awake(); |
| | 18 | |
|
| 18 | 19 | | OnHideAllInfos += HideInfo; |
| | 20 | |
|
| 18 | 21 | | HideInfo(); |
| 18 | 22 | | infoButton.onClick.AddListener(ToggleInfo); |
| 18 | 23 | | closeInfoButton.onClick.AddListener(HideInfo); |
| 18 | 24 | | sellButton.onClick.AddListener(CallOnSellClicked); |
| 18 | 25 | | } |
| | 26 | |
|
| | 27 | | public override void Initialize(WearableItem w, bool isSelected, int amount) |
| | 28 | | { |
| 36 | 29 | | base.Initialize(w, isSelected, amount); |
| 36 | 30 | | nftItemInfo.SetModel(NFTItemInfo.Model.FromWearableItem(wearableItem)); |
| 36 | 31 | | smartItemBadge.SetActive(w.IsSmart()); |
| 36 | 32 | | } |
| | 33 | |
|
| | 34 | | protected override void SetSelection(bool isSelected) |
| | 35 | | { |
| 56 | 36 | | base.SetSelection(isSelected); |
| 56 | 37 | | OnHideAllInfos?.Invoke(); |
| 38 | 38 | | } |
| | 39 | |
|
| | 40 | | protected override void OnDestroy() |
| | 41 | | { |
| 18 | 42 | | OnHideAllInfos -= HideInfo; |
| 18 | 43 | | base.OnDestroy(); |
| 18 | 44 | | } |
| | 45 | |
|
| | 46 | | private void ShowInfo() |
| | 47 | | { |
| 0 | 48 | | if (!nftItemInfo.gameObject.activeSelf) |
| 0 | 49 | | AudioScriptableObjects.dialogOpen.Play(true); |
| | 50 | |
|
| 0 | 51 | | OnHideAllInfos?.Invoke(); |
| 0 | 52 | | nftItemInfo.SetActive(true); |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | private void HideInfo() |
| | 56 | | { |
| 56 | 57 | | if (nftItemInfo.gameObject.activeSelf) |
| 18 | 58 | | AudioScriptableObjects.dialogClose.Play(true); |
| | 59 | |
|
| 56 | 60 | | nftItemInfo.SetActive(false); |
| 56 | 61 | | } |
| | 62 | |
|
| | 63 | | private void ToggleInfo() |
| | 64 | | { |
| 0 | 65 | | if (nftItemInfo.gameObject.activeSelf) |
| | 66 | | { |
| 0 | 67 | | HideInfo(); |
| 0 | 68 | | } |
| | 69 | | else |
| | 70 | | { |
| 0 | 71 | | ShowInfo(); |
| | 72 | | } |
| 0 | 73 | | } |
| | 74 | | } |