]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_settings_game.qc
fc87261a538b736546e2481b29d992d6d3abc2eb
[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(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(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(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.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                 entity adding = this.topicList.source.getEntry(this.topicList.selectedItem, func_null);
96                 if (removing == adding) return;
97                 if (removing) {
98                         this.currentItem = NULL;
99                         c.removeItem(c, removing);
100                 }
101                 if (adding) {
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);
105                 }
106         }
107         METHOD(XonoticGameSettingsTab, fill, void(entity this))
108         {
109                 entity topics = this.topicList;
110                         topics.onChange = this.topicChangeNotify;
111                         topics.onChangeEntity = this;
112
113                 int
114                 col = 0, width = 1.5;
115                 this.gotoRC(this, 0, col);
116                         this.TD(this, this.rows, width, topics);
117
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);
121
122                 this.topicChangeNotify(topics, this);
123         }
124     INIT(XonoticGameSettingsTab)
125     {
126                 this.configureDialog(this);
127         }
128 ENDCLASS(XonoticGameSettingsTab)
129 #endif