New nametag rendering

This commit is contained in:
Sardelka9515
2023-03-15 15:58:03 +08:00
parent fd4b5f8afb
commit 920b5d15ba
5 changed files with 30 additions and 20 deletions

View File

@ -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());

View File

@ -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<uint, bool> _lastWeaponComponents;
private ScaledText _nameTag;
internal Entity WeaponObj;
internal BlipColor BlipColor = (BlipColor)255;
internal float BlipScale = 1;

View File

@ -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<float>(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();
}
}

View File

@ -83,18 +83,15 @@ 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<bool>(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;
}
}
return false;
}