-#ifdef INTERFACE
-CLASS(XonoticMapList) EXTENDS(XonoticListBox)
- METHOD(XonoticMapList, configureXonoticMapList, void(entity))
+#ifndef MAPLIST_H
+#define MAPLIST_H
+#include "listbox.qc"
+CLASS(XonoticMapList, XonoticListBox)
+ METHOD(XonoticMapList, configureXonoticMapList, void(entity));
ATTRIB(XonoticMapList, rowsPerItem, float, 4)
- METHOD(XonoticMapList, draw, void(entity))
- METHOD(XonoticMapList, drawListBoxItem, void(entity, float, vector, float))
- METHOD(XonoticMapList, clickListBoxItem, void(entity, float, vector))
- METHOD(XonoticMapList, doubleClickListBoxItem, void(entity, float, vector))
- METHOD(XonoticMapList, resizeNotify, void(entity, vector, vector, vector, vector))
- METHOD(XonoticMapList, refilter, void(entity))
- METHOD(XonoticMapList, refilterCallback, void(entity, entity))
- METHOD(XonoticMapList, keyDown, float(entity, float, float, float))
+ METHOD(XonoticMapList, draw, void(entity));
+ METHOD(XonoticMapList, drawListBoxItem, void(entity, int, vector, bool, bool));
+ METHOD(XonoticMapList, clickListBoxItem, void(entity, float, vector));
+ METHOD(XonoticMapList, doubleClickListBoxItem, void(entity, float, vector));
+ METHOD(XonoticMapList, resizeNotify, void(entity, vector, vector, vector, vector));
+ METHOD(XonoticMapList, refilter, void(entity));
+ METHOD(XonoticMapList, refilterCallback, void(entity, entity));
+ METHOD(XonoticMapList, keyDown, float(entity, float, float, float));
ATTRIB(XonoticMapList, realFontSize, vector, '0 0 0')
ATTRIB(XonoticMapList, columnPreviewOrigin, float, 0)
ATTRIB(XonoticMapList, itemAbsSize, vector, '0 0 0')
ATTRIB(XonoticMapList, g_maplistCache, string, string_null)
- METHOD(XonoticMapList, g_maplistCacheToggle, void(entity, float))
- METHOD(XonoticMapList, g_maplistCacheQuery, float(entity, float))
+ METHOD(XonoticMapList, g_maplistCacheToggle, void(entity, float));
+ METHOD(XonoticMapList, g_maplistCacheQuery, float(entity, float));
+
+ ATTRIB(XonoticMapList, stringFilter, string, string_null)
+ ATTRIB(XonoticMapList, stringFilterBox, entity, NULL)
ATTRIB(XonoticMapList, startButton, entity, NULL)
- METHOD(XonoticMapList, loadCvars, void(entity))
+ METHOD(XonoticMapList, loadCvars, void(entity));
ATTRIB(XonoticMapList, typeToSearchString, string, string_null)
ATTRIB(XonoticMapList, typeToSearchTime, float, 0)
- METHOD(XonoticMapList, destroy, void(entity))
+ METHOD(XonoticMapList, destroy, void(entity));
- ATTRIB(XonoticListBox, alphaBG, float, 0)
+ ATTRIB(XonoticMapList, alphaBG, float, 0)
ENDCLASS(XonoticMapList)
entity makeXonoticMapList();
-void MapList_All(entity btn, entity me);
-void MapList_None(entity btn, entity me);
+void MapList_StringFilterBox_Change(entity box, entity me);
+float MapList_StringFilterBox_keyDown(entity me, float key, float ascii, float shift);
+void MapList_Add_Shown(entity btn, entity me);
+void MapList_Remove_Shown(entity btn, entity me);
+void MapList_Add_All(entity btn, entity me);
+void MapList_Remove_All(entity btn, entity me);
void MapList_LoadMap(entity btn, entity me);
#endif
entity makeXonoticMapList()
{
entity me;
- me = spawnXonoticMapList();
+ me = NEW(XonoticMapList);
me.configureXonoticMapList(me);
return me;
}
+entity MapList_Set_String_Filter_Box(entity me, entity e)
+{
+ me.stringFilterBox = e;
+ return e;
+}
+
void XonoticMapList_configureXonoticMapList(entity me)
{
me.configureXonoticListBox(me);
me.refilter(me);
}
+
float XonoticMapList_g_maplistCacheQuery(entity me, float i)
{
return stof(substring(me.g_maplistCache, i, 1));
me.itemAbsSize = '0 0 0';
SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
- me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
- me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
- me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize_y);
- me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize_y;
+ me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
+ me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
+ me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
+ me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
me.columnPreviewOrigin = 0;
- me.columnPreviewSize = me.itemAbsSize_y / me.itemAbsSize_x * 4 / 3;
- me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize_x;
- me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize_x;
+ me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
+ me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
+ me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
- me.checkMarkSize = (eX * (me.itemAbsSize_y / me.itemAbsSize_x) + eY) * 0.5;
+ me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
me.checkMarkOrigin = eY + eX * (me.columnPreviewOrigin + me.columnPreviewSize) - me.checkMarkSize;
}
void XonoticMapList_clickListBoxItem(entity me, float i, vector where)
{
- if(where_x <= me.columnPreviewOrigin + me.columnPreviewSize)
- if(where_x >= 0)
+ if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize)
+ if(where.x >= 0)
+ {
+ m_play_click_sound(MENU_SOUND_SELECT);
me.g_maplistCacheToggle(me, i);
+ }
}
void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where)
{
- if(where_x >= me.columnNameOrigin)
- if(where_x <= 1)
+ if(where.x >= me.columnNameOrigin)
+ if(where.x <= 1)
{
// pop up map info screen
+ m_play_click_sound(MENU_SOUND_OPEN);
main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me);
- 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));
+ 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));
}
}
-void XonoticMapList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
+void XonoticMapList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
{
// layout: Ping, Map name, Map name, NP, TP, MP
string s;
if(isSelected)
draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
- else if(included)
- draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
+ else
+ {
+ if(included)
+ draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG);
+ if(isFocused)
+ {
+ me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
+ draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
+ }
+ }
if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
gt = MapInfo_CurrentGametype();
f = MapInfo_CurrentFeatures();
MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
+ if (me.stringFilter)
+ MapInfo_FilterString(me.stringFilter);
me.nItems = MapInfo_count;
+
for(i = 0; i < MapInfo_count; ++i)
draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
if(me.g_maplistCache)
{
j = MapInfo_FindName(argv(i));
if(j >= 0)
- s = strcat(
- substring(s, 0, j),
- "1",
- substring(s, j+1, MapInfo_count - (j+1))
- );
+ {
+ // double check that the two mapnames are "identical", not just share the same prefix
+ if (strlen(MapInfo_BSPName_ByID(j)) == strlen(argv(i)))
+ s = strcat(
+ substring(s, 0, j),
+ "1",
+ substring(s, j+1, MapInfo_count - (j+1))
+ );
+ }
}
me.g_maplistCache = strzone(s);
if(gt != me.lastGametype || f != me.lastFeatures)
me.refilter(me);
}
-void MapList_All(entity btn, entity me)
+void MapList_StringFilterBox_Change(entity box, entity me)
+{
+ if(me.stringFilter)
+ strunzone(me.stringFilter);
+ if(box.text != "")
+ me.stringFilter = strzone(box.text);
+ else
+ me.stringFilter = string_null;
+
+ me.refilter(me);
+}
+
+void MapList_Add_Shown(entity btn, entity me)
+{
+ float i, n;
+ n = strlen(me.g_maplistCache);
+ for (i = 0 ; i < n; i++)
+ {
+ if (!me.g_maplistCacheQuery(me, i))
+ me.g_maplistCacheToggle(me, i);
+ }
+ me.refilter(me);
+}
+
+void MapList_Remove_Shown(entity btn, entity me)
+{
+ float i, n;
+ n = strlen(me.g_maplistCache);
+ for (i = 0 ; i < n; i++)
+ {
+ if (me.g_maplistCacheQuery(me, i))
+ me.g_maplistCacheToggle(me, i);
+ }
+ me.refilter(me);
+}
+
+void MapList_Add_All(entity btn, entity me)
{
float i;
string s;
me.refilter(me);
}
-void MapList_None(entity btn, entity me)
+void MapList_Remove_All(entity btn, entity me)
{
cvar_set("g_maplist", "");
me.refilter(me);
m = MapInfo_BSPName_ByID(i);
if (!m)
{
- print(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"));
+ LOG_INFO(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"));
me.refilter(me);
return;
}
}
else
{
- print(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"));
+ LOG_INFO(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"));
me.refilter(me);
return;
}
if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER)
{
// pop up map info screen
+ m_play_click_sound(MENU_SOUND_OPEN);
main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me);
- 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));
+ 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));
}
else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS)
{
+ m_play_click_sound(MENU_SOUND_SELECT);
me.g_maplistCacheToggle(me, me.selectedItem);
}
else if(ascii == 43) // +
{
if (!me.g_maplistCacheQuery(me, me.selectedItem))
+ {
+ m_play_click_sound(MENU_SOUND_SELECT);
me.g_maplistCacheToggle(me, me.selectedItem);
+ }
}
else if(ascii == 45) // -
{
if(me.g_maplistCacheQuery(me, me.selectedItem))
+ {
+ m_play_click_sound(MENU_SOUND_SELECT);
me.g_maplistCacheToggle(me, me.selectedItem);
+ }
}
else if(scan == K_BACKSPACE)
{
if(MapInfo_FindName_firstResult >= 0)
me.setSelected(me, MapInfo_FindName_firstResult);
}
+ else if(shift & S_CTRL && scan == 'f') // ctrl-f (as in "F"ind)
+ {
+ me.parent.setFocus(me.parent, me.stringFilterBox);
+ }
+ else if(shift & S_CTRL && scan == 'u') // ctrl-u (remove stringFilter line
+ {
+ me.stringFilterBox.setText(me.stringFilterBox, "");
+ MapList_StringFilterBox_Change(me.stringFilterBox, me);
+ }
else
return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift);
return 1;
}
+float MapList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift)
+{
+ // in this section, note that onChangeEntity has the ref to mapListBox
+ // we make use of that, instead of extending a class to add one more attrib
+ switch(scan)
+ {
+ case K_KP_ENTER:
+ case K_ENTER:
+ // move the focus to the mapListBox
+ me.onChangeEntity.parent.setFocus(me.onChangeEntity.parent, me.onChangeEntity);
+ return 1;
+ case K_KP_UPARROW:
+ case K_UPARROW:
+ case K_KP_DOWNARROW:
+ case K_DOWNARROW:
+ // pass the event to the mapListBox (to scroll up and down)
+ return me.onChangeEntity.keyDown(me.onChangeEntity, scan, ascii, shift);
+ }
+ return SUPER(XonoticInputBox).keyDown(me, scan, ascii, shift);
+}
#endif