instance icons and minecraft version

This commit is contained in:
Ice Yeti 2026-06-12 12:09:33 -04:00
parent 7e7de65fb4
commit 2e656c247b
4 changed files with 34 additions and 12 deletions

View file

@ -46,7 +46,10 @@
#include <QUuid> #include <QUuid>
#include <Qt> #include <Qt>
#include "Application.h"
#include "MinecraftInstance.h" #include "MinecraftInstance.h"
#include "PackProfile.h"
#include "icons/IconList.h"
MultiWorldList::MultiWorldList(const QList<BaseInstance*>& instances) : QAbstractListModel(), allInstances(instances) MultiWorldList::MultiWorldList(const QList<BaseInstance*>& instances) : QAbstractListModel(), allInstances(instances)
{ {
@ -230,6 +233,10 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const
case InstanceColumn: case InstanceColumn:
return instanceWorld.instance->name(); return instanceWorld.instance->name();
case VersionColumn:
static_cast<MinecraftInstance*>(instanceWorld.instance)->getPackProfile()->reload(Net::Mode::Online);
return static_cast<MinecraftInstance*>(instanceWorld.instance)->getPackProfile()->getComponentVersion("net.minecraft");
case GameModeColumn: case GameModeColumn:
return instanceWorld.world.gameType().toTranslatedString(); return instanceWorld.world.gameType().toTranslatedString();
@ -240,10 +247,8 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const
return locale.formattedDataSize(instanceWorld.world.bytes()); return locale.formattedDataSize(instanceWorld.world.bytes());
case InfoColumn: case InfoColumn:
for (QString path : instDirPaths()) { if (instanceWorld.world.isSymLinkUnder(QFileInfo(instanceWorld.instance->instanceRoot()).absoluteFilePath())) {
if (instanceWorld.world.isSymLinkUnder(path)) { return tr("This world is symbolically linked from elsewhere.");
return tr("This world is symbolically linked from elsewhere.");
}
} }
if (instanceWorld.world.isMoreThanOneHardLink()) { if (instanceWorld.world.isMoreThanOneHardLink()) {
return tr("\nThis world is hard linked elsewhere."); return tr("\nThis world is hard linked elsewhere.");
@ -260,12 +265,10 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const
case Qt::ToolTipRole: { case Qt::ToolTipRole: {
if (column == InfoColumn) { if (column == InfoColumn) {
for (QString path : instDirPaths()) { if (instanceWorld.world.isSymLinkUnder(QFileInfo(instanceWorld.instance->instanceRoot()).absoluteFilePath())) {
if (instanceWorld.world.isSymLinkUnder(path)) { return tr("Warning: This world is symbolically linked from elsewhere. Editing it will also change the original."
return tr("Warning: This world is symbolically linked from elsewhere. Editing it will also change the original." "\nCanonical Path: %1")
"\nCanonical Path: %1") .arg(instanceWorld.world.canonicalFilePath());
.arg(instanceWorld.world.canonicalFilePath());
}
} }
if (instanceWorld.world.isMoreThanOneHardLink()) { if (instanceWorld.world.isMoreThanOneHardLink()) {
return tr("Warning: This world is hard linked elsewhere. Editing it will also change the original."); return tr("Warning: This world is hard linked elsewhere. Editing it will also change the original.");
@ -294,6 +297,9 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const
case IconFileRole: { case IconFileRole: {
return instanceWorld.world.iconFile(); return instanceWorld.world.iconFile();
} }
case InstanceIconFileRole: {
return APPLICATION->icons()->getIcon(instanceWorld.instance->iconKey());
}
default: default:
return QVariant(); return QVariant();
} }
@ -308,6 +314,8 @@ QVariant MultiWorldList::headerData(int section, [[maybe_unused]] Qt::Orientatio
return tr("Name"); return tr("Name");
case InstanceColumn: case InstanceColumn:
return tr("Instance"); return tr("Instance");
case VersionColumn:
return tr("Version");
case GameModeColumn: case GameModeColumn:
return tr("Game Mode"); return tr("Game Mode");
case LastPlayedColumn: case LastPlayedColumn:
@ -328,6 +336,8 @@ QVariant MultiWorldList::headerData(int section, [[maybe_unused]] Qt::Orientatio
return tr("The name of the world."); return tr("The name of the world.");
case InstanceColumn: case InstanceColumn:
return tr("The instance the world belongs to."); return tr("The instance the world belongs to.");
case VersionColumn:
return tr("The Minecraft version of the world.");
case GameModeColumn: case GameModeColumn:
return tr("Game mode of the world."); return tr("Game mode of the world.");
case LastPlayedColumn: case LastPlayedColumn:

View file

@ -33,9 +33,9 @@ struct InstanceWorld {
class MultiWorldList : public QAbstractListModel { class MultiWorldList : public QAbstractListModel {
Q_OBJECT Q_OBJECT
public: public:
enum Columns { NameColumn, InstanceColumn, GameModeColumn, LastPlayedColumn, SizeColumn, InfoColumn }; enum Columns { NameColumn, InstanceColumn, VersionColumn, GameModeColumn, LastPlayedColumn, SizeColumn, InfoColumn };
enum Roles { ObjectRole = Qt::UserRole + 1, FolderRole, SeedRole, NameRole, InstanceRole, GameModeRole, LastPlayedRole, SizeRole, IconFileRole }; enum Roles { ObjectRole = Qt::UserRole + 1, FolderRole, SeedRole, NameRole, InstanceRole, VersionRole, GameModeRole, LastPlayedRole, SizeRole, IconFileRole, InstanceIconFileRole };
MultiWorldList(const QList<BaseInstance*>& instances); MultiWorldList(const QList<BaseInstance*>& instances);

View file

@ -889,11 +889,15 @@ void MainWindow::toggleAllWorldsScreen(bool toggled)
ui->instanceToolBar->setVisible(false); ui->instanceToolBar->setVisible(false);
allWorldsPage->setVisible(true); allWorldsPage->setVisible(true);
allWorlds->startWatching();
connect(allWorldsPage, &MultiWorldListPage::worldJoined, this, &MainWindow::worldJoined); connect(allWorldsPage, &MultiWorldListPage::worldJoined, this, &MainWindow::worldJoined);
} else { } else {
allWorldsPage->setVisible(false); allWorldsPage->setVisible(false);
view->setVisible(true); view->setVisible(true);
ui->instanceToolBar->setVisible(m_oldInstanceToolbarSetting); ui->instanceToolBar->setVisible(m_oldInstanceToolbarSetting);
allWorlds->stopWatching();
} }
} }

View file

@ -83,6 +83,12 @@ class MultiWorldListProxyModel : public QSortFilterProxyModel {
return QIcon(iconFile); return QIcon(iconFile);
} }
if (index.column() == 1 && role == Qt::DecorationRole) {
MultiWorldList* worlds = qobject_cast<MultiWorldList*>(sourceModel());
auto icon = worlds->data(sourceIndex, MultiWorldList::InstanceIconFileRole).value<QIcon>();
return icon.pixmap(24, 24);
}
return sourceIndex.data(role); return sourceIndex.data(role);
} }
}; };
@ -484,6 +490,8 @@ MinecraftInstance* MultiWorldListPage::selectInstance(const QString& message, Ba
} }
} }
instanceList->sortItems(Qt::AscendingOrder);
layout->addWidget(instanceList); layout->addWidget(instanceList);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);