From 8f5ea8bde0ee39ae1ca798c3e735bb24e73ced7b Mon Sep 17 00:00:00 2001 From: z411 Date: Wed, 9 Mar 2022 06:32:45 -0300 Subject: [PATCH] Create centerprint titles --- hud_luma.cfg | 1 + qcsrc/client/announcer.qc | 9 ++++++ qcsrc/client/hud/panel/centerprint.qc | 46 +++++++++++++++++++++++++-- qcsrc/client/hud/panel/centerprint.qh | 8 +++-- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/hud_luma.cfg b/hud_luma.cfg index c1f668aaf..bd0a1d93c 100644 --- a/hud_luma.cfg +++ b/hud_luma.cfg @@ -275,6 +275,7 @@ seta hud_panel_centerprint_align "0.5" seta hud_panel_centerprint_flip "0" seta hud_panel_centerprint_fontscale "1.4" seta hud_panel_centerprint_fontscale_bold "2" +seta hud_panel_centerprint_fontscale_bold "2.5" seta hud_panel_minigameboard_pos "0.22 0.15" seta hud_panel_minigameboard_size "0.50 0.60" diff --git a/qcsrc/client/announcer.qc b/qcsrc/client/announcer.qc index 5baaddeff..309d4a603 100644 --- a/qcsrc/client/announcer.qc +++ b/qcsrc/client/announcer.qc @@ -4,6 +4,7 @@ #include #include #include +#include bool announcer_1min; bool announcer_5min; @@ -26,6 +27,7 @@ void Announcer_Countdown(entity this) Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP); delete(this); announcer_countdown = NULL; + centerprint_ClearTitle(); return; } if(starttime <= time && roundstarttime != starttime) // game start time has passed @@ -35,12 +37,15 @@ void Announcer_Countdown(entity this) float countdown = (inround ? roundstarttime - time : starttime - time); float countdown_rounded = floor(0.5 + countdown); + if(time >= starttime) centerprint_ClearTitle(); + if(countdown <= 0) // countdown has finished, starttime is now { Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN); Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN); delete(this); announcer_countdown = NULL; + centerprint_ClearTitle(); return; } else // countdown is still going @@ -102,6 +107,10 @@ void Announcer_Gamestart() setthink(announcer_countdown, Announcer_Countdown); } + // Set centerprint title + if(time < STAT(GAMESTARTTIME) && !warmup_stage) + centerprint_SetTitle(MapInfo_Type_ToText(gametype)); + if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle if(time > announcer_countdown.nextthink) // don't play it again if countdown was already going Local_Notification(MSG_ANNCE, ANNCE_PREPARE); diff --git a/qcsrc/client/hud/panel/centerprint.qc b/qcsrc/client/hud/panel/centerprint.qc index e8299414f..c3022b396 100644 --- a/qcsrc/client/hud/panel/centerprint.qc +++ b/qcsrc/client/hud/panel/centerprint.qc @@ -34,6 +34,7 @@ void HUD_CenterPrint_Export(int fh) const int CENTERPRINT_MAX_MSGS = 10; const int CENTERPRINT_MAX_ENTRIES = 50; const float CENTERPRINT_SPACING = 0.5; +const float CENTERPRINT_TITLE_SPACING = 1; int cpm_index; string centerprint_messages[CENTERPRINT_MAX_MSGS]; int centerprint_msgID[CENTERPRINT_MAX_MSGS]; @@ -43,6 +44,9 @@ float centerprint_expire_time[CENTERPRINT_MAX_MSGS]; int centerprint_countdown_num[CENTERPRINT_MAX_MSGS]; bool centerprint_showing; +bool centerprint_title_show; +string centerprint_title; + void centerprint_Add(int new_id, string strMessage, float duration, int countdown_num) { TC(int, new_id); TC(int, countdown_num); @@ -141,6 +145,23 @@ void centerprint_KillAll() } } +void centerprint_ClearTitle() +{ + strfree(centerprint_title); + centerprint_title_show = false; +} + +void centerprint_SetTitle(string title) +{ + if(title != centerprint_title) { + if(centerprint_title) + strfree(centerprint_title); + + centerprint_title = strzone(title); + centerprint_title_show = true; + } +} + float hud_configure_cp_generation_time; void HUD_CenterPrint() { @@ -148,8 +169,10 @@ void HUD_CenterPrint() { if(!autocvar_hud_panel_centerprint) return; - if(hud_configure_prev) + if(hud_configure_prev) { + centerprint_ClearTitle(); centerprint_KillAll(); + } } else { @@ -162,6 +185,8 @@ void HUD_CenterPrint() { if(highlightedPanel == HUD_PANEL(CENTERPRINT)) { + centerprint_SetTitle(strcat("test", ftos(hud_configure_cp_generation_time))); + float r; r = random(); if (r > 0.8) @@ -222,7 +247,7 @@ void HUD_CenterPrint() } int i, j, k, n, g; - float a, sz, align, current_msg_posY = 0, msg_size; + float a = 1, sz, align, current_msg_posY = 0, msg_size; vector pos; string ts = ""; bool all_messages_expired = true; @@ -231,6 +256,22 @@ void HUD_CenterPrint() if (autocvar_hud_panel_centerprint_flip) pos.y += panel_size.y; align = bound(0, autocvar_hud_panel_centerprint_align, 1); + + // Show title if available + if(centerprint_title_show) { + vector fontsize = hud_fontsize * autocvar_hud_panel_centerprint_fontscale_title; + + pos.x = panel_pos.x + (panel_size.x - stringwidth(centerprint_title, true, fontsize)) * align; + drawcolorcodedstring(pos, centerprint_title, fontsize, 1, DRAWFLAG_NORMAL); + + if (autocvar_hud_panel_centerprint_flip) + pos.y -= fontsize.y + CENTERPRINT_TITLE_SPACING; + else + pos.y += fontsize.y + CENTERPRINT_TITLE_SPACING; + + all_messages_expired = false; + } + for (g=0, i=0, j=cpm_index; i