mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +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 Overlays = Overlays || {};
|
||||
var Script = Script || {};
|
||||
var AccountManager = AccountManager || {};
|
||||
var Account = Account || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
@ -24,6 +24,7 @@ var AccountManager = AccountManager || {};
|
|||
overlayTopOffset = 15,
|
||||
overlayRightOffset = 100,
|
||||
textRightOffset = 75,
|
||||
maxDecimals = 5,
|
||||
downColor = {
|
||||
red: 0,
|
||||
green: 0,
|
||||
|
@ -39,7 +40,7 @@ var AccountManager = AccountManager || {};
|
|||
green: 204,
|
||||
blue: 204
|
||||
},
|
||||
balance = 0,
|
||||
balance = -1,
|
||||
voxelTool = Overlays.addOverlay("image", {
|
||||
x: 0,
|
||||
y: overlayTopOffset,
|
||||
|
@ -52,7 +53,6 @@ var AccountManager = AccountManager || {};
|
|||
x: 0,
|
||||
y: overlayTopOffset,
|
||||
topMargin: 9,
|
||||
text: balance.toFixed(4),
|
||||
font: {
|
||||
size: 15
|
||||
},
|
||||
|
@ -68,11 +68,13 @@ var AccountManager = AccountManager || {};
|
|||
function update(deltaTime) {
|
||||
var xPos = Controller.getViewportDimensions().x;
|
||||
Overlays.editOverlay(voxelTool, {
|
||||
x: xPos - overlayRightOffset
|
||||
x: xPos - overlayRightOffset,
|
||||
visible: Account.isLoggedIn()
|
||||
});
|
||||
|
||||
Overlays.editOverlay(textOverlay, {
|
||||
x: xPos - textRightOffset
|
||||
x: xPos - textRightOffset,
|
||||
visible: Account.isLoggedIn()
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -83,8 +85,8 @@ var AccountManager = AccountManager || {};
|
|||
|
||||
var change = newBalance - balance,
|
||||
textColor = change < 0 ? downColor : upColor,
|
||||
integers = balance.toFixed(0).length,
|
||||
decimals = integers > 4 ? 0 : integers - 4;
|
||||
integers = newBalance.toFixed(0).length,
|
||||
decimals = integers > maxDecimals ? 0 : maxDecimals - integers;
|
||||
|
||||
balance = newBalance;
|
||||
Overlays.editOverlay(textOverlay, {
|
||||
|
@ -99,7 +101,8 @@ var AccountManager = AccountManager || {};
|
|||
}, 1000);
|
||||
}
|
||||
|
||||
AccountManager.balanceChanged.connect(updateBalance);
|
||||
updateBalance(Account.getBalance());
|
||||
Account.balanceChanged.connect(updateBalance);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
Script.update.connect(update);
|
||||
}());
|
|
@ -73,6 +73,7 @@
|
|||
#include "devices/TV3DManager.h"
|
||||
#include "renderer/ProgramObject.h"
|
||||
|
||||
#include "scripting/AccountScriptingInterface.h"
|
||||
#include "scripting/AudioDeviceScriptingInterface.h"
|
||||
#include "scripting/ClipboardScriptingInterface.h"
|
||||
#include "scripting/MenuScriptingInterface.h"
|
||||
|
@ -3469,7 +3470,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());
|
||||
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
|
||||
|
||||
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