| | 1 | | using DCL; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using Variables.RealmsInfo; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Main controller for the feature "Explore V2". |
| | 8 | | /// </summary> |
| | 9 | | public class ExploreV2MenuComponentController : IExploreV2MenuComponentController |
| | 10 | | { |
| 27 | 11 | | internal UserProfile ownUserProfile => UserProfile.GetOwnUserProfile(); |
| | 12 | |
|
| | 13 | | internal IExploreV2MenuComponentView view; |
| | 14 | | internal IPlacesAndEventsSectionComponentController placesAndEventsSectionController; |
| | 15 | |
|
| | 16 | | public void Initialize() |
| | 17 | | { |
| 9 | 18 | | view = CreateView(); |
| 9 | 19 | | SetVisibility(false); |
| | 20 | |
|
| 9 | 21 | | DataStore.i.playerRealm.OnChange += UpdateRealmInfo; |
| 9 | 22 | | UpdateRealmInfo(DataStore.i.playerRealm.Get(), null); |
| | 23 | |
|
| 9 | 24 | | ownUserProfile.OnUpdate += UpdateProfileInfo; |
| 9 | 25 | | UpdateProfileInfo(ownUserProfile); |
| | 26 | |
|
| 9 | 27 | | view.OnCloseButtonPressed += OnCloseButtonPressed; |
| 9 | 28 | | DataStore.i.taskbar.isExploreV2Enabled.OnChange += OnActivateFromTaskbar; |
| 9 | 29 | | DataStore.i.exploreV2.isInitialized.Set(true); |
| | 30 | |
|
| 9 | 31 | | view.OnInitialized += CreateControllers; |
| 9 | 32 | | } |
| | 33 | |
|
| | 34 | | internal void CreateControllers() |
| | 35 | | { |
| 1 | 36 | | placesAndEventsSectionController = new PlacesAndEventsSectionComponentController(view.currentPlacesAndEventsSect |
| 1 | 37 | | placesAndEventsSectionController.OnCloseExploreV2 += OnCloseButtonPressed; |
| 1 | 38 | | } |
| | 39 | |
|
| | 40 | | public void Dispose() |
| | 41 | | { |
| 9 | 42 | | DataStore.i.playerRealm.OnChange -= UpdateRealmInfo; |
| 9 | 43 | | ownUserProfile.OnUpdate -= UpdateProfileInfo; |
| | 44 | |
|
| 9 | 45 | | if (view != null) |
| | 46 | | { |
| 9 | 47 | | view.OnCloseButtonPressed -= OnCloseButtonPressed; |
| 9 | 48 | | view.OnInitialized -= CreateControllers; |
| 9 | 49 | | view.Dispose(); |
| | 50 | | } |
| | 51 | |
|
| 9 | 52 | | DataStore.i.taskbar.isExploreV2Enabled.OnChange -= OnActivateFromTaskbar; |
| | 53 | |
|
| 9 | 54 | | if (placesAndEventsSectionController != null) |
| | 55 | | { |
| 1 | 56 | | placesAndEventsSectionController.OnCloseExploreV2 -= OnCloseButtonPressed; |
| 1 | 57 | | placesAndEventsSectionController.Dispose(); |
| | 58 | | } |
| 9 | 59 | | } |
| | 60 | |
|
| | 61 | | public void SetVisibility(bool visible) |
| | 62 | | { |
| 14 | 63 | | if (view == null) |
| 0 | 64 | | return; |
| | 65 | |
|
| 14 | 66 | | if (visible && !view.isActive) |
| 2 | 67 | | DataStore.i.exploreV2.isOpen.Set(true); |
| 12 | 68 | | else if (!visible && view.isActive) |
| 0 | 69 | | DataStore.i.exploreV2.isOpen.Set(false); |
| | 70 | |
|
| 14 | 71 | | view.SetActive(visible); |
| 14 | 72 | | } |
| | 73 | |
|
| | 74 | | internal void UpdateRealmInfo(CurrentRealmModel currentRealm, CurrentRealmModel previousRealm) |
| | 75 | | { |
| | 76 | | // Get the name of the current realm |
| 11 | 77 | | string currentRealmServer = currentRealm?.serverName; |
| 11 | 78 | | string currentRealmLayer = currentRealm?.layer; |
| 11 | 79 | | string formattedRealmName = currentRealmServer; |
| 11 | 80 | | if (!string.IsNullOrEmpty(currentRealmLayer)) |
| | 81 | | { |
| 2 | 82 | | formattedRealmName = $"{formattedRealmName}-{currentRealmLayer}"; |
| | 83 | | } |
| | 84 | |
|
| 11 | 85 | | view.currentRealmViewer.SetRealm(formattedRealmName); |
| | 86 | |
|
| | 87 | | // Calculate number of users in the current realm |
| 11 | 88 | | List<RealmModel> realmList = DataStore.i.realmsInfo.Get()?.ToList(); |
| 12 | 89 | | RealmModel currentRealmModel = realmList?.FirstOrDefault(r => r.serverName == currentRealmServer && (r.layer == |
| 11 | 90 | | int realmUsers = 0; |
| 11 | 91 | | if (currentRealmModel != null) |
| 1 | 92 | | realmUsers = currentRealmModel.usersCount; |
| | 93 | |
|
| 11 | 94 | | view.currentRealmViewer.SetNumberOfUsers(realmUsers); |
| 11 | 95 | | } |
| | 96 | |
|
| | 97 | | internal void UpdateProfileInfo(UserProfile profile) |
| | 98 | | { |
| 10 | 99 | | view.currentProfileCard.SetProfileName(profile.userName); |
| 10 | 100 | | view.currentProfileCard.SetProfileAddress(profile.ethAddress); |
| 10 | 101 | | view.currentProfileCard.SetProfilePicture(profile.face128SnapshotURL); |
| 10 | 102 | | } |
| | 103 | |
|
| 2 | 104 | | internal void OnCloseButtonPressed() { SetVisibility(false); } |
| | 105 | |
|
| 4 | 106 | | internal void OnActivateFromTaskbar(bool current, bool previous) { SetVisibility(current); } |
| | 107 | |
|
| 0 | 108 | | internal virtual IExploreV2MenuComponentView CreateView() => ExploreV2MenuComponentView.Create(); |
| | 109 | | } |