From fea1433cedc28e4f4beeb2166673207cce946cb1 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sat, 7 Jun 2014 10:32:36 +0200 Subject: [PATCH] Add initial mybalance script --- examples/myBalance.js | 104 ++++++++++++++++++++++++++++++++++ interface/src/Application.cpp | 1 + 2 files changed, 105 insertions(+) create mode 100644 examples/myBalance.js diff --git a/examples/myBalance.js b/examples/myBalance.js new file mode 100644 index 0000000000..8cfad159e5 --- /dev/null +++ b/examples/myBalance.js @@ -0,0 +1,104 @@ +// +// myBalance.js +// examples +// +// Created by Stojce Slavkovski on June 5, 2014 +// Copyright 2014 High Fidelity, Inc. +// +// Show wallet balance +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var Controller = Controller || {}; +var Overlays = Overlays || {}; +var Script = Script || {}; +var AccountManager = AccountManager || {}; + +(function () { + "use strict"; + var iconUrl = 'http://localhost/~stojce/', + overlayWidth = 150, + overlayHeight = 150, + redColor = { + red: 255, + green: 0, + blue: 0 + }, + greenColor = { + red: 0, + green: 255, + blue: 0 + }, + whiteColor = { + red: 255, + green: 255, + blue: 255 + }, + balance = 0, + voxelTool = Overlays.addOverlay("image", { + x: 0, + y: 0, + width: 50, + height: 50, + subImage: { + x: 0, + y: 50, + width: 50, + height: 50 + }, + imageURL: iconUrl + "wallet.svg", + alpha: 1 + }), + textOverlay = Overlays.addOverlay("text", { + x: 0, + y: 0, + width: 55, + height: 13, + topMargin: 5, + text: balance, + alpha: 0 + }); + + function scriptEnding() { + Overlays.deleteOverlay(voxelTool); + Overlays.deleteOverlay(textOverlay); + } + + function update(deltaTime) { + var xPos = Controller.getViewportDimensions().x; + Overlays.editOverlay(voxelTool, { + x: xPos - 150 + }); + + Overlays.editOverlay(textOverlay, { + x: xPos - 100 + }); + } + + function updateBalance(newBalance) { + if (balance === newBalance) { + return; + } + + var change = balance - newBalance, + textColor = change > 0 ? redColor : greenColor; + + balance = newBalance; + Overlays.editOverlay(textOverlay, { + text: balance, + color: textColor + }); + + Script.setTimeout(function () { + Overlays.editOverlay(textOverlay, { + color: whiteColor + }); + }, 1000); + } + + AccountManager.balanceChanged.connect(updateBalance); + Script.scriptEnding.connect(scriptEnding); + Script.update.connect(update); +}()); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 533d03d9e7..e3df9c17bb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3475,6 +3475,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AnimationCache", &_animationCache); scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector); + scriptEngine->registerGlobalObject("AccountManager", &AccountManager::getInstance()); QThread* workerThread = new QThread(this);