NOISSUE redo new instance dialog

This commit is contained in:
Petr Mrázek
2018-03-19 02:36:12 +01:00
parent 4c7ea0f99a
commit 8e44ab2338
98 changed files with 1916 additions and 1254 deletions

View File

@ -31,8 +31,18 @@ public:
virtual bool apply() { return true; }
virtual bool shouldDisplay() const { return true; }
virtual QString helpPage() const { return QString(); }
virtual void opened() {}
virtual void closed() {}
void opened()
{
isOpened = true;
openedImpl();
}
void closed()
{
isOpened = false;
closedImpl();
}
virtual void openedImpl() {}
virtual void closedImpl() {}
virtual void setParentContainer(BasePageContainer * container)
{
m_container = container;
@ -42,6 +52,7 @@ public:
int listIndex = -1;
protected:
BasePageContainer * m_container = nullptr;
bool isOpened = false;
};
typedef std::shared_ptr<BasePage> BasePagePtr;

View File

@ -15,7 +15,7 @@
#pragma once
#include "BasePage.h"
#include "pages/BasePage.h"
#include <memory>
#include <functional>
@ -65,5 +65,3 @@ private:
QList<PageCreator> m_creators;
QString m_dialogTitle;
};
typedef std::shared_ptr<BasePageProvider> BasePageProviderPtr;

View File

@ -218,7 +218,7 @@ void PackagesPage::updateVersion()
}
}
void PackagesPage::opened()
void PackagesPage::openedImpl()
{
ENV.metadataIndex()->load(Net::Mode::Offline);
}

View File

@ -36,7 +36,7 @@ public:
QString id() const override { return "packages-global"; }
QString displayName() const override { return tr("Packages"); }
QIcon icon() const override;
void opened() override;
void openedImpl() override;
private slots:
void on_refreshIndexBtn_clicked();

View File

@ -20,7 +20,7 @@
#include "java/JavaChecker.h"
#include "BaseInstance.h"
#include <QObjectPtr.h>
#include "BasePage.h"
#include "pages/BasePage.h"
#include "JavaCommon.h"
#include "MultiMC.h"

View File

@ -35,7 +35,12 @@ void LegacyUpgradePage::runModalTask(Task *task)
void LegacyUpgradePage::on_upgradeButton_clicked()
{
std::unique_ptr<Task> task(MMC->folderProvider()->legacyUpgradeTask(m_inst));
QString newName = tr("%1 (Migrated)").arg(m_inst->name());
auto upgradeTask = new LegacyUpgradeTask(m_inst);
upgradeTask->setName(newName);
upgradeTask->setGroup(m_inst->group());
upgradeTask->setIcon(m_inst->iconKey());
std::unique_ptr<Task> task(MMC->folderProvider()->wrapInstanceTask(upgradeTask));
runModalTask(task.get());
}

View File

@ -19,7 +19,7 @@
#include "BaseInstance.h"
#include "launch/LaunchTask.h"
#include "BasePage.h"
#include "pages/BasePage.h"
#include <MultiMC.h>
namespace Ui

View File

@ -59,12 +59,12 @@ ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods,
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged );
}
void ModFolderPage::opened()
void ModFolderPage::openedImpl()
{
m_mods->startWatching();
}
void ModFolderPage::closed()
void ModFolderPage::closedImpl()
{
m_mods->stopWatching();
}

View File

@ -18,7 +18,7 @@
#include <QWidget>
#include "minecraft/MinecraftInstance.h"
#include "BasePage.h"
#include "pages/BasePage.h"
#include <MultiMC.h>
class ModList;
@ -60,8 +60,8 @@ public:
}
virtual bool shouldDisplay() const override;
virtual void opened() override;
virtual void closed() override;
virtual void openedImpl() override;
virtual void closedImpl() override;
protected:
bool eventFilter(QObject *obj, QEvent *ev) override;
bool modListFilter(QKeyEvent *ev);

View File

@ -18,7 +18,7 @@
#include <QWidget>
#include "BaseInstance.h"
#include "BasePage.h"
#include "pages/BasePage.h"
#include <MultiMC.h>
namespace Ui

View File

@ -54,11 +54,11 @@ OtherLogsPage::~OtherLogsPage()
delete ui;
}
void OtherLogsPage::opened()
void OtherLogsPage::openedImpl()
{
m_watcher->enable();
}
void OtherLogsPage::closed()
void OtherLogsPage::closedImpl()
{
m_watcher->disable();
}

View File

