]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_settings_game.qc
DataSource: pass context
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_settings_game.qc
1 #ifndef DIALOG_SETTINGS_GAME_H
2 #define DIALOG_SETTINGS_GAME_H
3
4 #include "../gamesettings.qh"
5
6 #include "datasource.qc"
7 CLASS(SettingSource, DataSource)
8     METHOD(SettingSource, getEntry, entity(entity this, int i, void(string name, string icon) returns))
9     {
10         Lazy l = SETTINGS[i];
11         entity it = l.m_get();
12         if (returns) returns(it.title, string_null);
13         return it;
14     }
15     METHOD(SettingSource, reload, int(entity this, string filter)) { return SETTINGS_COUNT; }
16 ENDCLASS(SettingSource)
17
18 #include "listbox.qc"
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)
35         {
36                 XonoticRegisteredSettingsList_cb_name = _name;
37         }
38         METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused))
39         {
40                 if (!this.source) return;
41                 if (!this.source.getEntry(this.source, i, XonoticRegisteredSettingsList_cb)) return;
42                 string name = XonoticRegisteredSettingsList_cb_name;
43                 if (isSelected) {
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);
48                 }
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);
51         }
52         METHOD(XonoticRegisteredSettingsList, refilter, void(entity this))
53         {
54                 if (!this.source) {
55                         this.nItems = 0;
56                         return;
57                 }
58                 this.nItems = this.source.reload(this.source, this.stringFilter);
59         }
60         METHOD(XonoticRegisteredSettingsList, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
61         {
62                 super.resizeNotify(this, relOrigin, relSize, absOrigin, absSize);
63
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);
68         }
69         METHOD(XonoticRegisteredSettingsList, setSelected, void(entity this, int i))
70         {
71                 super.setSelected(this, i);
72                 this.onChange(this, this.onChangeEntity);
73         }
74     CONSTRUCTOR(XonoticRegisteredSettingsList, DataSource _source) {
75         CONSTRUCT(XonoticRegisteredSettingsList);
76         this.source = _source;
77         this.configureXonoticListBox(this);
78         this.refilter(this);
79     }
80 ENDCLASS(XonoticRegisteredSettingsList)
81
82 #include "tab.qc"
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))
92         {
93                 entity c = this.currentPanel;
94                 entity removing = this.currentItem;
95                 DataSource data = this.topicList.source;
96                 entity adding = data.getEntry(data, this.topicList.selectedItem, func_null);
97                 if (removing == adding) return;
98                 if (removing) {
99                         this.currentItem = NULL;
100                         c.removeItem(c, removing);
101                 }
102                 if (adding) {
103                         this.currentItem = adding;
104                         adding.resizeNotify(adding, '0 0 0', c.size, '0 0 0', c.size);
105                         c.addItem(c, adding, '0 0 0', '1 1 0', 1);
106                 }
107         }
108         METHOD(XonoticGameSettingsTab, fill, void(entity this))
109         {
110                 entity topics = this.topicList;
111                         topics.onChange = this.topicChangeNotify;
112                         topics.onChangeEntity = this;
113
114                 int
115                 col = 0, width = 1.5;
116                 this.gotoRC(this, 0, col);
117                         this.TD(this, this.rows, width, topics);
118
119                 col += width, width = this.columns - col;
120                 this.gotoRC(this, 0, col); this.setFirstColumn(this, this.currentColumn);
121                         this.TD(this, this.rows, width, this.currentPanel);
122
123                 this.topicChangeNotify(topics, this);
124         }
125     INIT(XonoticGameSettingsTab)
126     {
127                 this.configureDialog(this);
128         }
129 ENDCLASS(XonoticGameSettingsTab)
130 #endif