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, float, vector, float))
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 entity makeXonoticMapListStringFilterBox(entity me, float doEditColorCodes, string theCvar);
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_Remove_All(entity btn, entity me);
57 void MapList_LoadMap(entity btn, entity me);
61 void XonoticMapList_destroy(entity me)
66 entity makeXonoticMapListStringFilterBox(entity me, float doEditColorCodes, string theCvar)
68 return makeXonoticInputBox(doEditColorCodes, theCvar);
70 entity makeXonoticMapList()
73 me = NEW(XonoticMapList);
74 me.configureXonoticMapList(me);
78 entity MapList_Set_String_Filter_Box(entity me, entity e)
80 me.stringFilterBox = e;
84 void XonoticMapList_configureXonoticMapList(entity me)
86 me.configureXonoticListBox(me);
90 void XonoticMapList_loadCvars(entity me)
96 float XonoticMapList_g_maplistCacheQuery(entity me, float i)
98 return stof(substring(me.g_maplistCache, i, 1));
100 void XonoticMapList_g_maplistCacheToggle(entity me, float i)
102 string a, b, c, s, bspname;
104 s = me.g_maplistCache;
107 b = substring(s, i, 1);
113 return; // nothing happens
114 a = substring(s, 0, i);
115 c = substring(s, i+1, strlen(s) - (i+1));
117 me.g_maplistCache = strzone(strcat(a, b, c));
118 // TODO also update the actual cvar
119 if (!((bspname = MapInfo_BSPName_ByID(i))))
122 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
126 n = tokenize_console(cvar_string("g_maplist"));
127 for(i = 0; i < n; ++i)
128 if(argv(i) != bspname)
129 s = strcat(s, " ", argv(i));
130 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
134 void XonoticMapList_draw(entity me)
137 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
138 SUPER(XonoticMapList).draw(me);
141 void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
143 me.itemAbsSize = '0 0 0';
144 SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
146 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
147 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
148 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
149 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
151 me.columnPreviewOrigin = 0;
152 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
153 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
154 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
156 me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
157 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
160 void XonoticMapList_clickListBoxItem(entity me, float i, vector where)
162 if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize)
165 m_play_click_sound(MENU_SOUND_SELECT);
166 me.g_maplistCacheToggle(me, i);
170 void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where)
172 if(where.x >= me.columnNameOrigin)
175 // pop up map info screen
176 m_play_click_sound(MENU_SOUND_OPEN);
177 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me);
178 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));
182 void XonoticMapList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
184 // layout: Ping, Map name, Map name, NP, TP, MP
189 if(!MapInfo_Get_ByID(i))
192 included = me.g_maplistCacheQuery(me, i);
193 if(included || isSelected)
194 theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG;
196 theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG;
199 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
201 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
203 if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
204 draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
206 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
209 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
210 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_titlestring), me.columnNameSize, 0, me.realFontSize);
211 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);
212 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_author), me.columnNameSize, 0, me.realFontSize);
213 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);
215 MapInfo_ClearTemps();
218 void XonoticMapList_refilter(entity me)
223 gt = MapInfo_CurrentGametype();
224 f = MapInfo_CurrentFeatures();
225 MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
227 MapInfo_FilterString(me.stringFilter);
228 me.nItems = MapInfo_count;
230 for(i = 0; i < MapInfo_count; ++i)
231 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
232 if(me.g_maplistCache)
233 strunzone(me.g_maplistCache);
235 for(i = 1; i < MapInfo_count; i *= 2)
237 n = tokenize_console(cvar_string("g_maplist"));
238 for(i = 0; i < n; ++i)
240 j = MapInfo_FindName(argv(i));
245 substring(s, j+1, MapInfo_count - (j+1))
248 me.g_maplistCache = strzone(s);
249 if(gt != me.lastGametype || f != me.lastFeatures)
251 me.lastGametype = gt;
253 me.setSelected(me, 0);
257 void XonoticMapList_refilterCallback(entity me, entity cb)
262 void MapList_StringFilterBox_Change(entity box, entity me)
265 strunzone(me.stringFilter);
267 me.stringFilter = strzone(box.text);
269 me.stringFilter = string_null;
274 void MapList_Add_Shown(entity btn, entity me)
277 n = strlen(me.g_maplistCache);
278 for (i = 0 ; i < n; i++)
280 if (!me.g_maplistCacheQuery(me, i))
281 me.g_maplistCacheToggle(me, i);
286 void MapList_Remove_Shown(entity btn, entity me)
289 n = strlen(me.g_maplistCache);
290 for (i = 0 ; i < n; i++)
292 if (me.g_maplistCacheQuery(me, i))
293 me.g_maplistCacheToggle(me, i);
298 void MapList_Add_All(entity btn, entity me)
302 n = strlen(me.g_maplistCache);
303 for (i = 0 ; i < n; i++)
305 if (!me.g_maplistCacheQuery(me, i))
306 me.g_maplistCacheToggle(me, i);
311 void MapList_Remove_All(entity btn, entity me)
313 cvar_set("g_maplist", "");
317 void MapList_LoadMap(entity btn, entity me)
324 if(btn.parent.instanceOfXonoticMapInfoDialog)
326 i = btn.parent.currentMapIndex;
327 Dialog_Close(btn, btn.parent);
330 if(i >= me.nItems || i < 0)
333 m = MapInfo_BSPName_ByID(i);
336 print(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"));
340 if(MapInfo_CheckMap(m))
342 localcmd("\nmenu_loadmap_prepare\n");
343 if(cvar("menu_use_default_hostname"))
344 localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n");
345 MapInfo_LoadMap(m, 1);
349 print(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"));
355 float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
359 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
360 if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER)
362 // pop up map info screen
363 m_play_click_sound(MENU_SOUND_OPEN);
364 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me);
365 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));
367 else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS)
369 m_play_click_sound(MENU_SOUND_SELECT);
370 me.g_maplistCacheToggle(me, me.selectedItem);
372 else if(ascii == 43) // +
374 if (!me.g_maplistCacheQuery(me, me.selectedItem))
376 m_play_click_sound(MENU_SOUND_SELECT);
377 me.g_maplistCacheToggle(me, me.selectedItem);
380 else if(ascii == 45) // -
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(scan == K_BACKSPACE)
390 if(time < me.typeToSearchTime)
392 save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
393 if(me.typeToSearchString)
394 strunzone(me.typeToSearchString);
395 me.typeToSearchString = strzone(save);
396 me.typeToSearchTime = time + 0.5;
397 if(strlen(me.typeToSearchString))
399 MapInfo_FindName(me.typeToSearchString);
400 if(MapInfo_FindName_firstResult >= 0)
401 me.setSelected(me, MapInfo_FindName_firstResult);
405 else if(ascii >= 32 && ascii != 127)
408 if(time > me.typeToSearchTime)
411 save = strcat(me.typeToSearchString, ch);
412 if(me.typeToSearchString)
413 strunzone(me.typeToSearchString);
414 me.typeToSearchString = strzone(save);
415 me.typeToSearchTime = time + 0.5;
416 MapInfo_FindName(me.typeToSearchString);
417 if(MapInfo_FindName_firstResult >= 0)
418 me.setSelected(me, MapInfo_FindName_firstResult);
420 else if(shift & S_CTRL && scan == 'f') // ctrl-f (as in "F"ind)
422 me.parent.setFocus(me.parent, me.stringFilterBox);
424 else if(shift & S_CTRL && scan == 'u') // ctrl-u (remove stringFilter line
426 me.stringFilterBox.setText(me.stringFilterBox, "");
427 MapList_StringFilterBox_Change(me.stringFilterBox, me);
430 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
434 float MapList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift)
436 // in this section, note that onChangeEntity has the ref to mapListBox
437 // we make use of that, instead of extending a class to add one more attrib
442 // move the focus to the mapListBox
443 me.onChangeEntity.parent.setFocus(me.onChangeEntity.parent, me.onChangeEntity);
449 // pass the event to the mapListBox (to scroll up and down)
450 return me.onChangeEntity.keyDown(me.onChangeEntity, scan, ascii, shift);
452 return SUPER(XonoticInputBox).keyDown(me, scan, ascii, shift);