Made Changes per Review, added js

This commit is contained in:
Cain Kilgore 2017-08-14 22:47:18 +01:00
parent 619da8c415
commit e7a4bff705
2 changed files with 123 additions and 16 deletions

View file

@ -9,26 +9,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.5 as QQControls
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4
import QtWebEngine 1.2
import QtWebChannel 1.0
import "../styles-uit"
import "../controls-uit" as HifiControls
import "../windows"
import "../controls"
Rectangle {
id: root;
HifiConstants { id: hifi; }
property string title: "";
color: hifi.colors.baseGray;
Item {
@ -62,7 +47,7 @@ Rectangle {
size: 14;
// Anchors
anchors.fill: parent;
anchors.topMargin: 56;
anchors.top: titleBarText.bottom
anchors.leftMargin: 16;
anchors.rightMargin: 16;
// Style
@ -72,6 +57,10 @@ Rectangle {
verticalAlignment: Text.AlignVCenter;
}
}
// This RowLayout could be a GridLayout instead for further expandability.
// As this SkyboxChanger task only required 6 images, implementing GridLayout wasn't necessary.
// In the future if this is to be expanded to add more Skyboxes, it might be worth changing this.
RowLayout {
id: row1
anchors.top: titleBarContainer.bottom

View file

@ -0,0 +1,118 @@
"use strict";
//
// skyboxchanger.js
//
// Created by Cain Kilgore on 9th August 2017
// Copyright 2017 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
//
(function() {
var TABLET_BUTTON_NAME = "SKYBOX";
var ICONS = {
icon: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxedit-i.svg",
activeIcon: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxedit-i.svg"
};
var onSkyboxChangerScreen = false;
function onClicked() {
if (onSkyboxChangerScreen) {
tablet.gotoHomeScreen();
} else {
tablet.loadQMLSource("../SkyboxChanger.qml");
}
}
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var button = tablet.addButton({
icon: ICONS.icon,
activeIcon: ICONS.activeIcon,
text: TABLET_BUTTON_NAME,
sortOrder: 1
});
var hasEventBridge = false;
function wireEventBridge(on) {
if (!tablet) {
print("Warning in wireEventBridge(): 'tablet' undefined!");
return;
}
if (on) {
if (!hasEventBridge) {
tablet.fromQml.connect(fromQml);
hasEventBridge = true;
}
} else {
if (hasEventBridge) {
tablet.fromQml.disconnect(fromQml);
hasEventBridge = false;
}
}
}
function onScreenChanged(type, url) {
if (url === "../SkyboxChanger.qml") {
onSkyboxChangerScreen = true;
} else {
onSkyboxChangerScreen = false;
}
button.editProperties({isActive: onSkyboxChangerScreen});
wireEventBridge(onSkyboxChangerScreen);
}
function fromQml(message) {
switch (message.method) {
case 'changeSkybox': // changeSkybox Code
var standingZone;
if (!Entities.canRez()) {
Window.alert("You need to have rez permissions to change the Skybox.");
break;
}
var nearbyEntities = Entities.findEntities(MyAvatar.position, 5);
for (var i = 0; i < nearbyEntities.length; i++) {
if (Entities.getEntityProperties(nearbyEntities[i]).type === "Zone") {
standingZone = nearbyEntities[i];
}
}
if (Entities.getEntityProperties(standingZone).locked) {
Window.alert("This zone is currently locked; the Skybox can't be changed.");
break;
}
var newSkybox = {
skybox: {
url: message.url
},
keyLight: {
ambientURL: message.url
}
};
Entities.editEntity(standingZone, newSkybox);
break;
default:
print('Unrecognized message from QML: ' + JSON.stringify(message));
}
}
button.clicked.connect(onClicked);
tablet.screenChanged.connect(onScreenChanged);
Script.scriptEnding.connect(function () {
if (onSkyboxChangerScreen) {
tablet.gotoHomeScreen();
}
button.clicked.disconnect(onClicked);
tablet.screenChanged.disconnect(onScreenChanged);
tablet.removeButton(button);
});
}());