]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
New panel for centerprint messages
authorterencehill <piuntn@gmail.com>
Mon, 23 May 2011 16:41:16 +0000 (18:41 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 23 May 2011 16:41:16 +0000 (18:41 +0200)
hud_luminos.cfg
qcsrc/client/View.qc
qcsrc/client/autocvars.qh
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/client/hud_config.qc
qcsrc/common/constants.qh
qcsrc/common/util.qh

index 4c11d42079856dee560dc26463a74c9e2001df10..13b241d4f8258044177d1258e42e927fecd174b7 100644 (file)
@@ -23,7 +23,7 @@ seta hud_progressbar_speed_color "1 0.75 0"
 seta hud_progressbar_acceleration_color "0.5 0.75 1"
 seta hud_progressbar_acceleration_neg_color "0.125 0.25 0.5"
 
-seta _hud_panelorder "15 12 9 10 5 6 14 0 7 4 11 2 1 3 8 13 "
+seta _hud_panelorder "15 12 9 10 5 6 14 0 7 4 11 2 1 3 8 13 16 "
 
 seta hud_configure_grid "1"
 seta hud_configure_grid_xsize "0.010000"
@@ -101,6 +101,18 @@ seta hud_panel_healtharmor_progressbar_health "progressbar"
 seta hud_panel_healtharmor_progressbar_armor "progressbar"
 seta hud_panel_healtharmor_text "1"
 
+seta hud_panel_centerprint 1
+seta hud_panel_centerprint_pos "0.180000 0.260000"
+seta hud_panel_centerprint_size "0.650000 0.210000"
+seta hud_panel_centerprint_bg "0"
+seta hud_panel_centerprint_bg_color ""
+seta hud_panel_centerprint_bg_color_team ""
+seta hud_panel_centerprint_bg_alpha ""
+seta hud_panel_centerprint_bg_border ""
+seta hud_panel_centerprint_bg_padding ""
+seta hud_panel_centerprint_fontscale "1"
+seta hud_panel_centerprint_time "2"
+
 seta hud_panel_notify 1
 seta hud_panel_notify_pos "0.710000 0.800000"
 seta hud_panel_notify_size "0.290000 0.190000"
index 029b9460f6f7f7209727efc0019b039fbd9ff77d..1c60a02f9fe7c610ff3a2dfdadf168846087a15b 100644 (file)
@@ -1421,7 +1421,6 @@ void CSQC_SPIDER_HUD()
        if (scoreboard_showscores)
        {
                HUD_DrawScoreboard();
-               HUD_DrawCenterPrint();
        }
 
 }
@@ -1488,7 +1487,6 @@ void CSQC_RAPTOR_HUD()
        if (scoreboard_showscores)
        {
                HUD_DrawScoreboard();
-               HUD_DrawCenterPrint();
        }
 
 }
@@ -1598,7 +1596,6 @@ const float STAT_VEHICLESTAT_RELOAD2 = 66;
        if (scoreboard_showscores)
        {
                HUD_DrawScoreboard();
-               HUD_DrawCenterPrint();
        }
 
 }
@@ -1637,25 +1634,12 @@ void CSQC_common_hud(void)
                        HUD_DrawScoreboard();
 
                        if (scoreboard_active) // scoreboard/accuracy
-                       {       
                                HUD_Reset();
-                               // HUD_DrawScoreboard takes care of centerprint_start
-                       }
                        else if (intermission == 2) // map voting screen
                        {
                                HUD_FinaleOverlay();
                                HUD_Reset();
-
-                               centerprint_start_x = 0;
-                               centerprint_start_y = autocvar_scr_centerpos * vid_conheight;
                        }
-                       else // hud
-                       {
-                               centerprint_start_x = 0;
-                               centerprint_start_y = autocvar_scr_centerpos * vid_conheight;
-                       }
-
-                       HUD_DrawCenterPrint();
                        break;
 
                case HUD_SPIDERBOT:
index b2a1602686530db5db228200b390fb5fc1379fff..bb7d4e6ed1958adda910ad69d339a8417ce6e1a0 100644 (file)
@@ -205,6 +205,9 @@ float autocvar_hud_panel_healtharmor_progressbar_gfx_damage;
 float autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth;
 float autocvar_hud_panel_healtharmor_progressbar_gfx_smooth;
 
+float autocvar_hud_panel_centerprint;
+float autocvar_hud_panel_centerprint_fontscale;
+float autocvar_hud_panel_centerprint_time;
 float autocvar_hud_panel_healtharmor_text;
 float autocvar_hud_panel_infomessages;
 float autocvar_hud_panel_infomessages_flip;
