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, getEntryTooltip, entity(int i, void(string theTooltip) returns))
18 entity it = l.m_get();
19 if (returns) returns(it.tooltip);
22 METHOD(SettingSource, reload, int(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(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.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.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, topicList, entity, NEW(XonoticRegisteredSettingsList, NEW(SettingSource)))
123 ATTRIB(XonoticGameSettingsTab, currentPanel, entity, NEW(XonoticTab))
124 ATTRIB(XonoticGameSettingsTab, currentItem, entity, NULL)
125 METHOD(XonoticGameSettingsTab, topicChangeNotify, void(entity, entity this))
127 entity c = this.currentPanel;
128 entity removing = this.currentItem;
129 entity adding = this.topicList.source.getEntry(this.topicList.selectedItem, func_null);
130 if (removing == adding) return;
132 this.currentItem = NULL;
133 c.removeItem(c, removing);
136 this.currentItem = adding;
137 adding.resizeNotify(adding, '0 0 0', c.size, '0 0 0', c.size);
138 c.addItem(c, adding, '0 0 0', '1 1 0', 1);
141 METHOD(XonoticGameSettingsTab, fill, void(entity this))
143 entity topics = this.topicList;
144 topics.onChange = this.topicChangeNotify;
145 topics.onChangeEntity = this;
148 col = 0, width = 1.5;
149 this.gotoRC(this, 0, col);
150 this.TD(this, this.rows, width, topics);
152 col += width, width = this.columns - col;
153 this.gotoRC(this, 0, col); this.setFirstColumn(this, this.currentColumn);
154 this.TD(this, this.rows, width, this.currentPanel);
156 this.topicChangeNotify(topics, this);
158 INIT(XonoticGameSettingsTab)
160 this.configureDialog(this);
162 ENDCLASS(XonoticGameSettingsTab)