93 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2016-08-23 12:34:32 -07:00
"use strict";
2016-06-17 10:56:35 -07:00
//
// audio.js
2016-06-17 10:56:35 -07:00
//
// 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
//
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
2016-06-17 10:56:35 -07:00
2016-08-23 12:34:32 -07:00
(function() { // BEGIN LOCAL_SCOPE
2016-06-17 10:56:35 -07:00
var TABLET_BUTTON_NAME = "AUDIO";
var HOME_BUTTON_TEXTURE = Script.getExternalPath(Script.ExternalPaths.HF_Content, "/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png");
var AUDIO_QML_SOURCE = "hifi/audio/Audio.qml";
2016-06-30 16:24:11 -07:00
var MUTE_ICONS = {
icon: "icons/tablet-icons/mic-mute-i.svg",
activeIcon: "icons/tablet-icons/mic-mute-a.svg"
};
var UNMUTE_ICONS = {
icon: "icons/tablet-icons/mic-unmute-i.svg",
activeIcon: "icons/tablet-icons/mic-unmute-a.svg"
};
var PTT_ICONS = {
icon: "icons/tablet-icons/mic-ptt-i.svg",
activeIcon: "icons/tablet-icons/mic-ptt-a.svg"
};
2016-06-30 16:24:11 -07:00
function onMuteToggled() {
if (Audio.pushToTalk) {
button.editProperties(PTT_ICONS);
} else if (Audio.muted) {
button.editProperties(MUTE_ICONS);
} else {
button.editProperties(UNMUTE_ICONS);
}
}
var onAudioScreen = false;
function onClicked() {
if (onAudioScreen) {
// for toolbar-mode: go back to home screen, this will close the window.
tablet.gotoHomeScreen();
} else {
if (HMD.tabletID) {
Entities.editEntity(HMD.tabletID, { textures: JSON.stringify({ "tex.close": HOME_BUTTON_TEXTURE }) });
}
2017-06-26 23:18:21 -07:00
tablet.loadQMLSource(AUDIO_QML_SOURCE);
}
2016-06-30 16:24:11 -07:00
}
function onScreenChanged(type, url) {
2017-06-26 23:18:21 -07:00
onAudioScreen = (type === "QML" && url === AUDIO_QML_SOURCE);
// for toolbar mode: change button to active when window is first openend, false otherwise.
2017-06-26 23:18:21 -07:00
button.editProperties({isActive: onAudioScreen});
2016-06-30 16:24:11 -07:00
}
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var button = tablet.addButton({
icon: Audio.pushToTalk ? PTT_ICONS.icon : Audio.muted ? MUTE_ICONS.icon : UNMUTE_ICONS.icon,
activeIcon: Audio.pushToTalk ? PTT_ICONS.activeIcon : Audio.muted ? MUTE_ICONS.activeIcon : UNMUTE_ICONS.activeIcon,
text: TABLET_BUTTON_NAME,
sortOrder: 1
});
onMuteToggled();
2016-06-30 16:24:11 -07:00
button.clicked.connect(onClicked);
tablet.screenChanged.connect(onScreenChanged);
2017-06-13 16:02:58 -04:00
Audio.mutedChanged.connect(onMuteToggled);
Audio.pushToTalkChanged.connect(onMuteToggled);
HMD.displayModeChanged.connect(onMuteToggled);
2016-06-17 10:56:35 -07:00
Script.scriptEnding.connect(function () {
if (onAudioScreen) {
tablet.gotoHomeScreen();
}
2016-06-30 16:24:11 -07:00
button.clicked.disconnect(onClicked);
tablet.screenChanged.disconnect(onScreenChanged);
2017-06-13 16:02:58 -04:00
Audio.mutedChanged.disconnect(onMuteToggled);
Audio.pushToTalkChanged.disconnect(onMuteToggled);
HMD.displayModeChanged.disconnect(onMuteToggled);
tablet.removeButton(button);
2016-06-17 10:56:35 -07:00
});
2016-08-23 12:34:32 -07:00
}()); // END LOCAL_SCOPE