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