| | 1 | | using DCL; |
| | 2 | | using DCL.Interface; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace GotoPanel |
| | 6 | | { |
| | 7 | | public class GotoPanelHUDController |
| | 8 | | { |
| 0 | 9 | | internal IGotoPanelHUDView view { get; private set; } |
| | 10 | |
|
| 0 | 11 | | internal virtual IGotoPanelHUDView CreateView() => GotoPanelHUDView.CreateView(); |
| | 12 | |
|
| | 13 | | public void Initialize() |
| | 14 | | { |
| 4 | 15 | | view = CreateView(); |
| 4 | 16 | | view.OnTeleportPressed += Teleport; |
| 4 | 17 | | view.OnClosePressed += ClosePanel; |
| 4 | 18 | | DataStore.i.HUDs.gotoPanelVisible.OnChange += ChangeVisibility; |
| 4 | 19 | | DataStore.i.HUDs.gotoPanelCoordinates.OnChange += SetCoordinates; |
| 4 | 20 | | } |
| | 21 | |
|
| | 22 | | private void ChangeVisibility(bool current, bool previous) |
| | 23 | | { |
| 2 | 24 | | SetVisibility(current); |
| 2 | 25 | | } |
| | 26 | |
|
| | 27 | | private void SetCoordinates(ParcelCoordinates current, ParcelCoordinates previous) |
| | 28 | | { |
| 1 | 29 | | if (current == previous) |
| 0 | 30 | | return; |
| | 31 | |
|
| 1 | 32 | | view.SetPanelInfo(current); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | public void Dispose() |
| | 36 | | { |
| 0 | 37 | | view.OnTeleportPressed -= Teleport; |
| 0 | 38 | | view.OnClosePressed -= ClosePanel; |
| 0 | 39 | | DataStore.i.HUDs.gotoPanelVisible.OnChange -= ChangeVisibility; |
| 0 | 40 | | DataStore.i.HUDs.gotoPanelCoordinates.OnChange -= SetCoordinates; |
| 0 | 41 | | view?.Dispose(); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public void SetVisibility(bool visible) |
| | 45 | | { |
| 2 | 46 | | view.SetVisible(visible); |
| 2 | 47 | | } |
| | 48 | |
|
| | 49 | | public void Teleport(ParcelCoordinates parcelCoordinates) |
| | 50 | | { |
| 0 | 51 | | WebInterface.GoTo(parcelCoordinates.x, parcelCoordinates.y); |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | public void ClosePanel() |
| | 55 | | { |
| 0 | 56 | | DataStore.i.HUDs.gotoPanelVisible.Set(false); |
| 0 | 57 | | AudioScriptableObjects.dialogClose.Play(true); |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | } |
| | 61 | | } |