@ -17,7 +17,7 @@
#include <QWidget>
#include "BasePage.h"
#include "pages/BasePage.h"
#include <MultiMC.h>
#include <pathmatcher/IPathMatcher.h>
@ -52,8 +52,8 @@ public:
{
return "Minecraft-Logs";
}
void opened() override;
void closed() override;
void openedImpl() override;
void closedImpl() override;
private slots:
void populateSelectLogBox();

View File

@ -347,7 +347,7 @@ void ScreenshotsPage::on_renameBtn_clicked()
// TODO: mass renaming
}
void ScreenshotsPage::opened()
void ScreenshotsPage::openedImpl()
{
if(!m_valid)
{

View File

@ -17,7 +17,7 @@
#include <QWidget>
#include "BasePage.h"
#include "pages/BasePage.h"
#include <MultiMC.h>
class QFileSystemModel;
@ -39,7 +39,7 @@ public:
explicit ScreenshotsPage(QString path, QWidget *parent = 0);
virtual ~ScreenshotsPage();
virtual void opened() override;
virtual void openedImpl() override;
enum
{

View File

@ -19,7 +19,7 @@
#include "minecraft/MinecraftInstance.h"
#include "minecraft/ComponentList.h"
#include "BasePage.h"
#include "pages/BasePage.h"
namespace Ui
{

View File

@ -55,12 +55,12 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worl
worldChanged(QModelIndex(), QModelIndex());
}
void WorldListPage::opened()
void WorldListPage::openedImpl()
{
m_worlds->startWatching();
}
void WorldListPage::closed()
void WorldListPage::closedImpl()
{
m_worlds->stopWatching();
}

View File

@ -18,7 +18,7 @@
#include <QWidget>
#include "minecraft/MinecraftInstance.h"
#include "BasePage.h"
#include "pages/BasePage.h"
#include <MultiMC.h>
#include <LoggedProcess.h>
@ -56,8 +56,8 @@ public:
}
virtual bool shouldDisplay() const override;
virtual void opened() override;
virtual void closed() override;
virtual void openedImpl() override;
virtual void closedImpl() override;
protected:
bool eventFilter(QObject *obj, QEvent *ev) override;

View File

@ -0,0 +1,152 @@
#include "FTBPage.h"
#include "ui_FTBPage.h"
#include "MultiMC.h"
#include "FolderInstanceProvider.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/NewInstanceDialog.h"
#include "modplatform/ftb/FtbPackDownloader.h"
#include "modplatform/ftb/FtbPackInstallTask.h"
#include <FtbListModel.h>
FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
{
ui->setupUi(this);
ftbPackDownloader = new FtbPackDownloader();
connect(ftbPackDownloader, &FtbPackDownloader::ready, this, &FTBPage::ftbPackDataDownloadSuccessfully);
connect(ftbPackDownloader, &FtbPackDownloader::packFetchFailed, this, &FTBPage::ftbPackDataDownloadFailed);
filterModel = new FtbFilterModel(this);
listModel = new FtbListModel(this);
filterModel->setSourceModel(listModel);
ui->packList->setModel(filterModel);
ui->packList->setSortingEnabled(true);
ui->packList->header()->hide();
ui->packList->setIndentation(0);
filterModel->setSorting(FtbFilterModel::Sorting::ByName);
for(int i = 0; i < filterModel->getAvailableSortings().size(); i++)
{
ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i));
}
ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->getCurrentSorting()));
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
connect(ui->packList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPackSelectionChanged);
ui->modpackInfo->setOpenExternalLinks(true);
}
FTBPage::~FTBPage()
{
delete ui;
if(ftbPackDownloader)
{
ftbPackDownloader->deleteLater();
}
}
bool FTBPage::shouldDisplay() const
{
return true;
}
void FTBPage::openedImpl()
{
if(!initialized)
{
ftbPackDownloader->fetchModpacks(false);
initialized = true;
}
suggestCurrent();
}
void FTBPage::suggestCurrent()
{
if(isOpened)
{
if(!selected.broken)
{
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
}
else
{
dialog->setSuggestedPack();
}
}
}
FtbPackDownloader *FTBPage::getFtbPackDownloader()
{
return ftbPackDownloader;
}
void FTBPage::ftbPackDataDownloadSuccessfully()
{
listModel->fill(ftbPackDownloader->getModpacks());
}
void FTBPage::ftbPackDataDownloadFailed()
{
qDebug() << "Stuff went missing while grabbing FTB pack list or something...";
}
void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev)
{
ui->packVersionSelection->clear();
FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value<FtbModpack>();
ui->modpackInfo->setHtml("Pack by <b>" + selectedPack.author + "</b>" + "<br>Minecraft " + selectedPack.mcVersion + "<br>"
"<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>");
bool currentAdded = false;
for(int i = 0; i < selectedPack.oldVersions.size(); i++)
{
if(selectedPack.currentVersion == selectedPack.oldVersions.at(i))
{
currentAdded = true;
}
ui->packVersionSelection->addItem(selectedPack.oldVersions.at(i));
}
if(!currentAdded)
{
ui->packVersionSelection->addItem(selectedPack.currentVersion);
}
selected = selectedPack;
suggestCurrent();
}
void FTBPage::onVersionSelectionItemChanged(QString data)
{
if(data.isNull() || data.isEmpty())
{
selectedVersion = "";
return;
}
selectedVersion = data;
}
FtbModpack FTBPage::getSelectedModpack()
{
return selected;
}
QString FTBPage::getSelectedVersion()
{
return selectedVersion;
}
void FTBPage::onSortingSelectionChanged(QString data)
{
filterModel->setSorting(filterModel->getAvailableSortings().value(data));
}

