]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Create a way to restart notifications
authorSamual Lenks <samual@xonotic.org>
Fri, 1 Mar 2013 04:51:03 +0000 (23:51 -0500)
committerSamual Lenks <samual@xonotic.org>
Fri, 1 Mar 2013 04:51:03 +0000 (23:51 -0500)
qcsrc/common/command/generic.qc
qcsrc/common/notifications.qc
qcsrc/common/notifications.qh

index 4d3df8e87d66b419eac4325858c45041bcccfa39..e85e3b111a8e06a5148769964e37973f234aaa2a 100644 (file)
@@ -426,6 +426,47 @@ void GenericCommand_removefromlist(float request, float argc)
        }
 }
 
+void GenericCommand_restartnotifs(float request)
+{
+       switch(request)
+       {
+               case CMD_REQUEST_COMMAND:
+               {
+                       #ifndef MENUQC
+                       print(sprintf(
+                               strcat(
+                                       "Restart_Notifications(): Restarting %d notifications... ",
+                                       "Counts: MSG_INFO = %d, MSG_CENTER = %d, MSG_WEAPON = %d, MSG_DEATH = %d\n"
+                               ),
+                               (
+                                       NOTIF_INFO_COUNT +
+                                       NOTIF_CENTER_COUNT +
+                                       NOTIF_WEAPON_COUNT +
+                                       NOTIF_DEATH_COUNT
+                               ), 
+                               NOTIF_INFO_COUNT,
+                               NOTIF_CENTER_COUNT,
+                               NOTIF_WEAPON_COUNT,
+                               NOTIF_DEATH_COUNT
+                       ));
+                       Destroy_All_Notifications();
+                       CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
+                       #else
+                       print(_("Notification restart command only works with cl_cmd and sv_cmd.\n"));
+                       #endif
+                       return;
+               }
+                       
+               default:
+               case CMD_REQUEST_USAGE:
+               {
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " restartnotifs"));
+                       print("  No arguments required.\n");
+                       return;
+               }
+       }
+}
+
 void GenericCommand_settemp(float request, float argc)
 {
        switch(request)
@@ -520,6 +561,7 @@ void GenericCommand_(float request)
        GENERIC_COMMAND("nextframe", GenericCommand_nextframe(request, arguments, command), "Execute the given command next frame of this VM") \
        GENERIC_COMMAND("qc_curl", GenericCommand_qc_curl(request, arguments), "Queries a URL") \
        GENERIC_COMMAND("removefromlist", GenericCommand_removefromlist(request, arguments), "Remove a string from a cvar") \
+       GENERIC_COMMAND("restartnotifs", GenericCommand_restartnotifs(request), "Re-initialize all notifications") \
        GENERIC_COMMAND("rpn", GenericCommand_rpn(request, arguments, command), "RPN calculator") \
        GENERIC_COMMAND("settemp", GenericCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored later") \
        GENERIC_COMMAND("settemp_restore", GenericCommand_settemp_restore(request, arguments), "Restore all cvars set by settemp command") \
index c07343c0f91ff3bed51ad9ebb2a244d06d0324b5..75a25b1033b64e80471e253382415137ab59ca07 100644 (file)
@@ -565,6 +565,43 @@ void Create_Notification_Entity(
        }
 }
 
+void Destroy_Notification_Entity(entity notif)
+{
+       if(notif.nent_name != "") { strunzone(notif.nent_name); }
+       if(notif.nent_args != "") { strunzone(notif.nent_args); }
+       if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
+       if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
+       if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
+       if(notif.nent_string != "") { strunzone(notif.nent_string); }
+       remove(notif);
+}
+
+void Destroy_All_Notifications(void)
+{
+       entity notif;
+       float i;
+       #define DESTROY_LOOP(type,count) \
+               for(i = 1; i <= count; ++i) \
+               { \
+                       notif = Get_Notif_Ent(type, i); \
+                       if not(notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
+                       Destroy_Notification_Entity(notif); \
+               }
+
+       // kill all networked notifications
+       #ifdef SVQC
+       Kill_Notification(NOTIF_ANY, world, 0, 0);
+       #endif
+
+       // kill all real notification entities
+       DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT)
+       DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT)
+       DESTROY_LOOP(MSG_WEAPON, NOTIF_WEAPON_COUNT)
+       DESTROY_LOOP(MSG_DEATH, NOTIF_DEATH_COUNT)
+
+       //print("Destroyed all huma-- I mean... notifications.. successfully.\n");
+}
+
 
 // =========================================
 //  Cvar Handling With 'dumpnotifs' Command
index 89b480ce9344216e4e4b418ae166527dda6cf796..130a57f89ef658bd7cf9030c5ef7808e38367c11 100644 (file)
        VARITEM(3, 4, XPD(s1, s2, s3, f1, f2, f3, f4)) \
        VARITEM(4, 4, XPD(s1, s2, s3, s4, f1, f2, f3, f4))
 
+void Destroy_All_Notifications(void);
+void Create_Notification_Entity(
+       float var_default,
+       float var_cvar,
+       float typeid,
+       float nameid,
+       string namestring,
+       float infoname,
+       float centername,
+       float strnum,
+       float flnum,
+       string args,
+       string hudargs,
+       string icon,
+       float cpid,
+       string durcnt,
+       string normal,
+       string gentle,
+       float msg_is_info,
+       float msg_is_multi);
+
 void Dump_Notifications(float fh, float alsoprint);
+
 void Local_Notification(float net_type, float net_name, ...count);
 void Local_Notification_WOVA(float net_type, float net_name, float stringcount, float floatcount, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4);
 
@@ -866,26 +888,6 @@ float NOTIF_CPID_COUNT;
 .string nent_strings[4];
 .float nent_floats[4];
 
-void Create_Notification_Entity(
-       float var_default,
-       float var_cvar,
-       float typeid,
-       float nameid,
-       string namestring,
-       float infoname,
-       float centername,
-       float strnum,
-       float flnum,
-       string args,
-       string hudargs,
-       string icon,
-       float cpid,
-       string durcnt,
-       string normal,
-       string gentle,
-       float msg_is_info,
-       float msg_is_multi);
-
 #define MSG_INFO_NOTIF(default,name,strnum,flnum,args,hudargs,icon,normal,gentle) \
        NOTIF_ADD_AUTOCVAR(name, default) \
        float name; \