From 681d36b23251993a8678db8e72859d4018396b63 Mon Sep 17 00:00:00 2001 From: Sky Date: Sat, 19 Oct 2013 06:40:46 +0100 Subject: First draft of player faces in the login dialog --- gui/logindialog.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ gui/logindialog.ui | 43 ++++++++++++++++++++++++++++++++++++++----- gui/mainwindow.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 5 deletions(-) (limited to 'gui') diff --git a/gui/logindialog.cpp b/gui/logindialog.cpp index ed3983b7..332b5d38 100644 --- a/gui/logindialog.cpp +++ b/gui/logindialog.cpp @@ -17,6 +17,13 @@ #include "ui_logindialog.h" #include "keyring.h" #include "gui/platform.h" +#include "MultiMC.h" + +#include +#include +#include +#include +#include "logic/net/HttpMetaCache.h" #include LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : @@ -51,6 +58,8 @@ LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : arg(loginErrMsg)); } + ui->lblFace->setVisible(false); + resize(minimumSizeHint()); layout()->setSizeConstraint(QLayout::SetFixedSize); Keyring * k = Keyring::instance(); @@ -151,13 +160,54 @@ void LoginDialog::userTextChanged ( const QString& user ) blockToggles = true; Keyring * k = Keyring::instance(); QStringList sl = k->getStoredAccounts("minecraft"); + bool gotFace = false; + if(sl.contains(user)) { ui->rememberUsernameCheckbox->setChecked(true); QString passwd = k->getPassword("minecraft",user); ui->rememberPasswordCheckbox->setChecked(!passwd.isEmpty()); ui->passwordTextBox->setText(passwd); + + QByteArray data; + { + auto filename = MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath(); + QFile listFile(filename); + if(!listFile.open(QIODevice::ReadOnly)) + return; + data = listFile.readAll(); + } + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + QJsonObject root = jsonDoc.object(); + QJsonObject mappings = root.value("mappings").toObject(); + + if(!mappings[user].isUndefined()) + { + QJsonArray usernames = mappings.value(user).toArray(); + if(!usernames.isEmpty()) + { + QString mapped_username = usernames[0].toString(); + + if(!mapped_username.isEmpty()) + { + QFile fskin(MMC->metacache()->resolveEntry("skins", mapped_username + ".png")->getFullPath()); + if(fskin.exists()) + { + QPixmap skin(MMC->metacache()->resolveEntry("skins", mapped_username + ".png")->getFullPath()); + QPixmap face = skin.copy(8, 8, 8, 8).scaled(48, 48, Qt::KeepAspectRatio); + + ui->lblFace->setPixmap(face); + gotFace = true; + } + } + } + } } + + if(gotFace) ui->lblFace->setVisible(true); + else ui->lblFace->setVisible(false); blockToggles = false; } diff --git a/gui/logindialog.ui b/gui/logindialog.ui index 0aaad52b..46965425 100644 --- a/gui/logindialog.ui +++ b/gui/logindialog.ui @@ -23,10 +23,34 @@ - - + + + + + 48 + 48 + + + + + 48 + 48 + + + + + 1 + 1 + + - Username: + + + + :/icons/instances/steve + + + true @@ -37,6 +61,13 @@ + + + + Username: + + + @@ -54,7 +85,7 @@ - + @@ -111,7 +142,9 @@ - + + + loginButtonBox diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 0bd6f651..b68af5fa 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -57,6 +57,8 @@ #include "logic/lists/JavaVersionList.h" #include "logic/net/LoginTask.h" +#include "logic/net/SkinDownload.h" + #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" #include "logic/MinecraftProcess.h" @@ -517,6 +519,42 @@ void MainWindow::onLoginComplete() tDialog.exec(updateTask); delete updateTask; } + + auto download = new SkinDownload(m_activeLogin.player_name); + download->start(); + + auto filename = MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath(); + QFile listFile(filename); + + // Add skin mapping + QByteArray data; + { + if(!listFile.open(QIODevice::ReadWrite)) + { + QLOG_ERROR() << "Failed to open/make skins list JSON"; + return; + } + + data = listFile.readAll(); + } + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + QJsonObject root = jsonDoc.object(); + QJsonObject mappings = root.value("mappings").toObject(); + QJsonArray usernames = mappings.value(m_activeLogin.username).toArray(); + + if(!usernames.contains(m_activeLogin.player_name)) + { + usernames.prepend(m_activeLogin.player_name); + mappings[m_activeLogin.username] = usernames; + root["mappings"] = mappings; + jsonDoc.setObject(root); + + // QJson hack - shouldn't have to clear the file every time a save happens + listFile.resize(0); + listFile.write(jsonDoc.toJson()); + } } void MainWindow::onGameUpdateComplete() -- cgit v1.2.3