From: Samual Lenks Date: Wed, 26 Sep 2012 19:41:14 +0000 (-0400) Subject: Cleanup the code a bit X-Git-Tag: xonotic-v0.7.0~62^2~23^2~412 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=496660d78f9914ec79668bbd7536d857d734f445;p=xonotic%2Fxonotic-data.pk3dir.git Cleanup the code a bit --- diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index c13288832..6d8e4c1a8 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -22,34 +22,9 @@ #endif #define HANDLE_CPID(cpid) ((min(NOTIF_MAX, cpid) == NO_CPID) ? FALSE : cpid) - -// select between the normal or the gentle message string based on client (or server) settings -string normal_or_gentle(string normal, string gentle) -{ - #ifdef CSQC - if(autocvar_cl_gentle || autocvar_cl_gentle_messages) - #else - if(autocvar_sv_gentle) - #endif - return ((gentle != "") ? gentle : normal); - else - return normal; -} - -// color code replace, place inside of sprintf and parse the string -string CCR(string input) -{ - input = strreplace("^F1", "^3", input); - input = strreplace("^F2", "^2", input); - input = strreplace("^BG", "^7", input); - - input = strreplace("^N", "^7", input); // "none"-- reset to white - - return input; -} - -#define VAR_TO_TEXT(var) #var #define CHECK_MATCH(a,b) if(min(NOTIF_MAX, a) == b) +#define VAR_TO_TEXT(var) #var + // ==================================== // Notifications List and Information @@ -168,87 +143,118 @@ MSG_CENTER_NOTIFICATIONS MSG_WEAPON_NOTIFICATIONS -// =============================== -// Frontend Notification Pushing -// =============================== +// ====================== +// Supporting Functions +// ====================== -#ifdef CSQC -void Local_Notification(float net_type, float net_name, string s1, string s2, string s3) +// select between the normal or the gentle message string based on client (or server) settings +string normal_or_gentle(string normal, string gentle) +{ + #ifdef CSQC + if(autocvar_cl_gentle || autocvar_cl_gentle_messages) + #else + if(autocvar_sv_gentle) + #endif + return ((gentle != "") ? gentle : normal); + else + return normal; +} + +// get the actual name of a notification and return it as a string +string Get_Notif_Name(float net_type, float net_name) { switch(net_type) { case MSG_INFO: { #define MSG_INFO_NOTIF(name,args,normal,gentle) \ - { CHECK_MATCH(name, net_name) { print(sprintf(CCR(normal_or_gentle(normal, gentle)), args)); } } - + { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } } MSG_INFO_NOTIFICATIONS break; } - case MSG_NOTIFY: { + #define MSG_NOTIFY_NOTIF(name,args,icon,normal,gentle) \ + { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } } + MSG_NOTIFY_NOTIFICATIONS break; } - case MSG_CENTER: { #define MSG_CENTER_NOTIF(name,args,cpid,durcnt,normal,gentle) \ - { CHECK_MATCH(name, net_name) { centerprint_generic(HANDLE_CPID(cpid), sprintf(CCR(normal_or_gentle(normal, gentle)), args), durcnt); } } - + { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } } MSG_CENTER_NOTIFICATIONS break; } - case MSG_WEAPON: { + #define MSG_WEAPON_NOTIF(name,args,normal,gentle) \ + { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } } + MSG_WEAPON_NOTIFICATIONS break; } } + + return ""; } -#endif +// color code replace, place inside of sprintf and parse the string +string CCR(string input) +{ + input = strreplace("^F1", "^3", input); + input = strreplace("^F2", "^2", input); + input = strreplace("^BG", "^7", input); + + input = strreplace("^N", "^7", input); // "none"-- reset to white -// ========================= -// Notification Networking -// ========================= + return input; +} -string Get_Notif_Name(float net_type, float net_name) + +// =============================== +// Frontend Notification Pushing +// =============================== + +#ifdef CSQC +void Local_Notification(float net_type, float net_name, string s1, string s2, string s3) { switch(net_type) { case MSG_INFO: { #define MSG_INFO_NOTIF(name,args,normal,gentle) \ - { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } } + { CHECK_MATCH(name, net_name) { print(sprintf(CCR(normal_or_gentle(normal, gentle)), args)); } } + MSG_INFO_NOTIFICATIONS break; } + case MSG_NOTIFY: { - #define MSG_NOTIFY_NOTIF(name,args,icon,normal,gentle) \ - { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } } - MSG_NOTIFY_NOTIFICATIONS break; } + case MSG_CENTER: { #define MSG_CENTER_NOTIF(name,args,cpid,durcnt,normal,gentle) \ - { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } } + { CHECK_MATCH(name, net_name) { centerprint_generic(HANDLE_CPID(cpid), sprintf(CCR(normal_or_gentle(normal, gentle)), args), durcnt); } } + MSG_CENTER_NOTIFICATIONS break; } + case MSG_WEAPON: { - #define MSG_WEAPON_NOTIF(name,args,normal,gentle) \ - { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } } - MSG_WEAPON_NOTIFICATIONS break; } } - - return ""; } +#endif + + +// ========================= +// Notification Networking +// ========================= #ifdef SVQC void Send_Notification(float net_type, entity client, float net_name, string s1, string s2, string s3)