| | 1 | | using System; |
| | 2 | | using UIComponents.Scripts.Components; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.Backpack |
| | 7 | | { |
| | 8 | | public class OutfitComponentView : BaseComponentView<OutfitComponentModel>, IOutfitComponentView |
| | 9 | | { |
| | 10 | | [SerializeField] internal GameObject emptyState; |
| | 11 | | [SerializeField] internal GameObject filledState; |
| | 12 | | [SerializeField] internal GameObject loadingState; |
| | 13 | | [SerializeField] internal GameObject[] hoverStates; |
| | 14 | | [SerializeField] internal GameObject[] normalStates; |
| | 15 | | [SerializeField] internal Button equipButton; |
| | 16 | | [SerializeField] internal Button saveOutfitButton; |
| | 17 | | [SerializeField] internal Button discardOutfitButton; |
| | 18 | | [SerializeField] internal RawImage outfitPreviewImage; |
| | 19 | | [SerializeField] private int outfitIndex; |
| | 20 | |
|
| | 21 | | public event Action<OutfitItem> OnEquipOutfit; |
| | 22 | | public event Action<int> OnSaveOutfit; |
| | 23 | | public event Action<int> OnDiscardOutfit; |
| | 24 | |
|
| | 25 | | public override void Awake() |
| | 26 | | { |
| 6 | 27 | | base.Awake(); |
| 6 | 28 | | InitializeButtonEvents(); |
| 6 | 29 | | } |
| | 30 | |
|
| | 31 | | private void InitializeButtonEvents() |
| | 32 | | { |
| 6 | 33 | | equipButton.onClick.RemoveAllListeners(); |
| 6 | 34 | | equipButton.onClick.AddListener(() => OnEquipOutfit?.Invoke(model.outfitItem)); |
| 6 | 35 | | saveOutfitButton.onClick.RemoveAllListeners(); |
| 6 | 36 | | saveOutfitButton.onClick.AddListener(() => OnSaveOutfit?.Invoke(outfitIndex)); |
| 6 | 37 | | discardOutfitButton.onClick.RemoveAllListeners(); |
| 6 | 38 | | discardOutfitButton.onClick.AddListener(() => OnDiscardOutfit?.Invoke(outfitIndex)); |
| 6 | 39 | | } |
| | 40 | |
|
| | 41 | | public override void RefreshControl() => |
| 0 | 42 | | SetOutfit(model.outfitItem); |
| | 43 | |
|
| | 44 | | public void SetOutfit(OutfitItem outfitItem) => |
| 0 | 45 | | model.outfitItem = outfitItem; |
| | 46 | |
|
| | 47 | | public void SetOutfitPreviewImage(Texture bodyTexture) => |
| 0 | 48 | | outfitPreviewImage.texture = bodyTexture; |
| | 49 | |
|
| | 50 | | public void SetIsEmpty(bool isEmpty) |
| | 51 | | { |
| 2 | 52 | | emptyState.SetActive(isEmpty); |
| 2 | 53 | | filledState.SetActive(!isEmpty); |
| 2 | 54 | | } |
| | 55 | |
|
| | 56 | | public void SetIsLoading(bool isLoading) |
| | 57 | | { |
| 2 | 58 | | loadingState.SetActive(isLoading); |
| | 59 | |
|
| 3 | 60 | | if (!isLoading) return; |
| 1 | 61 | | emptyState.SetActive(false); |
| 1 | 62 | | filledState.SetActive(false); |
| 1 | 63 | | } |
| | 64 | |
|
| | 65 | | public override void OnFocus() |
| | 66 | | { |
| 1 | 67 | | base.OnFocus(); |
| | 68 | |
|
| 6 | 69 | | foreach (GameObject hoverState in hoverStates) |
| 2 | 70 | | hoverState.SetActive(true); |
| | 71 | |
|
| 6 | 72 | | foreach (GameObject normalState in normalStates) |
| 2 | 73 | | normalState.SetActive(false); |
| 1 | 74 | | } |
| | 75 | |
|
| | 76 | | public override void OnLoseFocus() |
| | 77 | | { |
| 7 | 78 | | base.OnLoseFocus(); |
| | 79 | |
|
| 42 | 80 | | foreach (GameObject normalState in normalStates) |
| 14 | 81 | | normalState.SetActive(true); |
| | 82 | |
|
| 42 | 83 | | foreach (GameObject hoverState in hoverStates) |
| 14 | 84 | | hoverState.SetActive(false); |
| 7 | 85 | | } |
| | 86 | | } |
| | 87 | | } |