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

keybind translations #631

Merged
merged 8 commits into from
Apr 15, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 26 additions & 38 deletions addons/help/XEH_postClientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,10 @@ if (!isNil QGVAR(keys)) then {
//player createDiaryRecord ["CBA_docs", [localize "STR_DN_CBA_WEBSITE", "http://dev-heaven.net/projects/cca"]];

// add diary for scripted keybinds
private _fnc_getKeyName = {
private _shift = [0, DIK_LSHIFT] select _shift;
private _ctrl = [0, DIK_LCONTROL] select _ctrl;
private _alt = [0, DIK_LMENU] select _alt;

private _keys = [_shift, _ctrl, _alt, _key];

_result = "^";

{
private _keyname1 = [cba_keybinding_dikDecToStringTable, format ["%1", _x], format ["Unknown key (%1)",_x]] call BIS_fnc_getFromPairs;
_keyname1 = [_keyname1, " "] call CBA_fnc_split;

private _keyname2 = "^";

{
_keyname2 = _keyname2 + " " + _x;
} forEach _keyname1;

_keyname2 = [_keyname2, "^ ", ""] call CBA_fnc_replace;
_result = _result + "+" + _keyname2;
} forEach _keys;

_result = [_result, "^ ", ""] call CBA_fnc_replace;
_result = [_result, "^+", ""] call CBA_fnc_replace;
_result = [_result, "^", "None"] call CBA_fnc_replace;
_result = [_result, "LAlt", "Alt"] call CBA_fnc_replace;
_result = [_result, "LCtrl", "Ctrl"] call CBA_fnc_replace;
_result = [_result, "LShift", "Shift"] call CBA_fnc_replace;
_result
};

_fnc_getKeyName spawn {
0 spawn {
private _text = GVAR(keys);

cba_keybinding_handlers params [["_modNames", [], [[]]], ["_keyHandlers", [], [[]]]];
EGVAR(keybinding,handlers) params [["_modNames", [], [[]]], ["_keyHandlers", [], [[]]]];

{
private _modName = _x;
Expand All @@ -78,7 +46,7 @@ _fnc_getKeyName spawn {
private _actionName = _x;
private _actionEntry = _actionEntries param [_forEachIndex, []];

_actionEntry params [["_displayName", "", ["", []]], ["_keyBind", [], [[]]]];
_actionEntry params [["_displayName", "", ["", []]], ["_keybind", [], [[]]]];

if (_displayName isEqualType []) then {
_displayName = _displayName param [0, ""];
Expand All @@ -88,10 +56,30 @@ _fnc_getKeyName spawn {
_displayName = [_displayName, "<", "&lt;"] call CBA_fnc_replace;
_displayName = [_displayName, ">", "&gt;"] call CBA_fnc_replace;

_keyBind params [["_key", 0, [0]], ["_mod", [], [[]]]];
_mod params [["_shift", false, [false]], ["_ctrl", false, [false]], ["_alt", false, [false]]];
_keybind params [["_key", 0, [0]], ["_modifier", [], [[]]]];
_modifier params [["_shift", false, [false]], ["_ctrl", false, [false]], ["_alt", false, [false]]];

// Try to convert dik code to a human key code.
private _keyName = EGVAR(keybinding,keyNames) getVariable str _key;

if (isNil "_keyName") then {
_keyName = format [localize LSTRING(unkownKey), _key];
};

// Build the full key combination name.
if (_shift && {!(_key in [DIK_LSHIFT, DIK_RSHIFT])}) then {
_keyName = localize "str_dik_shift" + "+" + _keyName;
};

if (_alt && {!(_key in [DIK_LMENU, DIK_RMENU])}) then {
_keyName = localize "str_dik_alt" + "+" + _keyName;
};

if (_ctrl && {!(_key in [DIK_LCONTROL, DIK_RCONTROL])}) then {
_keyName = localize "str_dik_control" + "+" + _keyName;
};

_text = _text + format [" %1: <font color='#c48214'>%2</font><br/>", _displayName, call _this];
_text = _text + format [" %1: <font color='#c48214'>%2</font><br/>", _displayName, _keyName];
} forEach _actionNames;

_text = _text + "<br/>";
Expand Down
7 changes: 6 additions & 1 deletion addons/keybinding/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ if (!hasInterface) exitWith {};
ADDON = false;

// Load DIK to string conversion table.
call COMPILE_FILE(dikDecToString);
with uiNamespace do {
GVAR(keyNames) = [GVAR(keyNamesHash)] call CBA_fnc_deserializeNamespace;
};

GVAR(keyNames) = uiNamespace getVariable QGVAR(keyNames);
GVAR(forbiddenKeys) = uiNamespace getVariable QGVAR(forbiddenKeys);

// Prepare GUI functions and variables.
PREP_SUB(gui,onButtonClick_configure);
Expand Down
183 changes: 183 additions & 0 deletions addons/keybinding/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,186 @@
#include "script_component.hpp"

PREP(configureDisplayLoad);

private _supportedKeys = [
DIK_ESCAPE,
DIK_1,
DIK_2,
DIK_3,
DIK_4,
DIK_5,
DIK_6,
DIK_7,
DIK_8,
DIK_9,
DIK_0,
DIK_MINUS,
DIK_EQUALS,
DIK_BACK,
DIK_TAB,
DIK_Q,
DIK_W,
DIK_E,
DIK_R,
DIK_T,
DIK_Y,
DIK_U,
DIK_I,
DIK_O,
DIK_P,
DIK_LBRACKET,
DIK_RBRACKET,
DIK_RETURN,
DIK_LCONTROL,
DIK_A,
DIK_S,
DIK_D,
DIK_F,
DIK_G,
DIK_H,
DIK_J,
DIK_K,
DIK_L,
DIK_SEMICOLON,
DIK_APOSTROPHE,
DIK_GRAVE,
DIK_LSHIFT,
DIK_BACKSLASH,
DIK_Z,
DIK_X,
DIK_C,
DIK_V,
DIK_B,
DIK_N,
DIK_M,
DIK_COMMA,
DIK_PERIOD,
DIK_SLASH,
DIK_RSHIFT,
DIK_MULTIPLY,
DIK_LMENU,
DIK_SPACE,
DIK_CAPITAL,
DIK_F1,
DIK_F2,
DIK_F3,
DIK_F4,
DIK_F5,
DIK_F6,
DIK_F7,
DIK_F8,
DIK_F9,
DIK_F10,
DIK_NUMLOCK,
DIK_SCROLL,
DIK_NUMPAD7,
DIK_NUMPAD8,
DIK_NUMPAD9,
DIK_SUBTRACT,
DIK_NUMPAD4,
DIK_NUMPAD5,
DIK_NUMPAD6,
DIK_ADD,
DIK_NUMPAD1,
DIK_NUMPAD2,
DIK_NUMPAD3,
DIK_NUMPAD0,
DIK_DECIMAL,
DIK_OEM_102,
DIK_F11,
DIK_F12,
DIK_F13,
DIK_F14,
DIK_F15,
DIK_KANA,
DIK_ABNT_C1,
DIK_CONVERT,
DIK_NOCONVERT,
DIK_YEN,
DIK_ABNT_C2,
DIK_NUMPADEQUALS,
DIK_PREVTRACK,
DIK_AT,
DIK_COLON,
DIK_UNDERLINE,
DIK_KANJI,
DIK_STOP,
DIK_AX,
DIK_UNLABELED,
DIK_NEXTTRACK,
DIK_NUMPADENTER,
DIK_RCONTROL,
DIK_MUTE,
DIK_CALCULATOR,
DIK_PLAYPAUSE,
DIK_MEDIASTOP,
DIK_VOLUMEDOWN,
DIK_VOLUMEUP,
DIK_WEBHOME,
DIK_NUMPADCOMMA,
DIK_DIVIDE,
DIK_SYSRQ,
DIK_RMENU,
DIK_PAUSE,
DIK_HOME,
DIK_UP,
DIK_PRIOR,
DIK_LEFT,
DIK_RIGHT,
DIK_END,
DIK_DOWN,
DIK_NEXT,
DIK_INSERT,
DIK_DELETE,
DIK_LWIN,
DIK_RWIN,
DIK_APPS,
DIK_POWER,
DIK_SLEEP,
DIK_WAKE,
DIK_WEBSEARCH,
DIK_WEBFAVORITES,
DIK_WEBREFRESH,
DIK_WEBSTOP,
DIK_WEBFORWARD,
DIK_WEBBACK,
DIK_MYCOMPUTER,
DIK_MAIL,
DIK_MEDIASELECT,
DIK_XBOX_A,
DIK_XBOX_B,
DIK_XBOX_X,
DIK_XBOX_Y,
DIK_XBOX_UP,
DIK_XBOX_DOWN,
DIK_XBOX_LEFT,
DIK_XBOX_RIGHT,
DIK_XBOX_START,
DIK_XBOX_BACK,
DIK_XBOX_BLACK,
DIK_XBOX_WHITE,
DIK_XBOX_LEFT_THUMB,
DIK_XBOX_RIGHT_THUMB
];

_supportedKeys = _supportedKeys apply {
// strip away additional quote marks
private _keyName = parseSimpleArray format ["[%1]", keyName _x] select 0;

[str _x, _keyName]
};

GVAR(keyNamesHash) = [_supportedKeys] call CBA_fnc_hashCreate;

GVAR(forbiddenKeys) = [
DIK_XBOX_LEFT_TRIGGER,
DIK_XBOX_RIGHT_TRIGGER,
DIK_XBOX_LEFT_THUMB_X_RIGHT,
DIK_XBOX_LEFT_THUMB_Y_UP,
DIK_XBOX_RIGHT_THUMB_X_RIGHT,
DIK_XBOX_RIGHT_THUMB_Y_UP,
DIK_XBOX_LEFT_THUMB_X_LEFT,
DIK_XBOX_LEFT_THUMB_Y_DOWN,
DIK_XBOX_RIGHT_THUMB_X_LEFT,
DIK_XBOX_RIGHT_THUMB_Y_DOWN
];
Loading