2 CLASS(XonoticMapList) EXTENDS(XonoticListBox)
3 METHOD(XonoticMapList, configureXonoticMapList, void(entity))
4 ATTRIB(XonoticMapList, rowsPerItem, float, 4)
5 METHOD(XonoticMapList, draw, void(entity))
6 METHOD(XonoticMapList, drawListBoxItem, void(entity, float, vector, float))
7 METHOD(XonoticMapList, clickListBoxItem, void(entity, float, vector))
8 METHOD(XonoticMapList, doubleClickListBoxItem, void(entity, float, vector))
9 METHOD(XonoticMapList, resizeNotify, void(entity, vector, vector, vector, vector))
10 METHOD(XonoticMapList, refilter, void(entity))
11 METHOD(XonoticMapList, refilterCallback, void(entity, entity))
12 METHOD(XonoticMapList, keyDown, float(entity, float, float, float))
14 ATTRIB(XonoticMapList, realFontSize, vector, '0 0 0')
15 ATTRIB(XonoticMapList, columnPreviewOrigin, float, 0)
16 ATTRIB(XonoticMapList, columnPreviewSize, float, 0)
17 ATTRIB(XonoticMapList, columnNameOrigin, float, 0)
18 ATTRIB(XonoticMapList, columnNameSize, float, 0)
19 ATTRIB(XonoticMapList, checkMarkOrigin, vector, '0 0 0')
20 ATTRIB(XonoticMapList, checkMarkSize, vector, '0 0 0')
21 ATTRIB(XonoticMapList, realUpperMargin1, float, 0)
22 ATTRIB(XonoticMapList, realUpperMargin2, float, 0)
24 ATTRIB(XonoticMapList, lastGametype, float, 0)
25 ATTRIB(XonoticMapList, lastFeatures, float, 0)
27 ATTRIB(XonoticMapList, origin, vector, '0 0 0')
28 ATTRIB(XonoticMapList, itemAbsSize, vector, '0 0 0')
30 ATTRIB(XonoticMapList, g_maplistCache, string, string_null)
31 METHOD(XonoticMapList, g_maplistCacheToggle, void(entity, float))
32 METHOD(XonoticMapList, g_maplistCacheQuery, float(entity, float))
34 ATTRIB(XonoticMapList, stringFilter, string, string_null)
35 ATTRIB(XonoticMapList, stringFilterBox, entity, NULL)
37 ATTRIB(XonoticMapList, startButton, entity, NULL)
39 METHOD(XonoticMapList, loadCvars, void(entity))
41 ATTRIB(XonoticMapList, typeToSearchString, string, string_null)
42 ATTRIB(XonoticMapList, typeToSearchTime, float, 0)
44 METHOD(XonoticMapList, destroy, void(entity))
46 ATTRIB(XonoticListBox, alphaBG, float, 0)
47 ENDCLASS(XonoticMapList)
48 entity makeXonoticMapList();
49 entity makeXonoticMapListStringFilterBox(entity me, float doEditColorCodes, string theCvar);
50 void MapList_StringFilterBox_Change(entity box, entity me);
51 float MapList_StringFilterBox_keyDown(entity me, float key, float ascii, float shift);
52 void MapList_Add_Shown(entity btn, entity me);
53 void MapList_Remove_Shown(entity btn, entity me);
54 void MapList_Remove_All(entity btn, entity me);
55 void MapList_LoadMap(entity btn, entity me);
59 void XonoticMapList_destroy(entity me)
64 entity makeXonoticMapListStringFilterBox(entity me, float doEditColorCodes, string theCvar)
66 return makeXonoticInputBox(doEditColorCodes, theCvar);
68 entity makeXonoticMapList()
71 me = spawnXonoticMapList();
72 me.configureXonoticMapList(me);
76 entity MapList_Set_String_Filter_Box(entity me, entity e)
78 me.stringFilterBox = e;
82 void XonoticMapList_configureXonoticMapList(entity me)
84 me.configureXonoticListBox(me);
88 void XonoticMapList_loadCvars(entity me)
94 float XonoticMapList_g_maplistCacheQuery(entity me, float i)
96 return stof(substring(me.g_maplistCache, i, 1));
98 void XonoticMapList_g_maplistCacheToggle(entity me, float i)
100 string a, b, c, s, bspname;
102 s = me.g_maplistCache;
105 b = substring(s, i, 1);
111 return; // nothing happens
112 a = substring(s, 0, i);
113 c = substring(s, i+1, strlen(s) - (i+1));
115 me.g_maplistCache = strzone(strcat(a, b, c));
116 // TODO also update the actual cvar
117 if (!((bspname = MapInfo_BSPName_ByID(i))))
120 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
124 n = tokenize_console(cvar_string("g_maplist"));
125 for(i = 0; i < n; ++i)
126 if(argv(i) != bspname)
127 s = strcat(s, " ", argv(i));
128 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
132 void XonoticMapList_draw(entity me)
135 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
136 SUPER(XonoticMapList).draw(me);
139 void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
141 me.itemAbsSize = '0 0 0';
142 SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
144 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
145 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
146 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
147 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
149 me.columnPreviewOrigin = 0;
150 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
151 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
152 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
154 me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
155 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
158 void XonoticMapList_clickListBoxItem(entity me, float i, vector where)
160 if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize)
163 m_play_click_sound(MENU_SOUND_SELECT);
164 me.g_maplistCacheToggle(me, i);
168 void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where)
170 if(where.x >= me.columnNameOrigin)
173 // pop up map info screen
174 m_play_click_sound(MENU_SOUND_OPEN);
175 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me);
176 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));
180 void XonoticMapList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
182 // layout: Ping, Map name, Map name, NP, TP, MP
187 if(!MapInfo_Get_ByID(i))
190 included = me.g_maplistCacheQuery(me, i);
191 if(included || isSelected)
192 theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG;
194 theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG;
197 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);
201 if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
202 draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
204 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
207 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
208 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_titlestring), me.columnNameSize, 0, me.realFontSize);
209 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);
210 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_author), me.columnNameSize, 0, me.realFontSize);
211 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);
213 MapInfo_ClearTemps();
216 void XonoticMapList_refilter(entity me)
221 gt = MapInfo_CurrentGametype();
222 f = MapInfo_CurrentFeatures();
223 MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
225 MapInfo_FilterString(me.stringFilter);
226 me.nItems = MapInfo_count;
228 for(i = 0; i < MapInfo_count; ++i)
229 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
230 if(me.g_maplistCache)
231 strunzone(me.g_maplistCache);
233 for(i = 1; i < MapInfo_count; i *= 2)
235 n = tokenize_console(cvar_string("g_maplist"));
236 for(i = 0; i < n; ++i)
238 j = MapInfo_FindName(argv(i));
243 substring(s, j+1, MapInfo_count - (j+1))
246 me.g_maplistCache = strzone(s);
247 if(gt != me.lastGametype || f != me.lastFeatures)
249 me.lastGametype = gt;
251 me.setSelected(me, 0);
255 void XonoticMapList_refilterCallback(entity me, entity cb)
260 void MapList_StringFilterBox_Change(entity box, entity me)
263 strunzone(me.stringFilter);
265 me.stringFilter = strzone(box.text);
267 me.stringFilter = string_null;
272 void MapList_Add_Shown(entity btn, entity me)
275 n = strlen(me.g_maplistCache);
276 for (i = 0 ; i < n; i++)
278 if (!me.g_maplistCacheQuery(me, i))
279 me.g_maplistCacheToggle(me, i);
284 void MapList_Remove_Shown(entity btn, entity me)
287 n = strlen(me.g_maplistCache);
288 for (i = 0 ; i < n; i++)
290 if (me.g_maplistCacheQuery(me, i))
291 me.g_maplistCacheToggle(me, i);
296 void MapList_Remove_All(entity btn, entity me)
298 cvar_set("g_maplist", "");
302 void MapList_LoadMap(entity btn, entity me)
309 if(btn.parent.instanceOfXonoticMapInfoDialog)
311 i = btn.parent.currentMapIndex;
312 Dialog_Close(btn, btn.parent);
315 if(i >= me.nItems || i < 0)
318 m = MapInfo_BSPName_ByID(i);
321 print(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"));
325 if(MapInfo_CheckMap(m))
327 localcmd("\nmenu_loadmap_prepare\n");
328 if(cvar("menu_use_default_hostname"))
329 localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n");
330 MapInfo_LoadMap(m, 1);
334 print(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"));
340 float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
344 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
345 if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER)
347 // pop up map info screen
348 m_play_click_sound(MENU_SOUND_OPEN);
349 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me);
350 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));
352 else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS)
354 m_play_click_sound(MENU_SOUND_SELECT);
355 me.g_maplistCacheToggle(me, me.selectedItem);
357 else if(ascii == 43) // +
359 if (!me.g_maplistCacheQuery(me, me.selectedItem))
361 m_play_click_sound(MENU_SOUND_SELECT);
362 me.g_maplistCacheToggle(me, me.selectedItem);
365 else if(ascii == 45) // -
367 if(me.g_maplistCacheQuery(me, me.selectedItem))
369 m_play_click_sound(MENU_SOUND_SELECT);
370 me.g_maplistCacheToggle(me, me.selectedItem);
373 else if(scan == K_BACKSPACE)
375 if(time < me.typeToSearchTime)
377 save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
378 if(me.typeToSearchString)
379 strunzone(me.typeToSearchString);
380 me.typeToSearchString = strzone(save);
381 me.typeToSearchTime = time + 0.5;
382 if(strlen(me.typeToSearchString))
384 MapInfo_FindName(me.typeToSearchString);
385 if(MapInfo_FindName_firstResult >= 0)
386 me.setSelected(me, MapInfo_FindName_firstResult);
390 else if(ascii >= 32 && ascii != 127)
393 if(time > me.typeToSearchTime)
396 save = strcat(me.typeToSearchString, ch);
397 if(me.typeToSearchString)
398 strunzone(me.typeToSearchString);
399 me.typeToSearchString = strzone(save);
400 me.typeToSearchTime = time + 0.5;
401 MapInfo_FindName(me.typeToSearchString);
402 if(MapInfo_FindName_firstResult >= 0)
403 me.setSelected(me, MapInfo_FindName_firstResult);
405 else if(shift & S_CTRL && scan == 'f') // ctrl-f (as in "F"ind)
407 me.parent.setFocus(me.parent, me.stringFilterBox);
409 else if(shift & S_CTRL && scan == 'u') // ctrl-u (remove stringFilter line
411 me.stringFilterBox.setText(me.stringFilterBox, "");
412 MapList_StringFilterBox_Change(me.stringFilterBox, me);
415 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
419 float MapList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift)
421 // in this section, note that onChangeEntity has the ref to mapListBox
422 // we make use of that, instead of extending a class to add one more attrib
427 // move the focus to the mapListBox
428 me.onChangeEntity.parent.setFocus(me.onChangeEntity.parent, me.onChangeEntity);
434 // pass the event to the mapListBox (to scroll up and down)
435 return me.onChangeEntity.keyDown(me.onChangeEntity, scan, ascii, shift);
437 return SUPER(XonoticInputBox).keyDown(me, scan, ascii, shift);