1 #ifndef DIALOG_SETTINGS_GAME_H
2 #define DIALOG_SETTINGS_GAME_H
4 #include "../gamesettings.qh"
6 #include "datasource.qc"
7 CLASS(SettingSource, DataSource)
8 METHOD(SettingSource, getEntry, entity(int i, void(string name, string icon) returns))
11 entity it = l.m_get();
12 if (returns) returns(it.title, string_null);
15 METHOD(SettingSource, reload, int(string filter)) { return SETTINGS_COUNT; }
16 ENDCLASS(SettingSource)
19 CLASS(XonoticRegisteredSettingsList, XonoticListBox)
20 ATTRIB(XonoticRegisteredSettingsList, alphaBG, float, 0)
21 ATTRIB(XonoticRegisteredSettingsList, itemAbsSize, vector, '0 0 0')
22 ATTRIB(XonoticRegisteredSettingsList, origin, vector, '0 0 0')
23 ATTRIB(XonoticRegisteredSettingsList, realFontSize, vector, '0 0 0')
24 ATTRIB(XonoticRegisteredSettingsList, realUpperMargin, float, 0)
25 ATTRIB(XonoticRegisteredSettingsList, rowsPerItem, float, 2)
26 ATTRIB(XonoticRegisteredSettingsList, stringFilterBox, entity, NULL)
27 ATTRIB(XonoticRegisteredSettingsList, stringFilter, string, string_null)
28 ATTRIB(XonoticRegisteredSettingsList, typeToSearchString, string, string_null)
29 ATTRIB(XonoticRegisteredSettingsList, typeToSearchTime, float, 0)
30 ATTRIB(XonoticRegisteredSettingsList, source, DataSource, NULL)
31 ATTRIB(XonoticRegisteredSettingsList, onChange, void(entity, entity), func_null)
32 ATTRIB(XonoticRegisteredSettingsList, onChangeEntity, entity, NULL)
33 string XonoticRegisteredSettingsList_cb_name;
34 void XonoticRegisteredSettingsList_cb(string _name, string _icon)
36 XonoticRegisteredSettingsList_cb_name = _name;
38 METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused))
40 if (!this.source) return;
41 if (!this.source.getEntry(i, XonoticRegisteredSettingsList_cb)) return;
42 string name = XonoticRegisteredSettingsList_cb_name;
44 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
45 } else if (isFocused) {
46 this.focusedItemAlpha = getFadedAlpha(this.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
47 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, this.focusedItemAlpha);
49 string s = draw_TextShortenToWidth(strdecolorize(name), 1, 0, this.realFontSize);
50 draw_Text(this.realUpperMargin * eY + (0.5 * this.realFontSize.x) * eX, s, this.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
52 METHOD(XonoticRegisteredSettingsList, refilter, void(entity this))
58 this.nItems = this.source.reload(this.stringFilter);
60 METHOD(XonoticRegisteredSettingsList, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
62 super.resizeNotify(this, relOrigin, relSize, absOrigin, absSize);
64 this.itemAbsSize = '0 0 0';
65 this.realFontSize_y = this.fontSize / (this.itemAbsSize_y = (absSize.y * this.itemHeight));
66 this.realFontSize_x = this.fontSize / (this.itemAbsSize_x = (absSize.x * (1 - this.controlWidth)));
67 this.realUpperMargin = 0.5 * (1 - this.realFontSize.y);
69 METHOD(XonoticRegisteredSettingsList, setSelected, void(entity this, int i))
71 super.setSelected(this, i);
72 this.onChange(this, this.onChangeEntity);
74 CONSTRUCTOR(XonoticRegisteredSettingsList, DataSource _source) {
75 CONSTRUCT(XonoticRegisteredSettingsList);
76 this.source = _source;
77 this.configureXonoticListBox(this);
80 ENDCLASS(XonoticRegisteredSettingsList)
83 CLASS(XonoticGameSettingsTab, XonoticTab)
84 ATTRIB(XonoticGameSettingsTab, intendedWidth, float, 0.9)
85 ATTRIB(XonoticGameSettingsTab, rows, float, 15.5)
86 ATTRIB(XonoticGameSettingsTab, columns, float, 6.5)
87 ATTRIB(XonoticGameSettingsTab, source, DataSource, NEW(SettingSource))
88 ATTRIB(XonoticGameSettingsTab, topicList, entity, NEW(XonoticRegisteredSettingsList, this.source))
89 ATTRIB(XonoticGameSettingsTab, currentPanel, entity, NEW(XonoticTab))
90 ATTRIB(XonoticGameSettingsTab, currentItem, entity, NULL)
91 METHOD(XonoticGameSettingsTab, topicChangeNotify, void(entity, entity this))
93 entity c = this.currentPanel;
94 entity removing = this.currentItem;
95 entity adding = this.topicList.source.getEntry(this.topicList.selectedItem, func_null);
96 if (removing == adding) return;
98 this.currentItem = NULL;
99 c.removeItem(c, removing);
102 this.currentItem = adding;
103 adding.resizeNotify(adding, '0 0 0', c.size, '0 0 0', c.size);
104 c.addItem(c, adding, '0 0 0', '1 1 0', 1);
107 METHOD(XonoticGameSettingsTab, fill, void(entity this))
109 entity topics = this.topicList;
110 topics.onChange = this.topicChangeNotify;
111 topics.onChangeEntity = this;
114 col = 0, width = 1.5;
115 this.gotoRC(this, 0, col);
116 this.TD(this, this.rows, width, topics);
118 col += width, width = this.columns - col;
119 this.gotoRC(this, 0, col); this.setFirstColumn(this, this.currentColumn);
120 this.TD(this, this.rows, width, this.currentPanel);
122 this.topicChangeNotify(topics, this);
124 INIT(XonoticGameSettingsTab)
126 this.configureDialog(this);
128 ENDCLASS(XonoticGameSettingsTab)