]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/centerprint.qc
Fix #2433 "Bold messages appearing twice"
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / centerprint.qc
index f67cbffbd04d176160d072b1e6bddcbfe3e045b0..446a64ec65649c7266c890f56fdc803f366dec72 100644 (file)
@@ -2,8 +2,13 @@
 
 #include "scoreboard.qh"
 #include <common/notifications/all.qh>
+#include <client/defs.qh>
+#include <client/miscfunctions.qh>
 
 // CenterPrint (#16)
+// These are the functions that draw the text at the center of the screen (e.g. frag messages and server MOTDs).
+// Usually local_notification_centerprint_generic() is called, which in turn calls centerprint_generic(), which
+// uses some kind of macro magic to call HUD_CenterPrint, which draws them on screen using drawcolorcodedstring().
 
 const int CENTERPRINT_MAX_MSGS = 10;
 const int CENTERPRINT_MAX_ENTRIES = 50;
@@ -18,7 +23,7 @@ bool centerprint_showing;
 
 void centerprint_generic(int new_id, string strMessage, float duration, int countdown_num)
 {
-    TC(int, new_id); TC(int, countdown_num);
+       TC(int, new_id); TC(int, countdown_num);
        //printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num);
        int i, j;
 
@@ -73,9 +78,7 @@ void centerprint_generic(int new_id, string strMessage, float duration, int coun
                        cpm_index = CENTERPRINT_MAX_MSGS - 1;
                j = cpm_index;
        }
-       if(centerprint_messages[j])
-               strunzone(centerprint_messages[j]);
-       centerprint_messages[j] = strzone(strMessage);
+       strcpy(centerprint_messages[j], strMessage);
        centerprint_msgID[j] = new_id;
        if (duration < 0)
        {
@@ -94,7 +97,7 @@ void centerprint_generic(int new_id, string strMessage, float duration, int coun
 
 void centerprint_kill(int id)
 {
-    TC(int, id);
+       TC(int, id);
        centerprint_generic(id, "", 0, 0);
 }
 
@@ -110,11 +113,10 @@ void reset_centerprint_messages()
                centerprint_expire_time[i] = 0;
                centerprint_time[i] = 1;
                centerprint_msgID[i] = 0;
-               if(centerprint_messages[i])
-                       strunzone(centerprint_messages[i]);
-               centerprint_messages[i] = string_null;
+               strfree(centerprint_messages[i]);
        }
 }
+
 float hud_configure_cp_generation_time;
 void HUD_CenterPrint ()
 {
@@ -139,16 +141,16 @@ void HUD_CenterPrint ()
                                float r;
                                r = random();
                                if (r > 0.8)
-                                       centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: ^COUNT"), 1, 10);
+                                       centerprint_generic(floor(r*1000), sprintf(_("^3Countdown message at time %s, seconds left: ^COUNT"), seconds_tostring(time)), 1, 10);
                                else if (r > 0.55)
-                                       centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
+                                       centerprint_generic(0, sprintf(_("^1Multiline message at time %s that\n^1lasts longer than normal"), seconds_tostring(time)), 20, 0);
                                else
-                                       centerprint_hud(sprintf("Message at time %s", seconds_tostring(time)));
+                                       centerprint_hud(sprintf(_("Message at time %s"), seconds_tostring(time)));
                                hud_configure_cp_generation_time = time + 1 + random()*4;
                        }
                        else
                        {
-                               centerprint_generic(0, sprintf("Centerprint message", seconds_tostring(time)), 10, 0);
+                               centerprint_generic(0, _("Generic message"), 10, 0);
                                hud_configure_cp_generation_time = time + 10 - random()*3;
                        }
                }
@@ -161,16 +163,16 @@ void HUD_CenterPrint ()
                if (hud_panel_radar_bottom >= 0.96 * vid_conheight)
                        return;
 
