RAGECOOP-V/Client/PlayerList.cs

64 lines
2.1 KiB
C#
Raw Normal View History

2022-03-28 14:49:26 +02:00
using System.Collections.Generic;
2021-07-07 13:36:25 +02:00
2021-12-27 10:15:52 +01:00
using CoopClient.Entities.Player;
2021-07-07 13:36:25 +02:00
using GTA;
using GTA.Native;
namespace CoopClient
{
2022-03-28 14:49:26 +02:00
internal class PlayerList
2021-07-07 13:36:25 +02:00
{
private const float LEFT_POSITION = 0.122f;
private const float RIGHT_POSITION = 0.9f;
private readonly Scaleform _mainScaleform = new Scaleform("mp_mm_card_freemode");
private ulong _lastUpdate = Util.GetTickCount64();
2022-03-28 14:49:26 +02:00
internal ulong Pressed { get; set; }
2021-07-07 13:36:25 +02:00
2022-03-28 14:49:26 +02:00
internal bool LeftAlign = true;
2022-03-28 14:49:26 +02:00
public void Tick()
2021-08-13 15:20:26 +02:00
{
2021-08-17 15:04:50 +02:00
if (!Main.MainNetworking.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
}
if ((Util.GetTickCount64() - _lastUpdate) >= 1000)
2021-08-13 15:20:26 +02:00
{
2021-08-17 15:04:50 +02:00
Update(Main.Players, Main.MainSettings.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
#if !NON_INTERACTIVE
&& !Main.MainMenu.MenuPool.AreAnyVisible
#endif
)
2021-08-13 15:20:26 +02:00
{
Function.Call(Hash.DRAW_SCALEFORM_MOVIE, _mainScaleform.Handle,
LeftAlign ? LEFT_POSITION : RIGHT_POSITION, 0.3f,
0.28f, 0.6f,
255, 255, 255, 255, 0);
2021-08-13 15:20:26 +02:00
}
}
2021-08-16 14:03:05 +02:00
private void Update(Dictionary<long, EntitiesPlayer> players, string localUsername)
2021-07-07 13:36:25 +02:00
{
_lastUpdate = Util.GetTickCount64();
2021-08-13 15:20:26 +02:00
_mainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
_mainScaleform.CallFunction("SET_DATA_SLOT", 0, $"{Main.MainNetworking.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
2021-08-16 14:03:05 +02:00
foreach (KeyValuePair<long, EntitiesPlayer> player in players)
2021-07-07 13:36:25 +02: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
}
_mainScaleform.CallFunction("SET_TITLE", "Player list", (players.Count + 1) + " players");
_mainScaleform.CallFunction("DISPLAY_VIEW");
2021-07-07 13:36:25 +02:00
}
}
}