| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Chat; |
| | 4 | | using DCL.Social.Chat; |
| | 5 | | using DCL.HelpAndSupportHUD; |
| | 6 | | using DCL.NotificationModel; |
| | 7 | | using DCL.SettingsPanelHUD; |
| | 8 | | using DCL.Social.Chat; |
| | 9 | | using DCL.Social.Friends; |
| | 10 | | using System; |
| | 11 | | using System.Collections.Generic; |
| | 12 | | using System.Threading; |
| | 13 | | using UnityEngine; |
| | 14 | | using Environment = DCL.Environment; |
| | 15 | | using Object = UnityEngine.Object; |
| | 16 | | using Type = DCL.NotificationModel.Type; |
| | 17 | |
|
| | 18 | | public class HUDController : IHUDController |
| | 19 | | { |
| | 20 | | private const string TOGGLE_UI_VISIBILITY_ASSET_NAME = "ToggleUIVisibility"; |
| | 21 | | private const string OPEN_PASSPORT_SOURCE = "ProfileHUD"; |
| | 22 | |
|
| | 23 | | static bool VERBOSE = false; |
| 427 | 24 | | public static HUDController i { get; private set; } |
| | 25 | |
|
| | 26 | | public IHUDFactory hudFactory = null; |
| | 27 | |
|
| | 28 | | private InputAction_Trigger toggleUIVisibilityTrigger; |
| | 29 | | private DataStore dataStore; |
| | 30 | |
|
| 427 | 31 | | private readonly Model hiddenUINotification = new Model() |
| | 32 | | { |
| | 33 | | timer = 3, |
| | 34 | | type = Type.UI_HIDDEN, |
| | 35 | | groupID = "UIHiddenNotification" |
| | 36 | | }; |
| | 37 | |
|
| 427 | 38 | | public HUDController(DataStore dataStore, IHUDFactory hudFactory = null) |
| | 39 | | { |
| 427 | 40 | | this.hudFactory = hudFactory; |
| 427 | 41 | | this.dataStore = dataStore; |
| 427 | 42 | | } |
| | 43 | |
|
| | 44 | | public void Initialize() |
| | 45 | | { |
| 427 | 46 | | i = this; |
| | 47 | |
|
| 427 | 48 | | if (this.hudFactory == null) |
| 425 | 49 | | this.hudFactory = Environment.i.hud.factory; |
| | 50 | |
|
| 427 | 51 | | toggleUIVisibilityTrigger = Resources.Load<InputAction_Trigger>(TOGGLE_UI_VISIBILITY_ASSET_NAME); |
| 427 | 52 | | toggleUIVisibilityTrigger.OnTriggered += ToggleUIVisibility_OnTriggered; |
| | 53 | |
|
| 427 | 54 | | CommonScriptableObjects.allUIHidden.OnChange += ToggleAllUIHiddenNotification; |
| 427 | 55 | | UserContextMenu.OnOpenPrivateChatRequest += OpenPrivateChatWindow; |
| 427 | 56 | | } |
| | 57 | |
|
| | 58 | |
|
| | 59 | | public event Action OnTaskbarCreation; |
| | 60 | |
|
| 0 | 61 | | public ProfileHUDController profileHud => GetHUDElement(HUDElementID.PROFILE_HUD) as ProfileHUDController; |
| | 62 | |
|
| | 63 | | public NotificationHUDController notificationHud => |
| 0 | 64 | | GetHUDElement(HUDElementID.NOTIFICATION) as NotificationHUDController; |
| | 65 | |
|
| 2 | 66 | | public MinimapHUDController minimapHud => GetHUDElement(HUDElementID.MINIMAP) as MinimapHUDController; |
| | 67 | |
|
| | 68 | | public SettingsPanelHUDController settingsPanelHud => |
| 2 | 69 | | GetHUDElement(HUDElementID.SETTINGS_PANEL) as SettingsPanelHUDController; |
| | 70 | |
|
| | 71 | |
|
| | 72 | | public TermsOfServiceHUDController termsOfServiceHud => |
| 0 | 73 | | GetHUDElement(HUDElementID.TERMS_OF_SERVICE) as TermsOfServiceHUDController; |
| | 74 | |
|
| 443 | 75 | | public TaskbarHUDController taskbarHud => GetHUDElement(HUDElementID.TASKBAR) as TaskbarHUDController; |
| | 76 | |
|
| | 77 | | public WorldChatWindowController worldChatWindowHud => |
| 443 | 78 | | GetHUDElement(HUDElementID.WORLD_CHAT_WINDOW) as WorldChatWindowController; |
| | 79 | |
|
| | 80 | | public PrivateChatWindowController PrivateChatWindow => |
| 435 | 81 | | GetHUDElement(HUDElementID.PRIVATE_CHAT_WINDOW) as PrivateChatWindowController; |
| | 82 | |
|
| | 83 | | public PublicChatWindowController PublicChatWindowHud => |
| 439 | 84 | | GetHUDElement(HUDElementID.PUBLIC_CHAT) as PublicChatWindowController; |
| | 85 | |
|
| | 86 | | private ChatChannelHUDController chatChannelHud => |
| 6 | 87 | | GetHUDElement(HUDElementID.CHANNELS_CHAT) as ChatChannelHUDController; |
| | 88 | |
|
| | 89 | | private SearchChannelsWindowController channelSearchHud => |
| 4 | 90 | | GetHUDElement(HUDElementID.CHANNELS_SEARCH) as SearchChannelsWindowController; |
| | 91 | |
|
| | 92 | | private CreateChannelWindowController channelCreateHud => |
| 4 | 93 | | GetHUDElement(HUDElementID.CHANNELS_CREATE) as CreateChannelWindowController; |
| | 94 | |
|
| | 95 | | private LeaveChannelConfirmationWindowController channelLeaveHud => |
| 4 | 96 | | GetHUDElement(HUDElementID.CHANNELS_LEAVE_CONFIRMATION) as LeaveChannelConfirmationWindowController; |
| | 97 | |
|
| 435 | 98 | | public FriendsHUDController friendsHud => GetHUDElement(HUDElementID.FRIENDS) as FriendsHUDController; |
| | 99 | |
|
| 0 | 100 | | public ControlsHUDController controlsHud => GetHUDElement(HUDElementID.CONTROLS_HUD) as ControlsHUDController; |
| | 101 | |
|
| | 102 | | public HelpAndSupportHUDController helpAndSupportHud => |
| 1 | 103 | | GetHUDElement(HUDElementID.HELP_AND_SUPPORT_HUD) as HelpAndSupportHUDController; |
| | 104 | |
|
| 0 | 105 | | public MinimapHUDController minimapHUD => GetHUDElement(HUDElementID.MINIMAP) as MinimapHUDController; |
| | 106 | |
|
| | 107 | | public VoiceChatWindowController voiceChatHud => |
| 2 | 108 | | GetHUDElement(HUDElementID.USERS_AROUND_LIST_HUD) as VoiceChatWindowController; |
| | 109 | |
|
| 3722 | 110 | | public Dictionary<HUDElementID, IHUD> hudElements { get; private set; } = new Dictionary<HUDElementID, IHUD>(); |
| | 111 | |
|
| 0 | 112 | | private UserProfile ownUserProfile => UserProfile.GetOwnUserProfile(); |
| | 113 | |
|
| | 114 | | private void ShowSettings() |
| | 115 | | { |
| 0 | 116 | | settingsPanelHud?.SetVisibility(true); |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | | private void ShowControls() |
| | 120 | | { |
| 0 | 121 | | controlsHud?.SetVisibility(true); |
| 0 | 122 | | } |
| | 123 | |
|
| | 124 | | private void ToggleUIVisibility_OnTriggered(DCLAction_Trigger action) |
| | 125 | | { |
| 0 | 126 | | bool anyInputFieldIsSelected = InputProcessor.FocusIsInInputField(); |
| | 127 | |
|
| 0 | 128 | | if (anyInputFieldIsSelected || |
| | 129 | | dataStore.exploreV2.isOpen.Get() || |
| | 130 | | CommonScriptableObjects.tutorialActive) |
| 0 | 131 | | return; |
| | 132 | |
|
| 0 | 133 | | CommonScriptableObjects.allUIHidden.Set(!CommonScriptableObjects.allUIHidden.Get()); |
| 0 | 134 | | } |
| | 135 | |
|
| | 136 | | public void ToggleAllUIHiddenNotification(bool isHidden, bool _) |
| | 137 | | { |
| 0 | 138 | | if (isHidden) |
| 0 | 139 | | NotificationsController.i?.ShowNotification(hiddenUINotification); |
| | 140 | | else |
| 0 | 141 | | NotificationsController.i?.DismissAllNotifications(hiddenUINotification.groupID); |
| 0 | 142 | | } |
| | 143 | |
|
| | 144 | | public async UniTask ConfigureHUDElement(HUDElementID hudElementId, HUDConfiguration configuration, CancellationToke |
| | 145 | | string extraPayload = null) |
| | 146 | | { |
| | 147 | | switch (hudElementId) |
| | 148 | | { |
| | 149 | | case HUDElementID.NONE: |
| | 150 | | break; |
| | 151 | | case HUDElementID.MINIMAP: |
| 1 | 152 | | if (minimapHud == null) |
| | 153 | | { |
| | 154 | | // dependencies should be initialized |
| 3 | 155 | | await Environment.WaitUntilInitialized(); |
| 1 | 156 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 157 | | minimapHud?.Initialize(); |
| | 158 | | } |
| | 159 | |
|
| 1 | 160 | | break; |
| | 161 | | case HUDElementID.PROFILE_HUD: |
| 1 | 162 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 163 | | break; |
| | 164 | | case HUDElementID.NOTIFICATION: |
| 3 | 165 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 166 | | if (NotificationsController.i != null) |
| 0 | 167 | | NotificationsController.i.Initialize(notificationHud, dataStore.notifications); |
| 0 | 168 | | break; |
| | 169 | | case HUDElementID.SETTINGS_PANEL: |
| 1 | 170 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 171 | | settingsPanelHud?.Initialize(); |
| 1 | 172 | | break; |
| | 173 | | case HUDElementID.TERMS_OF_SERVICE: |
| 1 | 174 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 175 | | break; |
| | 176 | | case HUDElementID.WORLD_CHAT_WINDOW: |
| 1 | 177 | | if (worldChatWindowHud == null) |
| | 178 | | { |
| 1 | 179 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| | 180 | |
|
| 1 | 181 | | if (worldChatWindowHud != null) |
| | 182 | | { |
| 3 | 183 | | worldChatWindowHud.Initialize( |
| | 184 | | await hudFactory.CreateHUDView<WorldChatWindowComponentView>("ConversationListHUD", cancella |
| | 185 | |
|
| 1 | 186 | | worldChatWindowHud.SetVisibility(false); |
| 1 | 187 | | worldChatWindowHud.OnOpenPrivateChat -= OpenPrivateChatWindow; |
| 1 | 188 | | worldChatWindowHud.OnOpenPrivateChat += OpenPrivateChatWindow; |
| 1 | 189 | | worldChatWindowHud.OnOpenPublicChat -= OpenPublicChatWindow; |
| 1 | 190 | | worldChatWindowHud.OnOpenPublicChat += OpenPublicChatWindow; |
| 1 | 191 | | worldChatWindowHud.OnOpenChannel -= OpenChannelChatWindow; |
| 1 | 192 | | worldChatWindowHud.OnOpenChannel += OpenChannelChatWindow; |
| 1 | 193 | | worldChatWindowHud.OnOpenChannelSearch -= OpenChannelSearchWindow; |
| 1 | 194 | | worldChatWindowHud.OnOpenChannelSearch += OpenChannelSearchWindow; |
| | 195 | |
|
| 1 | 196 | | taskbarHud?.AddWorldChatWindow(worldChatWindowHud); |
| | 197 | | } |
| | 198 | | } |
| | 199 | | else |
| 0 | 200 | | UpdateHudElement(configuration, hudElementId); |
| | 201 | |
|
| 1 | 202 | | if (PublicChatWindowHud == null) |
| | 203 | | { |
| 1 | 204 | | await CreateHudElement(configuration, HUDElementID.PUBLIC_CHAT, cancellationToken); |
| | 205 | |
|
| 1 | 206 | | if (PublicChatWindowHud != null) |
| | 207 | | { |
| 3 | 208 | | PublicChatWindowHud.Initialize( |
| | 209 | | await hudFactory.CreateHUDView<PublicChatWindowComponentView>("NearbyChatChannelHUD", ca |
| | 210 | |
|
| 1 | 211 | | PublicChatWindowHud.Setup(ChatUtils.NEARBY_CHANNEL_ID); |
| 1 | 212 | | PublicChatWindowHud.SetVisibility(false); |
| 1 | 213 | | PublicChatWindowHud.OnBack -= HandlePublicChatChannelBacked; |
| 1 | 214 | | PublicChatWindowHud.OnBack += HandlePublicChatChannelBacked; |
| 1 | 215 | | PublicChatWindowHud.OnClosed -= HandlePublicChatChannelClosed; |
| 1 | 216 | | PublicChatWindowHud.OnClosed += HandlePublicChatChannelClosed; |
| 1 | 217 | | taskbarHud?.AddPublicChatChannel(PublicChatWindowHud); |
| | 218 | | } |
| | 219 | | } |
| | 220 | | else |
| 0 | 221 | | UpdateHudElement(configuration, HUDElementID.PUBLIC_CHAT); |
| | 222 | |
|
| 1 | 223 | | if (PrivateChatWindow == null) |
| | 224 | | { |
| 1 | 225 | | await CreateHudElement(configuration, HUDElementID.PRIVATE_CHAT_WINDOW, cancellationToken); |
| | 226 | |
|
| 1 | 227 | | if (PrivateChatWindow != null) |
| | 228 | | { |
| 3 | 229 | | PrivateChatWindow.Initialize( |
| | 230 | | await hudFactory.CreateHUDView<PrivateChatWindowComponentView>("PrivateChatHUD", cancellatio |
| | 231 | |
|
| 1 | 232 | | PrivateChatWindow.SetVisibility(false); |
| 1 | 233 | | PrivateChatWindow.OnBack -= PrivateChatWindowHud_OnPressBack; |
| 1 | 234 | | PrivateChatWindow.OnBack += PrivateChatWindowHud_OnPressBack; |
| 1 | 235 | | taskbarHud?.AddPrivateChatWindow(PrivateChatWindow); |
| | 236 | | } |
| | 237 | | } |
| | 238 | | else |
| 0 | 239 | | UpdateHudElement(configuration, HUDElementID.PRIVATE_CHAT_WINDOW); |
| | 240 | |
|
| 1 | 241 | | if (chatChannelHud == null) |
| | 242 | | { |
| 1 | 243 | | await CreateHudElement(configuration, HUDElementID.CHANNELS_CHAT, cancellationToken); |
| | 244 | |
|
| 1 | 245 | | if (chatChannelHud != null) |
| | 246 | | { |
| 3 | 247 | | chatChannelHud.Initialize( |
| | 248 | | await hudFactory.CreateHUDView<ChatChannelComponentView>("ChatChannelHUD", cancellationToken |
| | 249 | |
|
| 1 | 250 | | chatChannelHud.SetVisibility(false); |
| 1 | 251 | | chatChannelHud.OnPressBack -= HandleChannelBacked; |
| 1 | 252 | | chatChannelHud.OnPressBack += HandleChannelBacked; |
| | 253 | |
|
| 1 | 254 | | taskbarHud?.AddChatChannel(chatChannelHud); |
| | 255 | | } |
| | 256 | | } |
| | 257 | |
|
| 1 | 258 | | if (channelSearchHud == null) |
| | 259 | | { |
| 1 | 260 | | await CreateHudElement(configuration, HUDElementID.CHANNELS_SEARCH, cancellationToken); |
| | 261 | |
|
| 1 | 262 | | if (channelSearchHud != null) |
| | 263 | | { |
| 3 | 264 | | channelSearchHud.Initialize( |
| | 265 | | await hudFactory.CreateHUDView<SearchChannelsWindowComponentView>("ChannelSearchHUD", cancel |
| 1 | 266 | | channelSearchHud.SetVisibility(false); |
| 1 | 267 | | taskbarHud?.AddChannelSearch(channelSearchHud); |
| | 268 | | } |
| | 269 | | } |
| | 270 | |
|
| 1 | 271 | | if (channelCreateHud == null) |
| | 272 | | { |
| 1 | 273 | | await CreateHudElement(configuration, HUDElementID.CHANNELS_CREATE, cancellationToken); |
| | 274 | |
|
| 1 | 275 | | if (channelCreateHud != null) |
| | 276 | | { |
| 3 | 277 | | channelCreateHud.Initialize( |
| | 278 | | await hudFactory.CreateHUDView<CreateChannelWindowComponentView>("ChannelCreationHUD", cance |
| 1 | 279 | | channelCreateHud.SetVisibility(false); |
| 1 | 280 | | taskbarHud?.AddChannelCreation(channelCreateHud); |
| | 281 | | } |
| | 282 | | } |
| | 283 | |
|
| 1 | 284 | | if (channelLeaveHud == null) |
| | 285 | | { |
| 1 | 286 | | await CreateHudElement(configuration, HUDElementID.CHANNELS_LEAVE_CONFIRMATION, cancellationToken); |
| | 287 | |
|
| 1 | 288 | | if (channelLeaveHud != null) |
| | 289 | | { |
| 3 | 290 | | channelLeaveHud.Initialize( |
| | 291 | | await hudFactory.CreateHUDView<LeaveChannelConfirmationWindowComponentView>("LeaveChannelCon |
| 1 | 292 | | channelLeaveHud.SetVisibility(false); |
| 1 | 293 | | taskbarHud?.AddChannelLeaveConfirmation(channelLeaveHud); |
| | 294 | | } |
| | 295 | | } |
| | 296 | |
|
| 0 | 297 | | break; |
| | 298 | | case HUDElementID.FRIENDS: |
| 1 | 299 | | if (friendsHud == null) |
| | 300 | | { |
| 1 | 301 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| | 302 | |
|
| 1 | 303 | | if (friendsHud != null) |
| | 304 | | { |
| 3 | 305 | | friendsHud.Initialize( |
| | 306 | | await hudFactory.CreateHUDView<FriendsHUDComponentView>("FriendsHUD", cancellationToken)); |
| 1 | 307 | | friendsHud.OnPressWhisper -= OpenPrivateChatWindow; |
| 1 | 308 | | friendsHud.OnPressWhisper += OpenPrivateChatWindow; |
| | 309 | |
|
| 1 | 310 | | taskbarHud?.AddFriendsWindow(friendsHud); |
| | 311 | | } |
| | 312 | | } |
| | 313 | | else |
| | 314 | | { |
| 0 | 315 | | UpdateHudElement(configuration, hudElementId); |
| | 316 | |
|
| 0 | 317 | | if (!configuration.active) |
| 0 | 318 | | taskbarHud?.DisableFriendsWindow(); |
| | 319 | | } |
| | 320 | |
|
| 0 | 321 | | break; |
| | 322 | | case HUDElementID.TASKBAR: |
| 1 | 323 | | if (taskbarHud == null) |
| | 324 | | { |
| 1 | 325 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| | 326 | |
|
| 1 | 327 | | if (taskbarHud != null) |
| | 328 | | { |
| 1 | 329 | | taskbarHud.Initialize(SceneReferences.i.mouseCatcher); |
| 1 | 330 | | taskbarHud.OnAnyTaskbarButtonClicked -= TaskbarHud_onAnyTaskbarButtonClicked; |
| 1 | 331 | | taskbarHud.OnAnyTaskbarButtonClicked += TaskbarHud_onAnyTaskbarButtonClicked; |
| | 332 | |
|
| 1 | 333 | | OnTaskbarCreation?.Invoke(); |
| | 334 | | } |
| | 335 | | } |
| | 336 | | else |
| | 337 | | { |
| 0 | 338 | | UpdateHudElement(configuration, hudElementId); |
| | 339 | | } |
| | 340 | |
|
| 0 | 341 | | break; |
| | 342 | | case HUDElementID.OPEN_EXTERNAL_URL_PROMPT: |
| 1 | 343 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 344 | | break; |
| | 345 | | case HUDElementID.NFT_INFO_DIALOG: |
| 1 | 346 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 347 | | break; |
| | 348 | | case HUDElementID.CONTROLS_HUD: |
| 1 | 349 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 350 | | break; |
| | 351 | | case HUDElementID.HELP_AND_SUPPORT_HUD: |
| 3 | 352 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 353 | | settingsPanelHud?.AddHelpAndSupportWindow(helpAndSupportHud); |
| 1 | 354 | | break; |
| | 355 | | case HUDElementID.USERS_AROUND_LIST_HUD: |
| 1 | 356 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| 1 | 357 | | if (voiceChatHud != null) |
| 1 | 358 | | taskbarHud?.AddVoiceChatWindow(voiceChatHud); |
| | 359 | |
|
| 1 | 360 | | break; |
| | 361 | | case HUDElementID.GRAPHIC_CARD_WARNING: |
| 1 | 362 | | await CreateHudElement(configuration, hudElementId, cancellationToken); |
| | 363 | | break; |
| | 364 | | case HUDElementID.AVATAR_NAMES: |
| | 365 | | // TODO Remove the HUDElementId once kernel stops sending the Configure HUD message |
| | 366 | | break; |
| | 367 | | } |
| | 368 | |
|
| 20 | 369 | | GetHUDElement(hudElementId)? |
| | 370 | | .SetVisibility(configuration.active && configuration.visible); |
| 20 | 371 | | } |
| | 372 | |
|
| | 373 | | private void OpenChannelSearchWindow() |
| | 374 | | { |
| 0 | 375 | | taskbarHud?.OpenChannelSearch(); |
| 0 | 376 | | } |
| | 377 | |
|
| | 378 | | private void HandleChannelBacked() |
| | 379 | | { |
| 0 | 380 | | chatChannelHud.SetVisibility(false); |
| 0 | 381 | | taskbarHud?.GoBackFromChat(); |
| 0 | 382 | | } |
| | 383 | |
|
| | 384 | | private void HandlePublicChatChannelBacked() |
| | 385 | | { |
| 0 | 386 | | PublicChatWindowHud.SetVisibility(false); |
| 0 | 387 | | taskbarHud?.GoBackFromChat(); |
| 0 | 388 | | } |
| | 389 | |
|
| | 390 | | private void OpenPublicChatWindow(string channelId) |
| | 391 | | { |
| 0 | 392 | | taskbarHud?.OpenPublicChat(channelId, true); |
| 0 | 393 | | } |
| | 394 | |
|
| | 395 | | private void OpenChannelChatWindow(string channelId) |
| | 396 | | { |
| 0 | 397 | | taskbarHud?.OpenChannelChat(channelId); |
| 0 | 398 | | } |
| | 399 | |
|
| | 400 | | private void OpenPrivateChatWindow(string targetUserId) |
| | 401 | | { |
| 0 | 402 | | taskbarHud?.OpenPrivateChat(targetUserId); |
| 0 | 403 | | } |
| | 404 | |
|
| | 405 | | private void PrivateChatWindowHud_OnPressBack() |
| | 406 | | { |
| 0 | 407 | | PrivateChatWindow?.SetVisibility(false); |
| 0 | 408 | | taskbarHud?.GoBackFromChat(); |
| 0 | 409 | | } |
| | 410 | |
|
| | 411 | | private void TaskbarHud_onAnyTaskbarButtonClicked() |
| | 412 | | { |
| 0 | 413 | | } |
| | 414 | |
|
| | 415 | | private async UniTask CreateHudElement(HUDConfiguration config, HUDElementID id, CancellationToken cancellationToken |
| | 416 | | { |
| 20 | 417 | | bool controllerCreated = hudElements.ContainsKey(id); |
| | 418 | |
|
| 20 | 419 | | if (config.active && !controllerCreated) |
| | 420 | | { |
| | 421 | | try |
| | 422 | | { |
| 24 | 423 | | IHUD hudElement = await hudFactory.CreateHUD(id, cancellationToken); |
| 20 | 424 | | hudElements.Add(id, hudElement); |
| | 425 | |
|
| 20 | 426 | | if (VERBOSE) |
| 0 | 427 | | Debug.Log($"Adding {id} .. type {hudElements[id].GetType().Name}"); |
| 20 | 428 | | } |
| 0 | 429 | | catch (Exception e) |
| | 430 | | { |
| 0 | 431 | | Debug.LogWarning($"Failed to load HUD element resource {id}. Exception message: {e.Message}"); |
| 0 | 432 | | } |
| | 433 | | } |
| 20 | 434 | | } |
| | 435 | |
|
| | 436 | | private void UpdateHudElement(HUDConfiguration config, HUDElementID id) |
| | 437 | | { |
| 0 | 438 | | if (!hudElements.ContainsKey(id)) |
| 0 | 439 | | return; |
| | 440 | |
|
| 0 | 441 | | if (VERBOSE) |
| 0 | 442 | | Debug.Log($"Updating {id}, type {hudElements[id].GetType().Name}, active: {config.active} visible: {config.v |
| | 443 | |
|
| 0 | 444 | | hudElements[id].SetVisibility(config.visible); |
| 0 | 445 | | } |
| | 446 | |
|
| | 447 | | public void Cleanup() |
| | 448 | | { |
| 428 | 449 | | toggleUIVisibilityTrigger.OnTriggered -= ToggleUIVisibility_OnTriggered; |
| 428 | 450 | | CommonScriptableObjects.allUIHidden.OnChange -= ToggleAllUIHiddenNotification; |
| | 451 | |
|
| 428 | 452 | | if (worldChatWindowHud != null) |
| | 453 | | { |
| 1 | 454 | | worldChatWindowHud.OnOpenPrivateChat -= OpenPrivateChatWindow; |
| 1 | 455 | | worldChatWindowHud.OnOpenPublicChat -= OpenPublicChatWindow; |
| 1 | 456 | | worldChatWindowHud.OnOpenChannel -= OpenChannelChatWindow; |
| | 457 | | } |
| | 458 | |
|
| 428 | 459 | | if (PrivateChatWindow != null) |
| 1 | 460 | | PrivateChatWindow.OnBack -= PrivateChatWindowHud_OnPressBack; |
| | 461 | |
|
| 428 | 462 | | if (PublicChatWindowHud != null) |
| | 463 | | { |
| 1 | 464 | | PublicChatWindowHud.OnClosed -= HandlePublicChatChannelClosed; |
| 1 | 465 | | PublicChatWindowHud.OnBack -= HandlePublicChatChannelBacked; |
| | 466 | | } |
| | 467 | |
|
| | 468 | |
|
| 428 | 469 | | if (friendsHud != null) |
| 1 | 470 | | friendsHud.OnPressWhisper -= OpenPrivateChatWindow; |
| | 471 | |
|
| 428 | 472 | | if (taskbarHud != null) |
| 1 | 473 | | taskbarHud.OnAnyTaskbarButtonClicked -= TaskbarHud_onAnyTaskbarButtonClicked; |
| | 474 | |
|
| 428 | 475 | | UserContextMenu.OnOpenPrivateChatRequest -= OpenPrivateChatWindow; |
| | 476 | |
|
| 896 | 477 | | foreach (var kvp in hudElements) |
| | 478 | | { |
| 20 | 479 | | kvp.Value?.Dispose(); |
| | 480 | | } |
| | 481 | |
|
| 428 | 482 | | hudElements.Clear(); |
| 428 | 483 | | } |
| | 484 | |
|
| | 485 | | private void HandlePublicChatChannelClosed() |
| | 486 | | { |
| 0 | 487 | | PublicChatWindowHud.SetVisibility(false); |
| 0 | 488 | | } |
| | 489 | |
|
| | 490 | | public IHUD GetHUDElement(HUDElementID id) => |
| 2291 | 491 | | hudElements.ContainsKey(id) ? hudElements[id] : null; |
| | 492 | |
|
| | 493 | | public static bool IsHUDElementDeprecated(HUDElementID element) |
| | 494 | | { |
| 31 | 495 | | System.Type enumType = typeof(HUDElementID); |
| 31 | 496 | | var enumName = enumType.GetEnumName(element); |
| 31 | 497 | | var fieldInfo = enumType.GetField(enumName); |
| 31 | 498 | | return Attribute.IsDefined(fieldInfo, typeof(ObsoleteAttribute)); |
| | 499 | | } |
| | 500 | |
|
| | 501 | | #if UNITY_EDITOR |
| | 502 | | [ContextMenu("Trigger fake PlayerInfoCard")] |
| | 503 | | public void TriggerFakePlayerInfoCard() |
| | 504 | | { |
| 0 | 505 | | var newModel = ownUserProfile.CloneModel(); |
| 0 | 506 | | newModel.name = "FakePassport"; |
| 0 | 507 | | newModel.description = "Fake Description for Testing"; |
| 0 | 508 | | newModel.userId = "test-id"; |
| | 509 | |
|
| 0 | 510 | | UserProfileController.i.AddUserProfileToCatalog(newModel); |
| 0 | 511 | | UserProfileController.GetProfileByUserId(newModel.userId).SetInventory(new[] |
| | 512 | | { |
| | 513 | | "dcl://halloween_2019/machete_headband_top_head", |
| | 514 | | "dcl://halloween_2019/bee_suit_upper_body", |
| | 515 | | "dcl://halloween_2019/bride_of_frankie_upper_body", |
| | 516 | | "dcl://halloween_2019/creepy_nurse_upper_body", |
| | 517 | | }); |
| 0 | 518 | | dataStore.HUDs.currentPlayerId.Set((newModel.userId, OPEN_PASSPORT_SOURCE)); |
| 0 | 519 | | } |
| | 520 | | #endif |
| | 521 | | public void Dispose() |
| | 522 | | { |
| 427 | 523 | | Cleanup(); |
| 427 | 524 | | } |
| | 525 | | } |