mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 17:39:26 +02:00
added LOD Warnings to notifications.js
This commit is contained in:
parent
b67cf3af24
commit
0e44126106
4 changed files with 31 additions and 122 deletions
|
@ -18,4 +18,3 @@ Script.load("lobby.js");
|
||||||
Script.load("notifications.js");
|
Script.load("notifications.js");
|
||||||
Script.load("look.js");
|
Script.load("look.js");
|
||||||
Script.load("users.js");
|
Script.load("users.js");
|
||||||
Script.load("utilities/LODWarning.js");
|
|
||||||
|
|
|
@ -13,5 +13,4 @@ Script.load("progress.js");
|
||||||
Script.load("lobby.js");
|
Script.load("lobby.js");
|
||||||
Script.load("notifications.js");
|
Script.load("notifications.js");
|
||||||
Script.load("controllers/oculus/goTo.js");
|
Script.load("controllers/oculus/goTo.js");
|
||||||
Script.load("utilities/LODWarning.js");
|
|
||||||
//Script.load("scripts.js"); // Not created yet
|
//Script.load("scripts.js"); // Not created yet
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
// after that we will send it to createNotification(text).
|
// after that we will send it to createNotification(text).
|
||||||
// If the message is 42 chars or less you should bypass wordWrap() and call createNotification() directly.
|
// If the message is 42 chars or less you should bypass wordWrap() and call createNotification() directly.
|
||||||
|
|
||||||
|
|
||||||
// To add a keypress driven notification:
|
// To add a keypress driven notification:
|
||||||
//
|
//
|
||||||
// 1. Add a key to the keyPressEvent(key).
|
// 1. Add a key to the keyPressEvent(key).
|
||||||
|
@ -85,16 +84,19 @@ var PLAY_NOTIFICATION_SOUNDS_MENU_ITEM = "Play Notification Sounds";
|
||||||
var NOTIFICATION_MENU_ITEM_POST = " Notifications";
|
var NOTIFICATION_MENU_ITEM_POST = " Notifications";
|
||||||
var PLAY_NOTIFICATION_SOUNDS_SETTING = "play_notification_sounds";
|
var PLAY_NOTIFICATION_SOUNDS_SETTING = "play_notification_sounds";
|
||||||
var PLAY_NOTIFICATION_SOUNDS_TYPE_SETTING_PRE = "play_notification_sounds_type_";
|
var PLAY_NOTIFICATION_SOUNDS_TYPE_SETTING_PRE = "play_notification_sounds_type_";
|
||||||
|
var lodTextID = false;
|
||||||
|
|
||||||
var NotificationType = {
|
var NotificationType = {
|
||||||
UNKNOWN: 0,
|
UNKNOWN: 0,
|
||||||
MUTE_TOGGLE: 1,
|
MUTE_TOGGLE: 1,
|
||||||
SNAPSHOT: 2,
|
SNAPSHOT: 2,
|
||||||
WINDOW_RESIZE: 3,
|
WINDOW_RESIZE: 3,
|
||||||
|
LOD_WARNING: 4,
|
||||||
properties: [
|
properties: [
|
||||||
{ text: "Mute Toggle" },
|
{ text: "Mute Toggle" },
|
||||||
{ text: "Snapshot" },
|
{ text: "Snapshot" },
|
||||||
{ text: "Window Resize" }
|
{ text: "Window Resize" },
|
||||||
|
{ text: "Level of Detail" }
|
||||||
],
|
],
|
||||||
getTypeFromMenuItem: function(menuItemName) {
|
getTypeFromMenuItem: function(menuItemName) {
|
||||||
if (menuItemName.substr(menuItemName.length - NOTIFICATION_MENU_ITEM_POST.length) !== NOTIFICATION_MENU_ITEM_POST) {
|
if (menuItemName.substr(menuItemName.length - NOTIFICATION_MENU_ITEM_POST.length) !== NOTIFICATION_MENU_ITEM_POST) {
|
||||||
|
@ -143,6 +145,10 @@ function createArrays(notice, button, createTime, height, myAlpha) {
|
||||||
|
|
||||||
// This handles the final dismissal of a notification after fading
|
// This handles the final dismissal of a notification after fading
|
||||||
function dismiss(firstNoteOut, firstButOut, firstOut) {
|
function dismiss(firstNoteOut, firstButOut, firstOut) {
|
||||||
|
if (firstNoteOut == lodTextID) {
|
||||||
|
lodTextID = false;
|
||||||
|
}
|
||||||
|
|
||||||
Overlays.deleteOverlay(firstNoteOut);
|
Overlays.deleteOverlay(firstNoteOut);
|
||||||
Overlays.deleteOverlay(firstButOut);
|
Overlays.deleteOverlay(firstButOut);
|
||||||
notifications.splice(firstOut, 1);
|
notifications.splice(firstOut, 1);
|
||||||
|
@ -261,7 +267,8 @@ function notify(notice, button, height) {
|
||||||
height: noticeHeight
|
height: noticeHeight
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
notifications.push((Overlays.addOverlay("text", notice)));
|
var notificationText = Overlays.addOverlay("text", notice);
|
||||||
|
notifications.push((notificationText));
|
||||||
buttons.push((Overlays.addOverlay("image", button)));
|
buttons.push((Overlays.addOverlay("image", button)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,6 +279,7 @@ function notify(notice, button, height) {
|
||||||
last = notifications.length - 1;
|
last = notifications.length - 1;
|
||||||
createArrays(notifications[last], buttons[last], times[last], heights[last], myAlpha[last]);
|
createArrays(notifications[last], buttons[last], times[last], heights[last], myAlpha[last]);
|
||||||
fadeIn(notifications[last], buttons[last]);
|
fadeIn(notifications[last], buttons[last]);
|
||||||
|
return notificationText;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function creates and sizes the overlays
|
// This function creates and sizes the overlays
|
||||||
|
@ -331,11 +339,15 @@ function createNotification(text, notificationType) {
|
||||||
randomSounds.playRandom();
|
randomSounds.playRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
notify(noticeProperties, buttonProperties, height);
|
return notify(noticeProperties, buttonProperties, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteNotification(index) {
|
function deleteNotification(index) {
|
||||||
Overlays.deleteOverlay(notifications[index]);
|
var notificationTextID = notifications[index];
|
||||||
|
if (notificationTextID == lodTextID) {
|
||||||
|
lodTextID = false;
|
||||||
|
}
|
||||||
|
Overlays.deleteOverlay(notificationTextID);
|
||||||
Overlays.deleteOverlay(buttons[index]);
|
Overlays.deleteOverlay(buttons[index]);
|
||||||
notifications.splice(index, 1);
|
notifications.splice(index, 1);
|
||||||
buttons.splice(index, 1);
|
buttons.splice(index, 1);
|
||||||
|
@ -575,6 +587,20 @@ function menuItemEvent(menuItem) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LODManager.LODDecreased.connect(function() {
|
||||||
|
var warningText = "\n"
|
||||||
|
+ "Due to the complexity of the content, the \n"
|
||||||
|
+ "level of detail has been decreased."
|
||||||
|
+ "You can now see: \n"
|
||||||
|
+ LODManager.getLODFeedbackText();
|
||||||
|
|
||||||
|
if (lodTextID == false) {
|
||||||
|
lodTextID = createNotification(warningText, NotificationType.LOD_WARNING);
|
||||||
|
} else {
|
||||||
|
Overlays.editOverlay(lodTextID, { text: warningText });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
AudioDevice.muteToggled.connect(onMuteStateChanged);
|
AudioDevice.muteToggled.connect(onMuteStateChanged);
|
||||||
Controller.keyPressEvent.connect(keyPressEvent);
|
Controller.keyPressEvent.connect(keyPressEvent);
|
||||||
Controller.mousePressEvent.connect(mousePressEvent);
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
|
|
|
@ -1,115 +0,0 @@
|
||||||
// LODWarning.js
|
|
||||||
// examples
|
|
||||||
//
|
|
||||||
// Created by Brad Hefta-Gaub on 3/17/15.
|
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// This script will display a warning when the LOD is adjusted to do scene complexity.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
var DISPLAY_WARNING_FOR = 3; // in seconds
|
|
||||||
var DISTANCE_FROM_CAMERA = 2;
|
|
||||||
var SHOW_LOD_UP_MESSAGE = false; // By default we only display the LOD message when reducing LOD
|
|
||||||
|
|
||||||
|
|
||||||
var warningIsVisible = false; // initially the warning is hidden
|
|
||||||
var warningShownAt = 0;
|
|
||||||
var billboardPosition = Vec3.sum(Camera.getPosition(),
|
|
||||||
Vec3.multiply(DISTANCE_FROM_CAMERA, Quat.getFront(Camera.getOrientation())));
|
|
||||||
|
|
||||||
var warningOverlay = Overlays.addOverlay("text3d", {
|
|
||||||
position: billboardPosition,
|
|
||||||
dimensions: { x: 2, y: 1.25 },
|
|
||||||
width: 2,
|
|
||||||
height: 1.25,
|
|
||||||
backgroundColor: { red: 0, green: 0, blue: 0 },
|
|
||||||
color: { red: 255, green: 255, blue: 255},
|
|
||||||
topMargin: 0.1,
|
|
||||||
leftMargin: 0.1,
|
|
||||||
lineHeight: 0.07,
|
|
||||||
text: "",
|
|
||||||
alpha: 0.5,
|
|
||||||
backgroundAlpha: 0.7,
|
|
||||||
isFacingAvatar: true,
|
|
||||||
visible: warningIsVisible,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle moving the billboard to remain in front of the camera
|
|
||||||
var billboardNeedsMoving = false;
|
|
||||||
Script.update.connect(function() {
|
|
||||||
|
|
||||||
if (warningIsVisible) {
|
|
||||||
var bestBillboardPosition = Vec3.sum(Camera.getPosition(),
|
|
||||||
Vec3.multiply(DISTANCE_FROM_CAMERA, Quat.getFront(Camera.getOrientation())));
|
|
||||||
|
|
||||||
var MAX_DISTANCE = 0.5;
|
|
||||||
var CLOSE_ENOUGH = 0.01;
|
|
||||||
if (!billboardNeedsMoving && Vec3.distance(bestBillboardPosition, billboardPosition) > MAX_DISTANCE) {
|
|
||||||
billboardNeedsMoving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (billboardNeedsMoving && Vec3.distance(bestBillboardPosition, billboardPosition) <= CLOSE_ENOUGH) {
|
|
||||||
billboardNeedsMoving = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (billboardNeedsMoving) {
|
|
||||||
// slurp the billboard to the best location
|
|
||||||
moveVector = Vec3.multiply(0.05, Vec3.subtract(bestBillboardPosition, billboardPosition));
|
|
||||||
billboardPosition = Vec3.sum(billboardPosition, moveVector);
|
|
||||||
Overlays.editOverlay(warningOverlay, { position: billboardPosition });
|
|
||||||
}
|
|
||||||
|
|
||||||
var now = new Date();
|
|
||||||
var sinceWarningShown = now - warningShownAt;
|
|
||||||
if (sinceWarningShown > 1000 * DISPLAY_WARNING_FOR) {
|
|
||||||
warningIsVisible = false;
|
|
||||||
Overlays.editOverlay(warningOverlay, { visible: warningIsVisible });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
LODManager.LODIncreased.connect(function() {
|
|
||||||
if (SHOW_LOD_UP_MESSAGE) {
|
|
||||||
// if the warning wasn't visible, then move it before showing it.
|
|
||||||
if (!warningIsVisible) {
|
|
||||||
billboardPosition = Vec3.sum(Camera.getPosition(),
|
|
||||||
Vec3.multiply(DISTANCE_FROM_CAMERA, Quat.getFront(Camera.getOrientation())));
|
|
||||||
Overlays.editOverlay(warningOverlay, { position: billboardPosition });
|
|
||||||
}
|
|
||||||
|
|
||||||
warningShownAt = new Date();
|
|
||||||
warningIsVisible = true;
|
|
||||||
warningText = "Level of detail has been increased. \n"
|
|
||||||
+ "You can now see: \n"
|
|
||||||
+ LODManager.getLODFeedbackText();
|
|
||||||
|
|
||||||
Overlays.editOverlay(warningOverlay, { visible: warningIsVisible, text: warningText });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
LODManager.LODDecreased.connect(function() {
|
|
||||||
// if the warning wasn't visible, then move it before showing it.
|
|
||||||
if (!warningIsVisible) {
|
|
||||||
billboardPosition = Vec3.sum(Camera.getPosition(),
|
|
||||||
Vec3.multiply(DISTANCE_FROM_CAMERA, Quat.getFront(Camera.getOrientation())));
|
|
||||||
Overlays.editOverlay(warningOverlay, { position: billboardPosition });
|
|
||||||
}
|
|
||||||
|
|
||||||
warningShownAt = new Date();
|
|
||||||
warningIsVisible = true;
|
|
||||||
warningText = "\n"
|
|
||||||
+ "Due to the complexity of the content, the \n"
|
|
||||||
+ "level of detail has been decreased. \n"
|
|
||||||
+ "You can now see: \n"
|
|
||||||
+ LODManager.getLODFeedbackText();
|
|
||||||
|
|
||||||
Overlays.editOverlay(warningOverlay, { visible: warningIsVisible, text: warningText });
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Script.scriptEnding.connect(function() {
|
|
||||||
Overlays.deleteOverlay(warningOverlay);
|
|
||||||
});
|
|
Loading…
Reference in a new issue