From: otta8634 Date: Fri, 10 Jan 2025 15:51:30 +0000 (+0800) Subject: Almost fix filtering in the guide X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=339b69334be04e6745ca502bf0ffeebf8df51041;p=xonotic%2Fxonotic-data.pk3dir.git Almost fix filtering in the guide Still has an issue: doesn't work properly for Gametypes and Mutators. - Method used was filtering based on .m_name, however Gametypes and Mutators don't use .m_name (yet), they use .message. - This can easily be fixed by just changing the macro to use .message for those two, but a better approach should be used, so I'm intentionally pushing slightly-buggy code in hopes a better approach will be found. Needed a bit of reworking of some functions in menu/guide/entries.qc so that MENUQC would stop crashing, added comments to help clarify code. --- diff --git a/qcsrc/menu/xonotic/dialog_singleplayer_guide.qc b/qcsrc/menu/xonotic/dialog_singleplayer_guide.qc index 7fcc095542..abd9d3abf8 100644 --- a/qcsrc/menu/xonotic/dialog_singleplayer_guide.qc +++ b/qcsrc/menu/xonotic/dialog_singleplayer_guide.qc @@ -60,16 +60,18 @@ void XonoticGuideDialog_topicChangeNotify(entity, entity me) while (0); #undef TOPIC entries.source = found; - entries.refilter(entries); - entries.setSelected(entries, 0); + entries.selectedItem = -1; // signal that the source has changed + entries.stringFilterBox.setText(entries.stringFilterBox, ""); + EntryList_StringFilterBox_Change(entries.stringFilterBox, entries); // this calls entries.refilter, which calls entries.setSelected, which calls entryChangeNotify } void XonoticGuideDialog_entryChangeNotify(entity, entity me) { - entity desc = me.descriptionPane; entity entries = me.entryList; + if (entries.nItems <= 0) + return; entity e = entries.source.getEntry(entries.source, entries.selectedItem, func_null); string s = e.describe(e); if (gamestatus & GAME_DEVELOPER) s = sprintf("entity %i\n\n%s", e, s); - desc.setDescription(desc, s); + me.descriptionPane.setDescription(me.descriptionPane, s); } diff --git a/qcsrc/menu/xonotic/guide/entries.qc b/qcsrc/menu/xonotic/guide/entries.qc index 7fccb4cc3a..5bc3982916 100644 --- a/qcsrc/menu/xonotic/guide/entries.qc +++ b/qcsrc/menu/xonotic/guide/entries.qc @@ -109,10 +109,25 @@ void XonoticEntryList_refilter(entity me) me.nItems = 0; return; } + string oldName; + int newSelectedItem = 0; + if (me.selectedItem >= 0) // if negative we just switched source + { + me.source.getEntry(me.source, me.selectedItem, XonoticEntryList_cb); + oldName = XonoticEntryList_cb_name; // keep oldName selected if still present + } + else + oldName = ""; + me.nItems = me.source.reload(me.source, me.stringFilter); for (int i = 0, n = me.nItems; i < n; ++i) if (me.source.getEntry(me.source, i, XonoticEntryList_cb)) + { draw_PreloadPicture(XonoticEntryList_cb_icon); + if (XonoticEntryList_cb_name == oldName) + newSelectedItem = i; + } + me.setSelected(me, newSelectedItem); } void EntryList_StringFilterBox_Change(entity box, entity me) diff --git a/qcsrc/menu/xonotic/guide/guide.qh b/qcsrc/menu/xonotic/guide/guide.qh index ab4335edcc..568f0208f6 100644 --- a/qcsrc/menu/xonotic/guide/guide.qh +++ b/qcsrc/menu/xonotic/guide/guide.qh @@ -40,27 +40,30 @@ ENDCLASS(DebugSource) .bool instanceOfArmor; .bool instanceOfPowerup; +#define _REGISTRY_SOURCE_FILL(arr_name, register_arr, cond1, cond2, cond3, num_conds, filter_cond) \ +if (num_conds >= 1) \ + FOREACH(register_arr, !it.m_hidden && (cond1) && (filter_cond), { \ + AL_sete(arr_name##_MENU, arr_name##_MENU_COUNT, it); \ + ++arr_name##_MENU_COUNT; \ + }); \ +if (num_conds >= 2) \ + FOREACH(register_arr, !it.m_hidden && (cond2) && (filter_cond), { \ + AL_sete(arr_name##_MENU, arr_name##_MENU_COUNT, it); \ + ++arr_name##_MENU_COUNT; \ + }); \ +if (num_conds >= 3) \ + FOREACH(register_arr, !it.m_hidden && (cond3) && (filter_cond), { \ + AL_sete(arr_name##_MENU, arr_name##_MENU_COUNT, it); \ + ++arr_name##_MENU_COUNT; \ + }); + #define _REGISTRY_SOURCE(id, arr_name, register_arr, cond1, cond2, cond3, num_conds) \ ArrayList arr_name##_MENU; \ int arr_name##_MENU_COUNT; \ STATIC_INIT_LATE(arr_name##_MENU) \ { \ AL_NEW(arr_name##_MENU, REGISTRY_MAX(register_arr), NULL, e); \ - if (num_conds >= 1) \ - FOREACH(register_arr, !it.m_hidden && (cond1), { \ - AL_sete(arr_name##_MENU, arr_name##_MENU_COUNT, it); \ - arr_name##_MENU_COUNT++; \ - }); \ - if (num_conds >= 2) \ - FOREACH(register_arr, !it.m_hidden && (cond2), { \ - AL_sete(arr_name##_MENU, arr_name##_MENU_COUNT, it); \ - arr_name##_MENU_COUNT++; \ - }); \ - if (num_conds >= 3) \ - FOREACH(register_arr, !it.m_hidden && (cond3), { \ - AL_sete(arr_name##_MENU, arr_name##_MENU_COUNT, it); \ - arr_name##_MENU_COUNT++; \ - }); \ + _REGISTRY_SOURCE_FILL(arr_name, register_arr, cond1, cond2, cond3, num_conds, true); \ } \ CLASS(id, DataSource) \ METHOD(id, getEntry, entity(id this, int i, void(string, string) returns)) { \ @@ -69,7 +72,11 @@ CLASS(id, DataSource) \ e.display(e, returns); \ return e; \ } \ - METHOD(id, reload, int(id this, string filter)) { return arr_name##_MENU_COUNT; } \ + METHOD(id, reload, int(id this, string filter)) { \ + arr_name##_MENU_COUNT = 0; \ + _REGISTRY_SOURCE_FILL(arr_name, register_arr, cond1, cond2, cond3, num_conds, filter == "" ? true : (strstrofs(strtolower(it.m_name), strtolower(filter), 0) >= 0)); \ + return arr_name##_MENU_COUNT; \ + } \ ENDCLASS(id) #define REGISTRY_SOURCE(...) EVAL(OVERLOAD(REGISTRY_SOURCE, __VA_ARGS__))