4 CLASS(XonoticMapList, XonoticListBox)
5 METHOD(XonoticMapList, configureXonoticMapList, void(entity));
6 ATTRIB(XonoticMapList, rowsPerItem, float, 4)
7 METHOD(XonoticMapList, draw, void(entity));
8 METHOD(XonoticMapList, drawListBoxItem, void(entity, int, vector, bool, bool));
9 METHOD(XonoticMapList, clickListBoxItem, void(entity, float, vector));
10 METHOD(XonoticMapList, doubleClickListBoxItem, void(entity, float, vector));
11 METHOD(XonoticMapList, resizeNotify, void(entity, vector, vector, vector, vector));
12 METHOD(XonoticMapList, refilter, void(entity));
13 METHOD(XonoticMapList, refilterCallback, void(entity, entity));
14 METHOD(XonoticMapList, keyDown, float(entity, float, float, float));
16 ATTRIB(XonoticMapList, realFontSize, vector, '0 0 0')
17 ATTRIB(XonoticMapList, columnPreviewOrigin, float, 0)
18 ATTRIB(XonoticMapList, columnPreviewSize, float, 0)
19 ATTRIB(XonoticMapList, columnNameOrigin, float, 0)
20 ATTRIB(XonoticMapList, columnNameSize, float, 0)
21 ATTRIB(XonoticMapList, checkMarkOrigin, vector, '0 0 0')
22 ATTRIB(XonoticMapList, checkMarkSize, vector, '0 0 0')
23 ATTRIB(XonoticMapList, realUpperMargin1, float, 0)
24 ATTRIB(XonoticMapList, realUpperMargin2, float, 0)
26 ATTRIB(XonoticMapList, lastGametype, float, 0)
27 ATTRIB(XonoticMapList, lastFeatures, float, 0)
29 ATTRIB(XonoticMapList, origin, vector, '0 0 0')
30 ATTRIB(XonoticMapList, itemAbsSize, vector, '0 0 0')
32 ATTRIB(XonoticMapList, g_maplistCache, string, string_null)
33 METHOD(XonoticMapList, g_maplistCacheToggle, void(entity, float));
34 METHOD(XonoticMapList, g_maplistCacheQuery, float(entity, float));
36 ATTRIB(XonoticMapList, stringFilter, string, string_null)
37 ATTRIB(XonoticMapList, stringFilterBox, entity, NULL)
39 ATTRIB(XonoticMapList, startButton, entity, NULL)
41 METHOD(XonoticMapList, loadCvars, void(entity));
43 ATTRIB(XonoticMapList, typeToSearchString, string, string_null)
44 ATTRIB(XonoticMapList, typeToSearchTime, float, 0)
46 METHOD(XonoticMapList, destroy, void(entity));
48 ATTRIB(XonoticMapList, alphaBG, float, 0)
49 ENDCLASS(XonoticMapList)
50 entity makeXonoticMapList();
51 void MapList_StringFilterBox_Change(entity box, entity me);
52 float MapList_StringFilterBox_keyDown(entity me, float key, float ascii, float shift);
53 void MapList_Add_Shown(entity btn, entity me);
54 void MapList_Remove_Shown(entity btn, entity me);
55 void MapList_Add_All(entity btn, entity me);
56 void MapList_Remove_All(entity btn, entity me);
57 void MapList_LoadMap(entity btn, entity me);
61 void XonoticMapList_destroy(entity me)
66 entity makeXonoticMapList()
69 me = NEW(XonoticMapList);
70 me.configureXonoticMapList(me);
74 entity MapList_Set_String_Filter_Box(entity me, entity e)
76 me.stringFilterBox = e;
80 void XonoticMapList_configureXonoticMapList(entity me)
82 me.configureXonoticListBox(me);
86 void XonoticMapList_loadCvars(entity me)
92 float XonoticMapList_g_maplistCacheQuery(entity me, float i)
94 return stof(substring(me.g_maplistCache, i, 1));
96 void XonoticMapList_g_maplistCacheToggle(entity me, float i)
98 string a, b, c, s, bspname;
100 s = me.g_maplistCache;
103 b = substring(s, i, 1);
109 return; // nothing happens
110 a = substring(s, 0, i);
111 c = substring(s, i+1, strlen(s) - (i+1));
113 me.g_maplistCache = strzone(strcat(a, b, c));
114 // TODO also update the actual cvar
115 if (!((bspname = MapInfo_BSPName_ByID(i))))
118 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
122 n = tokenize_console(cvar_string("g_maplist"));
123 for(i = 0; i < n; ++i)
124 if(argv(i) != bspname)
125 s = strcat(s, " ", argv(i));
126 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
130 void XonoticMapList_draw(entity me)
133 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
134 SUPER(XonoticMapList).draw(me);
137 void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
139 me.itemAbsSize = '0 0 0';
140 SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
142 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
143 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
144 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
145 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
147 me.columnPreviewOrigin = 0;
148 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
149 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
150 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
152 me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
153 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
156 void XonoticMapList_clickListBoxItem(entity me, float i, vector where)
158 if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize)
161 m_play_click_sound(MENU_SOUND_SELECT);
162 me.g_maplistCacheToggle(me, i);
166 void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where)
168 if(where.x >= me.columnNameOrigin)
171 // pop up map info screen
172 m_play_click_sound(MENU_SOUND_OPEN);
173 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me);
174 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));
178 void XonoticMapList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
180 // layout: Ping, Map name, Map name, NP, TP, MP
185 if(!MapInfo_Get_ByID(i))
188 included = me.g_maplistCacheQuery(me, i);
189 if(included || isSelected)
190 theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG;
192 theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG;
195 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
199 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
202 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
203 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
207 if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
208 draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
210 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
213 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
214 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_titlestring), me.columnNameSize, 0, me.realFontSize);
215 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);
216 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_author), me.columnNameSize, 0, me.realFontSize);
217 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);
219 MapInfo_ClearTemps();
222 void XonoticMapList_refilter(entity me)
227 gt = MapInfo_CurrentGametype();
228 f = MapInfo_CurrentFeatures();
229 MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
231 MapInfo_FilterString(me.stringFilter);
232 me.nItems = MapInfo_count;
234 for(i = 0; i < MapInfo_count; ++i)
235 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
236 if(me.g_maplistCache)
237 strunzone(me.g_maplistCache);
239 for(i = 1; i < MapInfo_count; i *= 2)
241 n = tokenize_console(cvar_string("g_maplist"));
242 for(i = 0; i < n; ++i)
244 j = MapInfo_FindName(argv(i));
247 // double check that the two mapnames are "identical", not just share the same prefix
248 if (strlen(MapInfo_BSPName_ByID(j)) == strlen(argv(i)))
252 substring(s, j+1, MapInfo_count - (j+1))
256 me.g_maplistCache = strzone(s);
257 if(gt != me.lastGametype || f != me.lastFeatures)
259 me.lastGametype = gt;
261 me.setSelected(me, 0);
265 void XonoticMapList_refilterCallback(entity me, entity cb)
270 void MapList_StringFilterBox_Change(entity box, entity me)
273 strunzone(me.stringFilter);
275 me.stringFilter = strzone(box.text);
277 me.stringFilter = string_null;
282 void MapList_Add_Shown(entity btn, entity me)
285 n = strlen(me.g_maplistCache);
286 for (i = 0 ; i < n; i++)
288 if (!me.g_maplistCacheQuery(me, i))
289 me.g_maplistCacheToggle(me, i);
294 void MapList_Remove_Shown(entity btn, entity me)
297 n = strlen(me.g_maplistCache);
298 for (i = 0 ; i < n; i++)
300 if (me.g_maplistCacheQuery(me, i))
301 me.g_maplistCacheToggle(me, i);
306 void MapList_Add_All(entity btn, entity me)
310 MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0); // all
312 for(i = 0; i < MapInfo_count; ++i)
313 s = strcat(s, " ", MapInfo_BSPName_ByID(i));
314 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
318 void MapList_Remove_All(entity btn, entity me)
320 cvar_set("g_maplist", "");
324 void MapList_LoadMap(entity btn, entity me)
331 if(btn.parent.instanceOfXonoticMapInfoDialog)
333 i = btn.parent.currentMapIndex;
334 Dialog_Close(btn, btn.parent);
337 if(i >= me.nItems || i < 0)
340 m = MapInfo_BSPName_ByID(i);
343 LOG_INFO(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"));
347 if(MapInfo_CheckMap(m))
349 localcmd("\nmenu_loadmap_prepare\n");
350 if(cvar("menu_use_default_hostname"))
351 localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n");
352 MapInfo_LoadMap(m, 1);
356 LOG_INFO(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"));
362 float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
366 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
367 if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER)
369 // pop up map info screen
370 m_play_click_sound(MENU_SOUND_OPEN);
371 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me);
372 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));
374 else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS)
376 m_play_click_sound(MENU_SOUND_SELECT);
377 me.g_maplistCacheToggle(me, me.selectedItem);
379 else if(ascii == 43) // +
381 if (!me.g_maplistCacheQuery(me, me.selectedItem))
383 m_play_click_sound(MENU_SOUND_SELECT);
384 me.g_maplistCacheToggle(me, me.selectedItem);
387 else if(ascii == 45) // -
389 if(me.g_maplistCacheQuery(me, me.selectedItem))
391 m_play_click_sound(MENU_SOUND_SELECT);
392 me.g_maplistCacheToggle(me, me.selectedItem);
395 else if(scan == K_BACKSPACE)
397 if(time < me.typeToSearchTime)
399 save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
400 if(me.typeToSearchString)
401 strunzone(me.typeToSearchString);
402 me.typeToSearchString = strzone(save);
403 me.typeToSearchTime = time + 0.5;
404 if(strlen(me.typeToSearchString))
406 MapInfo_FindName(me.typeToSearchString);
407 if(MapInfo_FindName_firstResult >= 0)
408 me.setSelected(me, MapInfo_FindName_firstResult);
412 else if(ascii >= 32 && ascii != 127)
415 if(time > me.typeToSearchTime)
418 save = strcat(me.typeToSearchString, ch);
419 if(me.typeToSearchString)
420 strunzone(me.typeToSearchString);
421 me.typeToSearchString = strzone(save);
422 me.typeToSearchTime = time + 0.5;
423 MapInfo_FindName(me.typeToSearchString);
424 if(MapInfo_FindName_firstResult >= 0)
425 me.setSelected(me, MapInfo_FindName_firstResult);
427 else if(shift & S_CTRL && scan == 'f') // ctrl-f (as in "F"ind)
429 me.parent.setFocus(me.parent, me.stringFilterBox);
431 else if(shift & S_CTRL && scan == 'u') // ctrl-u (remove stringFilter line
433 me.stringFilterBox.setText(me.stringFilterBox, "");
434 MapList_StringFilterBox_Change(me.stringFilterBox, me);
437 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
441 float MapList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift)
443 // in this section, note that onChangeEntity has the ref to mapListBox
444 // we make use of that, instead of extending a class to add one more attrib
449 // move the focus to the mapListBox
450 me.onChangeEntity.parent.setFocus(me.onChangeEntity.parent, me.onChangeEntity);
456 // pass the event to the mapListBox (to scroll up and down)
457 return me.onChangeEntity.keyDown(me.onChangeEntity, scan, ascii, shift);
459 return SUPER(XonoticInputBox).keyDown(me, scan, ascii, shift);