Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
dialog_multiplayer_create_mutators.qc
Go to the documentation of this file.
3
4#include "textbox.qh"
5#include "textlabel.qh"
6#include "button.qh"
7
8const string MUTATOR_ENABLED_ICON = "/gfx/scoreboard/player_ready";
9
10
11METHOD(MenuMutatorSource, getEntry, entity(entity me, int i, void(string name, string description) returns))
12{
14 {
15 if (returns)
16 returns((i == MENU_MUTATOR_HEADER_1 ? _("Weapon & item mutators:") : _("Gameplay mutators:")), "");
17 return NULL;
18 }
20 --i;
22 --i;
23 Lazy l = REGISTRY_GET(MenuMutators, i);
24 entity it = l.m_get();
25 if (returns)
26 returns(it.title, it.describe(it));
27 return it;
28}
29METHOD(MenuMutatorSource, getEntryOther, entity(entity me, int i, void(bool show_tick, bool disabled, string tree) returns))
30{
31 string tree_type;
32 if (i + 1 == REGISTRY_COUNT(MenuMutators) + 2 || i + 1 == MENU_MUTATOR_HEADER_2)
33 tree_type = "tree_elbow";
34 else if (i == MENU_MUTATOR_HEADER_1 + 1 || i == MENU_MUTATOR_HEADER_2 + 1)
35 tree_type = "tree_branch_start";
36 else
37 tree_type = "tree_branch";
38
40 --i;
42 --i;
43 Lazy l = REGISTRY_GET(MenuMutators, i);
44 entity it = l.m_get();
45 // canEnable with input true returns whether the mutator is enabled currently,
46 // input false returns whether the mutator can be enabled (all prerequisite cvars set correctly)
47 if (returns)
48 returns(it.canEnable(it, true), !it.canEnable(it, false), tree_type);
49 return it;
50}
51
52METHOD(MenuMutatorSource, reload, int(entity me, string filter))
53{
54 return REGISTRY_COUNT(MenuMutators) + 2; // two headers
55}
56
64
74
76{
78 me.configureXonoticListBox(me);
79 me.refilter(me);
80 me.setSelected(me, MENU_MUTATOR_HEADER_1 + 1);
81 return me;
82}
83
84METHOD(XonoticRegisteredMutatorsList, drawListBoxItem, void(entity me, int i, vector absSize, bool isSelected, bool isFocused))
85{
86 if (!me.source)
87 return;
88 me.source.getEntry(me.source, i, XonoticRegisteredMutatorsList_getNameDescription_cb);
89 if (XonoticRegisteredMutatorsList_cb_description != "") // no description means it's a header
90 {
91 if (isSelected)
92 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
93 else if (isFocused)
94 {
95 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
96 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
97 }
98 }
99
100 vector theColor;
101 float theAlpha, nameSize, nameOrigin;
103 {
104 theColor = SKINCOLOR_MUTATORS_TITLES;
105 theAlpha = SKINALPHA_MUTATORS_TITLES;
106 nameSize = 1;
107 nameOrigin = 0;
108 }
109 else
110 {
111 nameSize = me.columnNameSize;
112 nameOrigin = me.columnNameOrigin;
113 me.source.getEntryOther(me.source, i, XonoticRegisteredMutatorsList_getOther_cb);
114 if (XonoticRegisteredMutatorsList_cb_show_tick) // draw check if mutator is enabled
115 draw_Picture(me.columnIconOrigin * eX, MUTATOR_ENABLED_ICON, me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
116 if (XonoticRegisteredMutatorsList_cb_disabled) // draw text darker if mutator can't be enabled
117 {
118 theColor = SKINCOLOR_MUTATORS_DISABLED;
119 theAlpha = SKINALPHA_MUTATORS_DISABLED;
120 }
121 else
122 {
123 theColor = SKINCOLOR_MUTATORS_ENTRIES;
124 theAlpha = SKINALPHA_MUTATORS_ENTRIES;
125 }
126 // draw tree
127 draw_Picture('0 0 0', sprintf("/gfx/menu/%s/%s", cvar_string("menu_skin"), XonoticRegisteredMutatorsList_cb_tree),
128 me.columnTreeIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
129 }
130
131 string s = draw_TextShortenToWidth(strdecolorize(XonoticRegisteredMutatorsList_cb_name), nameSize, 0, me.realFontSize);
132 draw_Text(me.realUpperMargin * eY + nameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
133}
134
136{
137 if (!me.source)
138 {
139 me.nItems = 0;
140 return;
141 }
142 me.nItems = me.source.reload(me.source, "");
143}
144
145METHOD(XonoticRegisteredMutatorsList, resizeNotify, void(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
146{
147 SUPER(XonoticRegisteredMutatorsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
148
149 me.itemAbsSize = '0 0 0';
150 me.itemAbsSize.y = absSize.y * me.itemHeight;
151 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
152 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
153 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
154 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
155 me.columnIconSize = me.itemAbsSize.y / me.itemAbsSize.x;
156 me.columnIconOrigin = 1 - me.columnIconSize;
157 me.columnTreeIconSize = me.columnIconSize; // 1:1 aspect ratio
158 me.columnNameOrigin = me.columnTreeIconSize + 0.5 * me.realFontSize.x;
159 me.columnNameSize = me.columnIconOrigin - me.columnNameOrigin - me.realFontSize.x;
160}
161
163{
164 i = bound(0, i, me.nItems - 1);
165 me.source.getEntry(me.source, i, XonoticRegisteredMutatorsList_getNameDescription_cb);
166
167 // handling of "unselectable" items
168 // skip over unselectables if selected via keyboard, otherwise ignore mouse input
169 if (!me.pressed)
170 {
171 if (i < me.previouslySelected)
172 {
173 while ((i > 0) && XonoticRegisteredMutatorsList_cb_description == "")
174 me.source.getEntry(me.source, --i, XonoticRegisteredMutatorsList_getNameDescription_cb);
175 }
176 else
177 {
178 while ((i < me.nItems - 1) && XonoticRegisteredMutatorsList_cb_description == "")
179 me.source.getEntry(me.source, ++i, XonoticRegisteredMutatorsList_getNameDescription_cb);
180 }
181 }
183 i = me.previouslySelected;
184 else
185 me.previouslySelected = i;
186
187 SUPER(XonoticRegisteredMutatorsList).setSelected(me, i);
188 if (me.onChange)
189 me.onChange(me, me.onChangeEntity);
190}
191
192
194{
196 me.configureDialog(me);
197 return me;
198}
199
201{
202 entity s = NULL;
203 entity c = me.currentPanel;
204
205 entity removing = me.currentItem;
206 DataSource data = me.topicList.source;
207 entity adding = data.getEntry(data, me.topicList.selectedItem, XonoticRegisteredMutatorsList_getNameDescription_cb);
208 if (removing == adding)
209 return;
210 if (removing)
211 {
212 me.currentItem = NULL;
213 c.removeItem(c, removing);
214 }
215 if (adding)
216 {
217 me.currentItem = adding;
218 adding.resizeNotify(adding, '0 0 0', c.size, '0 0 0', c.size);
219 c.addItem(c, adding, '0 0 0', '1 1 0', 1);
220 if (s)
221 s.resizeNotify(s, '0 0 0', s.size, '0 0 0', s.size);
222 }
223
224 me.currentItem.showNotify(me.currentItem);
225 me.labelTitle.setText(me.labelTitle, XonoticRegisteredMutatorsList_cb_name);
226 me.descriptionLabel.setText(me.descriptionLabel, strcat("\n", XonoticRegisteredMutatorsList_cb_description, "\n"));
227}
228
230{
231 entity topics = me.topicList;
232 topics.onChange = me.topicChangeNotify;
233 topics.onChangeEntity = me;
234 entity e;
235
236 int col = 0;
237 int width = 1.75;
238 me.gotoRC(me, 0, col);
239 me.TD(me, me.rows - 1.5, width, topics);
240
241 col += width + 0.1;
242 width = me.columns - col;
243 me.gotoRC(me, 0, col); me.setFirstColumn(me, me.currentColumn);
244 me.TD(me, 1, width, me.labelTitle = makeXonoticHeaderLabel(""));
245 me.TR(me);
246 me.TD(me, me.rows - 6.5, width, me.currentPanel);
247 me.gotoRC(me, me.rows - 5.5, col);
248 me.TD(me, 4, width, e = makeXonoticTextBox());
249 e.align = 0.5;
250 e.allowColors = true;
251 me.descriptionLabel = e;
252
253 me.gotoRC(me, me.rows - 1, 0);
254 me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0'));
255 e.onClick = Dialog_Close;
256 e.onClickEntity = me;
257
258 me.topicChangeNotify(topics, me);
259}
260
262{
263 if (me.refilterEntity)
264 me.refilterEntity.refilter(me.refilterEntity);
265 SUPER(XonoticMutatorsDialog).close(me);
266}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
virtual void getEntry()
get entry i passing name and icon through returns if it is not null returns DataSource_false if out o...
Definition datasource.qh:11
Definition lazy.qh:7
virtual void getEntry()
get entry i passing name and icon through returns if it is not null returns DataSource_false if out o...
virtual void reload()
reload all entries matching filter returning how many matches were found
bool disabled
entity() spawn
void XonoticRegisteredMutatorsList_getOther_cb(bool _show_tick, bool _disabled, string _tree)
void XonoticMutatorsDialog_fill(entity me)
bool XonoticRegisteredMutatorsList_cb_show_tick
void XonoticMutatorsDialog_close(entity me)
string XonoticRegisteredMutatorsList_cb_tree
string XonoticRegisteredMutatorsList_cb_name
entity makeXonoticRegisteredMutatorsList()
const string MUTATOR_ENABLED_ICON
bool XonoticRegisteredMutatorsList_cb_disabled
void XonoticRegisteredMutatorsList_getNameDescription_cb(string _name, string _description)
entity makeXonoticMutatorsDialog()
string XonoticRegisteredMutatorsList_cb_description
const int MENU_MUTATOR_HEADER_2
const int MENU_MUTATOR_HEADER_1
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:378
void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:72
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:97
void Dialog_Close(entity button, entity me)
Definition dialog.qc:7
entity makeXonoticButton(string theText, vector theColor)
Definition button.qc:9
float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha)
Definition util.qc:816
string name
Definition menu.qh:30
float bound(float min, float value, float max)
const string cvar_string(string name)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NEW(cname,...)
Definition oo.qh:120
#define SUPER(cname)
Definition oo.qh:236
#define METHOD(cname, name, prototype)
Definition oo.qh:274
#define NULL
Definition post.qh:14
#define REGISTRY_COUNT(id)
Definition registry.qh:18
#define REGISTRY_GET(id, i)
Definition registry.qh:62
vector
Definition self.qh:96
entity makeXonoticTextBox()
Definition textbox.qc:4
entity makeXonoticHeaderLabel(string theText)
Definition textlabel.qc:9
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43