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