diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index 8f32b80bba..61bed8d9b1 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -18,3 +18,4 @@ Script.load("notifications.js"); Script.load("users.js"); Script.load("grab.js"); Script.load("pointer.js"); +Script.load("directory.js"); diff --git a/examples/directory.js b/examples/directory.js new file mode 100644 index 0000000000..b1fac19e8b --- /dev/null +++ b/examples/directory.js @@ -0,0 +1,92 @@ +// +// directory.js +// examples +// +// Created by David Rowe on 8 Jun 2015 +// Copyright 2015 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 +// + +Script.include("libraries/globals.js"); + +var directory = (function () { + + var DIRECTORY_URL = "https://metaverse.highfidelity.com/directory", + directoryWindow, + DIRECTORY_BUTTON_URL = HIFI_PUBLIC_BUCKET + "images/tools/directory.svg", + BUTTON_WIDTH = 50, + BUTTON_HEIGHT = 50, + BUTTON_ALPHA = 0.9, + BUTTON_MARGIN = 8, + directoryButton, + EDIT_TOOLBAR_BUTTONS = 10, // Number of buttons in edit.js toolbar + viewport; + + function updateButtonPosition() { + Overlays.editOverlay(directoryButton, { + x: viewport.x - BUTTON_WIDTH - BUTTON_MARGIN, + y: (viewport.y - (EDIT_TOOLBAR_BUTTONS + 1) * (BUTTON_HEIGHT + BUTTON_MARGIN) - BUTTON_MARGIN) / 2 - 1 + }); + } + + function onMousePressEvent(event) { + var clickedOverlay; + + clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); + + if (clickedOverlay === directoryButton) { + if (directoryWindow.url !== DIRECTORY_URL) { + directoryWindow.setURL(DIRECTORY_URL); + } + directoryWindow.setVisible(true); + directoryWindow.raise(); + } + } + + function onDomainChanged() { + directoryWindow.setVisible(false); + } + + function onScriptUpdate() { + var oldViewport = viewport; + + viewport = Controller.getViewportDimensions(); + + if (viewport.x !== oldViewport.x || viewport.y !== oldViewport.y) { + updateButtonPosition(); + } + } + + function setUp() { + viewport = Controller.getViewportDimensions(); + + directoryWindow = new WebWindow('Directory', DIRECTORY_URL, 900, 700, false); + directoryWindow.setVisible(false); + + directoryButton = Overlays.addOverlay("image", { + imageURL: DIRECTORY_BUTTON_URL, + width: BUTTON_WIDTH, + height: BUTTON_HEIGHT, + x: viewport.x - BUTTON_WIDTH - BUTTON_MARGIN, + y: BUTTON_MARGIN, + alpha: BUTTON_ALPHA, + visible: true + }); + + updateButtonPosition(); + + Controller.mousePressEvent.connect(onMousePressEvent); + Window.domainChanged.connect(onDomainChanged); + + Script.update.connect(onScriptUpdate); + } + + function tearDown() { + Overlays.deleteOverlay(directoryButton); + } + + setUp(); + Script.scriptEnding.connect(tearDown); +}()); \ No newline at end of file diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 3aae6a4d4a..6be67a7261 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -31,7 +31,7 @@ WindowScriptingInterface::WindowScriptingInterface() : _formResult(QDialog::Rejected) { const DomainHandler& domainHandler = DependencyManager::get()->getDomainHandler(); - connect(&domainHandler, &DomainHandler::hostnameChanged, this, &WindowScriptingInterface::domainChanged); + connect(&domainHandler, &DomainHandler::connectedToDomain, this, &WindowScriptingInterface::domainChanged); connect(Application::getInstance(), &Application::svoImportRequested, this, &WindowScriptingInterface::svoImportRequested); connect(Application::getInstance(), &Application::domainConnectionRefused, this, &WindowScriptingInterface::domainConnectionRefused); }