From: BuddyFriendGuy Date: Tue, 7 Apr 2015 21:06:48 +0000 (-0400) Subject: added string filter to map list X-Git-Tag: xonotic-v0.8.1~23^2~18 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=021c2ed0ea0525f0d60f6b3b02bcd7b5b704109d;p=xonotic%2Fxonotic-data.pk3dir.git added string filter to map list --- diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc index c3f15d193..b77b4f676 100644 --- a/qcsrc/common/mapinfo.qc +++ b/qcsrc/common/mapinfo.qc @@ -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, "", 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() { diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh index 54255ec8d..dc69a5568 100644 --- a/qcsrc/common/mapinfo.qh +++ b/qcsrc/common/mapinfo.qh @@ -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 diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create.qc index 4e76cbc6d..65858bbcf 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create.qc @@ -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; diff --git a/qcsrc/menu/xonotic/maplist.qc b/qcsrc/menu/xonotic/maplist.qc index d88ad0e8e..7978e5443 100644 --- a/qcsrc/menu/xonotic/maplist.qc +++ b/qcsrc/menu/xonotic/maplist.qc @@ -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); }