New nametag rendering
This commit is contained in:
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<bool>(GET_SCREEN_COORD_FROM_WORLD_COORD, pos.X, pos.Y, pos.Z, &x, &y))
|
||||
{
|
||||
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;
|
||||
}
|
||||
screenPos = new Point((int)(res.Width * x), (int)(y * 1080));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Submodule libs/ScriptHookVDotNetCore updated: aef51f4d58...5bca7ca4e4
Reference in New Issue
Block a user