]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow use of ctrl+F and ctrl+U in guide filter
authorotta8634 <k9wolf@pm.me>
Tue, 7 Jan 2025 11:51:53 +0000 (19:51 +0800)
committerotta8634 <k9wolf@pm.me>
Tue, 7 Jan 2025 11:51:53 +0000 (19:51 +0800)
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.

qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc
qcsrc/menu/xonotic/guide/entries.qc
qcsrc/menu/xonotic/guide/entries.qh
qcsrc/menu/xonotic/maplist.qc

index b3c2c432f35cae8f4041041463ebe7ded36fbd78..74f9fe479130e4dbaa25752a1b01d2d89fcd3b88 100644 (file)
@@ -1,47 +1,44 @@
 #include "dialog_multiplayer_media_guide.qh"
 
 #include "inputbox.qh"
-#include "maplist.qh"
 #include "textlabel.qh"
+#include <menu/xonotic/guide/entries.qh>
 
 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)
index f801b30f7de119bc7c6e4a9c0b4e22bd60e07396..7fccb4cc3ac8453379472c61038c756cc517aba2 100644 (file)
@@ -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';
index 05e5691f8f197ef3c9c8720108b30b14bc58feb3..657d0e7a6fead7356c60e99a4f10613d108522f4 100644 (file)
@@ -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);
index 84e408196674a1d4f2eb9307da91c5d721dc150e..22edd1d27dfdee1ea6f7f1a11f68f916ca98ad3c 100644 (file)
@@ -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);