mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-13 11:06:39 +02:00
Merge pull request #579 from kasenvr/feature/chat-improvements-noti
Feature/chat improvements noti
This commit is contained in:
commit
8f3377b716
3 changed files with 95 additions and 3 deletions
scripts/communityScripts
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue