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()
{
// 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
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;
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))
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);
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)
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),
);
}
me.g_maplistCache = strzone(s);
+ //localcmd(sprintf("say maplistcache %s\n", me.g_maplistCache));
if(gt != me.lastGametype || f != me.lastFeatures)
{
me.lastGametype = gt;
{
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);
}