| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.EventSystems; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.EmotesWheel |
| | 7 | | { |
| | 8 | | public class EmoteWheelSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler |
| | 9 | | { |
| | 10 | | [SerializeField] internal Button_OnPointerDown button; |
| | 11 | | [SerializeField] internal ImageComponentView image; |
| | 12 | | [SerializeField] internal Image rarityImage; |
| | 13 | | [SerializeField] internal GameObject loadingSpinnerGO; |
| | 14 | | [SerializeField] internal Sprite defaultImage; |
| | 15 | |
|
| | 16 | | public event Action<string> onSlotHover; |
| | 17 | |
|
| 0 | 18 | | public string emoteId { get; private set; } |
| 0 | 19 | | public bool isLoading { get; private set; } |
| | 20 | |
|
| | 21 | | private string emoteName; |
| | 22 | |
|
| 0 | 23 | | public void SetId(string id) { emoteId = id; } |
| | 24 | |
|
| 0 | 25 | | public void SetName(string name) { emoteName = name; } |
| | 26 | |
|
| | 27 | | public void SetRarity(bool isActive, Color color) |
| | 28 | | { |
| 30 | 29 | | rarityImage.transform.parent.gameObject.SetActive(isActive); |
| 30 | 30 | | rarityImage.color = color; |
| 30 | 31 | | } |
| | 32 | |
|
| | 33 | | public void SetImage(Sprite sprite) |
| | 34 | | { |
| 30 | 35 | | if (sprite != null) |
| 30 | 36 | | image.SetImage(sprite); |
| | 37 | | else |
| 0 | 38 | | image.SetImage(sprite); |
| 0 | 39 | | } |
| | 40 | |
|
| | 41 | | public void SetImage(string uri) |
| | 42 | | { |
| 0 | 43 | | if (!string.IsNullOrEmpty(uri)) |
| 0 | 44 | | image.SetImage(uri); |
| | 45 | | else |
| 0 | 46 | | image.SetImage(defaultImage); |
| 0 | 47 | | } |
| | 48 | |
|
| | 49 | | public void SetAsLoading(bool isLoading) |
| | 50 | | { |
| 30 | 51 | | this.isLoading = isLoading; |
| 30 | 52 | | loadingSpinnerGO.SetActive(isLoading); |
| 30 | 53 | | image.gameObject.SetActive(!isLoading); |
| 30 | 54 | | button.enabled = !isLoading; |
| 30 | 55 | | } |
| | 56 | |
|
| 0 | 57 | | public void OnPointerEnter(PointerEventData eventData) { onSlotHover?.Invoke(emoteName); } |
| | 58 | |
|
| 0 | 59 | | public void OnPointerExit(PointerEventData eventData) { onSlotHover?.Invoke(string.Empty); } |
| | 60 | | } |
| | 61 | | } |