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(entity this, 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, getEntryTooltip, entity(entity this, int i, void(string theTooltip) returns))
18 entity it = l.m_get();
19 if (returns) returns(it.tooltip);
22 METHOD(SettingSource, reload, int(entity this, string filter)) { return Settings_COUNT; }
23 ENDCLASS(SettingSource)
26 CLASS(XonoticRegisteredSettingsList, XonoticListBox)
27 ATTRIB(XonoticRegisteredSettingsList, alphaBG, float, 0)
28 ATTRIB(XonoticRegisteredSettingsList, itemAbsSize, vector, '0 0 0')
29 ATTRIB(XonoticRegisteredSettingsList, origin, vector, '0 0 0')
30 ATTRIB(XonoticRegisteredSettingsList, realFontSize, vector, '0 0 0')
31 ATTRIB(XonoticRegisteredSettingsList, realUpperMargin, float, 0)
32 ATTRIB(XonoticRegisteredSettingsList, rowsPerItem, float, 2)
33 ATTRIB(XonoticRegisteredSettingsList, stringFilterBox, entity, NULL)
34 ATTRIB(XonoticRegisteredSettingsList, stringFilter, string, string_null)
35 ATTRIB(XonoticRegisteredSettingsList, typeToSearchString, string, string_null)
36 ATTRIB(XonoticRegisteredSettingsList, typeToSearchTime, float, 0)
37 ATTRIB(XonoticRegisteredSettingsList, source, DataSource, NULL)
38 ATTRIB(XonoticRegisteredSettingsList, onChange, void(entity, entity), func_null)
39 ATTRIB(XonoticRegisteredSettingsList, onChangeEntity, entity, NULL)
40 METHOD(XonoticRegisteredSettingsList, focusedItemChangeNotify, void(entity));
42 string XonoticRegisteredSettingsList_cb_name;
43 string XonoticRegisteredSettingsList_cb_tooltip;
44 void XonoticRegisteredSettingsList_getNameIcon_cb(string _name, string _icon)
46 XonoticRegisteredSettingsList_cb_name = _name;
48 void XonoticRegisteredSettingsList_getTooltip_cb(string _tooltip)
50 XonoticRegisteredSettingsList_cb_tooltip = _tooltip;
53 METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused))
55 if (!this.source) return;
56 if (!this.source.getEntry(this.source, i, XonoticRegisteredSettingsList_getNameIcon_cb)) return;
57 string name = XonoticRegisteredSettingsList_cb_name;
59 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
60 } else if (isFocused) {
61 this.focusedItemAlpha = getFadedAlpha(this.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
62 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, this.focusedItemAlpha);
64 string s = draw_TextShortenToWidth(strdecolorize(name), 1, 0, this.realFontSize);
65 draw_Text(this.realUpperMargin * eY + (0.5 * this.realFontSize.x) * eX, s, this.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
68 METHOD(XonoticRegisteredSettingsList, focusedItemChangeNotify, void(entity this))
70 if (this.focusedItem == -1 || !this.source)
75 if (!this.source.getEntryTooltip(this, this.focusedItem, XonoticRegisteredSettingsList_getTooltip_cb))
80 string theTooltip = XonoticRegisteredSettingsList_cb_tooltip;
82 setZonedTooltip(this, theTooltip, string_null);
87 METHOD(XonoticRegisteredSettingsList, refilter, void(entity this))
93 this.nItems = this.source.reload(this.source, this.stringFilter);
95 METHOD(XonoticRegisteredSettingsList, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
97 super.resizeNotify(this, relOrigin, relSize, absOrigin, absSize);
99 this.itemAbsSize = '0 0 0';
100 this.realFontSize_y = this.fontSize / (this.itemAbsSize_y = (absSize.y * this.itemHeight));
101 this.realFontSize_x = this.fontSize / (this.itemAbsSize_x = (absSize.x * (1 - this.controlWidth)));
102 this.realUpperMargin = 0.5 * (1 - this.realFontSize.y);
104 METHOD(XonoticRegisteredSettingsList, setSelected, void(entity this, int i))
106 super.setSelected(this, i);
107 this.onChange(this, this.onChangeEntity);
109 CONSTRUCTOR(XonoticRegisteredSettingsList, DataSource _source) {
110 CONSTRUCT(XonoticRegisteredSettingsList);
111 this.source = _source;
112 this.configureXonoticListBox(this);
115 ENDCLASS(XonoticRegisteredSettingsList)
118 CLASS(XonoticGameSettingsTab, XonoticTab)
119 ATTRIB(XonoticGameSettingsTab, intendedWidth, float, 0.9)
120 ATTRIB(XonoticGameSettingsTab, rows, float, 15.5)
121 ATTRIB(XonoticGameSettingsTab, columns, float, 6.5)
122 ATTRIB(XonoticGameSettingsTab, source, DataSource, NEW(SettingSource))
123 ATTRIB(XonoticGameSettingsTab, topicList, entity, NEW(XonoticRegisteredSettingsList, this.source))
124 ATTRIB(XonoticGameSettingsTab, currentPanel, entity, NEW(XonoticTab))
125 ATTRIB(XonoticGameSettingsTab, currentItem, entity, NULL)
126 METHOD(XonoticGameSettingsTab, topicChangeNotify, void(entity, entity this))
128 entity c = this.currentPanel;
129 entity removing = this.currentItem;
130 DataSource data = this.topicList.source;
131 entity adding = data.getEntry(data, this.topicList.selectedItem, func_null);
132 if (removing == adding) return;
134 this.currentItem = NULL;
135 c.removeItem(c, removing);
138 this.currentItem = adding;
139 adding.resizeNotify(adding, '0 0 0', c.size, '0 0 0', c.size);
140 c.addItem(c, adding, '0 0 0', '1 1 0', 1);
143 METHOD(XonoticGameSettingsTab, fill, void(entity this))
145 entity topics = this.topicList;
146 topics.onChange = this.topicChangeNotify;
147 topics.onChangeEntity = this;
150 col = 0, width = 1.5;
151 this.gotoRC(this, 0, col);
152 this.TD(this, this.rows, width, topics);
154 col += width, width = this.columns - col;
155 this.gotoRC(this, 0, col); this.setFirstColumn(this, this.currentColumn);
156 this.TD(this, this.rows, width, this.currentPanel);
158 this.topicChangeNotify(topics, this);
160 INIT(XonoticGameSettingsTab)
162 this.configureDialog(this);
164 ENDCLASS(XonoticGameSettingsTab)