Chat box auto-hide (for next GTAC update)

This commit is contained in:
Vortrex
2022-03-22 00:14:58 -05:00
parent ba50a90e20
commit 1f095a5ed0
6 changed files with 66 additions and 2 deletions

View File

@@ -16,6 +16,9 @@ let maxChatBoxHistory = 500;
let scrollAmount = 1; let scrollAmount = 1;
let maxChatBoxLines = 6; let maxChatBoxLines = 6;
let chatAutoHideDelay = 0;
let chatLastUse = 0;
let scrollUpKey = false; let scrollUpKey = false;
let scrollDownKey = false; let scrollDownKey = false;
@@ -47,6 +50,10 @@ function unBindChatBoxKeys() {
function receiveChatBoxMessageFromServer(messageString, colour) { function receiveChatBoxMessageFromServer(messageString, colour) {
logToConsole(LOG_DEBUG, `[VRR.ChatBox]: Received chatbox message from server: ${messageString}`); 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); let colouredString = replaceColoursInMessage(messageString);
if(bottomMessageIndex >= chatBoxHistory.length-1) { if(bottomMessageIndex >= chatBoxHistory.length-1) {
@@ -54,6 +61,7 @@ function receiveChatBoxMessageFromServer(messageString, colour) {
bottomMessageIndex = chatBoxHistory.length-1; bottomMessageIndex = chatBoxHistory.length-1;
} }
addToChatBoxHistory(colouredString, colour); addToChatBoxHistory(colouredString, colour);
chatLastUse = getCurrentUnixTimestamp();
} }
// =========================================================================== // ===========================================================================
@@ -64,6 +72,12 @@ function setChatScrollLines(amount) {
// =========================================================================== // ===========================================================================
function setChatAutoHideDelay(delay) {
chatAutoHideDelay = delay*1000;
}
// ===========================================================================
function addToChatBoxHistory(messageString, colour) { function addToChatBoxHistory(messageString, colour) {
chatBoxHistory.push([messageString, colour]); chatBoxHistory.push([messageString, colour]);
} }
@@ -105,6 +119,7 @@ function updateChatBox() {
message("", COLOUR_WHITE); message("", COLOUR_WHITE);
} }
} }
chatLastUse = getCurrentUnixTimestamp();
} }
// =========================================================================== // ===========================================================================
@@ -118,7 +133,25 @@ function processMouseWheelForChatBox(up) {
if(up) { if(up) {
chatBoxScrollUp(); chatBoxScrollUp();
} else { } 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);
} }
} }

View File

@@ -21,6 +21,7 @@ function addAllNetworkHandlers() {
// Chat history // Chat history
addNetworkEventHandler("m", receiveChatBoxMessageFromServer); // Not prefixed with VRR to make it as small as possible addNetworkEventHandler("m", receiveChatBoxMessageFromServer); // Not prefixed with VRR to make it as small as possible
addNetworkEventHandler("vrr.chatScrollLines", setChatScrollLines); addNetworkEventHandler("vrr.chatScrollLines", setChatScrollLines);
addNetworkEventHandler("vrr.chatAutoHideDelay", setChatAutoHideDelay);
// Messaging (like textdraws and stuff) // Messaging (like textdraws and stuff)
addNetworkEventHandler("vrr.smallGameMessage", showSmallGameMessage); addNetworkEventHandler("vrr.smallGameMessage", showSmallGameMessage);

View File

@@ -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) { function setAccountEmailCommand(command, params, client) {
if(areParamsEmpty(params)) { if(areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command)); messagePlayerSyntax(client, getCommandSyntaxText(command));
@@ -637,6 +657,7 @@ function saveAccountToDatabase(accountData) {
["acct_svr_staff_flags", accountData.flags.admin], ["acct_svr_staff_flags", accountData.flags.admin],
["acct_svr_mod_flags", accountData.flags.moderation], ["acct_svr_mod_flags", accountData.flags.moderation],
["acct_svr_chat_scroll_lines", accountData.chatScrollLines], ["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}`); let queryString1 = createDatabaseUpdateQuery("acct_main", data, `acct_id=${accountData.databaseId}`);

View File

@@ -275,6 +275,7 @@ class AccountData {
this.twoFactorAuthVerificationCode = ""; this.twoFactorAuthVerificationCode = "";
this.chatScrollLines = 1; this.chatScrollLines = 1;
this.chatAutoHideDelay = 0;
this.streamingRadioVolume = 20; this.streamingRadioVolume = 20;
this.locale = 0; this.locale = 0;
@@ -304,6 +305,7 @@ class AccountData {
this.emailVerificationCode = dbAssoc["acct_code_verifyemail"]; this.emailVerificationCode = dbAssoc["acct_code_verifyemail"];
this.twoFactorAuthVerificationCode = dbAssoc["acct_code_2fa"]; this.twoFactorAuthVerificationCode = dbAssoc["acct_code_2fa"];
this.chatScrollLines = toInteger(dbAssoc["acct_svr_chat_scroll_lines"]); 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.streamingRadioVolume = toInteger(dbAssoc["acct_streaming_radio_volume"]);
this.locale = toInteger(dbAssoc["acct_locale"]); this.locale = toInteger(dbAssoc["acct_locale"]);
} }

View File

@@ -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) { function playRadioStreamForPlayer(client, streamURL, loop = true, volume = 0, element = false) {
logToConsole(LOG_DEBUG, `[VRR.Client] Forcing ${getPlayerDisplayForConsole(client)} to stream ${streamURL}`); logToConsole(LOG_DEBUG, `[VRR.Client] Forcing ${getPlayerDisplayForConsole(client)} to stream ${streamURL}`);
sendNetworkEventToPlayer("vrr.radioStream", client, streamURL, loop, volume, element); sendNetworkEventToPlayer("vrr.radioStream", client, streamURL, loop, volume, element);

View File

@@ -55,7 +55,8 @@ function loadCommands() {
//commandData("setdiscord", setAccountDiscordCommand, "<discord id>", getStaffFlagValue("None"), true, false, "Set up the integration for discord. Allows you to see info and use in-game commands on discord."), //commandData("setdiscord", setAccountDiscordCommand, "<discord id>", 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("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("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, "<number of lines>", getStaffFlagValue("None"), true, false, "Sets how many chatbox lines to scroll at a time when using pageup/pagedown"),
commandData("chatautohide", setAccountChatAutoHideDelayCommand, "<time in seconds>", getStaffFlagValue("None"), true, false, "Sets how long to wait to hide the chatbox after last use (in seconds)"),
], ],
ammunation: [], ammunation: [],