]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/statslist.qc
Unnecessary newlines are unnecessary
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / statslist.qc
index c7b744a66710697c02782151b8607edda74d1ab8..3e94738a9ab500d89a162003be58ef67106e49f0 100644 (file)
@@ -1,32 +1,10 @@
-#ifdef INTERFACE
-CLASS(XonoticStatsList) EXTENDS(XonoticListBox)
-       METHOD(XonoticStatsList, configureXonoticStatsList, void(entity))
-       ATTRIB(XonoticStatsList, rowsPerItem, float, 1.4)
-       METHOD(XonoticStatsList, resizeNotify, void(entity, vector, vector, vector, vector))
-       METHOD(XonoticStatsList, drawListBoxItem, void(entity, float, vector, float))
-       METHOD(XonoticStatsList, getStats, void(entity))
-       METHOD(XonoticStatsList, doubleClickListBoxItem, void(entity, float, vector))
-       METHOD(XonoticStatsList, keyDown, float(entity, float, float, float))
-       METHOD(XonoticStatsList, destroy, void(entity))
-       METHOD(XonoticStatsList, showNotify, void(entity))
-
-       ATTRIB(XonoticStatsList, listStats, float, -1)
-       ATTRIB(XonoticStatsList, realFontSize, vector, '0 0 0')
-       ATTRIB(XonoticStatsList, realUpperMargin, float, 0)
-       ATTRIB(XonoticStatsList, columnNameOrigin, float, 0)
-       ATTRIB(XonoticStatsList, columnNameSize, float, 0)
-ENDCLASS(XonoticStatsList)
-
-entity statslist; // for reference elsewhere
-entity makeXonoticStatsList();
-#endif
-
-#ifdef IMPLEMENTATION
+#include "statslist.qh"
+#include <common/playerstats.qh>
 
 entity makeXonoticStatsList()
 {
        entity me;
-       me = spawnXonoticStatsList();
+       me = NEW(XonoticStatsList);
        me.configureXonoticStatsList(me);
        return me;
 }
@@ -73,7 +51,7 @@ string XonoticStatsList_convertDate(string input)
 
 void XonoticStatsList_getStats(entity me)
 {
-       dprint("XonoticStatsList_getStats() at time: ", ftos(time), "\n");
+       LOG_TRACE("XonoticStatsList_getStats() at time: ", ftos(time));
        // delete the old buffer if it exists
        if(me.listStats >= 0)
                buf_del(me.listStats);
@@ -168,13 +146,13 @@ void XonoticStatsList_getStats(entity me)
 
                if((order == -1) && (out_total_matches >= 0) && (out_total_wins >= 0))
                {
-                       bufstr_add(me.listStats, sprintf("003Matches: %d", out_total_matches), TRUE);
-                       
+                       bufstr_add(me.listStats, sprintf("003Matches: %d", out_total_matches), true);
+
                        if(out_total_matches > 0) // don't show extra info if there are no matches played
                        {
                                out_total_losses = max(0, (out_total_matches - out_total_wins));
-                               bufstr_add(me.listStats, sprintf("003Wins/Losses: %d/%d", out_total_wins, out_total_losses), TRUE);
-                               bufstr_add(me.listStats, sprintf("004Win_Percentage: %d%%", ((out_total_wins / out_total_matches) * 100)), TRUE);
+                               bufstr_add(me.listStats, sprintf("003Wins/Losses: %d/%d", out_total_wins, out_total_losses), true);
+                               bufstr_add(me.listStats, sprintf("004Win_Percentage: %d%%", ((out_total_wins / out_total_matches) * 100)), true);
                        }
 
                        out_total_matches = -1;
@@ -185,13 +163,13 @@ void XonoticStatsList_getStats(entity me)
 
                if((order == -1) && (out_total_kills >= 0) && (out_total_deaths >= 0))
                {
-                       bufstr_add(me.listStats, sprintf("005Kills/Deaths: %d/%d", out_total_kills, out_total_deaths), TRUE);
+                       bufstr_add(me.listStats, sprintf("005Kills/Deaths: %d/%d", out_total_kills, out_total_deaths), true);
 
-                       // if there are no deaths, just show kill count 
+                       // if there are no deaths, just show kill count
                        if(out_total_deaths > 0)
-                               bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", (out_total_kills / out_total_deaths)), TRUE);
+                               bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", (out_total_kills / out_total_deaths)), true);
                        else
-                               bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", out_total_kills), TRUE);
+                               bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", out_total_kills), true);
 
                        out_total_kills = -1;
                        out_total_deaths = -1;
@@ -206,10 +184,10 @@ void XonoticStatsList_getStats(entity me)
                else
                {
                        float dividerpos = strstrofs(e, "/", 0);
-                       
+
                        string gametype = substring(e, 0, dividerpos);
                        if(gametype == "overall") { continue; }
-                       
+
                        string event = substring(e, (dividerpos + 1), strlen(e) - (dividerpos + 1));
 
                        // if we are ranked, read these sets of possible options
@@ -245,7 +223,7 @@ void XonoticStatsList_getStats(entity me)
                                                data = sprintf("%d%%", stof(data));
                                                break;
                                        }
-                                       
+
                                        #if 0
                                        case "favorite-map":
                                        {
@@ -255,7 +233,7 @@ void XonoticStatsList_getStats(entity me)
                                                break;
                                        }
                                        #endif
-                                       
+
                                        default: continue; // nothing to see here
                                }
 
@@ -273,12 +251,12 @@ void XonoticStatsList_getStats(entity me)
                        else { continue; }
                }
 
-               bufstr_add(me.listStats, sprintf("%s%s %s", orderstr, outstr, data), TRUE);
+               bufstr_add(me.listStats, sprintf("%s%s %s", orderstr, outstr, data), true);
        }
 
        me.nItems = buf_getsize(me.listStats);
        if(me.nItems > 0)
