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