]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Menu: add menu<-->client extensions system
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 7 Apr 2018 12:34:00 +0000 (22:34 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 7 Apr 2018 12:34:00 +0000 (22:34 +1000)
Disable menu based chat if not supported

15 files changed:
qcsrc/lib/unsafe.qh
qcsrc/menu/menu.qc
qcsrc/menu/modules/_mod.inc
qcsrc/menu/modules/_mod.qh
qcsrc/menu/modules/chat/commands.qc
qcsrc/menu/modules/chat/interface.qh
qcsrc/menu/modules/chat/state.qc
qcsrc/menu/modules/chat/state.qh
qcsrc/menu/modules/extensions/_mod.inc [new file with mode: 0644]
qcsrc/menu/modules/extensions/_mod.qh [new file with mode: 0644]
qcsrc/menu/modules/extensions/commands.qc [new file with mode: 0644]
qcsrc/menu/modules/extensions/commands.qh [new file with mode: 0644]
qcsrc/menu/modules/extensions/interface.qh [new file with mode: 0644]
qcsrc/menu/modules/extensions/state.qc [new file with mode: 0644]
qcsrc/menu/modules/extensions/state.qh [new file with mode: 0644]

index 60ad3d88da517e11174910a1a1d5da29085b5b15..5bea6878a6d04186f9b15352dd7685e7e2c9eecd 100644 (file)
@@ -10,8 +10,19 @@ X(float)
 X(vector)
 X(entity)
 X(string)
-USING(rawfunc, float(...));
-X(rawfunc)
+
+USING(func_v, void(...));
+X(func_v)
+
+USING(func_f, float(...));
+X(func_f)
+
+USING(func_v_v, void());
+X(func_v_v)
+
+USING(func_bool_v, void(bool));
+X(func_bool_v)
+
 #undef X
 
 #define _strid(s) ITOF(reinterpret_cast(int, s))
index af14e0842b4dc749897a45e7fc2f18ae2dcaf6c4..3f2e91e47736842f3bb30a84633fa871a864b859 100644 (file)
@@ -84,6 +84,7 @@ void m_init()
        }
 
        // needs to be done so early because of the constants they create
+       static_init_early();
        static_init();
        static_init_late();
        static_init_precache();
index 8b11cef8cba84fbc00df00f80d8100c3400265c6..3590ec3fe108a8ca9877bb9e6f8bae69918f47a9 100644 (file)
@@ -1,3 +1,4 @@
 // generated file; do not modify
 
 #include <menu/modules/chat/_mod.inc>
+#include <menu/modules/extensions/_mod.inc>
index 026d48278a5a1507478d693724fc9bea35a57c79..add806e2ec8e6bd7eafa7a4a77a83516cebc79ff 100644 (file)
@@ -1,3 +1,4 @@
 // generated file; do not modify
 
 #include <menu/modules/chat/_mod.qh>
