Skip to content

Commit

Permalink
NOISSUE update component buttons some more when the versions change
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed Jul 10, 2019
1 parent 5110b58 commit b9d4293
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 38 deletions.
3 changes: 3 additions & 0 deletions api/logic/minecraft/ComponentList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ void ComponentList::componentDataChanged()
qWarning() << "ComponentList got dataChenged signal from a non-Component!";
return;
}
if(objPtr->getID() == "net.minecraft") {
emit minecraftChanged();
}
// figure out which one is it... in a seriously dumb way.
int index = 0;
for (auto component: d->components)
Expand Down
3 changes: 3 additions & 0 deletions api/logic/minecraft/ComponentList.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class MULTIMC_LOGIC_EXPORT ComponentList : public QAbstractListModel
/// if there is a save scheduled, do it now.
void saveNow();

signals:
void minecraftChanged();

public:
/// get the profile component by id
Component * getComponent(const QString &id);
Expand Down
3 changes: 0 additions & 3 deletions api/logic/minecraft/MinecraftInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ class MULTIMC_LOGIC_EXPORT MinecraftInstance: public BaseInstance

virtual JavaVersion getJavaVersion() const;

signals:
void versionReloaded();

protected:
QMap<QString, QString> createCensorFilterFromSession(AuthSessionPtr session);
QStringList validLaunchMethods();
Expand Down
60 changes: 26 additions & 34 deletions application/pages/instance/VersionPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,18 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)

reloadComponentList();

if (m_profile)
{
auto proxy = new IconProxy(ui->packageView);
proxy->setSourceModel(m_profile.get());
ui->packageView->setModel(proxy);
ui->packageView->installEventFilter(this);
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
auto smodel = ui->packageView->selectionModel();
connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);
updateVersionControls();
// select first item.
preselect(0);
}
else
{
disableVersionControls();
}
connect(m_inst, &MinecraftInstance::versionReloaded, this, &VersionPage::updateVersionControls);
auto proxy = new IconProxy(ui->packageView);
proxy->setSourceModel(m_profile.get());
ui->packageView->setModel(proxy);
ui->packageView->installEventFilter(this);
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
auto smodel = ui->packageView->selectionModel();
connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);

updateVersionControls();
preselect(0);
connect(m_profile.get(), &ComponentList::minecraftChanged, this, &VersionPage::updateVersionControls);
}

VersionPage::~VersionPage()
Expand Down Expand Up @@ -181,21 +174,20 @@ void VersionPage::packageCurrent(const QModelIndex &current, const QModelIndex &
void VersionPage::updateVersionControls()
{
// FIXME: this is a dirty hack
auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft"));
bool newCraft = minecraftVersion >= Version("1.14");
bool oldCraft = minecraftVersion <= Version("1.12.2");
ui->fabricBtn->setEnabled(newCraft);
ui->forgeBtn->setEnabled(oldCraft);
ui->liteloaderBtn->setEnabled(oldCraft);
updateButtons();
}

void VersionPage::disableVersionControls()
{
ui->fabricBtn->setEnabled(false);
ui->forgeBtn->setEnabled(false);
ui->liteloaderBtn->setEnabled(false);
ui->reloadBtn->setEnabled(false);
if(m_profile) {
auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft"));
bool newCraft = minecraftVersion >= Version("1.14");
bool oldCraft = minecraftVersion <= Version("1.12.2");
ui->fabricBtn->setEnabled(newCraft);
ui->forgeBtn->setEnabled(oldCraft);
ui->liteloaderBtn->setEnabled(oldCraft);
}
else {
ui->fabricBtn->setEnabled(false);
ui->forgeBtn->setEnabled(false);
ui->liteloaderBtn->setEnabled(false);
ui->reloadBtn->setEnabled(false);
}
updateButtons();
}

Expand Down
1 change: 0 additions & 1 deletion application/pages/instance/VersionPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ private slots:
void on_downloadBtn_clicked();

void updateVersionControls();
void disableVersionControls();
void on_changeVersionBtn_clicked();

private:
Expand Down

0 comments on commit b9d4293

Please sign in to comment.