summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/gokz-hud/timer_text.sp
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2023-12-04 18:06:10 +0100
committernavewindre <nw@moneybot.cc>2023-12-04 18:06:10 +0100
commitaef0d1c1268ab7d4bc18996c9c6b4da16a40aadc (patch)
tree43e766b51704f4ab8b383583bdc1871eeeb9c698 /sourcemod/scripting/gokz-hud/timer_text.sp
parent38f1140c11724da05a23a10385061200b907cf6e (diff)
bbbbbbbbwaaaaaaaaaaa
Diffstat (limited to 'sourcemod/scripting/gokz-hud/timer_text.sp')
-rw-r--r--sourcemod/scripting/gokz-hud/timer_text.sp135
1 files changed, 135 insertions, 0 deletions
diff --git a/sourcemod/scripting/gokz-hud/timer_text.sp b/sourcemod/scripting/gokz-hud/timer_text.sp
new file mode 100644
index 0000000..a5fd17b
--- /dev/null
+++ b/sourcemod/scripting/gokz-hud/timer_text.sp
@@ -0,0 +1,135 @@
+/*
+ Uses HUD text to show current run time somewhere on the screen.
+
+ This is manually refreshed whenever the players' timer is started, ended or
+ stopped to improve responsiveness.
+*/
+
+
+
+static Handle timerHudSynchronizer;
+
+
+
+// =====[ PUBLIC ]=====
+
+char[] FormatTimerTextForMenu(KZPlayer player, HUDInfo info)
+{
+ char timerTextString[32];
+ if (info.TimerRunning)
+ {
+ if (player.GetHUDOption(HUDOption_TimerType) == TimerType_Enabled)
+ {
+ FormatEx(timerTextString, sizeof(timerTextString),
+ "%s %s",
+ gC_TimeTypeNames[info.TimeType],
+ GOKZ_HUD_FormatTime(player.ID, info.Time));
+ }
+ else
+ {
+ FormatEx(timerTextString, sizeof(timerTextString),
+ "%s",
+ GOKZ_HUD_FormatTime(player.ID, info.Time));
+ }
+ if (info.Paused)
+ {
+ Format(timerTextString, sizeof(timerTextString), "%s (%T)", timerTextString, "Info Panel Text - PAUSED", player.ID);
+ }
+ }
+ return timerTextString;
+}
+
+
+
+// =====[ EVENTS ]=====
+
+void OnPluginStart_TimerText()
+{
+ timerHudSynchronizer = CreateHudSynchronizer();
+}
+
+void OnPlayerRunCmdPost_TimerText(int client, int cmdnum, HUDInfo info)
+{
+ int updateSpeed = gB_FastUpdateRate[client] ? 3 : 6;
+ if (cmdnum % updateSpeed == 1)
+ {
+ UpdateTimerText(client, info);
+ }
+}
+
+void OnOptionChanged_TimerText(int client, HUDOption option)
+{
+ if (option == HUDOption_TimerText)
+ {
+ ClearTimerText(client);
+ }
+}
+
+void OnTimerEnd_TimerText(int client)
+{
+ ClearTimerText(client);
+}
+
+void OnTimerStopped_TimerText(int client)
+{
+ ClearTimerText(client);
+}
+
+
+// =====[ PRIVATE ]=====
+
+static void UpdateTimerText(int client, HUDInfo info)
+{
+ KZPlayer player = KZPlayer(client);
+
+ if (player.Fake)
+ {
+ return;
+ }
+
+ ShowTimerText(player, info);
+}
+
+static void ClearTimerText(int client)
+{
+ ClearSyncHud(client, timerHudSynchronizer);
+}
+
+static void ShowTimerText(KZPlayer player, HUDInfo info)
+{
+ if (!info.TimerRunning)
+ {
+ if (player.ID != info.ID)
+ {
+ CancelGOKZHUDMenu(player.ID);
+ }
+ return;
+ }
+ if (player.TimerText == TimerText_Top || player.TimerText == TimerText_Bottom)
+ {
+ int colour[4]; // RGBA
+ if (player.GetHUDOption(HUDOption_TimerType) == TimerType_Enabled)
+ {
+ switch (info.TimeType)
+ {
+ case TimeType_Nub:colour = { 234, 209, 138, 0 };
+ case TimeType_Pro:colour = { 181, 212, 238, 0 };
+ }
+ }
+ else colour = { 255, 255, 255, 0};
+
+ switch (player.TimerText)
+ {
+ case TimerText_Top:
+ {
+ SetHudTextParams(-1.0, 0.07, GetTextHoldTime(gB_FastUpdateRate[player.ID] ? 3 : 6), colour[0], colour[1], colour[2], colour[3], 0, 1.0, 0.0, 0.0);
+ }
+ case TimerText_Bottom:
+ {
+ SetHudTextParams(-1.0, 0.9, GetTextHoldTime(gB_FastUpdateRate[player.ID] ? 3 : 6), colour[0], colour[1], colour[2], colour[3], 0, 1.0, 0.0, 0.0);
+ }
+ }
+
+ ShowSyncHudText(player.ID, timerHudSynchronizer, GOKZ_HUD_FormatTime(player.ID, info.Time));
+ }
+} \ No newline at end of file