| | 1 | | using MainScripts.DCL.Controllers.HUD.CharacterPreview; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Backpack |
| | 7 | | { |
| | 8 | | public class AvatarSlotsHUDController |
| | 9 | | { |
| | 10 | | internal const string HANDS_FEATURE = "hands"; |
| | 11 | | public event Action<string, bool, PreviewCameraFocus, bool> OnToggleSlot; |
| | 12 | |
|
| | 13 | | private readonly IAvatarSlotsView avatarSlotsView; |
| | 14 | | private string lastSelectedSlot; |
| | 15 | | internal AvatarSlotsDefinitionSO avatarSlotsDefinition; |
| | 16 | | private readonly FeatureFlag featureFlag; |
| | 17 | |
|
| | 18 | | public event Action<string, UnequipWearableSource> OnUnequipFromSlot; |
| | 19 | | public event Action<string, bool> OnHideUnhidePressed; |
| | 20 | |
|
| 71 | 21 | | public AvatarSlotsHUDController(IAvatarSlotsView avatarSlotsView, |
| | 22 | | IBackpackAnalyticsService backpackAnalyticsService, |
| | 23 | | IBaseVariable<FeatureFlag> featureFlag) |
| | 24 | | { |
| 71 | 25 | | this.featureFlag = featureFlag.Get(); |
| 71 | 26 | | this.avatarSlotsView = avatarSlotsView; |
| 71 | 27 | | avatarSlotsView.OnToggleAvatarSlot += ToggleSlot; |
| 71 | 28 | | avatarSlotsView.OnUnequipFromSlot += (wearableId) => OnUnequipFromSlot?.Invoke(wearableId, UnequipWearableSo |
| 71 | 29 | | avatarSlotsView.OnHideUnhidePressed += (category, forceRender) => |
| | 30 | | { |
| 2 | 31 | | if (forceRender) |
| 1 | 32 | | backpackAnalyticsService.SendForceShowWearable(category); |
| | 33 | | else |
| 1 | 34 | | backpackAnalyticsService.SendForceHideWearable(category); |
| | 35 | |
|
| 2 | 36 | | OnHideUnhidePressed?.Invoke(category, forceRender); |
| 0 | 37 | | }; |
| 71 | 38 | | avatarSlotsDefinition = Resources.Load<AvatarSlotsDefinitionSO>("AvatarSlotsDefinition"); |
| 71 | 39 | | } |
| | 40 | |
|
| | 41 | | public void GenerateSlots() |
| | 42 | | { |
| 28 | 43 | | bool showHands = featureFlag.IsFeatureEnabled(HANDS_FEATURE); |
| 218 | 44 | | for (var i = 0; i < avatarSlotsDefinition.slotsDefinition.Length; i++) |
| | 45 | | { |
| 81 | 46 | | SerializableKeyValuePair<string, List<string>> section = avatarSlotsDefinition.slotsDefinition[i]; |
| 81 | 47 | | avatarSlotsView.CreateAvatarSlotSection(section.key, i < avatarSlotsDefinition.slotsDefinition.Length - |
| | 48 | |
|
| 1096 | 49 | | foreach (string avatarSlotSection in section.value) |
| | 50 | | { |
| 467 | 51 | | if (avatarSlotSection == WearableLiterals.Categories.HANDS_WEAR) |
| | 52 | | { |
| 27 | 53 | | if (showHands) |
| 1 | 54 | | avatarSlotsView.AddSlotToSection(section.key, avatarSlotSection, CanAvatarSlotBeUnEquipped(a |
| | 55 | | } |
| | 56 | | else |
| 440 | 57 | | avatarSlotsView.AddSlotToSection(section.key, avatarSlotSection, CanAvatarSlotBeUnEquipped(avata |
| | 58 | | } |
| | 59 | | } |
| 28 | 60 | | avatarSlotsView.RebuildLayout(); |
| 28 | 61 | | } |
| | 62 | |
|
| | 63 | | public void Dispose() => |
| 94 | 64 | | avatarSlotsView.OnToggleAvatarSlot -= ToggleSlot; |
| | 65 | |
|
| | 66 | | public void SelectSlot(string category, bool notify = true) |
| | 67 | | { |
| 11 | 68 | | ClearSlotSelection(); |
| | 69 | |
|
| 11 | 70 | | lastSelectedSlot = category; |
| 11 | 71 | | avatarSlotsView.Select(category, notify); |
| 11 | 72 | | } |
| | 73 | |
|
| | 74 | | public void UnselectAllSlots(bool notify = true) => |
| 0 | 75 | | avatarSlotsView.UnSelectAll(notify); |
| | 76 | |
|
| | 77 | | public void Recalculate(HashSet<string> forceRender) => |
| 7 | 78 | | avatarSlotsView.RecalculateHideList(forceRender); |
| | 79 | |
|
| | 80 | | public void Equip(WearableItem wearableItem, string bodyShape, HashSet<string> forceRender) => |
| 27 | 81 | | avatarSlotsView.SetSlotContent(wearableItem.data.category, wearableItem, bodyShape, forceRender); |
| | 82 | |
|
| | 83 | | public void UnEquip(string category, HashSet<string> forceRender) => |
| 7 | 84 | | avatarSlotsView.ResetCategorySlot(category, forceRender); |
| | 85 | |
|
| | 86 | | public void ClearSlotSelection() |
| | 87 | | { |
| 98 | 88 | | if (string.IsNullOrEmpty(lastSelectedSlot)) return; |
| 4 | 89 | | avatarSlotsView.DisablePreviousSlot(lastSelectedSlot); |
| 4 | 90 | | lastSelectedSlot = ""; |
| 4 | 91 | | } |
| | 92 | |
|
| | 93 | | private bool CanAvatarSlotBeUnEquipped(string avatarSlotSection) => |
| 441 | 94 | | avatarSlotSection != WearableLiterals.Categories.BODY_SHAPE && |
| | 95 | | avatarSlotSection != WearableLiterals.Categories.EYES && |
| | 96 | | avatarSlotSection != WearableLiterals.Categories.MOUTH; |
| | 97 | |
|
| | 98 | | private void ToggleSlot(string slotCategory, bool supportColor, PreviewCameraFocus previewCameraFocus, bool isSe |
| | 99 | | { |
| 7 | 100 | | if (isSelected && !string.IsNullOrEmpty(lastSelectedSlot)) |
| 1 | 101 | | avatarSlotsView.DisablePreviousSlot(lastSelectedSlot); |
| | 102 | |
|
| 7 | 103 | | lastSelectedSlot = isSelected ? slotCategory : ""; |
| | 104 | |
|
| 7 | 105 | | OnToggleSlot?.Invoke(slotCategory, supportColor, previewCameraFocus, isSelected); |
| 5 | 106 | | } |
| | 107 | | } |
| | 108 | | } |