| | 1 | | using UnityEngine; |
| | 2 | | using System; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Interface; |
| | 5 | |
|
| | 6 | | public class TeleportPromptHUDController : IHUD |
| | 7 | | { |
| | 8 | | const string TELEPORT_COMMAND_MAGIC = "magic"; |
| | 9 | | const string TELEPORT_COMMAND_CROWD = "crowd"; |
| | 10 | |
|
| | 11 | | const string EVENT_STRING_LIVE = "Current event"; |
| | 12 | | const string EVENT_STRING_TODAY = "Today @ {0:HH:mm}"; |
| | 13 | |
|
| 0 | 14 | | internal TeleportPromptHUDView view { get; private set; } |
| | 15 | |
|
| | 16 | | TeleportData teleportData; |
| | 17 | |
|
| 3 | 18 | | public TeleportPromptHUDController() |
| | 19 | | { |
| 3 | 20 | | view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("TeleportPromptHUD")).GetComponent<TeleportProm |
| 3 | 21 | | view.name = "_TeleportPromptHUD"; |
| 3 | 22 | | view.content.SetActive(false); |
| 3 | 23 | | view.OnTeleportEvent += OnTeleportPressed; |
| 3 | 24 | | } |
| | 25 | |
|
| | 26 | | public void SetVisibility(bool visible) |
| | 27 | | { |
| 2 | 28 | | if (view.contentAnimator.isVisible && !visible) |
| | 29 | | { |
| 0 | 30 | | view.contentAnimator.Hide(); |
| 0 | 31 | | } |
| 2 | 32 | | else if (!view.contentAnimator.isVisible && visible) |
| | 33 | | { |
| 2 | 34 | | view.content.SetActive(true); |
| 2 | 35 | | view.contentAnimator.Show(); |
| | 36 | |
|
| 2 | 37 | | AudioScriptableObjects.fadeIn.Play(true); |
| | 38 | | } |
| 2 | 39 | | } |
| | 40 | |
|
| | 41 | | public void RequestTeleport(string teleportDataJson) |
| | 42 | | { |
| 1 | 43 | | if (view.contentAnimator.isVisible) |
| 0 | 44 | | return; |
| | 45 | |
|
| 1 | 46 | | Utils.UnlockCursor(); |
| | 47 | |
|
| 1 | 48 | | view.Reset(); |
| 1 | 49 | | SetVisibility(true); |
| | 50 | |
|
| 1 | 51 | | teleportData = Utils.SafeFromJson<TeleportData>(teleportDataJson); |
| | 52 | |
|
| 1 | 53 | | switch (teleportData.destination) |
| | 54 | | { |
| | 55 | | case TELEPORT_COMMAND_MAGIC: |
| 1 | 56 | | view.ShowTeleportToMagic(); |
| 1 | 57 | | break; |
| | 58 | | case TELEPORT_COMMAND_CROWD: |
| 0 | 59 | | view.ShowTeleportToCrowd(); |
| 0 | 60 | | break; |
| | 61 | | default: |
| 0 | 62 | | view.ShowTeleportToCoords(teleportData.destination, |
| | 63 | | teleportData.sceneData.name, |
| | 64 | | teleportData.sceneData.owner, |
| | 65 | | teleportData.sceneData.previewImageUrl); |
| 0 | 66 | | SetSceneEvent(); |
| | 67 | | break; |
| | 68 | | } |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | public void Dispose() |
| | 72 | | { |
| 3 | 73 | | if (view) |
| | 74 | | { |
| 3 | 75 | | UnityEngine.Object.Destroy(view.gameObject); |
| | 76 | | } |
| 3 | 77 | | } |
| | 78 | |
|
| | 79 | | private void SetSceneEvent() |
| | 80 | | { |
| 0 | 81 | | EventData eventData = teleportData.sceneEvent; |
| | 82 | |
|
| 0 | 83 | | if (eventData == null) |
| 0 | 84 | | return; |
| | 85 | |
|
| 0 | 86 | | DateTime dateNow = DateTime.Now; |
| | 87 | | DateTime eventStart; |
| | 88 | | DateTime eventEnd; |
| 0 | 89 | | if (DateTime.TryParse(eventData.start_at, out eventStart) && DateTime.TryParse(eventData.finish_at, out eventEnd |
| | 90 | | { |
| 0 | 91 | | bool startsToday = eventStart.Date == dateNow.Date; |
| 0 | 92 | | bool isNow = eventStart <= dateNow && dateNow <= eventEnd; |
| | 93 | |
|
| 0 | 94 | | if (isNow || startsToday) |
| | 95 | | { |
| 0 | 96 | | string eventStatus = EVENT_STRING_LIVE; |
| 0 | 97 | | if (!isNow && startsToday) |
| 0 | 98 | | eventStatus = string.Format(EVENT_STRING_TODAY, eventStart); |
| 0 | 99 | | view.SetEventInfo(eventData.name, eventStatus, eventData.total_attendees); |
| | 100 | | } |
| | 101 | | } |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | private void OnTeleportPressed() |
| | 105 | | { |
| 0 | 106 | | switch (teleportData.destination) |
| | 107 | | { |
| | 108 | | case TELEPORT_COMMAND_CROWD: |
| 0 | 109 | | WebInterface.GoToCrowd(); |
| 0 | 110 | | break; |
| | 111 | | case TELEPORT_COMMAND_MAGIC: |
| 0 | 112 | | WebInterface.GoToMagic(); |
| 0 | 113 | | break; |
| | 114 | | default: |
| | 115 | | int x, y; |
| 0 | 116 | | string[] coordSplit = teleportData.destination.Split(','); |
| 0 | 117 | | if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out x) && int.TryParse(coordSplit[1], out y)) |
| | 118 | | { |
| 0 | 119 | | WebInterface.GoTo(x, y); |
| | 120 | | } |
| | 121 | |
|
| | 122 | | break; |
| | 123 | | } |
| 0 | 124 | | } |
| | 125 | |
|
| | 126 | | [Serializable] |
| | 127 | | internal class TeleportData |
| | 128 | | { |
| 1 | 129 | | public string destination = ""; |
| | 130 | | public MinimapMetadata.MinimapSceneInfo sceneData = null; |
| | 131 | | public EventData sceneEvent = null; |
| | 132 | | } |
| | 133 | |
|
| | 134 | | [Serializable] |
| | 135 | | internal class EventData |
| | 136 | | { |
| | 137 | | public string name; |
| | 138 | | public int total_attendees; |
| | 139 | | public string start_at; |
| | 140 | | public string finish_at; |
| | 141 | | } |
| | 142 | | } |