| | 1 | | using System; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | | using Random = UnityEngine.Random; |
| | 7 | |
|
| | 8 | | internal interface IOwnerInfoElement : IDisposable |
| | 9 | | { |
| | 10 | | void SetOwner(string address); |
| | 11 | | void SetAddressLength(int length); |
| | 12 | | void SetColorIndex(int index); |
| | 13 | | void SetParent(Transform parent); |
| | 14 | | void SetActive(bool active); |
| | 15 | | void SetConfig(float fontSize, float horizontalSpacing); |
| | 16 | | } |
| | 17 | |
|
| | 18 | | internal class OwnerInfoElement : MonoBehaviour, IOwnerInfoElement |
| | 19 | | { |
| | 20 | | private const int DEFAULT_ADDRESS_MAX_CHARS = 11; |
| | 21 | |
|
| | 22 | | [SerializeField] private TextMeshProUGUI textOwner; |
| | 23 | | [SerializeField] private Image imageEllipse; |
| | 24 | | [SerializeField] private HorizontalLayoutGroup horizontalLayout; |
| | 25 | | [SerializeField] private Color[] colorsEllipse; |
| | 26 | |
|
| | 27 | | private bool isDestroyed = false; |
| | 28 | | private string address; |
| 1 | 29 | | private int lastAddressLength = DEFAULT_ADDRESS_MAX_CHARS; |
| | 30 | |
|
| | 31 | | void IOwnerInfoElement.SetOwner(string ownerAddress) |
| | 32 | | { |
| 0 | 33 | | address = ownerAddress; |
| 0 | 34 | | textOwner.text = NFTPromptHUDController.FormatOwnerAddress(ownerAddress, lastAddressLength); |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | void IOwnerInfoElement.SetAddressLength(int length) |
| | 38 | | { |
| 0 | 39 | | lastAddressLength = length; |
| 0 | 40 | | if (textOwner.text.Length != length) |
| | 41 | | { |
| 0 | 42 | | textOwner.text = NFTPromptHUDController.FormatOwnerAddress(address, lastAddressLength); |
| | 43 | | } |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | void IOwnerInfoElement.SetColorIndex(int index) |
| | 47 | | { |
| 0 | 48 | | int colorIndex = index % colorsEllipse.Length; |
| 0 | 49 | | imageEllipse.color = colorsEllipse[colorIndex]; |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | void IOwnerInfoElement.SetParent(Transform parent) |
| | 53 | | { |
| 0 | 54 | | transform.SetParent(parent); |
| 0 | 55 | | transform.ResetLocalTRS(); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | void IOwnerInfoElement.SetConfig(float fontSize, float horizontalSpacing) |
| | 59 | | { |
| 0 | 60 | | textOwner.fontSize = fontSize; |
| 0 | 61 | | horizontalLayout.spacing = horizontalSpacing; |
| 0 | 62 | | } |
| | 63 | |
|
| 0 | 64 | | void IOwnerInfoElement.SetActive(bool active) { gameObject.SetActive(active); } |
| | 65 | |
|
| | 66 | | public void Dispose() |
| | 67 | | { |
| 0 | 68 | | if (!isDestroyed) |
| | 69 | | { |
| 0 | 70 | | Destroy(gameObject); |
| | 71 | | } |
| 0 | 72 | | } |
| | 73 | |
|
| 0 | 74 | | private void OnDestroy() { isDestroyed = true; } |
| | 75 | | } |