mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-30 19:01:43 +02:00
Merge pull request #12208 from zfox23/fixBubbleButtonFlash
Fix the Space Bubble button flash behavior; Rate limit sound
This commit is contained in:
commit
8c52f92de8
1 changed files with 35 additions and 17 deletions
|
@ -16,10 +16,10 @@
|
||||||
var button;
|
var button;
|
||||||
// Used for animating and disappearing the bubble
|
// Used for animating and disappearing the bubble
|
||||||
var bubbleOverlayTimestamp;
|
var bubbleOverlayTimestamp;
|
||||||
|
// Used for rate limiting the bubble sound
|
||||||
|
var lastBubbleSoundTimestamp = 0;
|
||||||
// Used for flashing the HUD button upon activation
|
// Used for flashing the HUD button upon activation
|
||||||
var bubbleButtonFlashState = false;
|
var bubbleButtonFlashState = false;
|
||||||
// Used for flashing the HUD button upon activation
|
|
||||||
var bubbleButtonTimestamp;
|
|
||||||
// Affects bubble height
|
// Affects bubble height
|
||||||
var BUBBLE_HEIGHT_SCALE = 0.15;
|
var BUBBLE_HEIGHT_SCALE = 0.15;
|
||||||
// The bubble model itself
|
// The bubble model itself
|
||||||
|
@ -36,9 +36,11 @@
|
||||||
var bubbleActivateSound = SoundCache.getSound(Script.resolvePath("assets/sounds/bubble.wav"));
|
var bubbleActivateSound = SoundCache.getSound(Script.resolvePath("assets/sounds/bubble.wav"));
|
||||||
// Is the update() function connected?
|
// Is the update() function connected?
|
||||||
var updateConnected = false;
|
var updateConnected = false;
|
||||||
|
var bubbleFlashTimer = false;
|
||||||
|
|
||||||
var BUBBLE_VISIBLE_DURATION_MS = 3000;
|
var BUBBLE_VISIBLE_DURATION_MS = 3000;
|
||||||
var BUBBLE_RAISE_ANIMATION_DURATION_MS = 750;
|
var BUBBLE_RAISE_ANIMATION_DURATION_MS = 750;
|
||||||
|
var BUBBLE_SOUND_RATE_LIMIT_MS = 15000;
|
||||||
|
|
||||||
// Hides the bubble model overlay and resets the button flash state
|
// Hides the bubble model overlay and resets the button flash state
|
||||||
function hideOverlays() {
|
function hideOverlays() {
|
||||||
|
@ -50,11 +52,15 @@
|
||||||
|
|
||||||
// Make the bubble overlay visible, set its position, and play the sound
|
// Make the bubble overlay visible, set its position, and play the sound
|
||||||
function createOverlays() {
|
function createOverlays() {
|
||||||
Audio.playSound(bubbleActivateSound, {
|
var nowTimestamp = Date.now();
|
||||||
position: { x: MyAvatar.position.x, y: MyAvatar.position.y, z: MyAvatar.position.z },
|
if (nowTimestamp - lastBubbleSoundTimestamp >= BUBBLE_SOUND_RATE_LIMIT_MS) {
|
||||||
localOnly: true,
|
Audio.playSound(bubbleActivateSound, {
|
||||||
volume: 0.2
|
position: { x: MyAvatar.position.x, y: MyAvatar.position.y, z: MyAvatar.position.z },
|
||||||
});
|
localOnly: true,
|
||||||
|
volume: 0.2
|
||||||
|
});
|
||||||
|
lastBubbleSoundTimestamp = nowTimestamp;
|
||||||
|
}
|
||||||
hideOverlays();
|
hideOverlays();
|
||||||
if (updateConnected === true) {
|
if (updateConnected === true) {
|
||||||
updateConnected = false;
|
updateConnected = false;
|
||||||
|
@ -80,10 +86,17 @@
|
||||||
},
|
},
|
||||||
visible: true
|
visible: true
|
||||||
});
|
});
|
||||||
bubbleOverlayTimestamp = Date.now();
|
bubbleOverlayTimestamp = nowTimestamp;
|
||||||
bubbleButtonTimestamp = bubbleOverlayTimestamp;
|
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
updateConnected = true;
|
updateConnected = true;
|
||||||
|
|
||||||
|
// Flash button
|
||||||
|
if (!bubbleFlashTimer) {
|
||||||
|
bubbleFlashTimer = Script.setInterval(function () {
|
||||||
|
writeButtonProperties(bubbleButtonFlashState);
|
||||||
|
bubbleButtonFlashState = !bubbleButtonFlashState;
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called from the C++ scripting interface to show the bubble overlay
|
// Called from the C++ scripting interface to show the bubble overlay
|
||||||
|
@ -103,12 +116,6 @@
|
||||||
var delay = (timestamp - bubbleOverlayTimestamp);
|
var delay = (timestamp - bubbleOverlayTimestamp);
|
||||||
var overlayAlpha = 1.0 - (delay / BUBBLE_VISIBLE_DURATION_MS);
|
var overlayAlpha = 1.0 - (delay / BUBBLE_VISIBLE_DURATION_MS);
|
||||||
if (overlayAlpha > 0) {
|
if (overlayAlpha > 0) {
|
||||||
// Flash button
|
|
||||||
if ((timestamp - bubbleButtonTimestamp) >= BUBBLE_VISIBLE_DURATION_MS) {
|
|
||||||
writeButtonProperties(bubbleButtonFlashState);
|
|
||||||
bubbleButtonTimestamp = timestamp;
|
|
||||||
bubbleButtonFlashState = !bubbleButtonFlashState;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delay < BUBBLE_RAISE_ANIMATION_DURATION_MS) {
|
if (delay < BUBBLE_RAISE_ANIMATION_DURATION_MS) {
|
||||||
Overlays.editOverlay(bubbleOverlay, {
|
Overlays.editOverlay(bubbleOverlay, {
|
||||||
|
@ -157,8 +164,11 @@
|
||||||
Script.update.disconnect(update);
|
Script.update.disconnect(update);
|
||||||
updateConnected = false;
|
updateConnected = false;
|
||||||
}
|
}
|
||||||
var bubbleActive = Users.getIgnoreRadiusEnabled();
|
if (bubbleFlashTimer) {
|
||||||
writeButtonProperties(bubbleActive);
|
Script.clearTimeout(bubbleFlashTimer);
|
||||||
|
bubbleFlashTimer = false;
|
||||||
|
}
|
||||||
|
writeButtonProperties(Users.getIgnoreRadiusEnabled());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +176,10 @@
|
||||||
// NOTE: the c++ calls this with just the first param -- we added a second
|
// NOTE: the c++ calls this with just the first param -- we added a second
|
||||||
// just for not logging the initial state of the bubble when we startup.
|
// just for not logging the initial state of the bubble when we startup.
|
||||||
function onBubbleToggled(enabled, doNotLog) {
|
function onBubbleToggled(enabled, doNotLog) {
|
||||||
|
if (bubbleFlashTimer) {
|
||||||
|
Script.clearTimeout(bubbleFlashTimer);
|
||||||
|
bubbleFlashTimer = false;
|
||||||
|
}
|
||||||
writeButtonProperties(enabled);
|
writeButtonProperties(enabled);
|
||||||
if (doNotLog !== true) {
|
if (doNotLog !== true) {
|
||||||
UserActivityLogger.bubbleToggled(enabled);
|
UserActivityLogger.bubbleToggled(enabled);
|
||||||
|
@ -200,6 +214,10 @@
|
||||||
// Cleanup the tablet button and overlays when script is stopped
|
// Cleanup the tablet button and overlays when script is stopped
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
button.clicked.disconnect(Users.toggleIgnoreRadius);
|
button.clicked.disconnect(Users.toggleIgnoreRadius);
|
||||||
|
if (bubbleFlashTimer) {
|
||||||
|
Script.clearTimeout(bubbleFlashTimer);
|
||||||
|
bubbleFlashTimer = false;
|
||||||
|
}
|
||||||
if (tablet) {
|
if (tablet) {
|
||||||
tablet.removeButton(button);
|
tablet.removeButton(button);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue