mirror of
https://github.com/overte-org/overte.git
synced 2025-04-11 05:22:11 +02:00
create audioMuteOverlay.js
client scipt that creates an overlay to provide mute feedback
This commit is contained in:
parent
49efd8ad42
commit
eb4dee0495
1 changed files with 122 additions and 0 deletions
122
scripts/system/audioMuteOverlay.js
Normal file
122
scripts/system/audioMuteOverlay.js
Normal file
|
@ -0,0 +1,122 @@
|
|||
"use strict";
|
||||
/* jslint vars: true, plusplus: true, forin: true*/
|
||||
/* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, Controller, print, getControllerWorldLocation */
|
||||
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
||||
//
|
||||
// audioMuteOverlay.js
|
||||
//
|
||||
// client scipt that creates an overlay to provide mute feedback
|
||||
//
|
||||
// Created by Triplelexx on 17/03/09
|
||||
// Copyright 2017 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
|
||||
//
|
||||
|
||||
(function() { // BEGIN LOCAL_SCOPE
|
||||
var TWEEN_SPEED = 0.025;
|
||||
var LERP_AMOUNT = 0.25;
|
||||
|
||||
var overlayPosition = Vec3.ZERO;
|
||||
var tweenPosition = 0;
|
||||
var startColor = {
|
||||
red: 150,
|
||||
green: 150,
|
||||
blue: 150
|
||||
};
|
||||
var endColor = {
|
||||
red: 255,
|
||||
green: 0,
|
||||
blue: 0
|
||||
};
|
||||
var overlayID;
|
||||
|
||||
AudioDevice.muteToggled.connect(onMuteToggled);
|
||||
Script.update.connect(update);
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
|
||||
function update(dt) {
|
||||
if (!AudioDevice.getMuted()) {
|
||||
return;
|
||||
}
|
||||
updateTween();
|
||||
}
|
||||
|
||||
function lerp(a, b, val) {
|
||||
return (1 - val) * a + val * b;
|
||||
}
|
||||
|
||||
function getOffsetPosition() {
|
||||
return Vec3.sum(MyAvatar.getHeadPosition(), Quat.getFront(MyAvatar.headOrientation));
|
||||
}
|
||||
|
||||
function updateTween() {
|
||||
// increase the tween value based on speed till it's complete
|
||||
if (tweenPosition < 1) {
|
||||
tweenPosition += TWEEN_SPEED;
|
||||
} else {
|
||||
// after tween completion reset to zero and flip values to ping pong
|
||||
tweenPosition = 0;
|
||||
var buf = startColor.red;
|
||||
startColor.red = endColor.red;
|
||||
endColor.red = buf;
|
||||
buf = startColor.green;
|
||||
startColor.green = endColor.green;
|
||||
endColor.green = buf;
|
||||
buf = startColor.blue;
|
||||
startColor.blue = endColor.blue;
|
||||
endColor.blue = buf;
|
||||
}
|
||||
|
||||
// update position based on LERP_AMOUNT
|
||||
var offsetPosition = getOffsetPosition();
|
||||
overlayPosition.x = lerp(overlayPosition.x, offsetPosition.x, LERP_AMOUNT);
|
||||
overlayPosition.y = lerp(overlayPosition.y, offsetPosition.y, LERP_AMOUNT);
|
||||
overlayPosition.z = lerp(overlayPosition.z, offsetPosition.z, LERP_AMOUNT);
|
||||
|
||||
Overlays.editOverlay(overlayID, {
|
||||
color: {
|
||||
red: lerp(startColor.red, endColor.red, tweenPosition),
|
||||
green: lerp(startColor.green, endColor.green, tweenPosition),
|
||||
blue: lerp(startColor.blue, endColor.blue, tweenPosition)
|
||||
},
|
||||
position: overlayPosition,
|
||||
rotation: MyAvatar.orientation,
|
||||
});
|
||||
}
|
||||
|
||||
function onMuteToggled() {
|
||||
if (AudioDevice.getMuted()) {
|
||||
createOverlay();
|
||||
} else {
|
||||
deleteOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
function createOverlay() {
|
||||
overlayPosition = getOffsetPosition();
|
||||
overlayID = Overlays.addOverlay("sphere", {
|
||||
name: "muteSphere",
|
||||
position: overlayPosition,
|
||||
rotation: MyAvatar.orientation,
|
||||
alpha: 0.9,
|
||||
dimensions: 0.1,
|
||||
solid: true,
|
||||
ignoreRayIntersection: true,
|
||||
visible: true
|
||||
});
|
||||
}
|
||||
|
||||
function deleteOverlay() {
|
||||
Overlays.deleteOverlay(overlayID);
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
if (overlayID) {
|
||||
deleteOverlay();
|
||||
}
|
||||
AudioDevice.muteToggled.disconnect(onMuteToggled);
|
||||
Script.update.disconnect(update);
|
||||
}
|
||||
}()); // END LOCAL_SCOPE
|
Loading…
Reference in a new issue