Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
statslist.qc File Reference
Include dependency graph for statslist.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

entity makeXonoticStatsList ()
void XonoticStatsList_configureXonoticStatsList (entity me)
string XonoticStatsList_convertDate (string input)
void XonoticStatsList_destroy (entity me)
void XonoticStatsList_doubleClickListBoxItem (entity me, float i, vector where)
void XonoticStatsList_drawListBoxItem (entity me, int i, vector absSize, bool isSelected, bool isFocused)
void XonoticStatsList_getStats (entity me)
float XonoticStatsList_keyDown (entity me, float scan, float ascii, float shift)
void XonoticStatsList_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void XonoticStatsList_showNotify (entity me)

Function Documentation

◆ makeXonoticStatsList()

entity makeXonoticStatsList ( )

Definition at line 7 of file statslist.qc.

8{
10 me.configureXonoticStatsList(me);
11 return me;
12}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define NEW(cname,...)
Definition oo.qh:120

References entity(), and NEW.

Referenced by XonoticProfileTab_fill().

◆ XonoticStatsList_configureXonoticStatsList()

void XonoticStatsList_configureXonoticStatsList ( entity me)

Definition at line 14 of file statslist.qc.

15{
16 me.configureXonoticListBox(me);
17 me.getStats(me);
18
19 for (int i = 0; i < GameType_GetTotalCount(); ++i)
20 if (SKINBOOL_STATSLIST_ICON_BLUR)
22 else
24}
float PRECACHE_PIC_MIPMAP
string draw_PreloadPictureWithFlags(string pic, float f)
Definition draw.qc:66
string draw_PreloadPicture(string pic)
Definition draw.qc:60
int GameType_GetTotalCount()
Definition util.qc:687
string GameType_GetIcon(int cnt)
Definition util.qc:703

References draw_PreloadPicture(), draw_PreloadPictureWithFlags(), entity(), GameType_GetIcon(), GameType_GetTotalCount(), and PRECACHE_PIC_MIPMAP.

◆ XonoticStatsList_convertDate()

string XonoticStatsList_convertDate ( string input)

Definition at line 26 of file statslist.qc.

27{
28 // 2013-12-21
29 // 0123456789
30 if (strlen(input) != 10)
31 return input;
32
33 string month_num = substring(input, 5, 2);
34 string monthname;
35 switch (stoi(month_num))
36 {
37 case 1: monthname = _("January"); break;
38 case 2: monthname = _("February"); break;
39 case 3: monthname = _("March"); break;
40 case 4: monthname = _("April"); break;
41 case 5: monthname = _("May"); break;
42 case 6: monthname = _("June"); break;
43 case 7: monthname = _("July"); break;
44 case 8: monthname = _("August"); break;
45 case 9: monthname = _("September"); break;
46 case 10: monthname = _("October"); break;
47 case 11: monthname = _("November"); break;
48 case 12: monthname = _("December"); break;
49 default: return input; // failed, why?
50 }
51
52 // without no-c-format this string looks messed up in Transifex since only %d is a valid c placeholder
53 // TRANSLATORS: %MMMM: Month name, %d: day number, %y: year.
54 // "%MM" (zero-padded month number), "%M" (month number), "%dd" (zero-padded day number), "%yy" (last two digits of the year) are supported too.
55 /* xgettext:no-c-format */
56 string date = CTX(_("DATE^%MMMM %d, %y"));
57
58 date = strreplace("%yy", substring(input, 2, 2), date);
59 date = strreplace("%y", substring(input, 0, 4), date);
60
61 string day_num = substring(input, 8, 2);
62 date = strreplace("%dd", day_num, date); // day number as-is (zero-padded)
63 date = strreplace("%d", itos(stoi(day_num)), date); // remove leading 0
64
65 date = strreplace("%MMMM", monthname, date);
66 date = strreplace("%MM", month_num, date); // month number as-is (zero-padded)
67 date = strreplace("%M", itos(stoi(month_num)), date); // remove leading 0
68 return strzone(date);
69}
#define strlen
ERASEABLE string CTX(string s)
Definition i18n.qh:46
#define stoi(s)
Definition int.qh:4
#define itos(i)
Definition int.qh:6
string substring(string s, float start, float length)
string strzone(string s)

References CTX(), itos, stoi, strlen, strzone(), and substring().

Referenced by XonoticStatsList_getStats().

◆ XonoticStatsList_destroy()

