2 CLASS(XonoticStatsList) EXTENDS(XonoticListBox)
3 METHOD(XonoticStatsList, configureXonoticStatsList, void(entity))
4 ATTRIB(XonoticStatsList, rowsPerItem, float, 1.4)
5 METHOD(XonoticStatsList, resizeNotify, void(entity, vector, vector, vector, vector))
6 METHOD(XonoticStatsList, drawListBoxItem, void(entity, float, vector, float))
7 METHOD(XonoticStatsList, getStats, void(entity))
8 METHOD(XonoticStatsList, clickListBoxItem, void(entity, float, vector))
9 METHOD(XonoticStatsList, keyDown, float(entity, float, float, float))
10 METHOD(XonoticStatsList, destroy, void(entity))
11 METHOD(XonoticStatsList, showNotify, void(entity))
13 ATTRIB(XonoticStatsList, listStats, float, -1)
14 ATTRIB(XonoticStatsList, realFontSize, vector, '0 0 0')
15 ATTRIB(XonoticStatsList, realUpperMargin, float, 0)
16 ATTRIB(XonoticStatsList, columnNameOrigin, float, 0)
17 ATTRIB(XonoticStatsList, columnNameSize, float, 0)
19 ATTRIB(XonoticStatsList, lastClickedDemo, float, -1)
20 ATTRIB(XonoticStatsList, lastClickedTime, float, 0)
21 ENDCLASS(XonoticStatsList)
23 entity statslist; // for reference elsewhere
24 entity makeXonoticStatsList();
29 entity makeXonoticStatsList()
32 me = spawnXonoticStatsList();
33 me.configureXonoticStatsList(me);
37 void XonoticStatsList_configureXonoticStatsList(entity me)
39 me.configureXonoticListBox(me);
43 string XonoticStatsList_convertDate(string input)
47 if(strlen(input) != 10)
50 string monthname = "";
52 switch(stof(substring(input, 5, 2)))
54 case 1: monthname = _("January"); break;
55 case 2: monthname = _("February"); break;
56 case 3: monthname = _("March"); break;
57 case 4: monthname = _("April"); break;
58 case 5: monthname = _("May"); break;
59 case 6: monthname = _("June"); break;
60 case 7: monthname = _("July"); break;
61 case 8: monthname = _("August"); break;
62 case 9: monthname = _("September"); break;
63 case 10: monthname = _("October"); break;
64 case 11: monthname = _("November"); break;
65 case 12: monthname = _("December"); break;
66 default: return input; // failed, why?
72 count_ordinal(stof(substring(input, 8, 2))),
73 stof(substring(input, 0, 4))
77 void XonoticStatsList_getStats(entity me)
79 print("XonoticStatsList_getStats() at time: ", ftos(time), "\n");
80 // delete the old buffer if it exists
82 buf_del(me.listStats);
84 // create the new buffer if we have a stats buffer
86 me.listStats = buf_create();
88 // now confirmation, if we didn't create a buffer then just return now
96 string e = "", en = "", data = "";
98 string outstr = ""; // NOTE: out string MUST use underscores for spaces here, we'll replace them later
101 float out_total_matches = -1;
102 float out_total_wins = -1;
103 float out_total_losses = -1;
105 float out_total_kills = -1;
106 float out_total_deaths = -1;
108 for(e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en)
113 data = db_get(PS_D_IN_DB, sprintf("#%s", e));
115 // non-gamemode specific stuff
118 case "overall/joined_dt":
121 outstr = _("Joined:");
122 data = XonoticStatsList_convertDate(car(data));
125 case "overall/last_seen_dt":
128 outstr = _("Last_Seen:");
129 data = XonoticStatsList_convertDate(car(data));
132 case "overall/alivetime":
135 outstr = _("Time_Played:");
136 data = process_time(3, stof(data));
139 case "overall/favorite-map":
142 outstr = _("Favorite_Map:");
146 case "overall/matches":
149 out_total_matches = stof(data);
155 out_total_wins = stof(data);
158 case "overall/total-kills":
161 out_total_kills = stof(data);
164 case "overall/total-deaths":
167 out_total_deaths = stof(data);
172 if((order == -1) && (out_total_matches >= 0) && (out_total_wins >= 0))
174 bufstr_add(me.listStats, sprintf("003Matches: %d", out_total_matches), TRUE);
176 if(out_total_matches > 0) // don't show extra info if there are no matches played
178 out_total_losses = max(0, (out_total_matches - out_total_wins));
179 bufstr_add(me.listStats, sprintf("003Wins/Losses: %d/%d", out_total_wins, out_total_losses), TRUE);
180 bufstr_add(me.listStats, sprintf("004Win_Percentage: %d%%", ((out_total_wins / out_total_matches) * 100)), TRUE);
183 out_total_matches = -1;
185 out_total_losses = -1;
189 if((order == -1) && (out_total_kills >= 0) && (out_total_deaths >= 0))
191 bufstr_add(me.listStats, sprintf("005Kills/Deaths: %d/%d", out_total_kills, out_total_deaths), TRUE);
193 // if there are no deaths, just show kill count
194 if(out_total_deaths > 0)
195 bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", (out_total_kills / out_total_deaths)), TRUE);
197 bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", out_total_kills), TRUE);
199 out_total_kills = -1;
200 out_total_deaths = -1;
204 // game mode specific stuff
207 orderstr = sprintf("%03d", order);
211 float dividerpos = strstrofs(e, "/", 0);
213 string gametype = substring(e, 0, dividerpos);
214 if(gametype == "overall") { continue; }
216 string event = substring(e, (dividerpos + 1), strlen(e) - (dividerpos + 1));
218 // if we are ranked, read these sets of possible options
219 if(stof(db_get(PS_D_IN_DB, sprintf("#%s/rank", gametype))))
226 outstr = sprintf(_("%s_Matches:"), strtoupper(gametype));
227 //data = sprintf(_("%d (unranked)"), data);
233 outstr = sprintf(_("%s_ELO:"), strtoupper(gametype));
234 data = sprintf("%d", stof(data));
240 outstr = sprintf(_("%s_Rank:"), strtoupper(gametype));
241 data = sprintf("%d", stof(data));
247 outstr = sprintf(_("%s_Percentile:"), strtoupper(gametype));
248 data = sprintf("%d%%", stof(data));
256 outstr = sprintf(_("%s_Favorite_Map:"), strtoupper(gametype));
257 //data = sprintf(_("%d (unranked)"), data);
262 default: continue; // nothing to see here
265 // now set up order for sorting later
266 orderstr = sprintf("%2.2s%d", gametype, order);
268 else if(event == "matches")
270 outstr = sprintf(_("%s_Matches:"), strtoupper(gametype));
271 data = sprintf(_("%d (unranked)"), stof(data));
273 // unranked game modes ALWAYS get put last
279 bufstr_add(me.listStats, sprintf("%s%s %s", orderstr, outstr, data), TRUE);
282 me.nItems = buf_getsize(me.listStats);
284 buf_sort(me.listStats, 128, FALSE);
287 void XonoticStatsList_destroy(entity me)
290 buf_del(me.listStats);
293 void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
295 me.itemAbsSize = '0 0 0';
296 SUPER(XonoticStatsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
298 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
299 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
300 me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
303 me.columnNameOrigin = me.realFontSize_x;
304 me.columnNameSize = 0.5 - me.realFontSize_x; // end halfway at maximum length
305 me.columnDataOrigin = me.columnNameOrigin + me.columnNameSize;
306 me.columnDataSize = 1 - me.columnNameSize - me.realFontSize_x; // fill the rest of the control
308 me.columnNameOrigin = me.realFontSize_x;
309 me.columnNameSize = 1 - 2 * me.realFontSize_x;
313 void XonoticStatsList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
316 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
318 string data = bufstr_get(me.listStats, i);
319 string s = car(data);
320 string d = cdr(data);
322 s = substring(s, 3, strlen(s) - 3);
323 s = strreplace("_", " ", s);
324 s = draw_TextShortenToWidth(s, 0.5 * me.columnNameSize, 0, me.realFontSize);
325 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 1);
327 d = draw_TextShortenToWidth(d, me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize), 0, me.realFontSize);
328 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);
331 void XonoticStatsList_showNotify(entity me)
333 PlayerStats_PlayerDetail_CheckUpdate();
336 void XonoticStatsList_clickListBoxItem(entity me, float i, vector where)
338 if(i == me.lastClickedDemo)
339 if(time < me.lastClickedTime + 0.3)
342 me.setSelected(me, i);
343 //DemoConfirm_ListClick_Check_Gamestatus(me);
345 me.lastClickedDemo = i;
346 me.lastClickedTime = time;
349 float XonoticStatsList_keyDown(entity me, float scan, float ascii, float shift)
351 if(scan == K_ENTER || scan == K_KP_ENTER)
353 //DemoConfirm_ListClick_Check_Gamestatus(me);
358 return SUPER(XonoticStatsList).keyDown(me, scan, ascii, shift);