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