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