@@ -319,9 +322,6 @@ var float autocvar_scoreboard_highlight_alpha = 0.10;
 var float autocvar_scoreboard_highlight_alpha_self = 0.25;
 float autocvar_scoreboard_offset_left;
 float autocvar_scoreboard_offset_right;
-float autocvar_scr_centerpos;
-float autocvar_scr_centersize;
-float autocvar_scr_centertime;
 float autocvar_v_flipped;
 float autocvar_vid_conheight;
 float autocvar_vid_conwidth;
index 47ee55818f6f198a40f14842cd4620ac18ec5d1c..0711fb677974eec73f48ed96841c73a2170386b5 100644 (file)
@@ -142,230 +142,6 @@ float stringwidth_nocolors(string s, vector theSize)
        return stringwidth(s, FALSE, theSize);
 }
 
-#define CENTERPRINT_MAX_MSGS 10
-float cpm_index;
-string centerprint_messages[CENTERPRINT_MAX_MSGS];
-float centerprint_msgID[CENTERPRINT_MAX_MSGS];
-float centerprint_width[CENTERPRINT_MAX_MSGS];
-float centerprint_time[CENTERPRINT_MAX_MSGS];
-float centerprint_expire;
-float centerprint_num;
-vector centerprint_fontsize;
-
-string strip_CPID(string s)
-{
-       return substring(s, strstrofs(s, " ", 0) + 1, strlen(s));
-}
-float get_CPID(string s)
-{
-       if(substring(s, 0, 1) != "\r")
-               return 0;
-       return stof(substring(s, 1, strstrofs(s, " ", 0)));
-}
-void centerprint(string strMessage)
-{
-       float i, j, n, hcount;
-       string s;
-
-       centerprint_fontsize = HUD_GetFontsize("scr_centersize");
-
-       centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
-
-       if(autocvar_scr_centertime <= 0)
-               return;
-
-       if(strMessage == "")
-               return;
-
-       float new_id = get_CPID(strMessage);
-
-       for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
-       {
-               if (j == CENTERPRINT_MAX_MSGS)
-                       j = 0;
-               if (new_id && new_id == centerprint_msgID[j])
-               {
-                       if(centerprint_messages[j])
-                               strunzone(centerprint_messages[j]);
-                       centerprint_messages[j] == strzone(strip_CPID(strMessage));
-                       centerprint_time[j] = time;
-                       return;
-               }
-               if(centerprint_messages[j] == strMessage)
-               {
-                       centerprint_time[j] = time;
-                       centerprint_msgID[j] = new_id;
-                       return;
-               }
-       }
-
-       --cpm_index;
-       if (cpm_index == -1)
-               cpm_index = CENTERPRINT_MAX_MSGS - 1;
-       if(centerprint_messages[cpm_index])
-               strunzone(centerprint_messages[cpm_index]);
-       if (new_id)
-               centerprint_messages[cpm_index] = strzone(strip_CPID(strMessage));
-       else
-               centerprint_messages[cpm_index] = strzone(strMessage);
-       centerprint_msgID[cpm_index] = new_id;
-       centerprint_time[cpm_index] = time;
-
-
-#if 0
-       i = hcount = 0;
-       for(j = 0; j < n; ++j)
-       {
-               getWrappedLine_remaining = argv(j);
-               while(getWrappedLine_remaining)
-               {
-                       s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
-                       if(centerprint_messages[i] != s) // don't fade the same message in, looks stupid
-                               centerprint_time = time;
-                       if(centerprint_messages[i])
-                               strunzone(centerprint_messages[i]);
-                       centerprint_messages[i] = strzone(s);
-                       centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
-                       ++i;
-
-                       // half height for empty lines looks better
-                       if(s == "")
-                               hcount += 0.5;
-                       else
-                               hcount += 1;
-
-                       if(i >= CENTERPRINT_MAX_MSGS)
-                               break;
-               }
-       }
-#endif
-
-#if 0
-       float h, havail;
-       h = centerprint_fontsize_y*hcount;
-
-       havail = vid_conheight;
-       if(autocvar_con_chatpos < 0)
-               havail -= (-autocvar_con_chatpos + autocvar_con_chat) * autocvar_con_chatsize; // avoid overlapping chat
-       if(havail > vid_conheight - 70)
-               havail = vid_conheight - 70; // avoid overlapping HUD
-
-       float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
-
-       // here, the centerprint would cover the crosshair. REALLY BAD.
-       forbiddenmin = vid_conheight * 0.5 - h - 16;
-       forbiddenmax = vid_conheight * 0.5 + 16;
-
-       allowedmin = scoreboard_bottom;
-       allowedmax = havail - h;
-       preferred = (havail - h)/2;
-
-
-       // possible orderings (total: 4! / 4 = 6)
-       //  allowedmin allowedmax forbiddenmin forbiddenmax
-       //  forbiddenmin forbiddenmax allowedmin allowedmax
-       if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
-       {
-               // forbidden doesn't matter in this case
-               centerprint_start_y = bound(allowedmin, preferred, allowedmax);
-       }
-       //  allowedmin forbiddenmin allowedmax forbiddenmax
-       else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
-       {
-               centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
-       }
-       //  allowedmin forbiddenmin forbiddenmax allowedmax
-       else if(allowedmin < forbiddenmin)
-       {
-               // make sure the forbidden zone is not covered
-               if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
-                       centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
-               else
-                       centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
-       }
-       //  forbiddenmin allowedmin allowedmax forbiddenmax
-       else if(allowedmax < forbiddenmax)
-       {
-               // it's better to leave the allowed zone (overlap with scoreboard) than
-               // to cover the forbidden zone (crosshair)
-               if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
-                       centerprint_start_y = forbiddenmax;
-               else
-                       centerprint_start_y = forbiddenmin;
-       }
-       //  forbiddenmin allowedmin forbiddenmax allowedmax
-       else
-       {
-               centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
-       }
-#else
-#endif
-
-       // centerprint_num = i;
-
-       centerprint_expire = time + autocvar_scr_centertime;
-}
-
-void HUD_DrawCenterPrint (void)
-{
-       float i, j, k, n;
-       vector pos;
-       string ts;
-       float a, sz, fade;
-
-       // if(centerprint_num * autocvar_scr_centersize > 24 && scoreboard_active) // 24 = height of Scoreboard text
-               // centerprint_start_y = scoreboard_bottom + centerprint_fontsize_y;
-
-       pos = centerprint_start;
-       fade = min(autocvar_scr_centertime/8, 0.25);
-       for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
-       {
-               if (j == CENTERPRINT_MAX_MSGS)
-                       j = 0;
-               if (centerprint_time[j] + autocvar_scr_centertime < time)
-                       continue;
-               else if (centerprint_time[j] + autocvar_scr_centertime - fade > time)
-               {
-                       a = 1;
-                       sz = 1;
-               }
-               else if (centerprint_time[j] + autocvar_scr_centertime > time)
-               {
-                       a = (centerprint_time[j] + autocvar_scr_centertime - time) / fade;
-                       sz = 0.8 + a * (1 - 0.8);
-               }
-
-               drawfontscale = sz * '1 1 0';
-               n = tokenizebyseparator(centerprint_messages[j], "\n");
-               for(k = 0; k < n; ++k)
-               {
-                       getWrappedLine_remaining = argv(k);
-                       while(getWrappedLine_remaining)
-                       {
-                               ts = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
-                               if (cvar("debug"))
-                               {
-                                       ts = strcat(ftos(i), " -", ts, "-");
-                                       print(sprintf("^x8f0ts = %s\n", ts));
-                               }
-                               pos_x = (vid_conwidth - stringwidth(ts, TRUE, centerprint_fontsize)) * 0.5;
-                               if (ts != "")
-                               {
-                                       drawcolorcodedstring(pos + '0 1 0' * (1 - sz) * 0.5 *centerprint_fontsize_y, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
-                                       pos_y = pos_y + centerprint_fontsize_y;
-                               }
-                               else
-                                       // half height for empty lines looks better
-                                       pos_y = pos_y + sz * centerprint_fontsize_y * 0.5;
-                       }
-               }
-               pos_y += centerprint_fontsize_y * 0.5;
-               if (a < 1)
-                       pos_y -= 1.5 * centerprint_fontsize_y * (1 - a*a);
-               drawfontscale = '1 1 0';
-       }
-}
-
 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
 {
        position_x -= 2 / 3 * strlen(text) * scale_x;
@@ -4543,6 +4319,150 @@ void HUD_Physics(void)
                drawstring_aspect(panel_pos + acceleration_offset, strcat(ftos_decimals(acceleration, 2), "g"), panel_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
 }
 
+#define CENTERPRINT_MAX_MSGS 10
+#define CENTERPRINT_MAX_ENTRIES 50
+float cpm_index;
+string centerprint_messages[CENTERPRINT_MAX_MSGS];
+float centerprint_msgID[CENTERPRINT_MAX_MSGS];
+float centerprint_time[CENTERPRINT_MAX_MSGS];
+
+string strip_CPID(string s)
+{
+       return substring(s, strstrofs(s, " ", 0) + 1, strlen(s));
+}
+float get_CPID(string s)
+{
+       if(substring(s, 0, 1) != "\r")
+               return 0;
+       return stof(substring(s, 1, strstrofs(s, " ", 0)));
+}
+void centerprint(string strMessage)
+{
+       float i, j;
+
+       if(autocvar_hud_panel_centerprint_time <= 0)
+               return;
+
+       if(strMessage == "")
+               return;
+
+       float new_id = get_CPID(strMessage);
+
+       for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
+       {
+               if (j == CENTERPRINT_MAX_MSGS)
+                       j = 0;
+               if (new_id && new_id == centerprint_msgID[j])
+               {
+                       if(centerprint_messages[j])
+                               strunzone(centerprint_messages[j]);
+                       centerprint_messages[j] == strzone(strip_CPID(strMessage));
+                       centerprint_time[j] = time;
+                       return;
+               }
+               if(centerprint_messages[j] == strMessage)
+               {
+                       centerprint_time[j] = time;
+                       centerprint_msgID[j] = new_id;
+                       return;
+               }
+       }
+
+       --cpm_index;
+       if (cpm_index == -1)
+               cpm_index = CENTERPRINT_MAX_MSGS - 1;
+       if(centerprint_messages[cpm_index])
+               strunzone(centerprint_messages[cpm_index]);
+       if (new_id)
+               centerprint_messages[cpm_index] = strzone(strip_CPID(strMessage));
+       else
+               centerprint_messages[cpm_index] = strzone(strMessage);
+       centerprint_msgID[cpm_index] = new_id;
+       centerprint_time[cpm_index] = time;
+}
+
+// CenterPrint (#16)
+//
+void HUD_CenterPrint (void)
+{
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_centerprint) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_CENTERPRINT;
+
+       HUD_Panel_UpdateCvars(centerprint);
+
+       HUD_Panel_DrawBg(1);
+       if(panel_bg_padding)
+       {
+               panel_pos += '1 1 0' * panel_bg_padding;
+               panel_size -= '2 2 0' * panel_bg_padding;
+       }
+
+       float entries, 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/40 * autocvar_hud_panel_centerprint_fontscale;
+       fontsize = '1 1 0' * height;
+       entries = bound(1, floor(panel_size_y/height), CENTERPRINT_MAX_ENTRIES);
+
+       float i, j, k, n;
+       vector pos;
+       string ts;
+       float a, sz, fade;
+
+       pos = panel_pos;
+       fade = min(autocvar_hud_panel_centerprint_time/8, 0.25);
+       for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
+       {
+               if (j == CENTERPRINT_MAX_MSGS)
+                       j = 0;
+               if (centerprint_time[j] + autocvar_hud_panel_centerprint_time < time)
+                       continue;
+               else if (centerprint_time[j] + autocvar_hud_panel_centerprint_time - fade > time)
+               {
+                       a = 1;
+                       sz = 1;
+               }
+               else if (centerprint_time[j] + autocvar_hud_panel_centerprint_time > time)
+               {
+                       a = (centerprint_time[j] + autocvar_hud_panel_centerprint_time - time) / fade;
+                       sz = 0.8 + a * (1 - 0.8);
+               }
+
+               drawfontscale = sz * '1 1 0';
+               n = tokenizebyseparator(centerprint_messages[j], "\n");
+               for(k = 0; k < n; ++k)
+               {
+                       getWrappedLine_remaining = argv(k);
+                       while(getWrappedLine_remaining)
+                       {
+                               ts = getWrappedLine(panel_size_x, fontsize, stringwidth_colors);
+                               pos_x = panel_pos_x + (panel_size_x - stringwidth(ts, TRUE, fontsize)) * 0.5;
+                               if (ts != "")
+                               {
+                                       drawcolorcodedstring(pos + '0 1 0' * 1.5 * (1 - sz) * fontsize_y, ts, fontsize, a, DRAWFLAG_NORMAL);
+                                       pos_y += fontsize_y * 1.5;
+                               }
+                               else
+                                       pos_y += fontsize_y;
+                               if (pos_y > panel_pos_y + panel_size_y - fontsize_y)
+                               {
+                                       drawfontscale = '1 1 0';
+                                       return;
+                               }
+                       }
+               }
+               if (a < 1)
+                       pos_y -= 1.5 * fontsize_y * (1 - a*a);
+               drawfontscale = '1 1 0';
+       }
+}
+
 /*
 ==================
 Main HUD system
@@ -4592,6 +4512,8 @@ switch (id) {\
                 HUD_InfoMessages(); break;\
        case (HUD_PANEL_PHYSICS):\
                 HUD_Physics(); break;\
+       case (HUD_PANEL_CENTERPRINT):\
+                HUD_CenterPrint(); break;\
 } ENDS_WITH_CURLY_BRACE
 
 void HUD_Main (void)
index d2fbfebef2603ca71bc6ee2fc470cfbc47076f44..dc285652b91801a4a45bd29538a4648cc84b112b 100644 (file)
@@ -283,6 +283,7 @@ if(menu_enabled == 2 && hud_configure_active_panel == highlightedPanel) {\
 switch(id) { \
        case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdateCvars(infomessages) break; \
        case HUD_PANEL_PHYSICS: HUD_Panel_UpdateCvars(physics); break;\
+       case HUD_PANEL_CENTERPRINT: HUD_Panel_UpdateCvars(centerprint); break;\
 }
 
 #define HUD_Panel_UpdateCvarsForId(id) \
@@ -320,6 +321,7 @@ HUD_Panel_GetBorder()
 switch(id) { \
        case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdatePosSize(infomessages) break;\
        case HUD_PANEL_PHYSICS: HUD_Panel_UpdatePosSize(physics); break;\
+       case HUD_PANEL_CENTERPRINT: HUD_Panel_UpdatePosSize(centerprint); break;\
 }
 
 #define HUD_Panel_UpdatePosSizeForId(id) \
index 0923e4ed97e1603fc14251ce566c70489d20f817..97a0cb6cc787773f1932f7818cc9b4682b2a0eb6 100644 (file)
@@ -45,9 +45,6 @@ void HUD_Panel_ExportCfg(string cfgname)
                HUD_Write_Cvar_q("hud_configure_grid_ysize");
                HUD_Write("\n");
 
-               HUD_Write_Cvar_q("scr_centerpos");
-               HUD_Write("\n");
-
                // common cvars for all panels
                float i;
                for (i = 0; i < HUD_PANEL_NUM; ++i)
@@ -124,6 +121,10 @@ void HUD_Panel_ExportCfg(string cfgname)
                                        HUD_Write_PanelCvar_q("_progressbar");
                                        HUD_Write_PanelCvar_q("_acceleration_mode");
                                        break;
+                               case HUD_PANEL_CENTERPRINT:
+                                       HUD_Write_PanelCvar_q("_fontscale");
+                                       HUD_Write_PanelCvar_q("_time");
+                                       break;
                        }
                        HUD_Write("\n");
                }
index 94602b69478528471037d317dd966289b3278d6d..04a1588e3a88b5972f2823f34e40dfd80d179f81 100644 (file)
@@ -664,7 +664,8 @@ float HUD_PANEL_CHAT                = 12;
 float HUD_PANEL_ENGINEINFO     = 13;
 float HUD_PANEL_INFOMESSAGES   = 14;
 float HUD_PANEL_PHYSICS        = 15;
-float HUD_PANEL_NUM            = 16; // always last panel id + 1, please increment when adding a new panel
+float HUD_PANEL_CENTERPRINT    = 16;
+float HUD_PANEL_NUM            = 17; // always last panel id + 1, please increment when adding a new panel
 
 string HUD_PANELNAME_WEAPONS           = "weapons";
 string HUD_PANELNAME_AMMO              = "ammo";
@@ -682,6 +683,7 @@ string HUD_PANELNAME_CHAT           = "chat";
 string HUD_PANELNAME_ENGINEINFO                = "engineinfo";
 string HUD_PANELNAME_INFOMESSAGES      = "infomessages";
 string HUD_PANELNAME_PHYSICS   = "physics";
+string HUD_PANELNAME_CENTERPRINT       = "centerprint";
 
 float HUD_MENU_ENABLE          = 0;
 
index 49afad22d7f19bc62f552b8dcdbf3884f7e8654d..40ef2875a00fa9bb586d71c760ec55762a656d49 100644 (file)
@@ -222,6 +222,7 @@ switch(id) {\
        case HUD_PANEL_ENGINEINFO: panel_name = HUD_PANELNAME_ENGINEINFO; break; \
        case HUD_PANEL_INFOMESSAGES: panel_name = HUD_PANELNAME_INFOMESSAGES; break; \
        case HUD_PANEL_PHYSICS: panel_name = HUD_PANELNAME_PHYSICS; break; \
+       case HUD_PANEL_CENTERPRINT: panel_name = HUD_PANELNAME_CENTERPRINT; break; \
 } ENDS_WITH_CURLY_BRACE
 
 // Get name of specified panel id