void XonoticStatsList_destroy ( entity me)

Definition at line 260 of file statslist.qc.

261{
262 if (me.nItems > 0)
263 buf_del(me.listStats);
264}

References entity().

◆ XonoticStatsList_doubleClickListBoxItem()

void XonoticStatsList_doubleClickListBoxItem ( entity me,
float i,
vector where )

Definition at line 337 of file statslist.qc.

338{
339 //DemoConfirm_ListClick_Check_Gamestatus(me);
340}

References entity(), and vector.

◆ XonoticStatsList_drawListBoxItem()

void XonoticStatsList_drawListBoxItem ( entity me,
int i,
vector absSize,
bool isSelected,
bool isFocused )

Definition at line 283 of file statslist.qc.

284{
285 if (isFocused)
286 {
287 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
288 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
289 }
290
291 string data = bufstr_get(me.listStats, i);
292 int ofs_data = strstrofs(data, "\n", 0);
293 int ofs_extra = strstrofs(data, "\n", ofs_data + 1);
294
295 string s = substring(data, 3, ofs_data - 3); // column name -- first 3 chars are orderstr, discard
296 string d = substring(data, ofs_data + 1, ofs_extra - (ofs_data + 1)); // data
297 string icon = substring(data, ofs_extra + 1, strlen(data) - (ofs_extra + 1)); // extra will be the gamtype icon path, or ""
298
299 if (icon != "")
300 draw_Picture(me.columnIconOrigin * eX, icon, me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
301
302 vector save_fontscale = draw_fontscale;
303 float f = draw_CondensedFontFactor(s, false, me.realFontSize, 0.5 * me.columnNameSize);
304 draw_fontscale.x *= f;
305 vector fs = me.realFontSize;
306 fs.x *= f;
307
308 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, fs, '1 1 1', SKINALPHA_TEXT, 0);
309
310 draw_fontscale = save_fontscale;
311
312 f = draw_CondensedFontFactor(d, false, me.realFontSize, 0.5 * me.columnNameSize);
313 draw_fontscale.x *= f;
314 fs = me.realFontSize;
315 fs.x *= f;
316
317 bool drawStar = (substring(d, -1, 1) == "*");
318 float starwidth = 0;
319 if (drawStar)
320 {
321 starwidth = draw_TextWidth("*", 0, fs);
322 d = substring(d, 0, -2); // remove asterisk
323 }
324 float textwidth = draw_TextWidth(d, 0, fs);
325 draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + me.columnNameSize - starwidth - textwidth) * eX, d, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0);
326 if (drawStar)
327 draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + me.columnNameSize - starwidth) * eX, "*", fs, SKINCOLOR_HEADER, SKINALPHA_HEADER, 0);
328
329 draw_fontscale = save_fontscale;
330}
#define strstrofs
void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:72
float draw_CondensedFontFactor(string theText, float ICanHasKallerz, vector SizeThxBye, float maxWidth)
Definition draw.qc:317
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:304
void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:97
#define draw_fontscale
Definition draw.qh:5
float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha)
Definition util.qc:824
vector
Definition self.qh:96
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43

References draw_CondensedFontFactor(), draw_Fill(), draw_fontscale, draw_Picture(), draw_Text(), draw_TextWidth(), entity(), eX, eY, getFadedAlpha(), strlen, strstrofs, substring(), and vector.

◆ XonoticStatsList_getStats()

void XonoticStatsList_getStats ( entity me)

Definition at line 71 of file statslist.qc.

