From: otta8634 Date: Tue, 7 Jan 2025 11:51:53 +0000 (+0800) Subject: Allow use of ctrl+F and ctrl+U in guide filter X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5d5e5924130ea9c800713c8edb067324b2f178c6;p=xonotic%2Fxonotic-data.pk3dir.git Allow use of ctrl+F and ctrl+U in guide filter The filtering still doesn't work yet. Also cleaned up guide tab fill function, and some other code. Made the guide XonoticEntryList not have to refer to XonoticMapList. --- diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc index b3c2c432f3..74f9fe4791 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc @@ -1,47 +1,44 @@ #include "dialog_multiplayer_media_guide.qh" #include "inputbox.qh" -#include "maplist.qh" #include "textlabel.qh" +#include void XonoticGuideTab_fill(entity me) { - entity topics = me.topicList; - topics.onChange = XonoticGuideTab_topicChangeNotify; - topics.onChangeEntity = me; - entity entries = me.entryList; - entries.onChange = XonoticGuideTab_entryChangeNotify; - entries.onChangeEntity = me; - entity filter = entries.stringFilterBox = makeXonoticInputBox(false, string_null); - filter.keyDown = MapList_StringFilterBox_keyDown; - filter.onChange = MapList_StringFilterBox_Change; - filter.onChangeEntity = entries; - entries.controlledTextbox = filter; - entity description = me.descriptionPane; + entity e; - int - col = 0, width = 1.5; + int col = 0, width = 1.5; me.gotoRC(me, 0, col); me.TD(me, 1, width, makeXonoticHeaderLabel(_("Topic"))); me.TR(me); - me.TD(me, me.rows - 1, width, topics); + me.TD(me, me.rows - 1, width, e = me.topicList); + e.onChange = XonoticGuideTab_topicChangeNotify; + e.onChangeEntity = me; col += width, width = 2; me.gotoRC(me, 0, col); me.setFirstColumn(me, me.currentColumn); me.TD(me, 1, width, makeXonoticHeaderLabel(_("Entry"))); me.TR(me); - me.TD(me, me.rows - 1 - 1, width, entries); + me.TD(me, me.rows - 1 - 1, width, e = me.entryList); + e.onChange = XonoticGuideTab_entryChangeNotify; + e.onChangeEntity = me; me.gotoRC(me, me.rows - 1, col); + me.entryList.stringFilterBox = makeXonoticInputBox_T(false, string_null, + _("Click here or Ctrl-F to provide a keyword to narrow down the map list. Ctrl-Delete to clear; Enter when done.")); me.TD(me, 1, 0.3, makeXonoticTextLabel(0, _("Filter:"))); - me.TD(me, 1, width - 0.3, filter); + me.TD(me, 1, width - 0.3, e = me.entryList.stringFilterBox); + e.onChange = EntryList_StringFilterBox_Change; + e.keyDown = EntryList_StringFilterBox_keyDown; + e.onChangeEntity = me.entryList; col += width, width = 2.5; me.gotoRC(me, 0, col); me.setFirstColumn(me, me.currentColumn); me.TD(me, 1, width, makeXonoticHeaderLabel(_("Description"))); me.TR(me); - me.TD(me, me.rows - 1, width, description); + me.TD(me, me.rows - 1, width, me.descriptionPane); - me.topicChangeNotify(topics, me); + me.topicChangeNotify(me.topicList, me); } void XonoticGuideTab_topicChangeNotify(entity, entity me) diff --git a/qcsrc/menu/xonotic/guide/entries.qc b/qcsrc/menu/xonotic/guide/entries.qc index f801b30f7d..7fccb4cc3a 100644 --- a/qcsrc/menu/xonotic/guide/entries.qc +++ b/qcsrc/menu/xonotic/guide/entries.qc @@ -11,6 +11,12 @@ void XonoticEntryList_cb(string _name, string _icon) XonoticEntryList_cb_icon = _icon; } +entity EntryList_Set_StringFilterBox(entity me, entity e) +{ + me.stringFilterBox = e; + return e; +} + void XonoticEntryList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { if (!me.source) return; @@ -63,19 +69,39 @@ METHOD(XonoticEntryList, keyDown, float(entity this, float scan, float ascii, fl this.setSelected(this, idx); } } - else if (shift & S_CTRL && scan == 'f') + else if ((shift & S_CTRL) && scan == 'f') // ctrl-f (as in "F"ind) + { this.parent.setFocus(this.parent, this.stringFilterBox); - else if (shift & S_CTRL && scan == 'u') + } + else if ((shift & S_CTRL) && scan == 'u') // ctrl-u (remove stringFilter line) { this.stringFilterBox.setText(this.stringFilterBox, ""); - if (this.stringFilter) - strunzone(this.stringFilter); - this.stringFilter = string_null; - this.refilter(this); + EntryList_StringFilterBox_Change(this.stringFilterBox, this); } return SUPER(XonoticEntryList).keyDown(this, scan, ascii, shift); } +float EntryList_StringFilterBox_keyDown(entity me, float scan, float ascii, float shift) +{ + // in this section, note that onChangeEntity has the ref to entryList + // 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 entryList + 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 entryList (to scroll up and down) + return me.onChangeEntity.keyDown(me.onChangeEntity, scan, ascii, shift); + } + return SUPER(XonoticInputBox).keyDown(me, scan, ascii, shift); +} + void XonoticEntryList_refilter(entity me) { if (!me.source) @@ -89,6 +115,15 @@ void XonoticEntryList_refilter(entity me) draw_PreloadPicture(XonoticEntryList_cb_icon); } +void EntryList_StringFilterBox_Change(entity box, entity me) +{ + strfree(me.stringFilter); + if(box.text != "") + me.stringFilter = strzone(box.text); + + me.refilter(me); +} + void XonoticEntryList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { me.itemAbsSize = '0 0 0'; diff --git a/qcsrc/menu/xonotic/guide/entries.qh b/qcsrc/menu/xonotic/guide/entries.qh index 05e5691f8f..657d0e7a6f 100644 --- a/qcsrc/menu/xonotic/guide/entries.qh +++ b/qcsrc/menu/xonotic/guide/entries.qh @@ -10,6 +10,7 @@ CLASS(XonoticEntryList, XonoticListBox) ATTRIB(XonoticEntryList, realUpperMargin1, float, 0); ATTRIB(XonoticEntryList, realUpperMargin2, float, 0); ATTRIB(XonoticEntryList, rowsPerItem, float, 4); + ATTRIB(XonoticEntryList, stringFilterBox, entity, NULL); ATTRIB(XonoticEntryList, stringFilter, string, string_null); ATTRIB(XonoticEntryList, typeToSearchString, string, string_null); @@ -33,3 +34,5 @@ CLASS(XonoticEntryList, XonoticListBox) } ENDCLASS(XonoticEntryList) +void EntryList_StringFilterBox_Change(entity box, entity me); +float EntryList_StringFilterBox_keyDown(entity me, float key, float ascii, float shift); diff --git a/qcsrc/menu/xonotic/maplist.qc b/qcsrc/menu/xonotic/maplist.qc index 84e4081966..22edd1d27d 100644 --- a/qcsrc/menu/xonotic/maplist.qc +++ b/qcsrc/menu/xonotic/maplist.qc @@ -20,7 +20,7 @@ entity makeXonoticMapList() return me; } -entity MapList_Set_String_Filter_Box(entity me, entity e) +entity MapList_Set_StringFilterBox(entity me, entity e) { me.stringFilterBox = e; return e; @@ -375,7 +375,7 @@ float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift) { me.parent.setFocus(me.parent, me.stringFilterBox); } - else if((shift & S_CTRL) && scan == 'u') // ctrl-u (remove stringFilter line + else if((shift & S_CTRL) && scan == 'u') // ctrl-u (remove stringFilter line) { me.stringFilterBox.setText(me.stringFilterBox, ""); MapList_StringFilterBox_Change(me.stringFilterBox, me);