-               panel_pos = eY * hud_panel_radar_bottom + eX * 0.5 * (vid_conwidth - panel_size_x);
-               panel_size_y = min(panel_size_y, vid_conheight - hud_panel_radar_bottom);
+               panel_pos.x = 0.5 * (vid_conwidth - panel_size.x);
+               panel_pos.y = hud_panel_radar_bottom;
+               panel_size.y = min(panel_size.y, vid_conheight - hud_panel_radar_bottom);
        }
        else if(!autocvar__hud_configure && scoreboard_fade_alpha)
        {
                // move the panel below the scoreboard
                if (scoreboard_bottom >= 0.96 * vid_conheight)
                        return;
-               vector target_pos;
-               target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size.x);
+               vector target_pos = vec2(0.5 * (vid_conwidth - panel_size.x), scoreboard_bottom);
                if(target_pos.y > panel_pos.y)
                {
                        panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
@@ -193,15 +195,11 @@ void HUD_CenterPrint ()
                panel_size -= '2 2 0' * panel_bg_padding;
        }
 
+       bool is_bold;
+       string centerprint_message = strzone("");
        int entries;
        float height;
        vector fontsize;
-       // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
-       // height = panel_size_y/entries;
-       // fontsize = '1 1 0' * height;
-       height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
-       fontsize = '1 1 0' * height;
-       entries = bound(1, floor(panel_size.y/height), CENTERPRINT_MAX_ENTRIES);
 
        int i, j, k, n, g;
        float a, sz, align, current_msg_posY = 0, msg_size;
@@ -215,6 +213,21 @@ void HUD_CenterPrint ()
        align = bound(0, autocvar_hud_panel_centerprint_align, 1);
        for (g=0, i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
        {
+               // if the notification starts with ^BOLD make it bold (e.g. frag messages);
+               is_bold = (substring(centerprint_messages[j], 0, 5) == BOLD_OPERATOR);
+               // remove ^BOLD so it doesn't get printed onscreen
+               if (is_bold)
+                       strcpy(centerprint_message, substring(centerprint_messages[j], 5, -1));
+               else
+                       strcpy(centerprint_message, centerprint_messages[j]);
+
+               // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
+               // height = panel_size_y/entries;
+               // fontsize = '1 1 0' * height;
+               height = (is_bold) ? vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale_bold : vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
+               fontsize = '1 1 0' * height;
+               entries = bound(1, floor(panel_size.y/height), CENTERPRINT_MAX_ENTRIES);
+
                if (j == CENTERPRINT_MAX_MSGS)
                        j = 0;
                if (centerprint_expire_time[j] == -1)
@@ -274,9 +287,9 @@ void HUD_CenterPrint ()
                drawfontscale = hud_scale * sz;
 
                if (centerprint_countdown_num[j])
-                       n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n");
+                       n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_message), "\n");
                else
-                       n = tokenizebyseparator(centerprint_messages[j], "\n");
+                       n = tokenizebyseparator(centerprint_message, "\n");
 
                if (autocvar_hud_panel_centerprint_flip)
                {
@@ -308,7 +321,9 @@ void HUD_CenterPrint ()
                                        if (align)
                                                pos.x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize) * sz) * align;
                                        if (a > 0.5/255.0)  // Otherwise guaranteed invisible - don't show. This is checked a second time after some multiplications with other factors were done so temporary changes of these cannot cause flicker.
+                                               if (is_bold) draw_beginBoldFont();
                                                drawcolorcodedstring(pos + eY * 0.5 * (1 - sz * hud_scale.x) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL);
+                                               if (is_bold) draw_endBoldFont();
                                        pos.y += fontsize.y;
                                }
                                else
@@ -328,6 +343,7 @@ void HUD_CenterPrint ()
                        if (pos.y < panel_pos.y) // check if the next message can be shown
                        {
                                drawfontscale = hud_scale;
+                               strfree(centerprint_message);
                                return;
                        }
                }
@@ -340,10 +356,13 @@ void HUD_CenterPrint ()
                        if(pos.y > panel_pos.y + panel_size.y - fontsize.y) // check if the next message can be shown
                        {
                                drawfontscale = hud_scale;
+                               strfree(centerprint_message);
                                return;
                        }
                }
        }
+       strfree(centerprint_message);
+
        drawfontscale = hud_scale;
        if (all_messages_expired)
        {