72{
73 LOG_TRACE("XonoticStatsList_getStats() at time: ", ftos(time));
74 // delete the old buffer if it exists
75 if (me.listStats >= 0)
76 buf_del(me.listStats);
77
78 // create the new buffer if we have a stats buffer
79 if (PS_D_IN_DB >= 0)
80 me.listStats = buf_create();
81
82 bool have_unranked_stats = false;
83 if (me.controlledTextLabel)
84 me.controlledTextLabel.setText(me.controlledTextLabel, "");
85
86 // now confirmation, if we didn't create a buffer then just return now
87 if (me.listStats < 0)
88 {
89 me.nItems = 0;
90 return;
91 }
92
93 int order;
94 string data, extra;
95 string outstr; // NOTE: out string MUST use underscores for spaces here, we'll replace them later
96 string orderstr; // 3 chars
97 // Strings added with bufstr_add are in the format: {orderstr}{outstr}\n{data}\n{extra}
98
99 int out_total_matches = -1;
100 int out_total_wins = -1;
101 int out_total_losses = -1;
102 int out_total_kills = -1;
103 int out_total_deaths = -1;
104
105 for (string en, e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en)
106 {
107 order = 0;
108 outstr = "";
109 orderstr = "";
110 data = db_get(PS_D_IN_DB, strcat("#", e));
111 extra = "";
112
113 // non-gametype specific stuff
114 switch (e)
115 {
116 case "overall/joined_dt":
117 order = 1;
118 outstr = _("Joined:");
119 data = XonoticStatsList_convertDate(car(data));
120 break;
121 case "overall/last_seen_dt":
122 order = 1;
123 outstr = _("Last match:");
124 data = XonoticStatsList_convertDate(car(data));
125 break;
126 case "overall/alivetime":
127 order = 1;
128 outstr = _("Time played:");
129 data = process_time(3, stoi(data));
130 break;
131 case "overall/favorite-map":
132 order = 2;
133 outstr = _("Favorite map:");
134 data = car(data);
135 break;
136 case "overall/matches":
137 order = -1;
138 out_total_matches = stoi(data);
139 break;
140 case "overall/wins":
141 order = -1;
142 out_total_wins = stoi(data);
143 break;
144 case "overall/total-kills":
145 order = -1;
146 out_total_kills = stoi(data);
147 break;
148 case "overall/total-deaths":
149 order = -1;
150 out_total_deaths = stoi(data);
151 break;
152 }
153
154 if (order == -1 && out_total_matches >= 0 && out_total_wins >= 0)
155 {
156 bufstr_add(me.listStats, sprintf("003%s\n%d\n", _("Matches:"), out_total_matches), true);
157
158 if (out_total_matches > 0) // don't show extra info if there are no matches played
159 {
160 out_total_losses = max(0, out_total_matches - out_total_wins);
161 bufstr_add(me.listStats, sprintf("004%s\n%d/%d\n", _("Wins/Losses:"), out_total_wins, out_total_losses), true);
162 bufstr_add(me.listStats, sprintf("005%s\n%s\n", _("Win percentage:"), ftos_decimals_percentage(out_total_wins / out_total_matches, 0)), true);
163 }
164
165 out_total_matches = -1;
166 out_total_wins = -1;
167 out_total_losses = -1;
168 continue;
169 }
170
171 if (order == -1 && out_total_kills >= 0 && out_total_deaths >= 0)
172 {
173 bufstr_add(me.listStats, sprintf("006%s\n%d/%d\n", _("Kills/Deaths:"), out_total_kills, out_total_deaths), true);
174
175 // if there are no deaths, just show kill count
176 if (out_total_deaths == 0)
177 out_total_deaths = 1;
178
179 bufstr_add(me.listStats, sprintf("007%s\n%.2f\n", _("Kill-death ratio:"), out_total_kills / out_total_deaths), true);
180
181 out_total_kills = -1;
182 out_total_deaths = -1;
183 continue;
184 }
185
186 // gametype specific stuff
187 if (order > 0)
188 orderstr = sprintf("%03d", order);
189 else
190 {
191 int dividerpos = strstrofs(e, "/", 0);
192 string gametype = substring(e, 0, dividerpos);
193 if (gametype == "overall")
194 continue;
195
196 string event = substring(e, dividerpos + 1, strlen(e) - (dividerpos + 1));
197
198 // if we are ranked, read these sets of possible options
199 if (stof(db_get(PS_D_IN_DB, strcat("#", gametype, "/rank"))))
200 {
201 switch (event)
202 {
203 case "matches":
204 order = 1;
205 Gametype gt = MapInfo_Type_FromString(gametype, false, false);
206 outstr = (gt) ? MapInfo_Type_ToText(gt) : gametype;
207 int num = stoi(data);
208 data = count_matches(num);
210 break;
211 #if 0
212 case "skill":
213 order = 2;
214 outstr = _("Skill:");
215 data = sprintf("%d", stoi(data));
216 break;
217 case "favorite-map":
218 order = 3;
219 outstr = _("Favorite map:");
220 break;
221 #endif
222 default:
223 continue; // nothing to see here
224 }
225
226 outstr = sprintf(outstr, strtoupper(gametype));
227 // now set up order for sorting later
228 orderstr = sprintf("%2.2s%d", gametype, order);
229 }
230 else if (event == "matches")
231 {
232 Gametype gt = MapInfo_Type_FromString(gametype, false, false);
233 outstr = (gt) ? MapInfo_Type_ToText(gt) : gametype;
234 int num = stoi(data);
235 data = count_matches(num);
236 data = strcat(data, "*");
238
239 if (!have_unranked_stats && me.controlledTextLabel)
240 {
241 me.controlledTextLabel.setText(me.controlledTextLabel, _("* = unranked"));
242 have_unranked_stats = true;
243 }
244
245 // unranked gametypes ALWAYS get put last
246 orderstr = "zzz";
247 }
248 else
249 continue;
250 }
251
252 bufstr_add(me.listStats, strcat(orderstr, outstr, "\n", data, "\n", extra), true);
253 }
254
255 me.nItems = buf_getsize(me.listStats);
256 if (me.nItems > 0)
257 buf_sort(me.listStats, 128, false);
258}
entity gametype
Definition main.qh:43
#define count_matches(num)
Definition counting.qh:50
ERASEABLE string process_time(float outputtype, int seconds)
Definition counting.qh:183
float time
#define buf_create
#define LOG_TRACE(...)
Definition log.qh:74
ERASEABLE string db_get(int db, string key)
Definition map.qh:93
string MapInfo_Type_ToText(Gametype t)
Definition mapinfo.qc:660
Gametype MapInfo_Type_FromString(string gtype, bool dowarn, bool is_q3compat)
Definition mapinfo.qc:620
string GameType_GetIcon_FromString(string gtype)
Definition util.qc:709
float stof(string val,...)
string ftos(float f)
float max(float f,...)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
string PS_D_IN_EVL
int PS_D_IN_DB
string XonoticStatsList_convertDate(string input)
Definition statslist.qc:26
ERASEABLE string car(string s)
Returns first word.
Definition string.qh:258
ERASEABLE string ftos_decimals_percentage(float number, int decimals)
Converts a percentage to a string with the indicated number of decimals.
Definition string.qh:485

