]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_settings_game.qc
Merge branch 'master' into TimePath/gamemode_composition
[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, getEntryTooltip, entity(entity this, int i, void(string theTooltip) returns))
16     {
17         Lazy l = Settings[i];
18         entity it = l.m_get();
19         if (returns) returns(it.tooltip);
20         return it;
21     }
22     METHOD(SettingSource, reload, int(entity this, string filter)) { return Settings_COUNT; }
23 ENDCLASS(SettingSource)
24
25 #include "listbox.qc"
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));
41
42         string XonoticRegisteredSettingsList_cb_name;
43         string XonoticRegisteredSettingsList_cb_tooltip;
44         void XonoticRegisteredSettingsList_getNameIcon_cb(string _name, string _icon)
45         {
46                 XonoticRegisteredSettingsList_cb_name = _name;
47         }
48         void XonoticRegisteredSettingsList_getTooltip_cb(string _tooltip)
49         {
50                 XonoticRegisteredSettingsList_cb_tooltip = _tooltip;
51         }
52
53         METHOD(XonoticRegisteredSettingsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused))
54         {
55                 if (!this.source) return;
56                 if (!this.source.getEntry(this.source, i, XonoticRegisteredSettingsList_getNameIcon_cb)) return;
57                 string name = XonoticRegisteredSettingsList_cb_name;
58                 if (isSelected) {
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);
63                 }
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);
66         }
67
68         METHOD(XonoticRegisteredSettingsList, focusedItemChangeNotify, void(entity this))
69         {
70                 if (this.focusedItem == -1 || !this.source)
71                 {
72                         clearTooltip(this);
73                         return;
74                 }
75                 if (!this.source.getEntryTooltip(this, this.focusedItem, XonoticRegisteredSettingsList_getTooltip_cb))
76                 {
77                         clearTooltip(this);
78                         return;
79                 }
80                 string theTooltip = XonoticRegisteredSettingsList_cb_tooltip;
81                 if(theTooltip != "")
82                         setZonedTooltip(this, theTooltip, string_null);
83                 else
84                         clearTooltip(this);
85         }
86
87         METHOD(XonoticRegisteredSettingsList, refilter, void(entity this))
88         {
89                 if (!this.source) {
90                         this.nItems = 0;
91                         return;
92                 }
93                 this.nItems = this.source.reload(this.source, this.stringFilter);
94         }
95         METHOD(XonoticRegisteredSettingsList, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
96         {
97                 super.resizeNotify(this, relOrigin, relSize, absOrigin, absSize);
98
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);
103         }
104         METHOD(XonoticRegisteredSettingsList, setSelected, void(entity this, int i))
105         {
106                 super.setSelected(this, i);
107                 this.onChange(this, this.onChangeEntity);
108         }
109     CONSTRUCTOR(XonoticRegisteredSettingsList, DataSource _source) {
110         CONSTRUCT(XonoticRegisteredSettingsList);
111         this.source = _source;
112         this.configureXonoticListBox(this);
113         this.refilter(this);
114     }
115 ENDCLASS(XonoticRegisteredSettingsList)
116
117 #include "tab.qc"
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))
127         {
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;
133                 if (removing) {
134                         this.currentItem = NULL;
135                         c.removeItem(c, removing);
136                 }
137                 if (adding) {
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);
141                 }
142         }
143         METHOD(XonoticGameSettingsTab, fill, void(entity this))
144         {
145                 entity topics = this.topicList;
146                         topics.onChange = this.topicChangeNotify;
147                         topics.onChangeEntity = this;
148
149                 int
150                 col = 0, width = 1.5;
151                 this.gotoRC(this, 0, col);
152                         this.TD(this, this.rows, width, topics);
153
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);
157
158                 this.topicChangeNotify(topics, this);
159         }
160     INIT(XonoticGameSettingsTab)
161     {
162                 this.configureDialog(this);
163         }
164 ENDCLASS(XonoticGameSettingsTab)
165 #endif