| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using UnityEngine; |
| | 6 | | using DCL; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using SocialFeaturesAnalytics; |
| | 9 | |
|
| | 10 | | namespace DCL.Social.Passports |
| | 11 | | { |
| | 12 | | public class PlayerPassportHUDController : IHUD |
| | 13 | | { |
| | 14 | | internal readonly IPlayerPassportHUDView view; |
| | 15 | | internal readonly StringVariable currentPlayerId; |
| | 16 | | internal readonly IUserProfileBridge userProfileBridge; |
| | 17 | | private readonly ISocialAnalytics socialAnalytics; |
| | 18 | |
|
| | 19 | | internal UserProfile currentUserProfile; |
| | 20 | |
|
| | 21 | | private readonly InputAction_Trigger closeWindowTrigger; |
| | 22 | |
|
| | 23 | | private PassportPlayerInfoComponentController playerInfoController; |
| | 24 | | private PassportPlayerPreviewComponentController playerPreviewController; |
| | 25 | | private PassportNavigationComponentController passportNavigationController; |
| | 26 | |
|
| 2 | 27 | | public PlayerPassportHUDController( |
| | 28 | | IPlayerPassportHUDView view, |
| | 29 | | PassportPlayerInfoComponentController playerInfoController, |
| | 30 | | PassportPlayerPreviewComponentController playerPreviewController, |
| | 31 | | PassportNavigationComponentController passportNavigationController, |
| | 32 | | StringVariable currentPlayerId, |
| | 33 | | IUserProfileBridge userProfileBridge, |
| | 34 | | ISocialAnalytics socialAnalytics) |
| | 35 | | { |
| 2 | 36 | | this.view = view; |
| 2 | 37 | | this.playerInfoController = playerInfoController; |
| 2 | 38 | | this.playerPreviewController = playerPreviewController; |
| 2 | 39 | | this.passportNavigationController = passportNavigationController; |
| 2 | 40 | | this.currentPlayerId = currentPlayerId; |
| 2 | 41 | | this.userProfileBridge = userProfileBridge; |
| 2 | 42 | | this.socialAnalytics = socialAnalytics; |
| | 43 | |
|
| 2 | 44 | | view.Initialize(); |
| 2 | 45 | | view.OnClose += RemoveCurrentPlayer; |
| | 46 | |
|
| 2 | 47 | | closeWindowTrigger = Resources.Load<InputAction_Trigger>("CloseWindow"); |
| 2 | 48 | | closeWindowTrigger.OnTriggered -= OnCloseButtonPressed; |
| 2 | 49 | | closeWindowTrigger.OnTriggered += OnCloseButtonPressed; |
| | 50 | |
|
| 2 | 51 | | currentPlayerId.OnChange += OnCurrentPlayerIdChanged; |
| 2 | 52 | | OnCurrentPlayerIdChanged(currentPlayerId, null); |
| 2 | 53 | | } |
| | 54 | |
|
| | 55 | | public void SetVisibility(bool visible) |
| | 56 | | { |
| 2 | 57 | | view.SetVisibility(visible); |
| 2 | 58 | | } |
| | 59 | |
|
| | 60 | | private void OnCloseButtonPressed(DCLAction_Trigger action = DCLAction_Trigger.CloseWindow) |
| | 61 | | { |
| 0 | 62 | | RemoveCurrentPlayer(); |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | public void Dispose() |
| | 66 | | { |
| 2 | 67 | | closeWindowTrigger.OnTriggered -= OnCloseButtonPressed; |
| 2 | 68 | | currentPlayerId.OnChange -= OnCurrentPlayerIdChanged; |
| 2 | 69 | | if (view != null) |
| 2 | 70 | | view.Dispose(); |
| 2 | 71 | | } |
| | 72 | |
|
| | 73 | | private void OnCurrentPlayerIdChanged(string current, string previous) |
| | 74 | | { |
| 2 | 75 | | if (currentUserProfile != null) |
| 0 | 76 | | currentUserProfile.OnUpdate -= UpdateUserProfile; |
| | 77 | |
|
| 2 | 78 | | currentUserProfile = string.IsNullOrEmpty(current) |
| | 79 | | ? null |
| | 80 | | : userProfileBridge.Get(current); |
| | 81 | |
|
| 2 | 82 | | if (currentUserProfile == null) |
| | 83 | | { |
| 2 | 84 | | view.SetPassportPanelVisibility(false); |
| | 85 | | } |
| | 86 | | else |
| | 87 | | { |
| 0 | 88 | | userProfileBridge.RequestFullUserProfile(currentUserProfile.userId); |
| 0 | 89 | | currentUserProfile.OnUpdate += UpdateUserProfile; |
| 0 | 90 | | view.SetPassportPanelVisibility(true); |
| 0 | 91 | | UpdateUserProfileInSubpanels(currentUserProfile); |
| | 92 | | } |
| 0 | 93 | | } |
| | 94 | |
|
| 0 | 95 | | private void UpdateUserProfile(UserProfile userProfile) => UpdateUserProfileInSubpanels(userProfile); |
| | 96 | |
|
| | 97 | | private void UpdateUserProfileInSubpanels(UserProfile userProfile) |
| | 98 | | { |
| 0 | 99 | | playerInfoController.UpdateWithUserProfile(userProfile); |
| 0 | 100 | | passportNavigationController.UpdateWithUserProfile(userProfile); |
| 0 | 101 | | } |
| | 102 | |
|
| | 103 | | private void RemoveCurrentPlayer() |
| | 104 | | { |
| 0 | 105 | | currentPlayerId.Set(null); |
| 0 | 106 | | } |
| | 107 | |
|
| | 108 | | } |
| | 109 | | } |