From: Samual Lenks Date: Fri, 1 Mar 2013 04:51:03 +0000 (-0500) Subject: Create a way to restart notifications X-Git-Tag: xonotic-v0.7.0~62^2~23^2~69 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e0b4c585e550e4182c7c133fee0a08f2d3b9f2cc;p=xonotic%2Fxonotic-data.pk3dir.git Create a way to restart notifications --- diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index 4d3df8e87..e85e3b111 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -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") \ diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index c07343c0f..75a25b103 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -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 diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index 89b480ce9..130a57f89 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -38,7 +38,29 @@ 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; \