From 6a966ce59127e888e11aa8dded8809e2e0b78f71 Mon Sep 17 00:00:00 2001 From: terencehill Date: Mon, 23 May 2011 18:41:16 +0200 Subject: [PATCH] New panel for centerprint messages --- hud_luminos.cfg | 14 +- qcsrc/client/View.qc | 16 -- qcsrc/client/autocvars.qh | 6 +- qcsrc/client/hud.qc | 370 +++++++++++++++---------------------- qcsrc/client/hud.qh | 2 + qcsrc/client/hud_config.qc | 7 +- qcsrc/common/constants.qh | 4 +- qcsrc/common/util.qh | 1 + 8 files changed, 172 insertions(+), 248 deletions(-) diff --git a/hud_luminos.cfg b/hud_luminos.cfg index 4c11d4207..13b241d4f 100644 --- a/hud_luminos.cfg +++ b/hud_luminos.cfg @@ -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" diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index 029b9460f..1c60a02f9 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -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: diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index b2a160268..bb7d4e6ed 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -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; diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 47ee55818..0711fb677 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -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) - 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 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 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) diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index d2fbfebef..dc285652b 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -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) \ diff --git a/qcsrc/client/hud_config.qc b/qcsrc/client/hud_config.qc index 0923e4ed9..97a0cb6cc 100644 --- a/qcsrc/client/hud_config.qc +++ b/qcsrc/client/hud_config.qc @@ -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"); } diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 94602b694..04a1588e3 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -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; diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 49afad22d..40ef2875a 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -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 -- 2.39.2