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 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<InstanceId> InstanceList::discoverInstances()
|
|||
|
||||
InstanceList::InstListError InstanceList::loadList()
|
||||
{
|
||||
auto existingIds = getIdMapping(m_instances);
|
||||
auto existingIds = getIdMapping(instances);
|
||||
|
||||
std::vector<std::unique_ptr<BaseInstance>> 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<std::unique_ptr<BaseInstance>>& t)
|
|||
{
|
||||
beginInsertRows(QModelIndex(), count(), static_cast<int>(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<BaseInstance*> InstanceList::getAllInstances()
|
||||
{
|
||||
QList<BaseInstance*> 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<int>(m_instances.size()); }
|
||||
int count() const { return static_cast<int>(instances.size()); }
|
||||
|
||||
InstListError loadList();
|
||||
void saveNow();
|
||||
|
||||
QList<BaseInstance*> 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<std::unique_ptr<BaseInstance>> m_instances;
|
||||
std::vector<std::unique_ptr<BaseInstance>> instances;
|
||||
// id -> refs
|
||||
QMap<QString, int> m_groupNameCache;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@
|
|||
|
||||
MultiWorldList::MultiWorldList(const QList<QString>& dirs, QList<BaseInstance*> 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) {
|
||||
|
|
|
|||
|
|
@ -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<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
|
||||
{
|
||||
// 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) {
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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<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)
|
||||
{
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue