3 CLASS(XonoticMapList, XonoticListBox)
4 METHOD(XonoticMapList, configureXonoticMapList, void(entity))
5 ATTRIB(XonoticMapList, rowsPerItem, float, 4)
6 METHOD(XonoticMapList, draw, void(entity))
7 METHOD(XonoticMapList, drawListBoxItem, void(entity, float, vector, float))
8 METHOD(XonoticMapList, clickListBoxItem, void(entity, float, vector))
9 METHOD(XonoticMapList, doubleClickListBoxItem, void(entity, float, vector))
10 METHOD(XonoticMapList, resizeNotify, void(entity, vector, vector, vector, vector))
11 METHOD(XonoticMapList, refilter, void(entity))
12 METHOD(XonoticMapList, refilterCallback, void(entity, entity))
13 METHOD(XonoticMapList, keyDown, float(entity, float, float, float))
15 ATTRIB(XonoticMapList, realFontSize, vector, '0 0 0')
16 ATTRIB(XonoticMapList, columnPreviewOrigin, float, 0)
17 ATTRIB(XonoticMapList, columnPreviewSize, float, 0)
18 ATTRIB(XonoticMapList, columnNameOrigin, float, 0)
19 ATTRIB(XonoticMapList, columnNameSize, float, 0)
20 ATTRIB(XonoticMapList, checkMarkOrigin, vector, '0 0 0')
21 ATTRIB(XonoticMapList, checkMarkSize, vector, '0 0 0')
22 ATTRIB(XonoticMapList, realUpperMargin1, float, 0)
23 ATTRIB(XonoticMapList, realUpperMargin2, float, 0)
25 ATTRIB(XonoticMapList, lastGametype, float, 0)
26 ATTRIB(XonoticMapList, lastFeatures, float, 0)
28 ATTRIB(XonoticMapList, origin, vector, '0 0 0')
29 ATTRIB(XonoticMapList, itemAbsSize, vector, '0 0 0')
31 ATTRIB(XonoticMapList, g_maplistCache, string, string_null)
32 METHOD(XonoticMapList, g_maplistCacheToggle, void(entity, float))
33 METHOD(XonoticMapList, g_maplistCacheQuery, float(entity, float))
35 ATTRIB(XonoticMapList, startButton, entity, NULL)
37 METHOD(XonoticMapList, loadCvars, void(entity))
39 ATTRIB(XonoticMapList, typeToSearchString, string, string_null)
40 ATTRIB(XonoticMapList, typeToSearchTime, float, 0)
42 METHOD(XonoticMapList, destroy, void(entity))
44 ATTRIB(XonoticMapList, alphaBG, float, 0)
45 ENDCLASS(XonoticMapList)
46 entity makeXonoticMapList();
47 void MapList_All(entity btn, entity me);
48 void MapList_None(entity btn, entity me);
49 void MapList_LoadMap(entity btn, entity me);
53 void XonoticMapList_destroy(entity me)
58 entity makeXonoticMapList()
61 me = NEW(XonoticMapList);
62 me.configureXonoticMapList(me);
66 void XonoticMapList_configureXonoticMapList(entity me)
68 me.configureXonoticListBox(me);
72 void XonoticMapList_loadCvars(entity me)
77 float XonoticMapList_g_maplistCacheQuery(entity me, float i)
79 return stof(substring(me.g_maplistCache, i, 1));
81 void XonoticMapList_g_maplistCacheToggle(entity me, float i)
83 string a, b, c, s, bspname;
85 s = me.g_maplistCache;
88 b = substring(s, i, 1);
94 return; // nothing happens
95 a = substring(s, 0, i);
96 c = substring(s, i+1, strlen(s) - (i+1));
98 me.g_maplistCache = strzone(strcat(a, b, c));
99 // TODO also update the actual cvar
100 if (!((bspname = MapInfo_BSPName_ByID(i))))
103 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
107 n = tokenize_console(cvar_string("g_maplist"));
108 for(i = 0; i < n; ++i)
109 if(argv(i) != bspname)
110 s = strcat(s, " ", argv(i));
111 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
115 void XonoticMapList_draw(entity me)
118 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
119 SUPER(XonoticMapList).draw(me);
122 void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
124 me.itemAbsSize = '0 0 0';
125 SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
127 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
128 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
129 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
130 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
132 me.columnPreviewOrigin = 0;
133 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
134 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
135 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
137 me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
138 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
141 void XonoticMapList_clickListBoxItem(entity me, float i, vector where)
143 if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize)
146 m_play_click_sound(MENU_SOUND_SELECT);
147 me.g_maplistCacheToggle(me, i);
151 void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where)
153 if(where.x >= me.columnNameOrigin)
156 // pop up map info screen
157 m_play_click_sound(MENU_SOUND_OPEN);
158 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me);
159 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));
163 void XonoticMapList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
165 // layout: Ping, Map name, Map name, NP, TP, MP
170 if(!MapInfo_Get_ByID(i))
173 included = me.g_maplistCacheQuery(me, i);
174 if(included || isSelected)
175 theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG;
177 theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG;
180 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
182 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
184 if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
185 draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
187 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
190 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
191 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_titlestring), me.columnNameSize, 0, me.realFontSize);
192 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);
193 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_author), me.columnNameSize, 0, me.realFontSize);
194 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);
196 MapInfo_ClearTemps();
199 void XonoticMapList_refilter(entity me)
204 gt = MapInfo_CurrentGametype();
205 f = MapInfo_CurrentFeatures();
206 MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
207 me.nItems = MapInfo_count;
208 for(i = 0; i < MapInfo_count; ++i)
209 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
210 if(me.g_maplistCache)
211 strunzone(me.g_maplistCache);
213 for(i = 1; i < MapInfo_count; i *= 2)
215 n = tokenize_console(cvar_string("g_maplist"));
216 for(i = 0; i < n; ++i)
218 j = MapInfo_FindName(argv(i));
223 substring(s, j+1, MapInfo_count - (j+1))
226 me.g_maplistCache = strzone(s);
227 if(gt != me.lastGametype || f != me.lastFeatures)
229 me.lastGametype = gt;
231 me.setSelected(me, 0);
235 void XonoticMapList_refilterCallback(entity me, entity cb)
240 void MapList_All(entity btn, entity me)
244 MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0); // all
246 for(i = 0; i < MapInfo_count; ++i)
247 s = strcat(s, " ", MapInfo_BSPName_ByID(i));
248 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
252 void MapList_None(entity btn, entity me)
254 cvar_set("g_maplist", "");
258 void MapList_LoadMap(entity btn, entity me)
265 if(btn.parent.instanceOfXonoticMapInfoDialog)
267 i = btn.parent.currentMapIndex;
268 Dialog_Close(btn, btn.parent);
271 if(i >= me.nItems || i < 0)
274 m = MapInfo_BSPName_ByID(i);
277 print(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"));
281 if(MapInfo_CheckMap(m))
283 localcmd("\nmenu_loadmap_prepare\n");
284 if(cvar("menu_use_default_hostname"))
285 localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n");
286 MapInfo_LoadMap(m, 1);
290 print(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"));
296 float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
300 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
301 if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER)
303 // pop up map info screen
304 m_play_click_sound(MENU_SOUND_OPEN);
305 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me);
306 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));
308 else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS)
310 m_play_click_sound(MENU_SOUND_SELECT);
311 me.g_maplistCacheToggle(me, me.selectedItem);
313 else if(ascii == 43) // +
315 if (!me.g_maplistCacheQuery(me, me.selectedItem))
317 m_play_click_sound(MENU_SOUND_SELECT);
318 me.g_maplistCacheToggle(me, me.selectedItem);
321 else if(ascii == 45) // -
323 if(me.g_maplistCacheQuery(me, me.selectedItem))
325 m_play_click_sound(MENU_SOUND_SELECT);
326 me.g_maplistCacheToggle(me, me.selectedItem);
329 else if(scan == K_BACKSPACE)
331 if(time < me.typeToSearchTime)
333 save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
334 if(me.typeToSearchString)
335 strunzone(me.typeToSearchString);
336 me.typeToSearchString = strzone(save);
337 me.typeToSearchTime = time + 0.5;
338 if(strlen(me.typeToSearchString))
340 MapInfo_FindName(me.typeToSearchString);
341 if(MapInfo_FindName_firstResult >= 0)
342 me.setSelected(me, MapInfo_FindName_firstResult);
346 else if(ascii >= 32 && ascii != 127)
349 if(time > me.typeToSearchTime)
352 save = strcat(me.typeToSearchString, ch);
353 if(me.typeToSearchString)
354 strunzone(me.typeToSearchString);
355 me.typeToSearchString = strzone(save);
356 me.typeToSearchTime = time + 0.5;
357 MapInfo_FindName(me.typeToSearchString);
358 if(MapInfo_FindName_firstResult >= 0)
359 me.setSelected(me, MapInfo_FindName_firstResult);
362 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);