]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Implement a proper way for notification system to use countdowns (FINALLY)
authorSamual Lenks <samual@xonotic.org>
Sun, 24 Feb 2013 06:37:55 +0000 (01:37 -0500)
committerSamual Lenks <samual@xonotic.org>
Sun, 24 Feb 2013 06:37:55 +0000 (01:37 -0500)
qcsrc/client/hud.qc
qcsrc/common/notifications.qc
qcsrc/common/notifications.qh
qcsrc/common/util.qc
qcsrc/common/util.qh

index 6effbe7ebf3a3eb3d48c242a2b66581721cd4b43..015a83ca137a54d5bb1848bad407ac2da078881b 100644 (file)
@@ -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");
 
index f9ac2ad5614eaaaa3fb87ba36abd0c1c52b6c6ae..c516bfc685e0c248c7db5e9b388077e7808ad657 100644 (file)
@@ -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
index a8dbe6597ce3689a1cc2b1e2d9117d6960f3cba3..7de7f279e80d2c25567fd30a966d2a803eff3dee 100644 (file)
@@ -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 */ \
index b21915da3b33a089c5b23ca9874cd988ef0ee974..c3346663328abe19a33d2fe3f9e45a5482a56604 100644 (file)
@@ -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 "";
 }
-
-
-
-
-
index 497183ad9251007460e232737a0cc1f0c0d1d0ac..6511ef3b30e1e1f88787f9a43b7209470821ce24 100644 (file)
@@ -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, \