From f66a6c0e1497314192c75a8acac60a648daf0df1 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 30 Aug 2023 14:18:48 -0500 Subject: [PATCH 1/6] Arsenal - Add option to show live search results --- addons/arsenal/XEH_PREP.hpp | 1 + .../functions/fnc_handleSearchModeToggle.sqf | 30 +++++++++++++++++++ .../arsenal/functions/fnc_onArsenalClose.sqf | 1 + .../arsenal/functions/fnc_onArsenalOpen.sqf | 1 + addons/arsenal/functions/fnc_onKeyDown.sqf | 17 ++++++----- addons/arsenal/stringtable.xml | 3 ++ addons/arsenal/ui/RscAttributes.hpp | 2 ++ 7 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 addons/arsenal/functions/fnc_handleSearchModeToggle.sqf diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index 3b063d8ebea..271639010f9 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -44,6 +44,7 @@ PREP(handleLoadoutsSearchbar); PREP(handleMouse); PREP(handleScrollWheel); PREP(handleSearchbar); +PREP(handleSearchModeToggle); PREP(handleStats); PREP(initBox); PREP(itemInfo); diff --git a/addons/arsenal/functions/fnc_handleSearchModeToggle.sqf b/addons/arsenal/functions/fnc_handleSearchModeToggle.sqf new file mode 100644 index 00000000000..839e89de7c2 --- /dev/null +++ b/addons/arsenal/functions/fnc_handleSearchModeToggle.sqf @@ -0,0 +1,30 @@ +#include "script_component.hpp" +#include "..\defines.hpp" +/* + * Author: PabstMirror + * Handles mouse clicks on search button to toggle live results + * + * Arguments: + * 0: Search button (left or right) + * 1: Mouse Button + * 2: Not used + * 3: Not used + * 4: Not used + * 5: Ctrl Button + * + * Return Value: + * None + * + * Public: No +*/ + +params ["_ctrl", "_mouseButton", "", "", "", "_keyCtrl"]; + +if ((!_keyCtrl)) exitWith {}; // Ignore if not CTRL + Click + +GVAR(liveUpdateSearch) = !GVAR(liveUpdateSearch); + +private _display = ctrlParent _ctrl; +private _color = if (GVAR(liveUpdateSearch)) then { [0,1,0,0.5] } else { [0,0,0,0.5] }; +(_display displayCtrl IDC_leftSearchbarButton) ctrlSetBackgroundColor _color; +(_display displayCtrl IDC_rightSearchbarButton) ctrlSetBackgroundColor _color; diff --git a/addons/arsenal/functions/fnc_onArsenalClose.sqf b/addons/arsenal/functions/fnc_onArsenalClose.sqf index 222ef8a9d98..dd2d4026353 100644 --- a/addons/arsenal/functions/fnc_onArsenalClose.sqf +++ b/addons/arsenal/functions/fnc_onArsenalClose.sqf @@ -104,6 +104,7 @@ GVAR(currentLeftPanel) = nil; GVAR(currentRightPanel) = nil; GVAR(leftSearchbarFocus) = nil; GVAR(rightSearchbarFocus) = nil; +GVAR(liveUpdateSearch) = nil; GVAR(shiftState) = nil; GVAR(leftTabFocus) = nil; GVAR(rightTabFocus) = nil; diff --git a/addons/arsenal/functions/fnc_onArsenalOpen.sqf b/addons/arsenal/functions/fnc_onArsenalOpen.sqf index f3c499cef09..9642eb9b149 100644 --- a/addons/arsenal/functions/fnc_onArsenalOpen.sqf +++ b/addons/arsenal/functions/fnc_onArsenalOpen.sqf @@ -241,6 +241,7 @@ GVAR(currentLeftPanel) = nil; GVAR(currentRightPanel) = nil; GVAR(leftSearchbarFocus) = false; GVAR(rightSearchbarFocus) = false; +GVAR(liveUpdateSearch) = false; GVAR(leftTabFocus) = false; GVAR(rightTabFocus) = false; GVAR(rightTabLnBFocus) = false; diff --git a/addons/arsenal/functions/fnc_onKeyDown.sqf b/addons/arsenal/functions/fnc_onKeyDown.sqf index bc110f3f64b..d843eff3dd0 100644 --- a/addons/arsenal/functions/fnc_onKeyDown.sqf +++ b/addons/arsenal/functions/fnc_onKeyDown.sqf @@ -153,6 +153,7 @@ if (!isNull _loadoutsDisplay) then { }; } else { // If in arsenal and a search bar is selected + private _updateSearchResults = GVAR(liveUpdateSearch); switch (true) do { // Close button case (_keyPressed == DIK_ESCAPE): { @@ -161,13 +162,7 @@ if (!isNull _loadoutsDisplay) then { // Search case (_keyPressed == DIK_NUMPADENTER); case (_keyPressed == DIK_RETURN): { - if (GVAR(leftSearchbarFocus)) then { - [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); - }; - - if (GVAR(rightSearchbarFocus)) then { - [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); - }; + _updateSearchResults = true; }; case (_keyPressed in [DIK_LEFT, DIK_RIGHT]); case (_keyPressed == DIK_BACKSPACE); @@ -183,6 +178,14 @@ if (!isNull _loadoutsDisplay) then { }; }; }; + if (_updateSearchResults) then { + if (GVAR(leftSearchbarFocus)) then { + [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); + }; + if (GVAR(rightSearchbarFocus)) then { + [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); + }; + }; }; }; diff --git a/addons/arsenal/stringtable.xml b/addons/arsenal/stringtable.xml index 4c1dc4cffcb..5931f4edde5 100644 --- a/addons/arsenal/stringtable.xml +++ b/addons/arsenal/stringtable.xml @@ -1587,5 +1587,8 @@ Switch between displaying all items or your favorites.\nDouble click while holding Shift to add or remove an item. + + Search\nCTRL + Click to enable live results + diff --git a/addons/arsenal/ui/RscAttributes.hpp b/addons/arsenal/ui/RscAttributes.hpp index 3a707a3dc35..20f85f8ccdd 100644 --- a/addons/arsenal/ui/RscAttributes.hpp +++ b/addons/arsenal/ui/RscAttributes.hpp @@ -647,8 +647,10 @@ class GVAR(display) { class leftSearchbarButton: ctrlButtonPicture { idc = IDC_leftSearchbarButton; text = "\a3\Ui_f\data\GUI\RscCommon\RscButtonSearch\search_start_ca.paa"; + tooltip = CSTRING(buttonSearchTooltip); colorBackground[] = {0,0,0,0.5}; onButtonClick = QUOTE([ARR_2(ctrlParent (_this select 0), ctrlParent (_this select 0) displayCtrl IDC_leftSearchbar)] call FUNC(handleSearchbar)); + onMouseButtonDown = QUOTE(call FUNC(handleSearchModeToggle)); x = QUOTE(safezoneX + 87 * GRID_W); y = QUOTE(safezoneY + 1.8 * GRID_H); w = QUOTE(6 * GRID_W); From 6eebb412ab00844b9517631bc06de9071e4141fb Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 3 Sep 2023 23:00:24 -0500 Subject: [PATCH 2/6] use onEditChanged --- addons/arsenal/XEH_PREP.hpp | 1 + .../fnc_handleSearchInputChanged.sqf | 28 +++++++++++++++++++ addons/arsenal/functions/fnc_onKeyDown.sqf | 16 ++++------- addons/arsenal/ui/RscAttributes.hpp | 1 + 4 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 addons/arsenal/functions/fnc_handleSearchInputChanged.sqf diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index 271639010f9..a75c053dcec 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -44,6 +44,7 @@ PREP(handleLoadoutsSearchbar); PREP(handleMouse); PREP(handleScrollWheel); PREP(handleSearchbar); +PREP(handleSearchInputChanged); PREP(handleSearchModeToggle); PREP(handleStats); PREP(initBox); diff --git a/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf b/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf new file mode 100644 index 00000000000..8655eaec9d3 --- /dev/null +++ b/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf @@ -0,0 +1,28 @@ +#include "script_component.hpp" +#include "..\defines.hpp" +/* + * Author: PabstMirror + * Handles user input in the search text boxes + * + * Arguments: + * 0: Search text input (left or right) + * 1: Text + * + * Return Value: + * None + * + * Public: No +*/ + +params ["_ctrl", "_newText"]; + +if (!GVAR(liveUpdateSearch)) exitWith {}; + +private _display = ctrlParent _ctrl; + +if (GVAR(leftSearchbarFocus)) then { + [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); +}; +if (GVAR(rightSearchbarFocus)) then { + [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); +}; diff --git a/addons/arsenal/functions/fnc_onKeyDown.sqf b/addons/arsenal/functions/fnc_onKeyDown.sqf index d843eff3dd0..e10016c8126 100644 --- a/addons/arsenal/functions/fnc_onKeyDown.sqf +++ b/addons/arsenal/functions/fnc_onKeyDown.sqf @@ -153,7 +153,6 @@ if (!isNull _loadoutsDisplay) then { }; } else { // If in arsenal and a search bar is selected - private _updateSearchResults = GVAR(liveUpdateSearch); switch (true) do { // Close button case (_keyPressed == DIK_ESCAPE): { @@ -162,7 +161,12 @@ if (!isNull _loadoutsDisplay) then { // Search case (_keyPressed == DIK_NUMPADENTER); case (_keyPressed == DIK_RETURN): { - _updateSearchResults = true; + if (GVAR(leftSearchbarFocus)) then { + [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); + }; + if (GVAR(rightSearchbarFocus)) then { + [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); + }; }; case (_keyPressed in [DIK_LEFT, DIK_RIGHT]); case (_keyPressed == DIK_BACKSPACE); @@ -178,14 +182,6 @@ if (!isNull _loadoutsDisplay) then { }; }; }; - if (_updateSearchResults) then { - if (GVAR(leftSearchbarFocus)) then { - [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); - }; - if (GVAR(rightSearchbarFocus)) then { - [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); - }; - }; }; }; diff --git a/addons/arsenal/ui/RscAttributes.hpp b/addons/arsenal/ui/RscAttributes.hpp index 20f85f8ccdd..1073c26dba3 100644 --- a/addons/arsenal/ui/RscAttributes.hpp +++ b/addons/arsenal/ui/RscAttributes.hpp @@ -638,6 +638,7 @@ class GVAR(display) { onSetFocus = QUOTE(GVAR(leftSearchbarFocus) = true); onKillFocus = QUOTE(GVAR(leftSearchbarFocus) = false); onMouseButtonClick = QUOTE([ARR_3(ctrlParent (_this select 0), _this select 0, _this select 1)] call FUNC(clearSearchbar)); + onEditChanged = QUOTE(call FUNC(handleSearchInputChanged)); x = QUOTE(safezoneX + 13 * GRID_W); y = QUOTE(safezoneY + 1.8 * GRID_H); w = QUOTE(74 * GRID_W); From dd3b96bde3dfffe4181eb9c7aeabd4da59ceda1c Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 3 Sep 2023 23:01:22 -0500 Subject: [PATCH 3/6] Update fnc_onKeyDown.sqf --- addons/arsenal/functions/fnc_onKeyDown.sqf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/arsenal/functions/fnc_onKeyDown.sqf b/addons/arsenal/functions/fnc_onKeyDown.sqf index e10016c8126..0a685e36ee5 100644 --- a/addons/arsenal/functions/fnc_onKeyDown.sqf +++ b/addons/arsenal/functions/fnc_onKeyDown.sqf @@ -161,12 +161,12 @@ if (!isNull _loadoutsDisplay) then { // Search case (_keyPressed == DIK_NUMPADENTER); case (_keyPressed == DIK_RETURN): { - if (GVAR(leftSearchbarFocus)) then { - [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); - }; - if (GVAR(rightSearchbarFocus)) then { - [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); - }; + if (GVAR(leftSearchbarFocus)) then { + [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); + }; + if (GVAR(rightSearchbarFocus)) then { + [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); + }; }; case (_keyPressed in [DIK_LEFT, DIK_RIGHT]); case (_keyPressed == DIK_BACKSPACE); From a2acaee75880e98b0af5f16de5d9c4702731331a Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 3 Sep 2023 23:02:03 -0500 Subject: [PATCH 4/6] Update fnc_onKeyDown.sqf --- addons/arsenal/functions/fnc_onKeyDown.sqf | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/arsenal/functions/fnc_onKeyDown.sqf b/addons/arsenal/functions/fnc_onKeyDown.sqf index 0a685e36ee5..bc110f3f64b 100644 --- a/addons/arsenal/functions/fnc_onKeyDown.sqf +++ b/addons/arsenal/functions/fnc_onKeyDown.sqf @@ -164,6 +164,7 @@ if (!isNull _loadoutsDisplay) then { if (GVAR(leftSearchbarFocus)) then { [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); }; + if (GVAR(rightSearchbarFocus)) then { [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); }; From 4e4922506f6f2d9cb2385ff0f9ac93b04c1445e6 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 12 Sep 2023 14:08:00 -0500 Subject: [PATCH 5/6] update script_components --- addons/arsenal/functions/fnc_handleSearchInputChanged.sqf | 2 +- addons/arsenal/functions/fnc_handleSearchModeToggle.sqf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf b/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf index 8655eaec9d3..5c588e63556 100644 --- a/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf +++ b/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf @@ -1,4 +1,4 @@ -#include "script_component.hpp" +#include "..\script_component.hpp" #include "..\defines.hpp" /* * Author: PabstMirror diff --git a/addons/arsenal/functions/fnc_handleSearchModeToggle.sqf b/addons/arsenal/functions/fnc_handleSearchModeToggle.sqf index 839e89de7c2..b5c35b59a55 100644 --- a/addons/arsenal/functions/fnc_handleSearchModeToggle.sqf +++ b/addons/arsenal/functions/fnc_handleSearchModeToggle.sqf @@ -1,4 +1,4 @@ -#include "script_component.hpp" +#include "..\script_component.hpp" #include "..\defines.hpp" /* * Author: PabstMirror From 3fd47a69da2c0b00f7de483b7641287f19b0230c Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 26 Oct 2023 12:34:54 -0500 Subject: [PATCH 6/6] skip animate on live search --- addons/arsenal/functions/fnc_fillRightPanel.sqf | 2 +- addons/arsenal/functions/fnc_handleSearchInputChanged.sqf | 4 ++-- addons/arsenal/functions/fnc_handleSearchbar.sqf | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/arsenal/functions/fnc_fillRightPanel.sqf b/addons/arsenal/functions/fnc_fillRightPanel.sqf index db56bd35f96..d01991f9248 100644 --- a/addons/arsenal/functions/fnc_fillRightPanel.sqf +++ b/addons/arsenal/functions/fnc_fillRightPanel.sqf @@ -7,7 +7,7 @@ * Arguments: * 0: Arsenal display * 1: Tab control - * 2: Animate panel refresh + * 2: Animate panel refresh (default: true) * * Return Value: * None diff --git a/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf b/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf index 5c588e63556..2c7364c6ef1 100644 --- a/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf +++ b/addons/arsenal/functions/fnc_handleSearchInputChanged.sqf @@ -21,8 +21,8 @@ if (!GVAR(liveUpdateSearch)) exitWith {}; private _display = ctrlParent _ctrl; if (GVAR(leftSearchbarFocus)) then { - [_display, _display displayCtrl IDC_leftSearchbar] call FUNC(handleSearchBar); + [_display, _display displayCtrl IDC_leftSearchbar, false] call FUNC(handleSearchBar); }; if (GVAR(rightSearchbarFocus)) then { - [_display, _display displayCtrl IDC_rightSearchbar] call FUNC(handleSearchBar); + [_display, _display displayCtrl IDC_rightSearchbar, false] call FUNC(handleSearchBar); }; diff --git a/addons/arsenal/functions/fnc_handleSearchbar.sqf b/addons/arsenal/functions/fnc_handleSearchbar.sqf index 77f681ce1b1..592096b6407 100644 --- a/addons/arsenal/functions/fnc_handleSearchbar.sqf +++ b/addons/arsenal/functions/fnc_handleSearchbar.sqf @@ -7,6 +7,7 @@ * Arguments: * 0: Arsenal display * 1: Searchbar control + * 2: Animate panel refresh (default: true) * * Return Value: * None @@ -14,7 +15,7 @@ * Public: No */ -params ["_display", "_control"]; +params ["_display", "_control", ["_animate", true]]; // Have to use toLower here and displayName to handle non-ANSI characters private _searchString = toLower ctrlText _control; @@ -28,7 +29,7 @@ if (_searchString != "") then { if ((ctrlIDC _control) == IDC_rightSearchbar) then { // Don't refill if there is no need if (GVAR(lastSearchTextRight) != "" && {(_searchString find GVAR(lastSearchTextRight)) != 0}) then { - [_display, _display displayCtrl GVAR(currentRightPanel)] call FUNC(fillRightPanel); + [_display, _display displayCtrl GVAR(currentRightPanel), _animate] call FUNC(fillRightPanel); }; GVAR(lastSearchTextRight) = _searchString; @@ -127,7 +128,7 @@ if ((ctrlIDC _control) == IDC_rightSearchbar) then { // Left panel search bar // Don't refill if there is no need if (GVAR(lastSearchTextLeft) != "" && {(_searchString find GVAR(lastSearchTextLeft)) != 0}) then { - [_display, _display displayCtrl GVAR(currentLeftPanel)] call FUNC(fillLeftPanel); + [_display, _display displayCtrl GVAR(currentLeftPanel), _animate] call FUNC(fillLeftPanel); }; GVAR(lastSearchTextLeft) = _searchString;