diff --git a/launcher/minecraft/MultiWorldList.cpp b/launcher/minecraft/MultiWorldList.cpp index 923f1751b..cff1c298c 100644 --- a/launcher/minecraft/MultiWorldList.cpp +++ b/launcher/minecraft/MultiWorldList.cpp @@ -227,6 +227,9 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const case NameColumn: return instanceWorld.world.name(); + case InstanceColumn: + return instanceWorld.instance->name(); + case GameModeColumn: return instanceWorld.world.gameType().toTranslatedString(); @@ -303,6 +306,8 @@ QVariant MultiWorldList::headerData(int section, [[maybe_unused]] Qt::Orientatio switch (section) { case NameColumn: return tr("Name"); + case InstanceColumn: + return tr("Instance"); case GameModeColumn: return tr("Game Mode"); case LastPlayedColumn: @@ -321,6 +326,8 @@ QVariant MultiWorldList::headerData(int section, [[maybe_unused]] Qt::Orientatio switch (section) { case NameColumn: return tr("The name of the world."); + case InstanceColumn: + return tr("The instance the world belongs to."); case GameModeColumn: return tr("Game mode of the world."); case LastPlayedColumn: @@ -454,7 +461,7 @@ int64_t MultiWorldList::calculateWorldSize(const QFileInfo& file) return -1; } -void MultiWorldList::loadWorldsAsync() //this causes problems when deleting instances iy - only load this screen when switch to all worlds page? +void MultiWorldList::loadWorldsAsync() { for (int i = 0; i < m_worlds.size(); ++i) { auto file = m_worlds.at(i).world.container(); diff --git a/launcher/minecraft/MultiWorldList.h b/launcher/minecraft/MultiWorldList.h index 147f5e8f8..75d140aea 100644 --- a/launcher/minecraft/MultiWorldList.h +++ b/launcher/minecraft/MultiWorldList.h @@ -33,9 +33,9 @@ struct InstanceWorld { class MultiWorldList : public QAbstractListModel { Q_OBJECT public: - enum Columns { NameColumn, GameModeColumn, LastPlayedColumn, SizeColumn, InfoColumn }; + enum Columns { NameColumn, InstanceColumn, GameModeColumn, LastPlayedColumn, SizeColumn, InfoColumn }; - enum Roles { ObjectRole = Qt::UserRole + 1, FolderRole, SeedRole, NameRole, GameModeRole, LastPlayedRole, SizeRole, IconFileRole }; + enum Roles { ObjectRole = Qt::UserRole + 1, FolderRole, SeedRole, NameRole, InstanceRole, GameModeRole, LastPlayedRole, SizeRole, IconFileRole }; MultiWorldList(const QList& dirs, const QList& instances); diff --git a/launcher/ui/MultiWorldListPage.cpp b/launcher/ui/MultiWorldListPage.cpp index 3075bf840..417a37eda 100644 --- a/launcher/ui/MultiWorldListPage.cpp +++ b/launcher/ui/MultiWorldListPage.cpp @@ -92,6 +92,7 @@ MultiWorldListPage::MultiWorldListPage(MultiWorldList* worlds, QWidget* parent) ui->setupUi(this); ui->toolBar->insertSpacer(ui->actionRefresh); + ui->actionJoin->setEnabled(true); auto* proxy = new MultiWorldListProxyModel(this); proxy->setSortCaseSensitivity(Qt::CaseInsensitive); @@ -117,10 +118,6 @@ void MultiWorldListPage::openedImpl() { m_worlds->startWatching(); - // if (!m_inst || !m_inst->traits().contains("feature:is_quick_play_singleplayer")) { //get rid of this??? iy - // ui->toolBar->removeAction(ui->actionJoin); - // } - auto const setting_name = QString("WideBarVisibility_%1").arg(id()); m_wide_bar_setting = APPLICATION->settings()->getOrRegisterSetting(setting_name); @@ -209,7 +206,15 @@ void MultiWorldListPage::on_actionRemove_triggered() void MultiWorldListPage::on_actionView_Folder_triggered() { - DesktopServices::openPath(m_worlds->dirs()[0].absolutePath(), true); //remove view folder option for all worlds (make it world specific) iy + QModelIndex index = getSelectedWorld(); + if (!index.isValid()) { + return; + } + + auto worldVariant = m_worlds->data(index, MultiWorldList::ObjectRole); + auto world = (World*)worldVariant.value(); + + DesktopServices::openPath(world->canonicalFilePath(), true); } void MultiWorldListPage::on_actionData_Packs_triggered() @@ -237,9 +242,9 @@ void MultiWorldListPage::on_actionData_Packs_triggered() GenericPageProvider provider(dialog->windowTitle()); bool isIndexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool(); - m_datapackModel.reset(new DataPackFolderModel(folder, m_worlds->allWorlds()[0].instance, isIndexed, true)); //don't use instance 0 iy + m_datapackModel.reset(new DataPackFolderModel(folder, static_cast(m_worlds->data(index, MultiWorldList::ObjectRole).value())->instance, isIndexed, true)); //these cause crashes sometimes iy with null error SIGSEGV (probably due to watchers) after every first time launched -> using index 0 for instances doesnt fix it - provider.addPageCreator([this] { return new DataPackPage(m_worlds->allWorlds()[0].instance, m_datapackModel.get(), this); }); //no instance 0 iy + provider.addPageCreator([this, index] { return new DataPackPage(static_cast(m_worlds->data(index, MultiWorldList::ObjectRole).value())->instance, m_datapackModel.get(), this); }); //iy auto layout = new QVBoxLayout(dialog); @@ -375,16 +380,10 @@ void MultiWorldListPage::worldChanged([[maybe_unused]] const QModelIndex& curren ui->actionCopy->setEnabled(enable); ui->actionRename->setEnabled(enable); ui->actionData_Packs->setEnabled(enable); + ui->actionView_Folder->setEnabled(enable); + ui->actionJoin->setEnabled(enable); bool hasIcon = !index.data(MultiWorldList::IconFileRole).isNull(); ui->actionReset_Icon->setEnabled(enable && hasIcon); - - // auto supportsJoin = m_inst && m_inst->traits().contains("feature:is_quick_play_singleplayer"); //change this to be on instance by instance basis iy - // ui->actionJoin->setEnabled(enable && supportsJoin); - ui->actionJoin->setEnabled(true); - - // if (!supportsJoin) { - // ui->toolBar->removeAction(ui->actionJoin); - // } } void MultiWorldListPage::on_actionAdd_triggered() @@ -400,9 +399,9 @@ void MultiWorldListPage::on_actionAdd_triggered() } } -bool MultiWorldListPage::isWorldSafe(QModelIndex) +bool MultiWorldListPage::isWorldSafe(QModelIndex index) { - return !m_worlds->allWorlds()[0].instance->isRunning(); //don't use instance 0 iy + return !static_cast(m_worlds->data(index, MultiWorldList::ObjectRole).value())->instance->isRunning(); } bool MultiWorldListPage::worldSafetyNagQuestion(const QString& actionType) @@ -471,7 +470,7 @@ void MultiWorldListPage::on_actionJoin_triggered() return; } auto worldVariant = m_worlds->data(index, MultiWorldList::ObjectRole); - auto world = (InstanceWorld*)worldVariant.value(); + auto *world = static_cast(worldVariant.value()); APPLICATION->launch(world->instance, LaunchMode::Normal, std::make_shared(MinecraftTarget::parse(world->world.folderName(), true))); } diff --git a/launcher/ui/MultiWorldListPage.ui b/launcher/ui/MultiWorldListPage.ui index 874721eee..4b4acfd70 100644 --- a/launcher/ui/MultiWorldListPage.ui +++ b/launcher/ui/MultiWorldListPage.ui @@ -91,10 +91,10 @@ + -