| | 1 | | using DCL; |
| | 2 | | using ExploreV2Analytics; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// Main controller for the feature "Explore V2". |
| | 10 | | /// Controls different sections: Maps, Backpack, Settings |
| | 11 | | /// their initialization and switching between them |
| | 12 | | /// </summary> |
| | 13 | | public class ExploreV2MenuComponentController : IExploreV2MenuComponentController |
| | 14 | | { |
| | 15 | | internal const ExploreSection DEFAULT_SECTION = ExploreSection.Explore; |
| | 16 | |
|
| | 17 | | internal IExploreV2MenuComponentView view; |
| | 18 | | internal IExploreV2Analytics exploreV2Analytics; |
| | 19 | |
|
| | 20 | | internal IPlacesAndEventsSectionComponentController placesAndEventsSectionController; |
| | 21 | |
|
| | 22 | | internal ExploreSection currentOpenSection; |
| | 23 | | internal Dictionary<BaseVariable<bool>, ExploreSection> sectionsByVisibilityVar; |
| | 24 | | private ExploreV2ComponentRealmsController realmController; |
| | 25 | |
|
| | 26 | | private MouseCatcher mouseCatcher; |
| | 27 | | private Dictionary<BaseVariable<bool>, ExploreSection> sectionsByInitVar; |
| | 28 | | private Dictionary<ExploreSection, (BaseVariable<bool> initVar, BaseVariable<bool> visibilityVar)> sectionsVariables |
| | 29 | |
|
| 297 | 30 | | internal BaseVariable<bool> isOpen => DataStore.i.exploreV2.isOpen; |
| 106 | 31 | | internal BaseVariable<bool> isInitialized => DataStore.i.exploreV2.isInitialized; |
| 71 | 32 | | internal BaseVariable<bool> profileCardIsOpen => DataStore.i.exploreV2.profileCardIsOpen; |
| | 33 | |
|
| 57 | 34 | | internal BaseVariable<bool> placesAndEventsVisible => DataStore.i.exploreV2.placesAndEventsVisible; |
| 53 | 35 | | internal BaseVariable<bool> isAvatarEditorInitialized => DataStore.i.HUDs.isAvatarEditorInitialized; |
| 57 | 36 | | internal BaseVariable<bool> avatarEditorVisible => DataStore.i.HUDs.avatarEditorVisible; |
| 53 | 37 | | internal BaseVariable<bool> isNavmapInitialized => DataStore.i.HUDs.isNavMapInitialized; |
| 57 | 38 | | internal BaseVariable<bool> navmapVisible => DataStore.i.HUDs.navmapVisible; |
| 53 | 39 | | internal BaseVariable<bool> isQuestInitialized => DataStore.i.Quests.isInitialized; |
| 57 | 40 | | internal BaseVariable<bool> questVisible => DataStore.i.HUDs.questsPanelVisible; |
| 53 | 41 | | internal BaseVariable<bool> isSettingsPanelInitialized => DataStore.i.settings.isInitialized; |
| 57 | 42 | | internal BaseVariable<bool> settingsVisible => DataStore.i.settings.settingsPanelVisible; |
| | 43 | |
|
| 236 | 44 | | internal BaseVariable<int> currentSectionIndex => DataStore.i.exploreV2.currentSectionIndex; |
| 153 | 45 | | private UserProfile ownUserProfile => UserProfile.GetOwnUserProfile(); |
| 51 | 46 | | private BaseVariable<bool> isPlacesAndEventsSectionInitialized => DataStore.i.exploreV2.isPlacesAndEventsSectionInit |
| 21 | 47 | | private BaseVariable<bool> isPromoteChannelsToastVisible => DataStore.i.channels.isPromoteToastVisible; |
| | 48 | |
|
| 51 | 49 | | private RectTransform topMenuTooltipReference => view.currentTopMenuTooltipReference; |
| 51 | 50 | | private RectTransform placesAndEventsTooltipReference => view.currentPlacesAndEventsTooltipReference; |
| 51 | 51 | | private RectTransform backpackTooltipReference => view.currentBackpackTooltipReference; |
| 51 | 52 | | private RectTransform mapTooltipReference => view.currentMapTooltipReference; |
| 51 | 53 | | private RectTransform questTooltipReference => view.currentQuestTooltipReference; |
| 51 | 54 | | private RectTransform settingsTooltipReference => view.currentSettingsTooltipReference; |
| 51 | 55 | | private RectTransform profileCardTooltipReference => view.currentProfileCardTooltipReference; |
| | 56 | |
|
| | 57 | | public void Initialize() |
| | 58 | | { |
| 51 | 59 | | sectionsVariables = new Dictionary<ExploreSection, (BaseVariable<bool>, BaseVariable<bool>)> |
| | 60 | | { |
| | 61 | | { ExploreSection.Explore, (isPlacesAndEventsSectionInitialized, placesAndEventsVisible) }, |
| | 62 | | { ExploreSection.Backpack, (isAvatarEditorInitialized, avatarEditorVisible) }, |
| | 63 | | { ExploreSection.Map, (isNavmapInitialized, navmapVisible) }, |
| | 64 | | { ExploreSection.Quest, (isQuestInitialized, questVisible) }, |
| | 65 | | { ExploreSection.Settings, (isSettingsPanelInitialized, settingsVisible) }, |
| | 66 | | }; |
| | 67 | |
|
| 561 | 68 | | sectionsByInitVar = sectionsVariables.ToDictionary(pair => pair.Value.initVar, pair => pair.Key); |
| 561 | 69 | | sectionsByVisibilityVar = sectionsVariables.ToDictionary(pair => pair.Value.visibilityVar, pair => pair.Key); |
| | 70 | |
|
| 51 | 71 | | mouseCatcher = SceneReferences.i?.mouseCatcher; |
| 51 | 72 | | exploreV2Analytics = CreateAnalyticsController(); |
| | 73 | |
|
| 51 | 74 | | view = CreateView(); |
| 51 | 75 | | SetVisibility(false); |
| | 76 | |
|
| 51 | 77 | | realmController = new ExploreV2ComponentRealmsController(DataStore.i.realm, view); |
| 51 | 78 | | realmController.Initialize(); |
| 51 | 79 | | view.currentRealmViewer.onLogoClick?.AddListener(view.ShowRealmSelectorModal); |
| | 80 | |
|
| 51 | 81 | | ownUserProfile.OnUpdate += UpdateProfileInfo; |
| 51 | 82 | | UpdateProfileInfo(ownUserProfile); |
| 51 | 83 | | view.currentProfileCard.onClick?.AddListener(() => { profileCardIsOpen.Set(!profileCardIsOpen.Get()); }); |
| | 84 | |
|
| 51 | 85 | | view.OnCloseButtonPressed += OnCloseButtonPressed; |
| 51 | 86 | | view.OnAfterShowAnimation += OnAfterShowAnimation; |
| | 87 | |
|
| 51 | 88 | | DataStore.i.exploreV2.topMenuTooltipReference.Set(topMenuTooltipReference); |
| 51 | 89 | | DataStore.i.exploreV2.placesAndEventsTooltipReference.Set(placesAndEventsTooltipReference); |
| 51 | 90 | | DataStore.i.exploreV2.backpackTooltipReference.Set(backpackTooltipReference); |
| 51 | 91 | | DataStore.i.exploreV2.mapTooltipReference.Set(mapTooltipReference); |
| 51 | 92 | | DataStore.i.exploreV2.questTooltipReference.Set(questTooltipReference); |
| 51 | 93 | | DataStore.i.exploreV2.settingsTooltipReference.Set(settingsTooltipReference); |
| 51 | 94 | | DataStore.i.exploreV2.profileCardTooltipReference.Set(profileCardTooltipReference); |
| | 95 | |
|
| 51 | 96 | | view.OnSectionOpen += OnSectionOpen; |
| | 97 | |
|
| 51 | 98 | | isOpen.OnChange += SetVisibilityOnOpenChanged; |
| 51 | 99 | | SetVisibilityOnOpenChanged(isOpen.Get()); |
| | 100 | |
|
| 51 | 101 | | currentSectionIndex.OnChange += CurrentSectionIndexChanged; |
| 51 | 102 | | CurrentSectionIndexChanged(currentSectionIndex.Get(), 0); |
| | 103 | |
|
| 612 | 104 | | foreach ((BaseVariable<bool> initVar, BaseVariable<bool> visibilityVar) sectionsVars in sectionsVariables.Values |
| | 105 | | { |
| 255 | 106 | | sectionsVars.initVar.OnChangeWithSenderInfo += OnSectionInitializedChanged; |
| 255 | 107 | | OnSectionInitializedChanged(sectionsVars.initVar, sectionsVars.initVar.Get()); |
| | 108 | |
|
| 255 | 109 | | sectionsVars.visibilityVar.OnChangeWithSenderInfo += OnSectionVisibilityChanged; |
| 255 | 110 | | OnSectionVisibilityChanged(sectionsVars.visibilityVar, sectionsVars.visibilityVar.Get()); |
| | 111 | | } |
| | 112 | |
|
| 51 | 113 | | isInitialized.Set(true); |
| | 114 | |
|
| 51 | 115 | | currentSectionIndex.Set((int)DEFAULT_SECTION, false); |
| | 116 | |
|
| 51 | 117 | | view.ConfigureEncapsulatedSection(ExploreSection.Map, DataStore.i.exploreV2.configureMapInFullscreenMenu); |
| 51 | 118 | | view.ConfigureEncapsulatedSection(ExploreSection.Quest, DataStore.i.exploreV2.configureQuestInFullscreenMenu); |
| 51 | 119 | | view.ConfigureEncapsulatedSection(ExploreSection.Settings, DataStore.i.exploreV2.configureSettingsInFullscreenMe |
| 51 | 120 | | } |
| | 121 | |
|
| | 122 | | public void Dispose() |
| | 123 | | { |
| 51 | 124 | | realmController.Dispose(); |
| | 125 | |
|
| 51 | 126 | | ownUserProfile.OnUpdate -= UpdateProfileInfo; |
| 51 | 127 | | view?.currentProfileCard.onClick?.RemoveAllListeners(); |
| | 128 | |
|
| 51 | 129 | | isOpen.OnChange -= SetVisibilityOnOpenChanged; |
| 51 | 130 | | currentSectionIndex.OnChange -= CurrentSectionIndexChanged; |
| | 131 | |
|
| 612 | 132 | | foreach ((BaseVariable<bool> initVar, BaseVariable<bool> visibilityVar) sectionsVars in sectionsVariables.Values |
| | 133 | | { |
| 255 | 134 | | sectionsVars.initVar.OnChangeWithSenderInfo -= OnSectionInitializedChanged; |
| 255 | 135 | | sectionsVars.visibilityVar.OnChangeWithSenderInfo -= OnSectionVisibilityChanged; |
| | 136 | | } |
| | 137 | |
|
| 51 | 138 | | if (placesAndEventsSectionController != null) |
| | 139 | | { |
| 1 | 140 | | placesAndEventsSectionController.OnCloseExploreV2 -= OnCloseButtonPressed; |
| 1 | 141 | | placesAndEventsSectionController.Dispose(); |
| | 142 | | } |
| | 143 | |
|
| 51 | 144 | | if (view != null) |
| | 145 | | { |
| 51 | 146 | | view.currentProfileCard.onClick?.RemoveAllListeners(); |
| 51 | 147 | | view.currentRealmViewer.onLogoClick?.RemoveAllListeners(); |
| 51 | 148 | | view.OnCloseButtonPressed -= OnCloseButtonPressed; |
| 51 | 149 | | view.OnAfterShowAnimation -= OnAfterShowAnimation; |
| 51 | 150 | | view.OnSectionOpen -= OnSectionOpen; |
| 51 | 151 | | view.Dispose(); |
| | 152 | | } |
| 51 | 153 | | } |
| | 154 | |
|
| | 155 | | protected internal virtual IExploreV2MenuComponentView CreateView() => |
| 0 | 156 | | ExploreV2MenuComponentView.Create(); |
| | 157 | |
|
| | 158 | | internal virtual IExploreV2Analytics CreateAnalyticsController() => |
| 0 | 159 | | new ExploreV2Analytics.ExploreV2Analytics(); |
| | 160 | |
|
| | 161 | | internal void InitializePlacesAndEventsSection() |
| | 162 | | { |
| 1 | 163 | | if (placesAndEventsSectionController != null) |
| 0 | 164 | | return; |
| | 165 | |
|
| 1 | 166 | | placesAndEventsSectionController = new PlacesAndEventsSectionComponentController(view.currentPlacesAndEventsSect |
| 1 | 167 | | placesAndEventsSectionController.OnCloseExploreV2 += OnCloseButtonPressed; |
| 1 | 168 | | } |
| | 169 | |
|
| | 170 | | private void OnSectionInitializedChanged(BaseVariable<bool> initVar, bool initialized, bool _ = false) => |
| 259 | 171 | | SectionInitializedChanged(sectionsByInitVar[initVar], initialized); |
| | 172 | |
|
| | 173 | | internal void SectionInitializedChanged(ExploreSection section, bool initialized, bool _ = false) |
| | 174 | | { |
| 267 | 175 | | view.SetSectionActive(section, initialized); |
| | 176 | |
|
| 267 | 177 | | if (section == ExploreSection.Explore && initialized) |
| 0 | 178 | | InitializePlacesAndEventsSection(); |
| 267 | 179 | | } |
| | 180 | |
|
| | 181 | | public void SetVisibility(bool visible) => |
| 71 | 182 | | isOpen.Set(visible); |
| | 183 | |
|
| | 184 | | internal void SetVisibilityOnOpenChanged(bool open, bool _ = false) => |
| 76 | 185 | | SetVisibility_Internal(open); |
| | 186 | |
|
| | 187 | | internal void SetMenuTargetVisibility(ExploreSection section, bool toVisible, bool _ = false) |
| | 188 | | { |
| 127 | 189 | | if (toVisible) |
| | 190 | | { |
| 16 | 191 | | if (currentSectionIndex.Get() != (int)section) |
| 11 | 192 | | currentSectionIndex.Set((int)section); |
| | 193 | |
|
| 16 | 194 | | SetSectionTargetVisibility(section, toVisible: true); |
| | 195 | | } |
| 111 | 196 | | else if (currentOpenSection == section) |
| 55 | 197 | | SetSectionTargetVisibility(section, toVisible: false); |
| 111 | 198 | | } |
| | 199 | |
|
| | 200 | | private void SetSectionTargetVisibility(ExploreSection section, bool toVisible) |
| | 201 | | { |
| 71 | 202 | | bool wasInTargetVisibility = toVisible ^ isOpen.Get(); |
| | 203 | |
|
| 71 | 204 | | if (wasInTargetVisibility) |
| | 205 | | { |
| 16 | 206 | | SetVisibility(toVisible); |
| 16 | 207 | | exploreV2Analytics.SendStartMenuVisibility(toVisible, ExploreUIVisibilityMethod.FromShortcut); |
| | 208 | | } |
| | 209 | |
|
| 71 | 210 | | exploreV2Analytics.SendStartMenuSectionVisibility(section, toVisible); |
| 71 | 211 | | } |
| | 212 | |
|
| | 213 | | private void SetVisibility_Internal(bool visible) |
| | 214 | | { |
| 76 | 215 | | if (view == null || DataStore.i.common.isSignUpFlow.Get()) |
| 0 | 216 | | return; |
| | 217 | |
|
| 76 | 218 | | if (visible) |
| | 219 | | { |
| 21 | 220 | | if (mouseCatcher != null) |
| 0 | 221 | | mouseCatcher.UnlockCursor(); |
| | 222 | |
|
| 21 | 223 | | if (DataStore.i.common.isTutorialRunning.Get()) |
| 1 | 224 | | view.GoToSection(DEFAULT_SECTION); |
| | 225 | |
|
| 21 | 226 | | isPromoteChannelsToastVisible.Set(false); |
| | 227 | | } |
| | 228 | | else |
| | 229 | | { |
| 55 | 230 | | CommonScriptableObjects.isFullscreenHUDOpen.Set(false); |
| | 231 | |
|
| 660 | 232 | | foreach ((BaseVariable<bool> initVar, BaseVariable<bool> visibilityVar) sectionsVars in sectionsVariables.Va |
| 275 | 233 | | sectionsVars.visibilityVar.Set(false); |
| | 234 | |
|
| 55 | 235 | | profileCardIsOpen.Set(false); |
| | 236 | | } |
| | 237 | |
|
| 76 | 238 | | view.SetVisible(visible); |
| 76 | 239 | | } |
| | 240 | |
|
| | 241 | | private void OnSectionVisibilityChanged(BaseVariable<bool> visibilityVar, bool visible, bool previous = false) |
| | 242 | | { |
| 265 | 243 | | ExploreSection section = sectionsByVisibilityVar[visibilityVar]; |
| 265 | 244 | | BaseVariable<bool> initVar = section == ExploreSection.Explore ? isInitialized : sectionsVariables[section].init |
| | 245 | |
|
| 265 | 246 | | if (!initVar.Get() || DataStore.i.common.isSignUpFlow.Get()) |
| 153 | 247 | | return; |
| | 248 | |
|
| 112 | 249 | | SetMenuTargetVisibility(sectionsByVisibilityVar[visibilityVar], visible); |
| 112 | 250 | | } |
| | 251 | |
|
| | 252 | | private void ChangeVisibilityVarForSwitchedSections() |
| | 253 | | { |
| 120 | 254 | | foreach (BaseVariable<bool> visibilityVar in sectionsByVisibilityVar.Keys) |
| 50 | 255 | | if (visibilityVar.Get() != (currentOpenSection == sectionsByVisibilityVar[visibilityVar])) |
| 10 | 256 | | visibilityVar.Set(currentOpenSection == sectionsByVisibilityVar[visibilityVar]); |
| 10 | 257 | | } |
| | 258 | |
|
| | 259 | | internal void OnSectionOpen(ExploreSection section) |
| | 260 | | { |
| 10 | 261 | | if (section != currentOpenSection) |
| 9 | 262 | | exploreV2Analytics.SendStartMenuSectionVisibility(currentOpenSection, false); |
| | 263 | |
|
| 10 | 264 | | currentOpenSection = section; |
| | 265 | |
|
| 10 | 266 | | if (currentOpenSection == ExploreSection.Backpack) |
| 2 | 267 | | view.ConfigureEncapsulatedSection(ExploreSection.Backpack, DataStore.i.exploreV2.configureBackpackInFullscre |
| | 268 | |
|
| 10 | 269 | | ChangeVisibilityVarForSwitchedSections(); |
| | 270 | |
|
| 10 | 271 | | profileCardIsOpen.Set(false); |
| 10 | 272 | | } |
| | 273 | |
|
| | 274 | | internal void CurrentSectionIndexChanged(int current, int previous) |
| | 275 | | { |
| 340 | 276 | | if (DataStore.i.exploreV2.isInShowAnimationTransiton.Get()) |
| 0 | 277 | | return; |
| | 278 | |
|
| 340 | 279 | | if (Enum.IsDefined(typeof(ExploreSection), current)) |
| | 280 | | { |
| 270 | 281 | | if (!view.IsSectionActive((ExploreSection)current)) |
| 270 | 282 | | CurrentSectionIndexChanged(current + 1, current); |
| | 283 | | else |
| 0 | 284 | | view.GoToSection((ExploreSection)current); |
| | 285 | | } |
| | 286 | | else |
| 70 | 287 | | view.GoToSection(0); |
| 70 | 288 | | } |
| | 289 | |
|
| | 290 | | private static void OnAfterShowAnimation() => |
| 0 | 291 | | CommonScriptableObjects.isFullscreenHUDOpen.Set(true); |
| | 292 | |
|
| | 293 | | internal void UpdateProfileInfo(UserProfile profile) |
| | 294 | | { |
| 52 | 295 | | view.currentProfileCard.SetIsClaimedName(profile.hasClaimedName); |
| 52 | 296 | | view.currentProfileCard.SetProfileName(profile.userName); |
| 52 | 297 | | view.currentProfileCard.SetProfileAddress(profile.ethAddress); |
| 52 | 298 | | view.currentProfileCard.SetProfilePicture(profile.face256SnapshotURL); |
| 52 | 299 | | } |
| | 300 | |
|
| | 301 | | internal void OnCloseButtonPressed(bool fromShortcut) |
| | 302 | | { |
| 2 | 303 | | SetVisibility(false); |
| 2 | 304 | | exploreV2Analytics.SendStartMenuVisibility(false, fromShortcut ? ExploreUIVisibilityMethod.FromShortcut : Explor |
| 2 | 305 | | } |
| | 306 | | } |