Update nametag drawing method

This commit is contained in:
Sardelka
2022-07-14 10:33:24 +08:00
parent 1e2a9992d8
commit 038860f158
3 changed files with 47 additions and 16 deletions

View File

@ -180,7 +180,7 @@ namespace RageCoop.Client
}
}
internal class DownloadFile: System.IDisposable
internal class DownloadFile: IDisposable
{
public int FileID { get; set; } = 0;
public string FileName { get; set; } = string.Empty;

View File

@ -205,26 +205,23 @@ namespace RageCoop.Client
private void RenderNameTag()
{
if (!Player.DisplayNameTag || (MainPed==null) || !MainPed.IsVisible || !MainPed.IsInRange(Game.Player.Character.Position, 20f))
if (!Player.DisplayNameTag || (MainPed==null) || !MainPed.IsVisible || !MainPed.IsInRange(Game.Player.Character.Position, 40f))
{
return;
}
string renderText = IsOutOfSync ? "~r~AFK" : Player.Username;
Vector3 targetPos = MainPed.Bones[Bone.IKHead].Position + new Vector3(0, 0, 0.35f);
Function.Call(Hash.SET_DRAW_ORIGIN, targetPos.X, targetPos.Y, targetPos.Z, 0);
float dist = (GameplayCamera.Position - MainPed.Position).Length();
var sizeOffset = Math.Max(1f - (dist / 30f), 0.3f);
new ScaledText(new PointF(0, 0), renderText, 0.4f * sizeOffset, GTA.UI.Font.ChaletLondon)
Vector3 targetPos = MainPed.Bones[Bone.IKHead].Position;
Point toDraw=default;
if (Util.WorldToScreen(targetPos, ref toDraw))
{
Outline = true,
Alignment = GTA.UI.Alignment.Center
}.Draw();
Function.Call(Hash.CLEAR_DRAW_ORIGIN);
toDraw.Y-=100;
new ScaledText(toDraw, Player.Username, 0.4f, GTA.UI.Font.ChaletLondon)
{
Outline = true,
Alignment = GTA.UI.Alignment.Center
}.Draw();
}
}
private void CreateCharacter()

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using GTA.Math;
using System.Drawing;
using GTA;
using RageCoop.Core;
using GTA.Native;
@ -16,6 +17,37 @@ namespace RageCoop.Client
{
internal static class Util
{
public static SizeF ResolutionMaintainRatio
{
get
{
// Get the game width and height
int screenw = GTA.UI.Screen.Resolution.Width;
int screenh = GTA.UI.Screen.Resolution.Height;
// Calculate the ratio
float ratio = (float)screenw / screenh;
// And the width with that ratio
float width = 1080f * ratio;
// Finally, return a SizeF
return new SizeF(width, 1080f);
}
}
public static bool WorldToScreen(Vector3 pos, ref Point screenPos)
{
float x, y;
unsafe
{
var res = ResolutionMaintainRatio;
if (Function.Call<bool>(Hash.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;
}
#region -- POINTER --
private static int _steeringAngleOffset { get; set; }
@ -208,6 +240,7 @@ namespace RageCoop.Client
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
}
#region WIN32
const UInt32 WM_KEYDOWN = 0x0100;
public static void Reload()
@ -262,5 +295,6 @@ namespace RageCoop.Client
[DllImport("kernel32.dll")]
public static extern ulong GetTickCount64();
#endregion
}
}