From 583e5946f4cd29f0a18bcc4fad5608de739aa113 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 Aug 2015 19:10:17 -0400 Subject: GH-1047 World management for instances. Removal only currently. --- application/CMakeLists.txt | 3 ++ application/InstancePageProvider.h | 3 ++ application/pages/WorldListPage.cpp | 94 +++++++++++++++++++++++++++++++++++++ application/pages/WorldListPage.h | 69 +++++++++++++++++++++++++++ application/pages/WorldListPage.ui | 94 +++++++++++++++++++++++++++++++++++++ 5 files changed, 263 insertions(+) create mode 100644 application/pages/WorldListPage.cpp create mode 100644 application/pages/WorldListPage.h create mode 100644 application/pages/WorldListPage.ui (limited to 'application') diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 1cc37a5d..f72b6a16 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -177,6 +177,8 @@ SET(MULTIMC_SOURCES pages/LegacyJarModPage.h pages/LegacyUpgradePage.cpp pages/LegacyUpgradePage.h + pages/WorldListPage.cpp + pages/WorldListPage.h # GUI - global settings pages pages/global/AccountListPage.cpp @@ -272,6 +274,7 @@ SET(MULTIMC_UIS pages/OtherLogsPage.ui pages/LegacyJarModPage.ui pages/LegacyUpgradePage.ui + pages/WorldListPage.ui # Global settings pages pages/global/AccountListPage.ui diff --git a/application/InstancePageProvider.h b/application/InstancePageProvider.h index 1da4c9f1..c3ae17c1 100644 --- a/application/InstancePageProvider.h +++ b/application/InstancePageProvider.h @@ -12,6 +12,7 @@ #include "pages/OtherLogsPage.h" #include "pages/BasePageProvider.h" #include "pages/LegacyJarModPage.h" +#include "pages/WorldListPage.h" #include @@ -39,6 +40,7 @@ public: values.append(new ResourcePackPage(onesix.get())); values.append(new TexturePackPage(onesix.get())); values.append(new NotesPage(onesix.get())); + values.append(new WorldListPage(onesix.get(), onesix->worldList(), "worlds", "worlds", tr("Worlds"), "Worlds")); values.append(new ScreenshotsPage(PathCombine(onesix->minecraftRoot(), "screenshots"))); values.append(new InstanceSettingsPage(onesix.get())); } @@ -54,6 +56,7 @@ public: values.append(new ModFolderPage(legacy.get(), legacy->coreModList(), "coremods", "coremods", tr("Core mods"), "Loader-mods")); values.append(new TexturePackPage(legacy.get())); values.append(new NotesPage(legacy.get())); + values.append(new WorldListPage(legacy.get(), legacy->worldList(), "worlds", "worlds", tr("Worlds"), "Worlds")); values.append(new ScreenshotsPage(PathCombine(legacy->minecraftRoot(), "screenshots"))); values.append(new InstanceSettingsPage(legacy.get())); } diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp new file mode 100644 index 00000000..662b7452 --- /dev/null +++ b/application/pages/WorldListPage.cpp @@ -0,0 +1,94 @@ +// +// Created by robotbrain on 8/18/15. +// + +#include "WorldListPage.h" +#include "ui_WorldListPage.h" +#include "minecraft/WorldList.h" +#include "dialogs/ModEditDialogCommon.h" +#include +#include + +WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr worlds, QString id, + QString iconName, QString displayName, QString helpPage, + QWidget *parent) + : QWidget(parent), ui(new Ui::WorldListPage) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + m_inst = inst; + m_worlds = worlds; + m_id = id; + m_displayName = displayName; + m_iconName = iconName; + m_helpName = helpPage; + ui->worldTreeView->setModel(m_worlds.get()); + ui->worldTreeView->installEventFilter(this); + auto smodel = ui->worldTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(modCurrent(QModelIndex, QModelIndex))); +} + +void WorldListPage::opened() +{ + m_worlds->startWatching(); +} + +void WorldListPage::closed() +{ + m_worlds->stopWatching(); +} + +WorldListPage::~WorldListPage() +{ + m_worlds->stopWatching(); + delete ui; +} + +bool WorldListPage::shouldDisplay() const +{ + if (m_inst) + return !m_inst->isRunning(); + return true; +} + +bool WorldListPage::worldListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmWorldBtn_clicked(); + return true; + default: + break; + } + return QWidget::eventFilter(ui->worldTreeView, keyEvent); +} + +bool WorldListPage::eventFilter(QObject *obj, QEvent *ev) +{ + if (ev->type() != QEvent::KeyPress) + { + return QWidget::eventFilter(obj, ev); + } + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->worldTreeView) + return worldListFilter(keyEvent); + return QWidget::eventFilter(obj, ev); +} +void WorldListPage::on_rmWorldBtn_clicked() +{ + int first, last; + auto list = ui->worldTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_worlds->stopWatching(); + m_worlds->deleteWorlds(first, last); + m_worlds->startWatching(); +} + +void WorldListPage::on_viewFolderBtn_clicked() +{ + openDirInDefaultProgram(m_worlds->dir().absolutePath(), true); +} diff --git a/application/pages/WorldListPage.h b/application/pages/WorldListPage.h new file mode 100644 index 00000000..f55f2999 --- /dev/null +++ b/application/pages/WorldListPage.h @@ -0,0 +1,69 @@ +// +// Created by robotbrain on 8/18/15. +// + +#pragma once + +#include + +#include "minecraft/OneSixInstance.h" +#include "BasePage.h" +#include +#include + +class WorldList; +namespace Ui +{ +class WorldListPage; +} + +class WorldListPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit WorldListPage(BaseInstance *inst, std::shared_ptr worlds, QString id, + QString iconName, QString displayName, QString helpPage = "", + QWidget *parent = 0); + virtual ~WorldListPage(); + + virtual QString displayName() const override + { + return m_displayName; + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon(m_iconName); + } + virtual QString id() const override + { + return m_id; + } + virtual QString helpPage() const override + { + return m_helpName; + } + virtual bool shouldDisplay() const; + + virtual void opened(); + virtual void closed(); + +protected: + bool eventFilter(QObject *obj, QEvent *ev); + bool worldListFilter(QKeyEvent *ev); + +protected: + BaseInstance *m_inst; + +private: + Ui::WorldListPage *ui; + std::shared_ptr m_worlds; + QString m_iconName; + QString m_id; + QString m_displayName; + QString m_helpName; + +private slots: + void on_rmWorldBtn_clicked(); + void on_viewFolderBtn_clicked(); +}; diff --git a/application/pages/WorldListPage.ui b/application/pages/WorldListPage.ui new file mode 100644 index 00000000..b8100acd --- /dev/null +++ b/application/pages/WorldListPage.ui @@ -0,0 +1,94 @@ + + + WorldListPage + + + + 0 + 0 + 723 + 532 + + + + Mods + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + + + -- cgit v1.2.3