From 11d5833c6171de1796e99e1255955d3e9e3d7562 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Sat, 16 Apr 2022 21:42:44 -0500 Subject: [PATCH] Add keypress for some GUI buttons + fix prompt text --- scripts/client/gui.js | 41 +++++++++++++++++++------------- scripts/client/gui/charselect.js | 5 ++++ scripts/client/gui/error.js | 4 +++- scripts/client/gui/info.js | 4 +++- scripts/client/gui/yesno.js | 5 +++- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/scripts/client/gui.js b/scripts/client/gui.js index 52b88f8b..a780f47f 100644 --- a/scripts/client/gui.js +++ b/scripts/client/gui.js @@ -29,12 +29,6 @@ let textInputAlpha = 180; let guiReady = false; -let guiSubmitKey = false; -let guiLeftKey = false; -let guiRightKey = false; -let guiUpKey = false; -let guiDownKey = false; - // =========================================================================== let characterData = []; @@ -170,23 +164,23 @@ addNetworkEventHandler("vrr.switchCharacterSelect", function(firstName, lastName // =========================================================================== -addNetworkEventHandler("vrr.showError", function(errorMessage, errorTitle) { +addNetworkEventHandler("vrr.showError", function(errorMessage, errorTitle, buttonText) { logToConsole(LOG_DEBUG, `[VRR.GUI] Received request from server to show error window`); - showError(errorMessage, errorTitle); + showError(errorMessage, errorTitle, buttonText); }); // =========================================================================== -addNetworkEventHandler("vrr.showPrompt", function(promptMessage, promptTitle) { +addNetworkEventHandler("vrr.showPrompt", function(promptMessage, promptTitle, yesButtonText, noButtonText) { logToConsole(LOG_DEBUG, `[VRR.GUI] Received request from server to show prompt window`); - showYesNoPromptGUI(promptMessage, promptTitle); + showYesNoPromptGUI(promptMessage, promptTitle, yesButtonText, noButtonText); }); // =========================================================================== -addNetworkEventHandler("vrr.showInfo", function(infoMessage) { +addNetworkEventHandler("vrr.showInfo", function(infoMessage, buttonText) { logToConsole(LOG_DEBUG, `[VRR.GUI] Received request from server to show info dialog`); - showInfo(infoMessage); + showInfo(infoMessage, buttonText); }); // =========================================================================== @@ -277,29 +271,42 @@ function hideAllGUI() { // =========================================================================== function processGUIKeyPress(keyCode) { + logToConsole(LOG_DEBUG, `[VRR.GUI] Processing key press: ${keyCode}`); + if(!isAnyGUIActive()) { + logToConsole(LOG_DEBUG, `[VRR.GUI] GUI is not active. Cancelling keypress processing.`); return false; } if(keyCode == SDLK_RETURN || keyCode == SDLK_RETURN2) { + logToConsole(LOG_DEBUG, `[VRR.GUI] Key press is submit (${guiSubmitKey})`); if(guiSubmitKey != false) { - guiSubmitKey(); + logToConsole(LOG_DEBUG, `[VRR.GUI] Calling submit key function`); + guiSubmitKey.call(); } } else if(keyCode == getKeyIdFromParams("left") || keyCode == getKeyIdFromParams("a")) { + logToConsole(LOG_DEBUG, `[VRR.GUI] Key press is left (${guiLeftKey})`); if(guiLeftKey != false) { - guiLeftKey(); + logToConsole(LOG_DEBUG, `[VRR.GUI] Calling left key function`); + guiLeftKey.call(); } } else if(keyCode == getKeyIdFromParams("right") || keyCode == getKeyIdFromParams("d")) { + logToConsole(LOG_DEBUG, `[VRR.GUI] Key press is right (${guiRightKey})`); if(guiRightKey != false) { - guiRightKey(); + logToConsole(LOG_DEBUG, `[VRR.GUI] Calling right key function`); + guiRightKey.call(); } } else if(keyCode == getKeyIdFromParams("down") || keyCode == getKeyIdFromParams("s")) { + logToConsole(LOG_DEBUG, `[VRR.GUI] Key press is down (${guiDownKey})`); if(guiDownKey != false) { - guiDownKey(); + logToConsole(LOG_DEBUG, `[VRR.GUI] Calling down key function`); + guiDownKey.call(); } } else if(keyCode == getKeyIdFromParams("up") || keyCode == getKeyIdFromParams("w")) { + logToConsole(LOG_DEBUG, `[VRR.GUI] Key press is up (${guiUpKey})`); if(guiUpKey != false) { - guiUpKey(); + logToConsole(LOG_DEBUG, `[VRR.GUI] Calling up key function`); + guiUpKey.call(); } } } diff --git a/scripts/client/gui/charselect.js b/scripts/client/gui/charselect.js index fb9b25fb..ecd1f191 100644 --- a/scripts/client/gui/charselect.js +++ b/scripts/client/gui/charselect.js @@ -163,6 +163,10 @@ function showCharacterSelectGUI(firstName, lastName, cash, clan, lastPlayed, ski characterSelect.lastPlayedText.text = `Last Played: ${lastPlayed}`; characterSelect.skinImage = characterSelect.window.image(310, 32, 100, 90, "files/images/skins/none.png"); characterSelect.window.shown = true; + + guiSubmitKey = selectThisCharacter; + guiLeftKey = selectPreviousCharacter; + guiRightKey = selectNextCharacter; } // =========================================================================== @@ -211,6 +215,7 @@ function switchCharacterSelectGUI(firstName, lastName, cash, clan, lastPlayed, s characterSelect.skinImage = (getGame() == VRR_GAME_GTA_III) ? characterSelect.window.image(310, 32, 100, 90, `files/images/skins/gta3/${getSkinImage(skinId)}.png`) : characterSelect.window.image(310, 32, 100, 90, "files/images/skins/none.png"); characterSelect.window.shown = true; + guiSubmitKey = selectThisCharacter; guiLeftKey = selectPreviousCharacter; guiRightKey = selectNextCharacter; diff --git a/scripts/client/gui/error.js b/scripts/client/gui/error.js index 25315568..3516f00b 100644 --- a/scripts/client/gui/error.js +++ b/scripts/client/gui/error.js @@ -63,12 +63,14 @@ function initErrorDialogGUI() { // =========================================================================== -function showErrorGUI(errorMessage, errorTitle) { +function showErrorGUI(errorMessage, errorTitle, buttonText) { closeAllWindows(); logToConsole(LOG_DEBUG, `[VRR.GUI] Showing error window. Error: ${errorTitle} - ${errorMessage}`); setChatWindowEnabled(false); mexui.setInput(true); errorDialog.messageLabel.text = errorMessage; + errorDialog.okayButton.text = buttonText; + errprDialog.window.title = errorTitle; errorDialog.window.shown = true; } diff --git a/scripts/client/gui/info.js b/scripts/client/gui/info.js index 7ecff81b..f2f4582b 100644 --- a/scripts/client/gui/info.js +++ b/scripts/client/gui/info.js @@ -70,11 +70,13 @@ function closeInfoDialog() { // =========================================================================== -function showInfo(infoMessage, infoTitle) { +function showInfo(infoMessage, infoTitle, buttonText) { closeAllWindows(); logToConsole(LOG_DEBUG, `[VRR.GUI] Showing info dialog window. Info: ${infoTitle} - ${infoMessage}`); mexui.setInput(true); infoDialog.messageLabel.text = infoMessage; + infoDialog.okayButton.text = buttonText; + infoDialog.window.title = infoTitle; infoDialog.window.shown = true; } diff --git a/scripts/client/gui/yesno.js b/scripts/client/gui/yesno.js index 60487747..26fb2770 100644 --- a/scripts/client/gui/yesno.js +++ b/scripts/client/gui/yesno.js @@ -78,11 +78,14 @@ function initYesNoDialogGUI() { // =========================================================================== -function showYesNoPromptGUI(promptMessage, promptTitle) { +function showYesNoPromptGUI(promptMessage, promptTitle, yesButtonText, noButtonText) { closeAllWindows(); logToConsole(LOG_DEBUG, `[VRR.GUI] Showing prompt window. Prompt: ${promptTitle} - ${promptMessage}`); mexui.setInput(true); yesNoDialog.messageLabel.text = promptMessage; + yesNoDialog.yesButton.text = yesButtonText; + yesNoDialog.noButton.text = noButtonText; + yesNoDialog.window.title = promptTitle; yesNoDialog.window.shown = true; }