Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
entries.qc
Go to the documentation of this file.
1#include "entries.qh"
2
6
8void XonoticEntryList_cb(string _name, string _icon)
9{
12}
13
15{
16 me.stringFilterBox = e;
17 return e;
18}
19
20void XonoticEntryList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
21{
22 if (!me.source)
23 return;
24 if (!me.source.getEntry(me.source, i, XonoticEntryList_cb))
25 return;
26
27 if (isSelected)
28 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
29 else if (isFocused)
30 {
31 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
32 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
33 }
34
35 vector sz;
37 sz = me.rowsPerItem * 0.5 * me.realFontSize.x * eX;
38 else
39 {
41 if (!sz)
42 sz = '1 1 0';
43 float szr = sz.x / sz.y;
44 //if (strstrofs(XonoticEntryList_cb_icon, "map", 0) >= 0)
45 //szr = 4 / 3;
46 const float asr = me.itemAbsSize.x / me.itemAbsSize.y;
47 sz.y = 1;
48 sz.x = szr / asr;
49 draw_Picture('0 0 0', XonoticEntryList_cb_icon, sz, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
50 sz.x += 0.5 * me.realFontSize.x;
51 }
52
53 // display maximum 2 lines, last potentially truncated, vertically centered
54 string s;
55 vector pos = me.realUpperMargin * eY + sz.x * eX;
56 const float maxWidth = 1 - sz.x - me.realFontSize.x;
58 s = getWrappedLine(maxWidth, me.realFontSize, draw_TextWidth_WithoutColors);
60 {
61 pos.y -= 0.5 * me.realFontSize.y;
62 draw_Text(pos, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, false);
63 s = draw_TextShortenToWidth(getWrappedLine_remaining, maxWidth, false, me.realFontSize);
64 pos.y += me.realFontSize.y;
65 }
66 draw_Text(pos, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, false);
67}
68
69METHOD(XonoticEntryList, keyDown, float(entity this, float scan, float ascii, float shift))
70{
71 if (this.nItems <= 0)
72 return SUPER(XonoticEntryList).keyDown(this, scan, ascii, shift);
73 else if ((ascii >= 32 || scan == K_BACKSPACE) && this.source.indexOf)
74 {
75 string save;
76 if (scan == K_BACKSPACE)
77 save = substring(this.typeToSearchString, 0, strlen(this.typeToSearchString) - 1);
78 else
79 {
80 const string ch = chr(ascii);
81 save = (time > this.typeToSearchTime) ? ch : strcat(this.typeToSearchString, ch);
82 }
83 if (this.typeToSearchString)
85 this.typeToSearchString = strzone(save);
86 this.typeToSearchTime = time + 0.5;
87 if (strlen(this.typeToSearchString))
88 {
89 const int idx = this.source.indexOf(this.source, this.typeToSearchString);
90 if (idx >= 0)
91 this.setSelected(this, idx);
92 }
93 }
94 else if ((shift & S_CTRL) && scan == 'f') // ctrl-f (as in "F"ind)
95 {
96 this.parent.setFocus(this.parent, this.stringFilterBox);
97 }
98 else if ((shift & S_CTRL) && scan == 'u') // ctrl-u (remove stringFilter line)
99 {
100 this.stringFilterBox.setText(this.stringFilterBox, "");
102 }
103 return SUPER(XonoticEntryList).keyDown(this, scan, ascii, shift);
104}
105
106float EntryList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift)
107{
108 // in this section, note that onChangeEntity has the ref to entryList
109 // we make use of that, instead of extending a class to add one more attrib
110 switch (scan)
111 {
112 case K_KP_ENTER:
113 case K_ENTER:
114 // move the focus to the entryList
115 me.onChangeEntity.parent.setFocus(me.onChangeEntity.parent, me.onChangeEntity);
116 return 1;
117 case K_KP_UPARROW:
118 case K_UPARROW:
119 case K_KP_DOWNARROW:
120 case K_DOWNARROW:
121 // pass the event to the entryList (to scroll up and down)
122 return me.onChangeEntity.keyDown(me.onChangeEntity, scan, ascii, shift);
123 }
124 return SUPER(XonoticInputBox).keyDown(me, scan, ascii, shift);
125}
126
128{
129 if (!me.source)
130 {
131 me.nItems = 0;
132 return;
133 }
134 string oldName;
135 if (me.selectedItem >= 0) // if negative we just switched source
136 {
137 me.source.getEntry(me.source, me.selectedItem, XonoticEntryList_cb);
138 oldName = XonoticEntryList_cb_name; // keep oldName selected if still present
139 }
140 else
141 oldName = "";
142
143 int newSelectedItem = 0;
144 me.nItems = me.source.reload(me.source, me.stringFilter);
145 for (int i = 0, n = me.nItems; i < n; ++i)
146 if (me.source.getEntry(me.source, i, XonoticEntryList_cb))
147 {
148 if (XonoticEntryList_cb_icon != "")
150 if (XonoticEntryList_cb_name == oldName)
151 newSelectedItem = i;
152 }
153 me.setSelected(me, newSelectedItem);
154}
155
157{
158 strfree(me.stringFilter);
159 if (box.text != "")
160 me.stringFilter = strzone(box.text);
161
162 me.refilter(me);
163}
164
165void XonoticEntryList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
166{
167 me.itemAbsSize = '0 0 0';
168 SUPER(XonoticEntryList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
169
170 me.itemAbsSize.y = absSize.y * me.itemHeight;
171 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
172 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
173 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
174 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
175}
176
178{
179 SUPER(XonoticEntryList).setSelected(me, i);
180 me.onChange(me, me.onChangeEntity);
181}
entity parent
Definition animhost.qc:7
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
int nItems
Definition listbox.qh:46
DataSource source
Definition entries.qh:26
XonoticEntryList(DataSource _source)
Definition entries.qh:28
entity stringFilterBox
Definition entries.qh:13
virtual void keyDown()
Definition entries.qc:69
string typeToSearchString
Definition entries.qh:15
virtual void setSelected()
float typeToSearchTime
Definition entries.qh:16
string getWrappedLine(float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:995
string getWrappedLine_remaining
Definition util.qh:147
float time
#define strlen
void XonoticEntryList_refilter(entity me)
Definition entries.qc:127
void EntryList_StringFilterBox_Change(entity box, entity me)
Definition entries.qc:156
string XonoticEntryList_cb_name
Definition entries.qc:7
entity EntryList_Set_StringFilterBox(entity me, entity e)
Definition entries.qc:14
string XonoticEntryList_cb_icon
Definition entries.qc:7
void XonoticEntryList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition entries.qc:20
void XonoticEntryList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition entries.qc:165
void XonoticEntryList_cb(string _name, string _icon)
Definition entries.qc:8
void XonoticEntryList_setSelected(entity me, int i)
Definition entries.qc:177
float EntryList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift)
Definition entries.qc:106
const int S_CTRL
Definition hud.qh:130
float K_UPARROW
Definition keycodes.qc:15
float K_BACKSPACE
Definition keycodes.qc:14
float K_DOWNARROW
Definition keycodes.qc:16
float K_KP_UPARROW
Definition keycodes.qc:64
float K_ENTER
Definition keycodes.qc:8
float K_KP_DOWNARROW
Definition keycodes.qc:53
float K_KP_ENTER
Definition keycodes.qc:74
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:377
float draw_TextWidth_WithoutColors(string s, vector theFontSize)
Definition draw.qc:396
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
vector draw_PictureSize(string pic)
Definition draw.qc:80
void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:97
string draw_PreloadPicture(string pic)
Definition draw.qc:60
float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha)
Definition util.qc:816
string chr(float ascii)
string substring(string s, float start, float length)
void strunzone(string s)
string strzone(string s)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define SUPER(cname)
Definition oo.qh:231
#define METHOD(cname, name, prototype)
Definition oo.qh:269
vector
Definition self.qh:92
#define strfree(this)
Definition string.qh:59
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44