]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
added string filter to map list
authorBuddyFriendGuy <bfggeneral@gmail.com>
Tue, 7 Apr 2015 21:06:48 +0000 (17:06 -0400)
committerBuddyFriendGuy <bfggeneral@gmail.com>
Tue, 7 Apr 2015 21:06:48 +0000 (17:06 -0400)
qcsrc/common/mapinfo.qc
qcsrc/common/mapinfo.qh
qcsrc/menu/xonotic/dialog_multiplayer_create.qc
qcsrc/menu/xonotic/maplist.qc

index c3f15d1937e4963b06a1f6343c0d896c6ac44ce4..b77b4f676208b10959031ff1a4b6234c2e9718ee 100644 (file)
@@ -187,6 +187,47 @@ float MapInfo_FilterGametype(int pGametype, int pFeatures, int pFlagsRequired, i
 
        return 1;
 }
+float MapInfo_FilterGametypeAndString(int pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate, string fs)
+{
+       float i, j;
+       string title;
+       if (!_MapInfo_filtered_allocated)
+       {
+               _MapInfo_filtered_allocated = 1;
+               _MapInfo_filtered = buf_create();
+       }
+       MapInfo_count = 0;
+       for(i = 0, j = -1; i < _MapInfo_globcount; ++i)
+       {
+               if(MapInfo_Get_ByName(_MapInfo_GlobItem(i), 1, 0) == 2) // if we generated one... BAIL OUT and let the caller continue in the next frame.
+                       if(pAbortOnGenerate)
+                       {
+                               dprint("Autogenerated a .mapinfo, doing the rest later.\n");
+                               MapInfo_progress = i / _MapInfo_globcount;
+                               return 0;
+                       }
+               // prepare for keyword filter
+               //localcmd(sprintf("say filterString in mapinfo filter: %s\n", fs));
+               if (MapInfo_Map_title && strstrofs(MapInfo_Map_title, "<TITLE>", 0) == -1)
+                       title = MapInfo_Map_title;
+               else
+                       title = MapInfo_Map_bspname;
+               localcmd(sprintf("say map title: %s\n", title));
+               // keyword filter
+               if((strstrofs(strtolower(title), strtolower(fs), 0)) >= 0)
+               if((MapInfo_Map_supportedGametypes & pGametype) != 0)
+               if((MapInfo_Map_supportedFeatures & pFeatures) == pFeatures)
+               if((MapInfo_Map_flags & pFlagsForbidden) == 0)
+               if((MapInfo_Map_flags & pFlagsRequired) == pFlagsRequired)
+                       bufstr_set(_MapInfo_filtered, ++j, ftos(i));
+       }
+       MapInfo_count = j + 1;
+       MapInfo_ClearTemps();
+
+       // sometimes the glob isn't sorted nicely, so fix it here...
+       heapsort(MapInfo_count, _MapInfo_FilterList_swap, _MapInfo_FilterList_cmp, world);
+       return 1;
+}
 
 void MapInfo_Filter_Free()
 {
index 54255ec8d2aa153abfb6da7242d08b3635c40423..dc69a55689e6db71b9b26806aedc594e8ac33c11 100644 (file)
@@ -118,6 +118,7 @@ void MapInfo_Enumerate();
 // filter the info by game type mask (updates MapInfo_count)
 float MapInfo_progress;
 float MapInfo_FilterGametype(float gametype, float features, float pFlagsRequired, float pFlagsForbidden, float pAbortOnGenerate); // 1 on success, 0 on temporary failure (call it again next frame then; use MapInfo_progress as progress indicator)
+float MapInfo_FilterGametypeAndString(float gametype, float features, float pFlagsRequired, float pFlagsForbidden, float pAbortOnGenerate, string filterString); // 1 on success, 0 on temporary failure (call it again next frame then; use MapInfo_progress as progress indicator)
 int MapInfo_CurrentFeatures(); // retrieves currently required features from cvars
 int MapInfo_CurrentGametype(); // retrieves current gametype from cvars
 int MapInfo_ForbiddenFlags(); // retrieves current flags from cvars
index 4e76cbc6d3a5095560d41dd71da3bbb969476678..65858bbcf84208d0904d9e88d023ad096e8920b4 100644 (file)
@@ -146,10 +146,19 @@ void XonoticServerCreateTab_fill(entity me)
                me.mapListBox = makeXonoticMapList();
                me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Maplist")));
                        makeCallback(e, me.mapListBox, me.mapListBox.refilterCallback);
+
+       // TODO can somebody help check TD and gotoRC size/position parameters (till the end of this function)?
        me.TR(me);
-               me.TD(me, me.rows - 4, 3, me.mapListBox);
+               me.TD(me, me.rows - 6, 3, me.mapListBox);
+       me.gotoRC(me, me.rows - 3.7, 3.2);
+               /* map string filter */
+               me.TD(me, 1, 0.6, e = makeXonoticTextLabel(1, _("Filter:")));
+               me.TD(me, 1, 2.2, e = makeXonoticInputBox(0, string_null));
+                       e.onChange = MapList_Filter_Change;
+                       e.onChangeEntity = me.mapListBox;
+                       me.mapListBox.controlledTextbox = e;
+
        me.gotoRC(me, me.rows - 2.5, 3.2);
-               me.TDempty(me, 0.375);
                me.TD(me, 1, 1.125, e = makeXonoticButton(_("Select all"), '0 0 0'));
                        e.onClick = MapList_All;
                        e.onClickEntity = me.mapListBox;
index d88ad0e8e6747beddf8296226b33a7d03fad2289..7978e544357798bb9cfb3ad2c7f8b3a2de9938c2 100644 (file)
@@ -31,6 +31,8 @@ CLASS(XonoticMapList) EXTENDS(XonoticListBox)
        METHOD(XonoticMapList, g_maplistCacheToggle, void(entity, float))
        METHOD(XonoticMapList, g_maplistCacheQuery, float(entity, float))
 
+       ATTRIB(XonoticMapList, filterString, string, string_null)
+
        ATTRIB(XonoticMapList, startButton, entity, NULL)
 
        METHOD(XonoticMapList, loadCvars, void(entity))
@@ -43,6 +45,7 @@ CLASS(XonoticMapList) EXTENDS(XonoticListBox)
        ATTRIB(XonoticListBox, alphaBG, float, 0)
 ENDCLASS(XonoticMapList)
 entity makeXonoticMapList();
+void MapList_Filter_Change(entity box, entity me);
 void MapList_All(entity btn, entity me);
 void MapList_None(entity btn, entity me);
 void MapList_LoadMap(entity btn, entity me);
@@ -202,8 +205,13 @@ void XonoticMapList_refilter(entity me)
        float gt, f;
        gt = MapInfo_CurrentGametype();
        f = MapInfo_CurrentFeatures();
-       MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
+       // TODO consider consolidating the two functions
+       if (me.filterString)
+               MapInfo_FilterGametypeAndString(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0, me.filterString);
+       else
+               MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
        me.nItems = MapInfo_count;
+
        for(i = 0; i < MapInfo_count; ++i)
                draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
        if(me.g_maplistCache)
@@ -215,6 +223,7 @@ void XonoticMapList_refilter(entity me)
        for(i = 0; i < n; ++i)
        {
                j = MapInfo_FindName(argv(i));
+               //localcmd(sprintf("say %s\n", argv(i)));
                if(j >= 0)
                        s = strcat(
                                substring(s, 0, j),
@@ -223,6 +232,7 @@ void XonoticMapList_refilter(entity me)
                        );
        }
        me.g_maplistCache = strzone(s);
+       //localcmd(sprintf("say maplistcache %s\n", me.g_maplistCache));
        if(gt != me.lastGametype || f != me.lastFeatures)
        {
                me.lastGametype = gt;
@@ -235,15 +245,30 @@ void XonoticMapList_refilterCallback(entity me, entity cb)
 {
        me.refilter(me);
 }
+void MapList_Filter_Change(entity box, entity me)
+{
+       if(me.filterString)
+               strunzone(me.filterString);
+       if(box.text != "")
+               me.filterString = strzone(box.text);
+       else
+               me.filterString = string_null;
+       
+       me.refilter(me);
+}
 
 void MapList_All(entity btn, entity me)
 {
        float i;
        string s;
-       MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0); // all
+       if (me.filterString)
+               MapInfo_FilterGametypeAndString(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0, me.filterString);
+       else
+               MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0); // all
        s = "";
        for(i = 0; i < MapInfo_count; ++i)
                s = strcat(s, " ", MapInfo_BSPName_ByID(i));
+               
        cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
        me.refilter(me);
 }