5 CLASS(XonoticMapList, XonoticListBox)
6 METHOD(XonoticMapList, configureXonoticMapList, void(entity));
7 ATTRIB(XonoticMapList, rowsPerItem, float, 4)
8 METHOD(XonoticMapList, draw, void(entity));
9 METHOD(XonoticMapList, drawListBoxItem, void(entity, int, vector, bool, bool));
10 METHOD(XonoticMapList, clickListBoxItem, void(entity, float, vector));
11 METHOD(XonoticMapList, doubleClickListBoxItem, void(entity, float, vector));
12 METHOD(XonoticMapList, resizeNotify, void(entity, vector, vector, vector, vector));
13 METHOD(XonoticMapList, refilter, void(entity));
14 METHOD(XonoticMapList, refilterCallback, void(entity, entity));
15 METHOD(XonoticMapList, keyDown, float(entity, float, float, float));
17 ATTRIB(XonoticMapList, realFontSize, vector, '0 0 0')
18 ATTRIB(XonoticMapList, columnPreviewOrigin, float, 0)
19 ATTRIB(XonoticMapList, columnPreviewSize, float, 0)
20 ATTRIB(XonoticMapList, columnNameOrigin, float, 0)
21 ATTRIB(XonoticMapList, columnNameSize, float, 0)
22 ATTRIB(XonoticMapList, checkMarkOrigin, vector, '0 0 0')
23 ATTRIB(XonoticMapList, checkMarkSize, vector, '0 0 0')
24 ATTRIB(XonoticMapList, realUpperMargin1, float, 0)
25 ATTRIB(XonoticMapList, realUpperMargin2, float, 0)
27 ATTRIB(XonoticMapList, lastGametype, float, 0)
28 ATTRIB(XonoticMapList, lastFeatures, float, 0)
30 ATTRIB(XonoticMapList, origin, vector, '0 0 0')
31 ATTRIB(XonoticMapList, itemAbsSize, vector, '0 0 0')
33 ATTRIB(XonoticMapList, g_maplistCache, string, string_null)
34 METHOD(XonoticMapList, g_maplistCacheToggle, void(entity, float));
35 METHOD(XonoticMapList, g_maplistCacheQuery, float(entity, float));
37 ATTRIB(XonoticMapList, stringFilter, string, string_null)
38 ATTRIB(XonoticMapList, stringFilterBox, entity, NULL)
40 ATTRIB(XonoticMapList, startButton, entity, NULL)
42 METHOD(XonoticMapList, loadCvars, void(entity));
44 ATTRIB(XonoticMapList, typeToSearchString, string, string_null)
45 ATTRIB(XonoticMapList, typeToSearchTime, float, 0)
47 METHOD(XonoticMapList, destroy, void(entity));
49 ATTRIB(XonoticMapList, alphaBG, float, 0)
50 ENDCLASS(XonoticMapList)
51 entity makeXonoticMapList();
52 void MapList_StringFilterBox_Change(entity box, entity me);
53 float MapList_StringFilterBox_keyDown(entity me, float key, float ascii, float shift);
54 void MapList_Add_Shown(entity btn, entity me);
55 void MapList_Remove_Shown(entity btn, entity me);
56 void MapList_Add_All(entity btn, entity me);
57 void MapList_Remove_All(entity btn, entity me);
58 void MapList_LoadMap(entity btn, entity me);
62 void XonoticMapList_destroy(entity me)
67 entity makeXonoticMapList()
70 me = NEW(XonoticMapList);
71 me.configureXonoticMapList(me);
75 entity MapList_Set_String_Filter_Box(entity me, entity e)
77 me.stringFilterBox = e;
81 void XonoticMapList_configureXonoticMapList(entity me)
83 me.configureXonoticListBox(me);
87 void XonoticMapList_loadCvars(entity me)
93 float XonoticMapList_g_maplistCacheQuery(entity me, float i)
95 return stof(substring(me.g_maplistCache, i, 1));
97 void XonoticMapList_g_maplistCacheToggle(entity me, float i)
99 string a, b, c, s, bspname;
101 s = me.g_maplistCache;
104 b = substring(s, i, 1);
110 return; // nothing happens
111 a = substring(s, 0, i);
112 c = substring(s, i+1, strlen(s) - (i+1));
114 me.g_maplistCache = strzone(strcat(a, b, c));
115 // TODO also update the actual cvar
116 if (!((bspname = MapInfo_BSPName_ByID(i))))
119 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
123 n = tokenize_console(cvar_string("g_maplist"));
124 for(i = 0; i < n; ++i)
125 if(argv(i) != bspname)
126 s = strcat(s, " ", argv(i));
127 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
131 void XonoticMapList_draw(entity me)
134 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
135 SUPER(XonoticMapList).draw(me);
138 void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
140 me.itemAbsSize = '0 0 0';
141 SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
143 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
144 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
145 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
146 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
148 me.columnPreviewOrigin = 0;
149 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
150 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
151 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
153 me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
154 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
157 void XonoticMapList_clickListBoxItem(entity me, float i, vector where)
159 if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize)
162 m_play_click_sound(MENU_SOUND_SELECT);
163 me.g_maplistCacheToggle(me, i);
167 void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where)
169 if(where.x >= me.columnNameOrigin)
172 // pop up map info screen
173 m_play_click_sound(MENU_SOUND_OPEN);
174 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me);
175 DialogOpenButton_Click_withCoords(NULL, main.mapInfoDialog, me.origin + eX * (me.columnNameOrigin * me.size.x) + eY * ((me.itemHeight * i - me.scrollPos) * me.size.y), eY * me.itemAbsSize.y + eX * (me.itemAbsSize.x * me.columnNameSize));
179 void XonoticMapList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
181 // layout: Ping, Map name, Map name, NP, TP, MP
186 if(!MapInfo_Get_ByID(i))
189 included = me.g_maplistCacheQuery(me, i);
190 if(included || isSelected)
191 theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG;
193 theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG;
196 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
200 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
203 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
204 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
208 if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
209 draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
211 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
214 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
215 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_titlestring), me.columnNameSize, 0, me.realFontSize);
216 draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_TITLE, theAlpha, 0);
217 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_author), me.columnNameSize, 0, me.realFontSize);
218 draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_AUTHOR, theAlpha, 0);
220 MapInfo_ClearTemps();
223 void XonoticMapList_refilter(entity me)
228 gt = MapInfo_CurrentGametype();
229 f = MapInfo_CurrentFeatures();
230 MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
232 MapInfo_FilterString(me.stringFilter);
233 me.nItems = MapInfo_count;
235 for(i = 0; i < MapInfo_count; ++i)
236 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
237 if(me.g_maplistCache)
238 strunzone(me.g_maplistCache);
240 for(i = 1; i < MapInfo_count; i *= 2)
242 n = tokenize_console(cvar_string("g_maplist"));
243 for(i = 0; i < n; ++i)
245 j = MapInfo_FindName(argv(i));
248 // double check that the two mapnames are "identical", not just share the same prefix
249 if (strlen(MapInfo_BSPName_ByID(j)) == strlen(argv(i)))
253 substring(s, j+1, MapInfo_count - (j+1))
257 me.g_maplistCache = strzone(s);
258 if(gt != me.lastGametype || f != me.lastFeatures)
260 me.lastGametype = gt;
262 me.setSelected(me, 0);
266 void XonoticMapList_refilterCallback(entity me, entity cb)
271 void MapList_StringFilterBox_Change(entity box, entity me)
274 strunzone(me.stringFilter);
276 me.stringFilter = strzone(box.text);
278 me.stringFilter = string_null;
283 void MapList_Add_Shown(entity btn, entity me)
286 n = strlen(me.g_maplistCache);
287 for (i = 0 ; i < n; i++)
289 if (!me.g_maplistCacheQuery(me, i))
290 me.g_maplistCacheToggle(me, i);
295 void MapList_Remove_Shown(entity btn, entity me)
298 n = strlen(me.g_maplistCache);
299 for (i = 0 ; i < n; i++)
301 if (me.g_maplistCacheQuery(me, i))
302 me.g_maplistCacheToggle(me, i);
307 void MapList_Add_All(entity btn, entity me)
311 MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0); // all
313 for(i = 0; i < MapInfo_count; ++i)
314 s = strcat(s, " ", MapInfo_BSPName_ByID(i));
315 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
319 void MapList_Remove_All(entity btn, entity me)
321 cvar_set("g_maplist", "");
325 void MapList_LoadMap(entity btn, entity me)
332 if(btn.parent.instanceOfXonoticMapInfoDialog)
334 i = btn.parent.currentMapIndex;
335 Dialog_Close(btn, btn.parent);
338 if(i >= me.nItems || i < 0)
341 m = MapInfo_BSPName_ByID(i);
344 LOG_INFO(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"));
348 if(MapInfo_CheckMap(m))
350 localcmd("\nmenu_loadmap_prepare\n");
351 if(cvar("menu_use_default_hostname"))
352 localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n");
353 MapInfo_LoadMap(m, 1);
357 LOG_INFO(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"));
363 float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
367 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
368 if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER)
370 // pop up map info screen
371 m_play_click_sound(MENU_SOUND_OPEN);
372 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me);
373 DialogOpenButton_Click_withCoords(NULL, main.mapInfoDialog, me.origin + eX * (me.columnNameOrigin * me.size.x) + eY * ((me.itemHeight * me.selectedItem - me.scrollPos) * me.size.y), eY * me.itemAbsSize.y + eX * (me.itemAbsSize.x * me.columnNameSize));
375 else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS)
377 m_play_click_sound(MENU_SOUND_SELECT);
378 me.g_maplistCacheToggle(me, me.selectedItem);
380 else if(ascii == 43) // +
382 if (!me.g_maplistCacheQuery(me, me.selectedItem))
384 m_play_click_sound(MENU_SOUND_SELECT);
385 me.g_maplistCacheToggle(me, me.selectedItem);
388 else if(ascii == 45) // -
390 if(me.g_maplistCacheQuery(me, me.selectedItem))
392 m_play_click_sound(MENU_SOUND_SELECT);
393 me.g_maplistCacheToggle(me, me.selectedItem);
396 else if(scan == K_BACKSPACE)
398 if(time < me.typeToSearchTime)
400 save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
401 if(me.typeToSearchString)
402 strunzone(me.typeToSearchString);
403 me.typeToSearchString = strzone(save);
404 me.typeToSearchTime = time + 0.5;
405 if(strlen(me.typeToSearchString))
407 MapInfo_FindName(me.typeToSearchString);
408 if(MapInfo_FindName_firstResult >= 0)
409 me.setSelected(me, MapInfo_FindName_firstResult);
413 else if(ascii >= 32 && ascii != 127)
416 if(time > me.typeToSearchTime)
419 save = strcat(me.typeToSearchString, ch);
420 if(me.typeToSearchString)
421 strunzone(me.typeToSearchString);
422 me.typeToSearchString = strzone(save);
423 me.typeToSearchTime = time + 0.5;
424 MapInfo_FindName(me.typeToSearchString);
425 if(MapInfo_FindName_firstResult >= 0)
426 me.setSelected(me, MapInfo_FindName_firstResult);
428 else if(shift & S_CTRL && scan == 'f') // ctrl-f (as in "F"ind)
430 me.parent.setFocus(me.parent, me.stringFilterBox);
432 else if(shift & S_CTRL && scan == 'u') // ctrl-u (remove stringFilter line
434 me.stringFilterBox.setText(me.stringFilterBox, "");
435 MapList_StringFilterBox_Change(me.stringFilterBox, me);
438 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
442 float MapList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift)
444 // in this section, note that onChangeEntity has the ref to mapListBox
445 // we make use of that, instead of extending a class to add one more attrib
450 // move the focus to the mapListBox
451 me.onChangeEntity.parent.setFocus(me.onChangeEntity.parent, me.onChangeEntity);
457 // pass the event to the mapListBox (to scroll up and down)
458 return me.onChangeEntity.keyDown(me.onChangeEntity, scan, ascii, shift);
460 return SUPER(XonoticInputBox).keyDown(me, scan, ascii, shift);