| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.EmotesWheel |
| | 8 | | { |
| | 9 | | public class EmotesWheelView : MonoBehaviour |
| | 10 | | { |
| | 11 | | public class EmoteSlotData |
| | 12 | | { |
| | 13 | | public WearableItem emoteItem; |
| | 14 | | public Sprite thumbnailSprite; |
| | 15 | | } |
| | 16 | |
|
| | 17 | | [Serializable] |
| | 18 | | internal class RarityColor |
| | 19 | | { |
| | 20 | | public string rarity; |
| | 21 | | public Color markColor; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | private const string PATH = "EmotesWheelHUD"; |
| | 25 | |
|
| | 26 | |
|
| | 27 | | public event Action<string> onEmoteClicked; |
| | 28 | | public event Action OnClose; |
| | 29 | | public event Action OnCustomizeClicked; |
| | 30 | |
|
| | 31 | | [SerializeField] internal Sprite nonAssignedEmoteSprite; |
| | 32 | | [SerializeField] internal EmoteWheelSlot[] emoteButtons; |
| | 33 | | [SerializeField] internal Button_OnPointerDown[] closeButtons; |
| | 34 | | [SerializeField] internal ButtonComponentView openCustomizeButton; |
| | 35 | | [SerializeField] internal TMP_Text selectedEmoteName; |
| | 36 | | [SerializeField] internal List<RarityColor> rarityColors; |
| | 37 | | [SerializeField] internal GameObject customizeTitle; |
| | 38 | |
|
| | 39 | | private HUDCanvasCameraModeController hudCanvasCameraModeController; |
| | 40 | |
|
| 3 | 41 | | public static EmotesWheelView Create() { return Instantiate(Resources.Load<GameObject>(PATH)).GetComponent<Emote |
| | 42 | |
|
| | 43 | | private void Awake() |
| | 44 | | { |
| 18 | 45 | | for (int i = 0; i < closeButtons.Length; i++) |
| | 46 | | { |
| 6 | 47 | | closeButtons[i].onPointerDown += Close; |
| | 48 | | } |
| | 49 | |
|
| 3 | 50 | | openCustomizeButton.onClick.AddListener(() => |
| | 51 | | { |
| 0 | 52 | | OnCustomizeClicked?.Invoke(); |
| 0 | 53 | | }); |
| | 54 | |
|
| 3 | 55 | | selectedEmoteName.text = string.Empty; |
| 3 | 56 | | hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera |
| 3 | 57 | | } |
| | 58 | |
|
| | 59 | | public void SetVisiblity(bool visible) |
| | 60 | | { |
| 5 | 61 | | if (visible == gameObject.activeSelf) |
| 0 | 62 | | return; |
| | 63 | |
|
| 5 | 64 | | gameObject.SetActive(visible); |
| 5 | 65 | | if (visible) |
| | 66 | | { |
| 1 | 67 | | AudioScriptableObjects.dialogOpen.Play(true); |
| 1 | 68 | | } |
| | 69 | | else |
| | 70 | | { |
| 4 | 71 | | AudioScriptableObjects.dialogClose.Play(true); |
| | 72 | | } |
| 4 | 73 | | } |
| | 74 | |
|
| | 75 | | public List<EmoteWheelSlot> SetEmotes(List<EmoteSlotData> emotes) |
| | 76 | | { |
| 66 | 77 | | for (int i = 0; i < emotes.Count; i++) |
| | 78 | | { |
| 30 | 79 | | EmoteSlotData equippedEmote = emotes[i]; |
| | 80 | |
|
| 30 | 81 | | if (i < emoteButtons.Length) |
| | 82 | | { |
| 30 | 83 | | emoteButtons[i].button.onClick.RemoveAllListeners(); |
| 30 | 84 | | emoteButtons[i].onSlotHover -= OnSlotHover; |
| 30 | 85 | | emoteButtons[i].onSlotHover += OnSlotHover; |
| | 86 | |
|
| 30 | 87 | | if (equippedEmote != null) |
| | 88 | | { |
| 0 | 89 | | emoteButtons[i].button.onClick.AddListener(() => onEmoteClicked?.Invoke(equippedEmote.emoteItem. |
| | 90 | |
|
| 0 | 91 | | if (equippedEmote.thumbnailSprite != null) |
| 0 | 92 | | emoteButtons[i].SetImage(equippedEmote.thumbnailSprite); |
| | 93 | | else |
| 0 | 94 | | emoteButtons[i].SetImage(equippedEmote.emoteItem.ComposeThumbnailUrl()); |
| | 95 | |
|
| 0 | 96 | | emoteButtons[i].SetId(equippedEmote.emoteItem.id); |
| 0 | 97 | | emoteButtons[i].SetName(equippedEmote.emoteItem.GetName()); |
| | 98 | |
|
| 0 | 99 | | RarityColor rarityColor = rarityColors.FirstOrDefault(x => x.rarity == equippedEmote.emoteItem.r |
| 0 | 100 | | emoteButtons[i].SetRarity( |
| | 101 | | rarityColor != null, |
| | 102 | | rarityColor != null ? rarityColor.markColor : Color.white); |
| 0 | 103 | | } |
| | 104 | | else |
| | 105 | | { |
| 30 | 106 | | emoteButtons[i].SetImage(nonAssignedEmoteSprite); |
| 30 | 107 | | emoteButtons[i].SetId(string.Empty); |
| 30 | 108 | | emoteButtons[i].SetName(string.Empty); |
| 30 | 109 | | emoteButtons[i].SetRarity(false, Color.white); |
| | 110 | | } |
| | 111 | | } |
| | 112 | | } |
| | 113 | |
|
| 3 | 114 | | return emoteButtons.ToList(); |
| | 115 | | } |
| | 116 | |
|
| 0 | 117 | | private void OnSlotHover(string emoteName) { selectedEmoteName.text = emoteName; } |
| | 118 | |
|
| 0 | 119 | | private void Close() { OnClose?.Invoke(); } |
| | 120 | |
|
| | 121 | | public void OnDestroy() |
| | 122 | | { |
| 3 | 123 | | CleanUp(); |
| 3 | 124 | | hudCanvasCameraModeController?.Dispose(); |
| 3 | 125 | | } |
| | 126 | |
|
| | 127 | | public void CleanUp() |
| | 128 | | { |
| 36 | 129 | | for (int i = 0; i < closeButtons.Length; i++) |
| | 130 | | { |
| 12 | 131 | | closeButtons[i].onPointerDown -= Close; |
| | 132 | | } |
| | 133 | |
|
| 6 | 134 | | openCustomizeButton.onClick.RemoveAllListeners(); |
| 6 | 135 | | } |
| | 136 | | } |
| | 137 | | } |