]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Cleanup the code a bit
authorSamual Lenks <samual@xonotic.org>
Wed, 26 Sep 2012 19:41:14 +0000 (15:41 -0400)
committerSamual Lenks <samual@xonotic.org>
Wed, 26 Sep 2012 19:41:14 +0000 (15:41 -0400)
qcsrc/common/notifications.qc

index c132888327889ecba87c4b3242f6d50dc096f154..6d8e4c1a82138b6897db790d876a5cbfcaac29e1 100644 (file)
 #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)