-#define CENTERPRINT_MAX_LINES 10
-float cpm_index;
-string centerprint_messages[CENTERPRINT_MAX_LINES];
-float centerprint_width[CENTERPRINT_MAX_LINES];
-float centerprint_time[CENTERPRINT_MAX_LINES];
-float centerprint_expire;
-float centerprint_num;
-float centerprint_offset_hint;
-vector centerprint_fontsize;
-
-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;
-
- // strip trailing newlines
- j = strlen(strMessage) - 1;
- while(substring(strMessage, j, 1) == "\n" && j >= 0)
- j = j - 1;
- strMessage = substring(strMessage, 0, j + 1);
-
- if(strMessage == "")
- return;
-
- // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
- j = 0;
- while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
- j = j + 1;
- strMessage = substring(strMessage, j, strlen(strMessage) - j);
- centerprint_offset_hint = j;
-
- if(strMessage == "")
- return;
-
- for (i=0, j=cpm_index; i<CENTERPRINT_MAX_LINES; ++i, ++j)
- {
- if (j == CENTERPRINT_MAX_LINES)
- j = 0;
- if(centerprint_messages[j] == strMessage)
- {
- centerprint_time[j] = time;
- return;
- }
- }
-
- --cpm_index;
- if (cpm_index == -1)
- cpm_index = CENTERPRINT_MAX_LINES - 1;
- if(centerprint_messages[cpm_index])
- strunzone(centerprint_messages[cpm_index]);
- centerprint_messages[cpm_index] = strzone(strMessage);
- 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_LINES)
- 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_LINES; ++i, ++j)
- {
- if (j == CENTERPRINT_MAX_LINES)
- 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;
- drawfontscale = '1 1 0';
- }
-}
-