3 #include <common/mapinfo.qh>
4 #include "dialog_multiplayer_create_mapinfo.qh"
5 #include "mainwindow.qh"
10 void XonoticMapList_destroy(entity me)
15 entity makeXonoticMapList()
18 me = NEW(XonoticMapList);
19 me.configureXonoticMapList(me);
23 entity MapList_Set_String_Filter_Box(entity me, entity e)
25 me.stringFilterBox = e;
29 void XonoticMapList_configureXonoticMapList(entity me)
31 me.configureXonoticListBox(me);
35 void XonoticMapList_loadCvars(entity me)
41 float XonoticMapList_g_maplistCacheQuery(entity me, float i)
43 return stof(substring(me.g_maplistCache, i, 1));
45 void XonoticMapList_g_maplistCacheToggle(entity me, float i)
47 string a, b, c, s, bspname;
49 s = me.g_maplistCache;
52 b = substring(s, i, 1);
58 return; // nothing happens
59 a = substring(s, 0, i);
60 c = substring(s, i+1, strlen(s) - (i+1));
62 me.g_maplistCache = strzone(strcat(a, b, c));
63 // TODO also update the actual cvar
64 if (!((bspname = MapInfo_BSPName_ByID(i))))
67 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
71 n = tokenize_console(cvar_string("g_maplist"));
72 for(i = 0; i < n; ++i)
73 if(argv(i) != bspname)
74 s = strcat(s, " ", argv(i));
75 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
79 void XonoticMapList_draw(entity me)
82 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems)
83 || ((gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) && cvar("g_campaign")));
84 SUPER(XonoticMapList).draw(me);
87 void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
89 me.itemAbsSize = '0 0 0';
90 SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
92 me.itemAbsSize.y = absSize.y * me.itemHeight;
93 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
94 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
95 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
96 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
97 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
99 me.columnPreviewOrigin = 0;
100 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
101 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
102 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
104 me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
105 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
108 void XonoticMapList_clickListBoxItem(entity me, float i, vector where)
110 if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize)
113 m_play_click_sound(MENU_SOUND_SELECT);
114 me.g_maplistCacheToggle(me, i);
118 void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where)
120 if(where.x >= me.columnNameOrigin)
123 // pop up map info screen
124 m_play_click_sound(MENU_SOUND_OPEN);
125 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me);
126 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));
130 void XonoticMapList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
132 // layout: Ping, Map name, Map name, NP, TP, MP
137 if(!MapInfo_Get_ByID(i))
140 included = me.g_maplistCacheQuery(me, i);
141 if(included || isSelected)
142 theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG;
144 theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG;
147 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
151 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
154 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
155 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
159 if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
161 if(!draw_PictureExists(strcat("/levelshots/", MapInfo_Map_bspname)))
162 draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
164 draw_Picture(me.columnPreviewOrigin * eX, strcat("/levelshots/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
167 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
170 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
171 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_titlestring), me.columnNameSize, 0, me.realFontSize);
172 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);
173 s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_author), me.columnNameSize, 0, me.realFontSize);
174 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);
176 MapInfo_ClearTemps();
179 void XonoticMapList_refilter(entity me)
183 Gametype gt = MapInfo_CurrentGametype();
184 int f = MapInfo_CurrentFeatures();
185 MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
187 MapInfo_FilterString(me.stringFilter);
188 me.nItems = MapInfo_count;
190 for(i = 0; i < MapInfo_count; ++i)
191 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
193 for(i = 1; i < MapInfo_count; i *= 2)
195 n = tokenize_console(cvar_string("g_maplist"));
196 for(i = 0; i < n; ++i)
198 j = MapInfo_FindName(argv(i));
201 // double check that the two mapnames are "identical", not just share the same prefix
202 if (strlen(MapInfo_BSPName_ByID(j)) == strlen(argv(i)))
206 substring(s, j+1, MapInfo_count - (j+1))
210 strcpy(me.g_maplistCache, s);
211 if(gt != me.lastGametype || f != me.lastFeatures)
213 me.lastGametype = gt;
215 me.setSelected(me, 0);
219 void XonoticMapList_refilterCallback(entity me, entity cb)
224 void MapList_StringFilterBox_Change(entity box, entity me)
226 strfree(me.stringFilter);
228 me.stringFilter = strzone(box.text);
233 void MapList_Add_Shown(entity btn, entity me)
236 n = strlen(me.g_maplistCache);
237 for (i = 0 ; i < n; ++i)
239 if (!me.g_maplistCacheQuery(me, i))
240 me.g_maplistCacheToggle(me, i);
245 void MapList_Remove_Shown(entity btn, entity me)
248 n = strlen(me.g_maplistCache);
249 for (i = 0 ; i < n; ++i)
251 if (me.g_maplistCacheQuery(me, i))
252 me.g_maplistCacheToggle(me, i);
257 void MapList_Add_All(entity btn, entity me)
261 _MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0); // all
263 for(i = 0; i < MapInfo_count; ++i)
264 s = cons(s, MapInfo_BSPName_ByID(i));
265 cvar_set("g_maplist", s);
269 void MapList_Remove_All(entity btn, entity me)
271 cvar_set("g_maplist", "");
275 void MapList_LoadMap(entity btn, entity me)
282 if(btn.parent.instanceOfXonoticMapInfoDialog)
284 i = btn.parent.currentMapIndex;
285 Dialog_Close(btn, btn.parent);
288 if(i >= me.nItems || i < 0)
291 m = MapInfo_BSPName_ByID(i);
294 LOG_INFO(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again."));
298 if(MapInfo_CheckMap(m))
300 localcmd("\nmenu_loadmap_prepare\n");
301 if(cvar("menu_use_default_hostname"))
302 localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n");
303 MapInfo_LoadMap(m, 1);
307 LOG_INFO(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again."));
313 float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
317 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
318 if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER)
320 // pop up map info screen
321 m_play_click_sound(MENU_SOUND_OPEN);
322 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me);
323 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));
325 else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS)
327 m_play_click_sound(MENU_SOUND_SELECT);
328 me.g_maplistCacheToggle(me, me.selectedItem);
330 else if(ascii == 43) // +
332 if (!me.g_maplistCacheQuery(me, me.selectedItem))
334 m_play_click_sound(MENU_SOUND_SELECT);
335 me.g_maplistCacheToggle(me, me.selectedItem);
338 else if(ascii == 45) // -
340 if(me.g_maplistCacheQuery(me, me.selectedItem))
342 m_play_click_sound(MENU_SOUND_SELECT);
343 me.g_maplistCacheToggle(me, me.selectedItem);
346 else if(scan == K_BACKSPACE)
348 if(time < me.typeToSearchTime)
350 save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
351 strcpy(me.typeToSearchString, save);
352 me.typeToSearchTime = time + 0.5;
353 if(strlen(me.typeToSearchString))
355 MapInfo_FindName(me.typeToSearchString);
356 if(MapInfo_FindName_firstResult >= 0)
357 me.setSelected(me, MapInfo_FindName_firstResult);
361 else if(ascii >= 32 && ascii != 127)
364 if(time > me.typeToSearchTime)
367 save = strcat(me.typeToSearchString, ch);
368 strcpy(me.typeToSearchString, save);
369 me.typeToSearchTime = time + 0.5;
370 MapInfo_FindName(me.typeToSearchString);
371 if(MapInfo_FindName_firstResult >= 0)
372 me.setSelected(me, MapInfo_FindName_firstResult);
374 else if((shift & S_CTRL) && scan == 'f') // ctrl-f (as in "F"ind)
376 me.parent.setFocus(me.parent, me.stringFilterBox);
378 else if((shift & S_CTRL) && scan == 'u') // ctrl-u (remove stringFilter line
380 me.stringFilterBox.setText(me.stringFilterBox, "");
381 MapList_StringFilterBox_Change(me.stringFilterBox, me);
384 return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
388 float MapList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift)
390 // in this section, note that onChangeEntity has the ref to mapListBox
391 // we make use of that, instead of extending a class to add one more attrib
396 // move the focus to the mapListBox
397 me.onChangeEntity.parent.setFocus(me.onChangeEntity.parent, me.onChangeEntity);
403 // pass the event to the mapListBox (to scroll up and down)
404 return me.onChangeEntity.keyDown(me.onChangeEntity, scan, ascii, shift);
406 return SUPER(XonoticInputBox).keyDown(me, scan, ascii, shift);