mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 14:29:13 +02:00
expose account details via AccountScriptingInterface
This commit is contained in:
parent
39c1daca43
commit
8de2bdfb99
4 changed files with 85 additions and 9 deletions
|
@ -14,7 +14,7 @@
|
||||||
var Controller = Controller || {};
|
var Controller = Controller || {};
|
||||||
var Overlays = Overlays || {};
|
var Overlays = Overlays || {};
|
||||||
var Script = Script || {};
|
var Script = Script || {};
|
||||||
var AccountManager = AccountManager || {};
|
var Account = Account || {};
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -24,6 +24,7 @@ var AccountManager = AccountManager || {};
|
||||||
overlayTopOffset = 15,
|
overlayTopOffset = 15,
|
||||||
overlayRightOffset = 100,
|
overlayRightOffset = 100,
|
||||||
textRightOffset = 75,
|
textRightOffset = 75,
|
||||||
|
maxDecimals = 5,
|
||||||
downColor = {
|
downColor = {
|
||||||
red: 0,
|
red: 0,
|
||||||
green: 0,
|
green: 0,
|
||||||
|
@ -39,7 +40,7 @@ var AccountManager = AccountManager || {};
|
||||||
green: 204,
|
green: 204,
|
||||||
blue: 204
|
blue: 204
|
||||||
},
|
},
|
||||||
balance = 0,
|
balance = -1,
|
||||||
voxelTool = Overlays.addOverlay("image", {
|
voxelTool = Overlays.addOverlay("image", {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: overlayTopOffset,
|
y: overlayTopOffset,
|
||||||
|
@ -52,7 +53,6 @@ var AccountManager = AccountManager || {};
|
||||||
x: 0,
|
x: 0,
|
||||||
y: overlayTopOffset,
|
y: overlayTopOffset,
|
||||||
topMargin: 9,
|
topMargin: 9,
|
||||||
text: balance.toFixed(4),
|
|
||||||
font: {
|
font: {
|
||||||
size: 15
|
size: 15
|
||||||
},
|
},
|
||||||
|
@ -68,11 +68,13 @@ var AccountManager = AccountManager || {};
|
||||||
function update(deltaTime) {
|
function update(deltaTime) {
|
||||||
var xPos = Controller.getViewportDimensions().x;
|
var xPos = Controller.getViewportDimensions().x;
|
||||||
Overlays.editOverlay(voxelTool, {
|
Overlays.editOverlay(voxelTool, {
|
||||||
x: xPos - overlayRightOffset
|
x: xPos - overlayRightOffset,
|
||||||
|
visible: Account.isLoggedIn()
|
||||||
});
|
});
|
||||||
|
|
||||||
Overlays.editOverlay(textOverlay, {
|
Overlays.editOverlay(textOverlay, {
|
||||||
x: xPos - textRightOffset
|
x: xPos - textRightOffset,
|
||||||
|
visible: Account.isLoggedIn()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +85,8 @@ var AccountManager = AccountManager || {};
|
||||||
|
|
||||||
var change = newBalance - balance,
|
var change = newBalance - balance,
|
||||||
textColor = change < 0 ? downColor : upColor,
|
textColor = change < 0 ? downColor : upColor,
|
||||||
integers = balance.toFixed(0).length,
|
integers = newBalance.toFixed(0).length,
|
||||||
decimals = integers > 4 ? 0 : integers - 4;
|
decimals = integers > maxDecimals ? 0 : maxDecimals - integers;
|
||||||
|
|
||||||
balance = newBalance;
|
balance = newBalance;
|
||||||
Overlays.editOverlay(textOverlay, {
|
Overlays.editOverlay(textOverlay, {
|
||||||
|
@ -99,7 +101,8 @@ var AccountManager = AccountManager || {};
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountManager.balanceChanged.connect(updateBalance);
|
updateBalance(Account.getBalance());
|
||||||
|
Account.balanceChanged.connect(updateBalance);
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(scriptEnding);
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
}());
|
}());
|
|
@ -73,6 +73,7 @@
|
||||||
#include "devices/TV3DManager.h"
|
#include "devices/TV3DManager.h"
|
||||||
#include "renderer/ProgramObject.h"
|
#include "renderer/ProgramObject.h"
|
||||||
|
|
||||||
|
#include "scripting/AccountScriptingInterface.h"
|
||||||
#include "scripting/AudioDeviceScriptingInterface.h"
|
#include "scripting/AudioDeviceScriptingInterface.h"
|
||||||
#include "scripting/ClipboardScriptingInterface.h"
|
#include "scripting/ClipboardScriptingInterface.h"
|
||||||
#include "scripting/MenuScriptingInterface.h"
|
#include "scripting/MenuScriptingInterface.h"
|
||||||
|
@ -3469,7 +3470,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
|
||||||
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
|
||||||
scriptEngine->registerGlobalObject("AnimationCache", &_animationCache);
|
scriptEngine->registerGlobalObject("AnimationCache", &_animationCache);
|
||||||
scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector);
|
scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector);
|
||||||
scriptEngine->registerGlobalObject("AccountManager", &AccountManager::getInstance());
|
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
|
||||||
|
|
||||||
QThread* workerThread = new QThread(this);
|
QThread* workerThread = new QThread(this);
|
||||||
|
|
||||||
|
|
37
interface/src/scripting/AccountScriptingInterface.cpp
Normal file
37
interface/src/scripting/AccountScriptingInterface.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
//
|
||||||
|
// AccountScriptingInterface.cpp
|
||||||
|
// interface/src/scripting
|
||||||
|
//
|
||||||
|
// Created by Stojce Slavkovski on 6/07/14.
|
||||||
|
// Copyright 2014 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
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "AccountScriptingInterface.h"
|
||||||
|
|
||||||
|
AccountScriptingInterface::AccountScriptingInterface() {
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
connect(&accountManager, &AccountManager::balanceChanged, this,
|
||||||
|
&AccountScriptingInterface::updateBalance);
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountScriptingInterface* AccountScriptingInterface::getInstance() {
|
||||||
|
static AccountScriptingInterface sharedInstance;
|
||||||
|
return &sharedInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 AccountScriptingInterface::getBalance() {
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
return accountManager.getAccountInfo().getBalance();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AccountScriptingInterface::isLoggedIn() {
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
return accountManager.isLoggedIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccountScriptingInterface::updateBalance(qint16 newBalance) {
|
||||||
|
emit balanceChanged(newBalance);
|
||||||
|
}
|
35
interface/src/scripting/AccountScriptingInterface.h
Normal file
35
interface/src/scripting/AccountScriptingInterface.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
//
|
||||||
|
// AccountScriptingInterface.h
|
||||||
|
// interface/src/scripting
|
||||||
|
//
|
||||||
|
// Created by Stojce Slavkovski on 6/07/14.
|
||||||
|
// Copyright 2014 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
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_AccountScriptingInterface_h
|
||||||
|
#define hifi_AccountScriptingInterface_h
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
|
class AccountScriptingInterface : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
AccountScriptingInterface();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void balanceChanged(qint64 newBalance);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
static AccountScriptingInterface* getInstance();
|
||||||
|
qint64 getBalance();
|
||||||
|
bool isLoggedIn();
|
||||||
|
void updateBalance(qint16 newBalance);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_AccountScriptingInterface_h
|
Loading…
Reference in a new issue