From b2f712c1a9233640d3d120b5e2259e57ca2a75e6 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Wed, 20 Sep 2023 03:34:34 -0400 Subject: [PATCH 1/5] add addon searchbar --- addons/settings/XEH_PREP.sqf | 5 ++ addons/settings/fnc_gui_addonChanged.sqf | 2 - .../settings/fnc_gui_addonList_fillList.sqf | 29 +++++++++++ .../fnc_gui_addonList_handleSearchbar.sqf | 48 +++++++++++++++++++ addons/settings/fnc_gui_onKeyDown.sqf | 32 +++++++++++++ .../settings/fnc_initDisplayGameOptions.sqf | 30 +++++------- addons/settings/fnc_openSettingsMenu.sqf | 10 ++++ addons/settings/gui.hpp | 31 ++++++++++-- addons/settings/script_component.hpp | 4 ++ 9 files changed, 165 insertions(+), 26 deletions(-) create mode 100644 addons/settings/fnc_gui_addonList_fillList.sqf create mode 100644 addons/settings/fnc_gui_addonList_handleSearchbar.sqf create mode 100644 addons/settings/fnc_gui_onKeyDown.sqf diff --git a/addons/settings/XEH_PREP.sqf b/addons/settings/XEH_PREP.sqf index 88ba4861db..06eef396f2 100644 --- a/addons/settings/XEH_PREP.sqf +++ b/addons/settings/XEH_PREP.sqf @@ -19,6 +19,11 @@ if (hasInterface) then { PREP(gui_saveTempData); PREP(gui_export); + PREP(gui_addonList_fillList); + PREP(gui_addonList_handleSearchbar); + + PREP(gui_onKeyDown); + PREP(gui_settingCheckbox); PREP(gui_settingEditbox); PREP(gui_settingList); diff --git a/addons/settings/fnc_gui_addonChanged.sqf b/addons/settings/fnc_gui_addonChanged.sqf index 643f76cfda..75ccd3d3e8 100644 --- a/addons/settings/fnc_gui_addonChanged.sqf +++ b/addons/settings/fnc_gui_addonChanged.sqf @@ -15,8 +15,6 @@ if (_selectedAddon isEqualType "") then { uiNamespace setVariable [QGVAR(addon), _selectedAddon]; }; -uiNamespace setVariable [QGVAR(addonIndex), _index]; - // toggle lists private _selectedSource = uiNamespace getVariable QGVAR(source); diff --git a/addons/settings/fnc_gui_addonList_fillList.sqf b/addons/settings/fnc_gui_addonList_fillList.sqf new file mode 100644 index 0000000000..c1671c323c --- /dev/null +++ b/addons/settings/fnc_gui_addonList_fillList.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" + +params ["_display", "_ctrlAddonList"]; + +if (lbSize _ctrlAddonList > 0) then { + for "_i" from (lbSize _ctrlAddonList - 1) to 0 step -1 do { + _ctrlAddonList lbDelete _i; + }; +}; + +private _categories = []; +{ + (GVAR(default) getVariable _x) params ["", "", "", "", "_category"]; + + if !(_category in _categories) then { + private _categoryLocalized = _category; + if (isLocalized _category) then { + _categoryLocalized = localize _category; + }; + + private _index = _ctrlAddonList lbAdd _categoryLocalized; + _ctrlAddonList lbSetData [_index, str _index]; + _display setVariable [str _index, _category]; + + _categories pushBack _category; + }; +} forEach GVAR(allSettings); + +lbSort _ctrlAddonList; diff --git a/addons/settings/fnc_gui_addonList_handleSearchbar.sqf b/addons/settings/fnc_gui_addonList_handleSearchbar.sqf new file mode 100644 index 0000000000..247c949977 --- /dev/null +++ b/addons/settings/fnc_gui_addonList_handleSearchbar.sqf @@ -0,0 +1,48 @@ +#include "script_component.hpp" + +params ["_display", "_searchbar"]; + +private _searchString = ctrlText _searchbar; +if (_searchString != "") then { + _searchString = _searchString regexReplace ["[.?*+^$[\]\\(){}|-]/gio", "\\$&"]; // escape any user regex characters + _searchString = ".*?" + (_searchString splitString " " joinString ".*?") + ".*?/io"; +}; + +private _ctrlAddonList = _display displayCtrl IDC_ADDONS_LIST; + +private _selectedAddon = _ctrlAddonList lbText lbCurSel _ctrlAddonList; +if (_selectedAddon == "") then { + _selectedAddon = _ctrlAddonList lbText 0; +}; + +private _lastSearchString = _display getVariable [QGVAR(addonSearchString), ""]; +if (_lastSearchString != "" && {_lastSearchString isNotEqualTo _searchString}) then { + [_display, _ctrlAddonList] call FUNC(gui_addonList_fillList); +}; + +_display setVariable [QGVAR(addonSearchString), _searchString]; + +if (_searchString == "") exitWith { + _ctrlAddonList lbSetCurSel 0; +}; + +private _currentDisplayName = ""; + +// Go through all items in list and see if they need to be deleted or not +for "_lbIndex" from (lbSize _ctrlAddonList - 1) to 0 step -1 do { + _currentDisplayName = _ctrlAddonList lbText _lbIndex; + + if !(_currentDisplayName regexMatch _searchString) then { + _ctrlAddonList lbDelete _lbIndex; + }; +}; + +// Try to select previously selected item again +private _index = 0; +for "_lbIndex" from 0 to (lbSize _ctrlAddonList - 1) do { + if ((_ctrlAddonList lbText _lbIndex) == _selectedAddon) exitWith { + _index = _lbIndex; + }; +}; + +_ctrlAddonList lbSetCurSel _index; diff --git a/addons/settings/fnc_gui_onKeyDown.sqf b/addons/settings/fnc_gui_onKeyDown.sqf new file mode 100644 index 0000000000..d3beece404 --- /dev/null +++ b/addons/settings/fnc_gui_onKeyDown.sqf @@ -0,0 +1,32 @@ +#include "script_component.hpp" + +params ["_display", "_key", "_shift", "_ctrl"]; + +private _block = false; + +switch (_key) do { + case DIK_NUMPADENTER; + case DIK_RETURN: { + if (GVAR(AddonSearchbarFocus)) then { + [_display, _display displayCtrl IDC_ADDONS_SEARCHBAR] call FUNC(gui_addonList_handleSearchbar); + _block = true; + }; + if (GVAR(SettingSearchbarFocus)) then { + //[_display, _display displayCtrl IDC_SETTINGS_SEARCHBAR] call FUNC(gui_setting_handleSearchbar); + _block = true; + }; + }; + // Focus search bars + case DIK_F: { + if (_ctrl) then { + if (GVAR(AddonSearchbarFocus)) then { + ctrlSetFocus (_display displayCtrl IDC_SETTINGS_SEARCHBAR); + } else { + ctrlSetFocus (_display displayCtrl IDC_ADDONS_SEARCHBAR); + }; + _block = true; + }; + }; +}; + +_block diff --git a/addons/settings/fnc_initDisplayGameOptions.sqf b/addons/settings/fnc_initDisplayGameOptions.sqf index 6cec2b18d9..f0f87f6b0a 100644 --- a/addons/settings/fnc_initDisplayGameOptions.sqf +++ b/addons/settings/fnc_initDisplayGameOptions.sqf @@ -69,7 +69,7 @@ with uiNamespace do { GVAR(awaitingRestartTemp) = + GVAR(awaitingRestart); // ----- create addons list (filled later) -private _ctrlAddonList = _display ctrlCreate [QGVAR(AddonsList), -1, _ctrlAddonsGroup]; +private _ctrlAddonList = _display ctrlCreate [QGVAR(AddonsList), IDC_ADDONS_LIST, _ctrlAddonsGroup]; _ctrlAddonList ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(gui_addonChanged)}]; @@ -77,26 +77,18 @@ _ctrlAddonList ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(gui_addonCh _display setVariable [QGVAR(lists),[]]; // ----- fill addons list -private _categories = []; -{ - (GVAR(default) getVariable _x) params ["", "", "", "", "_category"]; - - if !(_category in _categories) then { - private _categoryLocalized = _category; - if (isLocalized _category) then { - _categoryLocalized = localize _category; +[_display, _ctrlAddonList] call FUNC(gui_addonList_fillList); + +private _listIndex = 0; +private _lastAddon = uiNamespace getVariable [QGVAR(addon), ""]; +if (_lastAddon != "") then { + for "_lbIndex" from 0 to (lbSize _ctrlAddonList - 1) do { + if ((_display getVariable [(_ctrlAddonList lbData _lbIndex), ""]) == _lastAddon) exitWith { + _listIndex = _lbIndex; }; - - private _index = _ctrlAddonList lbAdd _categoryLocalized; - _ctrlAddonList lbSetData [_index, str _index]; - _display setVariable [str _index, _category]; - - _categories pushBack _category; }; -} forEach GVAR(allSettings); - -lbSort _ctrlAddonList; -_ctrlAddonList lbSetCurSel (uiNamespace getVariable [QGVAR(addonIndex), 0]); +}; +_ctrlAddonList lbSetCurSel _listIndex; // ----- create save and load presets buttons private _ctrlButtonSave = _display ctrlCreate ["RscButtonMenu", IDC_BTN_SAVE]; diff --git a/addons/settings/fnc_openSettingsMenu.sqf b/addons/settings/fnc_openSettingsMenu.sqf index cbb5c16ca2..56944e5284 100644 --- a/addons/settings/fnc_openSettingsMenu.sqf +++ b/addons/settings/fnc_openSettingsMenu.sqf @@ -26,3 +26,13 @@ private _ctrlConfirm = _dlgSettings ctrlCreate ["RscButtonMenuOK", IDC_CANCEL]; _ctrlConfirm ctrlSetPosition ctrlPosition _ctrlScriptedOK; _ctrlConfirm ctrlCommit 0; _ctrlConfirm ctrlAddEventHandler ["ButtonClick", {call FUNC(gui_saveTempData)}]; + +// Add keyDown EH for search bars +GVAR(AddonSearchbarFocus) = false; +GVAR(SettingSearchbarFocus) = false; + +_dlgSettings displayAddEventHandler ["KeyDown", {call FUNC(gui_onKeyDown)}]; +_dlgSettings displayAddEventHandler ["Unload", { + GVAR(AddonSearchbarFocus) = nil; + GVAR(SettingSearchbarFocus) = nil; +}]; diff --git a/addons/settings/gui.hpp b/addons/settings/gui.hpp index a5c5e30311..ab1042f3cb 100644 --- a/addons/settings/gui.hpp +++ b/addons/settings/gui.hpp @@ -1,6 +1,7 @@ class RscButtonMenu; class RscControlsGroupNoScrollbars; class RscText; +class ctrlButtonPicture; class RscDisplayGameOptions { // pause game in SP while this menu is shown @@ -62,12 +63,32 @@ class RscDisplayGameOptions { idc = -1; style = ST_RIGHT; text = ECSTRING(main,AddonText); - x = QUOTE(POS_W(0.5)); - y = QUOTE(POS_H(1)); + x = QUOTE(POS_W(0)); + y = QUOTE(POS_H(0.8)); w = QUOTE(POS_W(4)); h = QUOTE(POS_H(1)); sizeEx = QUOTE(POS_H(1)); }; + class AddonSearch: RscEdit { + idc = IDC_ADDONS_SEARCHBAR; + onSetFocus = QUOTE(GVAR(AddonSearchbarFocus) = true); + onKillFocus = QUOTE(GVAR(AddonSearchbarFocus) = false); + x = QUOTE(POS_W(20)); + y = QUOTE(POS_H(0.8)); + w = QUOTE(POS_W(15)); + h = QUOTE(POS_H(1)); + sizeEx = QUOTE(POS_H(1)); + }; + class AddonSearchButton: ctrlButtonPicture { + idc = -1; + text = "\a3\Ui_f\data\GUI\RscCommon\RscButtonSearch\search_start_ca.paa"; + colorBackground[] = {0,0,0,0.4}; + onButtonClick = QUOTE([ARR_2(ctrlParent (_this select 0), (ctrlParentControlsGroup (_this select 0)) controlsGroupCtrl IDC_ADDONS_SEARCHBAR)] call FUNC(gui_addonList_handleSearchbar)); + x = QUOTE(POS_W(34.95)); + y = QUOTE(POS_H(0.72)); + w = QUOTE(POS_W(1)); + h = QUOTE(POS_H(1.1)); + }; class OverwriteClientText: RscText { // Set tooltip per script to avoid it being all upper case. // Disable multiline text to make in unselectable. @@ -162,9 +183,9 @@ class GVAR(AddonsList): GVAR(RscCombo) { linespacing = 1; text = ""; wholeHeight = QUOTE(POS_H(12)); - x = QUOTE(POS_W(4.5)); - y = QUOTE(POS_H(1)); - w = QUOTE(POS_W(21)); + x = QUOTE(POS_W(4)); + y = QUOTE(POS_H(0.8)); + w = QUOTE(POS_W(15)); h = QUOTE(POS_H(1)); }; diff --git a/addons/settings/script_component.hpp b/addons/settings/script_component.hpp index 131fdb723d..6961cbceb3 100644 --- a/addons/settings/script_component.hpp +++ b/addons/settings/script_component.hpp @@ -21,12 +21,16 @@ #include "\x\cba\addons\main\script_macros.hpp" #define IDC_ADDONS_GROUP 4301 +#define IDC_ADDONS_SEARCHBAR 4311 +#define IDC_ADDONS_LIST 4312 #define IDC_BTN_CONFIGURE_ADDONS 4302 #define IDC_BTN_CLIENT 9001 #define IDC_BTN_MISSION 9002 #define IDC_BTN_SERVER 9003 #define IDC_BTN_IMPORT 9010 #define IDC_BTN_EXPORT 9011 +#define IDC_SETTINGS_SEARCHBAR 9013 +#define IDC_BTN_SETTINGS_SEARCH 9014 #define IDC_BTN_SAVE 9020 #define IDC_BTN_LOAD 9021 #define IDC_BTN_CONFIGURE 9030 From a31e6e12c6f1d3b7cb8ed0018d2f307d28e8a92f Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Wed, 20 Sep 2023 03:58:47 -0400 Subject: [PATCH 2/5] create settings searchbar (does nothing for now) --- addons/settings/fnc_initDisplayGameOptions.sqf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/settings/fnc_initDisplayGameOptions.sqf b/addons/settings/fnc_initDisplayGameOptions.sqf index f0f87f6b0a..4825139165 100644 --- a/addons/settings/fnc_initDisplayGameOptions.sqf +++ b/addons/settings/fnc_initDisplayGameOptions.sqf @@ -123,6 +123,18 @@ _ctrlButtonLoad ctrlEnable false; _ctrlButtonLoad ctrlShow false; _ctrlButtonLoad ctrlAddEventHandler ["ButtonClick", {[ctrlParent (_this select 0), "load"] call FUNC(gui_preset)}]; +// ----- create settings search bar +private _ctrlSearchBarSettings = _display ctrlCreate ["RscEdit", IDC_SETTINGS_SEARCHBAR]; +_ctrlSearchBarSettings ctrlSetPosition [ + POS_X(13.8), + POS_Y(20.45), + POS_W(12.4), + POS_H(1) +]; + +_ctrlSearchBarSettings ctrlCommit 0; + + // ----- create export and import buttons private _ctrlButtonImport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_IMPORT]; From 680fb624e1659394bbe27459564d686ee803e678 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Wed, 20 Sep 2023 04:33:35 -0400 Subject: [PATCH 3/5] move class --- addons/settings/gui.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/settings/gui.hpp b/addons/settings/gui.hpp index ab1042f3cb..0be5e578b5 100644 --- a/addons/settings/gui.hpp +++ b/addons/settings/gui.hpp @@ -1,6 +1,7 @@ class RscButtonMenu; class RscControlsGroupNoScrollbars; class RscText; +class RscEdit; class ctrlButtonPicture; class RscDisplayGameOptions { @@ -313,8 +314,6 @@ class GVAR(Row_Checkbox): GVAR(Row_Base) { }; }; -class RscEdit; - class GVAR(Row_Editbox): GVAR(Row_Base) { GVAR(script) = QFUNC(gui_settingEditbox); From 18feb452782609c5cb25d4e13cf6e16f59da53cc Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Wed, 20 Sep 2023 04:35:45 -0400 Subject: [PATCH 4/5] drop settings search bar --- addons/settings/fnc_gui_onKeyDown.sqf | 10 +--------- addons/settings/fnc_initDisplayGameOptions.sqf | 11 ----------- addons/settings/fnc_openSettingsMenu.sqf | 4 +--- addons/settings/script_component.hpp | 4 +--- 4 files changed, 3 insertions(+), 26 deletions(-) diff --git a/addons/settings/fnc_gui_onKeyDown.sqf b/addons/settings/fnc_gui_onKeyDown.sqf index d3beece404..8913b9da0c 100644 --- a/addons/settings/fnc_gui_onKeyDown.sqf +++ b/addons/settings/fnc_gui_onKeyDown.sqf @@ -11,19 +11,11 @@ switch (_key) do { [_display, _display displayCtrl IDC_ADDONS_SEARCHBAR] call FUNC(gui_addonList_handleSearchbar); _block = true; }; - if (GVAR(SettingSearchbarFocus)) then { - //[_display, _display displayCtrl IDC_SETTINGS_SEARCHBAR] call FUNC(gui_setting_handleSearchbar); - _block = true; - }; }; // Focus search bars case DIK_F: { if (_ctrl) then { - if (GVAR(AddonSearchbarFocus)) then { - ctrlSetFocus (_display displayCtrl IDC_SETTINGS_SEARCHBAR); - } else { - ctrlSetFocus (_display displayCtrl IDC_ADDONS_SEARCHBAR); - }; + ctrlSetFocus (_display displayCtrl IDC_ADDONS_SEARCHBAR); _block = true; }; }; diff --git a/addons/settings/fnc_initDisplayGameOptions.sqf b/addons/settings/fnc_initDisplayGameOptions.sqf index 4825139165..2dfd1c2c04 100644 --- a/addons/settings/fnc_initDisplayGameOptions.sqf +++ b/addons/settings/fnc_initDisplayGameOptions.sqf @@ -123,17 +123,6 @@ _ctrlButtonLoad ctrlEnable false; _ctrlButtonLoad ctrlShow false; _ctrlButtonLoad ctrlAddEventHandler ["ButtonClick", {[ctrlParent (_this select 0), "load"] call FUNC(gui_preset)}]; -// ----- create settings search bar -private _ctrlSearchBarSettings = _display ctrlCreate ["RscEdit", IDC_SETTINGS_SEARCHBAR]; -_ctrlSearchBarSettings ctrlSetPosition [ - POS_X(13.8), - POS_Y(20.45), - POS_W(12.4), - POS_H(1) -]; - -_ctrlSearchBarSettings ctrlCommit 0; - // ----- create export and import buttons private _ctrlButtonImport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_IMPORT]; diff --git a/addons/settings/fnc_openSettingsMenu.sqf b/addons/settings/fnc_openSettingsMenu.sqf index 56944e5284..4f78fc50ca 100644 --- a/addons/settings/fnc_openSettingsMenu.sqf +++ b/addons/settings/fnc_openSettingsMenu.sqf @@ -27,12 +27,10 @@ _ctrlConfirm ctrlSetPosition ctrlPosition _ctrlScriptedOK; _ctrlConfirm ctrlCommit 0; _ctrlConfirm ctrlAddEventHandler ["ButtonClick", {call FUNC(gui_saveTempData)}]; -// Add keyDown EH for search bars +// Add keyDown EH for search bar GVAR(AddonSearchbarFocus) = false; -GVAR(SettingSearchbarFocus) = false; _dlgSettings displayAddEventHandler ["KeyDown", {call FUNC(gui_onKeyDown)}]; _dlgSettings displayAddEventHandler ["Unload", { GVAR(AddonSearchbarFocus) = nil; - GVAR(SettingSearchbarFocus) = nil; }]; diff --git a/addons/settings/script_component.hpp b/addons/settings/script_component.hpp index 6961cbceb3..60724dc402 100644 --- a/addons/settings/script_component.hpp +++ b/addons/settings/script_component.hpp @@ -6,7 +6,7 @@ #include "\a3\ui_f\hpp\defineResincl.inc" // #define DEBUG_MODE_FULL -// #define DISABLE_COMPILE_CACHE +#define DISABLE_COMPILE_CACHE // #define DEBUG_ENABLED_SETTINGS #ifdef DEBUG_ENABLED_SETTINGS @@ -29,8 +29,6 @@ #define IDC_BTN_SERVER 9003 #define IDC_BTN_IMPORT 9010 #define IDC_BTN_EXPORT 9011 -#define IDC_SETTINGS_SEARCHBAR 9013 -#define IDC_BTN_SETTINGS_SEARCH 9014 #define IDC_BTN_SAVE 9020 #define IDC_BTN_LOAD 9021 #define IDC_BTN_CONFIGURE 9030 From 48e04c56375a70573bebd16a88248aca839614e9 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Wed, 20 Sep 2023 04:37:02 -0400 Subject: [PATCH 5/5] compile cache --- addons/settings/script_component.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/settings/script_component.hpp b/addons/settings/script_component.hpp index 60724dc402..71b5199d5c 100644 --- a/addons/settings/script_component.hpp +++ b/addons/settings/script_component.hpp @@ -6,7 +6,7 @@ #include "\a3\ui_f\hpp\defineResincl.inc" // #define DEBUG_MODE_FULL -#define DISABLE_COMPILE_CACHE +// #define DISABLE_COMPILE_CACHE // #define DEBUG_ENABLED_SETTINGS #ifdef DEBUG_ENABLED_SETTINGS