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))
11 ATTRIB(NexuizMapList, realFontSize, vector, '0 0 0')
12 ATTRIB(NexuizMapList, columnPreviewOrigin, float, 0)
13 ATTRIB(NexuizMapList, columnPreviewSize, float, 0)
14 ATTRIB(NexuizMapList, columnNameOrigin, float, 0)
15 ATTRIB(NexuizMapList, columnNameSize, float, 0)
16 ATTRIB(NexuizMapList, checkMarkOrigin, vector, '0 0 0')
17 ATTRIB(NexuizMapList, checkMarkSize, vector, '0 0 0')
18 ATTRIB(NexuizMapList, realUpperMargin1, float, 0)
19 ATTRIB(NexuizMapList, realUpperMargin2, float, 0)
21 ATTRIB(NexuizMapList, lastClickedMap, float, -1)
22 ATTRIB(NexuizMapList, lastClickedTime, float, 0)
24 ATTRIB(NexuizMapList, lastGametype, float, 0)
25 ATTRIB(NexuizMapList, lastFeatures, float, 0)
27 ATTRIB(NexuizMapList, origin, vector, '0 0 0')
28 ATTRIB(NexuizMapList, itemAbsSize, vector, '0 0 0')
30 ATTRIB(NexuizMapList, g_maplistCache, string, string_null)
31 METHOD(NexuizMapList, g_maplistCacheToggle, void(entity, float))
32 METHOD(NexuizMapList, g_maplistCacheQuery, float(entity, float))
34 ATTRIB(NexuizMapList, startButton, entity, NULL)
36 ATTRIB(NexuizMapList, cvarName, string, "dummy")
37 METHOD(NexuizMapList, loadCvars, void(entity))
38 ENDCLASS(NexuizMapList)
39 entity makeNexuizMapList();
40 void MapList_All(entity btn, entity me);
41 void MapList_None(entity btn, entity me);
42 void MapList_LoadMap(entity btn, entity me);
46 entity makeNexuizMapList()
49 me = spawnNexuizMapList();
50 me.configureNexuizMapList(me);
53 void configureNexuizMapListNexuizMapList(entity me)
55 me.configureNexuizListBox(me);
59 void loadCvarsNexuizMapList(entity me)
64 float g_maplistCacheQueryNexuizMapList(entity me, float i)
66 return stof(substring(me.g_maplistCache, i, 1));
68 void g_maplistCacheToggleNexuizMapList(entity me, float i)
70 string a, b, c, s, bspname;
72 s = me.g_maplistCache;
75 b = substring(s, i, 1);
81 return; // nothing happens
82 a = substring(s, 0, i);
83 c = substring(s, i+1, strlen(s) - (i+1));
85 me.g_maplistCache = strzone(strcat(a, b, c));
86 // TODO also update the actual cvar
87 if not((bspname = MapInfo_BSPName_ByID(i)))
90 cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist")));
94 n = tokenize(cvar_string("g_maplist"));
95 for(i = 0; i < n; ++i)
96 if(argv(i) != bspname)
97 s = strcat(s, " ", argv(i));
98 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
102 void drawNexuizMapList(entity me)
105 me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
109 void resizeNotifyNexuizMapList(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
111 me.origin = absOrigin;
112 me.itemAbsSize = '0 0 0';
113 resizeNotifyNexuizListBox(me, relOrigin, relSize, absOrigin, absSize);
115 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
116 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
117 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize_y);
118 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize_y;
120 me.columnPreviewOrigin = 0;
121 me.columnPreviewSize = me.itemAbsSize_y / me.itemAbsSize_x * 4 / 3;
122 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize_x;
123 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize_x;
125 me.checkMarkSize = (eX * (me.itemAbsSize_y / me.itemAbsSize_x) + eY) * 0.5;
126 me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
128 void clickListBoxItemNexuizMapList(entity me, float i, vector where)
130 if(where_x <= me.columnPreviewOrigin + me.columnPreviewSize)
133 me.g_maplistCacheToggle(me, i);
135 if(where_x >= me.columnNameOrigin)
138 if(i == me.lastClickedMap)
139 if(time < me.lastClickedTime + 0.3)
142 // pop up map info screen
143 main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i);
144 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));
147 me.lastClickedMap = i;
148 me.lastClickedTime = time;
151 void drawListBoxItemNexuizMapList(entity me, float i, vector absSize, float isSelected)
153 // layout: Ping, Map name, Map name, NP, TP, MP
162 if(!MapInfo_Get_ByID(i))
165 included = me.g_maplistCacheQuery(me, i);
172 draw_Fill('0 0 0', '1 1 0', '0 0 1', 0.5);
174 draw_Fill('0 0 0', '1 1 0', '0 0 0', 0.5);
177 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
179 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
180 s = draw_TextShortenToWidth(strcat(MapInfo_Map_bspname, ": ", MapInfo_Map_title), me.columnNameSize / me.realFontSize_x, 0);
181 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);
182 s = draw_TextShortenToWidth(MapInfo_Map_author, me.columnNameSize / me.realFontSize_x, 0);
183 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);
186 void refilterNexuizMapList(entity me)
191 gt = MapInfo_CurrentGametype();
192 f = MapInfo_CurrentFeatures();
193 MapInfo_FilterGametype(gt, f, 0);
194 me.nItems = MapInfo_count;
195 for(i = 0; i < MapInfo_count; ++i)
196 draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
197 if(me.g_maplistCache)
198 strunzone(me.g_maplistCache);
200 for(i = 1; i < MapInfo_count; i *= 2)
202 n = tokenize(cvar_string("g_maplist"));
203 for(i = 0; i < n; ++i)
205 j = MapInfo_FindName(argv(i));
210 substring(s, j+1, MapInfo_count - (j+1))
213 me.g_maplistCache = strzone(s);
214 if(gt != me.lastGametype || f != me.lastFeatures)
216 me.lastGametype = gt;
218 me.setSelected(me, 0);
221 void MapList_All(entity btn, entity me)
225 MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0); // all
227 for(i = 0; i < MapInfo_count; ++i)
228 s = strcat(s, " ", MapInfo_BSPName_ByID(i));
229 cvar_set("g_maplist", substring(s, 1, strlen(s) - 1));
232 void MapList_None(entity btn, entity me)
234 cvar_set("g_maplist", "");
237 void MapList_LoadMap(entity btn, entity me)
240 if(me.selectedItem >= me.nItems || me.selectedItem < 0)
242 m = MapInfo_BSPName_ByID(me.selectedItem);
245 if(MapInfo_CheckMap(m))
251 print("Huh? Can't play this. Refiltering so this won't happen again.\n");