| | 1 | | using DCL; |
| | 2 | | using DCL.HelpAndSupportHUD; |
| | 3 | | using DCL.Huds.QuestsPanel; |
| | 4 | | using DCL.Huds.QuestsTracker; |
| | 5 | | using DCL.QuestsController; |
| | 6 | | using DCL.SettingsPanelHUD; |
| | 7 | | using SignupHUD; |
| | 8 | | using SocialFeaturesAnalytics; |
| | 9 | | using System; |
| | 10 | | using System.Collections.Generic; |
| | 11 | | using UnityEngine; |
| | 12 | | using UnityEngine.EventSystems; |
| | 13 | |
|
| | 14 | | public class HUDController : IHUDController |
| | 15 | | { |
| | 16 | | private const string TOGGLE_UI_VISIBILITY_ASSET_NAME = "ToggleUIVisibility"; |
| | 17 | |
|
| | 18 | | static bool VERBOSE = false; |
| 0 | 19 | | public static HUDController i { get; private set; } |
| | 20 | |
|
| | 21 | | public IHUDFactory hudFactory = null; |
| | 22 | |
|
| | 23 | | private InputAction_Trigger toggleUIVisibilityTrigger; |
| | 24 | | private ISocialAnalytics socialAnalytics; |
| | 25 | |
|
| 663 | 26 | | private readonly DCL.NotificationModel.Model hiddenUINotification = new DCL.NotificationModel.Model() |
| | 27 | | { |
| | 28 | | timer = 3, |
| | 29 | | type = DCL.NotificationModel.Type.UI_HIDDEN, |
| | 30 | | groupID = "UIHiddenNotification" |
| | 31 | | }; |
| | 32 | |
|
| 663 | 33 | | public HUDController(IHUDFactory hudFactory = null) |
| | 34 | | { |
| 663 | 35 | | this.hudFactory = hudFactory; |
| 663 | 36 | | socialAnalytics = new SocialAnalytics( |
| | 37 | | DCL.Environment.i.platform.serviceProviders.analytics, |
| | 38 | | new UserProfileWebInterfaceBridge()); |
| 663 | 39 | | } |
| | 40 | |
|
| | 41 | | public void Initialize() |
| | 42 | | { |
| 663 | 43 | | i = this; |
| | 44 | |
|
| 663 | 45 | | if (this.hudFactory == null) |
| 661 | 46 | | this.hudFactory = DCL.Environment.i.hud.factory; |
| | 47 | |
|
| 663 | 48 | | toggleUIVisibilityTrigger = Resources.Load<InputAction_Trigger>(TOGGLE_UI_VISIBILITY_ASSET_NAME); |
| 663 | 49 | | toggleUIVisibilityTrigger.OnTriggered += ToggleUIVisibility_OnTriggered; |
| | 50 | |
|
| 663 | 51 | | CommonScriptableObjects.allUIHidden.OnChange += AllUIHiddenOnOnChange; |
| 663 | 52 | | UserContextMenu.OnOpenPrivateChatRequest += OpenPrivateChatWindow; |
| 663 | 53 | | } |
| | 54 | |
|
| | 55 | |
|
| | 56 | | public event Action OnTaskbarCreation; |
| | 57 | |
|
| 0 | 58 | | public ProfileHUDController profileHud => GetHUDElement(HUDElementID.PROFILE_HUD) as ProfileHUDController; |
| | 59 | |
|
| | 60 | | public NotificationHUDController notificationHud => |
| 1 | 61 | | GetHUDElement(HUDElementID.NOTIFICATION) as NotificationHUDController; |
| | 62 | |
|
| 3 | 63 | | public MinimapHUDController minimapHud => GetHUDElement(HUDElementID.MINIMAP) as MinimapHUDController; |
| | 64 | |
|
| | 65 | | public AvatarEditorHUDController avatarEditorHud => |
| 2 | 66 | | GetHUDElement(HUDElementID.AVATAR_EDITOR) as AvatarEditorHUDController; |
| | 67 | |
|
| | 68 | | public SettingsPanelHUDController settingsPanelHud => |
| 3 | 69 | | GetHUDElement(HUDElementID.SETTINGS_PANEL) as SettingsPanelHUDController; |
| | 70 | |
|
| | 71 | | public PlayerInfoCardHUDController playerInfoCardHud => |
| 0 | 72 | | GetHUDElement(HUDElementID.PLAYER_INFO_CARD) as PlayerInfoCardHUDController; |
| | 73 | |
|
| | 74 | | public AirdroppingHUDController airdroppingHud => |
| 0 | 75 | | GetHUDElement(HUDElementID.AIRDROPPING) as AirdroppingHUDController; |
| | 76 | |
|
| | 77 | | public TermsOfServiceHUDController termsOfServiceHud => |
| 0 | 78 | | GetHUDElement(HUDElementID.TERMS_OF_SERVICE) as TermsOfServiceHUDController; |
| | 79 | |
|
| 676 | 80 | | public TaskbarHUDController taskbarHud => GetHUDElement(HUDElementID.TASKBAR) as TaskbarHUDController; |
| | 81 | |
|
| 2 | 82 | | public LoadingHUDController loadingHud => GetHUDElement(HUDElementID.LOADING) as LoadingHUDController; |
| | 83 | |
|
| | 84 | | public WorldChatWindowController worldChatWindowHud => |
| 674 | 85 | | GetHUDElement(HUDElementID.WORLD_CHAT_WINDOW) as WorldChatWindowController; |
| | 86 | |
|
| | 87 | | public PrivateChatWindowController PrivateChatWindow => |
| 671 | 88 | | GetHUDElement(HUDElementID.PRIVATE_CHAT_WINDOW) as PrivateChatWindowController; |
| | 89 | |
|
| | 90 | | public PublicChatChannelController PublicChatChannelHud => |
| 673 | 91 | | GetHUDElement(HUDElementID.PUBLIC_CHAT_CHANNEL) as PublicChatChannelController; |
| | 92 | |
|
| 671 | 93 | | public FriendsHUDController friendsHud => GetHUDElement(HUDElementID.FRIENDS) as FriendsHUDController; |
| | 94 | |
|
| | 95 | | public TeleportPromptHUDController teleportHud => |
| 0 | 96 | | GetHUDElement(HUDElementID.TELEPORT_DIALOG) as TeleportPromptHUDController; |
| | 97 | |
|
| 0 | 98 | | public ControlsHUDController controlsHud => GetHUDElement(HUDElementID.CONTROLS_HUD) as ControlsHUDController; |
| | 99 | |
|
| | 100 | | public HelpAndSupportHUDController helpAndSupportHud => |
| 1 | 101 | | GetHUDElement(HUDElementID.HELP_AND_SUPPORT_HUD) as HelpAndSupportHUDController; |
| | 102 | |
|
| 0 | 103 | | public MinimapHUDController minimapHUD => GetHUDElement(HUDElementID.MINIMAP) as MinimapHUDController; |
| | 104 | |
|
| | 105 | | public VoiceChatWindowController voiceChatHud => |
| 2 | 106 | | GetHUDElement(HUDElementID.USERS_AROUND_LIST_HUD) as VoiceChatWindowController; |
| | 107 | |
|
| | 108 | | public QuestsPanelHUDController questsPanelHUD => |
| 1 | 109 | | GetHUDElement(HUDElementID.QUESTS_PANEL) as QuestsPanelHUDController; |
| | 110 | |
|
| | 111 | | public QuestsTrackerHUDController questsTrackerHUD => |
| 1 | 112 | | GetHUDElement(HUDElementID.QUESTS_TRACKER) as QuestsTrackerHUDController; |
| | 113 | |
|
| 1 | 114 | | public SignupHUDController signupHUD => GetHUDElement(HUDElementID.SIGNUP) as SignupHUDController; |
| 1 | 115 | | public LoadingHUDController loadingController => GetHUDElement(HUDElementID.LOADING) as LoadingHUDController; |
| | 116 | |
|
| 663 | 117 | | public Dictionary<HUDElementID, IHUD> hudElements { get; private set; } = new Dictionary<HUDElementID, IHUD>(); |
| | 118 | |
|
| 1 | 119 | | private UserProfile ownUserProfile => UserProfile.GetOwnUserProfile(); |
| 1 | 120 | | private BaseDictionary<string, WearableItem> wearableCatalog => CatalogController.wearableCatalog; |
| | 121 | |
|
| | 122 | | private void ShowSettings() |
| | 123 | | { |
| 0 | 124 | | settingsPanelHud?.SetVisibility(true); |
| 0 | 125 | | } |
| | 126 | |
|
| | 127 | | private void ShowControls() |
| | 128 | | { |
| 0 | 129 | | controlsHud?.SetVisibility(true); |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | private void ToggleUIVisibility_OnTriggered(DCLAction_Trigger action) |
| | 133 | | { |
| 0 | 134 | | bool anyInputFieldIsSelected = EventSystem.current != null && |
| | 135 | | EventSystem.current.currentSelectedGameObject != null && |
| | 136 | | EventSystem.current.currentSelectedGameObject |
| | 137 | | .GetComponent<TMPro.TMP_InputField>() != null; |
| | 138 | |
|
| 0 | 139 | | if (anyInputFieldIsSelected || |
| | 140 | | DataStore.i.exploreV2.isOpen.Get() || |
| | 141 | | CommonScriptableObjects.tutorialActive) |
| 0 | 142 | | return; |
| | 143 | |
|
| 0 | 144 | | CommonScriptableObjects.allUIHidden.Set(!CommonScriptableObjects.allUIHidden.Get()); |
| 0 | 145 | | } |
| | 146 | |
|
| | 147 | | private void AllUIHiddenOnOnChange(bool current, bool previous) |
| | 148 | | { |
| 3 | 149 | | if (current) |
| | 150 | | { |
| 2 | 151 | | NotificationsController.i?.ShowNotification(hiddenUINotification); |
| 2 | 152 | | } |
| | 153 | | else |
| | 154 | | { |
| 1 | 155 | | NotificationsController.i?.DismissAllNotifications(hiddenUINotification.groupID); |
| | 156 | | } |
| 1 | 157 | | } |
| | 158 | |
|
| | 159 | | public void ConfigureHUDElement(HUDElementID hudElementId, HUDConfiguration configuration, |
| | 160 | | string extraPayload = null) |
| | 161 | | { |
| | 162 | | //TODO(Brian): For now, the factory code is using this switch approach. |
| | 163 | | // In order to avoid the factory upkeep we can transform the IHUD elements |
| | 164 | | // To ScriptableObjects. In this scenario, we can make each element handle its own |
| | 165 | | // specific initialization details. |
| | 166 | | // |
| | 167 | | // This will allow us to unify the serialized factory objects design, |
| | 168 | | // like we already do with ECS components. |
| | 169 | |
|
| | 170 | | switch (hudElementId) |
| | 171 | | { |
| | 172 | | case HUDElementID.NONE: |
| | 173 | | break; |
| | 174 | | case HUDElementID.MINIMAP: |
| 1 | 175 | | if (minimapHud == null) |
| | 176 | | { |
| 1 | 177 | | CreateHudElement(configuration, hudElementId); |
| | 178 | |
|
| 1 | 179 | | if (minimapHud != null) |
| | 180 | | { |
| 1 | 181 | | minimapHud.Initialize(); |
| | 182 | | } |
| | 183 | | } |
| | 184 | |
|
| 1 | 185 | | break; |
| | 186 | | case HUDElementID.PROFILE_HUD: |
| 1 | 187 | | CreateHudElement(configuration, hudElementId); |
| 1 | 188 | | break; |
| | 189 | | case HUDElementID.NOTIFICATION: |
| 1 | 190 | | CreateHudElement(configuration, hudElementId); |
| 1 | 191 | | NotificationsController.i?.Initialize(notificationHud); |
| 1 | 192 | | break; |
| | 193 | | case HUDElementID.AVATAR_EDITOR: |
| 1 | 194 | | CreateHudElement(configuration, hudElementId); |
| 1 | 195 | | avatarEditorHud?.Initialize(ownUserProfile, wearableCatalog); |
| 1 | 196 | | break; |
| | 197 | | case HUDElementID.SETTINGS_PANEL: |
| 1 | 198 | | CreateHudElement(configuration, hudElementId); |
| 1 | 199 | | if (settingsPanelHud != null) |
| 1 | 200 | | settingsPanelHud.Initialize(); |
| 1 | 201 | | break; |
| | 202 | | case HUDElementID.PLAYER_INFO_CARD: |
| 1 | 203 | | CreateHudElement(configuration, hudElementId); |
| 1 | 204 | | break; |
| | 205 | | case HUDElementID.AIRDROPPING: |
| 1 | 206 | | CreateHudElement(configuration, hudElementId); |
| 1 | 207 | | break; |
| | 208 | | case HUDElementID.TERMS_OF_SERVICE: |
| 1 | 209 | | CreateHudElement(configuration, hudElementId); |
| 1 | 210 | | break; |
| | 211 | | case HUDElementID.WORLD_CHAT_WINDOW: |
| 1 | 212 | | if (worldChatWindowHud == null) |
| | 213 | | { |
| 1 | 214 | | CreateHudElement(configuration, hudElementId); |
| | 215 | |
|
| 1 | 216 | | if (worldChatWindowHud != null) |
| | 217 | | { |
| 1 | 218 | | worldChatWindowHud.Initialize(WorldChatWindowComponentView.Create()); |
| 1 | 219 | | worldChatWindowHud.SetVisibility(false); |
| 1 | 220 | | worldChatWindowHud.OnOpenPrivateChat -= OpenPrivateChatWindow; |
| 1 | 221 | | worldChatWindowHud.OnOpenPrivateChat += OpenPrivateChatWindow; |
| 1 | 222 | | worldChatWindowHud.OnOpenPublicChannel -= OpenPublicChannelWindow; |
| 1 | 223 | | worldChatWindowHud.OnOpenPublicChannel += OpenPublicChannelWindow; |
| | 224 | |
|
| 1 | 225 | | taskbarHud?.AddWorldChatWindow(worldChatWindowHud); |
| | 226 | | } |
| 0 | 227 | | } |
| | 228 | | else |
| 0 | 229 | | UpdateHudElement(configuration, hudElementId); |
| | 230 | |
|
| 1 | 231 | | if (PublicChatChannelHud == null) |
| | 232 | | { |
| 1 | 233 | | CreateHudElement(configuration, HUDElementID.PUBLIC_CHAT_CHANNEL); |
| 1 | 234 | | PublicChatChannelHud.Initialize(); |
| 1 | 235 | | PublicChatChannelHud.OnBack -= HandlePublicChatChannelBacked; |
| 1 | 236 | | PublicChatChannelHud.OnBack += HandlePublicChatChannelBacked; |
| 1 | 237 | | PublicChatChannelHud.OnClosed -= HandlePublicChatChannelClosed; |
| 1 | 238 | | PublicChatChannelHud.OnClosed += HandlePublicChatChannelClosed; |
| 1 | 239 | | taskbarHud?.AddPublicChatChannel(PublicChatChannelHud); |
| | 240 | | // TODO: this call should be removed when chat notifications are implemented |
| 1 | 241 | | taskbarHud?.OpenPublicChatChannel("general", false); |
| 1 | 242 | | PublicChatChannelHud.ActivatePreviewModeInstantly(); |
| 1 | 243 | | } |
| | 244 | | else |
| 0 | 245 | | UpdateHudElement(configuration, HUDElementID.PUBLIC_CHAT_CHANNEL); |
| | 246 | |
|
| 1 | 247 | | if (PrivateChatWindow == null) |
| | 248 | | { |
| 1 | 249 | | CreateHudElement(configuration, HUDElementID.PRIVATE_CHAT_WINDOW); |
| | 250 | |
|
| 1 | 251 | | if (PrivateChatWindow != null) |
| | 252 | | { |
| 1 | 253 | | PrivateChatWindow.Initialize(); |
| 1 | 254 | | PrivateChatWindow.SetVisibility(false); |
| 1 | 255 | | PrivateChatWindow.OnPressBack -= PrivateChatWindowHud_OnPressBack; |
| 1 | 256 | | PrivateChatWindow.OnPressBack += PrivateChatWindowHud_OnPressBack; |
| | 257 | |
|
| 1 | 258 | | taskbarHud?.AddPrivateChatWindow(PrivateChatWindow); |
| | 259 | | } |
| 0 | 260 | | } |
| | 261 | | else |
| 0 | 262 | | UpdateHudElement(configuration, HUDElementID.PRIVATE_CHAT_WINDOW); |
| | 263 | |
|
| 0 | 264 | | break; |
| | 265 | | case HUDElementID.FRIENDS: |
| 1 | 266 | | if (friendsHud == null) |
| | 267 | | { |
| 1 | 268 | | CreateHudElement(configuration, hudElementId); |
| | 269 | |
|
| 1 | 270 | | if (friendsHud != null) |
| | 271 | | { |
| 1 | 272 | | friendsHud.Initialize(); |
| 1 | 273 | | friendsHud.OnPressWhisper -= OpenPrivateChatWindow; |
| 1 | 274 | | friendsHud.OnPressWhisper += OpenPrivateChatWindow; |
| | 275 | |
|
| 1 | 276 | | taskbarHud?.AddFriendsWindow(friendsHud); |
| | 277 | | } |
| 1 | 278 | | } |
| | 279 | | else |
| | 280 | | { |
| 0 | 281 | | UpdateHudElement(configuration, hudElementId); |
| | 282 | |
|
| 0 | 283 | | if (!configuration.active) |
| 0 | 284 | | taskbarHud?.DisableFriendsWindow(); |
| | 285 | | } |
| | 286 | |
|
| 0 | 287 | | break; |
| | 288 | | case HUDElementID.TASKBAR: |
| 1 | 289 | | if (taskbarHud == null) |
| | 290 | | { |
| 1 | 291 | | CreateHudElement(configuration, hudElementId); |
| | 292 | |
|
| 1 | 293 | | if (taskbarHud != null) |
| | 294 | | { |
| 1 | 295 | | taskbarHud.Initialize(SceneReferences.i.mouseCatcher); |
| 1 | 296 | | taskbarHud.OnAnyTaskbarButtonClicked -= TaskbarHud_onAnyTaskbarButtonClicked; |
| 1 | 297 | | taskbarHud.OnAnyTaskbarButtonClicked += TaskbarHud_onAnyTaskbarButtonClicked; |
| | 298 | |
|
| 1 | 299 | | OnTaskbarCreation?.Invoke(); |
| | 300 | | } |
| 0 | 301 | | } |
| | 302 | | else |
| | 303 | | { |
| 0 | 304 | | UpdateHudElement(configuration, hudElementId); |
| | 305 | | } |
| | 306 | |
|
| 0 | 307 | | break; |
| | 308 | | case HUDElementID.OPEN_EXTERNAL_URL_PROMPT: |
| 1 | 309 | | CreateHudElement(configuration, hudElementId); |
| 1 | 310 | | break; |
| | 311 | | case HUDElementID.NFT_INFO_DIALOG: |
| 1 | 312 | | CreateHudElement(configuration, hudElementId); |
| 1 | 313 | | break; |
| | 314 | | case HUDElementID.TELEPORT_DIALOG: |
| 1 | 315 | | CreateHudElement(configuration, hudElementId); |
| 1 | 316 | | break; |
| | 317 | | case HUDElementID.CONTROLS_HUD: |
| 1 | 318 | | CreateHudElement(configuration, hudElementId); |
| 1 | 319 | | break; |
| | 320 | | case HUDElementID.HELP_AND_SUPPORT_HUD: |
| 1 | 321 | | CreateHudElement(configuration, hudElementId); |
| 1 | 322 | | settingsPanelHud?.AddHelpAndSupportWindow(helpAndSupportHud); |
| 1 | 323 | | break; |
| | 324 | | case HUDElementID.USERS_AROUND_LIST_HUD: |
| 1 | 325 | | CreateHudElement(configuration, hudElementId); |
| 1 | 326 | | if (voiceChatHud != null) |
| 1 | 327 | | taskbarHud?.AddVoiceChatWindow(voiceChatHud); |
| | 328 | |
|
| 1 | 329 | | break; |
| | 330 | | case HUDElementID.GRAPHIC_CARD_WARNING: |
| 1 | 331 | | CreateHudElement(configuration, hudElementId); |
| 1 | 332 | | break; |
| | 333 | | case HUDElementID.QUESTS_PANEL: |
| 1 | 334 | | CreateHudElement(configuration, hudElementId); |
| 1 | 335 | | if (configuration.active) |
| 1 | 336 | | questsPanelHUD.Initialize(QuestsController.i); |
| 1 | 337 | | break; |
| | 338 | | case HUDElementID.QUESTS_TRACKER: |
| 1 | 339 | | CreateHudElement(configuration, hudElementId); |
| 1 | 340 | | if (configuration.active) |
| 1 | 341 | | questsTrackerHUD.Initialize(QuestsController.i); |
| 1 | 342 | | break; |
| | 343 | | case HUDElementID.SIGNUP: |
| 1 | 344 | | CreateHudElement(configuration, hudElementId); |
| 1 | 345 | | if (configuration.active) |
| | 346 | | { |
| | 347 | | //Same race condition risks as with the ProfileHUD |
| | 348 | | //TODO Refactor the way AvatarEditor sets its visibility to match our data driven pattern |
| | 349 | | //Then this reference can be removed so we just work with a BaseVariable<bool>. |
| | 350 | | //This refactor applies to the ProfileHUD and the way kernel asks the HUDController during signup |
| 1 | 351 | | signupHUD.Initialize(avatarEditorHud); |
| | 352 | | } |
| | 353 | |
|
| 1 | 354 | | break; |
| | 355 | | case HUDElementID.LOADING: |
| 1 | 356 | | if (loadingHud == null) |
| | 357 | | { |
| 1 | 358 | | CreateHudElement(configuration, hudElementId); |
| 1 | 359 | | if (loadingHud != null && configuration.active) |
| 1 | 360 | | loadingController.Initialize(); |
| | 361 | | } |
| | 362 | |
|
| | 363 | | break; |
| | 364 | | case HUDElementID.AVATAR_NAMES: |
| | 365 | | // TODO Remove the HUDElementId once kernel stops sending the Configure HUD message |
| | 366 | | break; |
| | 367 | | } |
| | 368 | |
|
| 33 | 369 | | var hudElement = GetHUDElement(hudElementId); |
| | 370 | |
|
| 33 | 371 | | if (hudElement != null) |
| 24 | 372 | | hudElement.SetVisibility(configuration.active && configuration.visible); |
| 33 | 373 | | } |
| | 374 | |
|
| | 375 | | private void HandlePublicChatChannelBacked() |
| | 376 | | { |
| 0 | 377 | | PublicChatChannelHud.SetVisibility(false); |
| 0 | 378 | | taskbarHud?.GoBackFromChat(); |
| 0 | 379 | | } |
| | 380 | |
|
| | 381 | | private void OpenPublicChannelWindow(string channelId) |
| | 382 | | { |
| 0 | 383 | | taskbarHud?.OpenPublicChatChannel(channelId, true); |
| 0 | 384 | | } |
| | 385 | |
|
| | 386 | | private void OpenPrivateChatWindow(string targetUserId) |
| | 387 | | { |
| 0 | 388 | | taskbarHud?.OpenPrivateChat(targetUserId); |
| 0 | 389 | | } |
| | 390 | |
|
| | 391 | | private void PrivateChatWindowHud_OnPressBack() |
| | 392 | | { |
| 0 | 393 | | PrivateChatWindow?.SetVisibility(false); |
| 0 | 394 | | taskbarHud?.GoBackFromChat(); |
| 0 | 395 | | } |
| | 396 | |
|
| | 397 | | private void TaskbarHud_onAnyTaskbarButtonClicked() |
| | 398 | | { |
| 0 | 399 | | playerInfoCardHud?.CloseCard(); |
| 0 | 400 | | } |
| | 401 | |
|
| | 402 | | public void CreateHudElement(HUDConfiguration config, HUDElementID id) |
| | 403 | | { |
| 24 | 404 | | bool controllerCreated = hudElements.ContainsKey(id); |
| | 405 | |
|
| 24 | 406 | | if (config.active && !controllerCreated) |
| | 407 | | { |
| 24 | 408 | | hudElements.Add(id, hudFactory.CreateHUD(id)); |
| | 409 | |
|
| 24 | 410 | | if (VERBOSE) |
| 0 | 411 | | Debug.Log($"Adding {id} .. type {hudElements[id].GetType().Name}"); |
| | 412 | | } |
| 24 | 413 | | } |
| | 414 | |
|
| | 415 | | public void UpdateHudElement(HUDConfiguration config, HUDElementID id) |
| | 416 | | { |
| 0 | 417 | | if (!hudElements.ContainsKey(id)) |
| 0 | 418 | | return; |
| | 419 | |
|
| 0 | 420 | | if (VERBOSE) |
| 0 | 421 | | Debug.Log( |
| | 422 | | $"Updating {id}, type {hudElements[id].GetType().Name}, active: {config.active} visible: {config.visible |
| | 423 | |
|
| 0 | 424 | | hudElements[id].SetVisibility(config.visible); |
| 0 | 425 | | } |
| | 426 | |
|
| | 427 | | public void Cleanup() |
| | 428 | | { |
| 664 | 429 | | toggleUIVisibilityTrigger.OnTriggered -= ToggleUIVisibility_OnTriggered; |
| 664 | 430 | | CommonScriptableObjects.allUIHidden.OnChange -= AllUIHiddenOnOnChange; |
| | 431 | |
|
| 664 | 432 | | if (worldChatWindowHud != null) |
| | 433 | | { |
| 1 | 434 | | worldChatWindowHud.OnOpenPrivateChat -= OpenPrivateChatWindow; |
| 1 | 435 | | worldChatWindowHud.OnOpenPublicChannel -= OpenPublicChannelWindow; |
| | 436 | | } |
| | 437 | |
|
| 664 | 438 | | if (PrivateChatWindow != null) |
| 1 | 439 | | PrivateChatWindow.OnPressBack -= PrivateChatWindowHud_OnPressBack; |
| | 440 | |
|
| 664 | 441 | | if (PublicChatChannelHud != null) |
| | 442 | | { |
| 1 | 443 | | PublicChatChannelHud.OnClosed -= HandlePublicChatChannelClosed; |
| 1 | 444 | | PublicChatChannelHud.OnBack -= HandlePublicChatChannelBacked; |
| | 445 | | } |
| | 446 | |
|
| | 447 | |
|
| 664 | 448 | | if (friendsHud != null) |
| 1 | 449 | | friendsHud.OnPressWhisper -= OpenPrivateChatWindow; |
| | 450 | |
|
| 664 | 451 | | if (taskbarHud != null) |
| 1 | 452 | | taskbarHud.OnAnyTaskbarButtonClicked -= TaskbarHud_onAnyTaskbarButtonClicked; |
| | 453 | |
|
| 664 | 454 | | UserContextMenu.OnOpenPrivateChatRequest -= OpenPrivateChatWindow; |
| | 455 | |
|
| 1376 | 456 | | foreach (var kvp in hudElements) |
| | 457 | | { |
| 24 | 458 | | kvp.Value?.Dispose(); |
| | 459 | | } |
| | 460 | |
|
| 664 | 461 | | hudElements.Clear(); |
| 664 | 462 | | } |
| | 463 | |
|
| | 464 | | private void HandlePublicChatChannelClosed() |
| | 465 | | { |
| 0 | 466 | | PublicChatChannelHud.SetVisibility(false); |
| 0 | 467 | | } |
| | 468 | |
|
| | 469 | | public IHUD GetHUDElement(HUDElementID id) |
| | 470 | | { |
| 3507 | 471 | | if (!hudElements.ContainsKey(id)) |
| 3402 | 472 | | return null; |
| | 473 | |
|
| 105 | 474 | | return hudElements[id]; |
| | 475 | | } |
| | 476 | |
|
| | 477 | | public static bool IsHUDElementDeprecated(HUDElementID element) |
| | 478 | | { |
| 33 | 479 | | Type enumType = typeof(HUDElementID); |
| 33 | 480 | | var enumName = enumType.GetEnumName(element); |
| 33 | 481 | | var fieldInfo = enumType.GetField(enumName); |
| 33 | 482 | | return Attribute.IsDefined(fieldInfo, typeof(ObsoleteAttribute)); |
| | 483 | | } |
| | 484 | |
|
| | 485 | | #if UNITY_EDITOR |
| | 486 | | [ContextMenu("Trigger fake PlayerInfoCard")] |
| | 487 | | public void TriggerFakePlayerInfoCard() |
| | 488 | | { |
| 0 | 489 | | var newModel = ownUserProfile.CloneModel(); |
| 0 | 490 | | newModel.name = "FakePassport"; |
| 0 | 491 | | newModel.description = "Fake Description for Testing"; |
| 0 | 492 | | newModel.userId = "test-id"; |
| | 493 | |
|
| 0 | 494 | | UserProfileController.i.AddUserProfileToCatalog(newModel); |
| 0 | 495 | | UserProfileController.GetProfileByUserId(newModel.userId).SetInventory(new[] |
| | 496 | | { |
| | 497 | | "dcl://halloween_2019/machete_headband_top_head", |
| | 498 | | "dcl://halloween_2019/bee_suit_upper_body", |
| | 499 | | "dcl://halloween_2019/bride_of_frankie_upper_body", |
| | 500 | | "dcl://halloween_2019/creepy_nurse_upper_body", |
| | 501 | | }); |
| 0 | 502 | | Resources.Load<StringVariable>("CurrentPlayerInfoCardId").Set(newModel.userId); |
| 0 | 503 | | } |
| | 504 | | #endif |
| | 505 | | public void Dispose() |
| | 506 | | { |
| 663 | 507 | | Cleanup(); |
| 663 | 508 | | } |
| | 509 | | } |