| | 1 | | using DCL.Helpers; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | | using UnityEngine.EventSystems; |
| | 6 | | using TMPro; |
| | 7 | | using KernelConfigurationTypes; |
| | 8 | | using Object = UnityEngine.Object; |
| | 9 | |
|
| | 10 | | namespace DCL |
| | 11 | | { |
| | 12 | | public class MapRenderer : MonoBehaviour |
| | 13 | | { |
| | 14 | | const int LEFT_BORDER_PARCELS = 25; |
| | 15 | | const int RIGHT_BORDER_PARCELS = 31; |
| | 16 | | const int TOP_BORDER_PARCELS = 31; |
| | 17 | | const int BOTTOM_BORDER_PARCELS = 25; |
| | 18 | | const int WORLDMAP_WIDTH_IN_PARCELS = 300; |
| | 19 | | const string MINIMAP_USER_ICONS_POOL_NAME = "MinimapUserIconsPool"; |
| | 20 | | const int MINIMAP_USER_ICONS_MAX_PREWARM = 30; |
| | 21 | | private const int MAX_CURSOR_PARCEL_DISTANCE = 40; |
| | 22 | | private const int MAX_SCENE_CHARACTER_TITLE = 29; |
| | 23 | | private const string EMPTY_PARCEL_NAME = "Empty parcel"; |
| | 24 | | private int NAVMAP_CHUNK_LAYER; |
| | 25 | |
|
| 638 | 26 | | public static MapRenderer i { get; private set; } |
| | 27 | |
|
| 14 | 28 | | [SerializeField] private float parcelHightlightScale = 1.25f; |
| | 29 | | [SerializeField] private Button ParcelHighlightButton; |
| | 30 | | [SerializeField] private MapParcelHighlight highlight; |
| | 31 | | [SerializeField] private Image parcelHighlightImage; |
| | 32 | | [SerializeField] private Image parcelHighlighImagePrefab; |
| | 33 | | [SerializeField] private Image parcelHighlighWithContentImagePrefab; |
| | 34 | | [SerializeField] private Image selectParcelHighlighImagePrefab; |
| | 35 | |
|
| 28 | 36 | | private Vector3Variable playerRotation => CommonScriptableObjects.cameraForward; |
| 14 | 37 | | private List<RaycastResult> uiRaycastResults = new List<RaycastResult>(); |
| 14 | 38 | | private PointerEventData uiRaycastPointerEventData = new PointerEventData(EventSystem.current); |
| | 39 | |
|
| | 40 | | [HideInInspector] public Vector2Int cursorMapCoords; |
| 14 | 41 | | [HideInInspector] public bool showCursorCoords = true; |
| 5 | 42 | | public Vector3 playerGridPosition => Utils.WorldToGridPositionUnclamped(playerWorldPosition.Get()); |
| | 43 | | public MapAtlas atlas; |
| | 44 | | public TextMeshProUGUI highlightedParcelText; |
| | 45 | | public Transform overlayContainer; |
| | 46 | | public Transform overlayContainerPlayers; |
| | 47 | | public Transform globalUserMarkerContainer; |
| | 48 | | public RectTransform playerPositionIcon; |
| | 49 | |
|
| | 50 | | public static System.Action<int, int> OnParcelClicked; |
| | 51 | | public static System.Action OnCursorFarFromParcel; |
| | 52 | |
|
| 14 | 53 | | public float scaleFactor = 1f; |
| | 54 | |
|
| | 55 | | // Used as a reference of the coordinates origin in-map and as a parcel width/height reference |
| | 56 | | public RectTransform centeredReferenceParcel; |
| | 57 | |
|
| | 58 | | public MapSceneIcon scenesOfInterestIconPrefab; |
| | 59 | | public GameObject userIconPrefab; |
| | 60 | | public UserMarkerObject globalUserMarkerPrefab; |
| | 61 | |
|
| 0 | 62 | | public MapGlobalUsersPositionMarkerController usersPositionMarkerController { private set; get; } |
| | 63 | |
|
| 14 | 64 | | private HashSet<MinimapMetadata.MinimapSceneInfo> scenesOfInterest = new HashSet<MinimapMetadata.MinimapSceneInf |
| 14 | 65 | | private Dictionary<MinimapMetadata.MinimapSceneInfo, GameObject> scenesOfInterestMarkers = new Dictionary<Minima |
| 14 | 66 | | private Dictionary<string, PoolableObject> usersInfoMarkers = new Dictionary<string, PoolableObject>(); |
| | 67 | |
|
| | 68 | | private Vector2Int lastClickedCursorMapCoords; |
| | 69 | | private Pool usersInfoPool; |
| | 70 | |
|
| | 71 | | private bool parcelHighlightEnabledValue = false; |
| 14 | 72 | | private bool otherPlayersIconsEnabled = true; |
| | 73 | |
|
| 14 | 74 | | List<WorldRange> validWorldRanges = new List<WorldRange> |
| | 75 | | { |
| | 76 | | new WorldRange(-150, -150, 150, 150) // default range |
| | 77 | | }; |
| | 78 | |
|
| | 79 | | public bool parcelHighlightEnabled |
| | 80 | | { |
| | 81 | | set |
| | 82 | | { |
| 0 | 83 | | parcelHighlightEnabledValue = value; |
| 0 | 84 | | parcelHighlightImage.gameObject.SetActive(parcelHighlightEnabledValue); |
| 0 | 85 | | } |
| 0 | 86 | | get { return parcelHighlightEnabledValue; } |
| | 87 | | } |
| | 88 | |
|
| 56 | 89 | | private BaseDictionary<string, Player> otherPlayers => DataStore.i.player.otherPlayers; |
| 14 | 90 | | private Dictionary<Vector2Int, Image> highlightedLands = new Dictionary<Vector2Int, Image>(); |
| 14 | 91 | | private List<Vector2Int> ownedLandsWithContent = new List<Vector2Int>(); |
| 14 | 92 | | private List<Vector2Int> ownedEmptyLands = new List<Vector2Int>(); |
| | 93 | | private Vector2Int lastSelectedLand; |
| 14 | 94 | | private Vector3 lastPlayerPosition = new Vector3(float.NegativeInfinity, 0, float.NegativeInfinity); |
| 14 | 95 | | private BaseVariable<Vector3> playerWorldPosition = DataStore.i.player.playerWorldPosition; |
| | 96 | |
|
| | 97 | | private bool isInitialized = false; |
| | 98 | |
|
| | 99 | | [HideInInspector] |
| | 100 | | public event System.Action<float, float> OnMovedParcelCursor; |
| | 101 | |
|
| | 102 | | private void Awake() |
| | 103 | | { |
| 12 | 104 | | i = this; |
| 12 | 105 | | Initialize(); |
| 12 | 106 | | } |
| | 107 | |
|
| | 108 | | public void Initialize() |
| | 109 | | { |
| 14 | 110 | | if (isInitialized) |
| 2 | 111 | | return; |
| | 112 | |
|
| 12 | 113 | | isInitialized = true; |
| 12 | 114 | | EnsurePools(); |
| 12 | 115 | | atlas.InitializeChunks(); |
| 12 | 116 | | NAVMAP_CHUNK_LAYER = LayerMask.NameToLayer("NavmapChunk"); |
| | 117 | |
|
| 12 | 118 | | MinimapMetadata.GetMetadata().OnSceneInfoUpdated += MapRenderer_OnSceneInfoUpdated; |
| 12 | 119 | | otherPlayers.OnAdded += OnOtherPlayersAdded; |
| 12 | 120 | | otherPlayers.OnRemoved += OnOtherPlayerRemoved; |
| | 121 | |
|
| 12 | 122 | | ParcelHighlightButton.onClick.AddListener(ClickMousePositionParcel); |
| | 123 | |
|
| 12 | 124 | | playerRotation.OnChange += OnCharacterRotate; |
| | 125 | |
|
| 12 | 126 | | highlight.SetScale(parcelHightlightScale); |
| | 127 | |
|
| 12 | 128 | | usersPositionMarkerController = new MapGlobalUsersPositionMarkerController(globalUserMarkerPrefab, |
| | 129 | | globalUserMarkerContainer, |
| | 130 | | MapUtils.CoordsToPosition); |
| | 131 | |
|
| 12 | 132 | | usersPositionMarkerController.SetUpdateMode(MapGlobalUsersPositionMarkerController.UpdateMode.BACKGROUND); |
| | 133 | |
|
| 12 | 134 | | KernelConfig.i.OnChange += OnKernelConfigChanged; |
| 12 | 135 | | } |
| | 136 | |
|
| | 137 | | private void EnsurePools() |
| | 138 | | { |
| 12 | 139 | | usersInfoPool = PoolManager.i.GetPool(MINIMAP_USER_ICONS_POOL_NAME); |
| | 140 | |
|
| 12 | 141 | | if (usersInfoPool == null) |
| | 142 | | { |
| 12 | 143 | | usersInfoPool = PoolManager.i.AddPool( |
| | 144 | | MINIMAP_USER_ICONS_POOL_NAME, |
| | 145 | | Instantiate(userIconPrefab.gameObject, overlayContainerPlayers.transform), |
| | 146 | | maxPrewarmCount: MINIMAP_USER_ICONS_MAX_PREWARM, |
| | 147 | | isPersistent: true); |
| | 148 | |
|
| 12 | 149 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| 0 | 150 | | usersInfoPool.ForcePrewarm(); |
| | 151 | | } |
| 12 | 152 | | } |
| | 153 | |
|
| 0 | 154 | | public void SetParcelHighlightActive(bool isAtive) => parcelHighlightImage.enabled = isAtive; |
| | 155 | |
|
| 2 | 156 | | public Vector3 GetParcelHighlightTransform() => parcelHighlightImage.transform.position; |
| | 157 | |
|
| | 158 | | public void SetOtherPlayersIconActive(bool isActive) |
| | 159 | | { |
| 0 | 160 | | otherPlayersIconsEnabled = isActive; |
| | 161 | |
|
| 0 | 162 | | foreach (PoolableObject poolableObject in usersInfoMarkers.Values) |
| | 163 | | { |
| 0 | 164 | | poolableObject.gameObject.SetActive(isActive); |
| | 165 | | } |
| 0 | 166 | | } |
| | 167 | |
|
| 0 | 168 | | public void SetPlayerIconActive(bool isActive) => playerPositionIcon.gameObject.SetActive(isActive); |
| | 169 | |
|
| 0 | 170 | | public void SetHighlighSize(Vector2Int size) { highlight.ChangeHighlighSize(size); } |
| | 171 | |
|
| 0 | 172 | | public void SetHighlightStyle(MapParcelHighlight.HighlighStyle style) { highlight.SetStyle(style); } |
| | 173 | |
|
| 24 | 174 | | public void OnDestroy() { Cleanup(); } |
| | 175 | |
|
| | 176 | | public void Cleanup() |
| | 177 | | { |
| 16 | 178 | | if (atlas != null) |
| 14 | 179 | | atlas.Cleanup(); |
| | 180 | |
|
| 36 | 181 | | foreach (var kvp in scenesOfInterestMarkers) |
| | 182 | | { |
| 2 | 183 | | if (kvp.Value != null) |
| 2 | 184 | | Destroy(kvp.Value); |
| | 185 | | } |
| | 186 | |
|
| 16 | 187 | | CleanLandsHighlights(); |
| 16 | 188 | | ClearLandHighlightsInfo(); |
| | 189 | |
|
| 16 | 190 | | scenesOfInterestMarkers.Clear(); |
| | 191 | |
|
| 16 | 192 | | playerRotation.OnChange -= OnCharacterRotate; |
| 16 | 193 | | MinimapMetadata.GetMetadata().OnSceneInfoUpdated -= MapRenderer_OnSceneInfoUpdated; |
| 16 | 194 | | otherPlayers.OnAdded -= OnOtherPlayersAdded; |
| 16 | 195 | | otherPlayers.OnRemoved -= OnOtherPlayerRemoved; |
| | 196 | |
|
| 16 | 197 | | ParcelHighlightButton.onClick.RemoveListener(ClickMousePositionParcel); |
| | 198 | |
|
| 16 | 199 | | usersPositionMarkerController?.Dispose(); |
| | 200 | |
|
| 16 | 201 | | KernelConfig.i.OnChange -= OnKernelConfigChanged; |
| | 202 | |
|
| 16 | 203 | | isInitialized = false; |
| 16 | 204 | | } |
| | 205 | |
|
| | 206 | | public void CleanLandsHighlights() |
| | 207 | | { |
| 32 | 208 | | foreach (KeyValuePair<Vector2Int, Image> kvp in highlightedLands) |
| | 209 | | { |
| 0 | 210 | | Destroy(kvp.Value.gameObject); |
| | 211 | | } |
| | 212 | |
|
| 16 | 213 | | highlightedLands.Clear (); //To Clear out the dictionary |
| 16 | 214 | | } |
| | 215 | |
|
| | 216 | | public void ClearLandHighlightsInfo() |
| | 217 | | { |
| 16 | 218 | | ownedLandsWithContent.Clear (); //To Clear out the content lands |
| 16 | 219 | | ownedEmptyLands.Clear (); //To Clear out the empty content |
| 16 | 220 | | } |
| | 221 | |
|
| | 222 | | public void SelectLand(Vector2Int coordsToSelect, Vector2Int size ) |
| | 223 | | { |
| 0 | 224 | | if (highlightedLands.ContainsKey(lastSelectedLand)) |
| | 225 | | { |
| 0 | 226 | | Destroy(highlightedLands[lastSelectedLand].gameObject); |
| 0 | 227 | | highlightedLands.Remove(lastSelectedLand); |
| | 228 | | } |
| | 229 | |
|
| 0 | 230 | | HighlightLands(ownedEmptyLands, ownedLandsWithContent); |
| | 231 | |
|
| 0 | 232 | | if (highlightedLands.ContainsKey(coordsToSelect)) |
| | 233 | | { |
| 0 | 234 | | Destroy(highlightedLands[coordsToSelect].gameObject); |
| 0 | 235 | | highlightedLands.Remove(coordsToSelect); |
| | 236 | | } |
| | 237 | |
|
| 0 | 238 | | CreateHighlightParcel(selectParcelHighlighImagePrefab, coordsToSelect, size); |
| 0 | 239 | | lastSelectedLand = coordsToSelect; |
| 0 | 240 | | } |
| | 241 | |
|
| | 242 | | public void HighlightLands(List<Vector2Int> landsToHighlight, List<Vector2Int> landsToHighlightWithContent) |
| | 243 | | { |
| 0 | 244 | | CleanLandsHighlights(); |
| | 245 | |
|
| 0 | 246 | | foreach (Vector2Int coords in landsToHighlight) |
| | 247 | | { |
| 0 | 248 | | if (highlightedLands.ContainsKey(coords)) |
| | 249 | | continue; |
| | 250 | |
|
| 0 | 251 | | CreateHighlightParcel(parcelHighlighImagePrefab, coords, Vector2Int.one); |
| | 252 | | } |
| | 253 | |
|
| 0 | 254 | | foreach (Vector2Int coords in landsToHighlightWithContent) |
| | 255 | | { |
| 0 | 256 | | if (highlightedLands.ContainsKey(coords)) |
| | 257 | | continue; |
| | 258 | |
|
| 0 | 259 | | if (!ownedLandsWithContent.Contains(coords)) |
| 0 | 260 | | ownedLandsWithContent.Add(coords); |
| 0 | 261 | | CreateHighlightParcel(parcelHighlighWithContentImagePrefab, coords, Vector2Int.one); |
| | 262 | | } |
| | 263 | |
|
| 0 | 264 | | ownedEmptyLands = landsToHighlight; |
| 0 | 265 | | ownedLandsWithContent = landsToHighlightWithContent; |
| 0 | 266 | | } |
| | 267 | |
|
| | 268 | | private void CreateHighlightParcel(Image prefab, Vector2Int coords, Vector2Int size) |
| | 269 | | { |
| 0 | 270 | | var highlightItem = Instantiate(prefab, overlayContainer, true).GetComponent<Image>(); |
| 0 | 271 | | highlightItem.rectTransform.localScale = new Vector3(parcelHightlightScale * size.x, parcelHightlightScale * |
| 0 | 272 | | highlightItem.rectTransform.SetAsLastSibling(); |
| 0 | 273 | | highlightItem.rectTransform.anchoredPosition = MapUtils.CoordsToPosition(coords); |
| 0 | 274 | | highlightedLands.Add(coords, highlightItem); |
| 0 | 275 | | } |
| | 276 | |
|
| | 277 | | void Update() |
| | 278 | | { |
| 11 | 279 | | if ((playerWorldPosition.Get() - lastPlayerPosition).sqrMagnitude >= 0.1f * 0.1f) |
| | 280 | | { |
| 3 | 281 | | lastPlayerPosition = playerWorldPosition.Get(); |
| 3 | 282 | | UpdateRendering(Utils.WorldToGridPositionUnclamped(lastPlayerPosition)); |
| | 283 | | } |
| | 284 | |
|
| 11 | 285 | | if (!parcelHighlightEnabled) |
| 11 | 286 | | return; |
| | 287 | |
|
| 0 | 288 | | UpdateCursorMapCoords(); |
| | 289 | |
|
| 0 | 290 | | UpdateParcelHighlight(); |
| | 291 | |
|
| 0 | 292 | | UpdateParcelHold(); |
| 0 | 293 | | } |
| | 294 | |
|
| | 295 | | void UpdateCursorMapCoords() |
| | 296 | | { |
| 0 | 297 | | if (!IsCursorOverMapChunk()) |
| 0 | 298 | | return; |
| | 299 | |
|
| | 300 | | const int OFFSET = -60; //Map is a bit off centered, we need to adjust it a little. |
| 0 | 301 | | RectTransformUtility.ScreenPointToLocalPointInRectangle(atlas.chunksParent, Input.mousePosition, DataStore.i |
| 0 | 302 | | mapPoint -= Vector2.one * OFFSET; |
| 0 | 303 | | mapPoint -= (atlas.chunksParent.sizeDelta / 2f); |
| 0 | 304 | | cursorMapCoords = Vector2Int.RoundToInt(mapPoint / MapUtils.PARCEL_SIZE); |
| 0 | 305 | | } |
| | 306 | |
|
| | 307 | | bool IsCursorOverMapChunk() |
| | 308 | | { |
| 0 | 309 | | uiRaycastPointerEventData.position = Input.mousePosition; |
| 0 | 310 | | EventSystem.current.RaycastAll(uiRaycastPointerEventData, uiRaycastResults); |
| | 311 | |
|
| 0 | 312 | | return uiRaycastResults.Count > 0 && uiRaycastResults[0].gameObject.layer == NAVMAP_CHUNK_LAYER; |
| | 313 | | } |
| | 314 | |
|
| | 315 | | void UpdateParcelHighlight() |
| | 316 | | { |
| 0 | 317 | | if (!CoordinatesAreInsideTheWorld((int)cursorMapCoords.x, (int)cursorMapCoords.y)) |
| | 318 | | { |
| 0 | 319 | | if (parcelHighlightImage.gameObject.activeSelf) |
| 0 | 320 | | parcelHighlightImage.gameObject.SetActive(false); |
| | 321 | |
|
| 0 | 322 | | return; |
| | 323 | | } |
| | 324 | |
|
| 0 | 325 | | if (!parcelHighlightImage.gameObject.activeSelf) |
| 0 | 326 | | parcelHighlightImage.gameObject.SetActive(true); |
| | 327 | |
|
| 0 | 328 | | string previousText = highlightedParcelText.text; |
| 0 | 329 | | parcelHighlightImage.rectTransform.SetAsLastSibling(); |
| 0 | 330 | | parcelHighlightImage.rectTransform.anchoredPosition = MapUtils.CoordsToPosition(cursorMapCoords); |
| 0 | 331 | | highlightedParcelText.text = showCursorCoords ? $"{cursorMapCoords.x}, {cursorMapCoords.y}" : string.Empty; |
| | 332 | |
|
| 0 | 333 | | if (highlightedParcelText.text != previousText && !Input.GetMouseButton(0)) |
| | 334 | | { |
| 0 | 335 | | OnMovedParcelCursor?.Invoke(cursorMapCoords.x, cursorMapCoords.y); |
| | 336 | | } |
| | 337 | |
|
| | 338 | | // ---------------------------------------------------- |
| | 339 | | // TODO: Use sceneInfo to highlight whole scene parcels and populate scenes hover info on navmap once we can |
| | 340 | | // var sceneInfo = mapMetadata.GetSceneInfo(cursorMapCoords.x, cursorMapCoords.y); |
| 0 | 341 | | } |
| | 342 | |
|
| | 343 | | void UpdateParcelHold() |
| | 344 | | { |
| 0 | 345 | | if (Vector2.Distance(lastClickedCursorMapCoords, cursorMapCoords) > MAX_CURSOR_PARCEL_DISTANCE / (scaleFacto |
| | 346 | | { |
| 0 | 347 | | OnCursorFarFromParcel?.Invoke(); |
| | 348 | | } |
| 0 | 349 | | } |
| | 350 | |
|
| 0 | 351 | | private void OnKernelConfigChanged(KernelConfigModel current, KernelConfigModel previous) { validWorldRanges = c |
| | 352 | |
|
| | 353 | | bool CoordinatesAreInsideTheWorld(int xCoord, int yCoord) |
| | 354 | | { |
| 0 | 355 | | foreach (WorldRange worldRange in validWorldRanges) |
| | 356 | | { |
| 0 | 357 | | if (worldRange.Contains(xCoord, yCoord)) |
| | 358 | | { |
| 0 | 359 | | return true; |
| | 360 | | } |
| | 361 | | } |
| 0 | 362 | | return false; |
| 0 | 363 | | } |
| | 364 | |
|
| | 365 | | private void MapRenderer_OnSceneInfoUpdated(MinimapMetadata.MinimapSceneInfo sceneInfo) |
| | 366 | | { |
| 4 | 367 | | if (!sceneInfo.isPOI) |
| 2 | 368 | | return; |
| | 369 | |
|
| 2 | 370 | | if (scenesOfInterest.Contains(sceneInfo)) |
| 0 | 371 | | return; |
| | 372 | |
|
| 2 | 373 | | if (IsEmptyParcel(sceneInfo)) |
| 0 | 374 | | return; |
| | 375 | |
|
| 2 | 376 | | scenesOfInterest.Add(sceneInfo); |
| | 377 | |
|
| 2 | 378 | | GameObject go = Object.Instantiate(scenesOfInterestIconPrefab.gameObject, overlayContainer.transform); |
| | 379 | |
|
| 2 | 380 | | Vector2 centerTile = Vector2.zero; |
| | 381 | |
|
| 20 | 382 | | foreach (var parcel in sceneInfo.parcels) |
| | 383 | | { |
| 8 | 384 | | centerTile += parcel; |
| | 385 | | } |
| | 386 | |
|
| 2 | 387 | | centerTile /= (float)sceneInfo.parcels.Count; |
| 2 | 388 | | float distance = float.PositiveInfinity; |
| 2 | 389 | | Vector2 centerParcel = Vector2.zero; |
| 20 | 390 | | foreach (var parcel in sceneInfo.parcels) |
| | 391 | | { |
| 8 | 392 | | if (Vector2.Distance(centerTile, parcel) < distance) |
| | 393 | | { |
| 5 | 394 | | distance = Vector2.Distance(centerParcel, parcel); |
| 5 | 395 | | centerParcel = parcel; |
| | 396 | | } |
| | 397 | |
|
| | 398 | | } |
| | 399 | |
|
| 2 | 400 | | (go.transform as RectTransform).anchoredPosition = MapUtils.CoordsToPosition(centerParcel); |
| | 401 | |
|
| 2 | 402 | | MapSceneIcon icon = go.GetComponent<MapSceneIcon>(); |
| | 403 | |
|
| 2 | 404 | | if (icon.title != null) |
| 2 | 405 | | icon.title.text = sceneInfo.name.Length > MAX_SCENE_CHARACTER_TITLE ? sceneInfo.name.Substring(0, MAX_SC |
| | 406 | |
|
| 2 | 407 | | scenesOfInterestMarkers.Add(sceneInfo, go); |
| 2 | 408 | | } |
| | 409 | |
|
| | 410 | | public void SetPointOfInterestActive(bool areActive) |
| | 411 | | { |
| 0 | 412 | | foreach (GameObject pointOfInterestGameObject in scenesOfInterestMarkers.Values) |
| | 413 | | { |
| 0 | 414 | | pointOfInterestGameObject.SetActive(areActive); |
| | 415 | | } |
| 0 | 416 | | } |
| | 417 | |
|
| | 418 | | private bool IsEmptyParcel(MinimapMetadata.MinimapSceneInfo sceneInfo) |
| | 419 | | { |
| 2 | 420 | | return (sceneInfo.name != null && sceneInfo.name.Equals(EMPTY_PARCEL_NAME)); |
| | 421 | | } |
| | 422 | |
|
| | 423 | | private void OnOtherPlayersAdded(string userId, Player player) |
| | 424 | | { |
| 0 | 425 | | var poolable = usersInfoPool.Get(); |
| 0 | 426 | | var marker = poolable.gameObject.GetComponent<MapUserIcon>(); |
| 0 | 427 | | marker.gameObject.name = $"UserIcon-{player.name}"; |
| 0 | 428 | | marker.gameObject.transform.SetParent(overlayContainerPlayers.transform, true); |
| 0 | 429 | | marker.Populate(player); |
| 0 | 430 | | marker.gameObject.SetActive(otherPlayersIconsEnabled); |
| 0 | 431 | | marker.transform.localScale = Vector3.one; |
| 0 | 432 | | usersInfoMarkers.Add(userId, poolable); |
| 0 | 433 | | } |
| | 434 | |
|
| | 435 | | private void OnOtherPlayerRemoved(string userId, Player player) |
| | 436 | | { |
| 0 | 437 | | if (!usersInfoMarkers.TryGetValue(userId, out PoolableObject go)) |
| | 438 | | { |
| 0 | 439 | | return; |
| | 440 | | } |
| | 441 | |
|
| 0 | 442 | | usersInfoPool.Release(go); |
| 0 | 443 | | usersInfoMarkers.Remove(userId); |
| 0 | 444 | | } |
| | 445 | |
|
| | 446 | | private void ConfigureUserIcon(GameObject iconGO, Vector3 pos) |
| | 447 | | { |
| 0 | 448 | | var gridPosition = Utils.WorldToGridPositionUnclamped(pos); |
| 0 | 449 | | iconGO.transform.localPosition = MapUtils.CoordsToPosition(Vector2Int.RoundToInt(gridPosition)); |
| 0 | 450 | | } |
| | 451 | |
|
| 4 | 452 | | private void OnCharacterRotate(Vector3 current, Vector3 previous) { UpdateRendering(Utils.WorldToGridPositionUnc |
| | 453 | |
|
| | 454 | | public void OnCharacterSetPosition(Vector2Int newCoords, Vector2Int oldCoords) |
| | 455 | | { |
| 0 | 456 | | if (oldCoords == newCoords) |
| 0 | 457 | | return; |
| | 458 | |
|
| 0 | 459 | | UpdateRendering(new Vector2((float)newCoords.x, (float)newCoords.y)); |
| 0 | 460 | | } |
| | 461 | |
|
| | 462 | | public void UpdateRendering(Vector2 newCoords) |
| | 463 | | { |
| 5 | 464 | | UpdateBackgroundLayer(newCoords); |
| 5 | 465 | | UpdateSelectionLayer(); |
| 5 | 466 | | UpdateOverlayLayer(); |
| 5 | 467 | | } |
| | 468 | |
|
| 10 | 469 | | void UpdateBackgroundLayer(Vector2 newCoords) { atlas.CenterToTile(newCoords); } |
| | 470 | |
|
| | 471 | | void UpdateSelectionLayer() |
| | 472 | | { |
| | 473 | | //TODO(Brian): Build and place here the scene highlight if applicable. |
| 0 | 474 | | } |
| | 475 | |
|
| | 476 | | void UpdateOverlayLayer() |
| | 477 | | { |
| | 478 | | //NOTE(Brian): Player icon |
| 5 | 479 | | Vector3 f = CommonScriptableObjects.cameraForward.Get(); |
| 5 | 480 | | Quaternion playerAngle = Quaternion.Euler(0, 0, Mathf.Atan2(-f.x, f.z) * Mathf.Rad2Deg); |
| | 481 | |
|
| 5 | 482 | | var gridPosition = playerGridPosition; |
| 5 | 483 | | playerPositionIcon.anchoredPosition = MapUtils.CoordsToPositionWithOffset(gridPosition); |
| 5 | 484 | | playerPositionIcon.rotation = playerAngle; |
| 5 | 485 | | } |
| | 486 | |
|
| | 487 | | // Called by the parcelhighlight image button |
| | 488 | | public void ClickMousePositionParcel() |
| | 489 | | { |
| 0 | 490 | | highlightedParcelText.text = string.Empty; |
| 0 | 491 | | lastClickedCursorMapCoords = cursorMapCoords; |
| 0 | 492 | | OnParcelClicked?.Invoke(cursorMapCoords.x, cursorMapCoords.y); |
| 0 | 493 | | } |
| | 494 | | } |
| | 495 | | } |