diff --git a/Client/Scripts/Menus/Sub/SettingsMenu.cs b/Client/Scripts/Menus/Sub/SettingsMenu.cs index 2e87483..dcb3fe9 100644 --- a/Client/Scripts/Menus/Sub/SettingsMenu.cs +++ b/Client/Scripts/Menus/Sub/SettingsMenu.cs @@ -39,7 +39,7 @@ namespace RageCoop.Client.Menus Settings.ShowPlayerNameTag); private static readonly NativeItem _menuKey = - new NativeItem("Menu Key", "The key to open menu", Settings.MenuKey.ToString()); + new("Menu Key", "The key to open menu", Settings.MenuKey.ToString()); private static readonly NativeItem _passengerKey = new("Passenger Key", "The key to enter a vehicle as passenger", Settings.PassengerKey.ToString()); diff --git a/Client/Scripts/Sync/Entities/Ped/SyncedPed.Variables.cs b/Client/Scripts/Sync/Entities/Ped/SyncedPed.Variables.cs index 1704d08..9a5c298 100644 --- a/Client/Scripts/Sync/Entities/Ped/SyncedPed.Variables.cs +++ b/Client/Scripts/Sync/Entities/Ped/SyncedPed.Variables.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using GTA; using GTA.Math; +using LemonUI.Elements; using RageCoop.Core; namespace RageCoop.Client @@ -20,6 +21,7 @@ namespace RageCoop.Client private bool _lastRagdoll; private ulong _lastRagdollTime; private Dictionary _lastWeaponComponents; + private ScaledText _nameTag; internal Entity WeaponObj; internal BlipColor BlipColor = (BlipColor)255; internal float BlipScale = 1; diff --git a/Client/Scripts/Sync/Entities/Ped/SyncedPed.cs b/Client/Scripts/Sync/Entities/Ped/SyncedPed.cs index 62b7d49..dcb1995 100644 --- a/Client/Scripts/Sync/Entities/Ped/SyncedPed.cs +++ b/Client/Scripts/Sync/Entities/Ped/SyncedPed.cs @@ -149,23 +149,34 @@ namespace RageCoop.Client LastUpdated = Ticked; } - private void RenderNameTag() { - if (!Owner.DisplayNameTag || !Settings.ShowPlayerNameTag || MainPed == null || !MainPed.IsVisible || - !MainPed.IsInRange(PlayerPosition, 40f)) return; + if (!Owner.DisplayNameTag || !Settings.ShowPlayerNameTag || MainPed == null || !MainPed.IsVisible) + return; + + float dist = PlayerPosition.DistanceToSquared2D(MainPed.Position); + if (dist > 10 * 10f) + return; + + float scale = 1f - (0.8f * dist) / 20f; + float fontSize = 0.6f * scale; + float frameTime = Call(GET_FRAME_TIME); + Vector3 headPos = MainPed.Bones[Bone.IKHead].Position; + headPos.Z += 0.5f; + headPos += Velocity * frameTime; - var targetPos = MainPed.Bones[Bone.IKHead].Position + Vector3.WorldUp * 0.5f; Point toDraw = default; - if (Util.WorldToScreen(targetPos, ref toDraw)) + if (Util.WorldToScreen(headPos, ref toDraw)) { - toDraw.Y -= 100; - new ScaledText(toDraw, Owner.Username, 0.4f, Font.ChaletLondon) + _nameTag ??= new ScaledText(toDraw, Owner.Username, fontSize, Font.ChaletLondon) { - Outline = true, Alignment = Alignment.Center, - Color = Owner.HasDirectConnection ? Color.FromArgb(179, 229, 252) : Color.White - }.Draw(); + Outline = true + }; + _nameTag.Position = toDraw; + _nameTag.Scale = fontSize; + _nameTag.Color = Owner.HasDirectConnection ? Color.FromArgb(179, 229, 252) : Color.White; + _nameTag.Draw(); } } diff --git a/Client/Scripts/Util/Util.cs b/Client/Scripts/Util/Util.cs index 7a210c7..dba83a4 100644 --- a/Client/Scripts/Util/Util.cs +++ b/Client/Scripts/Util/Util.cs @@ -83,17 +83,14 @@ namespace RageCoop.Client } } - public static bool WorldToScreen(Vector3 pos, ref Point screenPos) + public static unsafe bool WorldToScreen(Vector3 pos, ref Point screenPos) { float x, y; - unsafe + var res = ResolutionMaintainRatio; + if (Call(GET_SCREEN_COORD_FROM_WORLD_COORD, pos.X, pos.Y, pos.Z, &x, &y)) { - var res = ResolutionMaintainRatio; - if (Call(GET_SCREEN_COORD_FROM_WORLD_COORD, pos.X, pos.Y, pos.Z, &x, &y)) - { - screenPos = new Point((int)(res.Width * x), (int)(y * 1080)); - return true; - } + screenPos = new Point((int)(res.Width * x), (int)(y * 1080)); + return true; } return false; diff --git a/libs/ScriptHookVDotNetCore b/libs/ScriptHookVDotNetCore index aef51f4..5bca7ca 160000 --- a/libs/ScriptHookVDotNetCore +++ b/libs/ScriptHookVDotNetCore @@ -1 +1 @@ -Subproject commit aef51f4d5877dad309856fb1f4cd99e3e6a40b81 +Subproject commit 5bca7ca4e459a37be87d2cbeb688e7b7f15244de