Refining and allowing for Avatar Scale to be saved as well

This commit is contained in:
Menithal 2017-06-25 23:48:36 +03:00
parent d43d8ae846
commit 359642eb0e
4 changed files with 45 additions and 13 deletions

View file

@ -14,6 +14,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QStandardPaths> #include <QStandardPaths>
#include <QQmlContext> #include <QQmlContext>
#include <QList>
#include <Application.h> #include <Application.h>
#include <OffscreenUi.h> #include <OffscreenUi.h>
@ -24,6 +25,8 @@
#include "AvatarBookmarks.h" #include "AvatarBookmarks.h"
#include "InterfaceLogging.h" #include "InterfaceLogging.h"
#include "QVariantGLM.h"
#include <QtQuick/QQuickWindow> #include <QtQuick/QQuickWindow>
AvatarBookmarks::AvatarBookmarks() { AvatarBookmarks::AvatarBookmarks() {
@ -70,23 +73,32 @@ void AvatarBookmarks::changeToBookmarkedAvatar() {
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
// TODO: Phase this out eventually.
if (action->data().type() == QVariant::String) { if (action->data().type() == QVariant::String) {
// TODO: Phase this out eventually.
// Legacy avatar bookmark. // Legacy avatar bookmark.
myAvatar->useFullAvatarURL(action->data().toString()); myAvatar->useFullAvatarURL(action->data().toString());
qCDebug(interfaceapp) << " Using Legacy Avatar Bookmark "; qCDebug(interfaceapp) << " Using Legacy V1 Avatar Bookmark ";
} } else {
else {
// TODO: this is where the entry is interpreted.
const QMap<QString, QVariant> bookmark = action->data().toMap();
// Not magic value. This is the current made version, and if it changes this interpreter should be updated to handle the new one separately.
if (bookmark.value(ENTRY_VERSION) == 3) {
myAvatar->useFullAvatarURL(bookmark.value(ENTRY_AVATAR_URL).toString()); const QMap<QString, QVariant> bookmark = action->data().toMap();
myAvatar->setAttachmentsVariant(bookmark.value(ENTRY_AVATAR_ATTACHMENTS).toList()); // Not magic value. This is the current made version, and if it changes this interpreter should be updated to
} // handle the new one separately.
else { // This is where the avatar bookmark entry is parsed. If adding new Paradrims, make sure to have backward compat with previous
if (bookmark.value(ENTRY_VERSION) == 3) {
const QString& avatarUrl = bookmark.value(ENTRY_AVATAR_URL, "").toString();
myAvatar->useFullAvatarURL(avatarUrl);
qCDebug(interfaceapp) << "Avatar On " << avatarUrl;
const QList<QVariant>& attachments = bookmark.value(ENTRY_AVATAR_ATTACHMENTS, QList<QVariant>()).toList();
qCDebug(interfaceapp) << "Attach " << attachments;
myAvatar->setAttachmentsVariant(attachments);
const float& qScale = bookmark.value(ENTRY_AVATAR_SCALE, 1.0f).toFloat();
myAvatar->setAvatarScale(qScale);
} else {
qCDebug(interfaceapp) << " Bookmark entry does not match client version, make sure client has a handler for the new AvatarBookmark"; qCDebug(interfaceapp) << " Bookmark entry does not match client version, make sure client has a handler for the new AvatarBookmark";
} }
} }
@ -108,13 +120,14 @@ void AvatarBookmarks::addBookmark() {
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
const QString& avatarUrl = myAvatar->getSkeletonModelURL().toString(); const QString& avatarUrl = myAvatar->getSkeletonModelURL().toString();
const QVariantList& attachments = myAvatar->getAttachmentsVariant(); const QVariant& avatarScale = myAvatar->getAvatarScale();
// If Avatar attachments ever change, this is where to update them, when saving remember to also append to AVATAR_BOOKMARK_VERSION // If Avatar attachments ever change, this is where to update them, when saving remember to also append to AVATAR_BOOKMARK_VERSION
QVariantMap *bookmark = new QVariantMap; QVariantMap *bookmark = new QVariantMap;
bookmark->insert(ENTRY_VERSION, AVATAR_BOOKMARK_VERSION); bookmark->insert(ENTRY_VERSION, AVATAR_BOOKMARK_VERSION);
bookmark->insert(ENTRY_AVATAR_URL, avatarUrl); bookmark->insert(ENTRY_AVATAR_URL, avatarUrl);
bookmark->insert(ENTRY_AVATAR_ATTACHMENTS, attachments); bookmark->insert(ENTRY_AVATAR_SCALE, avatarScale);
bookmark->insert(ENTRY_AVATAR_ATTACHMENTS, myAvatar->getAttachmentsVariant());
Bookmarks::addBookmarkToFile(bookmarkName, *bookmark); Bookmarks::addBookmarkToFile(bookmarkName, *bookmark);
} }

View file

@ -34,6 +34,7 @@ private:
const QString AVATARBOOKMARKS_FILENAME = "avatarbookmarks.json"; const QString AVATARBOOKMARKS_FILENAME = "avatarbookmarks.json";
const QString ENTRY_AVATAR_URL = "avatarUrl"; const QString ENTRY_AVATAR_URL = "avatarUrl";
const QString ENTRY_AVATAR_ATTACHMENTS = "attachments"; const QString ENTRY_AVATAR_ATTACHMENTS = "attachments";
const QString ENTRY_AVATAR_SCALE = "avatarScale";
const QString ENTRY_VERSION = "version"; const QString ENTRY_VERSION = "version";
const int AVATAR_BOOKMARK_VERSION = 3; const int AVATAR_BOOKMARK_VERSION = 3;

View file

@ -2524,6 +2524,21 @@ bool MyAvatar::getFlyingEnabled() {
return _enableFlying; return _enableFlying;
} }
// Public interface for targetscale
float MyAvatar::getAvatarScale() {
return getTargetScale();
}
void MyAvatar::setAvatarScale(float val) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "setScale", Q_ARG(float, val));
return;
}
setTargetScale(val);
}
void MyAvatar::setCollisionsEnabled(bool enabled) { void MyAvatar::setCollisionsEnabled(bool enabled) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {

View file

@ -512,6 +512,9 @@ public:
Q_INVOKABLE void setFlyingEnabled(bool enabled); Q_INVOKABLE void setFlyingEnabled(bool enabled);
Q_INVOKABLE bool getFlyingEnabled(); Q_INVOKABLE bool getFlyingEnabled();
Q_INVOKABLE float getAvatarScale();
Q_INVOKABLE void setAvatarScale(float scale);
Q_INVOKABLE void setCollisionsEnabled(bool enabled); Q_INVOKABLE void setCollisionsEnabled(bool enabled);
Q_INVOKABLE bool getCollisionsEnabled(); Q_INVOKABLE bool getCollisionsEnabled();
Q_INVOKABLE void setCharacterControllerEnabled(bool enabled); // deprecated Q_INVOKABLE void setCharacterControllerEnabled(bool enabled); // deprecated