+#include <menu/modules/extensions/_mod.qh>
index 5e4c052a11f53d53a6bb96e5f0eac6717e7e2006..b84ef72266f6629b0d445f45580c0ca6000524aa 100644 (file)
@@ -41,6 +41,9 @@ GENERIC_COMMAND(commandmode, "input a console command")
     {
         case CMD_REQUEST_COMMAND:
         {
+            if (!autoextension_chat) {
+                return;
+            }
             string prefix = arguments > 1 ? strcat(substring(command, argv_start_index(1), argv_end_index(-1)), " ") : "";
             chat_command = "";
             strcpy(chat_text, prefix);
@@ -65,6 +68,9 @@ GENERIC_COMMAND(messagemode, "input a chat message to say to everyone")
     {
         case CMD_REQUEST_COMMAND:
         {
+            if (!autoextension_chat) {
+                return;
+            }
             string prefix = arguments > 1 ? strcat(substring(command, argv_start_index(1), argv_end_index(-1)), " ") : "";
             chat_command = "say ";
             strcpy(chat_text, prefix);
@@ -89,6 +95,9 @@ GENERIC_COMMAND(messagemode2, "input a chat message to say to only your team")
     {
         case CMD_REQUEST_COMMAND:
         {
+            if (!autoextension_chat) {
+                return;
+            }
             string prefix = arguments > 1 ? strcat(substring(command, argv_start_index(1), argv_end_index(-1)), " ") : "";
             chat_command = "say_team ";
             strcpy(chat_text, prefix);
index 1760a2ef368249a882fa93bf93f9c5c980794a43..7eb9b5039b3df6da0e262491a21b874fb60b9d54 100644 (file)
@@ -1,5 +1,12 @@
 #pragma once
 
+#include <menu/modules/extensions/interface.qh>
+
 #include "commands.qh"
 
 string autocvar__cl_hook_print;
+
+STATIC_INIT(extension_chat)
+{
+    extensions_report("org.xonotic:chat:1");
+}
index 299efbdb54ee8ac27b4ab7e275db6ee139a33201..bd5e717c94786c51f496d3c8553443fe38696a4e 100644 (file)
@@ -8,7 +8,7 @@ STATIC_INIT(chat_buffer) {
 }
 
 int chat_lines_count() {
-    return chat_buffer_idx + 1;
+    return chat_buffer_idx;
 }
 
 string chat_lines_get(int i) {
index 9ca190389c196eab98ba44be5644f4b6a58097c2..79be06a9e8c6dba87f6f222656f08aa0c35be17e 100644 (file)
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <menu/modules/extensions/interface.qh>
+
 string chat_command;
 string chat_text;
 
@@ -8,3 +10,5 @@ int chat_lines_count();
 string chat_lines_get(int i);
 
 void chat_lines_push(string s);
+
+AUTOEXTENSION(chat, "org.xonotic:chat:1");
diff --git a/qcsrc/menu/modules/extensions/_mod.inc b/qcsrc/menu/modules/extensions/_mod.inc
new file mode 100644 (file)
index 0000000..9a5edca
--- /dev/null
@@ -0,0 +1,3 @@
+// generated file; do not modify
+#include <menu/modules/extensions/commands.qc>
+#include <menu/modules/extensions/state.qc>
diff --git a/qcsrc/menu/modules/extensions/_mod.qh b/qcsrc/menu/modules/extensions/_mod.qh
new file mode 100644 (file)
index 0000000..93581cf
--- /dev/null
@@ -0,0 +1,3 @@
+// generated file; do not modify
+#include <menu/modules/extensions/commands.qh>
+#include <menu/modules/extensions/state.qh>
diff --git a/qcsrc/menu/modules/extensions/commands.qc b/qcsrc/menu/modules/extensions/commands.qc
new file mode 100644 (file)
index 0000000..77eab7f
--- /dev/null
@@ -0,0 +1,54 @@
+#include "commands.qh"
+
+#include "state.qh"
+
+// space separated list of extensions
+void extensions_set(string s)
+{
+    for (int i = 0, n = extensions_count(); i < n; ++i) {
+        string id = extensions_get_name(i);
+        void(bool) set = extensions_get_setter(i);
+        bool enable = strhasword(s, id);
+        set(enable);
+    }
+}
+
+GENERIC_COMMAND(_cl_hook_gamestart, "_cl_hook_gamestart")
+{
+    switch(request)
+    {
+        case CMD_REQUEST_COMMAND:
+        {
+            string s = substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
+            localcmd("\nset _cl_hook_gametype ", s, "; _cl_hook_gamestart_stage2\n");
+            extensions_set(cvar_string("_cl_extensions"));
+            cvar_set("_cl_extensions", "");
+            return;
+        }
+
+        default:
+        case CMD_REQUEST_USAGE:
+        {
+            return;
+        }
+    }
+}
+
+GENERIC_COMMAND(_cl_extensions, "_cl_extensions")
+{
+    switch(request)
+    {
+        case CMD_REQUEST_COMMAND:
+        {
+            string s = substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
+            extensions_set(s);
+            return;
+        }
+
+        default:
+        case CMD_REQUEST_USAGE:
+        {
+            return;
+        }
+    }
+}
diff --git a/qcsrc/menu/modules/extensions/commands.qh b/qcsrc/menu/modules/extensions/commands.qh
new file mode 100644 (file)
index 0000000..6f70f09
--- /dev/null
@@ -0,0 +1 @@
+#pragma once
diff --git a/qcsrc/menu/modules/extensions/interface.qh b/qcsrc/menu/modules/extensions/interface.qh
new file mode 100644 (file)
index 0000000..db690ec
--- /dev/null
@@ -0,0 +1,24 @@
+#pragma once
+
+#ifdef MENUQC
+void extensions_register(string id, void(bool) set);
+#endif
+
+#define AUTOEXTENSION(var, id) \
+    bool autoextension_##var; \
+    void autoextension_##var##_set(bool val) { \
+        autoextension_##var = val; \
+    } \
+    STATIC_INIT(autoextension_##var) \
+    { \
+        extensions_register(id, autoextension_##var##_set); \
+    }
+
+noref string autocvar__cl_extensions;
+STATIC_INIT(extensions)
+{
+    cvar_set("_cl_extensions", "");
+}
+
+#define extensions_report(id) \
+    cvar_set("_cl_extensions", cons(cvar_string("_cl_extensions"), id))
diff --git a/qcsrc/menu/modules/extensions/state.qc b/qcsrc/menu/modules/extensions/state.qc
new file mode 100644 (file)
index 0000000..1550281
--- /dev/null
@@ -0,0 +1,26 @@
+#include "state.qh"
+
+int extensions_buffer;
+int extensions_buffer_idx;
+
+STATIC_INIT_EARLY(extensions_buffer)
+{
+    extensions_buffer = buf_create();
+}
+
+int extensions_count()
+{
+    return extensions_buffer_idx;
+}
+
+string extensions_get(int i, int fld)
+{
+    return bufstr_get(extensions_buffer, i * _EXTENSIONS_FIELDS + fld);
+}
+
+void extensions_register(string id, void(bool) set)
+{
+    int i = extensions_buffer_idx++ * _EXTENSIONS_FIELDS;
+    bufstr_set(extensions_buffer, i + EXTENSIONS_NAME, id);
+    bufstr_set(extensions_buffer, i + EXTENSIONS_SETTER, ftos(ITOF(reinterpret_cast(int, set))));
+}
diff --git a/qcsrc/menu/modules/extensions/state.qh b/qcsrc/menu/modules/extensions/state.qh
new file mode 100644 (file)
index 0000000..4f2acbd
--- /dev/null
@@ -0,0 +1,16 @@
+#pragma once
+
+int extensions_count();
+
+enum {
+    EXTENSIONS_NAME,
+    EXTENSIONS_SETTER,
+    _EXTENSIONS_FIELDS,
+};
+
+string extensions_get(int i, int fld);
+
+#define extensions_get_name(i) extensions_get(i, EXTENSIONS_NAME)
+
+#define extensions_get_setter(i) reinterpret_cast(func_bool_v, FTOI(stof(extensions_get(i, EXTENSIONS_SETTER))))
+