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, startButton, entity, NULL)
36 METHOD(XonoticMapList, loadCvars, void(entity))
38 ATTRIB(XonoticMapList, typeToSearchString, string, string_null)
39 ATTRIB(XonoticMapList, typeToSearchTime, float, 0)
41 METHOD(XonoticMapList, destroy, void(entity))
43 ATTRIB(XonoticListBox, alphaBG, float, 0)
44 ENDCLASS(XonoticMapList)
45 entity makeXonoticMapList();
46 void MapList_All(entity btn, entity me);
47 void MapList_None(entity btn, entity me);
48 void MapList_LoadMap(entity btn, entity me);
52 void XonoticMapList_destroy(entity me)
57 entity makeXonoticMapList()
60 me = spawnXonoticMapList();
61 me.configureXonoticMapList(me);
65 void XonoticMapList_configureXonoticMapList(entity me)
67 me.configureXonoticListBox(me);
71 void XonoticMapList_loadCvars(entity me)
76 float XonoticMapList_g_maplistCacheQuery(entity me, float i)
78 return stof(substring(me.g_maplistCache, i, 1));
80 void XonoticMapList_g_maplistCacheToggle(entity me, float i)
82 string a, b, c, s, bspname;
84 s = me.g_maplistCache;
87 b = substring(s, i, 1);
93 return; // nothing happens
94 a = substring(s, 0, i);
95 c = substring(s, i+1, strlen(s) - (i+1));
97 me.g_maplistCache = strzone(strcat(a, b, c));
98 // TODO also update the actual cvar
99 if (!((bspname = MapInfo_BSPName_ByID(i))))
102 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
106 n = tokenize_console(cvar_string("g_maplist"));
107 for(i = 0; i < n; ++i)
108 if(argv(i) != bspname)
109 s = strcat(s, " ", argv(i));
110 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
114 void XonoticMapList_draw(entity me)
117 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
118 SUPER(XonoticMapList).draw(me);
121 void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
123 me.itemAbsSize = '0 0 0';
124 SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
126 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
127 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
128 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
129 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
131 me.columnPreviewOrigin = 0;
132 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
133 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
134 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
136 me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
137 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
140 void XonoticMapList_clickListBoxItem(entity me, float i, vector where)
142 if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize)
145 m_play_click_sound(MENU_SOUND_SELECT);
146 me.g_maplistCacheToggle(me, i);
150 void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where)
152 if(where.x >= me.columnNameOrigin)
155 // pop up map info screen
156 m_play_click_sound(MENU_SOUND_OPEN);
157 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me);
158 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));
162 void XonoticMapList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
164 // layout: Ping, Map name, Map name, NP, TP, MP
169 if(!MapInfo_Get_ByID(i))
172 included = me.g_maplistCacheQuery(me, i);
173 if(included || isSelected)
174 theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG;
176 theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG;
179 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
181 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
183 if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
184 draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
186 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
189 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
190 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_titlestring), me.columnNameSize, 0, me.realFontSize);
191 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);
192 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_author), me.columnNameSize, 0, me.realFontSize);
193 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);
195 MapInfo_ClearTemps();
198 void XonoticMapList_refilter(entity me)
203 gt = MapInfo_CurrentGametype();
204 f = MapInfo_CurrentFeatures();
205 MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
206 me.nItems = MapInfo_count;
207 for(i = 0; i < MapInfo_count; ++i)
208 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
209 if(me.g_maplistCache)
210 strunzone(me.g_maplistCache);
212 for(i = 1; i < MapInfo_count; i *= 2)
214 n = tokenize_console(cvar_string("g_maplist"));
215 for(i = 0; i < n; ++i)
217 j = MapInfo_FindName(argv(i));
222 substring(s, j+1, MapInfo_count - (j+1))
225 me.g_maplistCache = strzone(s);
226 if(gt != me.lastGametype || f != me.lastFeatures)
228 me.lastGametype = gt;
230 me.setSelected(me, 0);
234 void XonoticMapList_refilterCallback(entity me, entity cb)
239 void MapList_All(entity btn, entity me)
243 MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0); // all
245 for(i = 0; i < MapInfo_count; ++i)
246 s = strcat(s, " ", MapInfo_BSPName_ByID(i));
247 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
251 void MapList_None(entity btn, entity me)
253 cvar_set("g_maplist", "");
257 void MapList_LoadMap(entity btn, entity me)
264 if(btn.parent.instanceOfXonoticMapInfoDialog)
266 i = btn.parent.currentMapIndex;
267 Dialog_Close(btn, btn.parent);
270 if(i >= me.nItems || i < 0)
273 m = MapInfo_BSPName_ByID(i);
276 print(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"));
280 if(MapInfo_CheckMap(m))
282 localcmd("\nmenu_loadmap_prepare\n");
283 if(cvar("menu_use_default_hostname"))
284 localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n");
285 MapInfo_LoadMap(m, 1);
289 print(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"));
295 float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
299 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
300 if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER)
302 // pop up map info screen
303 m_play_click_sound(MENU_SOUND_OPEN);
304 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me);
305 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));
307 else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS)
309 m_play_click_sound(MENU_SOUND_SELECT);
310 me.g_maplistCacheToggle(me, me.selectedItem);
312 else if(ascii == 43) // +
314 if (!me.g_maplistCacheQuery(me, me.selectedItem))
316 m_play_click_sound(MENU_SOUND_SELECT);
317 me.g_maplistCacheToggle(me, me.selectedItem);
320 else if(ascii == 45) // -
322 if(me.g_maplistCacheQuery(me, me.selectedItem))
324 m_play_click_sound(MENU_SOUND_SELECT);
325 me.g_maplistCacheToggle(me, me.selectedItem);
328 else if(scan == K_BACKSPACE)
330 if(time < me.typeToSearchTime)
332 save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
333 if(me.typeToSearchString)
334 strunzone(me.typeToSearchString);
335 me.typeToSearchString = strzone(save);
336 me.typeToSearchTime = time + 0.5;
337 if(strlen(me.typeToSearchString))
339 MapInfo_FindName(me.typeToSearchString);
340 if(MapInfo_FindName_firstResult >= 0)
341 me.setSelected(me, MapInfo_FindName_firstResult);
345 else if(ascii >= 32 && ascii != 127)
348 if(time > me.typeToSearchTime)
351 save = strcat(me.typeToSearchString, ch);
352 if(me.typeToSearchString)
353 strunzone(me.typeToSearchString);
354 me.typeToSearchString = strzone(save);
355 me.typeToSearchTime = time + 0.5;
356 MapInfo_FindName(me.typeToSearchString);
357 if(MapInfo_FindName_firstResult >= 0)
358 me.setSelected(me, MapInfo_FindName_firstResult);
361 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);