From 90402faa533fdf24aa21c02692eb053baaeb2285 Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Sun, 24 Feb 2013 01:37:55 -0500 Subject: [PATCH] Implement a proper way for notification system to use countdowns (FINALLY) --- qcsrc/client/hud.qc | 2 +- qcsrc/common/notifications.qc | 40 ++++++++++++++++++++++++++++++++--- qcsrc/common/notifications.qh | 19 ++++++++++------- qcsrc/common/util.qc | 23 ++++++++------------ qcsrc/common/util.qh | 8 +++---- 5 files changed, 62 insertions(+), 30 deletions(-) diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 6effbe7eb..015a83ca1 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -4661,7 +4661,7 @@ void HUD_CenterPrint (void) drawfontscale = sz * '1 1 0'; if (centerprint_countdown_num[j]) - n = tokenizebyseparator(sprintf(centerprint_messages[j], centerprint_countdown_num[j]), "\n"); + n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n"); else n = tokenizebyseparator(centerprint_messages[j], "\n"); diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index f9ac2ad56..c516bfc68 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -199,6 +199,39 @@ void Local_Notification_HUD_Notify_Push(string icon, string hudargs, string s1, } HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]); } + +void Local_Notification_centerprint_generic(string input, string durcnt, float cpid, float f1, float f2) +{ + string olddurcnt = durcnt; + string selected; + float sel_num; + arg_slot[0] = ""; arg_slot[1] = ""; + + for(sel_num = 0;(durcnt != "");) + { + selected = car(durcnt); durcnt = cdr(durcnt); + NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_centerprint_generic") + switch(strtolower(selected)) + { + case "f1": { arg_slot[sel_num] = ftos(f1); ++sel_num; break; } + case "0": { arg_slot[sel_num] = "0"; ++sel_num; break; } + case "1": { arg_slot[sel_num] = "1"; ++sel_num; break; } + NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_centerprint_generic") + } + } + + #ifdef NOTIFICATIONS_DEBUG + dprint( + sprintf("Local_Notification_centerprint_generic(%d, '%s^7', '%s', '%s', '%s');\n", + cpid, + strreplace("\n", "\\n", input), + olddurcnt, + arg_slot[0], arg_slot[1] + ) + ); + #endif + centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1])); +} #endif void Local_Notification(float net_type, float net_name, ...count) @@ -292,14 +325,15 @@ void Local_Notification(float net_type, float net_name, ...count) #ifdef CSQC case MSG_CENTER: { - centerprint_generic( - notif.nent_cpid, + Local_Notification_centerprint_generic( Local_Notification_sprintf( notif.nent_string, notif.nent_args, s1, s2, s3, s4, f1, f2, f3, f4), - 0, 0); + notif.nent_durcnt, + notif.nent_cpid, + f1, f2); break; } #endif diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index a8dbe6597..7de7f279e 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -375,7 +375,7 @@ void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, MSG_CENTER_NOTIF(1, CENTER_DEATH_MURDER_TYPEFRAGGED_VERBOSE, 1, 4, "spree_cen s1 frag_stats", NO_CPID, "0 0", _("^K1%sYou were typefragged by ^BG%s^BG%s"), _("^K1%sYou were scored against by ^BG%s^K1 while typing^BG%s")) \ MSG_CENTER_NOTIF(1, CENTER_DEATH_TEAMKILL_FRAG, 1, 0, "s1", NO_CPID, "0 0", _("^K1Moron! You fragged ^BG%s^K1, a team mate!"), _("^K1Moron! You went against ^BG%s^K1, a team mate!")) \ MSG_CENTER_NOTIF(1, CENTER_DEATH_TEAMKILL_FRAGGED, 1, 0, "s1", NO_CPID, "0 0", _("^K1You were fragged by ^BG%s^K1, a team mate"), _("^K1You were scored against by ^BG%s^K1, a team mate")) \ - MSG_CENTER_NOTIF(1, CENTER_DISCONNECT_IDLING, 0, 1, "f1secs", CPID_IDLING, "1 f1", _("^K1Stop idling!\n^BGDisconnecting in %s..."), "") \ + MSG_CENTER_NOTIF(1, CENTER_DISCONNECT_IDLING, 0, 1, "", CPID_IDLING, "1 f1", _("^K1Stop idling!\n^BGDisconnecting in ^COUNT..."), "") \ MULTITEAM_CENTER(1, CENTER_FREEZETAG_ROUND_WIN_, 4, 0, 0, "", NO_CPID, "0 0", _("^TC^TT^BG team wins the round, all other teams were frozen"), "") \ MSG_CENTER_NOTIF(1, CENTER_FREEZETAG_SPAWN_LATE, 0, 0, "", NO_CPID, "0 0", _("^K1You spawned after the round started, you'll spawn as frozen"), "") \ MSG_CENTER_NOTIF(1, CENTER_FREEZETAG_REVIVE, 1, 0, "s1", NO_CPID, "0 0", _("^K3You revived ^BG%s"), "") \ @@ -403,10 +403,10 @@ void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, MSG_CENTER_NOTIF(1, CENTER_SUPERWEAPON_BROKEN, 0, 0, "", CPID_POWERUP, "0 0", _("^F2Superweapons have broken down"), "") \ MSG_CENTER_NOTIF(1, CENTER_SUPERWEAPON_PICKUP, 0, 0, "", CPID_POWERUP, "0 0", _("^F2You now have a superweapon"), "") \ MSG_CENTER_NOTIF(1, CENTER_SUPERWEAPON_LOST, 0, 0, "", CPID_POWERUP, "0 0", _("^F2Superweapons have been lost"), "") \ - MULTITEAM_CENTER(1, CENTER_TEAMCHANGE_, 4, 0, 1, "f1secs", CPID_TEAMCHANGE, "1 f1", _("^BGChanging to ^TC^TT^BG in %s"), "") \ - MSG_CENTER_NOTIF(1, CENTER_TEAMCHANGE_SPECTATE, 0, 1, "f1secs", CPID_TEAMCHANGE, "1 f1", _("^BGSpectating in %s"), "") \ - MSG_CENTER_NOTIF(1, CENTER_TEAMCHANGE_AUTO, 0, 1, "f1secs", CPID_TEAMCHANGE, "1 f1", _("^BGChanging team in %s"), "") \ - MSG_CENTER_NOTIF(1, CENTER_TEAMCHANGE_SUICIDE, 0, 1, "f1secs", CPID_TEAMCHANGE, "1 f1", _("^K1Suicide in %s"), "") + MULTITEAM_CENTER(1, CENTER_TEAMCHANGE_, 4, 0, 1, "", CPID_TEAMCHANGE, "1 f1", _("^BGChanging to ^TC^TT^BG in ^COUNT"), "") \ + MSG_CENTER_NOTIF(1, CENTER_TEAMCHANGE_SPECTATE, 0, 1, "", CPID_TEAMCHANGE, "1 f1", _("^BGSpectating in ^COUNT"), "") \ + MSG_CENTER_NOTIF(1, CENTER_TEAMCHANGE_AUTO, 0, 1, "", CPID_TEAMCHANGE, "1 f1", _("^BGChanging team in ^COUNT"), "") \ + MSG_CENTER_NOTIF(1, CENTER_TEAMCHANGE_SUICIDE, 0, 1, "", CPID_TEAMCHANGE, "1 f1", _("^K1Suicide in ^COUNT"), "") #define MSG_WEAPON_NOTIFICATIONS \ /*MSG_WEAPON_NOTIF(1, WEAPON_EMPTY, NO_MSG, NO_MSG)*/ \ @@ -763,6 +763,7 @@ string notif_arg_spree_inf(float type, string input, string player, float spree) ARG_CASE(ARG_DOUBLE, "f4", ftos(f4)) \ ARG_CASE(ARG_DOUBLE, "f1p2dec", ftos_decimals(f1/100, 2)) \ ARG_CASE(ARG_DOUBLE, "f2p2dec", ftos_decimals(f2/100, 2)) \ + ARG_CASE(ARG_CSQC, "f1secs", count_seconds(f1)) \ ARG_CASE(ARG_CSQC, "pass_key", ((((tmp_s = getcommandkey("pass", "+use")) != "pass") && !(strstrofs(tmp_s, "not bound", 0) >= 0)) ? sprintf(CCR(_(" ^F1(Press %s)")), tmp_s) : "")) \ ARG_CASE(ARG_CSQC, "frag_ping", ((f2 != NO_MSG) ? sprintf(CCR(_("\n(Ping ^2%d^BG)")), f2) : "")) \ ARG_CASE(ARG_CSQC, "frag_stats", sprintf(CCR(_("\n(Health ^1%d^BG / Armor ^2%d^BG)%s")), f2, f3, ((f4 != NO_MSG) ? sprintf(CCR(_(" (Ping ^2%d^BG)")), f4) : ""))) \ @@ -932,6 +933,8 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin if(args != "") { notif.nent_args = strzone(Process_Notif_Args(FALSE, args, strtoupper(#type), #name)); } \ if(hudargs != "") { notif.nent_hudargs = strzone(Process_Notif_Args(TRUE, hudargs, strtoupper(#type), #name)); } \ if(icon != "") { notif.nent_icon = strzone(icon); } \ + if(cpid != NO_MSG) { notif.nent_cpid = cpid; } \ + if(durcnt != "") { notif.nent_durcnt = strzone(durcnt); } \ if(GENTLE) \ { \ if(gentle != "") { notif.nent_string = strzone(CCR(Process_Notif_Line(check_newline, nent_chat, gentle, strtoupper(#type), #name, "GENTLE"))); } \ @@ -965,7 +968,7 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin hudargs, /* hudargs */ \ icon, /* icon */ \ NO_MSG, /* cpid */ \ - NO_MSG, /* durcnt */ \ + "", /* durcnt */ \ normal, /* normal */ \ gentle, /* gentle */ \ 1, /* check_newline */ \ @@ -1021,7 +1024,7 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin "", /* hudargs */ \ "", /* icon */ \ NO_MSG, /* cpid */ \ - NO_MSG, /* durcnt */ \ + "", /* durcnt */ \ "", /* normal */ \ "", /* gentle */ \ 0, /* check_newline */ \ @@ -1048,7 +1051,7 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin "", /* hudargs */ \ "", /* icon */ \ NO_MSG, /* cpid */ \ - NO_MSG, /* durcnt */ \ + "", /* durcnt */ \ "", /* normal */ \ "", /* gentle */ \ 0, /* check_newline */ \ diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index b21915da3..c33466633 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -2606,28 +2606,28 @@ vector animfixfps(entity e, vector a, vector b) } #endif -string count_append(float time, string zeroth, string first, string second, string third, string multi) +string count_append(float interval, string zeroth, string first, string second, string third, string multi) { // This function is designed primarily for the English language, it's impossible // to accomodate all languages unless we do a specific function for each one... // and since that's not technically feasible/practical, this is all we've got folks. - string timestring = sprintf("%d", time); + string timestring = sprintf("%d", interval); float lastnum = stof(substring(timestring, (strlen(timestring) - 1), 1)); switch(lastnum) { - case 0: return sprintf(zeroth, time); + case 0: return sprintf(zeroth, interval); case 1: { - if(time == 1) // EXACTLY value of 1 - return sprintf(first, time); + if(interval == 1) // EXACTLY value of 1 + return sprintf(first, interval); else - return sprintf(multi, time); + return sprintf(multi, interval); } - case 2: return sprintf(second, time); - case 3: return sprintf(third, time); - default: return sprintf(multi, time); + case 2: return sprintf(second, interval); + case 3: return sprintf(third, interval); + default: return sprintf(multi, interval); } return ""; } @@ -2671,8 +2671,3 @@ string process_time(float seconds, float output) } return ""; } - - - - - diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 497183ad9..6511ef3b3 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -430,10 +430,10 @@ vector animfixfps(entity e, vector a, vector b); _("%.##decs##f seconds")) /* multi */ \ #define count_seconds(time) count_append(time, \ - _("0 seconds"), /* zeroth */ \ - _("1 second"), /* first */ \ - _("2 seconds"), /* second */ \ - _("3 seconds"), /* third */ \ + _("%d seconds"), /* zeroth */ \ + _("%d second"), /* first */ \ + _("%d seconds"), /* second */ \ + _("%d seconds"), /* third */ \ _("%d seconds")) /* multi */ \ #define count_ordinal(time) count_append(time, \ -- 2.39.2