]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/demolist.c
Merge branch 'sev/scoreboard_skin' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / demolist.c
index 1b3b5c140fac91e2c8586549dcc36dd51b60d2e4..f2e209ca4d2b38190cdc64ec1f382f4756e4569d 100644 (file)
@@ -28,6 +28,7 @@ ENDCLASS(XonoticDemoList)
 
 entity demolist; // for reference elsewhere
 entity makeXonoticDemoList();
+void DemoList_Refresh_Click(entity btn, entity me);
 void DemoList_Filter_Change(entity box, entity me);
 #endif
 
@@ -47,11 +48,14 @@ void XonoticDemoList_configureXonoticDemoList(entity me)
        me.getDemos(me);
 }
 
-string XonoticDemoList_demoName(entity me, float i )
+string XonoticDemoList_demoName(entity me, float i)
 {
        string s;
        s = bufstr_get(me.listDemo, i);
-       s = substring(s, 6, strlen(s) - 6 - 4);  // demos/, .dem
+
+       if(substring(s, 0, 1) == "/")
+               s = substring(s, 1, strlen(s) - 1);  // remove the first forward slash
+
        return s;
 }
 
@@ -75,8 +79,16 @@ void getDemos_for_ext(entity me, string ext, float subdir)
                n = search_getsize(list);
                for(i = 0; i < n; ++i)
                {
-                       if(subdir) { bufstr_add(me.listDemo, sprintf("\{3}%s", search_getfilename(list, i)), TRUE); }
-                       else { bufstr_add(me.listDemo, search_getfilename(list, i), TRUE); }
+                       s = search_getfilename(list, i); // get initial full file name
+                       s = substring(s, 6, (strlen(s) - 6 - 4)); // remove "demos/" prefix and ".dem" suffix
+                       s = strdecolorize(s); // remove any pre-existing colors
+                       if(subdir)
+                       {
+                               s = strreplace("/", "^7/", s); // clear colors at the forward slash
+                               s = strcat("/", rgb_to_hexcolor(SKINCOLOR_DEMOLIST_SUBDIR), s); // add a forward slash for sorting, then color
+                               bufstr_add(me.listDemo, s, TRUE);
+                       }
+                       else { bufstr_add(me.listDemo, s, TRUE); }
                }
                search_end(list);
        }
@@ -128,7 +140,7 @@ void XonoticDemoList_drawListBoxItem(entity me, float i, vector absSize, float i
 
        s = me.demoName(me,i);
        s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
-       draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
+       draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 1);
 }
 
 void XonoticDemoList_showNotify(entity me)
@@ -136,6 +148,12 @@ void XonoticDemoList_showNotify(entity me)
        me.getDemos(me);
 }
 
+void DemoList_Refresh_Click(entity btn, entity me)
+{
+       me.getDemos(me);
+       me.setSelected(me, 0); //always select the first element after a list update
+}
+
 void DemoList_Filter_Change(entity box, entity me)
 {
        if(me.filterString)
@@ -158,6 +176,8 @@ void XonoticDemoList_startDemo(entity me)
 {
        string s;
        s = me.demoName(me, me.selectedItem);
+       s = strdecolorize(s);
+
        localcmd("playdemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
 }
 
@@ -165,12 +185,14 @@ void XonoticDemoList_timeDemo(entity me)
 {
        string s;
        s = me.demoName(me, me.selectedItem);
+       s = strdecolorize(s);
+
        localcmd("timedemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
 }
 
 void DemoConfirm_ListClick_Check_Gamestatus(entity me)
 {
-       if not(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)) // we're not in a match, lets watch the demo
+       if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) // we're not in a match, lets watch the demo
        {
                me.startDemo(me);
        }