]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/demolist.c
Merge branch 'Mario/weapons_new'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / demolist.c
index 9855a546a08b55825f031001a2a543a532f1a2a8..cf0e987c0a475dc34fbe920dfc9fa5cd9b6c3686 100644 (file)
@@ -6,7 +6,6 @@ CLASS(XonoticDemoList) EXTENDS(XonoticListBox)
        METHOD(XonoticDemoList, drawListBoxItem, void(entity, float, vector, float))
        METHOD(XonoticDemoList, getDemos, void(entity))
        METHOD(XonoticDemoList, startDemo, void(entity))
-       METHOD(XonoticDemoList, timeDemo, void(entity))
        METHOD(XonoticDemoList, demoName, string(entity, float))
        METHOD(XonoticDemoList, clickListBoxItem, void(entity, float, vector))
        METHOD(XonoticDemoList, keyDown, float(entity, float, float, float))
@@ -26,8 +25,9 @@ CLASS(XonoticDemoList) EXTENDS(XonoticListBox)
        ATTRIB(XonoticDemoList, filterString, string, string_null)
 ENDCLASS(XonoticDemoList)
 
-entity demolist; // for reference elsewhere
 entity makeXonoticDemoList();
+void StartDemo_Click(entity btn, entity me);
+void TimeDemo_Click(entity btn, entity me);
 void DemoList_Filter_Change(entity box, entity me);
 #endif
 
@@ -47,75 +47,40 @@ 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);
-
-       if(substring(s, 0, 1) == "/")
-               s = substring(s, 1, strlen(s) - 1);  // remove the first forward slash
-
+       s = search_getfilename(me.listDemo, i);
+       s = substring(s, 6, strlen(s) - 6 - 4);  // demos/, .dem
        return s;
 }
 
-// if subdir is TRUE look in subdirectories too (1 level)
-void getDemos_for_ext(entity me, string ext, float subdir)
+
+void XonoticDemoList_getDemos(entity me)
 {
        string s;
-       if (subdir)
-               s="demos/*/";
-       else
-               s="demos/";
+
        if(me.filterString)
-               s=strcat(s, me.filterString, ext);
+               //subdirectory in filterString allowed
+               s=strcat("demos/*", me.filterString, "*.dem");
        else
-               s=strcat(s, "*", ext);
-
-       float list, i, n;
-       list = search_begin(s, FALSE, TRUE);
-       if(list >= 0)
-       {
-               n = search_getsize(list);
-               for(i = 0; i < n; ++i)
-               {
-                       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('1 0 0'), 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);
-       }
+               s="demos/*.dem";
 
-       if (subdir)
-               getDemos_for_ext(me, ext, FALSE);
-}
+       //dprint("Search demos with the pattern ", s, "\n");
+       if(me.listDemo >= 0)
+               search_end(me.listDemo);
 
-void XonoticDemoList_getDemos(entity me)
-{
-       if (me.listDemo >= 0)
-               buf_del(me.listDemo);
-       me.listDemo = buf_create();
-       if (me.listDemo < 0)
-       {
-               me.nItems = 0;
-               return;
-       }
-       getDemos_for_ext(me, ".dem", TRUE);
-       me.nItems = buf_getsize(me.listDemo);
-       if(me.nItems > 0)
-               buf_sort(me.listDemo, 128, FALSE);
+       me.listDemo = search_begin(s, FALSE, TRUE);
+
+       if(me.listDemo < 0)
+               me.nItems=0;
+       else
+               me.nItems=search_getsize(me.listDemo);
 }
 
 void XonoticDemoList_destroy(entity me)
 {
-       if(me.nItems > 0)
-               buf_del(me.listDemo);
+       search_end(me.listDemo);
 }
 
 void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
@@ -139,7 +104,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, 1);
+       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, 0);
 }
 
 void XonoticDemoList_showNotify(entity me)
@@ -153,12 +118,7 @@ void DemoList_Filter_Change(entity box, entity me)
                strunzone(me.filterString);
 
        if(box.text != "")
-       {
-               if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
-                       me.filterString = strzone(box.text);
-               else
-                       me.filterString = strzone(strcat("*", box.text, "*"));
-       }
+               me.filterString = strzone(box.text);
        else
                me.filterString = string_null;
 
@@ -168,36 +128,20 @@ void DemoList_Filter_Change(entity box, entity me)
 void XonoticDemoList_startDemo(entity me)
 {
        string s;
-       s = me.demoName(me, me.selectedItem);
-       s = strdecolorize(s);
-
+       s = me.demoName(me,me.selectedItem);
        localcmd("playdemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
 }
 
-void XonoticDemoList_timeDemo(entity me)
+void StartDemo_Click(entity btn, entity me)
 {
-       string s;
-       s = me.demoName(me, me.selectedItem);
-       s = strdecolorize(s);
-
-       localcmd("timedemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
+       me.startDemo(me);
 }
 
-void DemoConfirm_ListClick_Check_Gamestatus(entity me)
+void TimeDemo_Click(entity btn, entity me)
 {
-       if not(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)) // we're not in a match, lets watch the demo
-       {
-               me.startDemo(me);
-       }
-       else // already in a match, player has to confirm
-       {
-               DialogOpenButton_Click_withCoords(
-                       me,
-                       main.demostartconfirmDialog,
-                       boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size),
-                       boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size)
-               );
-       }
+       string s;
+       s = me.demoName(me,me.selectedItem);
+       localcmd("timedemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
 }
 
 void XonoticDemoList_clickListBoxItem(entity me, float i, vector where)
@@ -207,7 +151,7 @@ void XonoticDemoList_clickListBoxItem(entity me, float i, vector where)
                {
                        // DOUBLE CLICK!
                        me.setSelected(me, i);
-                       DemoConfirm_ListClick_Check_Gamestatus(me);
+                       me.startDemo(me);
                }
        me.lastClickedDemo = i;
        me.lastClickedTime = time;
@@ -215,15 +159,12 @@ void XonoticDemoList_clickListBoxItem(entity me, float i, vector where)
 
 float XonoticDemoList_keyDown(entity me, float scan, float ascii, float shift)
 {
-       if(scan == K_ENTER || scan == K_KP_ENTER)
-       {
-               DemoConfirm_ListClick_Check_Gamestatus(me);
+       if(scan == K_ENTER || scan == K_KP_ENTER) {
+               me.startDemo(me);
                return 1;
        }
        else
-       {
                return SUPER(XonoticDemoList).keyDown(me, scan, ascii, shift);
-       }
 }
 #endif