| | 1 | | using DCL; |
| | 2 | | using DCL.Interface; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCLPlugins.RealmPlugin |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Controller for the Jump to Home logic. |
| | 10 | | /// Its used to chose the most populated realm to jump home to |
| | 11 | | /// </summary> |
| | 12 | | public class JumpToHomeController : MonoBehaviour |
| | 13 | | { |
| | 14 | | [SerializeField] private Button jumpButton; |
| | 15 | | [SerializeField] private ShowHideAnimator showHideAnimator; |
| | 16 | | [SerializeField] private RectTransform positionWithMiniMap; |
| | 17 | | [SerializeField] private RectTransform positionWithoutMiniMap; |
| | 18 | |
|
| 2 | 19 | | private BaseVariable<bool> jumpHomeButtonVisible => DataStore.i.HUDs.jumpHomeButtonVisible; |
| 0 | 20 | | private BaseVariable<bool> minimapVisible => DataStore.i.HUDs.minimapVisible; |
| 0 | 21 | | private BaseVariable<bool> exitedThroughButton => DataStore.i.common.exitedWorldThroughGoBackButton; |
| | 22 | |
|
| | 23 | | private RectTransform rectTransform; |
| | 24 | |
|
| | 25 | | private void Start() |
| | 26 | | { |
| 1 | 27 | | rectTransform = jumpButton.GetComponent<RectTransform>(); |
| 1 | 28 | | jumpButton.onClick.AddListener(GoHome); |
| | 29 | |
|
| 1 | 30 | | SetVisibility(jumpHomeButtonVisible.Get(), false); |
| 1 | 31 | | jumpHomeButtonVisible.OnChange += SetVisibility; |
| 1 | 32 | | } |
| | 33 | |
|
| | 34 | | private void SetVisibility(bool current, bool _) |
| | 35 | | { |
| 1 | 36 | | if (current) |
| | 37 | | { |
| 0 | 38 | | jumpButton.interactable = true; |
| 0 | 39 | | rectTransform.anchoredPosition = minimapVisible.Get() ? positionWithMiniMap.anchoredPosition : positionW |
| 0 | 40 | | showHideAnimator.Show(); |
| | 41 | | } |
| | 42 | | else |
| 1 | 43 | | showHideAnimator.Hide(); |
| 1 | 44 | | } |
| | 45 | |
|
| | 46 | | private void GoHome() |
| | 47 | | { |
| 0 | 48 | | jumpButton.interactable = false; |
| 0 | 49 | | exitedThroughButton.Set(true); |
| 0 | 50 | | WebInterface.SendChatMessage(new ChatMessage |
| | 51 | | { |
| | 52 | | messageType = ChatMessage.Type.NONE, |
| | 53 | | recipient = string.Empty, |
| | 54 | | body = "/goto home", |
| | 55 | | }); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | private void OnDestroy() => |
| 10 | 59 | | jumpButton.onClick.RemoveListener(GoHome); |
| | 60 | | } |
| | 61 | | } |