1 #include "dialog_settings_game.qh"
2 #ifndef DIALOG_SETTINGS_GAME_H
3 #define DIALOG_SETTINGS_GAME_H
5 #include "../gamesettings.qh"
7 #include "datasource.qc"
8 CLASS(SettingSource, DataSource)
9 METHOD(SettingSource, getEntry, entity(entity this, int i, void(string name, string icon) returns))
11 Lazy l = Settings_from(i);
12 entity it = l.m_get();
13 if (returns) returns(it.title, string_null);
16 METHOD(SettingSource, getEntryTooltip, entity(entity this, int i, void(string theTooltip) returns))
18 Lazy l = Settings_from(i);
19 entity it = l.m_get();
20 if (returns) returns(it.tooltip);
23 METHOD(SettingSource, reload, int(entity this, string filter)) { return Settings_COUNT; }
24 ENDCLASS(SettingSource)
27 CLASS(XonoticRegisteredSettingsList, XonoticListBox)
28 ATTRIB(XonoticRegisteredSettingsList, alphaBG, float, 0)
29 ATTRIB(XonoticRegisteredSettingsList, itemAbsSize, vector, '0 0 0')
30 ATTRIB(XonoticRegisteredSettingsList, origin, vector, '0 0 0')
31 ATTRIB(XonoticRegisteredSettingsList, realFontSize, vector, '0 0 0')
32 ATTRIB(XonoticRegisteredSettingsList, realUpperMargin, float, 0)
33 ATTRIB(XonoticRegisteredSettingsList, rowsPerItem, float, 2)
34 ATTRIB(XonoticRegisteredSettingsList, stringFilterBox, entity, NULL)
35 ATTRIB(XonoticRegisteredSettingsList, stringFilter, string, string_null)
36 ATTRIB(XonoticRegisteredSettingsList, typeToSearchString, string, string_null)
37 ATTRIB(XonoticRegisteredSettingsList, typeToSearchTime, float, 0)
38 ATTRIB(XonoticRegisteredSettingsList, source, DataSource, NULL)
39 ATTRIB(XonoticRegisteredSettingsList, onChange, void(entity, entity), func_null)
40 ATTRIB(XonoticRegisteredSettingsList, onChangeEntity, entity, NULL)
41 METHOD(XonoticRegisteredSettingsList, focusedItemChangeNotify, void(entity));
43 string XonoticRegisteredSettingsList_cb_name;
44 string XonoticRegisteredSettingsList_cb_tooltip;
45 void XonoticRegisteredSettingsList_getNameIcon_cb(string _name, string _icon)
47 XonoticRegisteredSettingsList_cb_name = _name;
49 void XonoticRegisteredSettingsList_getTooltip_cb(string _tooltip)
51 XonoticRegisteredSettingsList_cb_tooltip = _tooltip;
54 METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused))
56 if (!this.source) return;
57 if (!this.source.getEntry(this.source, i, XonoticRegisteredSettingsList_getNameIcon_cb)) return;
58 string name = XonoticRegisteredSettingsList_cb_name;
60 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
61 } else if (isFocused) {
62 this.focusedItemAlpha = getFadedAlpha(this.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
63 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, this.focusedItemAlpha);
65 string s = draw_TextShortenToWidth(strdecolorize(name), 1, 0, this.realFontSize);
66 draw_Text(this.realUpperMargin * eY + (0.5 * this.realFontSize.x) * eX, s, this.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
69 METHOD(XonoticRegisteredSettingsList, focusedItemChangeNotify, void(entity this))
71 if (this.focusedItem == -1 || !this.source)
76 if (!this.source.getEntryTooltip(this, this.focusedItem, XonoticRegisteredSettingsList_getTooltip_cb))
81 string theTooltip = XonoticRegisteredSettingsList_cb_tooltip;
83 setZonedTooltip(this, theTooltip, string_null);
88 METHOD(XonoticRegisteredSettingsList, refilter, void(entity this))
94 this.nItems = this.source.reload(this.source, this.stringFilter);
96 METHOD(XonoticRegisteredSettingsList, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
98 SUPER(XonoticRegisteredSettingsList).resizeNotify(this, relOrigin, relSize, absOrigin, absSize);
100 this.itemAbsSize = '0 0 0';
101 this.realFontSize_y = this.fontSize / (this.itemAbsSize_y = (absSize.y * this.itemHeight));
102 this.realFontSize_x = this.fontSize / (this.itemAbsSize_x = (absSize.x * (1 - this.controlWidth)));
103 this.realUpperMargin = 0.5 * (1 - this.realFontSize.y);
105 METHOD(XonoticRegisteredSettingsList, setSelected, void(entity this, int i))
107 SUPER(XonoticRegisteredSettingsList).setSelected(this, i);
108 this.onChange(this, this.onChangeEntity);
110 CONSTRUCTOR(XonoticRegisteredSettingsList, DataSource _source) {
111 CONSTRUCT(XonoticRegisteredSettingsList);
112 this.source = _source;
113 this.configureXonoticListBox(this);
116 ENDCLASS(XonoticRegisteredSettingsList)
119 CLASS(XonoticGameSettingsTab, XonoticTab)
120 ATTRIB(XonoticGameSettingsTab, intendedWidth, float, 0.9)
121 ATTRIB(XonoticGameSettingsTab, rows, float, 15.5)
122 ATTRIB(XonoticGameSettingsTab, columns, float, 6.5)
123 ATTRIB(XonoticGameSettingsTab, source, DataSource, NEW(SettingSource))
124 ATTRIB(XonoticGameSettingsTab, topicList, entity, NEW(XonoticRegisteredSettingsList, this.source))
125 ATTRIB(XonoticGameSettingsTab, currentPanel, entity, NEW(XonoticTab))
126 ATTRIB(XonoticGameSettingsTab, currentItem, entity, NULL)
127 METHOD(XonoticGameSettingsTab, topicChangeNotify, void(entity, entity this))
129 entity c = this.currentPanel;
130 entity removing = this.currentItem;
131 DataSource data = this.topicList.source;
132 entity adding = data.getEntry(data, this.topicList.selectedItem, func_null);
133 if (removing == adding) return;
135 this.currentItem = NULL;
136 c.removeItem(c, removing);
139 this.currentItem = adding;
140 adding.resizeNotify(adding, '0 0 0', c.size, '0 0 0', c.size);
141 c.addItem(c, adding, '0 0 0', '1 1 0', 1);
144 METHOD(XonoticGameSettingsTab, fill, void(entity this))
146 entity topics = this.topicList;
147 topics.onChange = this.topicChangeNotify;
148 topics.onChangeEntity = this;
152 this.gotoRC(this, 0, col);
153 this.TD(this, this.rows, width, topics);
155 col += width, width = this.columns - col;
156 this.gotoRC(this, 0, col); this.setFirstColumn(this, this.currentColumn);
157 this.TD(this, this.rows, width, this.currentPanel);
159 this.topicChangeNotify(topics, this);
161 INIT(XonoticGameSettingsTab)
163 this.configureDialog(this);
165 ENDCLASS(XonoticGameSettingsTab)