References buf_create, car(), count_matches, db_get(), entity(), ftos(), ftos_decimals_percentage(), gametype, GameType_GetIcon_FromString(), LOG_TRACE, MapInfo_Type_FromString(), MapInfo_Type_ToText(), max(), process_time(), PS_D_IN_DB, PS_D_IN_EVL, stof(), stoi, strcat(), strlen, strstrofs, substring(), time, and XonoticStatsList_convertDate().

◆ XonoticStatsList_keyDown()

float XonoticStatsList_keyDown ( entity me,
float scan,
float ascii,
float shift )

Definition at line 342 of file statslist.qc.

343{
344 if (scan == K_ENTER || scan == K_KP_ENTER)
345 {
346 //DemoConfirm_ListClick_Check_Gamestatus(me);
347 return 1;
348 }
349 return SUPER(XonoticStatsList).keyDown(me, scan, ascii, shift);
350}
float K_ENTER
Definition keycodes.qc:8
float K_KP_ENTER
Definition keycodes.qc:74
#define SUPER(cname)
Definition oo.qh:236

References entity(), K_ENTER, K_KP_ENTER, and SUPER.

◆ XonoticStatsList_resizeNotify()

void XonoticStatsList_resizeNotify ( entity me,
vector relOrigin,
vector relSize,
vector absOrigin,
vector absSize )

Definition at line 266 of file statslist.qc.

267{
268 me.itemAbsSize = '0 0 0';
269 SUPER(XonoticStatsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
270
271 me.itemAbsSize.y = absSize.y * me.itemHeight;
272 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
273 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
274 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
275 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
276
277 me.columnIconOrigin = 0.25 * me.realFontSize.x;
278 me.columnIconSize = me.itemAbsSize.y / me.itemAbsSize.x;
279 me.columnNameOrigin = me.columnIconOrigin * 2 + me.columnIconSize; // .columnIconOrigin padding on both sides
280 me.columnNameSize = 1 - me.columnIconOrigin - me.columnIconSize - me.realFontSize.x;
281}

References entity(), SUPER, and vector.

◆ XonoticStatsList_showNotify()

void XonoticStatsList_showNotify ( entity me)

Definition at line 332 of file statslist.qc.

333{
335}
void PlayerStats_PlayerDetail_CheckUpdate()

References entity(), and PlayerStats_PlayerDetail_CheckUpdate().