From 1f095a5ed05d02a780ad94c9f6cd722c38e88154 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Tue, 22 Mar 2022 00:14:58 -0500 Subject: [PATCH] Chat box auto-hide (for next GTAC update) --- scripts/client/chatbox.js | 35 ++++++++++++++++++++++++++++++++++- scripts/client/server.js | 1 + scripts/server/account.js | 21 +++++++++++++++++++++ scripts/server/class.js | 2 ++ scripts/server/client.js | 6 ++++++ scripts/server/command.js | 3 ++- 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/scripts/client/chatbox.js b/scripts/client/chatbox.js index 46813eee..b14dd176 100644 --- a/scripts/client/chatbox.js +++ b/scripts/client/chatbox.js @@ -16,6 +16,9 @@ let maxChatBoxHistory = 500; let scrollAmount = 1; let maxChatBoxLines = 6; +let chatAutoHideDelay = 0; +let chatLastUse = 0; + let scrollUpKey = false; let scrollDownKey = false; @@ -47,6 +50,10 @@ function unBindChatBoxKeys() { function receiveChatBoxMessageFromServer(messageString, colour) { logToConsole(LOG_DEBUG, `[VRR.ChatBox]: Received chatbox message from server: ${messageString}`); + + // Just in case it's hidden by auto hide + setChatWindowEnabled(true); + let colouredString = replaceColoursInMessage(messageString); if(bottomMessageIndex >= chatBoxHistory.length-1) { @@ -54,6 +61,7 @@ function receiveChatBoxMessageFromServer(messageString, colour) { bottomMessageIndex = chatBoxHistory.length-1; } addToChatBoxHistory(colouredString, colour); + chatLastUse = getCurrentUnixTimestamp(); } // =========================================================================== @@ -64,6 +72,12 @@ function setChatScrollLines(amount) { // =========================================================================== +function setChatAutoHideDelay(delay) { + chatAutoHideDelay = delay*1000; +} + +// =========================================================================== + function addToChatBoxHistory(messageString, colour) { chatBoxHistory.push([messageString, colour]); } @@ -105,6 +119,7 @@ function updateChatBox() { message("", COLOUR_WHITE); } } + chatLastUse = getCurrentUnixTimestamp(); } // =========================================================================== @@ -118,7 +133,25 @@ function processMouseWheelForChatBox(up) { if(up) { chatBoxScrollUp(); } else { - chatBoxScrollDown() + chatBoxScrollDown(); + } +} + +// =========================================================================== + +function checkChatAutoHide() { + // Make sure chat input isn't active + if(gui.cursorEnabled) { + return false; + } + + // Don't process auto-hide if it's disabled + if(chatAutoHideDelay == 0) { + return false; + } + + if(getCurrentUnixTimestamp()-chatLastUse >= chatAutoHideDelay) { + setChatWindowEnabled(false); } } diff --git a/scripts/client/server.js b/scripts/client/server.js index ad85c825..c53e058c 100644 --- a/scripts/client/server.js +++ b/scripts/client/server.js @@ -21,6 +21,7 @@ function addAllNetworkHandlers() { // Chat history addNetworkEventHandler("m", receiveChatBoxMessageFromServer); // Not prefixed with VRR to make it as small as possible addNetworkEventHandler("vrr.chatScrollLines", setChatScrollLines); + addNetworkEventHandler("vrr.chatAutoHideDelay", setChatAutoHideDelay); // Messaging (like textdraws and stuff) addNetworkEventHandler("vrr.smallGameMessage", showSmallGameMessage); diff --git a/scripts/server/account.js b/scripts/server/account.js index c128ea23..dd94a97f 100644 --- a/scripts/server/account.js +++ b/scripts/server/account.js @@ -271,6 +271,26 @@ function setAccountChatScrollLinesCommand(command, params, client) { // =========================================================================== +function setAccountChatAutoHideDelayCommand(command, params, client) { + if(areParamsEmpty(params)) { + messagePlayerSyntax(client, getCommandSyntaxText(command)); + return false; + } + + if(isNaN(params)) { + messagePlayerError(client, `The delay time must be a number!`); + return false; + } + + let delay = Math.ceil(toInteger(params)); + + getPlayerData(client).accountData.chatAutoHideDelay = delay; + sendPlayerChatAutoHideDelay(client, delay); + messagePlayerSuccess(client, `Your chatbox will now automatically hide after ${toInteger(delay)} seconds!`); +} + +// =========================================================================== + function setAccountEmailCommand(command, params, client) { if(areParamsEmpty(params)) { messagePlayerSyntax(client, getCommandSyntaxText(command)); @@ -637,6 +657,7 @@ function saveAccountToDatabase(accountData) { ["acct_svr_staff_flags", accountData.flags.admin], ["acct_svr_mod_flags", accountData.flags.moderation], ["acct_svr_chat_scroll_lines", accountData.chatScrollLines], + ["acct_svr_chat_auto_hide_delay", accountData.chatAutoHideDelay], ]; let queryString1 = createDatabaseUpdateQuery("acct_main", data, `acct_id=${accountData.databaseId}`); diff --git a/scripts/server/class.js b/scripts/server/class.js index e90b2aba..eab66010 100644 --- a/scripts/server/class.js +++ b/scripts/server/class.js @@ -275,6 +275,7 @@ class AccountData { this.twoFactorAuthVerificationCode = ""; this.chatScrollLines = 1; + this.chatAutoHideDelay = 0; this.streamingRadioVolume = 20; this.locale = 0; @@ -304,6 +305,7 @@ class AccountData { this.emailVerificationCode = dbAssoc["acct_code_verifyemail"]; this.twoFactorAuthVerificationCode = dbAssoc["acct_code_2fa"]; this.chatScrollLines = toInteger(dbAssoc["acct_svr_chat_scroll_lines"]); + this.chatAutoHideDelay = toInteger(dbAssoc["acct_svr_chat_auto_hide_delay"]); this.streamingRadioVolume = toInteger(dbAssoc["acct_streaming_radio_volume"]); this.locale = toInteger(dbAssoc["acct_locale"]); } diff --git a/scripts/server/client.js b/scripts/server/client.js index 59d47601..93c85b31 100644 --- a/scripts/server/client.js +++ b/scripts/server/client.js @@ -938,6 +938,12 @@ function sendPlayerChatScrollLines(client, amount) { // =========================================================================== +function sendPlayerChatAutoHideDelay(client, delay) { + sendNetworkEventToPlayer("vrr.chatAutoHideDelay", client, delay); +} + +// =========================================================================== + function playRadioStreamForPlayer(client, streamURL, loop = true, volume = 0, element = false) { logToConsole(LOG_DEBUG, `[VRR.Client] Forcing ${getPlayerDisplayForConsole(client)} to stream ${streamURL}`); sendNetworkEventToPlayer("vrr.radioStream", client, streamURL, loop, volume, element); diff --git a/scripts/server/command.js b/scripts/server/command.js index d9e87bdc..0b5058f5 100644 --- a/scripts/server/command.js +++ b/scripts/server/command.js @@ -55,7 +55,8 @@ function loadCommands() { //commandData("setdiscord", setAccountDiscordCommand, "", getStaffFlagValue("None"), true, false, "Set up the integration for discord. Allows you to see info and use in-game commands on discord."), commandData("notips", toggleNoRandomTipsCommand, "", getStaffFlagValue("None"), true, false, "Turn on and off random tips"), commandData("loginalert", toggleAccountLoginAttemptNotificationsCommand, "", getStaffFlagValue("None"), true, false, "Turn on and off email notifications for attempts to login to your account"), - commandData("scrolllines", setAccountChatScrollLinesCommand, "", getStaffFlagValue("None"), true, false, "Sets how many chatbox lines to scroll at a time when using pageup/pagedown"), + commandData("scrolllines", setAccountChatScrollLinesCommand, "", getStaffFlagValue("None"), true, false, "Sets how many chatbox lines to scroll at a time when using pageup/pagedown"), + commandData("chatautohide", setAccountChatAutoHideDelayCommand, "