mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 06:03:26 +02:00
Added timestamps to the scripted UI
This commit is contained in:
parent
56f7f88d75
commit
022109a249
5 changed files with 139 additions and 8 deletions
|
@ -29,6 +29,9 @@ var saveIcon;
|
||||||
var loadIcon;
|
var loadIcon;
|
||||||
setupToolBar();
|
setupToolBar();
|
||||||
|
|
||||||
|
var timer = null;
|
||||||
|
setupTimer();
|
||||||
|
|
||||||
function setupToolBar() {
|
function setupToolBar() {
|
||||||
if (toolBar != null) {
|
if (toolBar != null) {
|
||||||
print("Multiple calls to Recorder.js:setupToolBar()");
|
print("Multiple calls to Recorder.js:setupToolBar()");
|
||||||
|
@ -69,14 +72,68 @@ function setupToolBar() {
|
||||||
alpha: ALPHA_ON,
|
alpha: ALPHA_ON,
|
||||||
visible: true
|
visible: true
|
||||||
}, false, false);
|
}, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
moveUI();
|
function setupTimer() {
|
||||||
|
timer = Overlays.addOverlay("text", {
|
||||||
|
font: { size: 20 },
|
||||||
|
text: (0.00).toFixed(3),
|
||||||
|
backgroundColor: COLOR_OFF,
|
||||||
|
x: 0, y: 0,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
alpha: 1.0,
|
||||||
|
visible: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTimer() {
|
||||||
|
var text = "";
|
||||||
|
if (MyAvatar.isRecording()) {
|
||||||
|
text = formatTime(MyAvatar.recorderElapsed())
|
||||||
|
} else {
|
||||||
|
text = formatTime(MyAvatar.playerElapsed()) + " / " +
|
||||||
|
formatTime(MyAvatar.playerLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
Overlays.editOverlay(timer, {
|
||||||
|
text: text
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(time) {
|
||||||
|
var MIN_PER_HOUR = 60;
|
||||||
|
var SEC_PER_MIN = 60;
|
||||||
|
var MSEC_PER_SEC = 1000;
|
||||||
|
|
||||||
|
var hours = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR));
|
||||||
|
time -= hours * (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR);
|
||||||
|
|
||||||
|
var minutes = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN));
|
||||||
|
time -= minutes * (MSEC_PER_SEC * SEC_PER_MIN);
|
||||||
|
|
||||||
|
var seconds = Math.floor(time / MSEC_PER_SEC);
|
||||||
|
seconds = time / MSEC_PER_SEC;
|
||||||
|
|
||||||
|
var text = "";
|
||||||
|
text += (hours > 0) ? hours + ":" :
|
||||||
|
"";
|
||||||
|
text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :
|
||||||
|
"";
|
||||||
|
text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveUI() {
|
function moveUI() {
|
||||||
var relative = { x: 30, y: 90 };
|
var relative = { x: 30, y: 90 };
|
||||||
toolBar.move(relative.x,
|
toolBar.move(relative.x,
|
||||||
windowDimensions.y - relative.y);
|
windowDimensions.y - relative.y);
|
||||||
|
Overlays.editOverlay(timer, {
|
||||||
|
x: relative.x - 10,
|
||||||
|
y: windowDimensions.y - relative.y - 35,
|
||||||
|
width: 0,
|
||||||
|
height: 0
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mousePressEvent(event) {
|
function mousePressEvent(event) {
|
||||||
|
@ -100,11 +157,15 @@ function mousePressEvent(event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (saveIcon === toolBar.clicked(clickedOverlay)) {
|
} else if (saveIcon === toolBar.clicked(clickedOverlay)) {
|
||||||
|
if (!MyAvatar.isRecording()) {
|
||||||
recordingFile = Window.save("Save recording to file", ".", "*.rec");
|
recordingFile = Window.save("Save recording to file", ".", "*.rec");
|
||||||
MyAvatar.saveRecording(recordingFile);
|
MyAvatar.saveRecording(recordingFile);
|
||||||
|
}
|
||||||
} else if (loadIcon === toolBar.clicked(clickedOverlay)) {
|
} else if (loadIcon === toolBar.clicked(clickedOverlay)) {
|
||||||
|
if (!MyAvatar.isRecording()) {
|
||||||
recordingFile = Window.browse("Load recorcding from file", ".", "*.rec");
|
recordingFile = Window.browse("Load recorcding from file", ".", "*.rec");
|
||||||
MyAvatar.loadRecording(recordingFile);
|
MyAvatar.loadRecording(recordingFile);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -117,6 +178,8 @@ function update() {
|
||||||
windowDimensions = newDimensions;
|
windowDimensions = newDimensions;
|
||||||
moveUI();
|
moveUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
function scriptEnding() {
|
function scriptEnding() {
|
||||||
|
@ -127,12 +190,14 @@ function scriptEnding() {
|
||||||
MyAvatar.stopPlaying();
|
MyAvatar.stopPlaying();
|
||||||
}
|
}
|
||||||
toolBar.cleanup();
|
toolBar.cleanup();
|
||||||
|
Overlays.deleteOverlay(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.mousePressEvent.connect(mousePressEvent);
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(scriptEnding);
|
||||||
|
|
||||||
|
// Should be called last to put everything into position
|
||||||
|
moveUI();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -317,6 +317,11 @@ bool Player::computeCurrentFrame() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeRecordingToFile(RecordingPointer recording, QString filename) {
|
void writeRecordingToFile(RecordingPointer recording, QString filename) {
|
||||||
|
if (!recording || recording->getFrameNumber() < 1) {
|
||||||
|
qDebug() << "Can't save empty recording";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Writing recording to " << filename << ".";
|
qDebug() << "Writing recording to " << filename << ".";
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
|
|
|
@ -137,6 +137,8 @@ public:
|
||||||
bool isPlaying() const;
|
bool isPlaying() const;
|
||||||
qint64 elapsed() const;
|
qint64 elapsed() const;
|
||||||
|
|
||||||
|
RecordingPointer getRecording() const { return _recording; }
|
||||||
|
|
||||||
// Those should only be called if isPlaying() returns true
|
// Those should only be called if isPlaying() returns true
|
||||||
glm::quat getHeadRotation();
|
glm::quat getHeadRotation();
|
||||||
float getLeanSideways();
|
float getLeanSideways();
|
||||||
|
|
|
@ -509,6 +509,9 @@ bool MyAvatar::setJointReferential(int id, int jointIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyAvatar::isRecording() {
|
bool MyAvatar::isRecording() {
|
||||||
|
if (!_recorder) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
bool result;
|
bool result;
|
||||||
QMetaObject::invokeMethod(this, "isRecording", Qt::BlockingQueuedConnection,
|
QMetaObject::invokeMethod(this, "isRecording", Qt::BlockingQueuedConnection,
|
||||||
|
@ -518,6 +521,19 @@ bool MyAvatar::isRecording() {
|
||||||
return _recorder && _recorder->isRecording();
|
return _recorder && _recorder->isRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 MyAvatar::recorderElapsed() {
|
||||||
|
if (!_recorder) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
qint64 result;
|
||||||
|
QMetaObject::invokeMethod(this, "recorderElapsed", Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(qint64, result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return _recorder->elapsed();
|
||||||
|
}
|
||||||
|
|
||||||
void MyAvatar::startRecording() {
|
void MyAvatar::startRecording() {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "startRecording", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(this, "startRecording", Qt::BlockingQueuedConnection);
|
||||||
|
@ -532,6 +548,9 @@ void MyAvatar::startRecording() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::stopRecording() {
|
void MyAvatar::stopRecording() {
|
||||||
|
if (!_recorder) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "stopRecording", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(this, "stopRecording", Qt::BlockingQueuedConnection);
|
||||||
return;
|
return;
|
||||||
|
@ -542,6 +561,10 @@ void MyAvatar::stopRecording() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::saveRecording(QString filename) {
|
void MyAvatar::saveRecording(QString filename) {
|
||||||
|
if (!_recorder) {
|
||||||
|
qDebug() << "There is no recording to save";
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "saveRecording", Qt::BlockingQueuedConnection,
|
QMetaObject::invokeMethod(this, "saveRecording", Qt::BlockingQueuedConnection,
|
||||||
Q_ARG(QString, filename));
|
Q_ARG(QString, filename));
|
||||||
|
@ -553,6 +576,9 @@ void MyAvatar::saveRecording(QString filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyAvatar::isPlaying() {
|
bool MyAvatar::isPlaying() {
|
||||||
|
if (!_player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
bool result;
|
bool result;
|
||||||
QMetaObject::invokeMethod(this, "isPlaying", Qt::BlockingQueuedConnection,
|
QMetaObject::invokeMethod(this, "isPlaying", Qt::BlockingQueuedConnection,
|
||||||
|
@ -562,6 +588,32 @@ bool MyAvatar::isPlaying() {
|
||||||
return _player && _player->isPlaying();
|
return _player && _player->isPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 MyAvatar::playerElapsed() {
|
||||||
|
if (!_player) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
qint64 result;
|
||||||
|
QMetaObject::invokeMethod(this, "playerElapsed", Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(qint64, result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return _player->elapsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 MyAvatar::playerLength() {
|
||||||
|
if (!_player) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
qint64 result;
|
||||||
|
QMetaObject::invokeMethod(this, "playerLength", Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(qint64, result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return _player->getRecording()->getLength();
|
||||||
|
}
|
||||||
|
|
||||||
void MyAvatar::loadRecording(QString filename) {
|
void MyAvatar::loadRecording(QString filename) {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection,
|
QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection,
|
||||||
|
@ -581,6 +633,7 @@ void MyAvatar::loadLastRecording() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!_recorder) {
|
if (!_recorder) {
|
||||||
|
qDebug() << "There is no recording to load";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!_player) {
|
if (!_player) {
|
||||||
|
@ -604,6 +657,9 @@ void MyAvatar::startPlaying() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::stopPlaying() {
|
void MyAvatar::stopPlaying() {
|
||||||
|
if (!_player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "stopPlaying", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(this, "stopPlaying", Qt::BlockingQueuedConnection);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -162,11 +162,14 @@ public slots:
|
||||||
bool setJointReferential(int id, int jointIndex);
|
bool setJointReferential(int id, int jointIndex);
|
||||||
|
|
||||||
bool isRecording();
|
bool isRecording();
|
||||||
|
qint64 recorderElapsed();
|
||||||
void startRecording();
|
void startRecording();
|
||||||
void stopRecording();
|
void stopRecording();
|
||||||
void saveRecording(QString filename);
|
void saveRecording(QString filename);
|
||||||
|
|
||||||
bool isPlaying();
|
bool isPlaying();
|
||||||
|
qint64 playerElapsed();
|
||||||
|
qint64 playerLength();
|
||||||
void loadRecording(QString filename);
|
void loadRecording(QString filename);
|
||||||
void loadLastRecording();
|
void loadLastRecording();
|
||||||
void startPlaying();
|
void startPlaying();
|
||||||
|
|
Loading…
Reference in a new issue