1 #include "statslist.qh"
2 #include <common/playerstats.qh>
4 entity makeXonoticStatsList()
7 me = NEW(XonoticStatsList);
8 me.configureXonoticStatsList(me);
12 void XonoticStatsList_configureXonoticStatsList(entity me)
14 me.configureXonoticListBox(me);
18 string XonoticStatsList_convertDate(string input)
22 if(strlen(input) != 10)
25 string monthname = "";
27 switch(stof(substring(input, 5, 2)))
29 case 1: monthname = _("January"); break;
30 case 2: monthname = _("February"); break;
31 case 3: monthname = _("March"); break;
32 case 4: monthname = _("April"); break;
33 case 5: monthname = _("May"); break;
34 case 6: monthname = _("June"); break;
35 case 7: monthname = _("July"); break;
36 case 8: monthname = _("August"); break;
37 case 9: monthname = _("September"); break;
38 case 10: monthname = _("October"); break;
39 case 11: monthname = _("November"); break;
40 case 12: monthname = _("December"); break;
41 default: return input; // failed, why?
47 count_ordinal(stof(substring(input, 8, 2))),
48 stof(substring(input, 0, 4))
52 void XonoticStatsList_getStats(entity me)
54 LOG_TRACE("XonoticStatsList_getStats() at time: ", ftos(time));
55 // delete the old buffer if it exists
57 buf_del(me.listStats);
59 // create the new buffer if we have a stats buffer
61 me.listStats = buf_create();
63 // now confirmation, if we didn't create a buffer then just return now
71 string e = "", en = "", data = "";
73 string outstr = ""; // NOTE: out string MUST use underscores for spaces here, we'll replace them later
76 float out_total_matches = -1;
77 float out_total_wins = -1;
78 float out_total_losses = -1;
80 float out_total_kills = -1;
81 float out_total_deaths = -1;
83 for(e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en)
88 data = db_get(PS_D_IN_DB, sprintf("#%s", e));
90 // non-gamemode specific stuff
93 case "overall/joined_dt":
96 outstr = _("Joined:");
97 data = XonoticStatsList_convertDate(car(data));
100 case "overall/last_seen_dt":
103 outstr = _("Last match:");
104 data = XonoticStatsList_convertDate(car(data));
107 case "overall/alivetime":
110 outstr = _("Time played:");
111 data = process_time(3, stof(data));
114 case "overall/favorite-map":
117 outstr = _("Favorite map:");
121 case "overall/matches":
124 out_total_matches = stof(data);
130 out_total_wins = stof(data);
133 case "overall/total-kills":
136 out_total_kills = stof(data);
139 case "overall/total-deaths":
142 out_total_deaths = stof(data);
147 if((order == -1) && (out_total_matches >= 0) && (out_total_wins >= 0))
149 bufstr_add(me.listStats, sprintf("003%s\n%d", _("Matches:"), out_total_matches), true);
151 if(out_total_matches > 0) // don't show extra info if there are no matches played
153 out_total_losses = max(0, (out_total_matches - out_total_wins));
154 bufstr_add(me.listStats, sprintf("003%s\n%d/%d", _("Wins/Losses:"), out_total_wins, out_total_losses), true);
155 bufstr_add(me.listStats, sprintf("004%s\n%d%%", _("Win percentage:"), ((out_total_wins / out_total_matches) * 100)), true);
158 out_total_matches = -1;
160 out_total_losses = -1;
164 if((order == -1) && (out_total_kills >= 0) && (out_total_deaths >= 0))
166 bufstr_add(me.listStats, sprintf("005%s\n%d/%d", _("Kills/Deaths:"), out_total_kills, out_total_deaths), true);
168 // if there are no deaths, just show kill count
169 if(out_total_deaths == 0)
170 out_total_deaths = 1;
172 bufstr_add(me.listStats, sprintf("006%s\n%.2f", _("Kill ratio:"), (out_total_kills / out_total_deaths)), true);
174 out_total_kills = -1;
175 out_total_deaths = -1;
179 // game mode specific stuff
182 orderstr = sprintf("%03d", order);
186 float dividerpos = strstrofs(e, "/", 0);
188 string gametype = substring(e, 0, dividerpos);
189 if(gametype == "overall") { continue; }
191 string event = substring(e, (dividerpos + 1), strlen(e) - (dividerpos + 1));
193 // if we are ranked, read these sets of possible options
194 if(stof(db_get(PS_D_IN_DB, sprintf("#%s/rank", gametype))))
201 outstr = _("Matches:");
208 data = sprintf("%d", stof(data));
215 data = sprintf("%d", stof(data));
221 outstr = _("Percentile:");
222 data = sprintf("%d%%", stof(data));
230 outstr = _("Favorite map:");
235 default: continue; // nothing to see here
238 outstr = strcat(strtoupper(gametype), " ", outstr);
239 // now set up order for sorting later
240 orderstr = sprintf("%2.2s%d", gametype, order);
242 else if(event == "matches")
244 outstr = _("Matches:");
245 outstr = strcat(strtoupper(gametype), " ", outstr);
246 data = sprintf(_("%d (unranked)"), stof(data));
248 // unranked game modes ALWAYS get put last
254 bufstr_add(me.listStats, sprintf("%s%s\n%s", orderstr, outstr, data), true);
257 me.nItems = buf_getsize(me.listStats);
259 buf_sort(me.listStats, 128, false);
262 void XonoticStatsList_destroy(entity me)
265 buf_del(me.listStats);
268 void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
270 me.itemAbsSize = '0 0 0';
271 SUPER(XonoticStatsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
273 me.itemAbsSize.y = absSize.y * me.itemHeight;
274 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
275 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
276 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
277 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
280 me.columnNameOrigin = me.realFontSize.x;
281 me.columnNameSize = 0.5 - me.realFontSize.x; // end halfway at maximum length
282 me.columnDataOrigin = me.columnNameOrigin + me.columnNameSize;
283 me.columnDataSize = 1 - me.columnNameSize - me.realFontSize.x; // fill the rest of the control
285 me.columnNameOrigin = me.realFontSize.x;
286 me.columnNameSize = 1 - 2 * me.realFontSize.x;
290 void XonoticStatsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
294 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
295 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
298 string data = bufstr_get(me.listStats, i);
299 int ofs = strstrofs(data, "\n", 0);
301 string s = substring(data, 3, ofs - 3);
302 s = draw_TextShortenToWidth(s, 0.5 * me.columnNameSize, 0, me.realFontSize);
303 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 1);
305 string d = substring(data, ofs + 1, strlen(data) - (ofs + 1));
306 d = draw_TextShortenToWidth(d, me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize), 0, me.realFontSize);
307 draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 1 * (me.columnNameSize - draw_TextWidth(d, 0, me.realFontSize))) * eX, d, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 1);
310 void XonoticStatsList_showNotify(entity me)
312 PlayerStats_PlayerDetail_CheckUpdate();
315 void XonoticStatsList_doubleClickListBoxItem(entity me, float i, vector where)
317 //DemoConfirm_ListClick_Check_Gamestatus(me);
320 float XonoticStatsList_keyDown(entity me, float scan, float ascii, float shift)
322 if(scan == K_ENTER || scan == K_KP_ENTER)
324 //DemoConfirm_ListClick_Check_Gamestatus(me);
329 return SUPER(XonoticStatsList).keyDown(me, scan, ascii, shift);