Implement account per instance feature
Signed-off-by: urFate <georgiylakidon@gmail.com>
This commit is contained in:
parent
21db985b54
commit
2a7c666932
@ -112,7 +112,10 @@ void LaunchController::decideAccount()
|
||||
}
|
||||
}
|
||||
|
||||
m_accountToUse = accounts->defaultAccount();
|
||||
bool overrideAccount = m_instance->settings()->get("OverrideAccount").toBool();
|
||||
QString overrideAccountName = m_instance->settings()->get("OverrideAccountName").toString();
|
||||
|
||||
m_accountToUse = !overrideAccount ? accounts->defaultAccount() : accounts->getAccountByProfileName(overrideAccountName);
|
||||
if (!m_accountToUse)
|
||||
{
|
||||
// If no default account is set, ask the user which one to use.
|
||||
|
@ -188,6 +188,10 @@ void MinecraftInstance::loadSpecificSettings()
|
||||
m_settings->registerSetting("JoinServerOnLaunch", false);
|
||||
m_settings->registerSetting("JoinServerOnLaunchAddress", "");
|
||||
|
||||
// Account override
|
||||
m_settings->registerSetting("OverrideAccount", false);
|
||||
m_settings->registerSetting("OverrideAccountName", "");
|
||||
|
||||
qDebug() << "Instance-type specific settings were loaded!";
|
||||
|
||||
setSpecificSettingsLoaded(true);
|
||||
|
@ -53,11 +53,14 @@
|
||||
#include "java/JavaUtils.h"
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include "minecraft/auth/AccountList.h"
|
||||
|
||||
|
||||
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
|
||||
{
|
||||
m_settings = inst->settings();
|
||||
m_accounts = APPLICATION->accounts();
|
||||
ui->setupUi(this);
|
||||
auto sysMB = Sys::getSystemRam() / Sys::mebibyte;
|
||||
ui->maxMemSpinBox->setMaximum(sysMB);
|
||||
@ -275,6 +278,18 @@ void InstanceSettingsPage::applySettings()
|
||||
m_settings->reset("JoinServerOnLaunchAddress");
|
||||
}
|
||||
|
||||
// Account override settings
|
||||
bool accountOverride = ui->accountGroupBox->isChecked();
|
||||
m_settings->set("OverrideAccount", accountOverride);
|
||||
if (accountOverride)
|
||||
{
|
||||
m_settings->set("OverrideAccountName", ui->accountComboBox->currentText());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_settings->reset("OverrideAccountName");
|
||||
}
|
||||
|
||||
// FIXME: This should probably be called by a signal instead
|
||||
m_instance->updateRuntimeContext();
|
||||
}
|
||||
@ -372,6 +387,20 @@ void InstanceSettingsPage::loadSettings()
|
||||
|
||||
ui->serverJoinGroupBox->setChecked(m_settings->get("JoinServerOnLaunch").toBool());
|
||||
ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString());
|
||||
|
||||
for (int i = 0; i < m_accounts->count(); ++i) {
|
||||
MinecraftAccountPtr account = m_accounts->at(i);
|
||||
|
||||
QString profileLabel = account->profileName();
|
||||
QPixmap profileFace = account->getFace();
|
||||
QIcon profileIcon = !profileFace.isNull() ? QIcon(profileFace) : APPLICATION->getThemedIcon("noaccount");
|
||||
|
||||
ui->accountComboBox->addItem(profileIcon, profileLabel);
|
||||
}
|
||||
int accountIndex = ui->accountComboBox->findText(m_settings->get("OverrideAccountName").toString());
|
||||
|
||||
ui->accountGroupBox->setChecked(m_settings->get("OverrideAccount").toBool());
|
||||
ui->accountComboBox->setCurrentIndex(accountIndex == -1 ? 0 : accountIndex);
|
||||
}
|
||||
|
||||
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
||||
|
@ -93,5 +93,6 @@ private:
|
||||
Ui::InstanceSettingsPage *ui;
|
||||
BaseInstance *m_instance;
|
||||
SettingsObjectPtr m_settings;
|
||||
shared_qobject_ptr<AccountList> m_accounts;
|
||||
unique_qobject_ptr<JavaCommon::TestCheck> checker;
|
||||
};
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>691</width>
|
||||
<height>581</height>
|
||||
<height>629</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@ -39,7 +39,7 @@
|
||||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="minecraftTab">
|
||||
<attribute name="title">
|
||||
@ -595,6 +595,48 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="accountGroupBox">
|
||||
<property name="title">
|
||||
<string>Set a account to use</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_15">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="accountLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="accountLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Game account:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="accountComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacerMiscellaneous">
|
||||
<property name="orientation">
|
||||
|
Loading…
Reference in New Issue
Block a user