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