mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 00:23:33 +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;
|
||||
setupToolBar();
|
||||
|
||||
var timer = null;
|
||||
setupTimer();
|
||||
|
||||
function setupToolBar() {
|
||||
if (toolBar != null) {
|
||||
print("Multiple calls to Recorder.js:setupToolBar()");
|
||||
|
@ -69,14 +72,68 @@ function setupToolBar() {
|
|||
alpha: ALPHA_ON,
|
||||
visible: true
|
||||
}, 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() {
|
||||
var relative = { x: 30, y: 90 };
|
||||
toolBar.move(relative.x,
|
||||
windowDimensions.y - relative.y);
|
||||
Overlays.editOverlay(timer, {
|
||||
x: relative.x - 10,
|
||||
y: windowDimensions.y - relative.y - 35,
|
||||
width: 0,
|
||||
height: 0
|
||||
});
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
|
@ -100,11 +157,15 @@ function mousePressEvent(event) {
|
|||
}
|
||||
}
|
||||
} else if (saveIcon === toolBar.clicked(clickedOverlay)) {
|
||||
recordingFile = Window.save("Save recording to file", ".", "*.rec");
|
||||
MyAvatar.saveRecording(recordingFile);
|
||||
if (!MyAvatar.isRecording()) {
|
||||
recordingFile = Window.save("Save recording to file", ".", "*.rec");
|
||||
MyAvatar.saveRecording(recordingFile);
|
||||
}
|
||||
} else if (loadIcon === toolBar.clicked(clickedOverlay)) {
|
||||
recordingFile = Window.browse("Load recorcding from file", ".", "*.rec");
|
||||
MyAvatar.loadRecording(recordingFile);
|
||||
if (!MyAvatar.isRecording()) {
|
||||
recordingFile = Window.browse("Load recorcding from file", ".", "*.rec");
|
||||
MyAvatar.loadRecording(recordingFile);
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
@ -117,6 +178,8 @@ function update() {
|
|||
windowDimensions = newDimensions;
|
||||
moveUI();
|
||||
}
|
||||
|
||||
updateTimer();
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
|
@ -127,12 +190,14 @@ function scriptEnding() {
|
|||
MyAvatar.stopPlaying();
|
||||
}
|
||||
toolBar.cleanup();
|
||||
Overlays.deleteOverlay(timer);
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Script.update.connect(update);
|
||||
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) {
|
||||
if (!recording || recording->getFrameNumber() < 1) {
|
||||
qDebug() << "Can't save empty recording";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Writing recording to " << filename << ".";
|
||||
QElapsedTimer timer;
|
||||
QFile file(filename);
|
||||
|
|
|
@ -137,6 +137,8 @@ public:
|
|||
bool isPlaying() const;
|
||||
qint64 elapsed() const;
|
||||
|
||||
RecordingPointer getRecording() const { return _recording; }
|
||||
|
||||
// Those should only be called if isPlaying() returns true
|
||||
glm::quat getHeadRotation();
|
||||
float getLeanSideways();
|
||||
|
|
|
@ -509,6 +509,9 @@ bool MyAvatar::setJointReferential(int id, int jointIndex) {
|
|||
}
|
||||
|
||||
bool MyAvatar::isRecording() {
|
||||
if (!_recorder) {
|
||||
return false;
|
||||
}
|
||||
if (QThread::currentThread() != thread()) {
|
||||
bool result;
|
||||
QMetaObject::invokeMethod(this, "isRecording", Qt::BlockingQueuedConnection,
|
||||
|
@ -518,6 +521,19 @@ bool MyAvatar::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() {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "startRecording", Qt::BlockingQueuedConnection);
|
||||
|
@ -532,6 +548,9 @@ void MyAvatar::startRecording() {
|
|||
}
|
||||
|
||||
void MyAvatar::stopRecording() {
|
||||
if (!_recorder) {
|
||||
return;
|
||||
}
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "stopRecording", Qt::BlockingQueuedConnection);
|
||||
return;
|
||||
|
@ -542,6 +561,10 @@ void MyAvatar::stopRecording() {
|
|||
}
|
||||
|
||||
void MyAvatar::saveRecording(QString filename) {
|
||||
if (!_recorder) {
|
||||
qDebug() << "There is no recording to save";
|
||||
return;
|
||||
}
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "saveRecording", Qt::BlockingQueuedConnection,
|
||||
Q_ARG(QString, filename));
|
||||
|
@ -553,6 +576,9 @@ void MyAvatar::saveRecording(QString filename) {
|
|||
}
|
||||
|
||||
bool MyAvatar::isPlaying() {
|
||||
if (!_player) {
|
||||
return false;
|
||||
}
|
||||
if (QThread::currentThread() != thread()) {
|
||||
bool result;
|
||||
QMetaObject::invokeMethod(this, "isPlaying", Qt::BlockingQueuedConnection,
|
||||
|
@ -562,6 +588,32 @@ bool MyAvatar::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) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection,
|
||||
|
@ -581,6 +633,7 @@ void MyAvatar::loadLastRecording() {
|
|||
return;
|
||||
}
|
||||
if (!_recorder) {
|
||||
qDebug() << "There is no recording to load";
|
||||
return;
|
||||
}
|
||||
if (!_player) {
|
||||
|
@ -604,6 +657,9 @@ void MyAvatar::startPlaying() {
|
|||
}
|
||||
|
||||
void MyAvatar::stopPlaying() {
|
||||
if (!_player) {
|
||||
return;
|
||||
}
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "stopPlaying", Qt::BlockingQueuedConnection);
|
||||
return;
|
||||
|
|
|
@ -162,11 +162,14 @@ public slots:
|
|||
bool setJointReferential(int id, int jointIndex);
|
||||
|
||||
bool isRecording();
|
||||
qint64 recorderElapsed();
|
||||
void startRecording();
|
||||
void stopRecording();
|
||||
void saveRecording(QString filename);
|
||||
|
||||
bool isPlaying();
|
||||
qint64 playerElapsed();
|
||||
qint64 playerLength();
|
||||
void loadRecording(QString filename);
|
||||
void loadLastRecording();
|
||||
void startPlaying();
|
||||
|
|
Loading…
Reference in a new issue