Index: ps/trunk/binaries/data/mods/public/gui/common/functions_utility.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/common/functions_utility.js +++ ps/trunk/binaries/data/mods/public/gui/common/functions_utility.js @@ -1,7 +1,11 @@ /** - * Used by notifyUser() to limit the number of pings - */ -var g_LastNickNotification = -1; + * Used for acoustic GUI notifications. + * Define the soundfile paths and specific time thresholds (avoid spam). + * And store the timestamp of last interaction for each notification. + */ +var g_SoundNotifications = { + "nick": { "soundfile": "audio/interface/ui/chat_alert.ogg", "threshold": 3000 } +}; // Get list of XML files in pathname with recursion, excepting those starting with _ function getXMLFileList(pathname) @@ -196,20 +200,22 @@ } /** - * Plays a sound if user's nick is mentioned in chat + * Manage acoustic GUI notifications. + * + * @param {string} type - Notification type. */ -function notifyUser(userName, msgText) +function soundNotification(type) { - if (Engine.ConfigDB_GetValue("user", "sound.notify.nick") != "true" || - msgText.toLowerCase().indexOf(userName.toLowerCase()) == -1) + if (Engine.ConfigDB_GetValue("user", "sound.notify." + type) != "true") return; + let notificationType = g_SoundNotifications[type]; let timeNow = Date.now(); - if (!g_LastNickNotification || timeNow > g_LastNickNotification + 3000) - Engine.PlayUISound("audio/interface/ui/chat_alert.ogg", false); + if (!notificationType.lastInteractionTime || timeNow > notificationType.lastInteractionTime + notificationType.threshold) + Engine.PlayUISound(notificationType.soundfile, false); - g_LastNickNotification = timeNow; + notificationType.lastInteractionTime = timeNow; } /** Index: ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -2235,9 +2235,9 @@ if (msg.type == "chat") { let userName = g_PlayerAssignments[Engine.GetPlayerGUID()].name; - - if (userName != g_PlayerAssignments[msg.guid].name) - notifyUser(userName, msg.text); + if (userName != g_PlayerAssignments[msg.guid].name && + msg.text.toLowerCase().indexOf(splitRatingFromNick(userName)[0].toLowerCase()) != -1) + soundNotification("nick"); } let user = colorizePlayernameByGUID(msg.guid || -1, msg.username || ""); Index: ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js +++ ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js @@ -1278,8 +1278,8 @@ { msg.text = msg.text.replace(g_Username, colorPlayerName(g_Username)); - if (!msg.historic) - notifyUser(g_Username, msg.text); + if (!msg.historic && msg.text.toLowerCase().indexOf(g_Username.toLowerCase()) != -1) + soundNotification("nick"); } } Index: ps/trunk/binaries/data/mods/public/gui/session/messages.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/messages.js +++ ps/trunk/binaries/data/mods/public/gui/session/messages.js @@ -1106,9 +1106,9 @@ msg.text = escapeText(msg.text); let userName = g_PlayerAssignments[Engine.GetPlayerGUID()].name; - - if (userName != g_PlayerAssignments[msg.guid].name) - notifyUser(userName, msg.text); + if (userName != g_PlayerAssignments[msg.guid].name && + msg.text.toLowerCase().indexOf(splitRatingFromNick(userName)[0].toLowerCase()) != -1) + soundNotification("nick"); } // GUID for players, playerID for AIs