From 4d1141f274fd2013e1341d39463dc957c954a8d6 Mon Sep 17 00:00:00 2001 From: Ice Yeti <101294194+IceYetiWins@users.noreply.github.com> Date: Wed, 27 May 2026 20:27:27 -0400 Subject: [PATCH] start work on ui --- launcher/InstanceList.cpp | 39 +++++++++++++++++---------- launcher/InstanceList.h | 7 ++--- launcher/minecraft/MultiWorldList.cpp | 4 +-- launcher/ui/MainWindow.cpp | 33 +++++++++++++++++++++++ launcher/ui/MainWindow.h | 4 +++ launcher/ui/MultiWorldListPage.cpp | 19 ++++++------- 6 files changed, 78 insertions(+), 28 deletions(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index 1339499c7..8eb43d5da 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -138,7 +138,7 @@ QMimeData* InstanceList::mimeData(const QModelIndexList& indexes) const QStringList InstanceList::getLinkedInstancesById(const QString& id) const { QStringList linkedInstances; - for (auto& inst : m_instances) { + for (auto& inst : instances) { if (inst->isLinkedToInstanceId(id)) linkedInstances.append(inst->id()); } @@ -156,7 +156,7 @@ QModelIndex InstanceList::index(int row, int column, const QModelIndex& parent) Q_UNUSED(parent); if (row < 0 || row >= count()) return QModelIndex(); - return createIndex(row, column, m_instances.at(row).get()); + return createIndex(row, column, instances.at(row).get()); } QVariant InstanceList::data(const QModelIndex& index, int role) const @@ -279,7 +279,7 @@ void InstanceList::deleteGroup(const GroupId& name) bool removed = false; qDebug() << "Delete group" << name; - for (auto& instance : m_instances) { + for (auto& instance : instances) { const QString& instID = instance->id(); const QString instGroupName = getInstanceGroup(instID); if (instGroupName == name) { @@ -303,7 +303,7 @@ void InstanceList::renameGroup(const QString& src, const QString& dst) bool modified = false; qDebug() << "Rename group" << src << "to" << dst; - for (auto& instance : m_instances) { + for (auto& instance : instances) { const QString& instID = instance->id(); const QString instGroupName = getInstanceGroup(instID); if (instGroupName == src) { @@ -497,7 +497,7 @@ QList InstanceList::discoverInstances() InstanceList::InstListError InstanceList::loadList() { - auto existingIds = getIdMapping(m_instances); + auto existingIds = getIdMapping(instances); std::vector> newList; @@ -525,7 +525,7 @@ InstanceList::InstListError InstanceList::loadList() int currentItem = -1; auto removeNow = [this, &front_bookmark, &back_bookmark, ¤tItem]() { beginRemoveRows(QModelIndex(), front_bookmark, back_bookmark); - m_instances.erase(m_instances.begin() + front_bookmark, m_instances.begin() + back_bookmark + 1); + instances.erase(instances.begin() + front_bookmark, instances.begin() + back_bookmark + 1); endRemoveRows(); front_bookmark = -1; back_bookmark = currentItem; @@ -560,14 +560,14 @@ InstanceList::InstListError InstanceList::loadList() void InstanceList::updateTotalPlayTime() { totalPlayTime = 0; - for (const auto& itr : m_instances) { + for (const auto& itr : instances) { totalPlayTime += itr->totalTimePlayed(); } } void InstanceList::saveNow() { - for (auto& item : m_instances) { + for (auto& item : instances) { item->saveNow(); } } @@ -576,8 +576,8 @@ void InstanceList::add(std::vector>& t) { beginInsertRows(QModelIndex(), count(), static_cast(count() + t.size() - 1)); for (auto& ptr : t) { - m_instances.push_back(std::move(ptr)); - connect(m_instances.back().get(), &BaseInstance::propertiesChanged, this, &InstanceList::propertiesChanged); + instances.push_back(std::move(ptr)); + connect(instances.back().get(), &BaseInstance::propertiesChanged, this, &InstanceList::propertiesChanged); } endInsertRows(); } @@ -607,11 +607,22 @@ void InstanceList::providerUpdated() } } +QList InstanceList::getAllInstances() +{ + QList instanceList; + + for (auto& inst : instances) { + instanceList.append(inst.get()); + } + + return instanceList; +} + BaseInstance* InstanceList::getInstanceById(QString instId) const { if (instId.isEmpty()) return nullptr; - for (auto& inst : m_instances) { + for (auto& inst : instances) { if (inst->id() == instId) { return inst.get(); } @@ -624,7 +635,7 @@ BaseInstance* InstanceList::getInstanceByManagedName(const QString& managed_name if (managed_name.isEmpty()) return {}; - for (auto& instance : m_instances) { + for (auto& instance : instances) { if (instance->getManagedPackName() == managed_name) return instance.get(); } @@ -641,7 +652,7 @@ int InstanceList::getInstIndex(BaseInstance* inst) const { int count = this->count(); for (int i = 0; i < count; i++) { - if (inst == m_instances.at(i).get()) { + if (inst == instances.at(i).get()) { return i; } } @@ -882,7 +893,7 @@ void InstanceList::on_InstFolderChanged([[maybe_unused]] const Setting& setting, m_instDir = newInstDir; m_groupsLoaded = false; beginRemoveRows(QModelIndex(), 0, count()); - m_instances.erase(m_instances.begin(), m_instances.end()); + instances.erase(instances.begin(), instances.end()); endRemoveRows(); emit instancesChanged(); } diff --git a/launcher/InstanceList.h b/launcher/InstanceList.h index f0a92d273..76ac01bc3 100644 --- a/launcher/InstanceList.h +++ b/launcher/InstanceList.h @@ -96,13 +96,14 @@ class InstanceList : public QAbstractListModel { */ enum InstListError { NoError = 0, UnknownError }; - BaseInstance* at(int i) const { return m_instances.at(i).get(); } + BaseInstance* at(int i) const { return instances.at(i).get(); } - int count() const { return static_cast(m_instances.size()); } + int count() const { return static_cast(instances.size()); } InstListError loadList(); void saveNow(); + QList getAllInstances(); /* O(n) */ BaseInstance* getInstanceById(QString id) const; /* O(n) */ @@ -192,7 +193,7 @@ class InstanceList : public QAbstractListModel { int m_watchLevel = 0; int totalPlayTime = 0; bool m_dirty = false; - std::vector> m_instances; + std::vector> instances; // id -> refs QMap m_groupNameCache; diff --git a/launcher/minecraft/MultiWorldList.cpp b/launcher/minecraft/MultiWorldList.cpp index c32f8cabc..258768c18 100644 --- a/launcher/minecraft/MultiWorldList.cpp +++ b/launcher/minecraft/MultiWorldList.cpp @@ -48,8 +48,8 @@ MultiWorldList::MultiWorldList(const QList& dirs, QList instances) : QAbstractListModel(), m_instances(instances) { - for (int i = 0; i < dirs.length(); i++) { - m_dirs[i] = dirs[i]; + for (QString dir : dirs) { + m_dirs.append(dir); } for (QDir dir : m_dirs) { diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 1bdcd3f68..42611ab88 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -93,6 +93,7 @@ #include "InstanceWindow.h" #include "ui/GuiUtil.h" +#include "ui/MultiWorldListPage.h" #include "ui/ViewLogWindow.h" #include "ui/dialogs/AboutDialog.h" #include "ui/dialogs/CopyInstanceDialog.h" @@ -113,6 +114,7 @@ #include "ui/themes/ThemeManager.h" #include "ui/widgets/LabeledToolButton.h" +#include "minecraft/MultiWorldList.h" #include "minecraft/PackProfile.h" #include "minecraft/VersionFile.h" #include "minecraft/WorldList.h" @@ -334,6 +336,22 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi connect(view, &InstanceView::groupStateChanged, APPLICATION->instances(), &InstanceList::on_GroupStateChanged); ui->horizontalLayout->addWidget(view); } + // Create the all worlds widget + { + QList allInstances = APPLICATION->instances()->getAllInstances(); + qDebug() << "iy initially" << allInstances.length(); + QList dirs; + for (BaseInstance* inst : allInstances) { + dirs.append(dynamic_cast(inst)->worldDir()); + } + + allWorlds = new MultiWorldList(dirs, allInstances); + allWorlds->update(); + allWorldsPage = new MultiWorldListPage(dynamic_cast(allInstances[0]), allWorlds); //shouldnt be only one instance iy + + ui->horizontalLayout->addWidget(allWorldsPage); + } + // The cat background { // set the cat action priority here so you can still see the action in qt designer @@ -926,6 +944,21 @@ void MainWindow::addInstance(const QString& url, const QMap& e if (creationTask) { instanceFromInstanceTask(creationTask); } + + //clean this up iy - fix ghosting issue and only joining one world despite which one you click + + QList allInstances = APPLICATION->instances()->getAllInstances(); + qDebug() << "iy finally " << allInstances.length(); + QList dirs; + for (BaseInstance* inst : allInstances) { + dirs.append(dynamic_cast(inst)->worldDir()); + } + + allWorlds = new MultiWorldList(dirs, allInstances); + allWorlds->update(); + auto newAllWorldsPage = new MultiWorldListPage(dynamic_cast(allInstances[0]), allWorlds); //shouldnt be only one instance iy + ui->horizontalLayout->replaceWidget(allWorldsPage, newAllWorldsPage); + allWorldsPage = newAllWorldsPage; } void MainWindow::on_actionAddInstance_triggered() diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index 80860deef..adc13cfe1 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -58,6 +58,8 @@ class QLabel; class MinecraftLauncher; class BaseProfilerFactory; class InstanceView; +class MultiWorldList; +class MultiWorldListPage; class KonamiCode; class InstanceTask; class LabeledToolButton; @@ -236,6 +238,7 @@ class MainWindow : public QMainWindow { Ui::MainWindow* ui; // these are managed by Qt's memory management model! InstanceView* view = nullptr; + MultiWorldListPage* allWorldsPage = nullptr; InstanceProxyModel* proxymodel = nullptr; QToolButton* newsLabel = nullptr; QLabel* m_statusLeft = nullptr; @@ -244,6 +247,7 @@ class MainWindow : public QMainWindow { LabeledToolButton* renameButton = nullptr; QToolButton* helpMenuButton = nullptr; KonamiCode* secretEventFilter = nullptr; + MultiWorldList* allWorlds = nullptr; std::shared_ptr instanceToolbarSetting = nullptr; diff --git a/launcher/ui/MultiWorldListPage.cpp b/launcher/ui/MultiWorldListPage.cpp index da527cc4f..16dc6a5c5 100644 --- a/launcher/ui/MultiWorldListPage.cpp +++ b/launcher/ui/MultiWorldListPage.cpp @@ -86,7 +86,7 @@ class MultiWorldListProxyModel : public QSortFilterProxyModel { } }; -MultiWorldListPage::MultiWorldListPage(MinecraftInstance* inst, MultiWorldList* worlds, QWidget* parent) +MultiWorldListPage::MultiWorldListPage(MinecraftInstance* inst, MultiWorldList* worlds, QWidget* parent) //require all instances instead of just one iy : QMainWindow(parent), m_inst(inst), ui(new Ui::MultiWorldListPage), m_worlds(worlds) { ui->setupUi(this); @@ -117,9 +117,9 @@ void MultiWorldListPage::openedImpl() { m_worlds->startWatching(); - if (!m_inst || !m_inst->traits().contains("feature:is_quick_play_singleplayer")) { - ui->toolBar->removeAction(ui->actionJoin); - } + // 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); @@ -378,12 +378,13 @@ void MultiWorldListPage::worldChanged([[maybe_unused]] const QModelIndex& curren 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"); - ui->actionJoin->setEnabled(enable && supportsJoin); + // 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); - } + // if (!supportsJoin) { + // ui->toolBar->removeAction(ui->actionJoin); + // } } void MultiWorldListPage::on_actionAdd_triggered()