1 #include "../../common/counting.qh"
2 #include "../../common/playerstats.qh"
6 CLASS(XonoticStatsList, XonoticListBox)
7 METHOD(XonoticStatsList, configureXonoticStatsList, void(entity))
8 ATTRIB(XonoticStatsList, rowsPerItem, float, 1.4)
9 METHOD(XonoticStatsList, resizeNotify, void(entity, vector, vector, vector, vector))
10 METHOD(XonoticStatsList, drawListBoxItem, void(entity, float, vector, float))
11 METHOD(XonoticStatsList, getStats, void(entity))
12 METHOD(XonoticStatsList, doubleClickListBoxItem, void(entity, float, vector))
13 METHOD(XonoticStatsList, keyDown, float(entity, float, float, float))
14 METHOD(XonoticStatsList, destroy, void(entity))
15 METHOD(XonoticStatsList, showNotify, void(entity))
17 ATTRIB(XonoticStatsList, listStats, float, -1)
18 ATTRIB(XonoticStatsList, realFontSize, vector, '0 0 0')
19 ATTRIB(XonoticStatsList, realUpperMargin, float, 0)
20 ATTRIB(XonoticStatsList, columnNameOrigin, float, 0)
21 ATTRIB(XonoticStatsList, columnNameSize, float, 0)
22 ENDCLASS(XonoticStatsList)
24 #ifndef IMPLEMENTATION
26 entity statslist; // for reference elsewhere
28 entity makeXonoticStatsList();
33 entity makeXonoticStatsList()
36 me = NEW(XonoticStatsList);
37 me.configureXonoticStatsList(me);
41 void XonoticStatsList_configureXonoticStatsList(entity me)
43 me.configureXonoticListBox(me);
47 string XonoticStatsList_convertDate(string input)
51 if(strlen(input) != 10)
54 string monthname = "";
56 switch(stof(substring(input, 5, 2)))
58 case 1: monthname = _("January"); break;
59 case 2: monthname = _("February"); break;
60 case 3: monthname = _("March"); break;
61 case 4: monthname = _("April"); break;
62 case 5: monthname = _("May"); break;
63 case 6: monthname = _("June"); break;
64 case 7: monthname = _("July"); break;
65 case 8: monthname = _("August"); break;
66 case 9: monthname = _("September"); break;
67 case 10: monthname = _("October"); break;
68 case 11: monthname = _("November"); break;
69 case 12: monthname = _("December"); break;
70 default: return input; // failed, why?
76 count_ordinal(stof(substring(input, 8, 2))),
77 stof(substring(input, 0, 4))
81 void XonoticStatsList_getStats(entity me)
83 dprint("XonoticStatsList_getStats() at time: ", ftos(time), "\n");
84 // delete the old buffer if it exists
86 buf_del(me.listStats);
88 // create the new buffer if we have a stats buffer
90 me.listStats = buf_create();
92 // now confirmation, if we didn't create a buffer then just return now
100 string e = "", en = "", data = "";
102 string outstr = ""; // NOTE: out string MUST use underscores for spaces here, we'll replace them later
103 string orderstr = "";
105 float out_total_matches = -1;
106 float out_total_wins = -1;
107 float out_total_losses = -1;
109 float out_total_kills = -1;
110 float out_total_deaths = -1;
112 for(e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en)
117 data = db_get(PS_D_IN_DB, sprintf("#%s", e));
119 // non-gamemode specific stuff
122 case "overall/joined_dt":
125 outstr = _("Joined:");
126 data = XonoticStatsList_convertDate(car(data));
129 case "overall/last_seen_dt":
132 outstr = _("Last_Seen:");
133 data = XonoticStatsList_convertDate(car(data));
136 case "overall/alivetime":
139 outstr = _("Time_Played:");
140 data = process_time(3, stof(data));
143 case "overall/favorite-map":
146 outstr = _("Favorite_Map:");
150 case "overall/matches":
153 out_total_matches = stof(data);
159 out_total_wins = stof(data);
162 case "overall/total-kills":
165 out_total_kills = stof(data);
168 case "overall/total-deaths":
171 out_total_deaths = stof(data);
176 if((order == -1) && (out_total_matches >= 0) && (out_total_wins >= 0))
178 bufstr_add(me.listStats, sprintf("003Matches: %d", out_total_matches), true);
180 if(out_total_matches > 0) // don't show extra info if there are no matches played
182 out_total_losses = max(0, (out_total_matches - out_total_wins));
183 bufstr_add(me.listStats, sprintf("003Wins/Losses: %d/%d", out_total_wins, out_total_losses), true);
184 bufstr_add(me.listStats, sprintf("004Win_Percentage: %d%%", ((out_total_wins / out_total_matches) * 100)), true);
187 out_total_matches = -1;
189 out_total_losses = -1;
193 if((order == -1) && (out_total_kills >= 0) && (out_total_deaths >= 0))
195 bufstr_add(me.listStats, sprintf("005Kills/Deaths: %d/%d", out_total_kills, out_total_deaths), true);
197 // if there are no deaths, just show kill count
198 if(out_total_deaths > 0)
199 bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", (out_total_kills / out_total_deaths)), true);
201 bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", out_total_kills), true);
203 out_total_kills = -1;
204 out_total_deaths = -1;
208 // game mode specific stuff
211 orderstr = sprintf("%03d", order);
215 float dividerpos = strstrofs(e, "/", 0);
217 string gametype = substring(e, 0, dividerpos);
218 if(gametype == "overall") { continue; }
220 string event = substring(e, (dividerpos + 1), strlen(e) - (dividerpos + 1));
222 // if we are ranked, read these sets of possible options
223 if(stof(db_get(PS_D_IN_DB, sprintf("#%s/rank", gametype))))
230 outstr = sprintf(_("%s_Matches:"), strtoupper(gametype));
231 //data = sprintf(_("%d (unranked)"), data);
237 outstr = sprintf(_("%s_ELO:"), strtoupper(gametype));
238 data = sprintf("%d", stof(data));
244 outstr = sprintf(_("%s_Rank:"), strtoupper(gametype));
245 data = sprintf("%d", stof(data));
251 outstr = sprintf(_("%s_Percentile:"), strtoupper(gametype));
252 data = sprintf("%d%%", stof(data));
260 outstr = sprintf(_("%s_Favorite_Map:"), strtoupper(gametype));
261 //data = sprintf(_("%d (unranked)"), data);
266 default: continue; // nothing to see here
269 // now set up order for sorting later
270 orderstr = sprintf("%2.2s%d", gametype, order);
272 else if(event == "matches")
274 outstr = sprintf(_("%s_Matches:"), strtoupper(gametype));
275 data = sprintf(_("%d (unranked)"), stof(data));
277 // unranked game modes ALWAYS get put last
283 bufstr_add(me.listStats, sprintf("%s%s %s", orderstr, outstr, data), true);
286 me.nItems = buf_getsize(me.listStats);
288 buf_sort(me.listStats, 128, false);
291 void XonoticStatsList_destroy(entity me)
294 buf_del(me.listStats);
297 void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
299 me.itemAbsSize = '0 0 0';
300 SUPER(XonoticStatsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
302 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
303 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
304 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
307 me.columnNameOrigin = me.realFontSize.x;
308 me.columnNameSize = 0.5 - me.realFontSize.x; // end halfway at maximum length
309 me.columnDataOrigin = me.columnNameOrigin + me.columnNameSize;
310 me.columnDataSize = 1 - me.columnNameSize - me.realFontSize.x; // fill the rest of the control
312 me.columnNameOrigin = me.realFontSize.x;
313 me.columnNameSize = 1 - 2 * me.realFontSize.x;
317 void XonoticStatsList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
320 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
322 string data = bufstr_get(me.listStats, i);
323 string s = car(data);
324 string d = cdr(data);
326 s = substring(s, 3, strlen(s) - 3);
327 s = strreplace("_", " ", s);
328 s = draw_TextShortenToWidth(s, 0.5 * me.columnNameSize, 0, me.realFontSize);
329 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 1);
331 d = draw_TextShortenToWidth(d, me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize), 0, me.realFontSize);
332 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);
335 void XonoticStatsList_showNotify(entity me)
337 PlayerStats_PlayerDetail_CheckUpdate();
340 void XonoticStatsList_doubleClickListBoxItem(entity me, float i, vector where)
342 //DemoConfirm_ListClick_Check_Gamestatus(me);
345 float XonoticStatsList_keyDown(entity me, float scan, float ascii, float shift)
347 if(scan == K_ENTER || scan == K_KP_ENTER)
349 //DemoConfirm_ListClick_Check_Gamestatus(me);
354 return SUPER(XonoticStatsList).keyDown(me, scan, ascii, shift);