From 6dd4659238510d0d4452bed9cfc56fb0e6bbef2f Mon Sep 17 00:00:00 2001 From: z411 Date: Wed, 13 Apr 2022 06:29:16 +0000 Subject: [PATCH] Calculate centerprint title offset in real time in duel --- qcsrc/client/announcer.qc | 5 ++--- qcsrc/client/hud/panel/centerprint.qc | 29 +++++++++++++++++---------- qcsrc/client/hud/panel/centerprint.qh | 3 ++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/qcsrc/client/announcer.qc b/qcsrc/client/announcer.qc index 59f9778187..e86702afa0 100644 --- a/qcsrc/client/announcer.qc +++ b/qcsrc/client/announcer.qc @@ -42,8 +42,7 @@ void Announcer_Duel() strcpy(prev_pl2_name, pl2_name); // There are new duelers, update title - float offset = stringwidth(pl2_name, true, hud_fontsize) - stringwidth(pl1_name, true, hud_fontsize) - 1; - centerprint_SetTitle(sprintf("^BG%s^BG %s %s", pl1_name, _("vs"), pl2_name), offset / 2); + centerprint_SetDuelTitle(pl1_name, pl2_name, _("vs")); } void Announcer_ClearTitle() @@ -150,7 +149,7 @@ void Announcer_Gamestart() if (gametype.m_1v1) Announcer_Duel(); else - centerprint_SetTitle(strcat("^BG", MapInfo_Type_ToText(gametype)), 0); // Show game type as title + centerprint_SetTitle(strcat("^BG", MapInfo_Type_ToText(gametype))); // Show game type as title if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle Local_Notification(MSG_ANNCE, ANNCE_PREPARE); diff --git a/qcsrc/client/hud/panel/centerprint.qc b/qcsrc/client/hud/panel/centerprint.qc index 307e3c899a..1436f2ef6a 100644 --- a/qcsrc/client/hud/panel/centerprint.qc +++ b/qcsrc/client/hud/panel/centerprint.qc @@ -46,7 +46,8 @@ int centerprint_countdown_num[CENTERPRINT_MAX_MSGS]; bool centerprint_showing; string centerprint_title; -float centerprint_title_offset; +string centerprint_title_left; +string centerprint_title_right; void centerprint_Add(int new_id, string strMessage, float duration, int countdown_num) { @@ -150,18 +151,24 @@ void centerprint_KillAll() } } -void centerprint_ClearTitle() +void centerprint_SetDuelTitle(string left, string right, string div) { - strfree(centerprint_title); - centerprint_title_offset = 0; + strcpy(centerprint_title_left, left); + strcpy(centerprint_title_right, right); + centerprint_SetTitle(sprintf("^BG%s^BG %s %s", left, div, right)); } -void centerprint_SetTitle(string title, float offset) +void centerprint_SetTitle(string title) { - if(title != centerprint_title) { + if(title != centerprint_title) strcpy(centerprint_title, CCR(title)); - centerprint_title_offset = offset; - } +} + +void centerprint_ClearTitle() +{ + strfree(centerprint_title); + strfree(centerprint_title_left); + strfree(centerprint_title_right); } float hud_configure_cp_generation_time; @@ -187,7 +194,7 @@ void HUD_CenterPrint() { if(highlightedPanel == HUD_PANEL(CENTERPRINT)) { - centerprint_SetTitle(sprintf(_("Title at %s"), seconds_tostring(hud_configure_cp_generation_time)), 0); + centerprint_SetTitle(sprintf(_("Title at %s"), seconds_tostring(hud_configure_cp_generation_time))); float r; r = random(); @@ -268,8 +275,8 @@ void HUD_CenterPrint() if (autocvar_hud_panel_centerprint_flip) pos.y -= fontsize.y; - if (centerprint_title_offset && align == 0.5) - pos.x += centerprint_title_offset * CENTERPRINT_BASE_SIZE * autocvar_hud_panel_centerprint_fontscale_title; + if (centerprint_title_left != "" && align == 0.5) // Center line at the main word (for duels) + pos.x += (stringwidth(centerprint_title_right, true, fontsize) - stringwidth(centerprint_title_left, true, fontsize)) / 2; drawcolorcodedstring(pos, centerprint_title, fontsize, 1, DRAWFLAG_NORMAL); diff --git a/qcsrc/client/hud/panel/centerprint.qh b/qcsrc/client/hud/panel/centerprint.qh index b1d52cf0ad..02a046a6a1 100644 --- a/qcsrc/client/hud/panel/centerprint.qh +++ b/qcsrc/client/hud/panel/centerprint.qh @@ -23,5 +23,6 @@ void centerprint_AddStandard(string strMessage); void centerprint_Kill(int id); void centerprint_KillAll(); +void centerprint_SetDuelTitle(string left, string right, string div); +void centerprint_SetTitle(string title); void centerprint_ClearTitle(); -void centerprint_SetTitle(string title, float offset); -- 2.39.2