View File

@ -0,0 +1,86 @@
/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QWidget>
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
#include "modplatform/ftb/PackHelpers.h"
namespace Ui
{
class FTBPage;
}
class FtbListModel;
class FtbFilterModel;
class FtbPackDownloader;
class NewInstanceDialog;
class FTBPage : public QWidget, public BasePage
{
Q_OBJECT
public:
explicit FTBPage(NewInstanceDialog * dialog, QWidget *parent = 0);
virtual ~FTBPage();
QString displayName() const override
{
return tr("FTB Legacy");
}
QIcon icon() const override
{
return MMC->getThemedIcon("ftb_logo");
}
QString id() const override
{
return "ftb";
}
QString helpPage() const override
{
return "FTB-platform";
}
bool shouldDisplay() const override;
void openedImpl() override;
FtbPackDownloader* getFtbPackDownloader();
FtbModpack getSelectedModpack();
QString getSelectedVersion();
private:
void suggestCurrent();
private slots:
void ftbPackDataDownloadSuccessfully();
void ftbPackDataDownloadFailed();
void onSortingSelectionChanged(QString data);
void onVersionSelectionItemChanged(QString data);
void onPackSelectionChanged(QModelIndex first, QModelIndex second);
private:
bool initialized = false;
FtbPackDownloader* ftbPackDownloader = nullptr;
FtbModpack selectedPack;
FtbModpack selected;
QString selectedVersion;
FtbListModel* listModel = nullptr;
FtbFilterModel* filterModel = nullptr;
NewInstanceDialog* dialog = nullptr;
Ui::FTBPage *ui = nullptr;
};

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FTBPage</class>
<widget class="QWidget" name="FTBPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>801</width>
<height>674</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTreeView" name="packList">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="QTextBrowser" name="modpackInfo"/>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="sortByBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="selectedVersionLabel">
<property name="text">
<string>Version selected:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2" colspan="2">
<widget class="QComboBox" name="packVersionSelection">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,125 @@
#include "ImportPage.h"
#include "ui_ImportPage.h"
#include "MultiMC.h"
#include "FolderInstanceProvider.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/ProgressDialog.h"
#include "dialogs/NewInstanceDialog.h"
#include <QFileDialog>
#include <InstanceImportTask.h>
class UrlValidator : public QValidator
{
public:
using QValidator::QValidator;
State validate(QString &in, int &pos) const
{
const QUrl url(in);
if (url.isValid() && !url.isRelative() && !url.isEmpty())
{
return Acceptable;
}
else if (QFile::exists(in))
{
return Acceptable;
}
else
{
return Intermediate;
}
}
};
ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), ui(new Ui::ImportPage), dialog(dialog)
{
ui->setupUi(this);
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
connect(ui->modpackEdit, &QLineEdit::textChanged, this, &ImportPage::updateState);
}
ImportPage::~ImportPage()
{
delete ui;
}
bool ImportPage::shouldDisplay() const
{
return true;
}
void ImportPage::openedImpl()
{
updateState();
}
void ImportPage::updateState()
{
if(!isOpened)
{
return;
}
if(ui->modpackEdit->hasAcceptableInput())
{
QString input = ui->modpackEdit->text();
auto url = QUrl::fromUserInput(input);
if(url.isLocalFile())
{
// FIXME: actually do some validation of what's inside here... this is fake AF
QFileInfo fi(input);
if(fi.exists() && fi.suffix() == "zip")
{
QFileInfo fi(url.fileName());
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
}
}
else
{
// hook, line and sinker.
QFileInfo fi(url.fileName());
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
}
}
else
{
dialog->setSuggestedPack();
}
}
void ImportPage::setUrl(const QString& url)
{
ui->modpackEdit->setText(url);
updateState();
}
void ImportPage::on_modpackBtn_clicked()
{
const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), tr("Zip (*.zip)"));
if (url.isValid())
{
if (url.isLocalFile())
{
ui->modpackEdit->setText(url.toLocalFile());
}
else
{
ui->modpackEdit->setText(url.toString());
}
}
}
QUrl ImportPage::modpackUrl() const
{
const QUrl url(ui->modpackEdit->text());
if (url.isValid() && !url.isRelative() && !url.host().isEmpty())
{
return url;
}
else
{
return QUrl::fromLocalFile(ui->modpackEdit->text());
}
}

