Merge pull request #4304 from thoys/20245

CR for Job #20245 - Implement UI sounds for virtualKeyboard & notifications
This commit is contained in:
Clément Brisset 2015-02-18 09:55:34 -08:00
commit 87f4ae2425
4 changed files with 91 additions and 14 deletions

View file

@ -18,6 +18,7 @@
Script.include("../../libraries/globals.js");
Script.include("../../libraries/virtualKeyboard.js");
Script.include("../../libraries/soundArray.js");
const MAX_SHOW_INSTRUCTION_TIMES = 2;
const INSTRUCTIONS_SETTING = "GoToInstructionsShowCounter"
@ -82,6 +83,12 @@ var textFontSize = 9;
var text = null;
var locationURL = "";
var randomSounds = new SoundArray({}, true);
var numberOfSounds = 7;
for (var i = 1; i <= numberOfSounds; i++) {
randomSounds.addSound(HIFI_PUBLIC_BUCKET + "sounds/UI/virtualKeyboard-press" + i + ".raw");
}
function appendChar(char) {
locationURL += char;
updateTextOverlay();
@ -107,6 +114,7 @@ function updateTextOverlay() {
}
keyboard.onKeyPress = function(event) {
randomSounds.playRandom();
if (event.event == 'keypress') {
appendChar(event.char);
}

View file

@ -17,6 +17,7 @@
Script.include("../../libraries/globals.js");
Script.include("../../libraries/virtualKeyboard.js");
Script.include("../../libraries/soundArray.js");
const SPAWN_DISTANCE = 1;
const DEFAULT_TEXT_DIMENSION_Z = 0.02;
@ -34,6 +35,12 @@ var text = null;
var textText = "";
var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false});
var randomSounds = new SoundArray({}, true);
var numberOfSounds = 7;
for (var i = 1; i <= numberOfSounds; i++) {
randomSounds.addSound(HIFI_PUBLIC_BUCKET + "sounds/UI/virtualKeyboard-press" + i + ".raw");
}
function appendChar(char) {
textText += char;
updateTextOverlay();
@ -58,6 +65,7 @@ function updateTextOverlay() {
}
keyboard.onKeyPress = function(event) {
randomSounds.playRandom();
if (event.event == 'keypress') {
appendChar(event.char);
} else if (event.event == 'enter') {

View file

@ -0,0 +1,42 @@
/**
* An array for sounds, allows you to randomly play a sound
* taken from the removed editVoxels.js
*/
SoundArray = function(audioOptions, autoUpdateAudioPosition) {
this.audioOptions = audioOptions !== undefined ? audioOptions : {};
this.autoUpdateAudioPosition = autoUpdateAudioPosition !== undefined ? autoUpdateAudioPosition : false;
if (this.audioOptions.position === undefined) {
this.audioOptions.position = Vec3.sum(MyAvatar.position, { x: 0, y: 1, z: 0}),
}
if (this.audioOptions.volume === undefined) {
this.audioOptions.volume = 1.0;
}
this.sounds = new Array();
this.addSound = function (soundURL) {
this.sounds[this.sounds.length] = SoundCache.getSound(soundURL);
};
this.play = function (index) {
if (0 <= index && index < this.sounds.length) {
if (this.autoUpdateAudioPosition) {
this.updateAudioPosition();
}
if (this.sounds[index].downloaded) {
Audio.playSound(this.sounds[index], this.audioOptions);
}
} else {
print("[ERROR] libraries/soundArray.js:play() : Index " + index + " out of range.");
}
};
this.playRandom = function () {
if (this.sounds.length > 0) {
this.play(Math.floor(Math.random() * this.sounds.length));
} else {
print("[ERROR] libraries/soundArray.js:playRandom() : Array is empty.");
}
};
this.updateAudioPosition = function() {
var position = MyAvatar.position;
var forwardVector = Quat.getFront(MyAvatar.orientation);
this.audioOptions.position = Vec3.sum(position, forwardVector);
};
};

View file

@ -1,13 +1,13 @@
//
// notifications.js
// Version 0.801
// Created by Adrian
//
// notifications.js
// Version 0.801
// Created by Adrian
//
// Adrian McCarlie 8-10-14
// This script demonstrates on-screen overlay type notifications.
// Copyright 2014 High Fidelity, Inc.
//
//
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -20,29 +20,29 @@
// CTRL/m for mic mute and unmute.
// System generated notifications:
// Displays users online at startup.
// Displays users online at startup.
// If Screen is resized.
// Triggers notification if @MyUserName is mentioned in chat.
// Announces existing user logging out.
// Announces new user logging in.
// If mic is muted for any reason.
//
//
// To add a new System notification type:
//
// 1. Set the Event Connector at the bottom of the script.
// example:
// 1. Set the Event Connector at the bottom of the script.
// example:
// GlobalServices.incomingMessage.connect(onIncomingMessage);
//
// 2. Create a new function to produce a text string, do not include new line returns.
// 2. Create a new function to produce a text string, do not include new line returns.
// example:
// function onIncomingMessage(user, message) {
// //do stuff here;
// //do stuff here;
// var text = "This is a notification";
// wordWrap(text);
// }
//
// This new function must call wordWrap(text) if the length of message is longer than 42 chars or unknown.
// wordWrap() will format the text to fit the notifications overlay and send it to createNotification(text).
// wordWrap() will format the text to fit the notifications overlay and send it to createNotification(text).
// If the message is 42 chars or less you should bypass wordWrap() and call createNotification() directly.
@ -57,6 +57,8 @@
// var welcome = "There are " + GlobalServices.onlineUsers.length + " users online now.";
// createNotification(welcome);
// }
Script.include("./libraries/globals.js");
Script.include("./libraries/soundArray.js");
var width = 340.0; //width of notification overlay
var windowDimensions = Controller.getViewportDimensions(); // get the size of the interface window
@ -66,7 +68,7 @@ var locationY = 20.0; // position down from top of interface window
var topMargin = 13.0;
var leftMargin = 10.0;
var textColor = { red: 228, green: 228, blue: 228}; // text color
var backColor = { red: 2, green: 2, blue: 2}; // background color was 38,38,38
var backColor = { red: 2, green: 2, blue: 2}; // background color was 38,38,38
var backgroundAlpha = 0;
var fontSize = 12.0;
var PERSIST_TIME_2D = 10.0; // Time in seconds before notification fades
@ -81,6 +83,22 @@ var last_users = GlobalServices.onlineUsers;
var users = [];
var ctrlIsPressed = false;
var ready = true;
var randomSounds = new SoundArray({}, true);
var numberOfSounds = 2;
for (var i = 1; i <= numberOfSounds; i++) {
randomSounds.addSound(HIFI_PUBLIC_BUCKET + "sounds/UI/notification-general" + i + ".raw");
}
// When our script shuts down, we should clean up all of our overlays
function scriptEnding() {
for (i = 0; i < notifications.length; i++) {
Overlays.deleteOverlay(notifications[i]);
Overlays.deleteOverlay(buttons[i]);
}
}
Script.scriptEnding.connect(scriptEnding);
var notifications = [];
var buttons = [];
var times = [];
@ -193,6 +211,8 @@ function notify(notice, button, height) {
positions,
last;
randomSounds.playRandom();
if (isOnHMD) {
// Calculate 3D values from 2D overlay properties.
@ -454,7 +474,6 @@ function onOnlineUsersChanged(users) {
if (last_users.indexOf(users[i]) === -1.0) {
createNotification(users[i] + " has joined");
}
}
for (i = 0; i < last_users.length; i += 1) {