2022-03-28 14:49:26 +02:00
|
|
|
|
using System.Collections.Generic;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
using System.Linq;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
using GTA;
|
2022-06-22 08:58:36 +08:00
|
|
|
|
using GTA.Math;
|
2022-06-22 14:18:20 +08:00
|
|
|
|
using RageCoop.Core;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
using GTA.Native;
|
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
namespace RageCoop.Client
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-06-12 15:39:32 +08:00
|
|
|
|
internal static class PlayerList
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-02-24 21:29:04 -07:00
|
|
|
|
private const float LEFT_POSITION = 0.122f;
|
|
|
|
|
private const float RIGHT_POSITION = 0.9f;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
private static readonly Scaleform _mainScaleform = new Scaleform("mp_mm_card_freemode");
|
|
|
|
|
private static ulong _lastUpdate = Util.GetTickCount64();
|
|
|
|
|
public static ulong Pressed { get; set; }
|
2022-02-24 21:29:04 -07:00
|
|
|
|
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static bool LeftAlign = true;
|
2022-06-22 14:18:20 +08:00
|
|
|
|
public static Dictionary<int,PlayerData> Players=new Dictionary<int, PlayerData> { };
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static void Tick()
|
2021-08-13 15:20:26 +02:00
|
|
|
|
{
|
2022-05-25 11:32:34 +08:00
|
|
|
|
if (!Networking.IsOnServer)
|
2021-08-13 15:20:26 +02:00
|
|
|
|
{
|
2021-08-17 15:04:50 +02:00
|
|
|
|
return;
|
2021-08-13 15:20:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if ((Util.GetTickCount64() - _lastUpdate) >= 1000)
|
2021-08-13 15:20:26 +02:00
|
|
|
|
{
|
2022-05-22 15:55:26 +08:00
|
|
|
|
Update( Main.Settings.Username);
|
2021-08-13 15:20:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 22:08:15 +01:00
|
|
|
|
if ((Util.GetTickCount64() - Pressed) < 5000 && !Main.MainChat.Focused
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#if !NON_INTERACTIVE
|
2022-05-31 09:14:30 +08:00
|
|
|
|
&& !Menus.CoopMenu.MenuPool.AreAnyVisible
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#endif
|
|
|
|
|
)
|
2021-08-13 15:20:26 +02:00
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
Function.Call(Hash.DRAW_SCALEFORM_MOVIE, _mainScaleform.Handle,
|
2022-03-20 09:21:41 +01:00
|
|
|
|
LeftAlign ? LEFT_POSITION : RIGHT_POSITION, 0.3f,
|
2022-02-24 21:29:04 -07:00
|
|
|
|
0.28f, 0.6f,
|
|
|
|
|
255, 255, 255, 255, 0);
|
2021-08-13 15:20:26 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 16:59:49 +08:00
|
|
|
|
private static void Update( string localUsername)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_lastUpdate = Util.GetTickCount64();
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_mainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
|
2022-05-23 16:59:49 +08:00
|
|
|
|
_mainScaleform.CallFunction("SET_DATA_SLOT", 0, $"{Networking.Latency * 1000:N0}ms", localUsername, 116, 0, 0, "", "", 2, "", "", ' ');
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
int i = 1;
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
foreach (var player in Players)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-06-22 14:18:20 +08:00
|
|
|
|
_mainScaleform.CallFunction("SET_DATA_SLOT", i++, $"{player.Value.Latency * 1000:N0}ms", player.Value.Username, 116, 0, i - 1, "", "", 2, "", "", ' ');
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 11:11:40 +08:00
|
|
|
|
_mainScaleform.CallFunction("SET_TITLE", "Player list", $"{Players.Count+1} players");
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_mainScaleform.CallFunction("DISPLAY_VIEW");
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-05-25 10:09:59 +08:00
|
|
|
|
public static void SetPlayer(int id, string username,float latency=0)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
2022-06-22 14:18:20 +08:00
|
|
|
|
PlayerData p;
|
|
|
|
|
if (Players.TryGetValue(id,out p))
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
|
|
|
|
p.Username=username;
|
|
|
|
|
p.PedID=id;
|
2022-05-25 10:09:59 +08:00
|
|
|
|
p.Latency=latency;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-06-22 14:18:20 +08:00
|
|
|
|
p = new PlayerData { PedID=id, Username=username,Latency=latency };
|
|
|
|
|
Players.Add(id,p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static void UpdatePlayer(Packets.PlayerInfoUpdate packet)
|
|
|
|
|
{
|
|
|
|
|
var p = GetPlayer(packet.PedID);
|
|
|
|
|
if(p?.Character != null)
|
|
|
|
|
{
|
2022-07-03 10:46:24 +08:00
|
|
|
|
p.Latency= packet.Latency;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static PlayerData GetPlayer(int id)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-06-22 14:18:20 +08:00
|
|
|
|
PlayerData p;
|
|
|
|
|
Players.TryGetValue(id, out p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
public static PlayerData GetPlayer(SyncedPed p)
|
|
|
|
|
{
|
|
|
|
|
var player = GetPlayer(p.ID);
|
|
|
|
|
player.Character=p;
|
|
|
|
|
return player;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static void RemovePlayer(int id)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-06-22 14:18:20 +08:00
|
|
|
|
if (Players.ContainsKey(id))
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-06-22 14:18:20 +08:00
|
|
|
|
Players.Remove(id);
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static void Cleanup()
|
|
|
|
|
{
|
2022-06-22 14:18:20 +08:00
|
|
|
|
Players=new Dictionary<int, PlayerData>{ };
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-06-22 08:58:36 +08:00
|
|
|
|
|
2022-06-22 14:18:20 +08:00
|
|
|
|
|
|
|
|
|
internal class PlayerData
|
2022-06-22 08:58:36 +08:00
|
|
|
|
{
|
|
|
|
|
public string Username { get; internal set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Universal character ID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int PedID
|
|
|
|
|
{
|
|
|
|
|
get; internal set;
|
|
|
|
|
}
|
2022-06-22 14:18:20 +08:00
|
|
|
|
public SyncedPed Character { get; set; }
|
2022-06-22 08:58:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Player Latency in second.
|
|
|
|
|
/// </summary>
|
2022-07-09 19:32:11 +08:00
|
|
|
|
public float Latency { get; set; }
|
2022-06-22 14:18:20 +08:00
|
|
|
|
|
2022-07-09 19:32:11 +08:00
|
|
|
|
public bool DisplayNameTag { get; set; } = true;
|
2022-06-22 08:58:36 +08:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|