View File

@ -0,0 +1,70 @@
/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QWidget>
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
namespace Ui
{
class ImportPage;
}
class NewInstanceDialog;
class ImportPage : public QWidget, public BasePage
{
Q_OBJECT
public:
explicit ImportPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~ImportPage();
virtual QString displayName() const override
{
return tr("Import from zip");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("viewfolder");
}
virtual QString id() const override
{
return "import";
}
virtual QString helpPage() const override
{
return "Zip-import";
}
virtual bool shouldDisplay() const override;
void setUrl(const QString & url);
void openedImpl() override;
private slots:
void on_modpackBtn_clicked();
void updateState();
private:
QUrl modpackUrl() const;
private:
Ui::ImportPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
};

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportPage</class>
<widget class="QWidget" name="ImportPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>546</width>
<height>405</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QPushButton" name="modpackBtn">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="modpackEdit">
<property name="placeholderText">
<string notr="true">http://</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="modpackLabel">
<property name="text">
<string>Local file or link to a direct download:</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,29 @@
#include "TechnicPage.h"
#include "ui_TechnicPage.h"
#include "MultiMC.h"
#include "FolderInstanceProvider.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/ProgressDialog.h"
#include "dialogs/NewInstanceDialog.h"
TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
{
ui->setupUi(this);
}
TechnicPage::~TechnicPage()
{
delete ui;
}
bool TechnicPage::shouldDisplay() const
{
return true;
}
void TechnicPage::openedImpl()
{
dialog->setSuggestedPack();
}

View File

@ -0,0 +1,61 @@
/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QWidget>
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
namespace Ui
{
class TechnicPage;
}
class NewInstanceDialog;
class TechnicPage : public QWidget, public BasePage
{
Q_OBJECT
public:
explicit TechnicPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~TechnicPage();
virtual QString displayName() const override
{
return tr("Technic");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("technic");
}
virtual QString id() const override
{
return "technic";
}
virtual QString helpPage() const override
{
return "Technic-platform";
}
virtual bool shouldDisplay() const override;
void openedImpl() override;
private:
Ui::TechnicPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
};

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TechnicPage</class>
<widget class="QWidget" name="TechnicPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>546</width>
<height>405</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>40</pointsize>
</font>
</property>
<property name="text">
<string notr="true">¯\_(ツ)_/¯ </string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,29 @@
#include "TwitchPage.h"
#include "ui_TwitchPage.h"
#include "MultiMC.h"
#include "FolderInstanceProvider.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/ProgressDialog.h"
#include "dialogs/NewInstanceDialog.h"
TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
{
ui->setupUi(this);
}
TwitchPage::~TwitchPage()
{
delete ui;
}
bool TwitchPage::shouldDisplay() const
{
return true;
}
void TwitchPage::openedImpl()
{
dialog->setSuggestedPack();
}

View File

