1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
Uses HUD text to show current speed somewhere on the screen.
This is manually refreshed whenever player has taken off so that they see
their pre-speed as soon as possible, improving responsiveness.
*/
static Handle speedHudSynchronizer;
static bool speedTextDuckPressedLast[MAXPLAYERS + 1];
static bool speedTextOnGroundLast[MAXPLAYERS + 1];
static bool speedTextShowDuckString[MAXPLAYERS + 1];
// =====[ EVENTS ]=====
void OnPluginStart_SpeedText()
{
speedHudSynchronizer = CreateHudSynchronizer();
}
void OnPlayerRunCmdPost_SpeedText(int client, int cmdnum, HUDInfo info)
{
int updateSpeed = gB_FastUpdateRate[client] ? 3 : 6;
if (cmdnum % updateSpeed == 0 || info.IsTakeoff)
{
UpdateSpeedText(client, info);
}
speedTextOnGroundLast[info.ID] = info.OnGround;
speedTextDuckPressedLast[info.ID] = info.Ducking;
}
void OnOptionChanged_SpeedText(int client, HUDOption option)
{
if (option == HUDOption_SpeedText)
{
ClearSpeedText(client);
}
}
// =====[ PRIVATE ]=====
static void UpdateSpeedText(int client, HUDInfo info)
{
KZPlayer player = KZPlayer(client);
if (player.Fake
|| player.SpeedText != SpeedText_Bottom)
{
return;
}
ShowSpeedText(player, info);
}
static void ClearSpeedText(int client)
{
ClearSyncHud(client, speedHudSynchronizer);
}
static void ShowSpeedText(KZPlayer player, HUDInfo info)
{
if (info.Paused)
{
return;
}
int colour[4] = { 255, 255, 255, 0 }; // RGBA
float velZ = Movement_GetVerticalVelocity(info.ID);
if (!info.OnGround && !info.OnLadder && !info.Noclipping)
{
if (GOKZ_HUD_GetOption(player.ID, HUDOption_DeadstrafeColor) == DeadstrafeColor_Enabled && velZ > 0.0 && velZ < 140.0)
{
colour = { 255, 32, 32, 0 };
}
else if (info.HitPerf)
{
if (info.HitJB)
{
colour = { 255, 255, 32, 0 };
}
else
{
colour = { 64, 255, 64, 0 };
}
}
}
switch (player.SpeedText)
{
case SpeedText_Bottom:
{
// Set params based on the available screen space at max scaling HUD
if (!IsDrawingInfoPanel(player.ID))
{
SetHudTextParams(-1.0, 0.75, GetTextHoldTime(gB_FastUpdateRate[player.ID] ? 3 : 6), colour[0], colour[1], colour[2], colour[3], 0, 1.0, 0.0, 0.0);
}
else
{
SetHudTextParams(-1.0, 0.65, GetTextHoldTime(gB_FastUpdateRate[player.ID] ? 3 : 6), colour[0], colour[1], colour[2], colour[3], 0, 1.0, 0.0, 0.0);
}
}
}
if (info.OnGround || info.OnLadder || info.Noclipping)
{
ShowSyncHudText(player.ID, speedHudSynchronizer,
"%.0f",
RoundFloat(info.Speed * 10) / 10.0);
speedTextShowDuckString[info.ID] = false;
}
else
{
if (speedTextShowDuckString[info.ID]
|| (speedTextOnGroundLast[info.ID]
&& !info.HitBhop
&& info.IsTakeoff
&& info.Jumped
&& info.Ducking
&& (speedTextDuckPressedLast[info.ID] || GOKZ_GetCoreOption(info.ID, Option_Mode) == Mode_Vanilla)))
{
ShowSyncHudText(player.ID, speedHudSynchronizer,
"%.0f\n (%.0f)C",
RoundToPowerOfTen(info.Speed, -2),
RoundToPowerOfTen(info.TakeoffSpeed, -2));
speedTextShowDuckString[info.ID] = true;
}
else {
ShowSyncHudText(player.ID, speedHudSynchronizer,
"%.0f\n(%.0f)",
RoundToPowerOfTen(info.Speed, -2),
RoundToPowerOfTen(info.TakeoffSpeed, -2));
speedTextShowDuckString[info.ID] = false;
}
}
}
|