Skip to content

Commit d699c56

Browse files
authored
Merge pull request #371 from Slappy826/master
Improve remote player ui visuals
2 parents 5dc2bd9 + 2a296d1 commit d699c56

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

NebulaWorld/RemotePlayerModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class RemotePlayerModel
1818
public RemotePlayerEffects Effects { get; set; }
1919
public GameObject InGameNameText { get; set; }
2020
public Text StarmapNameText { get; set; }
21-
public Text StarmapMarker { get; set; }
21+
public Transform StarmapTracker { get; set; }
2222

2323
public global::Player PlayerInstance { get; set; }
2424
public Mecha MechaInstance { get; set; }
@@ -72,11 +72,12 @@ public void Destroy()
7272
Effects = null;
7373
PlayerInstance.Free();
7474
PlayerInstance = null;
75-
if (StarmapMarker != null) Object.Destroy(StarmapMarker);
75+
if (StarmapTracker != null) Object.Destroy(StarmapTracker);
7676
if (StarmapNameText != null) Object.Destroy(StarmapNameText);
7777
if (InGameNameText != null) Object.Destroy(InGameNameText);
7878

79-
StarmapMarker = StarmapNameText = null;
79+
StarmapTracker = null;
80+
StarmapNameText = null;
8081
InGameNameText = null;
8182
}
8283
}

