93 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2016-08-23 12:34:32 -07:00
"use strict";
2016-06-03 14:57:46 -07:00
//
// hmd.js
// scripts/system/
//
// Created by Howard Stearns on 2 Jun 2016
// Copyright 2016 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
//
/* globals HMD, Script, Menu, Tablet, Camera */
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
2016-06-03 14:57:46 -07:00
2016-08-23 12:34:32 -07:00
(function() { // BEGIN LOCAL_SCOPE
2016-06-03 14:57:46 -07:00
var headset; // The preferred headset. Default to the first one found in the following list.
var displayMenuName = "Display";
var desktopMenuItemName = "Desktop";
2018-05-08 15:10:57 -07:00
['HTC Vive', 'Oculus Rift', 'WindowMS'].forEach(function (name) {
2016-06-03 14:57:46 -07:00
if (!headset && Menu.menuItemExists(displayMenuName, name)) {
headset = name;
}
});
2017-03-09 00:09:32 +00:00
var controllerDisplay = false;
function updateControllerDisplay() {
if (HMD.active && Menu.isOptionChecked("Third Person")) {
if (!controllerDisplay) {
HMD.requestShowHandControllers();
controllerDisplay = true;
}
} else if (controllerDisplay) {
HMD.requestHideHandControllers();
controllerDisplay = false;
}
}
2017-03-09 00:15:02 +00:00
var button;
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
2017-08-04 17:19:26 -07:00
var switchToVR = "ENTER VR";
var switchToDesktop = "EXIT VR";
2016-06-30 16:24:11 -07:00
function onHmdChanged(isHmd) {
HMD.closeTablet();
2017-01-25 16:29:36 -08:00
if (isHmd) {
button.editProperties({
icon: "icons/tablet-icons/switch-desk-i.svg",
text: switchToDesktop
2017-01-25 16:29:36 -08:00
});
2017-01-20 17:31:16 +00:00
} else {
2017-01-25 16:29:36 -08:00
button.editProperties({
icon: "icons/tablet-icons/switch-vr-i.svg",
text: switchToVR
2017-01-25 16:29:36 -08:00
});
2017-01-20 17:31:16 +00:00
}
updateControllerDisplay();
2016-06-30 16:24:11 -07:00
}
function onClicked() {
2016-06-30 16:24:11 -07:00
var isDesktop = Menu.isOptionChecked(desktopMenuItemName);
Menu.setIsOptionChecked(isDesktop ? headset : desktopMenuItemName, true);
if (!isDesktop) {
UserActivityLogger.logAction("exit_vr");
}
2016-06-30 16:24:11 -07:00
}
2016-06-17 10:56:35 -07:00
if (headset) {
button = tablet.addButton({
icon: HMD.active ? "icons/tablet-icons/switch-desk-i.svg" : "icons/tablet-icons/switch-vr-i.svg",
text: HMD.active ? switchToDesktop : switchToVR,
sortOrder: 2
});
2016-06-30 16:24:11 -07:00
onHmdChanged(HMD.active);
2016-08-23 12:34:32 -07:00
2016-06-30 16:24:11 -07:00
button.clicked.connect(onClicked);
HMD.displayModeChanged.connect(onHmdChanged);
Camera.modeUpdated.connect(updateControllerDisplay);
2016-08-23 12:34:32 -07:00
2016-06-17 10:56:35 -07:00
Script.scriptEnding.connect(function () {
2016-06-30 16:24:11 -07:00
button.clicked.disconnect(onClicked);
if (tablet) {
tablet.removeButton(button);
}
2016-06-30 16:24:11 -07:00
HMD.displayModeChanged.disconnect(onHmdChanged);
Camera.modeUpdated.disconnect(updateControllerDisplay);
2016-06-17 10:56:35 -07:00
});
}
2016-08-23 12:34:32 -07:00
}()); // END LOCAL_SCOPE