< Summary

Class:ExploreV2MenuComponentController
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/MainMenu/ExploreV2Menu/ExploreV2MenuComponentController.cs
Covered lines:242
Uncovered lines:7
Coverable lines:249
Total lines:406
Line coverage:97.1% (242 of 249)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize()0%220100%
CreateControllers()0%110100%
OnSectionOpen(...)0%330100%
Dispose()0%440100%
SetVisibility(...)0%110100%
IsOpenChanged(...)0%110100%
CurrentSectionIndexChanged(...)0%4.594066.67%
SetVisibility_Internal(...)0%44094.12%
OnAfterShowAnimation()0%2100%
PlacesAndEventsVisibleChanged(...)0%440100%
IsAvatarEditorInitializedChanged(...)0%110100%
AvatarEditorVisibleChanged(...)0%550100%
IsNavMapInitializedChanged(...)0%220100%
NavmapVisibleChanged(...)0%440100%
IsBuilderInitializedChanged(...)0%220100%
BuilderVisibleChanged(...)0%440100%
IsQuestInitializedChanged(...)0%220100%
QuestVisibleChanged(...)0%440100%
IsSettingsPanelInitializedChanged(...)0%220100%
SettingsVisibleChanged(...)0%440100%
UpdateRealmInfo(...)0%11110100%
UpdateProfileInfo(...)0%110100%
OnCloseButtonPressed(...)0%440100%
CreateAnalyticsController()0%2100%
CreateView()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/MainMenu/ExploreV2Menu/ExploreV2MenuComponentController.cs

