Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add keybinding menu subcategories #966

Merged
merged 8 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions addons/keybinding/fnc_addKeybind.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Description:
0xF9: Mouse wheel down

Parameters:
_addon - Name of the registering mod <STRING>
_addon - Name of the registering mod + optional sub-category <STRING, ARRAY>
_action - Id of the key action. <STRING>
_title - Pretty name, or an array of pretty name and tooltip <STRING>
_downCode - Code for down event, empty string for no code. <CODE>
Expand Down Expand Up @@ -68,7 +68,7 @@ if (canSuspend) exitWith {
};

params [
["_addon", "", [""]],
["_addonArg", "", ["", []]],
["_addonAction", "", [""]],
["_title", "", ["", []]],
["_downCode", {}, [{}, ""]],
Expand All @@ -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];

Expand Down Expand Up @@ -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
{
Expand Down
18 changes: 12 additions & 6 deletions addons/keybinding/fnc_gui_editKey.sqf
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
76 changes: 68 additions & 8 deletions addons/keybinding/fnc_gui_update.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like before and vanilla, have the tooltip be shown for both the name and the keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

_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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of red on screen, like before, have only the keys turn to red when duplicate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will go with whatever the base game does. Will check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, Vanilla only highlights the keys.

_assigned ctrlSetTextColor [1,0,0,1];
};
} forEach _addonActions;

_subcontrols pushBack _subcontrol;
_editableSubcontrols pushBack _subcontrol;
} forEach _categoryKeyActions;
5 changes: 0 additions & 5 deletions addons/keybinding/fnc_initDisplayConfigure.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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]];

Expand Down
78 changes: 74 additions & 4 deletions addons/keybinding/gui.hpp
Original file line number Diff line number Diff line change
@@ -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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When hovered, the text can only be read because of the shadow. Remove the shadow, colorFocused[] = {0.5, 0.5, 0.5, 0.5};, and have text color change to black on hover (like before and vanilla). AFAIK RscButton has no property to do that, so would have to be done through EHs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is what I was thinking.

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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A style change that I can suggest is colorBackground[] = {0.15,0.15,0.15,0.4}; and bumping the size up to POS_H(1):
cba_keybind_subcat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have to be changed for the settings as well, for consistency. It's carbon coby atm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Should change both then.

x = POS_W(0);
y = POS_H(0);
w = POS_W(36);
h = POS_H(1);
};

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 {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions addons/keybinding/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down