Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1212 #1228

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions launcher/ui/pages/modplatform/ModPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,13 @@ void ModPage::filterMods()

void ModPage::triggerSearch()
{
auto changed = m_filter_widget->changed();
m_filter = m_filter_widget->getFilter();
m_ui->packView->clearSelection();
m_ui->packDescription->clear();
m_ui->versionSelectionBox->clear();
updateSelectionButton();

if (changed) {
m_ui->packView->clearSelection();
m_ui->packDescription->clear();
m_ui->versionSelectionBox->clear();
updateSelectionButton();
}

static_cast<ModModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentData().toUInt(), changed);
static_cast<ModModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentData().toUInt(), m_filter_widget->changed());
m_fetch_progress.watch(m_model->activeSearchJob().get());
}

Expand All @@ -122,6 +118,8 @@ void ModPage::updateVersionList()
QString mcVersion = packProfile->getComponentVersion("net.minecraft");

auto current_pack = getCurrentPack();
if (!current_pack)
return;
for (int i = 0; i < current_pack->versions.size(); i++) {
auto version = current_pack->versions[i];
bool valid = false;
Expand Down
31 changes: 18 additions & 13 deletions launcher/ui/pages/modplatform/ResourcePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ ModPlatform::IndexedPack::Ptr ResourcePage::getCurrentPack() const
void ResourcePage::updateUi()
{
auto current_pack = getCurrentPack();

if (!current_pack) {
m_ui->packDescription->setHtml({});
m_ui->packDescription->flush();
return;
}
QString text = "";
QString name = current_pack->name;

Expand Down Expand Up @@ -240,8 +244,8 @@ void ResourcePage::updateSelectionButton()
}

m_ui->resourceSelectionButton->setEnabled(true);
if (getCurrentPack()) {
if (!getCurrentPack()->isVersionSelected(m_selected_version_index))
if (auto current_pack = getCurrentPack(); current_pack) {
if (!current_pack->isVersionSelected(m_selected_version_index))
m_ui->resourceSelectionButton->setText(tr("Select %1 for download").arg(resourceString()));
else
m_ui->resourceSelectionButton->setText(tr("Deselect %1 for download").arg(resourceString()));
Expand All @@ -258,13 +262,14 @@ void ResourcePage::updateVersionList()
m_ui->versionSelectionBox->clear();
m_ui->versionSelectionBox->blockSignals(false);

for (int i = 0; i < current_pack->versions.size(); i++) {
auto& version = current_pack->versions[i];
if (optedOut(version))
continue;
if (current_pack)
for (int i = 0; i < current_pack->versions.size(); i++) {
auto& version = current_pack->versions[i];
if (optedOut(version))
continue;

m_ui->versionSelectionBox->addItem(current_pack->versions[i].version, QVariant(i));
}
m_ui->versionSelectionBox->addItem(current_pack->versions[i].version, QVariant(i));
}

if (m_ui->versionSelectionBox->count() == 0) {
m_ui->versionSelectionBox->addItem(tr("No valid version found."), QVariant(-1));
Expand All @@ -283,7 +288,7 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
auto current_pack = getCurrentPack();

bool request_load = false;
if (!current_pack->versionsLoaded) {
if (!current_pack || !current_pack->versionsLoaded) {
m_ui->resourceSelectionButton->setText(tr("Loading versions..."));
m_ui->resourceSelectionButton->setEnabled(false);

Expand All @@ -292,7 +297,7 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
updateVersionList();
}

if (!current_pack->extraDataLoaded)
if (current_pack && !current_pack->extraDataLoaded)
request_load = true;

if (request_load)
Expand Down Expand Up @@ -340,7 +345,7 @@ void ResourcePage::onResourceSelected()
return;

auto current_pack = getCurrentPack();
if (!current_pack->versionsLoaded)
if (!current_pack || !current_pack->versionsLoaded)
return;

auto& version = current_pack->versions[m_selected_version_index];
Expand Down Expand Up @@ -386,7 +391,7 @@ void ResourcePage::openUrl(const QUrl& url)
const QString slug = match.captured(1);

// ensure the user isn't opening the same mod
if (slug != getCurrentPack()->slug) {
if (auto current_pack = getCurrentPack(); current_pack && slug != current_pack->slug) {
m_parent_dialog->selectPage(page);

auto newPage = m_parent_dialog->getSelectedPage();
Expand Down