]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_settings_game.qc
Allow to display tooltips in XonoticRegisteredSettingsList, add tooltip for "Models"
[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, getEntryTooltip, entity(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(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(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.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.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, 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))
126         {
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;
131                 if (removing) {
132                         this.currentItem = NULL;
133                         c.removeItem(c, removing);
134                 }
135                 if (adding) {
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);
139                 }
140         }
141         METHOD(XonoticGameSettingsTab, fill, void(entity this))
142         {
143                 entity topics = this.topicList;
144                         topics.onChange = this.topicChangeNotify;
145                         topics.onChangeEntity = this;
146
147                 int
148                 col = 0, width = 1.5;
149                 this.gotoRC(this, 0, col);
150                         this.TD(this, this.rows, width, topics);
151
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);
155
156                 this.topicChangeNotify(topics, this);
157         }
158     INIT(XonoticGameSettingsTab)
159     {
160                 this.configureDialog(this);
161         }
162 ENDCLASS(XonoticGameSettingsTab)
163 #endif