diff --git a/addons/keybinding/fnc_addKeybind.sqf b/addons/keybinding/fnc_addKeybind.sqf index f56a89cf7..803814ad5 100644 --- a/addons/keybinding/fnc_addKeybind.sqf +++ b/addons/keybinding/fnc_addKeybind.sqf @@ -22,7 +22,7 @@ Description: 0xF9: Mouse wheel down Parameters: - _addon - Name of the registering mod + _addon - Name of the registering mod + optional sub-category _action - Id of the key action. _title - Pretty name, or an array of pretty name and tooltip _downCode - Code for down event, empty string for no code. @@ -68,7 +68,7 @@ if (canSuspend) exitWith { }; params [ - ["_addon", "", [""]], + ["_addonArg", "", ["", []]], ["_addonAction", "", [""]], ["_title", "", ["", []]], ["_downCode", {}, [{}, ""]], @@ -79,6 +79,7 @@ params [ ["_overwrite", false, [false]] ]; +_addonArg params [["_addon", "", [""]], ["_subcategory", "", [""]]]; _title params [["_displayName", _addonAction, [""]], ["_tooltip", "", [""]]]; private _action = toLower format ["%1$%2", _addon, _addonAction]; @@ -156,7 +157,7 @@ if (isNil "_addonInfo") then { (_addonInfo select 1) pushBackUnique toLower _addonAction; -GVAR(actions) setVariable [_action, [_displayName, _tooltip, _keybinds, _defaultKeybind, _downCode, _upCode, _holdKey, _holdDelay]]; +GVAR(actions) setVariable [_action, [_displayName, _tooltip, _keybinds, _defaultKeybind, _downCode, _upCode, _holdKey, _holdDelay, _subcategory]]; // add this action to all keybinds { diff --git a/addons/keybinding/fnc_gui_editKey.sqf b/addons/keybinding/fnc_gui_editKey.sqf index ad74be20c..5b4988aeb 100644 --- a/addons/keybinding/fnc_gui_editKey.sqf +++ b/addons/keybinding/fnc_gui_editKey.sqf @@ -1,9 +1,9 @@ #include "script_component.hpp" -params ["_control", "_index"]; +params ["_control"]; private _parentDisplay = ctrlParent _control; -parseSimpleArray (_control lnbData [_index, 0]) params ["_action", "_displayName", "_keybinds", "_defaultKeybind"]; +(_control getVariable QGVAR(data)) params ["_action", "_displayName", "_keybinds", "_defaultKeybind", "_index"]; private _display = _parentDisplay createDisplay "RscDisplayConfigureAction"; @@ -225,12 +225,15 @@ _ctrlButtonPrev ctrlAddEventHandler ["ButtonClick", { private _ctrlKeyList = _display displayCtrl IDC_CONFIGURE_ACTION_KEYS; private _index = (_ctrlKeyList getVariable QGVAR(index)) - 1; + private _subcontrols = _ctrlActionList getVariable QGVAR(KeyListEditableSubcontrols); if (_index < 0) then { - _index = (lnbSize _ctrlActionList select 0) - 1 + _index = count _subcontrols - 1 }; - parseSimpleArray (_ctrlActionList lnbData [_index, 0]) params ["_action", "_displayName", "_keybinds", "_defaultKeybind"]; + _subcontrols select _index controlsGroupCtrl IDC_KEY_EDIT getVariable QGVAR(data) params [ + "_action", "_displayName", "_keybinds", "_defaultKeybind" + ]; private _tempNamespace = uiNamespace getVariable QGVAR(tempKeybinds); _keybinds = _tempNamespace getVariable [_action, _keybinds]; @@ -266,12 +269,15 @@ _ctrlButtonNext ctrlAddEventHandler ["ButtonClick", { private _ctrlKeyList = _display displayCtrl IDC_CONFIGURE_ACTION_KEYS; private _index = (_ctrlKeyList getVariable QGVAR(index)) + 1; + private _subcontrols = _ctrlActionList getVariable QGVAR(KeyListEditableSubcontrols); - if (_index >= lnbSize _ctrlActionList select 0) then { + if (_index >= count _subcontrols) then { _index = 0; }; - parseSimpleArray (_ctrlActionList lnbData [_index, 0]) params ["_action", "_displayName", "_keybinds", "_defaultKeybind"]; + _subcontrols select _index controlsGroupCtrl IDC_KEY_EDIT getVariable QGVAR(data) params [ + "_action", "_displayName", "_keybinds", "_defaultKeybind" + ]; private _tempNamespace = uiNamespace getVariable QGVAR(tempKeybinds); _keybinds = _tempNamespace getVariable [_action, _keybinds]; diff --git a/addons/keybinding/fnc_gui_update.sqf b/addons/keybinding/fnc_gui_update.sqf index ab1976356..97fad42e1 100644 --- a/addons/keybinding/fnc_gui_update.sqf +++ b/addons/keybinding/fnc_gui_update.sqf @@ -6,7 +6,18 @@ if (isNull _display) exitWith {}; private _ctrlAddonList = _display displayCtrl IDC_ADDON_LIST; private _ctrlKeyList = _display displayCtrl IDC_KEY_LIST; -lnbClear _ctrlKeyList; +// clear key list +private _subcontrols = _ctrlKeyList getVariable [QGVAR(KeyListSubcontrols), []]; + +{ + ctrlDelete _x; +} forEach _subcontrols; + +_subcontrols = []; +_ctrlKeyList setVariable [QGVAR(KeyListSubcontrols), _subcontrols]; + +private _editableSubcontrols = []; +_ctrlKeyList setVariable [QGVAR(KeyListEditableSubcontrols), _editableSubcontrols]; private _index = lbCurSel _ctrlAddonList; private _addon = _ctrlAddonList lbData _index; @@ -17,8 +28,29 @@ uiNamespace setVariable [QGVAR(addonIndex), _index]; private _tempNamespace = uiNamespace getVariable QGVAR(tempKeybinds); +private _categoryKeyActions = []; + { private _action = format ["%1$%2", _addon, _x]; + private _subcategory = (GVAR(actions) getVariable _action) param [8, "", [""]]; + + _categoryKeyActions pushBack [_subcategory, _forEachIndex, _x]; +} forEach _addonActions; + +_categoryKeyActions sort true; +private _lastSubcategory = "$START"; +private _tablePosY = 0; + +{ + _x params ["_subcategory", "", "_keyAction"]; + + private _createHeader = false; + if (_subcategory != _lastSubcategory) then { + _lastSubcategory = _subcategory; + _createHeader = _subcategory != ""; + }; + + private _action = format ["%1$%2", _addon, _keyAction]; (GVAR(actions) getVariable _action) params ["_displayName", "_tooltip", "_keybinds", "_defaultKeybind"]; if (isLocalized _displayName) then { @@ -59,16 +91,44 @@ private _tempNamespace = uiNamespace getVariable QGVAR(tempKeybinds); }; } forEach _keybinds; - // add keybinds to action list - private _index = _ctrlKeyList lnbAddRow [_displayName, _keyNames joinString ", "]; + // add subcategory header + if (_createHeader) then { + private _header = _display ctrlCreate [QGVAR(subCat), -1, _ctrlKeyList]; + + if (isLocalized _subcategory) then { + _subcategory = localize _subcategory; + }; + + (_header controlsGroupCtrl IDC_SUBCATEGORY_NAME) ctrlSetText format ["%1:", _subcategory]; + _header ctrlSetPosition [POS_W(0), _tablePosY]; + _header ctrlCommit 0; + + _tablePosY = _tablePosY + getNumber (configFile >> QGVAR(subCat) >> "h"); + _subcontrols pushBack _header; + }; // tooltips bugged for lnb - _ctrlKeyList lbSetTooltip [2 * _index, _tooltip]; - _ctrlKeyList lbSetTooltip [2 * _index + 1, _tooltip]; + private _subcontrol = _display ctrlCreate [QGVAR(key), -1, _ctrlKeyList]; - _ctrlKeyList lnbSetData [[_index, 0], str [_action, _displayName, _keybinds, _defaultKeybind]]; + _subcontrol ctrlSetPosition [POS_W(0), _tablePosY]; + _subcontrol ctrlCommit 0; + + _tablePosY = _tablePosY + POS_H(1); + + private _edit = _subcontrol controlsGroupCtrl IDC_KEY_EDIT; + _edit ctrlSetText _displayName; + _edit ctrlSetTooltip _tooltip; + _edit ctrlSetTooltipColorShade [0,0,0,0.5]; + _edit setVariable [QGVAR(data), [_action, _displayName, _keybinds, _defaultKeybind, _forEachIndex]]; + + private _assigned = _subcontrol controlsGroupCtrl IDC_KEY_ASSIGNED; + _assigned ctrlSetText (_keyNames joinString ", "); if (_isDuplicated) then { - _ctrlKeyList lnbSetColor [[_index, 1], [1, 0, 0, 1]]; + _edit ctrlSetTextColor [1,0,0,1]; + _assigned ctrlSetTextColor [1,0,0,1]; }; -} forEach _addonActions; + + _subcontrols pushBack _subcontrol; + _editableSubcontrols pushBack _subcontrol; +} forEach _categoryKeyActions; diff --git a/addons/keybinding/fnc_initDisplayConfigure.sqf b/addons/keybinding/fnc_initDisplayConfigure.sqf index 0fd0a2770..1b5c847c6 100644 --- a/addons/keybinding/fnc_initDisplayConfigure.sqf +++ b/addons/keybinding/fnc_initDisplayConfigure.sqf @@ -45,11 +45,6 @@ lbSort _ctrlAddonList; _ctrlAddonList lbSetCurSel (uiNamespace getVariable [QGVAR(addonIndex), 0]); _ctrlAddonList ctrlAddEventHandler ["LBSelChanged", {_this call (uiNamespace getVariable QFUNC(gui_update))}]; -private _ctrlKeyList = _display displayCtrl IDC_KEY_LIST; - -_ctrlKeyList ctrlSetTooltipColorShade [0, 0, 0, 0.5]; -_ctrlKeyList ctrlAddEventHandler ["LBSelChanged", {_this call (uiNamespace getVariable QFUNC(gui_editKey))}]; - // ----- namespace for temp changed keybinds uiNamespace setVariable [QGVAR(tempKeybinds), _display ctrlCreate ["RscText", -1]]; diff --git a/addons/keybinding/gui.hpp b/addons/keybinding/gui.hpp index f8abb887f..7785d3a49 100644 --- a/addons/keybinding/gui.hpp +++ b/addons/keybinding/gui.hpp @@ -1,8 +1,79 @@ -class RscButtonMenu; +class RscControlsGroup; class RscControlsGroupNoScrollbars; class RscText; +class RscButton; +class RscButtonMenu; class RscCombo; -class RscListNBox; + +class GVAR(key): RscControlsGroupNoScrollbars { + idc = -1; + enableDisplay = 0; + x = POS_W(0); + y = POS_H(0); + w = POS_W(37); + h = POS_H(1); + + class controls { + class EditButton: RscButton { + idc = IDC_KEY_EDIT; + onButtonClick = QUOTE(_this call (uiNamespace getVariable 'FUNC(gui_editKey)')); + style = ST_LEFT; + colorBackground[] = {0,0,0,0}; + colorBackgroundActive[] = {1,1,1,1}; + colorFocused[] = {1,1,1,1}; + x = POS_W(0); + y = POS_H(0); + w = POS_W(17); + h = POS_H(1); + }; + + class AssignedKey: RscText { + idc = IDC_KEY_ASSIGNED; + shadow = 2; + colorShadow[] = {0,0,0,0}; + x = POS_W(17); + y = POS_H(0); + w = POS_W(20); + h = POS_H(1); + }; + }; +}; + +class GVAR(subCat): RscControlsGroupNoScrollbars { + x = POS_W(1); + y = POS_H(0); + w = POS_W(37); + h = POS_H(0.75); + + class controls { + class Background: RscText { + colorBackground[] = {0.25,0.25,0.25,0.4}; + x = POS_W(0); + y = POS_H(0); + w = POS_W(36); + h = POS_H(0.75); + }; + + class Name: RscText { + idc = IDC_SUBCATEGORY_NAME; + style = ST_LEFT; + SizeEx = POS_H(0.75); + x = POS_W(0); + y = POS_H(0); + w = POS_W(15.5); + h = POS_H(0.75); + }; + + class Bar: RscText { + colorBackground[] = {1,1,1,1}; + style = ST_LEFT; + x = POS_W(0); + y = POS_H(0.75) - 2 * pixelH; + w = POS_W(36); + h = pixelH; + }; + }; +}; class RscDisplayConfigure { class controls { @@ -58,9 +129,8 @@ class RscDisplayConfigure { h = POS_H(1); wholeHeight = POS_H(12); }; - class CA_ValueKeys: RscListNBox { + class KeyList: RscControlsGroup { idc = IDC_KEY_LIST; - columns[] = {0, 0.459459459}; //17/37 x = POS_W(0.5); y = POS_H(3.5); w = POS_W(37); diff --git a/addons/keybinding/script_component.hpp b/addons/keybinding/script_component.hpp index 00506bb6b..b4fcb84eb 100644 --- a/addons/keybinding/script_component.hpp +++ b/addons/keybinding/script_component.hpp @@ -20,6 +20,9 @@ #define IDC_BTN_KEYBOARD_FAKE 8000 #define IDC_ADDON_LIST 9000 #define IDC_KEY_LIST 9001 +#define IDC_KEY_EDIT 9002 +#define IDC_KEY_ASSIGNED 9003 +#define IDC_SUBCATEGORY_NAME 9004 #define POS_X(N) ((N) * GUI_GRID_W + GUI_GRID_CENTER_X) #define POS_Y(N) ((N) * GUI_GRID_H + GUI_GRID_CENTER_Y)