#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)
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);
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;
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);
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);
}
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));
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);
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;