]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Support switching between data sources
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 16 Aug 2015 10:05:39 +0000 (20:05 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 16 Aug 2015 10:05:39 +0000 (20:05 +1000)
qcsrc/menu/xonotic/datasource.qc
qcsrc/menu/xonotic/dialog_media_guide.qc
qcsrc/menu/xonotic/dialog_media_guide_entries.qc
qcsrc/menu/xonotic/dialog_media_guide_topics.qc

index 4abea359c48e85f27e1ee887b82be55465905f2d..46e5a287c4e7972cdac6b6bd6ff2c66c1fb0a3f6 100644 (file)
@@ -2,8 +2,9 @@
 #define DATASOURCE_H
 .string stringfield_null;
 CLASS(DataSource, Object)
-    ATTRIB(DataSource, entryIcon, .string, stringfield_null)
     ATTRIB(DataSource, entryName, .string, stringfield_null)
+    ATTRIB(DataSource, entryIcon, .string, stringfield_null)
+    ATTRIB(DataSource, entryIconPrefix, string, "")
     METHOD(DataSource, getEntry, entity(int))
     METHOD(DataSource, indexOf, int(string))
     METHOD(DataSource, reload, int(string))
index f28ad61f8f09d80af7cac20f6c8685496fd447f2..929cc20151fccd4ecc7dd7ba8afb1b1ad79b091e 100644 (file)
@@ -1,15 +1,49 @@
 #ifndef DIALOG_MEDIA_GUIDE_H
 #define DIALOG_MEDIA_GUIDE_H
 #include "datasource.qc"
+
+#define TOPICS(X) \
+    X(NEW(GametypeSource),  _("Gametypes"), "gametype_dm") \
+    X(NEW(MapSource),       _("Maps"),      "gametype_ctf") \
+    /**/
 CLASS(TopicSource, DataSource)
-    .string mdl, message;
-    ATTRIB(TopicSource, entryIcon, .string, mdl)
-    ATTRIB(TopicSource, entryName, .string, message)
+    .string icon, name;
+    ATTRIB(TopicSource, entryIcon, .string, icon)
+    ATTRIB(TopicSource, entryName, .string, name)
     METHOD(TopicSource, getEntry, entity(int))
+    entity TopicSource_getEntry(int i) {
+        static entity e;
+        if (!e) e = new(entry);
+        int idx = 0;
+        .string en = name, ei = icon;
+        #define TOPIC(src, name, icon) if (idx++ == i) { e.(en) = name; e.(ei) = icon; return e; }
+        TOPICS(TOPIC)
+        #undef TOPIC
+        e.en = "undefined"; e.ei = "undefined";
+        return e;
+    }
     METHOD(TopicSource, reload, int(string))
-    METHOD(TopicSource, destroy, void(entity))
+    int TopicSource_reload(string filter) {
+        int i = 0;
+        #define TOPIC(src, name, icon) i++;
+        TOPICS(TOPIC)
+        #undef TOPIC
+        return i;
+    }
 ENDCLASS(TopicSource)
 
+#include "../../common/mapinfo.qh"
+CLASS(GametypeSource, DataSource)
+    .string mdl, message;
+    ATTRIB(GametypeSource, entryName, .string, message)
+    ATTRIB(GametypeSource, entryIcon, .string, mdl)
+    ATTRIB(GametypeSource, entryIconPrefix, string, "gametype_")
+    METHOD(GametypeSource, getEntry, entity(int))
+    entity GametypeSource_getEntry(int i) { return MAPINFO_TYPES[i]; }
+    METHOD(GametypeSource, reload, int(string))
+    int GametypeSource_reload(string filter) { return MAPINFO_TYPE_COUNT; }
+ENDCLASS(GametypeSource)
+
 CLASS(MapSource, DataSource)
     .string icon, name;
     ATTRIB(MapSource, entryIcon, .string, icon)
@@ -29,11 +63,8 @@ CLASS(XonoticGuideTab, XonoticTab)
     METHOD(XonoticGuideTab, topicChangeNotify, void(entity))
     METHOD(XonoticGuideTab, topicSelectNotify, void(entity))
 
-    ATTRIB(XonoticGuideTab, topicSource, entity, NEW(TopicSource))
-    ATTRIB(XonoticGuideTab, mapSource, entity, NEW(MapSource))
-
-    ATTRIB(XonoticGuideTab, topicList, entity, NEW(XonoticTopicList, this.topicSource, "gametype_", this))
-    ATTRIB(XonoticGuideTab, entryList, entity, NEW(XonoticEntryList, this.mapSource))
+    ATTRIB(XonoticGuideTab, topicList, entity, NEW(XonoticTopicList, NEW(TopicSource), this))
+    ATTRIB(XonoticGuideTab, entryList, entity, NEW(XonoticEntryList, NULL))
 
     INIT(XonoticGuideTab) {
         this.configureDialog(this);
@@ -73,16 +104,20 @@ void XonoticGuideTab_fill(entity this)
 
 void XonoticGuideTab_topicChangeNotify(entity this)
 {
+    entity topics = this.topicList;
     entity entries = this.entryList;
+    int i = topics.selectedItem;
+    int idx = 0;
+    entity found = NULL;
+    #define TOPIC(src, name, icon) if (idx++ == i) { static entity e; if (!e) e = src; found = e; break; }
+    do { TOPICS(TOPIC); } while (0);
+    #undef TOPIC
+    entries.source = found;
     entries.refilter(entries);
 }
 
 void XonoticGuideTab_topicSelectNotify(entity this) { this.setFocus(this, this.entryList); }
 
-entity TopicSource_getEntry(int i) { return MAPINFO_TYPES[i]; }
-
-int TopicSource_reload(string filter) { return MAPINFO_TYPE_COUNT; }
-
 entity MapSource_getEntry(int i)
 {
     if (!MapInfo_Get_ByID(i)) return NULL;
index fed9d5d91ef644951481ffc4b5b3bb46cce6984a..eede28ba3f5e4b133917faeaa903efeeea298dff 100644 (file)
@@ -40,8 +40,9 @@ ENDCLASS(XonoticEntryList)
 
 void XonoticEntryList_drawListBoxItem(entity this, int i, vector absSize, bool isSelected, bool isFocused)
 {
-    entity e = this.source.getEntry(i);
-    if (!e) return;
+    if (!this.source) return;
+    entity entry = this.source.getEntry(i);
+    if (!entry) return;
 
     if (isSelected) {
         draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
@@ -49,8 +50,10 @@ void XonoticEntryList_drawListBoxItem(entity this, int i, vector absSize, bool i
         this.focusedItemAlpha = getFadedAlpha(this.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
         draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, this.focusedItemAlpha);
     }
-    string s = draw_TextShortenToWidth(strdecolorize(e.(this.source.entryName)), this.columnNameSize, 0, this.realFontSize);
-    draw_Picture(this.columnPreviewOrigin * eX, e.(this.source.entryIcon), this.columnPreviewSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
+    string icon = strcat(this.source.entryIconPrefix, entry.(this.source.entryIcon));
+    string name = entry.(this.source.entryName);
+    string s = draw_TextShortenToWidth(strdecolorize(name), this.columnNameSize, 0, this.realFontSize);
+    draw_Picture(this.columnPreviewOrigin * eX, icon, this.columnPreviewSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
     draw_Text(this.realUpperMargin1 * eY + (this.columnNameOrigin + 0.00 * (this.columnNameSize - draw_TextWidth(s, 0, this.realFontSize))) * eX, s, this.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
 }
 
@@ -90,6 +93,10 @@ float XonoticEntryList_keyDown(entity this, float scan, float ascii, float shift
 
 void XonoticEntryList_refilter(entity this)
 {
+    if (!this.source) {
+        this.nItems = 0;
+        return;
+    }
     this.nItems = this.source.reload(this.stringFilter);
     for (int i = 0, n = this.nItems; i < n; ++i) {
         draw_PreloadPicture(this.source.getEntry(i).(this.source.entryIcon));
index 8866b6736b1068b71f5ea4078c12a324cf4f465e..b3845c67bf5ce37f753f50233af968d6fd620d0c 100644 (file)
@@ -18,13 +18,11 @@ CLASS(XonoticTopicList, XonoticListBox)
     METHOD(XonoticTopicList, setSelected, void(entity, int))
 
     ATTRIB(XonoticTopicList, source, DataSource, NULL)
-    ATTRIB(XonoticTopicList, entryIconPrefix, string, "")
     ATTRIB(XonoticTopicList, listener, entity, NULL)
 
-    CONSTRUCTOR(XonoticTopicList, DataSource _source, string _entryIconPrefix, entity _listener) {
+    CONSTRUCTOR(XonoticTopicList, DataSource _source, entity _listener) {
        CONSTRUCT(XonoticTopicList);
        this.source = _source;
-       this.entryIconPrefix = _entryIconPrefix;
        this.listener = _listener;
        this.nItems = _source.reload("");
        this.configureXonoticListBox(this);
@@ -48,7 +46,7 @@ void XonoticTopicList_drawListBoxItem(entity this, int i, vector absSize, bool i
         draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, this.focusedItemAlpha);
     }
     entity entry = this.source.getEntry(i);
-    string icon = strcat(this.entryIconPrefix, entry.(this.source.entryIcon));
+    string icon = strcat(this.source.entryIconPrefix, entry.(this.source.entryIcon));
     string name = entry.(this.source.entryName);
     draw_Picture(this.columnIconOrigin * eX, icon, this.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
     vector save_fontscale = draw_fontscale;