2 CLASS(NexuizMapList) EXTENDS(NexuizListBox)
3 METHOD(NexuizMapList, configureNexuizMapList, void(entity))
4 ATTRIB(NexuizMapList, rowsPerItem, float, 4)
5 METHOD(NexuizMapList, draw, void(entity))
6 METHOD(NexuizMapList, drawListBoxItem, void(entity, float, vector, float))
7 METHOD(NexuizMapList, clickListBoxItem, void(entity, float, vector))
8 METHOD(NexuizMapList, resizeNotify, void(entity, vector, vector, vector, vector))
9 METHOD(NexuizMapList, refilter, void(entity))
10 METHOD(NexuizMapList, keyDown, float(entity, float, float, float))
12 ATTRIB(NexuizMapList, realFontSize, vector, '0 0 0')
13 ATTRIB(NexuizMapList, columnPreviewOrigin, float, 0)
14 ATTRIB(NexuizMapList, columnPreviewSize, float, 0)
15 ATTRIB(NexuizMapList, columnNameOrigin, float, 0)
16 ATTRIB(NexuizMapList, columnNameSize, float, 0)
17 ATTRIB(NexuizMapList, checkMarkOrigin, vector, '0 0 0')
18 ATTRIB(NexuizMapList, checkMarkSize, vector, '0 0 0')
19 ATTRIB(NexuizMapList, realUpperMargin1, float, 0)
20 ATTRIB(NexuizMapList, realUpperMargin2, float, 0)
22 ATTRIB(NexuizMapList, lastClickedMap, float, -1)
23 ATTRIB(NexuizMapList, lastClickedTime, float, 0)
25 ATTRIB(NexuizMapList, lastGametype, float, 0)
26 ATTRIB(NexuizMapList, lastFeatures, float, 0)
28 ATTRIB(NexuizMapList, origin, vector, '0 0 0')
29 ATTRIB(NexuizMapList, itemAbsSize, vector, '0 0 0')
31 ATTRIB(NexuizMapList, g_maplistCache, string, string_null)
32 METHOD(NexuizMapList, g_maplistCacheToggle, void(entity, float))
33 METHOD(NexuizMapList, g_maplistCacheQuery, float(entity, float))
35 ATTRIB(NexuizMapList, startButton, entity, NULL)
37 ATTRIB(NexuizMapList, cvarName, string, "dummy")
38 METHOD(NexuizMapList, loadCvars, void(entity))
39 ENDCLASS(NexuizMapList)
40 entity makeNexuizMapList();
41 void MapList_All(entity btn, entity me);
42 void MapList_None(entity btn, entity me);
43 void MapList_LoadMap(entity btn, entity me);
47 entity makeNexuizMapList()
50 me = spawnNexuizMapList();
51 me.configureNexuizMapList(me);
54 void configureNexuizMapListNexuizMapList(entity me)
56 me.configureNexuizListBox(me);
60 void loadCvarsNexuizMapList(entity me)
65 float g_maplistCacheQueryNexuizMapList(entity me, float i)
67 return stof(substring(me.g_maplistCache, i, 1));
69 void g_maplistCacheToggleNexuizMapList(entity me, float i)
71 string a, b, c, s, bspname;
73 s = me.g_maplistCache;
76 b = substring(s, i, 1);
82 return; // nothing happens
83 a = substring(s, 0, i);
84 c = substring(s, i+1, strlen(s) - (i+1));
86 me.g_maplistCache = strzone(strcat(a, b, c));
87 // TODO also update the actual cvar
88 if not((bspname = MapInfo_BSPName_ByID(i)))
91 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
95 n = tokenize(cvar_string("g_maplist"));
96 for(i = 0; i < n; ++i)
97 if(argv(i) != bspname)
98 s = strcat(s, " ", argv(i));
99 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
103 void drawNexuizMapList(entity me)
106 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
110 void resizeNotifyNexuizMapList(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
112 me.origin = absOrigin;
113 me.itemAbsSize = '0 0 0';
114 resizeNotifyNexuizListBox(me, relOrigin, relSize, absOrigin, absSize);
116 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
117 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
118 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize_y);
119 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize_y;
121 me.columnPreviewOrigin = 0;
122 me.columnPreviewSize = me.itemAbsSize_y / me.itemAbsSize_x * 4 / 3;
123 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize_x;
124 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize_x;
126 me.checkMarkSize = (eX * (me.itemAbsSize_y / me.itemAbsSize_x) + eY) * 0.5;
127 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
129 void clickListBoxItemNexuizMapList(entity me, float i, vector where)
131 if(where_x <= me.columnPreviewOrigin + me.columnPreviewSize)
134 me.g_maplistCacheToggle(me, i);
136 if(where_x >= me.columnNameOrigin)
139 if(i == me.lastClickedMap)
140 if(time < me.lastClickedTime + 0.3)
143 // pop up map info screen
144 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i);
145 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));
148 me.lastClickedMap = i;
149 me.lastClickedTime = time;
152 void drawListBoxItemNexuizMapList(entity me, float i, vector absSize, float isSelected)
154 // layout: Ping, Map name, Map name, NP, TP, MP
160 if(!MapInfo_Get_ByID(i))
163 included = me.g_maplistCacheQuery(me, i);
165 theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG;
167 theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG;
170 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
172 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
175 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
177 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
178 s = draw_TextShortenToWidth(strcat(MapInfo_Map_bspname, ": ", MapInfo_Map_title), me.columnNameSize / me.realFontSize_x, 0);
179 draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_TITLE, theAlpha, 0);
180 s = draw_TextShortenToWidth(MapInfo_Map_author, me.columnNameSize / me.realFontSize_x, 0);
181 draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_AUTHOR, theAlpha, 0);
184 void refilterNexuizMapList(entity me)
189 gt = MapInfo_CurrentGametype();
190 f = MapInfo_CurrentFeatures();
191 MapInfo_FilterGametype(gt, f, 0);
192 me.nItems = MapInfo_count;
193 for(i = 0; i < MapInfo_count; ++i)
194 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
195 if(me.g_maplistCache)
196 strunzone(me.g_maplistCache);
198 for(i = 1; i < MapInfo_count; i *= 2)
200 n = tokenize(cvar_string("g_maplist"));
201 for(i = 0; i < n; ++i)
203 j = MapInfo_FindName(argv(i));
208 substring(s, j+1, MapInfo_count - (j+1))
211 me.g_maplistCache = strzone(s);
212 if(gt != me.lastGametype || f != me.lastFeatures)
214 me.lastGametype = gt;
216 me.setSelected(me, 0);
219 void MapList_All(entity btn, entity me)
223 MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0); // all
225 for(i = 0; i < MapInfo_count; ++i)
226 s = strcat(s, " ", MapInfo_BSPName_ByID(i));
227 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
230 void MapList_None(entity btn, entity me)
232 cvar_set("g_maplist", "");
235 void MapList_LoadMap(entity btn, entity me)
238 if(me.selectedItem >= me.nItems || me.selectedItem < 0)
240 m = MapInfo_BSPName_ByID(me.selectedItem);
243 if(MapInfo_CheckMap(m))
245 localcmd("\ndisconnect\nwait\nmaxplayers $menu_maxplayers\ng_maplist_shufflenow\n");
250 print("Huh? Can't play this. Refiltering so this won't happen again.\n");
255 float keyDownNexuizMapList(entity me, float scan, float ascii, float shift)
259 // pop up map info screen
260 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem);
261 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));
263 else if(scan == K_SPACE)
265 me.g_maplistCacheToggle(me, me.selectedItem);
267 else if(ascii == 43) // +
269 if not(me.g_maplistCacheQuery(me, me.selectedItem))
270 me.g_maplistCacheToggle(me, me.selectedItem);
272 else if(ascii == 45) // -
274 if(me.g_maplistCacheQuery(me, me.selectedItem))
275 me.g_maplistCacheToggle(me, me.selectedItem);
278 return keyDownListBox(me, scan, ascii, shift);