| | 1 | | using UnityEngine; |
| | 2 | | using System; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Interface; |
| | 5 | |
|
| | 6 | | public class ExploreHUDController : IHUD |
| | 7 | | { |
| | 8 | | internal static bool isTest = false; |
| | 9 | |
|
| | 10 | | internal ExploreHUDView view; |
| | 11 | | internal InputAction_Trigger toggleExploreTrigger; |
| | 12 | |
|
| | 13 | | FriendTrackerController friendsController; |
| | 14 | |
|
| | 15 | | public event Action OnToggleTriggered; |
| | 16 | | public event Action OnOpen; |
| | 17 | | public event Action OnClose; |
| | 18 | |
|
| 4 | 19 | | public ExploreHUDController() |
| | 20 | | { |
| 4 | 21 | | view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("ExploreHUD")).GetComponent<ExploreHUDView>(); |
| 4 | 22 | | view.name = "_ExploreHUD"; |
| 4 | 23 | | view.popup.gameObject.SetActive(false); |
| | 24 | |
|
| 4 | 25 | | toggleExploreTrigger = Resources.Load<InputAction_Trigger>("ToggleExploreHud"); |
| 4 | 26 | | toggleExploreTrigger.OnTriggered += OnToggleActionTriggered; |
| | 27 | |
|
| 4 | 28 | | view.OnCloseButtonPressed += () => |
| | 29 | | { |
| 0 | 30 | | if (view.IsVisible()) |
| | 31 | | { |
| 0 | 32 | | toggleExploreTrigger.RaiseOnTriggered(); |
| | 33 | | } |
| 0 | 34 | | }; |
| | 35 | |
|
| 4 | 36 | | view.gotoMagicButton.OnGotoMagicPressed += GoToMagic; |
| 4 | 37 | | view.togglePopupButton.onPointerDown += () => toggleExploreTrigger.RaiseOnTriggered(); |
| 4 | 38 | | HotSceneCellView.OnJumpIn += OnJumpIn; |
| 4 | 39 | | } |
| | 40 | |
|
| | 41 | | public void Initialize(IFriendsController friendsController) |
| | 42 | | { |
| 4 | 43 | | this.friendsController = new FriendTrackerController(friendsController, view.friendColors); |
| | 44 | |
|
| 4 | 45 | | view.Initialize(this.friendsController); |
| 4 | 46 | | view.togglePopupButton.gameObject.SetActive(false); |
| 4 | 47 | | } |
| | 48 | |
|
| | 49 | | public void SetVisibility(bool visible) |
| | 50 | | { |
| 4 | 51 | | if (view == null) |
| | 52 | | { |
| 0 | 53 | | return; |
| | 54 | | } |
| | 55 | |
|
| 4 | 56 | | if (visible && !view.IsActive()) |
| | 57 | | { |
| 3 | 58 | | Utils.UnlockCursor(); |
| 3 | 59 | | view.RefreshData(); |
| 3 | 60 | | OnOpen?.Invoke(); |
| 1 | 61 | | } |
| 1 | 62 | | else if (!visible && view.IsActive()) |
| | 63 | | { |
| 1 | 64 | | OnClose?.Invoke(); |
| | 65 | | } |
| | 66 | |
|
| 4 | 67 | | view.SetVisibility(visible); |
| | 68 | |
|
| 4 | 69 | | if (visible) |
| | 70 | | { |
| 3 | 71 | | AudioScriptableObjects.dialogOpen.Play(true); |
| 3 | 72 | | AudioScriptableObjects.listItemAppear.ResetPitch(); |
| 3 | 73 | | } |
| | 74 | | else |
| 1 | 75 | | AudioScriptableObjects.dialogClose.Play(true); |
| 1 | 76 | | } |
| | 77 | |
|
| | 78 | | public void Dispose() |
| | 79 | | { |
| 12 | 80 | | friendsController?.Dispose(); |
| | 81 | |
|
| 12 | 82 | | toggleExploreTrigger.OnTriggered -= OnToggleActionTriggered; |
| 12 | 83 | | HotSceneCellView.OnJumpIn -= OnJumpIn; |
| | 84 | |
|
| 12 | 85 | | if (view != null) |
| | 86 | | { |
| 4 | 87 | | view.gotoMagicButton.OnGotoMagicPressed -= GoToMagic; |
| 4 | 88 | | GameObject.Destroy(view.gameObject); |
| | 89 | | } |
| 12 | 90 | | } |
| | 91 | |
|
| | 92 | | void OnToggleActionTriggered(DCLAction_Trigger action) |
| | 93 | | { |
| 1 | 94 | | if (view) |
| | 95 | | { |
| 1 | 96 | | SetVisibility(!view.IsVisible()); |
| 1 | 97 | | OnToggleTriggered?.Invoke(); |
| | 98 | | } |
| 1 | 99 | | } |
| | 100 | |
|
| | 101 | | void OnJumpIn(Vector2Int coords, string serverName, string layerName) |
| | 102 | | { |
| 0 | 103 | | if (view.IsVisible()) |
| | 104 | | { |
| 0 | 105 | | toggleExploreTrigger.RaiseOnTriggered(); |
| | 106 | | } |
| | 107 | |
|
| 0 | 108 | | if (string.IsNullOrEmpty(serverName)) |
| | 109 | | { |
| 0 | 110 | | WebInterface.GoTo(coords.x, coords.y); |
| 0 | 111 | | } |
| | 112 | | else |
| | 113 | | { |
| 0 | 114 | | WebInterface.JumpIn(coords.x, coords.y, serverName, layerName); |
| | 115 | | } |
| 0 | 116 | | } |
| | 117 | |
|
| | 118 | | void GoToMagic() |
| | 119 | | { |
| 0 | 120 | | if (view.IsVisible()) |
| | 121 | | { |
| 0 | 122 | | toggleExploreTrigger.RaiseOnTriggered(); |
| | 123 | | } |
| | 124 | |
|
| 0 | 125 | | WebInterface.GoToMagic(); |
| 0 | 126 | | } |
| | 127 | | } |