| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.UI; |
| | 3 | | using TMPro; |
| | 4 | |
|
| | 5 | | internal class SceneInfoView : MonoBehaviour |
| | 6 | | { |
| | 7 | | [SerializeField] float idleTime; |
| | 8 | | [SerializeField] RawImageFillParent thumbnail; |
| | 9 | | [SerializeField] TextMeshProUGUI sceneName; |
| | 10 | | [SerializeField] TextMeshProUGUI coordinates; |
| | 11 | | [SerializeField] TextMeshProUGUI creatorName; |
| | 12 | | [SerializeField] TextMeshProUGUI description; |
| | 13 | | [SerializeField] Button_OnPointerDown jumpIn; |
| | 14 | | [SerializeField] ShowHideAnimator showHideAnimator; |
| | 15 | | [SerializeField] UIHoverCallback hoverArea; |
| | 16 | | [SerializeField] GameObject loadingSpinner; |
| | 17 | |
|
| | 18 | | private float timer; |
| | 19 | | private RectTransform thisRT; |
| | 20 | | private RectTransform parentRT; |
| | 21 | | private HotSceneCellView baseSceneView; |
| | 22 | |
|
| | 23 | | public void Show() |
| | 24 | | { |
| 0 | 25 | | if (!gameObject.activeSelf) |
| | 26 | | { |
| 0 | 27 | | gameObject.SetActive(true); |
| | 28 | |
|
| 0 | 29 | | AudioScriptableObjects.dialogOpen.Play(true); |
| | 30 | | } |
| 0 | 31 | | showHideAnimator.Show(); |
| 0 | 32 | | this.enabled = false; |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | | public void Show(Vector2 position) |
| | 36 | | { |
| 0 | 37 | | thisRT.anchoredPosition = position; |
| 0 | 38 | | Show(); |
| 0 | 39 | | } |
| | 40 | |
|
| 0 | 41 | | public void Hide() { Hide(false); } |
| | 42 | |
|
| | 43 | | public void Hide(bool instant) |
| | 44 | | { |
| 0 | 45 | | if (instant) |
| | 46 | | { |
| 0 | 47 | | showHideAnimator.Hide(true); |
| | 48 | |
|
| 0 | 49 | | AudioScriptableObjects.dialogClose.Play(true); |
| 0 | 50 | | } |
| | 51 | | else |
| | 52 | | { |
| 0 | 53 | | timer = idleTime; |
| 0 | 54 | | this.enabled = true; |
| | 55 | | } |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | void SetSceneView(HotSceneCellView sceneView) |
| | 59 | | { |
| 0 | 60 | | if (baseSceneView) |
| | 61 | | { |
| 0 | 62 | | baseSceneView.OnThumbnailSet -= SetThumbnail; |
| | 63 | | } |
| | 64 | |
|
| 0 | 65 | | baseSceneView = sceneView; |
| | 66 | |
|
| 0 | 67 | | SetMapInfoData(sceneView.mapInfoHandler); |
| | 68 | |
|
| 0 | 69 | | thumbnail.texture = sceneView.thumbnailHandler.texture; |
| 0 | 70 | | bool hasThumbnail = thumbnail.texture != null; |
| 0 | 71 | | loadingSpinner.SetActive(!hasThumbnail); |
| 0 | 72 | | if (!hasThumbnail) |
| | 73 | | { |
| 0 | 74 | | sceneView.OnThumbnailSet += SetThumbnail; |
| | 75 | | } |
| 0 | 76 | | } |
| | 77 | |
|
| | 78 | | void SetMapInfoData(IMapDataView mapInfoView) |
| | 79 | | { |
| 0 | 80 | | sceneName.text = mapInfoView.name; |
| 0 | 81 | | coordinates.text = $"{mapInfoView.baseCoord.x},{mapInfoView.baseCoord.y}"; |
| 0 | 82 | | creatorName.text = mapInfoView.creator; |
| 0 | 83 | | description.text = mapInfoView.description; |
| 0 | 84 | | } |
| | 85 | |
|
| | 86 | | void SetThumbnail(Texture2D thumbnailTexture) |
| | 87 | | { |
| 0 | 88 | | thumbnail.texture = thumbnailTexture; |
| 0 | 89 | | loadingSpinner.SetActive(thumbnailTexture != null); |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | void Awake() |
| | 93 | | { |
| 4 | 94 | | thisRT = (RectTransform)transform; |
| 4 | 95 | | parentRT = (RectTransform)transform.parent; |
| | 96 | |
|
| 4 | 97 | | this.enabled = false; |
| 4 | 98 | | gameObject.SetActive(false); |
| | 99 | |
|
| 4 | 100 | | jumpIn.onPointerDown += () => |
| | 101 | | { |
| 0 | 102 | | if (baseSceneView) |
| | 103 | | { |
| 0 | 104 | | baseSceneView.JumpInPressed(); |
| | 105 | | } |
| 0 | 106 | | }; |
| | 107 | |
|
| 4 | 108 | | hoverArea.OnPointerEnter += OnPointerEnter; |
| 4 | 109 | | hoverArea.OnPointerExit += OnPointerExit; |
| | 110 | |
|
| 4 | 111 | | HotSceneCellView.OnInfoButtonPointerDown += OnInfoButtonPointerDown; |
| 4 | 112 | | HotSceneCellView.OnInfoButtonPointerExit += OnInfoButtonPointerExit; |
| 4 | 113 | | HotSceneCellView.OnJumpIn += OnJumpIn; |
| | 114 | |
|
| 4 | 115 | | showHideAnimator.OnWillFinishHide += OnHidden; |
| 4 | 116 | | } |
| | 117 | |
|
| | 118 | | void OnDestroy() |
| | 119 | | { |
| 4 | 120 | | hoverArea.OnPointerEnter -= OnPointerEnter; |
| 4 | 121 | | hoverArea.OnPointerExit -= OnPointerExit; |
| | 122 | |
|
| 4 | 123 | | HotSceneCellView.OnInfoButtonPointerDown -= OnInfoButtonPointerDown; |
| 4 | 124 | | HotSceneCellView.OnInfoButtonPointerExit -= OnInfoButtonPointerExit; |
| 4 | 125 | | HotSceneCellView.OnJumpIn -= OnJumpIn; |
| | 126 | |
|
| 4 | 127 | | showHideAnimator.OnWillFinishHide -= OnHidden; |
| 4 | 128 | | } |
| | 129 | |
|
| | 130 | | void Update() |
| | 131 | | { |
| 0 | 132 | | timer -= Time.deltaTime; |
| 0 | 133 | | if (timer <= 0) |
| | 134 | | { |
| 0 | 135 | | showHideAnimator.Hide(); |
| 0 | 136 | | this.enabled = false; |
| | 137 | |
|
| 0 | 138 | | AudioScriptableObjects.dialogClose.Play(true); |
| | 139 | | } |
| 0 | 140 | | } |
| | 141 | |
|
| 0 | 142 | | void OnHidden(ShowHideAnimator animator) { baseSceneView = null; } |
| | 143 | |
|
| | 144 | | void OnInfoButtonPointerDown(HotSceneCellView sceneView) |
| | 145 | | { |
| 0 | 146 | | if (sceneView == baseSceneView) |
| 0 | 147 | | return; |
| | 148 | |
|
| | 149 | |
|
| 0 | 150 | | SetSceneView(sceneView); |
| | 151 | |
|
| | 152 | | Vector2 localpoint; |
| 0 | 153 | | if (RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRT, Input.mousePosition, null, out localpoint) |
| | 154 | | { |
| 0 | 155 | | Show(localpoint); |
| | 156 | | } |
| 0 | 157 | | } |
| | 158 | |
|
| 0 | 159 | | void OnInfoButtonPointerExit() { Hide(); } |
| | 160 | |
|
| 0 | 161 | | void OnPointerEnter() { Show(); } |
| | 162 | |
|
| 0 | 163 | | void OnPointerExit() { Hide(); } |
| | 164 | |
|
| 0 | 165 | | void OnJumpIn(Vector2Int coords, string serverName, string layerName) { gameObject.SetActive(false); } |
| | 166 | | } |