| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UIComponents.Scripts.Components; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Backpack |
| | 7 | | { |
| | 8 | | public class VRMDetailItemComponentView : BaseComponentView<VRMItemModel> |
| | 9 | | { |
| | 10 | | [SerializeField] private NftTypeIconSO typeIcons; |
| | 11 | | [SerializeField] private ImageComponentView wearableImage; |
| | 12 | | [SerializeField] private TMP_Text wearableName; |
| | 13 | | [SerializeField] private ImageComponentView wearableTypeImage; |
| | 14 | | [SerializeField] private TMP_Text wearableTypeName; |
| | 15 | | [SerializeField] private ImageComponentView wearableCreatorImage; |
| | 16 | | [SerializeField] private TMP_Text wearableCreatorName; |
| | 17 | | [SerializeField] private ButtonComponentView actionButton; |
| | 18 | |
|
| 1 | 19 | | private bool isUnEquipAction = true; |
| | 20 | | private const string UNEQUIP_TEXT = "unequip"; |
| | 21 | | private const string EQUIP_TEXT = "equip"; |
| | 22 | |
|
| | 23 | | public event Action OnUnEquipWearable; |
| | 24 | | public event Action OnEquipWearable; |
| | 25 | |
|
| | 26 | | public void Start() |
| | 27 | | { |
| 0 | 28 | | actionButton.onClick.RemoveAllListeners(); |
| 0 | 29 | | actionButton.onClick.AddListener(OnActionButtonClicked); |
| 0 | 30 | | } |
| | 31 | |
|
| | 32 | | private void OnActionButtonClicked() |
| | 33 | | { |
| 0 | 34 | | if (isUnEquipAction) |
| | 35 | | { |
| 0 | 36 | | actionButton.SetText(EQUIP_TEXT); |
| 0 | 37 | | isUnEquipAction = false; |
| 0 | 38 | | OnUnEquipWearable?.Invoke(); |
| | 39 | | } |
| | 40 | | else |
| | 41 | | { |
| 0 | 42 | | actionButton.SetText(UNEQUIP_TEXT); |
| 0 | 43 | | isUnEquipAction = true; |
| 0 | 44 | | OnEquipWearable?.Invoke(); |
| | 45 | | } |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | public void ClearOnWearableUnequippedEvents() |
| | 49 | | { |
| 0 | 50 | | OnUnEquipWearable = null; |
| 0 | 51 | | OnEquipWearable = null; |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | public override void RefreshControl() |
| | 55 | | { |
| 0 | 56 | | if (model == null) |
| 0 | 57 | | return; |
| | 58 | |
|
| 0 | 59 | | isUnEquipAction = true; |
| 0 | 60 | | actionButton.SetText(UNEQUIP_TEXT); |
| | 61 | |
|
| 0 | 62 | | SetWearableImage(model.wearableImageUrl); |
| 0 | 63 | | SetWearableName(model.wearableName); |
| | 64 | |
|
| 0 | 65 | | SetWearableCategoryImage(model.wearableCategoryName); |
| 0 | 66 | | SetWearableCategoryName(model.wearableCategoryName); |
| | 67 | |
|
| 0 | 68 | | SetWearableCreatorImage(model.wearableCreatorImageUrl); |
| 0 | 69 | | SetWearableCreatorName(model.wearableCreatorName); |
| | 70 | |
|
| 0 | 71 | | SetActionButtonEnableState(model.wearableCanBeUnEquipped); |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | private void SetActionButtonEnableState(bool state) |
| | 75 | | { |
| 0 | 76 | | actionButton.gameObject.SetActive(state); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | private void SetWearableImage(string modelWearableImageUrl) |
| | 80 | | { |
| 0 | 81 | | model.wearableImageUrl = modelWearableImageUrl; |
| | 82 | |
|
| 0 | 83 | | if (string.IsNullOrEmpty(modelWearableImageUrl)) |
| | 84 | | { |
| 0 | 85 | | wearableImage.SetImage(Texture2D.grayTexture); |
| 0 | 86 | | return; |
| | 87 | | } |
| | 88 | |
|
| 0 | 89 | | wearableImage.SetImage(modelWearableImageUrl); |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | private void SetWearableName(string name) |
| | 93 | | { |
| 0 | 94 | | model.wearableName = name; |
| 0 | 95 | | wearableName.text = name; |
| 0 | 96 | | } |
| | 97 | |
|
| | 98 | | private void SetWearableCategoryImage(string categoryName) |
| | 99 | | { |
| 0 | 100 | | var categoryIcon = typeIcons.GetTypeImage(categoryName); |
| | 101 | |
|
| 0 | 102 | | if (categoryIcon) |
| 0 | 103 | | wearableTypeImage.SetImage(categoryIcon); |
| | 104 | | else |
| 0 | 105 | | wearableTypeImage.SetImage(Texture2D.grayTexture); |
| 0 | 106 | | } |
| | 107 | |
|
| | 108 | | private void SetWearableCategoryName(string categoryName) |
| | 109 | | { |
| 0 | 110 | | string readableName = WearableItem.CATEGORIES_READABLE_MAPPING[categoryName]; |
| 0 | 111 | | model.wearableCategoryName = readableName; |
| 0 | 112 | | wearableTypeName.text = readableName; |
| 0 | 113 | | } |
| | 114 | |
|
| | 115 | | private void SetWearableCreatorImage(string creatorImageUrl) |
| | 116 | | { |
| 0 | 117 | | model.wearableCreatorImageUrl = creatorImageUrl; |
| | 118 | |
|
| 0 | 119 | | if (string.IsNullOrEmpty(creatorImageUrl)) |
| | 120 | | { |
| 0 | 121 | | wearableCreatorImage.SetImage(Texture2D.grayTexture); |
| 0 | 122 | | return; |
| | 123 | | } |
| | 124 | |
|
| 0 | 125 | | wearableCreatorImage.SetImage(creatorImageUrl); |
| 0 | 126 | | } |
| | 127 | |
|
| | 128 | | private void SetWearableCreatorName(string creatorName) |
| | 129 | | { |
| 0 | 130 | | model.wearableCreatorName = creatorName; |
| 0 | 131 | | wearableCreatorName.text = creatorName; |
| 0 | 132 | | } |
| | 133 | | } |
| | 134 | | } |