From 7d74d11a8dadacc3a2723fe748b0ceb82f3eb55a Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Sun, 25 Jul 2021 22:10:49 -0500 Subject: [PATCH] Use new keybind utils --- scripts/client/chatbox.js | 13 +++++++++---- scripts/client/keybind.js | 12 ++++++++++++ scripts/client/server.js | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/client/chatbox.js b/scripts/client/chatbox.js index 9d853793..a014badc 100644 --- a/scripts/client/chatbox.js +++ b/scripts/client/chatbox.js @@ -16,10 +16,15 @@ let maxChatBoxHistory = 500; let scrollAmount = 1; let maxChatBoxLines = 6; +let scrollUpKey = false; +let scrollDownKey = false; + // =========================================================================== function initChatBoxScript() { logToConsole(LOG_DEBUG, "[VRR.ChatBox]: Initializing chatbox script ..."); + scrollUpKey = getKeyIdFromParams("pageup"); + scrollDownKey = getKeyIdFromParams("pagedown"); bindChatBoxKeys(); logToConsole(LOG_DEBUG, "[VRR.ChatBox]: Chatbox script initialized!"); } @@ -27,15 +32,15 @@ function initChatBoxScript() { // =========================================================================== function bindChatBoxKeys() { - bindKey(SDLK_PAGEUP, KEYSTATE_DOWN, chatBoxScrollUp); - bindKey(SDLK_PAGEDOWN, KEYSTATE_DOWN, chatBoxScrollDown); + bindKey(toInteger(scrollUpKey), KEYSTATE_DOWN, chatBoxScrollUp); + bindKey(toInteger(scrollDownKey), KEYSTATE_DOWN, chatBoxScrollDown); } // =========================================================================== function unBindChatBoxKeys() { - unbindKey(SDLK_PAGEUP); - unbindKey(SDLK_PAGEDOWN); + unbindKey(toInteger(scrollUpKey)); + unbindKey(toInteger(scrollDownKey)); } // =========================================================================== diff --git a/scripts/client/keybind.js b/scripts/client/keybind.js index 4e8d1151..edbb18b7 100644 --- a/scripts/client/keybind.js +++ b/scripts/client/keybind.js @@ -7,6 +7,7 @@ // TYPE: Client (JavaScript) // =========================================================================== +let keyBinds = []; let lastKeyBindUse = 0; let keyBindDelayTime = 500; let keyBindShortHoldDuration = 500; @@ -23,6 +24,7 @@ function initKeyBindScript() { function bindAccountKey(key, keyState) { logToConsole(LOG_DEBUG, `[VRR.KeyBind]: Binded key ${toUpperCase(getKeyNameFromId(key))} (${key})`); + keyBinds.push(toInteger(key)); bindKey(toInteger(key), keyState, function(event) { if(hasKeyBindDelayElapsed()) { if(canLocalPlayerUseKeyBinds()) { @@ -43,6 +45,7 @@ function bindAccountKey(key, keyState) { function unBindAccountKey(key) { logToConsole(LOG_DEBUG, `[VRR.KeyBind]: Unbinded key ${toUpperCase(getKeyNameFromId(key))} (${key})`); unbindKey(key); + keyBinds.splice(keyBinds.indexOf(key), 1); return true; } @@ -62,4 +65,13 @@ function canLocalPlayerUseKeyBinds() { return true; //(!usingSkinSelector && isSpawned && !itemActionDelayEnabled); } +// =========================================================================== + +function clearKeyBinds() { + for(let i in keyBinds) { + unbindKey(keyBinds[i]); + } + keyBinds = []; +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/client/server.js b/scripts/client/server.js index 90a6c627..11750c76 100644 --- a/scripts/client/server.js +++ b/scripts/client/server.js @@ -62,6 +62,7 @@ function addAllNetworkHandlers() { addNetworkHandler("vrr.delKeyBind", unBindAccountKey); addNetworkHandler("vrr.addKeyBind", bindAccountKey); + addNetworkHandler("vrr.clearKeyBinds", clearKeyBinds); addNetworkHandler("vrr.nametag", updatePlayerNameTag); addNetworkHandler("vrr.ping", updatePlayerPing);