#LineLine coverage
 1using DCL;
 2using DCL.Helpers;
 3using ExploreV2Analytics;
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using UnityEngine;
 8using Variables.RealmsInfo;
 9
 10/// <summary>
 11/// Main controller for the feature "Explore V2".
 12/// </summary>
 13public class ExploreV2MenuComponentController : IExploreV2MenuComponentController
 14{
 13515    internal UserProfile ownUserProfile => UserProfile.GetOwnUserProfile();
 4516    internal RectTransform topMenuTooltipReference { get => view.currentTopMenuTooltipReference; }
 4517    internal RectTransform placesAndEventsTooltipReference { get => view.currentPlacesAndEventsTooltipReference; }
 4518    internal RectTransform backpackTooltipReference { get => view.currentBackpackTooltipReference; }
 4519    internal RectTransform mapTooltipReference { get => view.currentMapTooltipReference; }
 4520    internal RectTransform builderTooltipReference { get => view.currentBuilderTooltipReference; }
 4521    internal RectTransform questTooltipReference { get => view.currentQuestTooltipReference; }
 4522    internal RectTransform settingsTooltipReference { get => view.currentSettingsTooltipReference; }
 4523    internal RectTransform profileCardTooltipReference { get => view.currentProfileCardTooltipReference; }
 24
 25    internal IExploreV2MenuComponentView view;
 26    internal IPlacesAndEventsSectionComponentController placesAndEventsSectionController;
 27    internal IExploreV2Analytics exploreV2Analytics;
 28    internal ExploreSection currentOpenSection;
 29
 24830    internal BaseVariable<bool> isOpen => DataStore.i.exploreV2.isOpen;
 13531    internal BaseVariable<int> currentSectionIndex => DataStore.i.exploreV2.currentSectionIndex;
 6232    internal BaseVariable<bool> profileCardIsOpen => DataStore.i.exploreV2.profileCardIsOpen;
 9533    internal BaseVariable<bool> isInitialized => DataStore.i.exploreV2.isInitialized;
 19734    internal BaseVariable<bool> placesAndEventsVisible => DataStore.i.exploreV2.placesAndEventsVisible;
 18535    internal BaseVariable<bool> isAvatarEditorInitialized => DataStore.i.HUDs.isAvatarEditorInitialized;
 19736    internal BaseVariable<bool> avatarEditorVisible => DataStore.i.HUDs.avatarEditorVisible;
 18537    internal BaseVariable<bool> isNavmapInitialized => DataStore.i.HUDs.isNavMapInitialized;
 19738    internal BaseVariable<bool> navmapVisible => DataStore.i.HUDs.navmapVisible;
 18539    internal BaseVariable<bool> isBuilderInitialized => DataStore.i.builderInWorld.isInitialized;
 19740    internal BaseVariable<bool> builderVisible => DataStore.i.HUDs.builderProjectsPanelVisible;
 18541    internal BaseVariable<bool> isQuestInitialized => DataStore.i.Quests.isInitialized;
 19742    internal BaseVariable<bool> questVisible => DataStore.i.HUDs.questsPanelVisible;
 18543    internal BaseVariable<bool> isSettingsPanelInitialized => DataStore.i.settings.isInitialized;
 19744    internal BaseVariable<bool> settingsVisible => DataStore.i.settings.settingsPanelVisible;
 45
 46    public void Initialize()
 47    {
 4548        exploreV2Analytics = CreateAnalyticsController();
 4549        view = CreateView();
 4550        SetVisibility(false);
 51
 4552        DataStore.i.realm.playerRealm.OnChange += UpdateRealmInfo;
 4553        UpdateRealmInfo(DataStore.i.realm.playerRealm.Get(), null);
 54
 4555        ownUserProfile.OnUpdate += UpdateProfileInfo;
 4556        UpdateProfileInfo(ownUserProfile);
 4557        view.currentProfileCard.onClick?.AddListener(() => { profileCardIsOpen.Set(!profileCardIsOpen.Get()); });
 4558        view.OnCloseButtonPressed += OnCloseButtonPressed;
 4559        view.OnAfterShowAnimation += OnAfterShowAnimation;
 60
 4561        DataStore.i.exploreV2.topMenuTooltipReference.Set(topMenuTooltipReference);
 4562        DataStore.i.exploreV2.placesAndEventsTooltipReference.Set(placesAndEventsTooltipReference);
 4563        DataStore.i.exploreV2.backpackTooltipReference.Set(backpackTooltipReference);
 4564        DataStore.i.exploreV2.mapTooltipReference.Set(mapTooltipReference);
 4565        DataStore.i.exploreV2.builderTooltipReference.Set(builderTooltipReference);
 4566        DataStore.i.exploreV2.questTooltipReference.Set(questTooltipReference);
 4567        DataStore.i.exploreV2.settingsTooltipReference.Set(settingsTooltipReference);
 4568        DataStore.i.exploreV2.profileCardTooltipReference.Set(profileCardTooltipReference);
 69
 4570        view.OnInitialized += CreateControllers;
 4571        view.OnSectionOpen += OnSectionOpen;
 72
 4573        isOpen.OnChange += IsOpenChanged;
 4574        IsOpenChanged(isOpen.Get(), false);
 75
 4576        currentSectionIndex.OnChange += CurrentSectionIndexChanged;
 4577        CurrentSectionIndexChanged(currentSectionIndex.Get(), 0);
 78
 4579        placesAndEventsVisible.OnChange += PlacesAndEventsVisibleChanged;
 4580        PlacesAndEventsVisibleChanged(placesAndEventsVisible.Get(), false);
 81
 4582        isAvatarEditorInitialized.OnChange += IsAvatarEditorInitializedChanged;
 4583        IsAvatarEditorInitializedChanged(isAvatarEditorInitialized.Get(), false);
 4584        avatarEditorVisible.OnChange += AvatarEditorVisibleChanged;
 4585        AvatarEditorVisibleChanged(avatarEditorVisible.Get(), false);
 86
 4587        isNavmapInitialized.OnChange += IsNavMapInitializedChanged;
 4588        IsNavMapInitializedChanged(isNavmapInitialized.Get(), false);
 4589        navmapVisible.OnChange += NavmapVisibleChanged;
 4590        NavmapVisibleChanged(navmapVisible.Get(), false);
 91
 4592        isBuilderInitialized.OnChange += IsBuilderInitializedChanged;
 4593        IsBuilderInitializedChanged(isBuilderInitialized.Get(), false);
 4594        builderVisible.OnChange += BuilderVisibleChanged;
 4595        BuilderVisibleChanged(builderVisible.Get(), false);
 96
 4597        isQuestInitialized.OnChange += IsQuestInitializedChanged;
 4598        IsQuestInitializedChanged(isQuestInitialized.Get(), false);
 4599        questVisible.OnChange += QuestVisibleChanged;
 45100        QuestVisibleChanged(questVisible.Get(), false);
 101
 45102        isSettingsPanelInitialized.OnChange += IsSettingsPanelInitializedChanged;
 45103        IsSettingsPanelInitializedChanged(isSettingsPanelInitialized.Get(), false);
 45104        settingsVisible.OnChange += SettingsVisibleChanged;
 45105        SettingsVisibleChanged(settingsVisible.Get(), false);
 106
 45107        isInitialized.Set(true);
 45108    }
 109
 110    internal void CreateControllers()
 111    {
 1112        placesAndEventsSectionController = new PlacesAndEventsSectionComponentController(view.currentPlacesAndEventsSect
 1113        placesAndEventsSectionController.OnCloseExploreV2 += OnCloseButtonPressed;
 1114    }
 115
 116    internal void OnSectionOpen(ExploreSection section)
 117    {
 6118        if (section != currentOpenSection)
 5119            exploreV2Analytics.SendStartMenuSectionVisibility(currentOpenSection, false);
 120
 6121        currentOpenSection = section;
 122
 6123        if (currentOpenSection == ExploreSection.Backpack)
 124        {
 1125            view.ConfigureEncapsulatedSection(
 126                ExploreSection.Backpack,
 127                DataStore.i.exploreV2.configureBackpackInFullscreenMenu);
 128        }
 129
 6130        placesAndEventsVisible.Set(currentOpenSection == ExploreSection.Explore);
 6131        avatarEditorVisible.Set(currentOpenSection == ExploreSection.Backpack);
 6132        navmapVisible.Set(currentOpenSection == ExploreSection.Map);
 6133        builderVisible.Set(currentOpenSection == ExploreSection.Builder);
 6134        questVisible.Set(currentOpenSection == ExploreSection.Quest);
 6135        settingsVisible.Set(currentOpenSection == ExploreSection.Settings);
 6136        profileCardIsOpen.Set(false);
 6137    }
 138
 139    public void Dispose()
 140    {
 45141        DataStore.i.realm.playerRealm.OnChange -= UpdateRealmInfo;
 45142        ownUserProfile.OnUpdate -= UpdateProfileInfo;
 45143        view.currentProfileCard.onClick?.RemoveAllListeners();
 45144        isOpen.OnChange -= IsOpenChanged;
 45145        currentSectionIndex.OnChange -= CurrentSectionIndexChanged;
 45146        placesAndEventsVisible.OnChange -= PlacesAndEventsVisibleChanged;
 45147        isAvatarEditorInitialized.OnChange += IsAvatarEditorInitializedChanged;
 45148        avatarEditorVisible.OnChange -= AvatarEditorVisibleChanged;
 45149        isNavmapInitialized.OnChange -= IsNavMapInitializedChanged;
 45150        navmapVisible.OnChange -= NavmapVisibleChanged;
 45151        isBuilderInitialized.OnChange -= IsBuilderInitializedChanged;
 45152        builderVisible.OnChange -= BuilderVisibleChanged;
 45153        isQuestInitialized.OnChange -= IsQuestInitializedChanged;
 45154        questVisible.OnChange -= QuestVisibleChanged;
 45155        isSettingsPanelInitialized.OnChange -= IsSettingsPanelInitializedChanged;
 45156        settingsVisible.OnChange -= SettingsVisibleChanged;
 157
 45158        if (view != null)
 159        {
 45160            view.OnCloseButtonPressed -= OnCloseButtonPressed;
 45161            view.OnAfterShowAnimation -= OnAfterShowAnimation;
 45162            view.OnInitialized -= CreateControllers;
 45163            view.OnSectionOpen -= OnSectionOpen;
 45164            view.Dispose();
 165        }
 166
 45167        if (placesAndEventsSectionController != null)
 168        {
 1169            placesAndEventsSectionController.OnCloseExploreV2 -= OnCloseButtonPressed;
 1170            placesAndEventsSectionController.Dispose();
 171        }
 45172    }
 173
 218174    public void SetVisibility(bool visible) { isOpen.Set(visible); }
 175
 128176    internal void IsOpenChanged(bool current, bool previous) { SetVisibility_Internal(current); }
 177
 178    internal void CurrentSectionIndexChanged(int current, int previous)
 179    {
 343180        if (DataStore.i.exploreV2.isInShowAnimationTransiton.Get())
 0181            return;
 182
 343183        if (Enum.IsDefined(typeof(ExploreSection), current))
 184        {
 291185            if (!view.IsSectionActive((ExploreSection)current))
 291186                CurrentSectionIndexChanged(current + 1, current);
 187            else
 0188                view.GoToSection((ExploreSection)current);
 0189        }
 190        else
 52191            view.GoToSection(0);
 52192    }
 193
 194    internal void SetVisibility_Internal(bool visible)
 195    {
 64196        if (view == null)
 0197            return;
 198
 64199        if (visible)
 200        {
 15201            Utils.UnlockCursor();
 202
 15203            if (DataStore.i.common.isTutorialRunning.Get())
 1204                view.GoToSection(ExploreV2MenuComponentView.DEFAULT_SECTION);
 1205        }
 206        else
 207        {
 49208            CommonScriptableObjects.isFullscreenHUDOpen.Set(false);
 49209            placesAndEventsVisible.Set(false);
 49210            avatarEditorVisible.Set(false);
 49211            profileCardIsOpen.Set(false);
 49212            navmapVisible.Set(false);
 49213            builderVisible.Set(false);
 49214            questVisible.Set(false);
 49215            settingsVisible.Set(false);
 216        }
 217
 64218        view.SetVisible(visible);
 64219    }
 220
 0221    internal void OnAfterShowAnimation() { CommonScriptableObjects.isFullscreenHUDOpen.Set(true); }
 222
 223    internal void PlacesAndEventsVisibleChanged(bool current, bool previous)
 224    {
 48225        if (!isInitialized.Get())
 1226            return;
 227
 47228        if (current)
 229        {
 2230            SetVisibility(true);
 2231            view.GoToSection(ExploreSection.Explore);
 2232            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Explore, true);
 2233        }
 45234        else if (currentOpenSection == ExploreSection.Explore)
 235        {
 45236            SetVisibility(false);
 45237            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Explore, false);
 238        }
 45239    }
 240
 112241    internal void IsAvatarEditorInitializedChanged(bool current, bool previous) { view.SetSectionActive(ExploreSection.B
 242
 243    internal void AvatarEditorVisibleChanged(bool current, bool previous)
 244    {
 48245        if (!isAvatarEditorInitialized.Get() || DataStore.i.common.isSignUpFlow.Get())
 5246            return;
 247
 43248        if (current)
 249        {
 2250            SetVisibility(true);
 2251            view.GoToSection(ExploreSection.Backpack);
 2252            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Backpack, true);
 2253        }
 41254        else if (currentOpenSection == ExploreSection.Backpack)
 255        {
 1256            SetVisibility(false);
 1257            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Backpack, false);
 258        }
 41259    }
 260
 261    internal void IsNavMapInitializedChanged(bool current, bool previous)
 262    {
 48263        view.SetSectionActive(ExploreSection.Map, current);
 264
 48265        if (current)
 19266            view.ConfigureEncapsulatedSection(ExploreSection.Map, DataStore.i.exploreV2.configureMapInFullscreenMenu);
 48267    }
 268
 269    internal void NavmapVisibleChanged(bool current, bool previous)
 270    {
 48271        if (!isNavmapInitialized.Get())
 28272            return;
 273
 20274        if (current)
 275        {
 2276            SetVisibility(true);
 2277            view.GoToSection(ExploreSection.Map);
 2278            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Map, true);
 2279        }
 18280        else if (currentOpenSection == ExploreSection.Map)
 281        {
 1282            SetVisibility(false);
 1283            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Map, false);
 284        }
 18285    }
 286
 287    internal void IsBuilderInitializedChanged(bool current, bool previous)
 288    {
 48289        view.SetSectionActive(ExploreSection.Builder, current);
 290
 48291        if (current)
 40292            view.ConfigureEncapsulatedSection(ExploreSection.Builder, DataStore.i.exploreV2.configureBuilderInFullscreen
 48293    }
 294
 295    internal void BuilderVisibleChanged(bool current, bool previous)
 296    {
 48297        if (!isBuilderInitialized.Get())
 7298            return;
 299
 41300        if (current)
 301        {
 2302            SetVisibility(true);
 2303            view.GoToSection(ExploreSection.Builder);
 2304            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Builder, true);
 2305        }
 39306        else if (currentOpenSection == ExploreSection.Builder)
 307        {
 1308            SetVisibility(false);
 1309            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Builder, false);
 310        }
 39311    }
 312
 313    internal void IsQuestInitializedChanged(bool current, bool previous)
 314    {
 48315        view.SetSectionActive(ExploreSection.Quest, current);
 316
 48317        if (current)
 9318            view.ConfigureEncapsulatedSection(ExploreSection.Quest, DataStore.i.exploreV2.configureQuestInFullscreenMenu
 48319    }
 320
 321    internal void QuestVisibleChanged(bool current, bool previous)
 322    {
 48323        if (!isQuestInitialized.Get())
 39324            return;
 325
 9326        if (current)
 327        {
 1328            SetVisibility(true);
 1329            view.GoToSection(ExploreSection.Quest);
 1330            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Quest, true);
 1331        }
 8332        else if (currentOpenSection == ExploreSection.Quest)
 333        {
 1334            SetVisibility(false);
 1335            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Quest, false);
 336        }
 8337    }
 338
 339    internal void IsSettingsPanelInitializedChanged(bool current, bool previous)
 340    {
 48341        view.SetSectionActive(ExploreSection.Settings, current);
 342
 48343        if (current)
 7344            view.ConfigureEncapsulatedSection(ExploreSection.Settings, DataStore.i.exploreV2.configureSettingsInFullscre
 48345    }
 346
 347    internal void SettingsVisibleChanged(bool current, bool previous)
 348    {
 48349        if (!isSettingsPanelInitialized.Get())
 41350            return;
 351
 7352        if (current)
 353        {
 1354            SetVisibility(true);
 1355            view.GoToSection(ExploreSection.Settings);
 1356            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Settings, true);
 1357        }
 6358        else if (currentOpenSection == ExploreSection.Settings)
 359        {
 1360            SetVisibility(false);
 1361            exploreV2Analytics.SendStartMenuSectionVisibility(ExploreSection.Settings, false);
 362        }
 6363    }
 364
 365    internal void UpdateRealmInfo(CurrentRealmModel currentRealm, CurrentRealmModel previousRealm)
 366    {
 367        // Get the name of the current realm
 47368        string currentRealmServer = currentRealm?.serverName;
 47369        string currentRealmLayer = currentRealm?.layer;
 47370        string formattedRealmName = currentRealmServer;
 47371        if (!string.IsNullOrEmpty(currentRealmLayer))
 372        {
 2373            formattedRealmName = $"{formattedRealmName}-{currentRealmLayer}";
 374        }
 375
 47376        view.currentRealmViewer.SetRealm(formattedRealmName);
 377
 378        // Calculate number of users in the current realm
 47379        List<RealmModel> realmList = DataStore.i.realm.realmsInfo.Get()?.ToList();
 48380        RealmModel currentRealmModel = realmList?.FirstOrDefault(r => r.serverName == currentRealmServer && (r.layer == 
 47381        int realmUsers = 0;
 47382        if (currentRealmModel != null)
 1383            realmUsers = currentRealmModel.usersCount;
 384
 47385        view.currentRealmViewer.SetNumberOfUsers(realmUsers);
 47386    }
 387
 388    internal void UpdateProfileInfo(UserProfile profile)
 389    {
 46390        view.currentProfileCard.SetProfileName(profile.userName);
 46391        view.currentProfileCard.SetProfileAddress(profile.ethAddress);
 46392        view.currentProfileCard.SetProfilePicture(profile.face128SnapshotURL);
 46393    }
 394
 395    internal void OnCloseButtonPressed(bool fromShortcut)
 396    {
 2397        if (isOpen.Get())
 2398            exploreV2Analytics.SendStartMenuVisibility(false, fromShortcut ? ExploreUIVisibilityMethod.FromShortcut : Ex
 399
 2400        SetVisibility(false);
 2401    }
 402
 0403    internal virtual IExploreV2Analytics CreateAnalyticsController() => new ExploreV2Analytics.ExploreV2Analytics();
 404
 0405    internal virtual IExploreV2MenuComponentView CreateView() => ExploreV2MenuComponentView.Create();
 406}

Methods/Properties

ownUserProfile()
topMenuTooltipReference()
placesAndEventsTooltipReference()
backpackTooltipReference()
mapTooltipReference()
builderTooltipReference()
questTooltipReference()
settingsTooltipReference()
profileCardTooltipReference()
isOpen()
currentSectionIndex()
profileCardIsOpen()
isInitialized()
placesAndEventsVisible()
isAvatarEditorInitialized()
avatarEditorVisible()
isNavmapInitialized()
navmapVisible()
isBuilderInitialized()
builderVisible()
isQuestInitialized()
questVisible()
isSettingsPanelInitialized()
settingsVisible()
Initialize()
CreateControllers()
OnSectionOpen(ExploreSection)
Dispose()
SetVisibility(System.Boolean)
IsOpenChanged(System.Boolean, System.Boolean)
CurrentSectionIndexChanged(System.Int32, System.Int32)
SetVisibility_Internal(System.Boolean)
OnAfterShowAnimation()
PlacesAndEventsVisibleChanged(System.Boolean, System.Boolean)
IsAvatarEditorInitializedChanged(System.Boolean, System.Boolean)
AvatarEditorVisibleChanged(System.Boolean, System.Boolean)
IsNavMapInitializedChanged(System.Boolean, System.Boolean)
NavmapVisibleChanged(System.Boolean, System.Boolean)
IsBuilderInitializedChanged(System.Boolean, System.Boolean)
BuilderVisibleChanged(System.Boolean, System.Boolean)
IsQuestInitializedChanged(System.Boolean, System.Boolean)
QuestVisibleChanged(System.Boolean, System.Boolean)
IsSettingsPanelInitializedChanged(System.Boolean, System.Boolean)
SettingsVisibleChanged(System.Boolean, System.Boolean)
UpdateRealmInfo(Variables.RealmsInfo.CurrentRealmModel, Variables.RealmsInfo.CurrentRealmModel)
UpdateProfileInfo(UserProfile)
OnCloseButtonPressed(System.Boolean)
CreateAnalyticsController()
CreateView()