1 #include "../../common/counting.qh"
2 #include "../../common/playerstats.qh"
7 CLASS(XonoticStatsList, XonoticListBox)
8 METHOD(XonoticStatsList, configureXonoticStatsList, void(entity))
9 ATTRIB(XonoticStatsList, rowsPerItem, float, 1.4)
10 METHOD(XonoticStatsList, resizeNotify, void(entity, vector, vector, vector, vector))
11 METHOD(XonoticStatsList, drawListBoxItem, void(entity, int, vector, bool, bool))
12 METHOD(XonoticStatsList, getStats, void(entity))
13 METHOD(XonoticStatsList, doubleClickListBoxItem, void(entity, float, vector))
14 METHOD(XonoticStatsList, keyDown, float(entity, float, float, float))
15 METHOD(XonoticStatsList, destroy, void(entity))
16 METHOD(XonoticStatsList, showNotify, void(entity))
18 ATTRIB(XonoticStatsList, listStats, float, -1)
19 ATTRIB(XonoticStatsList, realFontSize, vector, '0 0 0')
20 ATTRIB(XonoticStatsList, realUpperMargin, float, 0)
21 ATTRIB(XonoticStatsList, columnNameOrigin, float, 0)
22 ATTRIB(XonoticStatsList, columnNameSize, float, 0)
23 ENDCLASS(XonoticStatsList)
25 #ifndef IMPLEMENTATION
27 entity statslist; // for reference elsewhere
29 entity makeXonoticStatsList();
34 entity makeXonoticStatsList()
37 me = NEW(XonoticStatsList);
38 me.configureXonoticStatsList(me);
42 void XonoticStatsList_configureXonoticStatsList(entity me)
44 me.configureXonoticListBox(me);
48 string XonoticStatsList_convertDate(string input)
52 if(strlen(input) != 10)
55 string monthname = "";
57 switch(stof(substring(input, 5, 2)))
59 case 1: monthname = _("January"); break;
60 case 2: monthname = _("February"); break;
61 case 3: monthname = _("March"); break;
62 case 4: monthname = _("April"); break;
63 case 5: monthname = _("May"); break;
64 case 6: monthname = _("June"); break;
65 case 7: monthname = _("July"); break;
66 case 8: monthname = _("August"); break;
67 case 9: monthname = _("September"); break;
68 case 10: monthname = _("October"); break;
69 case 11: monthname = _("November"); break;
70 case 12: monthname = _("December"); break;
71 default: return input; // failed, why?
77 count_ordinal(stof(substring(input, 8, 2))),
78 stof(substring(input, 0, 4))
82 void XonoticStatsList_getStats(entity me)
84 dprint("XonoticStatsList_getStats() at time: ", ftos(time), "\n");
85 // delete the old buffer if it exists
87 buf_del(me.listStats);
89 // create the new buffer if we have a stats buffer
91 me.listStats = buf_create();
93 // now confirmation, if we didn't create a buffer then just return now
101 string e = "", en = "", data = "";
103 string outstr = ""; // NOTE: out string MUST use underscores for spaces here, we'll replace them later
104 string orderstr = "";
106 float out_total_matches = -1;
107 float out_total_wins = -1;
108 float out_total_losses = -1;
110 float out_total_kills = -1;
111 float out_total_deaths = -1;
113 for(e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en)
118 data = db_get(PS_D_IN_DB, sprintf("#%s", e));
120 // non-gamemode specific stuff
123 case "overall/joined_dt":
126 outstr = _("Joined:");
127 data = XonoticStatsList_convertDate(car(data));
130 case "overall/last_seen_dt":
133 outstr = _("Last_Seen:");
134 data = XonoticStatsList_convertDate(car(data));
137 case "overall/alivetime":
140 outstr = _("Time_Played:");
141 data = process_time(3, stof(data));
144 case "overall/favorite-map":
147 outstr = _("Favorite_Map:");
151 case "overall/matches":
154 out_total_matches = stof(data);
160 out_total_wins = stof(data);
163 case "overall/total-kills":
166 out_total_kills = stof(data);
169 case "overall/total-deaths":
172 out_total_deaths = stof(data);
177 if((order == -1) && (out_total_matches >= 0) && (out_total_wins >= 0))
179 bufstr_add(me.listStats, sprintf("003Matches: %d", out_total_matches), true);
181 if(out_total_matches > 0) // don't show extra info if there are no matches played
183 out_total_losses = max(0, (out_total_matches - out_total_wins));
184 bufstr_add(me.listStats, sprintf("003Wins/Losses: %d/%d", out_total_wins, out_total_losses), true);
185 bufstr_add(me.listStats, sprintf("004Win_Percentage: %d%%", ((out_total_wins / out_total_matches) * 100)), true);
188 out_total_matches = -1;
190 out_total_losses = -1;
194 if((order == -1) && (out_total_kills >= 0) && (out_total_deaths >= 0))
196 bufstr_add(me.listStats, sprintf("005Kills/Deaths: %d/%d", out_total_kills, out_total_deaths), true);
198 // if there are no deaths, just show kill count
199 if(out_total_deaths > 0)
200 bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", (out_total_kills / out_total_deaths)), true);
202 bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", out_total_kills), true);
204 out_total_kills = -1;
205 out_total_deaths = -1;
209 // game mode specific stuff
212 orderstr = sprintf("%03d", order);
216 float dividerpos = strstrofs(e, "/", 0);
218 string gametype = substring(e, 0, dividerpos);
219 if(gametype == "overall") { continue; }
221 string event = substring(e, (dividerpos + 1), strlen(e) - (dividerpos + 1));
223 // if we are ranked, read these sets of possible options
224 if(stof(db_get(PS_D_IN_DB, sprintf("#%s/rank", gametype))))
231 outstr = sprintf(_("%s_Matches:"), strtoupper(gametype));
232 //data = sprintf(_("%d (unranked)"), data);
238 outstr = sprintf(_("%s_ELO:"), strtoupper(gametype));
239 data = sprintf("%d", stof(data));
245 outstr = sprintf(_("%s_Rank:"), strtoupper(gametype));
246 data = sprintf("%d", stof(data));
252 outstr = sprintf(_("%s_Percentile:"), strtoupper(gametype));
253 data = sprintf("%d%%", stof(data));
261 outstr = sprintf(_("%s_Favorite_Map:"), strtoupper(gametype));
262 //data = sprintf(_("%d (unranked)"), data);
267 default: continue; // nothing to see here
270 // now set up order for sorting later
271 orderstr = sprintf("%2.2s%d", gametype, order);
273 else if(event == "matches")
275 outstr = sprintf(_("%s_Matches:"), strtoupper(gametype));
276 data = sprintf(_("%d (unranked)"), stof(data));
278 // unranked game modes ALWAYS get put last
284 bufstr_add(me.listStats, sprintf("%s%s %s", orderstr, outstr, data), true);
287 me.nItems = buf_getsize(me.listStats);
289 buf_sort(me.listStats, 128, false);
292 void XonoticStatsList_destroy(entity me)
295 buf_del(me.listStats);
298 void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
300 me.itemAbsSize = '0 0 0';
301 SUPER(XonoticStatsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
303 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
304 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
305 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
308 me.columnNameOrigin = me.realFontSize.x;
309 me.columnNameSize = 0.5 - me.realFontSize.x; // end halfway at maximum length
310 me.columnDataOrigin = me.columnNameOrigin + me.columnNameSize;
311 me.columnDataSize = 1 - me.columnNameSize - me.realFontSize.x; // fill the rest of the control
313 me.columnNameOrigin = me.realFontSize.x;
314 me.columnNameSize = 1 - 2 * me.realFontSize.x;
318 void XonoticStatsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
321 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
324 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
325 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
328 string data = bufstr_get(me.listStats, i);
329 string s = car(data);
330 string d = cdr(data);
332 s = substring(s, 3, strlen(s) - 3);
333 s = strreplace("_", " ", s);
334 s = draw_TextShortenToWidth(s, 0.5 * me.columnNameSize, 0, me.realFontSize);
335 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 1);
337 d = draw_TextShortenToWidth(d, me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize), 0, me.realFontSize);
338 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);
341 void XonoticStatsList_showNotify(entity me)
343 PlayerStats_PlayerDetail_CheckUpdate();
346 void XonoticStatsList_doubleClickListBoxItem(entity me, float i, vector where)
348 //DemoConfirm_ListClick_Check_Gamestatus(me);
351 float XonoticStatsList_keyDown(entity me, float scan, float ascii, float shift)
353 if(scan == K_ENTER || scan == K_KP_ENTER)
355 //DemoConfirm_ListClick_Check_Gamestatus(me);
360 return SUPER(XonoticStatsList).keyDown(me, scan, ascii, shift);