diff --git a/scripts/communityScripts/chat/FloofChat.html b/scripts/communityScripts/chat/FloofChat.html index 7baac63455..b493b05090 100644 --- a/scripts/communityScripts/chat/FloofChat.html +++ b/scripts/communityScripts/chat/FloofChat.html @@ -389,7 +389,8 @@ function time() { var d = new Date(); - var month = (d.getMonth()).toString(); + // Months are returned in range 0-11 instead of 1-12, so we have to add 1. + var month = (d.getMonth() + 1).toString(); var day = (d.getDate()).toString(); var h = (d.getHours()).toString(); var m = (d.getMinutes()).toString(); diff --git a/scripts/communityScripts/chat/FloofChat.js b/scripts/communityScripts/chat/FloofChat.js index 6200540532..d1324bd560 100644 --- a/scripts/communityScripts/chat/FloofChat.js +++ b/scripts/communityScripts/chat/FloofChat.js @@ -6,6 +6,7 @@ // // Created by Fluffy Jenkins January 2020. // Copyright 2020 Fluffy Jenkins +// Copyright 2020 Vircadia contributors. // // For any future coders, please keep me in the loop when making changes. // Please tag me in any Pull Requests. @@ -98,6 +99,8 @@ function init() { chatBar.sendToQml(JSON.stringify({visible: false, history: chatBarHistory})); Controller.keyPressEvent.connect(keyPressEvent); Messages.messageReceived.connect(messageReceived); + AvatarManager.avatarAddedEvent.connect(avatarJoinsDomain); + AvatarManager.avatarRemovedEvent.connect(avatarLeavesDomain); connectWebSocket(); } @@ -510,13 +513,17 @@ function messageReceived(channel, message) { })); } } + if (cmd.type === "ShowChatWindow") { + toggleMainChatWindow(); + } } } } function time() { var d = new Date(); - var month = (d.getMonth()).toString(); + // Months are returned in range 0-11 instead of 1-12, so we have to add 1. + var month = (d.getMonth() + 1).toString(); var day = (d.getDate()).toString(); var h = (d.getHours()).toString(); var m = (d.getMinutes()).toString(); @@ -618,6 +625,46 @@ function setVisible(_visible) { visible = _visible; } +function avatarJoinsDomain(sessionID) { + Script.setTimeout(function () { + var messageText = AvatarManager.getPalData([sessionID]).data[0].sessionDisplayName + " has joined." + var messageColor = { red: 122, green: 122, blue: 122 }; + + addToLog(messageText, "Notice", messageColor, "Domain"); + + if (!mutedAudio["Domain"]) { + playNotificationSound(); + } + + if (!muted["Domain"]) { + Messages.sendLocalMessage(FLOOF_NOTIFICATION_CHANNEL, JSON.stringify({ + sender: "(D)", + text: messageText, + colour: { text: messageColor } + })); + } + }, 500); // Wait 500ms for the avatar to load to properly get info about them. +} + +function avatarLeavesDomain(sessionID) { + var messageText = AvatarManager.getPalData([sessionID]).data[0].sessionDisplayName + " has left." + var messageColor = { red: 122, green: 122, blue: 122 }; + + addToLog(messageText, "Notice", messageColor, "Domain"); + + if (!mutedAudio["Domain"]) { + playNotificationSound(); + } + + if (!muted["Domain"]) { + Messages.sendLocalMessage(FLOOF_NOTIFICATION_CHANNEL, JSON.stringify({ + sender: "(D)", + text: messageText, + colour: { text: messageColor } + })); + } +} + function keyPressEvent(event) { if (event.key === H_KEY && !event.isAutoRepeat && event.isControl) { toggleMainChatWindow() @@ -636,11 +683,25 @@ function shutdown() { } catch (e) { // empty } + + try { + AvatarManager.avatarAddedEvent.disconnect(avatarJoinsDomain); + } catch (e) { + // empty + } + + try { + AvatarManager.avatarRemovedEvent.disconnect(avatarLeavesDomain); + } catch (e) { + // empty + } + try { Controller.keyPressEvent.disconnect(keyPressEvent); } catch (e) { // empty } + chatBar.close(); chatHistory.close(); } diff --git a/scripts/communityScripts/notificationCore/notificationCore.js b/scripts/communityScripts/notificationCore/notificationCore.js index da88ff7c5d..7920a575ec 100644 --- a/scripts/communityScripts/notificationCore/notificationCore.js +++ b/scripts/communityScripts/notificationCore/notificationCore.js @@ -1,3 +1,17 @@ +// +// notificationCore.js +// +// Created by Fluffy Jenkins January 2020. +// Copyright 2020 Fluffy Jenkins +// Copyright 2020 Vircadia contributors. +// +// For any future coders, please keep me in the loop when making changes. +// Please tag me in any Pull Requests. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + "use strict"; var notificationList = []; @@ -6,6 +20,7 @@ var sizeData = {30: {widthMul: 1.8, heightMul: 2.05, split: 35, size: 30}}; var DEFAULT_SIZE = 30; var DEFAULT_OFFSET = 10; var FLOOF_NOTIFICATION_CHANNEL = "Floof-Notif"; +var MAIN_CHAT_APP_CHANNEL = "Chat"; var offset = DEFAULT_OFFSET; @@ -161,4 +176,19 @@ function notif(text, colour) { notificationList.push(noti); } -Script.scriptEnding.connect(cleanUp); \ No newline at end of file +Controller.mousePressEvent.connect(function (event) { + // Overlays.getOverlayAtPoint applies only to 2D overlays. + var overlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); + if (overlay) { + for (var i = 0; i < notificationList.length; i++) { + if (overlay === notificationList[i].id) { + Overlays.deleteOverlay(notificationList[i].id) + Messages.sendMessage(MAIN_CHAT_APP_CHANNEL, JSON.stringify({ + type: "ShowChatWindow", + })); + } + } + } +}); + +Script.scriptEnding.connect(cleanUp);