mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Handle domain and permission changes; disable app icon appropriately
This commit is contained in:
parent
310750fc0f
commit
61fc32714a
2 changed files with 84 additions and 15 deletions
|
@ -25,16 +25,17 @@ Feedback = (function () {
|
|||
ERROR_SOUND = SoundCache.getSound(Script.resolvePath("../assets/audio/error.wav")),
|
||||
|
||||
FEEDBACK_PARAMETERS = {
|
||||
DROP_TOOL: { sound: DROP_SOUND, volume: 0.3, haptic: 0.75 },
|
||||
DELETE_ENTITY: { sound: DELETE_SOUND, volume: 0.5, haptic: 0.2 },
|
||||
SELECT_ENTITY: { sound: SELECT_SOUND, volume: 0.2, haptic: 0.1 }, // E.g., Group tool.
|
||||
CLONE_ENTITY: { sound: CLONE_SOUND, volume: 0.2, haptic: 0.1 },
|
||||
CREATE_ENTITY: { sound: CREATE_SOUND, volume: 0.4, haptic: 0.2 },
|
||||
HOVER_MENU_ITEM: { sound: null, volume: 0, haptic: 0.1 }, // Tools menu.
|
||||
DROP_TOOL: { sound: DROP_SOUND, volume: 0.3, haptic: 0.75 },
|
||||
DELETE_ENTITY: { sound: DELETE_SOUND, volume: 0.5, haptic: 0.2 },
|
||||
SELECT_ENTITY: { sound: SELECT_SOUND, volume: 0.2, haptic: 0.1 }, // E.g., Group tool.
|
||||
CLONE_ENTITY: { sound: CLONE_SOUND, volume: 0.2, haptic: 0.1 },
|
||||
CREATE_ENTITY: { sound: CREATE_SOUND, volume: 0.4, haptic: 0.2 },
|
||||
HOVER_MENU_ITEM: { sound: null, volume: 0, haptic: 0.1 } , // Tools menu.
|
||||
HOVER_BUTTON: { sound: null, volume: 0, haptic: 0.075 }, // Tools options and Create palette items.
|
||||
EQUIP_TOOL: { sound: EQUIP_SOUND, volume: 0.3, haptic: 0.6 },
|
||||
APPLY_PROPERTY: { sound: null, volume: 0, haptic: 0.3 },
|
||||
APPLY_ERROR: { sound: ERROR_SOUND, volume: 0.2, haptic: 0.7 }
|
||||
EQUIP_TOOL: { sound: EQUIP_SOUND, volume: 0.3, haptic: 0.6 },
|
||||
APPLY_PROPERTY: { sound: null, volume: 0, haptic: 0.3 },
|
||||
APPLY_ERROR: { sound: ERROR_SOUND, volume: 0.2, haptic: 0.7 },
|
||||
GENERAL_ERROR: { sound: ERROR_SOUND, volume: 0.2, haptic: 0.7 }
|
||||
},
|
||||
|
||||
VOLUME_MULTPLIER = 0.5, // Resulting volume range should be within 0.0 - 1.0.
|
||||
|
@ -67,6 +68,7 @@ Feedback = (function () {
|
|||
EQUIP_TOOL: "EQUIP_TOOL",
|
||||
APPLY_PROPERTY: "APPLY_PROPERTY",
|
||||
APPLY_ERROR: "APPLY_ERROR",
|
||||
GENERAL_ERROR: "GENERAL_ERROR",
|
||||
play: play
|
||||
};
|
||||
}());
|
||||
|
|
|
@ -15,10 +15,13 @@
|
|||
var APP_NAME = "VR EDIT", // TODO: App name.
|
||||
APP_ICON_INACTIVE = "icons/tablet-icons/edit-i.svg", // TODO: App icons.
|
||||
APP_ICON_ACTIVE = "icons/tablet-icons/edit-a.svg",
|
||||
APP_ICON_DISABLED = "icons/tablet-icons/edit-disabled.svg",
|
||||
ENABLED_CAPTION_COLOR_OVERRIDE = "",
|
||||
DISABLED_CAPTION_COLOR_OVERRIDE = "#888888",
|
||||
VR_EDIT_SETTING = "io.highfidelity.isVREditing", // Note: This constant is duplicated in utils.js.
|
||||
|
||||
// Application state
|
||||
isAppActive = false,
|
||||
isAppActive,
|
||||
dominantHand,
|
||||
|
||||
// Tool state
|
||||
|
@ -65,6 +68,7 @@
|
|||
updateTimer = null,
|
||||
tablet,
|
||||
button,
|
||||
DOMAIN_CHANGED_MESSAGE = "Toolbar-DomainChanged",
|
||||
|
||||
DEBUG = true; // TODO: Set false.
|
||||
|
||||
|
@ -1569,7 +1573,7 @@
|
|||
|
||||
function startApp() {
|
||||
ui.display();
|
||||
update();
|
||||
update(); // Start main update loop.
|
||||
}
|
||||
|
||||
function stopApp() {
|
||||
|
@ -1584,8 +1588,14 @@
|
|||
toolSelected = TOOL_NONE;
|
||||
}
|
||||
|
||||
|
||||
function onAppButtonClicked() {
|
||||
// Application tablet/toolbar button clicked.
|
||||
if (!isAppActive && !(Entities.canRez() || Entities.canRezTmp())) {
|
||||
Feedback.play(dominantHand, Feedback.GENERAL_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
isAppActive = !isAppActive;
|
||||
updateHandControllerGrab();
|
||||
button.editProperties({ isActive: isAppActive });
|
||||
|
@ -1597,6 +1607,49 @@
|
|||
}
|
||||
}
|
||||
|
||||
function onDomainChanged() {
|
||||
// Fires when domain starts or domain changes; does not fire when domain stops.
|
||||
var hasRezPermissions = Entities.canRez() || Entities.canRezTmp();
|
||||
if (isAppActive && !hasRezPermissions) {
|
||||
isAppActive = false;
|
||||
updateHandControllerGrab();
|
||||
stopApp();
|
||||
}
|
||||
button.editProperties({
|
||||
icon: hasRezPermissions ? APP_ICON_INACTIVE : APP_ICON_DISABLED,
|
||||
captionColorOverride: hasRezPermissions ? ENABLED_CAPTION_COLOR_OVERRIDE : DISABLED_CAPTION_COLOR_OVERRIDE,
|
||||
isActive: isAppActive
|
||||
});
|
||||
}
|
||||
|
||||
function onCanRezChanged() {
|
||||
// canRez or canRezTmp changed.
|
||||
var hasRezPermissions = Entities.canRez() || Entities.canRezTmp();
|
||||
if (isAppActive && !hasRezPermissions) {
|
||||
isAppActive = false;
|
||||
updateHandControllerGrab();
|
||||
stopApp();
|
||||
}
|
||||
button.editProperties({
|
||||
icon: hasRezPermissions ? APP_ICON_INACTIVE : APP_ICON_DISABLED,
|
||||
captionColorOverride: hasRezPermissions ? ENABLED_CAPTION_COLOR_OVERRIDE : DISABLED_CAPTION_COLOR_OVERRIDE,
|
||||
isActive: isAppActive
|
||||
});
|
||||
}
|
||||
|
||||
function onMessageReceived(channel) {
|
||||
// Hacky but currently the only way of detecting server stopping or restarting. Also occurs if changing domains.
|
||||
// TODO: Remove this when Window.domainChanged or other signal is emitted when you disconnect from a domain.
|
||||
if (channel === DOMAIN_CHANGED_MESSAGE) {
|
||||
// Happens a little while after server goes away.
|
||||
if (isAppActive && !location.isConnected) {
|
||||
// Interface deletes all overlays when domain connection is lost; restart app to work around this.
|
||||
stopApp();
|
||||
startApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onDominantHandChanged(hand) {
|
||||
dominantHand = hand === "left" ? LEFT_HAND : RIGHT_HAND;
|
||||
|
||||
|
@ -1627,19 +1680,24 @@
|
|||
|
||||
|
||||
function setUp() {
|
||||
updateHandControllerGrab();
|
||||
var hasRezPermissions;
|
||||
|
||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
if (!tablet) {
|
||||
App.log("ERROR: Tablet not found! App not started.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Settings values.
|
||||
// Application state.
|
||||
isAppActive = false;
|
||||
updateHandControllerGrab();
|
||||
dominantHand = MyAvatar.getDominantHand() === "left" ? LEFT_HAND : RIGHT_HAND;
|
||||
|
||||
// Tablet/toolbar button.
|
||||
hasRezPermissions = Entities.canRez() || Entities.canRezTmp();
|
||||
button = tablet.addButton({
|
||||
icon: APP_ICON_INACTIVE,
|
||||
icon: hasRezPermissions ? APP_ICON_INACTIVE : APP_ICON_DISABLED,
|
||||
captionColorOverride: hasRezPermissions ? ENABLED_CAPTION_COLOR_OVERRIDE : DISABLED_CAPTION_COLOR_OVERRIDE,
|
||||
activeIcon: APP_ICON_ACTIVE,
|
||||
text: APP_NAME,
|
||||
isActive: isAppActive
|
||||
|
@ -1665,6 +1723,11 @@
|
|||
grouping = new Grouping();
|
||||
|
||||
// Changes.
|
||||
Window.domainChanged.connect(onDomainChanged);
|
||||
Entities.canRezChanged.connect(onCanRezChanged);
|
||||
Entities.canRezTmpChanged.connect(onCanRezChanged);
|
||||
Messages.subscribe(DOMAIN_CHANGED_MESSAGE);
|
||||
Messages.messageReceived.connect(onMessageReceived);
|
||||
MyAvatar.dominantHandChanged.connect(onDominantHandChanged);
|
||||
MyAvatar.skeletonChanged.connect(onSkeletonChanged);
|
||||
|
||||
|
@ -1683,13 +1746,17 @@
|
|||
Script.clearTimeout(updateTimer);
|
||||
}
|
||||
|
||||
Window.domainChanged.disconnect(onDomainChanged);
|
||||
Entities.canRezChanged.disconnect(onCanRezChanged);
|
||||
Entities.canRezTmpChanged.disconnect(onCanRezChanged);
|
||||
Messages.messageReceived.disconnect(onMessageReceived);
|
||||
Messages.unsubscribe(DOMAIN_CHANGED_MESSAGE);
|
||||
MyAvatar.dominantHandChanged.disconnect(onDominantHandChanged);
|
||||
MyAvatar.skeletonChanged.disconnect(onSkeletonChanged);
|
||||
|
||||
isAppActive = false;
|
||||
updateHandControllerGrab();
|
||||
|
||||
|
||||
if (button) {
|
||||
button.clicked.disconnect(onAppButtonClicked);
|
||||
tablet.removeButton(button);
|
||||
|
|
Loading…
Reference in a new issue