From: z411 Date: Wed, 13 Apr 2022 06:29:16 +0000 (+0000) Subject: Calculate centerprint title offset in real time in duel X-Git-Tag: xonotic-v0.8.5~79^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6dd4659238510d0d4452bed9cfc56fb0e6bbef2f;p=xonotic%2Fxonotic-data.pk3dir.git Calculate centerprint title offset in real time in duel --- diff --git a/qcsrc/client/announcer.qc b/qcsrc/client/announcer.qc index 59f977818..e86702afa 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 307e3c899..1436f2ef6 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 b1d52cf0a..02a046a6a 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);