-               buf_sort(me.listStats, 128, FALSE);
+               buf_sort(me.listStats, 128, false);
 }
 
 void XonoticStatsList_destroy(entity me)
@@ -292,30 +270,33 @@ void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize,
        me.itemAbsSize = '0 0 0';
        SUPER(XonoticStatsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
 
-       me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
-       me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
-       me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
+       me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
+       me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
+       me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
 
 #if 0
-       me.columnNameOrigin = me.realFontSize_x;
-       me.columnNameSize = 0.5 - me.realFontSize_x; // end halfway at maximum length
+       me.columnNameOrigin = me.realFontSize.x;
+       me.columnNameSize = 0.5 - me.realFontSize.x; // end halfway at maximum length
        me.columnDataOrigin = me.columnNameOrigin + me.columnNameSize;
-       me.columnDataSize = 1 - me.columnNameSize - me.realFontSize_x; // fill the rest of the control
+       me.columnDataSize = 1 - me.columnNameSize - me.realFontSize.x; // fill the rest of the control
 #else
-       me.columnNameOrigin = me.realFontSize_x;
-       me.columnNameSize = 1 - 2 * me.realFontSize_x;
+       me.columnNameOrigin = me.realFontSize.x;
+       me.columnNameSize = 1 - 2 * me.realFontSize.x;
 #endif
 }
 
-void XonoticStatsList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
+void XonoticStatsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
 {
-       if(isSelected)
-               draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
+       if(isFocused)
+       {
+               me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
+               draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
+       }
 
        string data = bufstr_get(me.listStats, i);
        string s = car(data);
        string d = cdr(data);
-       
+
        s = substring(s, 3, strlen(s) - 3);
        s = strreplace("_", " ", s);
        s = draw_TextShortenToWidth(s, 0.5 * me.columnNameSize, 0, me.realFontSize);
@@ -347,5 +328,3 @@ float XonoticStatsList_keyDown(entity me, float scan, float ascii, float shift)
                return SUPER(XonoticStatsList).keyDown(me, scan, ascii, shift);
        }
 }
-#endif
-