From 8ec9ac310a703aa84a545d0db6ee228073c71795 Mon Sep 17 00:00:00 2001 From: div0 Date: Sat, 10 Nov 2007 15:00:08 +0000 Subject: [PATCH] made server filter work! Hooray, JOIN dialog is complete! git-svn-id: svn://svn.icculus.org/nexuiz/trunk@2934 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/menu-div0test/classes.c | 1 + .../nexuiz/dialog_multiplayer_join.c | 13 +--- data/qcsrc/menu-div0test/nexuiz/inputbox.c | 60 +++++++++++++++++++ data/qcsrc/menu-div0test/nexuiz/serverlist.c | 18 ++++++ data/qcsrc/menu-div0test/skin.qh | 1 + 5 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 data/qcsrc/menu-div0test/nexuiz/inputbox.c diff --git a/data/qcsrc/menu-div0test/classes.c b/data/qcsrc/menu-div0test/classes.c index 62a9f7f7a..5b413143f 100644 --- a/data/qcsrc/menu-div0test/classes.c +++ b/data/qcsrc/menu-div0test/classes.c @@ -40,3 +40,4 @@ #include "nexuiz/dialog_multiplayer_join.c" #include "nexuiz/listbox.c" #include "nexuiz/serverlist.c" +#include "nexuiz/inputbox.c" diff --git a/data/qcsrc/menu-div0test/nexuiz/dialog_multiplayer_join.c b/data/qcsrc/menu-div0test/nexuiz/dialog_multiplayer_join.c index f622ffa95..a1284fe31 100644 --- a/data/qcsrc/menu-div0test/nexuiz/dialog_multiplayer_join.c +++ b/data/qcsrc/menu-div0test/nexuiz/dialog_multiplayer_join.c @@ -10,15 +10,6 @@ entity makeNexuizServerListTab(); #endif #ifdef IMPLEMENTATION -entity makeNexuizTextBox() -{ - entity e; - e = spawnInputBox(); - e.configureInputBox(e, "hello world", 3, 12, "qcsrc/menu-div0test/basebutton"); - e.keepspaceLeft = 0.1; - e.keepspaceRight = 0.2; - return e; -} entity makeNexuizServerListTab() { @@ -35,7 +26,9 @@ void fillNexuizServerListTab(entity me) me.TR(me); me.TD(me, 1, 0.5, e = makeNexuizTextLabel(0, "Filter:")); - me.TD(me, 1, me.columns - 2, e = makeNexuizTextBox()); + me.TD(me, 1, me.columns - 2, e = makeNexuizInputBox(0, string_null)); + e.onChange = ServerList_Filter_Change; + e.onChangeEntity = slist; me.TD(me, 1, 0.75, e = makeNexuizCheckBox(0, string_null, "Empty")); e.checked = slist.filterShowEmpty; e.onClickEntity = slist; diff --git a/data/qcsrc/menu-div0test/nexuiz/inputbox.c b/data/qcsrc/menu-div0test/nexuiz/inputbox.c new file mode 100644 index 000000000..86da96e47 --- /dev/null +++ b/data/qcsrc/menu-div0test/nexuiz/inputbox.c @@ -0,0 +1,60 @@ +#ifdef INTERFACE +CLASS(NexuizInputBox) EXTENDS(InputBox) + METHOD(NexuizInputBox, configureNexuizInputBox, void(entity, float, string)) + METHOD(NexuizInputBox, focusLeave, void(entity)) + METHOD(NexuizInputBox, setText, void(entity, string)) + ATTRIB(NexuizInputBox, fontSize, float, SKINFONTSIZE_NORMAL) + ATTRIB(NexuizInputBox, image, string, SKINGFX_INPUTBOX) + ATTRIB(NexuizInputBox, onChange, void(entity, entity), SUB_Null) + ATTRIB(NexuizInputBox, onChangeEntity, entity, NULL) + + ATTRIB(NexuizInputBox, cvarName, string, string_null) + METHOD(NexuizInputBox, loadCvars, void(entity)) + METHOD(NexuizInputBox, saveCvars, void(entity)) +ENDCLASS(NexuizInputBox) +entity makeNexuizInputBox(float, string); +#endif + +#ifdef IMPLEMENTATION +entity makeNexuizInputBox(float doEditColorCodes, string theCvar) +{ + entity me; + me = spawnNexuizInputBox(); + me.configureNexuizInputBox(me, doEditColorCodes, theCvar); + return me; +} +void configureNexuizInputBoxNexuizInputBox(entity me, float doEditColorCodes, string theCvar) +{ + me.configureInputBox(me, "", 0, me.fontSize, me.image); + me.editColorCodes = doEditColorCodes; + if(theCvar) + { + me.cvarName = theCvar; + me.loadCvars(me); + } + me.cursorPos = strlen(me.text); +} +void focusLeaveNexuizInputBox(entity me) +{ + if(me.cvarName) + me.saveCvars(me); +} +void setTextNexuizInputBox(entity me, string new) +{ + if(me.text != new) + { + setTextInputBox(me, new); + me.onChange(me, me.onChangeEntity); + } + else + setTextInputBox(me, new); +} +void loadCvarsNexuizInputBox(entity me) +{ + setTextInputBox(me, cvar_string(me.cvarName)); +} +void saveCvarsNexuizInputBox(entity me) +{ + cvar_set(me.cvarName, me.text); +} +#endif diff --git a/data/qcsrc/menu-div0test/nexuiz/serverlist.c b/data/qcsrc/menu-div0test/nexuiz/serverlist.c index 7deec9174..299b24551 100644 --- a/data/qcsrc/menu-div0test/nexuiz/serverlist.c +++ b/data/qcsrc/menu-div0test/nexuiz/serverlist.c @@ -23,6 +23,7 @@ CLASS(NexuizServerList) EXTENDS(NexuizListBox) METHOD(NexuizServerList, setSortOrder, void(entity, float, float)) ATTRIB(NexuizServerList, filterShowEmpty, float, 1) ATTRIB(NexuizServerList, filterShowFull, float, 1) + ATTRIB(NexuizServerList, filterString, string, string_null) ATTRIB(NexuizServerList, nextRefreshTime, float, 0) METHOD(NexuizServerList, refreshServerList, void(entity, float)) // refresh mode: 0 = just reparametrize, 1 = send new requests, 2 = clear ATTRIB(NexuizServerList, needsRefresh, float, 1) @@ -42,6 +43,7 @@ entity makeNexuizServerList(); void ServerList_Connect_Click(entity btn, entity me); void ServerList_ShowEmpty_Click(entity box, entity me); void ServerList_ShowFull_Click(entity box, entity me); +void ServerList_Filter_Change(entity box, entity me); #endif #ifdef IMPLEMENTATION @@ -126,6 +128,12 @@ void refreshServerListNexuizServerList(entity me, float mode) sethostcachemasknumber(m++, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); if(!me.filterShowEmpty) sethostcachemasknumber(m++, SLIST_FIELD_NUMHUMANS, 1, SLIST_TEST_GREATEREQUAL); + m = SLIST_MASK_OR; + if(me.filterString) + { + sethostcachemaskstring(m++, SLIST_FIELD_NAME, me.filterString, SLIST_TEST_CONTAINS); + sethostcachemaskstring(m++, SLIST_FIELD_MAP, me.filterString, SLIST_TEST_CONTAINS); + } sethostcachesort(me.currentSortField, me.currentSortOrder < 0); resorthostcache(); if(mode >= 1) @@ -207,6 +215,16 @@ void ServerList_PlayerSort_Click(entity btn, entity me) { me.setSortOrder(me, SLIST_FIELD_NUMHUMANS, -1); } +void ServerList_Filter_Change(entity box, entity me) +{ + if(me.filterString) + strunzone(me.filterString); + if(box.text != "") + me.filterString = strzone(box.text); + else + me.filterString = string_null; + me.refreshServerList(me, 0); +} void ServerList_ShowEmpty_Click(entity box, entity me) { box.checked = me.filterShowEmpty = !me.filterShowEmpty; diff --git a/data/qcsrc/menu-div0test/skin.qh b/data/qcsrc/menu-div0test/skin.qh index 5ada4a53b..a946c2504 100644 --- a/data/qcsrc/menu-div0test/skin.qh +++ b/data/qcsrc/menu-div0test/skin.qh @@ -10,6 +10,7 @@ const string SKINGFX_RADIOBUTTON = "qcsrc/menu-div0test/baseradiobutton"; const string SKINGFX_COLORBUTTON = "qcsrc/menu-div0test/basebutton"; const string SKINGFX_COLORBUTTON_COLOR = "qcsrc/menu-div0test/color"; const string SKINGFX_SCROLLBAR = "qcsrc/menu-div0test/basescrollbar"; +const string SKINGFX_INPUTBOX = "qcsrc/menu-div0test/basebuttongray"; const float SKINMARGIN_TOP = 8; const float SKINMARGIN_LEFT = 8; -- 2.39.2