NebulaWorld/SimulatedWorld.cs

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ public static void RenderPlayerNameTagsOnStarmap(UIStarmap starmap)
469469
{
470470
// Make a copy of the "Icarus" text from the starmap
471471
Text starmap_playerNameText = (Text)AccessTools.Field(typeof(UIStarmap), "playerNameText").GetValue(starmap);
472+
Transform starmap_playerTrack = (Transform)AccessTools.Field(typeof(UIStarmap), "playerTrack").GetValue(starmap);
472473

473474
using (GetRemotePlayersModels(out var remotePlayersModels))
474475
{
@@ -477,11 +478,11 @@ public static void RenderPlayerNameTagsOnStarmap(UIStarmap starmap)
477478
RemotePlayerModel playerModel = player.Value;
478479

479480
Text nameText;
480-
Text starmapMarker;
481-
if (playerModel.StarmapNameText != null && playerModel.StarmapMarker != null)
481+
Transform starmapTracker;
482+
if (playerModel.StarmapNameText != null && playerModel.StarmapTracker != null)
482483
{
483484
nameText = playerModel.StarmapNameText;
484-
starmapMarker = playerModel.StarmapMarker;
485+
starmapTracker = playerModel.StarmapTracker;
485486
}
486487
else
487488
{
@@ -490,11 +491,9 @@ public static void RenderPlayerNameTagsOnStarmap(UIStarmap starmap)
490491
nameText.text = $"{ playerModel.Username }";
491492
nameText.gameObject.SetActive(true);
492493

493-
// Make another copy of it, but just replace it with a point to represent their location
494-
starmapMarker = playerModel.StarmapMarker = GameObject.Instantiate(starmap_playerNameText, starmap_playerNameText.transform.parent);
495-
starmapMarker.text = "•";
496-
starmapMarker.fontSize = nameText.fontSize * 4;
497-
starmapMarker.gameObject.SetActive(true);
494+
// Make an instance the player tracker object
495+
starmapTracker = playerModel.StarmapTracker = GameObject.Instantiate(starmap_playerTrack, starmap_playerTrack.parent);
496+
starmapTracker.gameObject.SetActive(true);
498497
}
499498

500499
VectorLF3 adjustedVector;
@@ -524,12 +523,27 @@ public static void RenderPlayerNameTagsOnStarmap(UIStarmap starmap)
524523
}
525524

526525
// Put the marker directly on the location of the player
527-
starmapMarker.rectTransform.anchoredPosition = rectPoint;
528-
starmapMarker.transform.localScale = Vector3.one;
526+
starmapTracker.position = adjustedVector;
527+
528+
if (playerModel.Movement.localPlanetId > 0)
529+
{
530+
PlanetData planet = GameMain.galaxy.PlanetById(playerModel.Movement.localPlanetId);
531+
var rotation = planet.runtimeRotation *
532+
Quaternion.LookRotation(playerModel.PlayerModelTransform.forward, playerModel.Movement.GetLastPosition().LocalPlanetPosition.ToVector3());
533+
starmapTracker.rotation = rotation;
534+
}
535+
else
536+
{
537+
var rotation = Quaternion.LookRotation(playerModel.PlayerModelTransform.forward, playerModel.PlayerTransform.localPosition);
538+
starmapTracker.rotation = rotation;
539+
}
540+
541+
starmapTracker.localScale = UIStarmap.isChangingToMilkyWay ? Vector3.zero :
542+
Vector3.one * (starmap.screenCamera.transform.position - starmapTracker.position).magnitude;
529543

530544
// Put their name above or below it
531-
nameText.rectTransform.anchoredPosition = new Vector2(rectPoint.x, rectPoint.y + (rectPoint.y >= -350.0 ? -19f : 19f));
532-
nameText.transform.localScale = Vector3.one;
545+
nameText.rectTransform.anchoredPosition = new Vector2(rectPoint.x + (rectPoint.x > 600f ? -35 : 35), rectPoint.y + (rectPoint.y > -350.0 ? -19f : 19f));
546+
nameText.gameObject.SetActive(!UIStarmap.isChangingToMilkyWay);
533547
}
534548
}
535549
}
@@ -542,11 +556,11 @@ public static void ClearPlayerNameTagsOnStarmap()
542556
{
543557
// Destroy the marker and name so they don't linger and cause problems
544558
GameObject.Destroy(player.Value.StarmapNameText.gameObject);
545-
GameObject.Destroy(player.Value.StarmapMarker);
559+
GameObject.Destroy(player.Value.StarmapTracker.gameObject);
546560

547561
// Null them out so they can be recreated next time the map is opened
548562
player.Value.StarmapNameText = null;
549-
player.Value.StarmapMarker = null;
563+
player.Value.StarmapTracker = null;
550564
}
551565
}
552566
}
@@ -589,8 +603,6 @@ public static void RenderPlayerNameTagsInGame()
589603
// Copy the font over from the sail indicator
590604
textMesh.font = uiSailIndicator_targetText.font;
591605
meshRenderer.sharedMaterial = uiSailIndicator_targetText.gameObject.GetComponent<MeshRenderer>().sharedMaterial;
592-
// Scale it down a little bit otherwise it looks too big when next to the player
593-
playerNameText.transform.localScale *= 0.6f;
594606

595607
playerNameText.SetActive(true);
596608
}
@@ -607,6 +619,26 @@ public static void RenderPlayerNameTagsInGame()
607619

608620
// Make sure the text is pointing at the camera
609621
playerNameText.transform.rotation = GameCamera.main.transform.rotation;
622+
623+
// Resizes the text based on distance from camera for better visual quality
624+
var distanceFromCamera = Vector3.Distance(playerNameText.transform.position, GameCamera.main.transform.position);
625+
var nameTextMesh = playerNameText.GetComponent<TextMesh>();
626+
627+
if (distanceFromCamera > 100f)
628+
{
629+
nameTextMesh.characterSize = 0.2f;
630+
nameTextMesh.fontSize = 60;
631+
}
632+
else if (distanceFromCamera > 50f)
633+
{
634+
nameTextMesh.characterSize = 0.15f;
635+
nameTextMesh.fontSize = 48;
636+
}
637+
else
638+
{
639+
nameTextMesh.characterSize = 0.1f;
640+
nameTextMesh.fontSize = 36;
641+
}
610642
}
611643
}
612644
}

0 commit comments

Comments
 (0)