@ -0,0 +1,61 @@
/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QWidget>
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
namespace Ui
{
class TwitchPage;
}
class NewInstanceDialog;
class TwitchPage : public QWidget, public BasePage
{
Q_OBJECT
public:
explicit TwitchPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~TwitchPage();
virtual QString displayName() const override
{
return tr("Twitch");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("twitch");
}
virtual QString id() const override
{
return "twitch";
}
virtual QString helpPage() const override
{
return "Twitch-platform";
}
virtual bool shouldDisplay() const override;
void openedImpl() override;
private:
Ui::TwitchPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
};

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TwitchPage</class>
<widget class="QWidget" name="TwitchPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>546</width>
<height>405</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>40</pointsize>
</font>
</property>
<property name="text">
<string notr="true">¯\_(ツ)_/¯ </string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,114 @@
#include "VanillaPage.h"
#include "ui_VanillaPage.h"
#include "MultiMC.h"
#include "FolderInstanceProvider.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/ProgressDialog.h"
#include <meta/Index.h>
#include <meta/VersionList.h>
#include <dialogs/NewInstanceDialog.h>
#include <Filter.h>
#include <Env.h>
#include <InstanceCreationTask.h>
VanillaPage::VanillaPage(NewInstanceDialog *dialog, QWidget *parent)
: QWidget(parent), dialog(dialog), ui(new Ui::VanillaPage)
{
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
connect(ui->versionList, &VersionSelectWidget::selectedVersionChanged, this, &VanillaPage::setSelectedVersion);
filterChanged();
connect(ui->alphaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->betaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->snapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->oldSnapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->releaseFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
}
void VanillaPage::openedImpl()
{
if(!initialized)
{
auto vlist = ENV.metadataIndex()->get("net.minecraft");
ui->versionList->initialize(vlist.get());
if(vlist->isLoaded())
{
setSelectedVersion(vlist->getRecommended());
}
else
{
vlist->load(Net::Mode::Online);
auto task = vlist->getLoadTask();
if(vlist->isLoaded())
{
setSelectedVersion(vlist->getRecommended());
}
if(task)
{
connect(task.get(), &Task::succeeded, this, &VanillaPage::versionListUpdated);
}
}
initialized = true;
}
else
{
suggestCurrent();
}
}
void VanillaPage::filterChanged()
{
QStringList out;
if(ui->alphaFilter->isChecked())
out << "(old_alpha)";
if(ui->betaFilter->isChecked())
out << "(old_beta)";
if(ui->snapshotFilter->isChecked())
out << "(snapshot)";
if(ui->oldSnapshotFilter->isChecked())
out << "(old_snapshot)";
if(ui->releaseFilter->isChecked())
out << "(release)";
auto regexp = out.join('|');
ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false));
}
VanillaPage::~VanillaPage()
{
delete ui;
}
bool VanillaPage::shouldDisplay() const
{
return true;
}
BaseVersionPtr VanillaPage::selectedVersion() const
{
return m_selectedVersion;
}
void VanillaPage::versionListUpdated()
{
if(!m_versionSetByUser)
{
auto vlist = ENV.metadataIndex()->get("net.minecraft");
setSelectedVersion(vlist->getRecommended());
}
}
void VanillaPage::suggestCurrent()
{
if(m_selectedVersion && isOpened)
{
dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion));
}
}
void VanillaPage::setSelectedVersion(BaseVersionPtr version)
{
m_selectedVersion = version;
suggestCurrent();
}

View File

@ -0,0 +1,75 @@
/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QWidget>
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
namespace Ui
{
class VanillaPage;
}
class NewInstanceDialog;
class VanillaPage : public QWidget, public BasePage
{
Q_OBJECT
public:
explicit VanillaPage(NewInstanceDialog *dialog, QWidget *parent = 0);
virtual ~VanillaPage();
virtual QString displayName() const override
{
return tr("Vanilla");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("minecraft");
}
virtual QString id() const override
{
return "vanilla";
}
virtual QString helpPage() const override
{
return "Vanilla-platform";
}
virtual bool shouldDisplay() const override;
void openedImpl() override;
BaseVersionPtr selectedVersion() const;
public slots:
void setSelectedVersion(BaseVersionPtr version);
private slots:
void versionListUpdated();
void filterChanged();
private:
void suggestCurrent();
private:
bool initialized = false;
NewInstanceDialog *dialog = nullptr;
Ui::VanillaPage *ui = nullptr;
bool m_versionSetByUser = false;
BaseVersionPtr m_selectedVersion;
};

View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VanillaPage</class>
<widget class="QWidget" name="VanillaPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>815</width>
<height>607</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string notr="true">Tab 1</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Filter</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="releaseFilter">
<property name="text">
<string>Releases</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="snapshotFilter">
<property name="text">
<string>Snapshots</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="oldSnapshotFilter">
<property name="text">
<string>Old Snapshots</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="betaFilter">
<property name="text">
<string>Betas</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="alphaFilter">
<property name="text">
<string>Alphas</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="refreshBtn">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="VersionSelectWidget" name="versionList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>VersionSelectWidget</class>
<extends>QWidget</extends>
<header>widgets/VersionSelectWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>