This commit is contained in:
Howard Stearns 2017-04-26 08:20:12 -07:00
parent ee9b953b1c
commit 0f8ee7051c
2 changed files with 571 additions and 568 deletions

View file

@ -1,5 +1,6 @@
"use strict";
/*jslint vars:true, plusplus:true, forin:true*/
/*global Script, Settings, Window, Controller, Overlays, SoundArray, LODManager, MyAvatar, Tablet, Camera, HMD, Menu, Quat, Vec3*/
//
// notifications.js
// Version 0.801
@ -56,7 +57,6 @@
// }
// }
/* global Script, Controller, Overlays, SoundArray, Quat, Vec3, MyAvatar, Menu, HMD, AudioDevice, LODManager, Settings, Camera */
(function () { // BEGIN LOCAL_SCOPE
@ -77,8 +77,6 @@ var PERSIST_TIME_2D = 10.0; // Time in seconds before notification fades
var PERSIST_TIME_3D = 15.0;
var persistTime = PERSIST_TIME_2D;
var frame = 0;
var ourWidth = Window.innerWidth;
var ourHeight = Window.innerHeight;
var ctrlIsPressed = false;
var ready = true;
var MENU_NAME = 'Tools > Notifications';
@ -105,13 +103,14 @@ var NotificationType = {
{ text: "Connection" }
],
getTypeFromMenuItem: function (menuItemName) {
var type;
if (menuItemName.substr(menuItemName.length - NOTIFICATION_MENU_ITEM_POST.length) !== NOTIFICATION_MENU_ITEM_POST) {
return NotificationType.UNKNOWN;
}
var preMenuItemName = menuItemName.substr(0, menuItemName.length - NOTIFICATION_MENU_ITEM_POST.length);
for (var type in this.properties) {
for (type in this.properties) {
if (this.properties[type].text === preMenuItemName) {
return parseInt(type) + 1;
return parseInt(type, 10) + 1;
}
}
return NotificationType.UNKNOWN;
@ -123,8 +122,9 @@ var NotificationType = {
var randomSounds = new SoundArray({ localOnly: true }, true);
var numberOfSounds = 2;
for (var i = 1; i <= numberOfSounds; i++) {
randomSounds.addSound(Script.resolvePath("assets/sounds/notification-general"+ i + ".raw"));
var soundIndex;
for (soundIndex = 1; soundIndex <= numberOfSounds; soundIndex++) {
randomSounds.addSound(Script.resolvePath("assets/sounds/notification-general" + soundIndex + ".raw"));
}
var notifications = [];
@ -150,7 +150,7 @@ function createArrays(notice, button, createTime, height, myAlpha) {
// This handles the final dismissal of a notification after fading
function dismiss(firstNoteOut, firstButOut, firstOut) {
if (firstNoteOut == lodTextID) {
if (firstNoteOut === lodTextID) {
lodTextID = false;
}
@ -290,32 +290,33 @@ function notify(notice, button, height, imageProperties, image) {
avatarOrientation,
notificationPosition,
notificationOrientation,
buttonPosition;
buttonPosition,
notificationIndex;
if (isOnHMD && notifications.length > 0) {
// Update 3D overlays to maintain positions relative to avatar
defaultEyePosition = MyAvatar.getDefaultEyePosition();
avatarOrientation = MyAvatar.orientation;
for (i = 0; i < notifications.length; i += 1) {
for (notificationIndex = 0; notificationIndex < notifications.length; notificationIndex += 1) {
notificationPosition = Vec3.sum(defaultEyePosition,
Vec3.multiplyQbyV(avatarOrientation,
overlay3DDetails[i].notificationPosition));
overlay3DDetails[notificationIndex].notificationPosition));
notificationOrientation = Quat.multiply(avatarOrientation,
overlay3DDetails[i].notificationOrientation);
overlay3DDetails[notificationIndex].notificationOrientation);
buttonPosition = Vec3.sum(defaultEyePosition,
Vec3.multiplyQbyV(avatarOrientation,
overlay3DDetails[i].buttonPosition));
Overlays.editOverlay(notifications[i], { position: notificationPosition,
overlay3DDetails[notificationIndex].buttonPosition));
Overlays.editOverlay(notifications[notificationIndex], { position: notificationPosition,
rotation: notificationOrientation });
Overlays.editOverlay(buttons[i], { position: buttonPosition, rotation: notificationOrientation });
Overlays.editOverlay(buttons[notificationIndex], { position: buttonPosition, rotation: notificationOrientation });
}
}
} else {
if (!image) {
notificationText = Overlays.addOverlay("text", notice);
notifications.push((notificationText));
notifications.push(notificationText);
} else {
notifications.push(Overlays.addOverlay("image", notice));
}
@ -413,7 +414,7 @@ function createNotification(text, notificationType, imageProperties) {
function deleteNotification(index) {
var notificationTextID = notifications[index];
if (notificationTextID == lodTextID) {
if (notificationTextID === lodTextID) {
lodTextID = false;
}
Overlays.deleteOverlay(notificationTextID);
@ -448,8 +449,7 @@ function wordWrap(string) {
}
function update() {
var nextOverlay,
noticeOut,
var noticeOut,
buttonOut,
arraysOut,
positions,
@ -470,7 +470,6 @@ function update() {
if ((frame % 60.0) === 0) { // only update once a second
locationY = 20.0;
for (i = 0; i < arrays.length; i += 1) { //repositions overlays as others fade
nextOverlay = Overlays.getOverlayAtPoint({ x: overlayLocationX, y: locationY });
Overlays.editOverlay(notifications[i], { x: overlayLocationX, y: locationY });
Overlays.editOverlay(buttons[i], { x: buttonLocationX, y: locationY + 12.0 });
if (isOnHMD) {
@ -593,6 +592,7 @@ function keyPressEvent(key) {
}
function setup() {
var type;
Menu.addMenu(MENU_NAME);
var checked = Settings.getValue(PLAY_NOTIFICATION_SOUNDS_SETTING);
checked = checked === '' ? true : checked;
@ -603,8 +603,8 @@ function setup() {
isChecked: Settings.getValue(PLAY_NOTIFICATION_SOUNDS_SETTING)
});
Menu.addSeparator(MENU_NAME, "Play sounds for:");
for (var type in NotificationType.properties) {
checked = Settings.getValue(PLAY_NOTIFICATION_SOUNDS_TYPE_SETTING_PRE + (parseInt(type) + 1));
for (type in NotificationType.properties) {
checked = Settings.getValue(PLAY_NOTIFICATION_SOUNDS_TYPE_SETTING_PRE + (parseInt(type, 10) + 1));
checked = checked === '' ? true : checked;
Menu.addMenuItem({
menuName: MENU_NAME,
@ -617,9 +617,10 @@ function setup() {
// When our script shuts down, we should clean up all of our overlays
function scriptEnding() {
for (var i = 0; i < notifications.length; i++) {
Overlays.deleteOverlay(notifications[i]);
Overlays.deleteOverlay(buttons[i]);
var notificationIndex;
for (notificationIndex = 0; notificationIndex < notifications.length; notificationIndex++) {
Overlays.deleteOverlay(notifications[notificationIndex]);
Overlays.deleteOverlay(buttons[notificationIndex]);
}
Menu.removeMenu(MENU_NAME);
}

View file

@ -1,4 +1,6 @@
"use strict";
/*jslint vars:true, plusplus:true, forin:true*/
/*global Window, Script, Tablet, HMD, Controller, Account, XMLHttpRequest, location, print*/
//
// goto.js
@ -16,30 +18,7 @@
var buttonName = "GOTO";
var onGotoScreen = false;
var shouldActivateButton = false;
function onClicked() {
if (onGotoScreen) {
// for toolbar-mode: go back to home screen, this will close the window.
tablet.gotoHomeScreen();
} else {
shouldActivateButton = true;
tablet.loadQMLSource(gotoQmlSource);
onGotoScreen = true;
}
}
function onScreenChanged(type, url) {
if (url === gotoQmlSource) {
onGotoScreen = true;
shouldActivateButton = true;
button.editProperties({isActive: shouldActivateButton});
messagesWaiting(false);
} else {
shouldActivateButton = false;
onGotoScreen = false;
button.editProperties({isActive: shouldActivateButton});
}
}
function ignore() { }
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var NORMAL_ICON = "icons/tablet-icons/goto-i.svg";
@ -58,10 +37,33 @@
});
}
function onClicked() {
if (onGotoScreen) {
// for toolbar-mode: go back to home screen, this will close the window.
tablet.gotoHomeScreen();
} else {
shouldActivateButton = true;
tablet.loadQMLSource(gotoQmlSource);
onGotoScreen = true;
}
}
function onScreenChanged(type, url) {
ignore(type);
if (url === gotoQmlSource) {
onGotoScreen = true;
shouldActivateButton = true;
button.editProperties({isActive: shouldActivateButton});
messagesWaiting(false);
} else {
shouldActivateButton = false;
onGotoScreen = false;
button.editProperties({isActive: shouldActivateButton});
}
}
button.clicked.connect(onClicked);
tablet.screenChanged.connect(onScreenChanged);
var METAVERSE_BASE = location.metaverseServerUrl;
function request(options, callback) { // cb(error, responseOfCorrectContentType) of url. A subset of npm request.
var httpRequest = new XMLHttpRequest(), key;
// QT bug: apparently doesn't handle onload. Workaround using readyState.
@ -129,7 +131,7 @@
uri: url
}, function (error, data) {
if (error || (data.status !== 'success')) {
print("Error: unable to get", url, error || response.status);
print("Error: unable to get", url, error || data.status);
return;
}
var didNotify = false;