]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Calculate centerprint title offset in real time in duel
authorz411 <z411@omaera.org>
Wed, 13 Apr 2022 06:29:16 +0000 (06:29 +0000)
committerbones_was_here <bones_was_here@xa.org.au>
Wed, 13 Apr 2022 06:29:16 +0000 (06:29 +0000)
qcsrc/client/announcer.qc
qcsrc/client/hud/panel/centerprint.qc
qcsrc/client/hud/panel/centerprint.qh

index 59f977818748240387cc9cca1bc569093a9623d4..e86702afa086a8314ee12ba92540f605929a6b7d 100644 (file)
@@ -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);
index 307e3c899a52504a30b464dfcd5c3ee45ff70308..1436f2ef6a9d48e8675976e190ee76c542847329 100644 (file)
@@ -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);
 
index b1d52cf0adc06d4e14be1e837ac4f1ecd7dd7a41..02a046a6a140015eae8167254f1ff670e2354854 100644 (file)
@@ -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);