diff --git a/api/logic/minecraft/ComponentList.cpp b/api/logic/minecraft/ComponentList.cpp index b2afdb17..51fe214d 100644 --- a/api/logic/minecraft/ComponentList.cpp +++ b/api/logic/minecraft/ComponentList.cpp @@ -43,6 +43,8 @@ ComponentList::ComponentList(MinecraftInstance * instance) d->m_instance = instance; d->m_saveTimer.setSingleShot(true); d->m_saveTimer.setInterval(5000); + d->interactionDisabled = instance->isRunning(); + connect(d->m_instance, &BaseInstance::runningStatusChanged, this, &ComponentList::disableInteraction); connect(&d->m_saveTimer, &QTimer::timeout, this, &ComponentList::save_internal); } @@ -765,8 +767,9 @@ QVariant ComponentList::data(const QModelIndex &index, int role) const { switch (column) { - case NameColumn: - return d->components.at(row)->isEnabled() ? Qt::Checked : Qt::Unchecked; + case NameColumn: { + return patch->isEnabled() ? Qt::Checked : Qt::Unchecked; + } default: return QVariant(); } @@ -776,7 +779,7 @@ QVariant ComponentList::data(const QModelIndex &index, int role) const switch (column) { case NameColumn: - return d->components.at(row)->getName(); + return patch->getName(); case VersionColumn: { if(patch->isCustom()) @@ -856,21 +859,25 @@ QVariant ComponentList::headerData(int section, Qt::Orientation orientation, int } return QVariant(); } + +// FIXME: zero precision mess Qt::ItemFlags ComponentList::flags(const QModelIndex &index) const { - if (!index.isValid()) + if (!index.isValid()) { return Qt::NoItemFlags; + } Qt::ItemFlags outFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; int row = index.row(); - if (row < 0 || row >= d->components.size()) + if (row < 0 || row >= d->components.size()) { return Qt::NoItemFlags; + } auto patch = d->components.at(row); // TODO: this will need fine-tuning later... - if(patch->canBeDisabled()) + if(patch->canBeDisabled() && !d->interactionDisabled) { outFlags |= Qt::ItemIsUserCheckable; } @@ -1205,3 +1212,14 @@ QString ComponentList::getComponentVersion(const QString& uid) const } return QString(); } + +void ComponentList::disableInteraction(bool disable) +{ + if(d->interactionDisabled != disable) { + d->interactionDisabled = disable; + auto size = d->components.size(); + if(size) { + emit dataChanged(index(0), index(size - 1)); + } + } +} diff --git a/api/logic/minecraft/ComponentList.h b/api/logic/minecraft/ComponentList.h index cb20c559..7b5e1385 100644 --- a/api/logic/minecraft/ComponentList.h +++ b/api/logic/minecraft/ComponentList.h @@ -134,6 +134,7 @@ private slots: void updateSucceeded(); void updateFailed(const QString & error); void componentDataChanged(); + void disableInteraction(bool disable); private: bool load(); diff --git a/api/logic/minecraft/ComponentList_p.h b/api/logic/minecraft/ComponentList_p.h index aed65337..7a3d498b 100644 --- a/api/logic/minecraft/ComponentList_p.h +++ b/api/logic/minecraft/ComponentList_p.h @@ -38,5 +38,6 @@ struct ComponentListData QTimer m_saveTimer; shared_qobject_ptr m_updateTask; bool loaded = false; + bool interactionDisabled = true; }; diff --git a/application/pages/instance/VersionPage.cpp b/application/pages/instance/VersionPage.cpp index ed300e77..ed2f1391 100644 --- a/application/pages/instance/VersionPage.cpp +++ b/application/pages/instance/VersionPage.cpp @@ -97,7 +97,7 @@ QIcon VersionPage::icon() const } bool VersionPage::shouldDisplay() const { - return !m_inst->isRunning(); + return true; } QMenu * VersionPage::createPopupMenu() @@ -140,9 +140,11 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) auto smodel = ui->packageView->selectionModel(); connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent); + connect(m_profile.get(), &ComponentList::minecraftChanged, this, &VersionPage::updateVersionControls); + controlsEnabled = !m_inst->isRunning(); updateVersionControls(); preselect(0); - connect(m_profile.get(), &ComponentList::minecraftChanged, this, &VersionPage::updateVersionControls); + connect(m_inst, &BaseInstance::runningStatusChanged, this, &VersionPage::updateRunningStatus); } VersionPage::~VersionPage() @@ -192,28 +194,47 @@ void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex & ui->frame->setModDescription(problemOut); } +void VersionPage::updateRunningStatus(bool running) +{ + if(controlsEnabled == running) { + controlsEnabled = !running; + updateVersionControls(); + } +} void VersionPage::updateVersionControls() { // FIXME: this is a dirty hack - 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->actionInstall_Fabric->setEnabled(newCraft); - ui->actionInstall_Forge->setEnabled(oldCraft); - ui->actionInstall_LiteLoader->setEnabled(oldCraft); - ui->actionReload->setEnabled(true); - } - else { - ui->actionInstall_Fabric->setEnabled(false); - ui->actionInstall_Forge->setEnabled(false); - ui->actionInstall_LiteLoader->setEnabled(false); - ui->actionReload->setEnabled(false); - } + auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft")); + bool newCraft = controlsEnabled && (minecraftVersion >= Version("1.14")); + bool oldCraft = controlsEnabled && (minecraftVersion <= Version("1.12.2")); + ui->actionInstall_Fabric->setEnabled(newCraft); + ui->actionInstall_Forge->setEnabled(oldCraft); + ui->actionInstall_LiteLoader->setEnabled(oldCraft); + ui->actionReload->setEnabled(true); updateButtons(); } +void VersionPage::updateButtons(int row) +{ + if(row == -1) + row = currentRow(); + auto patch = m_profile->getComponent(row); + ui->actionRemove->setEnabled(controlsEnabled && patch && patch->isRemovable()); + ui->actionMove_down->setEnabled(controlsEnabled && patch && patch->isMoveable()); + ui->actionMove_up->setEnabled(controlsEnabled && patch && patch->isMoveable()); + ui->actionChange_version->setEnabled(controlsEnabled && patch && patch->isVersionChangeable()); + ui->actionEdit->setEnabled(controlsEnabled && patch && patch->isCustom()); + ui->actionCustomize->setEnabled(controlsEnabled && patch && patch->isCustomizable()); + ui->actionRevert->setEnabled(controlsEnabled && patch && patch->isRevertible()); + ui->actionDownload_All->setEnabled(controlsEnabled); + ui->actionAdd_Empty->setEnabled(controlsEnabled); + ui->actionReload->setEnabled(controlsEnabled); + ui->actionInstall_mods->setEnabled(controlsEnabled); + ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled); + ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled); +} + bool VersionPage::reloadComponentList() { try @@ -515,37 +536,9 @@ void VersionPage::preselect(int row) updateButtons(row); } -void VersionPage::updateButtons(int row) -{ - if(row == -1) - row = currentRow(); - auto patch = m_profile->getComponent(row); - if (!patch) - { - ui->actionRemove->setDisabled(true); - ui->actionMove_down->setDisabled(true); - ui->actionMove_up->setDisabled(true); - ui->actionChange_version->setDisabled(true); - ui->actionEdit->setDisabled(true); - ui->actionCustomize->setDisabled(true); - ui->actionRevert->setDisabled(true); - } - else - { - ui->actionRemove->setEnabled(patch->isRemovable()); - ui->actionMove_down->setEnabled(patch->isMoveable()); - ui->actionMove_up->setEnabled(patch->isMoveable()); - ui->actionChange_version->setEnabled(patch->isVersionChangeable()); - ui->actionEdit->setEnabled(patch->isCustom()); - ui->actionCustomize->setEnabled(patch->isCustomizable()); - ui->actionRevert->setEnabled(patch->isRevertible()); - } -} - void VersionPage::onGameUpdateError(QString error) { - CustomMessageBox::selectable(this, tr("Error updating instance"), error, - QMessageBox::Warning)->show(); + CustomMessageBox::selectable(this, tr("Error updating instance"), error, QMessageBox::Warning)->show(); } Component * VersionPage::current() diff --git a/application/pages/instance/VersionPage.h b/application/pages/instance/VersionPage.h index 6f5285ac..553c6ae3 100644 --- a/application/pages/instance/VersionPage.h +++ b/application/pages/instance/VersionPage.h @@ -86,11 +86,13 @@ private: std::shared_ptr m_profile; MinecraftInstance *m_inst; int currentIdx = 0; + bool controlsEnabled = false; public slots: void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); private slots: + void updateRunningStatus(bool running); void onGameUpdateError(QString error); void packageCurrent(const QModelIndex ¤t, const QModelIndex &previous);