Skip to content

Commit

Permalink
Reword instance-specific account settings, apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
byteduck committed Jan 2, 2023
1 parent 2f31c82 commit 5ae4802
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
8 changes: 2 additions & 6 deletions launcher/LaunchController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,12 @@ void LaunchController::decideAccount()
// Select the account to use. If the instance has a specific account set, that will be used. Otherwise, the default account will be used
auto instanceAccountId = m_instance->settings()->get("InstanceAccountId").toString();
auto instanceAccountIndex = accounts->findAccountByProfileId(instanceAccountId);
if (instanceAccountIndex == -1)
{
if (instanceAccountIndex == -1) {
m_accountToUse = accounts->defaultAccount();
}
else
{
} else {
m_accountToUse = accounts->at(instanceAccountIndex);
}


if (!m_accountToUse)
{
// If no default account is set, ask the user which one to use.
Expand Down
39 changes: 16 additions & 23 deletions launcher/ui/pages/instance/InstanceSettingsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ void InstanceSettingsPage::applySettings()
// Use an account for this instance
bool useAccountForInstance = ui->instanceAccountGroupBox->isChecked();
m_settings->set("UseAccountForInstance", useAccountForInstance);
if (!useAccountForInstance)
{
if (!useAccountForInstance) {
m_settings->reset("InstanceAccountId");
}

Expand Down Expand Up @@ -459,33 +458,33 @@ void InstanceSettingsPage::updateAccountsMenu()

auto accounts = APPLICATION->accounts();
int accountIndex = accounts->findAccountByProfileId(m_settings->get("InstanceAccountId").toString());
MinecraftAccountPtr defaultAccount = accounts->defaultAccount();

if (accountIndex != -1)
{
auto account = accounts->at(accountIndex);
ui->instanceAccountSelector->setText(account->profileName());
ui->instanceAccountSelector->setIcon(account->getFace());
if (accountIndex != -1 && accounts->at(accountIndex)) {
defaultAccount = accounts->at(accountIndex);
}

if (defaultAccount) {
ui->instanceAccountSelector->setText(defaultAccount->profileName());
ui->instanceAccountSelector->setIcon(defaultAccount->getFace());
} else {
ui->instanceAccountSelector->setText(tr("No default account"));
ui->instanceAccountSelector->setIcon(APPLICATION->getThemedIcon("noaccount"));
}

for (int i = 0; i < accounts->count(); i++)
{
for (int i = 0; i < accounts->count(); i++) {
MinecraftAccountPtr account = accounts->at(i);
QAction *action = new QAction(account->profileName(), this);
QAction* action = new QAction(account->profileName(), this);
action->setData(i);
action->setCheckable(true);
if (accountIndex == i)
{
if (accountIndex == i) {
action->setChecked(true);
}

auto face = account->getFace();
if(!face.isNull()) {
if (!face.isNull()) {
action->setIcon(face);
}
else {
} else {
action->setIcon(APPLICATION->getThemedIcon("noaccount"));
}

Expand All @@ -496,20 +495,14 @@ void InstanceSettingsPage::updateAccountsMenu()

void InstanceSettingsPage::changeInstanceAccount()
{
QAction *sAction = (QAction *)sender();
QAction* sAction = (QAction*)sender();

// Profile's associated Mojang username
Q_ASSERT(sAction->data().type() == QVariant::Type::Int);

QVariant data = sAction->data();
bool valid = false;
int index = data.toInt(&valid);
if(!valid) {
index = -1;
}
int index = data.toInt();
auto accounts = APPLICATION->accounts();
auto account = accounts->at(index);

m_settings->set("InstanceAccountId", account->profileId());

ui->instanceAccountSelector->setText(account->profileName());
Expand Down
2 changes: 1 addition & 1 deletion launcher/ui/pages/instance/InstanceSettingsPage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@
<item>
<widget class="QGroupBox" name="instanceAccountGroupBox">
<property name="title">
<string>Set a default account to use with this instance</string>
<string>Override default account</string>
</property>
<property name="checkable">
<bool>true</bool>
Expand Down

0 comments on commit 5ae4802

Please sign in to comment.