]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
DataSource: pass context
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 3 Oct 2015 09:41:39 +0000 (19:41 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 3 Oct 2015 09:42:53 +0000 (19:42 +1000)
qcsrc/menu/xonotic/datasource.qc
qcsrc/menu/xonotic/dialog_settings_game.qc

index 49cc571761885e394686651985b548d98af1f7c7..57ce0c80c312e73c7826110a6075dc8a6e9b4284 100644 (file)
@@ -12,12 +12,58 @@ CLASS(DataSource, Object)
      * returns `DataSource_false` if out of bounds
      * otherwise returns an entity or `DataSource_true`
      */
      * returns `DataSource_false` if out of bounds
      * otherwise returns an entity or `DataSource_true`
      */
-    METHOD(DataSource, getEntry, entity(int i, void(string name, string icon) returns)) { return DataSource_false; }
+    METHOD(DataSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) { return DataSource_false; }
     /** return the index of the first match for `find`. optional */
     /** return the index of the first match for `find`. optional */
-    METHOD(DataSource, indexOf, int(string find)) { return -1; }
+    METHOD(DataSource, indexOf, int(entity this, string find)) { return -1; }
     /** reload all entries matching `filter` returning how many matches were found */
     /** reload all entries matching `filter` returning how many matches were found */
-    METHOD(DataSource, reload, int(string filter)) { return 0; }
+    METHOD(DataSource, reload, int(entity this, string filter)) { return 0; }
     /** cleanup on shutdown. optional */
     /** cleanup on shutdown. optional */
-    METHOD(DataSource, destroy, void(entity)) { }
+    METHOD(DataSource, destroy, void(entity this)) { }
 ENDCLASS(DataSource)
 ENDCLASS(DataSource)
+
+
+CLASS(StringSource, DataSource)
+    ATTRIB(StringSource, StringSource_str, string, string_null)
+    ATTRIB(StringSource, StringSource_sep, string, string_null)
+    CONSTRUCTOR(StringSource, string str, string sep)
+    {
+        CONSTRUCT(StringSource);
+        this.StringSource_str = str;
+        this.StringSource_sep = sep;
+    }
+    METHOD(StringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns))
+    {
+        int n = tokenizebyseparator(this.StringSource_str, this.StringSource_sep);
+        if (i < 0 || i >= n) return DataSource_false;
+        string s = argv(i);
+        if (returns) returns(s, string_null);
+        return DataSource_true;
+    }
+    METHOD(StringSource, reload, int(entity this, string filter))
+    {
+        return tokenizebyseparator(this.StringSource_str, this.StringSource_sep);
+    }
+ENDCLASS(StringSource)
+
+CLASS(CvarStringSource, StringSource)
+    ATTRIB(CvarStringSource, CvarStringSource_cvar, string, string_null)
+    CONSTRUCTOR(CvarStringSource, string cv, string sep)
+    {
+        CONSTRUCT(CvarStringSource);
+        this.CvarStringSource_cvar = cv;
+        this.StringSource_sep = sep;
+    }
+    METHOD(CvarStringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns))
+    {
+        string s = this.CvarStringSource_cvar;
+        this.StringSource_str = s ? cvar_string(s) : string_null;
+        return super.getEntry(this, i, returns);
+    }
+    METHOD(CvarStringSource, reload, int(entity this, string filter))
+    {
+        string s = this.CvarStringSource_cvar;
+        this.StringSource_str = s ? cvar_string(s) : string_null;
+        return super.reload(this, filter);
+    }
+ENDCLASS(CvarStringSource)
 #endif
 #endif
index fc87261a538b736546e2481b29d992d6d3abc2eb..16bc110adb2516d8c80b86aad5a51009e0f7e11d 100644 (file)
@@ -5,14 +5,14 @@
 
 #include "datasource.qc"
 CLASS(SettingSource, DataSource)
 
 #include "datasource.qc"
 CLASS(SettingSource, DataSource)
-    METHOD(SettingSource, getEntry, entity(int i, void(string name, string icon) returns))
+    METHOD(SettingSource, getEntry, entity(entity this, int i, void(string name, string icon) returns))
     {
         Lazy l = SETTINGS[i];
         entity it = l.m_get();
         if (returns) returns(it.title, string_null);
         return it;
     }
     {
         Lazy l = SETTINGS[i];
         entity it = l.m_get();
         if (returns) returns(it.title, string_null);
         return it;
     }
-    METHOD(SettingSource, reload, int(string filter)) { return SETTINGS_COUNT; }
+    METHOD(SettingSource, reload, int(entity this, string filter)) { return SETTINGS_COUNT; }
 ENDCLASS(SettingSource)
 
 #include "listbox.qc"
 ENDCLASS(SettingSource)
 
 #include "listbox.qc"
@@ -38,7 +38,7 @@ CLASS(XonoticRegisteredSettingsList, XonoticListBox)
        METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused))
        {
                if (!this.source) return;
        METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused))
        {
                if (!this.source) return;
-               if (!this.source.getEntry(i, XonoticRegisteredSettingsList_cb)) return;
+               if (!this.source.getEntry(this.source, i, XonoticRegisteredSettingsList_cb)) return;
                string name = XonoticRegisteredSettingsList_cb_name;
                if (isSelected) {
                        draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
                string name = XonoticRegisteredSettingsList_cb_name;
                if (isSelected) {
                        draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
@@ -55,7 +55,7 @@ CLASS(XonoticRegisteredSettingsList, XonoticListBox)
                        this.nItems = 0;
                        return;
                }
                        this.nItems = 0;
                        return;
                }
-               this.nItems = this.source.reload(this.stringFilter);
+               this.nItems = this.source.reload(this.source, this.stringFilter);
        }
        METHOD(XonoticRegisteredSettingsList, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
        {
        }
        METHOD(XonoticRegisteredSettingsList, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
        {
@@ -92,7 +92,8 @@ CLASS(XonoticGameSettingsTab, XonoticTab)
        {
                entity c = this.currentPanel;
                entity removing = this.currentItem;
        {
                entity c = this.currentPanel;
                entity removing = this.currentItem;
-               entity adding = this.topicList.source.getEntry(this.topicList.selectedItem, func_null);
+               DataSource data = this.topicList.source;
+               entity adding = data.getEntry(data, this.topicList.selectedItem, func_null);
                if (removing == adding) return;
                if (removing) {
                        this.currentItem = NULL;
                if (removing == adding) return;
                if (removing) {
                        this.currentItem = NULL;