myBalance

- balance formatting
	- symbol layout changes
This commit is contained in:
Stojce Slavkovski 2014-06-08 15:56:37 +02:00
parent 939f8c49de
commit 83b096ca1d

View file

@ -5,7 +5,7 @@
// Created by Stojce Slavkovski on June 5, 2014 // Created by Stojce Slavkovski on June 5, 2014
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// Show wallet balance // Show wallet balance
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -22,9 +22,9 @@ var Account = Account || {};
overlayWidth = 150, overlayWidth = 150,
overlayHeight = 50, overlayHeight = 50,
overlayTopOffset = 15, overlayTopOffset = 15,
overlayRightOffset = 100, overlayRightOffset = 140,
textRightOffset = 75, textRightOffset = 105,
maxDecimals = 5, maxIntegers = 5,
downColor = { downColor = {
red: 0, red: 0,
green: 0, green: 0,
@ -41,12 +41,12 @@ var Account = Account || {};
blue: 204 blue: 204
}, },
balance = -1, balance = -1,
voxelTool = Overlays.addOverlay("image", { walletBox = Overlays.addOverlay("image", {
x: 0, x: 0,
y: overlayTopOffset, y: overlayTopOffset,
width: 92, width: 122,
height: 32, height: 32,
imageURL: iconUrl + "wallet.svg", imageURL: iconUrl + "walletsymbol.svg",
alpha: 1 alpha: 1
}), }),
textOverlay = Overlays.addOverlay("text", { textOverlay = Overlays.addOverlay("text", {
@ -54,20 +54,19 @@ var Account = Account || {};
y: overlayTopOffset, y: overlayTopOffset,
topMargin: 9, topMargin: 9,
font: { font: {
size: 15 size: 16
}, },
color: normalColor, color: normalColor
alpha: 0
}); });
function scriptEnding() { function scriptEnding() {
Overlays.deleteOverlay(voxelTool); Overlays.deleteOverlay(walletBox);
Overlays.deleteOverlay(textOverlay); Overlays.deleteOverlay(textOverlay);
} }
function update(deltaTime) { function update(deltaTime) {
var xPos = Controller.getViewportDimensions().x; var xPos = Controller.getViewportDimensions().x;
Overlays.editOverlay(voxelTool, { Overlays.editOverlay(walletBox, {
x: xPos - overlayRightOffset, x: xPos - overlayRightOffset,
visible: Account.isLoggedIn() visible: Account.isLoggedIn()
}); });
@ -78,19 +77,31 @@ var Account = Account || {};
}); });
} }
function formatedBalance() {
var integers = balance.toFixed(0).length,
decimals = Math.abs(maxIntegers - integers) + 2;
var x = balance.toFixed(decimals).split('.'),
x1 = x[0],
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
function updateBalance(newBalance) { function updateBalance(newBalance) {
if (balance === newBalance) { if (balance === newBalance) {
return; return;
} }
var change = newBalance - balance, var change = newBalance - balance,
textColor = change < 0 ? downColor : upColor, textColor = change < 0 ? downColor : upColor;
integers = newBalance.toFixed(0).length,
decimals = integers > maxDecimals ? 0 : maxDecimals - integers;
balance = newBalance; balance = newBalance;
Overlays.editOverlay(textOverlay, { Overlays.editOverlay(textOverlay, {
text: balance.toFixed(decimals), text: formatedBalance(),
color: textColor color: textColor
}); });