mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
start work on ui
This commit is contained in:
parent
c295055279
commit
4d1141f274
6 changed files with 78 additions and 28 deletions
|
|
@ -138,7 +138,7 @@ QMimeData* InstanceList::mimeData(const QModelIndexList& indexes) const
|
||||||
QStringList InstanceList::getLinkedInstancesById(const QString& id) const
|
QStringList InstanceList::getLinkedInstancesById(const QString& id) const
|
||||||
{
|
{
|
||||||
QStringList linkedInstances;
|
QStringList linkedInstances;
|
||||||
for (auto& inst : m_instances) {
|
for (auto& inst : instances) {
|
||||||
if (inst->isLinkedToInstanceId(id))
|
if (inst->isLinkedToInstanceId(id))
|
||||||
linkedInstances.append(inst->id());
|
linkedInstances.append(inst->id());
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +156,7 @@ QModelIndex InstanceList::index(int row, int column, const QModelIndex& parent)
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
if (row < 0 || row >= count())
|
if (row < 0 || row >= count())
|
||||||
return QModelIndex();
|
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
|
QVariant InstanceList::data(const QModelIndex& index, int role) const
|
||||||
|
|
@ -279,7 +279,7 @@ void InstanceList::deleteGroup(const GroupId& name)
|
||||||
|
|
||||||
bool removed = false;
|
bool removed = false;
|
||||||
qDebug() << "Delete group" << name;
|
qDebug() << "Delete group" << name;
|
||||||
for (auto& instance : m_instances) {
|
for (auto& instance : instances) {
|
||||||
const QString& instID = instance->id();
|
const QString& instID = instance->id();
|
||||||
const QString instGroupName = getInstanceGroup(instID);
|
const QString instGroupName = getInstanceGroup(instID);
|
||||||
if (instGroupName == name) {
|
if (instGroupName == name) {
|
||||||
|
|
@ -303,7 +303,7 @@ void InstanceList::renameGroup(const QString& src, const QString& dst)
|
||||||
|
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
qDebug() << "Rename group" << src << "to" << dst;
|
qDebug() << "Rename group" << src << "to" << dst;
|
||||||
for (auto& instance : m_instances) {
|
for (auto& instance : instances) {
|
||||||
const QString& instID = instance->id();
|
const QString& instID = instance->id();
|
||||||
const QString instGroupName = getInstanceGroup(instID);
|
const QString instGroupName = getInstanceGroup(instID);
|
||||||
if (instGroupName == src) {
|
if (instGroupName == src) {
|
||||||
|
|
@ -497,7 +497,7 @@ QList<InstanceId> InstanceList::discoverInstances()
|
||||||
|
|
||||||
InstanceList::InstListError InstanceList::loadList()
|
InstanceList::InstListError InstanceList::loadList()
|
||||||
{
|
{
|
||||||
auto existingIds = getIdMapping(m_instances);
|
auto existingIds = getIdMapping(instances);
|
||||||
|
|
||||||
std::vector<std::unique_ptr<BaseInstance>> newList;
|
std::vector<std::unique_ptr<BaseInstance>> newList;
|
||||||
|
|
||||||
|
|
@ -525,7 +525,7 @@ InstanceList::InstListError InstanceList::loadList()
|
||||||
int currentItem = -1;
|
int currentItem = -1;
|
||||||
auto removeNow = [this, &front_bookmark, &back_bookmark, ¤tItem]() {
|
auto removeNow = [this, &front_bookmark, &back_bookmark, ¤tItem]() {
|
||||||
beginRemoveRows(QModelIndex(), front_bookmark, back_bookmark);
|
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();
|
endRemoveRows();
|
||||||
front_bookmark = -1;
|
front_bookmark = -1;
|
||||||
back_bookmark = currentItem;
|
back_bookmark = currentItem;
|
||||||
|
|
@ -560,14 +560,14 @@ InstanceList::InstListError InstanceList::loadList()
|
||||||
void InstanceList::updateTotalPlayTime()
|
void InstanceList::updateTotalPlayTime()
|
||||||
{
|
{
|
||||||
totalPlayTime = 0;
|
totalPlayTime = 0;
|
||||||
for (const auto& itr : m_instances) {
|
for (const auto& itr : instances) {
|
||||||
totalPlayTime += itr->totalTimePlayed();
|
totalPlayTime += itr->totalTimePlayed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceList::saveNow()
|
void InstanceList::saveNow()
|
||||||
{
|
{
|
||||||
for (auto& item : m_instances) {
|
for (auto& item : instances) {
|
||||||
item->saveNow();
|
item->saveNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -576,8 +576,8 @@ void InstanceList::add(std::vector<std::unique_ptr<BaseInstance>>& t)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), count(), static_cast<int>(count() + t.size() - 1));
|
beginInsertRows(QModelIndex(), count(), static_cast<int>(count() + t.size() - 1));
|
||||||
for (auto& ptr : t) {
|
for (auto& ptr : t) {
|
||||||
m_instances.push_back(std::move(ptr));
|
instances.push_back(std::move(ptr));
|
||||||
connect(m_instances.back().get(), &BaseInstance::propertiesChanged, this, &InstanceList::propertiesChanged);
|
connect(instances.back().get(), &BaseInstance::propertiesChanged, this, &InstanceList::propertiesChanged);
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
@ -607,11 +607,22 @@ void InstanceList::providerUpdated()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<BaseInstance*> InstanceList::getAllInstances()
|
||||||
|
{
|
||||||
|
QList<BaseInstance*> instanceList;
|
||||||
|
|
||||||
|
for (auto& inst : instances) {
|
||||||
|
instanceList.append(inst.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
return instanceList;
|
||||||
|
}
|
||||||
|
|
||||||
BaseInstance* InstanceList::getInstanceById(QString instId) const
|
BaseInstance* InstanceList::getInstanceById(QString instId) const
|
||||||
{
|
{
|
||||||
if (instId.isEmpty())
|
if (instId.isEmpty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
for (auto& inst : m_instances) {
|
for (auto& inst : instances) {
|
||||||
if (inst->id() == instId) {
|
if (inst->id() == instId) {
|
||||||
return inst.get();
|
return inst.get();
|
||||||
}
|
}
|
||||||
|
|
@ -624,7 +635,7 @@ BaseInstance* InstanceList::getInstanceByManagedName(const QString& managed_name
|
||||||
if (managed_name.isEmpty())
|
if (managed_name.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
for (auto& instance : m_instances) {
|
for (auto& instance : instances) {
|
||||||
if (instance->getManagedPackName() == managed_name)
|
if (instance->getManagedPackName() == managed_name)
|
||||||
return instance.get();
|
return instance.get();
|
||||||
}
|
}
|
||||||
|
|
@ -641,7 +652,7 @@ int InstanceList::getInstIndex(BaseInstance* inst) const
|
||||||
{
|
{
|
||||||
int count = this->count();
|
int count = this->count();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (inst == m_instances.at(i).get()) {
|
if (inst == instances.at(i).get()) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -882,7 +893,7 @@ void InstanceList::on_InstFolderChanged([[maybe_unused]] const Setting& setting,
|
||||||
m_instDir = newInstDir;
|
m_instDir = newInstDir;
|
||||||
m_groupsLoaded = false;
|
m_groupsLoaded = false;
|
||||||
beginRemoveRows(QModelIndex(), 0, count());
|
beginRemoveRows(QModelIndex(), 0, count());
|
||||||
m_instances.erase(m_instances.begin(), m_instances.end());
|
instances.erase(instances.begin(), instances.end());
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
emit instancesChanged();
|
emit instancesChanged();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,13 +96,14 @@ class InstanceList : public QAbstractListModel {
|
||||||
*/
|
*/
|
||||||
enum InstListError { NoError = 0, UnknownError };
|
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<int>(m_instances.size()); }
|
int count() const { return static_cast<int>(instances.size()); }
|
||||||
|
|
||||||
InstListError loadList();
|
InstListError loadList();
|
||||||
void saveNow();
|
void saveNow();
|
||||||
|
|
||||||
|
QList<BaseInstance*> getAllInstances();
|
||||||
/* O(n) */
|
/* O(n) */
|
||||||
BaseInstance* getInstanceById(QString id) const;
|
BaseInstance* getInstanceById(QString id) const;
|
||||||
/* O(n) */
|
/* O(n) */
|
||||||
|
|
@ -192,7 +193,7 @@ class InstanceList : public QAbstractListModel {
|
||||||
int m_watchLevel = 0;
|
int m_watchLevel = 0;
|
||||||
int totalPlayTime = 0;
|
int totalPlayTime = 0;
|
||||||
bool m_dirty = false;
|
bool m_dirty = false;
|
||||||
std::vector<std::unique_ptr<BaseInstance>> m_instances;
|
std::vector<std::unique_ptr<BaseInstance>> instances;
|
||||||
// id -> refs
|
// id -> refs
|
||||||
QMap<QString, int> m_groupNameCache;
|
QMap<QString, int> m_groupNameCache;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@
|
||||||
|
|
||||||
MultiWorldList::MultiWorldList(const QList<QString>& dirs, QList<BaseInstance*> instances) : QAbstractListModel(), m_instances(instances)
|
MultiWorldList::MultiWorldList(const QList<QString>& dirs, QList<BaseInstance*> instances) : QAbstractListModel(), m_instances(instances)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < dirs.length(); i++) {
|
for (QString dir : dirs) {
|
||||||
m_dirs[i] = dirs[i];
|
m_dirs.append(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (QDir dir : m_dirs) {
|
for (QDir dir : m_dirs) {
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@
|
||||||
#include "InstanceWindow.h"
|
#include "InstanceWindow.h"
|
||||||
|
|
||||||
#include "ui/GuiUtil.h"
|
#include "ui/GuiUtil.h"
|
||||||
|
#include "ui/MultiWorldListPage.h"
|
||||||
#include "ui/ViewLogWindow.h"
|
#include "ui/ViewLogWindow.h"
|
||||||
#include "ui/dialogs/AboutDialog.h"
|
#include "ui/dialogs/AboutDialog.h"
|
||||||
#include "ui/dialogs/CopyInstanceDialog.h"
|
#include "ui/dialogs/CopyInstanceDialog.h"
|
||||||
|
|
@ -113,6 +114,7 @@
|
||||||
#include "ui/themes/ThemeManager.h"
|
#include "ui/themes/ThemeManager.h"
|
||||||
#include "ui/widgets/LabeledToolButton.h"
|
#include "ui/widgets/LabeledToolButton.h"
|
||||||
|
|
||||||
|
#include "minecraft/MultiWorldList.h"
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
#include "minecraft/VersionFile.h"
|
#include "minecraft/VersionFile.h"
|
||||||
#include "minecraft/WorldList.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);
|
connect(view, &InstanceView::groupStateChanged, APPLICATION->instances(), &InstanceList::on_GroupStateChanged);
|
||||||
ui->horizontalLayout->addWidget(view);
|
ui->horizontalLayout->addWidget(view);
|
||||||
}
|
}
|
||||||
|
// Create the all worlds widget
|
||||||
|
{
|
||||||
|
QList<BaseInstance*> allInstances = APPLICATION->instances()->getAllInstances();
|
||||||
|
qDebug() << "iy initially" << allInstances.length();
|
||||||
|
QList<QString> dirs;
|
||||||
|
for (BaseInstance* inst : allInstances) {
|
||||||
|
dirs.append(dynamic_cast<MinecraftInstance*>(inst)->worldDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
allWorlds = new MultiWorldList(dirs, allInstances);
|
||||||
|
allWorlds->update();
|
||||||
|
allWorldsPage = new MultiWorldListPage(dynamic_cast<MinecraftInstance*>(allInstances[0]), allWorlds); //shouldnt be only one instance iy
|
||||||
|
|
||||||
|
ui->horizontalLayout->addWidget(allWorldsPage);
|
||||||
|
}
|
||||||
|
|
||||||
// The cat background
|
// The cat background
|
||||||
{
|
{
|
||||||
// set the cat action priority here so you can still see the action in qt designer
|
// 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<QString, QString>& e
|
||||||
if (creationTask) {
|
if (creationTask) {
|
||||||
instanceFromInstanceTask(creationTask);
|
instanceFromInstanceTask(creationTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//clean this up iy - fix ghosting issue and only joining one world despite which one you click
|
||||||
|
|
||||||
|
QList<BaseInstance*> allInstances = APPLICATION->instances()->getAllInstances();
|
||||||
|
qDebug() << "iy finally " << allInstances.length();
|
||||||
|
QList<QString> dirs;
|
||||||
|
for (BaseInstance* inst : allInstances) {
|
||||||
|
dirs.append(dynamic_cast<MinecraftInstance*>(inst)->worldDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
allWorlds = new MultiWorldList(dirs, allInstances);
|
||||||
|
allWorlds->update();
|
||||||
|
auto newAllWorldsPage = new MultiWorldListPage(dynamic_cast<MinecraftInstance*>(allInstances[0]), allWorlds); //shouldnt be only one instance iy
|
||||||
|
ui->horizontalLayout->replaceWidget(allWorldsPage, newAllWorldsPage);
|
||||||
|
allWorldsPage = newAllWorldsPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionAddInstance_triggered()
|
void MainWindow::on_actionAddInstance_triggered()
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ class QLabel;
|
||||||
class MinecraftLauncher;
|
class MinecraftLauncher;
|
||||||
class BaseProfilerFactory;
|
class BaseProfilerFactory;
|
||||||
class InstanceView;
|
class InstanceView;
|
||||||
|
class MultiWorldList;
|
||||||
|
class MultiWorldListPage;
|
||||||
class KonamiCode;
|
class KonamiCode;
|
||||||
class InstanceTask;
|
class InstanceTask;
|
||||||
class LabeledToolButton;
|
class LabeledToolButton;
|
||||||
|
|
@ -236,6 +238,7 @@ class MainWindow : public QMainWindow {
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
// these are managed by Qt's memory management model!
|
// these are managed by Qt's memory management model!
|
||||||
InstanceView* view = nullptr;
|
InstanceView* view = nullptr;
|
||||||
|
MultiWorldListPage* allWorldsPage = nullptr;
|
||||||
InstanceProxyModel* proxymodel = nullptr;
|
InstanceProxyModel* proxymodel = nullptr;
|
||||||
QToolButton* newsLabel = nullptr;
|
QToolButton* newsLabel = nullptr;
|
||||||
QLabel* m_statusLeft = nullptr;
|
QLabel* m_statusLeft = nullptr;
|
||||||
|
|
@ -244,6 +247,7 @@ class MainWindow : public QMainWindow {
|
||||||
LabeledToolButton* renameButton = nullptr;
|
LabeledToolButton* renameButton = nullptr;
|
||||||
QToolButton* helpMenuButton = nullptr;
|
QToolButton* helpMenuButton = nullptr;
|
||||||
KonamiCode* secretEventFilter = nullptr;
|
KonamiCode* secretEventFilter = nullptr;
|
||||||
|
MultiWorldList* allWorlds = nullptr;
|
||||||
|
|
||||||
std::shared_ptr<Setting> instanceToolbarSetting = nullptr;
|
std::shared_ptr<Setting> instanceToolbarSetting = nullptr;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
: QMainWindow(parent), m_inst(inst), ui(new Ui::MultiWorldListPage), m_worlds(worlds)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
@ -117,9 +117,9 @@ void MultiWorldListPage::openedImpl()
|
||||||
{
|
{
|
||||||
m_worlds->startWatching();
|
m_worlds->startWatching();
|
||||||
|
|
||||||
if (!m_inst || !m_inst->traits().contains("feature:is_quick_play_singleplayer")) {
|
// if (!m_inst || !m_inst->traits().contains("feature:is_quick_play_singleplayer")) { //get rid of this??? iy
|
||||||
ui->toolBar->removeAction(ui->actionJoin);
|
// ui->toolBar->removeAction(ui->actionJoin);
|
||||||
}
|
// }
|
||||||
|
|
||||||
auto const setting_name = QString("WideBarVisibility_%1").arg(id());
|
auto const setting_name = QString("WideBarVisibility_%1").arg(id());
|
||||||
m_wide_bar_setting = APPLICATION->settings()->getOrRegisterSetting(setting_name);
|
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();
|
bool hasIcon = !index.data(MultiWorldList::IconFileRole).isNull();
|
||||||
ui->actionReset_Icon->setEnabled(enable && hasIcon);
|
ui->actionReset_Icon->setEnabled(enable && hasIcon);
|
||||||
|
|
||||||
auto supportsJoin = m_inst && m_inst->traits().contains("feature:is_quick_play_singleplayer");
|
// 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(enable && supportsJoin);
|
||||||
|
ui->actionJoin->setEnabled(true);
|
||||||
|
|
||||||
if (!supportsJoin) {
|
// if (!supportsJoin) {
|
||||||
ui->toolBar->removeAction(ui->actionJoin);
|
// ui->toolBar->removeAction(ui->actionJoin);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiWorldListPage::on_actionAdd_triggered()
|
void MultiWorldListPage::on_actionAdd_triggered()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue