diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/LegacyModEditDialog.cpp | 60 | ||||
-rw-r--r-- | gui/LegacyModEditDialog.h | 1 | ||||
-rw-r--r-- | gui/LegacyModEditDialog.ui | 4 | ||||
-rw-r--r-- | gui/mainwindow.cpp | 179 | ||||
-rw-r--r-- | gui/mainwindow.h | 17 | ||||
-rw-r--r-- | gui/mainwindow.ui | 68 |
6 files changed, 214 insertions, 115 deletions
diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp index 218e0979..ea5aa941 100644 --- a/gui/LegacyModEditDialog.cpp +++ b/gui/LegacyModEditDialog.cpp @@ -35,18 +35,29 @@ LegacyModEditDialog::LegacyModEditDialog( LegacyInstance* inst, QWidget* parent m_mods = m_inst->loaderModList(); m_coremods = m_inst->coreModList(); m_jarmods = m_inst->jarModList(); + m_texturepacks = m_inst->texturePackList(); ui->jarModsTreeView->setModel(m_jarmods.data()); ui->coreModsTreeView->setModel(m_coremods.data()); ui->mlModTreeView->setModel(m_mods.data()); + ui->texPackTreeView->setModel(m_texturepacks.data()); ui->jarModsTreeView->installEventFilter( this ); ui->coreModsTreeView->installEventFilter( this ); ui->mlModTreeView->installEventFilter( this ); + ui->texPackTreeView->installEventFilter( this ); + m_mods->startWatching(); + m_coremods->startWatching(); + m_jarmods->startWatching(); + m_texturepacks->startWatching(); } LegacyModEditDialog::~LegacyModEditDialog() { + m_mods->stopWatching(); + m_coremods->stopWatching(); + m_jarmods->stopWatching(); + m_texturepacks->stopWatching(); delete ui; } @@ -116,6 +127,22 @@ bool LegacyModEditDialog::loaderListFilter ( QKeyEvent* keyEvent ) return QDialog::eventFilter( ui->mlModTreeView, keyEvent ); } +bool LegacyModEditDialog::texturePackListFilter ( QKeyEvent* keyEvent ) +{ + switch(keyEvent->key()) + { + case Qt::Key_Delete: + on_rmTexPackBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addTexPackBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter( ui->texPackTreeView, keyEvent ); +} + bool LegacyModEditDialog::eventFilter ( QObject* obj, QEvent* ev ) { @@ -130,6 +157,8 @@ bool LegacyModEditDialog::eventFilter ( QObject* obj, QEvent* ev ) return coreListFilter(keyEvent); if(obj == ui->mlModTreeView) return loaderListFilter(keyEvent); + if(obj == ui->texPackTreeView) + return loaderListFilter(keyEvent); return QDialog::eventFilter( obj, ev ); } @@ -139,7 +168,9 @@ void LegacyModEditDialog::on_addCoreBtn_clicked() QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Core Mods"); for(auto filename:fileNames) { + m_coremods->stopWatching(); m_coremods->installMod(QFileInfo(filename)); + m_coremods->startWatching(); } } void LegacyModEditDialog::on_addForgeBtn_clicked() @@ -151,7 +182,9 @@ void LegacyModEditDialog::on_addJarBtn_clicked() QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Jar Mods"); for(auto filename:fileNames) { + m_jarmods->stopWatching(); m_jarmods->installMod(QFileInfo(filename)); + m_jarmods->startWatching(); } } void LegacyModEditDialog::on_addModBtn_clicked() @@ -159,12 +192,20 @@ void LegacyModEditDialog::on_addModBtn_clicked() QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Loader Mods"); for(auto filename:fileNames) { + m_mods->stopWatching(); m_mods->installMod(QFileInfo(filename)); + m_mods->startWatching(); } } void LegacyModEditDialog::on_addTexPackBtn_clicked() { - + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Texture Packs"); + for(auto filename:fileNames) + { + m_texturepacks->stopWatching(); + m_texturepacks->installMod(QFileInfo(filename)); + m_texturepacks->startWatching(); + } } bool lastfirst (QModelIndexList & list, int & first, int & last) @@ -209,7 +250,9 @@ void LegacyModEditDialog::on_rmCoreBtn_clicked() if(!lastfirst(list, first, last)) return; + m_coremods->stopWatching(); m_coremods->deleteMods(first, last); + m_coremods->startWatching(); } void LegacyModEditDialog::on_rmJarBtn_clicked() { @@ -218,7 +261,9 @@ void LegacyModEditDialog::on_rmJarBtn_clicked() if(!lastfirst(list, first, last)) return; + m_jarmods->stopWatching(); m_jarmods->deleteMods(first, last); + m_jarmods->startWatching(); } void LegacyModEditDialog::on_rmModBtn_clicked() { @@ -227,11 +272,20 @@ void LegacyModEditDialog::on_rmModBtn_clicked() if(!lastfirst(list, first, last)) return; + m_mods->stopWatching(); m_mods->deleteMods(first, last); + m_mods->startWatching(); } void LegacyModEditDialog::on_rmTexPackBtn_clicked() { - + int first, last; + auto list = ui->texPackTreeView->selectionModel()->selectedRows(); + + if(!lastfirst(list, first, last)) + return; + m_texturepacks->stopWatching(); + m_texturepacks->deleteMods(first, last); + m_texturepacks->startWatching(); } void LegacyModEditDialog::on_viewCoreBtn_clicked() { @@ -243,7 +297,7 @@ void LegacyModEditDialog::on_viewModBtn_clicked() } void LegacyModEditDialog::on_viewTexPackBtn_clicked() { - //openDirInDefaultProgram(m_inst->mlModsDir(), true); + openDirInDefaultProgram(m_inst->texturePackDir(), true); } diff --git a/gui/LegacyModEditDialog.h b/gui/LegacyModEditDialog.h index 536d402a..bc9ebac0 100644 --- a/gui/LegacyModEditDialog.h +++ b/gui/LegacyModEditDialog.h @@ -56,6 +56,7 @@ protected: bool jarListFilter( QKeyEvent* ev ); bool coreListFilter( QKeyEvent* ev ); bool loaderListFilter( QKeyEvent* ev ); + bool texturePackListFilter( QKeyEvent* ev ); private: Ui::LegacyModEditDialog *ui; QSharedPointer<ModList> m_mods; diff --git a/gui/LegacyModEditDialog.ui b/gui/LegacyModEditDialog.ui index c219e7c2..bff2bfbe 100644 --- a/gui/LegacyModEditDialog.ui +++ b/gui/LegacyModEditDialog.ui @@ -17,7 +17,7 @@ <item> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> - <number>0</number> + <number>1</number> </property> <widget class="QWidget" name="jarTab"> <attribute name="title"> @@ -261,7 +261,7 @@ <item> <widget class="QDialogButtonBox" name="buttonBox"> <property name="standardButtons"> - <set>QDialogButtonBox::Close|QDialogButtonBox::Reset</set> + <set>QDialogButtonBox::Close</set> </property> </widget> </item> diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 97e60658..b562769e 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -28,6 +28,8 @@ #include <QUrl> #include <QDir> #include <QFileInfo> +#include <QLabel> +#include <QToolButton> #include "osutils.h" #include "userutils.h" @@ -58,6 +60,8 @@ #include "logic/OneSixUpdate.h" #include "logic/lists/MinecraftVersionList.h" #include "logic/lists/LwjglVersionList.h" +#include <logic/IconListModel.h> +#include <logic/LegacyInstance.h> #include "instancemodel.h" #include "instancedelegate.h" @@ -69,10 +73,13 @@ MainWindow::MainWindow ( QWidget *parent ) : instList ( globalSettings->get ( "InstanceDir" ).toString() ) { ui->setupUi ( this ); - + + // Set the selected instance to null + m_selectedInstance = nullptr; // Set active instance to null. - m_activeInst = NULL; - + m_activeInst = nullptr; + // the rename label is inside the rename tool button + renameLabel = nullptr; // Create the widget view = new KCategorizedView ( ui->centralWidget ); drawer = new KCategoryDrawer ( view ); @@ -118,12 +125,14 @@ MainWindow::MainWindow ( QWidget *parent ) : // restoreGeometry(settings->getConfig().value("MainWindowGeometry", saveGeometry()).toByteArray()); // restoreState(settings->getConfig().value("MainWindowState", saveState()).toByteArray()); view->setModel ( proxymodel ); - connect(view, SIGNAL(doubleClicked(const QModelIndex &)), - this, SLOT(instanceActivated(const QModelIndex &))); - - connect(view, SIGNAL(clicked(const QModelIndex &)), - this, SLOT(instanceChanged(const QModelIndex &))); - + connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(instanceActivated(const QModelIndex &))); + auto selectionmodel = view->selectionModel(); + connect( + selectionmodel, + SIGNAL(currentChanged(const QModelIndex &,const QModelIndex &)), + this, + SLOT(instanceChanged(const QModelIndex &,const QModelIndex &)) + ); // Load the instances. FIXME: this is not the place I'd say. instList.loadList(); @@ -242,31 +251,32 @@ void MainWindow::on_actionAddInstance_triggered() void MainWindow::on_actionChangeInstIcon_triggered() { - BaseInstance* inst = selectedInstance(); - if(!inst) + if(!m_selectedInstance) return; IconPickerDialog dlg(this); - dlg.exec(selectedInstance()->iconKey()); + dlg.exec(m_selectedInstance->iconKey()); if(dlg.result() == QDialog::Accepted) { - selectedInstance()->setIconKey(dlg.selectedIconKey); + m_selectedInstance->setIconKey(dlg.selectedIconKey); + IconList * iconListModel = IconList::instance(); + auto ico =iconListModel->getIcon(dlg.selectedIconKey); + ui->actionChangeInstIcon->setIcon(ico); } } void MainWindow::on_actionChangeInstGroup_triggered() { - BaseInstance* inst = selectedInstance(); - if(!inst) + if(!m_selectedInstance) return; bool ok = false; - QString name ( inst->group() ); + QString name ( m_selectedInstance->group() ); name = QInputDialog::getText ( this, tr ( "Group name" ), tr ( "Enter a new group name." ), QLineEdit::Normal, name, &ok ); if(ok) - inst->setGroup(name); + m_selectedInstance->setGroup(name); } @@ -286,6 +296,16 @@ void MainWindow::on_actionViewCentralModsFolder_triggered() openDirInDefaultProgram ( globalSettings->get ( "CentralModsDir" ).toString() , true); } +void MainWindow::on_actionConfig_Folder_triggered() +{ + if(m_selectedInstance) + { + QString str = m_selectedInstance->instanceConfigFolder(); + openDirInDefaultProgram ( QDir(str).absolutePath() ); + } +} + + void MainWindow::on_actionCheckUpdate_triggered() { @@ -322,14 +342,13 @@ void MainWindow::on_mainToolBar_visibilityChanged ( bool ) void MainWindow::on_actionDeleteInstance_triggered() { - BaseInstance* inst = selectedInstance(); - if (inst) + if (m_selectedInstance) { int response = QMessageBox::question(this, "CAREFUL", - QString("This is permanent! Are you sure?\nAbout to delete: ") + inst->name()); + QString("This is permanent! Are you sure?\nAbout to delete: ") + m_selectedInstance->name()); if (response == QMessageBox::Yes) { - QDir(inst->instanceRoot()).removeRecursively(); + QDir(m_selectedInstance->instanceRoot()).removeRecursively(); instList.loadList(); } } @@ -337,38 +356,38 @@ void MainWindow::on_actionDeleteInstance_triggered() void MainWindow::on_actionRenameInstance_triggered() { - BaseInstance* inst = selectedInstance(); - if(inst) + if(m_selectedInstance) { bool ok = false; - QString name ( inst->name() ); + QString name ( m_selectedInstance->name() ); name = QInputDialog::getText ( this, tr ( "Instance name" ), tr ( "Enter a new instance name." ), QLineEdit::Normal, name, &ok ); if (name.length() > 0) { if(ok && name.length() && name.length() <= 25) - inst->setName(name); + m_selectedInstance->setName(name); + //ui->actionRenameInstance->setText(name); + setRenameText(name); } + } } void MainWindow::on_actionViewSelectedInstFolder_triggered() { - BaseInstance* inst = selectedInstance(); - if(inst) + if(m_selectedInstance) { - QString str = inst->instanceRoot(); + QString str = m_selectedInstance->instanceRoot(); openDirInDefaultProgram ( QDir(str).absolutePath() ); } } void MainWindow::on_actionEditInstMods_triggered() { - BaseInstance* inst = selectedInstance(); - if (inst) + if (m_selectedInstance) { - auto dialog = inst->createModEditDialog(this); + auto dialog = m_selectedInstance->createModEditDialog(this); if(dialog) dialog->exec(); dialog->deleteLater(); @@ -394,30 +413,9 @@ void MainWindow::on_instanceView_customContextMenuRequested ( const QPoint &pos instContextMenu->exec ( view->mapToGlobal ( pos ) ); } -BaseInstance* MainWindow::selectedInstance() -{ - QAbstractItemView * iv = view; - auto smodel = iv->selectionModel(); - QModelIndex mindex; - if(smodel->hasSelection()) - { - auto rows = smodel->selectedRows(); - mindex = rows.at(0); - } - - if(mindex.isValid()) - { - return (BaseInstance *) mindex.data(InstanceModel::InstancePointerRole).value<void *>(); - } - else - return nullptr; -} - - void MainWindow::on_actionLaunchInstance_triggered() { - BaseInstance* inst = selectedInstance(); - if(inst) + if(m_selectedInstance) { doLogin(); } @@ -425,7 +423,7 @@ void MainWindow::on_actionLaunchInstance_triggered() void MainWindow::doLogin(const QString& errorMsg) { - if (!selectedInstance()) + if (!m_selectedInstance) return; LoginDialog* loginDlg = new LoginDialog(this, errorMsg); @@ -438,7 +436,7 @@ void MainWindow::doLogin(const QString& errorMsg) LoginTask* loginTask = new LoginTask(uInfo, tDialog); connect(loginTask, SIGNAL(succeeded()),SLOT(onLoginComplete()), Qt::QueuedConnection); connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection); - m_activeInst = selectedInstance(); + m_activeInst = m_selectedInstance; tDialog->exec(loginTask); } } @@ -534,27 +532,24 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() if (view->selectionModel()->selectedIndexes().count() < 1) return; - BaseInstance *inst = selectedInstance(); - - VersionSelectDialog vselect(inst->versionList(), this); + VersionSelectDialog vselect(m_selectedInstance->versionList(), this); if (vselect.exec() && vselect.selectedVersion()) { - inst->setIntendedVersionId(vselect.selectedVersion()->descriptor); + m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor); } } void MainWindow::on_actionChangeInstLWJGLVersion_triggered() { - BaseInstance *inst = selectedInstance(); - - if (!inst) + if (!m_selectedInstance) return; LWJGLSelectDialog lselect(this); lselect.exec(); if (lselect.result() == QDialog::Accepted) { - + LegacyInstance * linst = (LegacyInstance *) m_selectedInstance; + linst->setLWJGLVersion(lselect.selectedVersion()); } } @@ -563,14 +558,60 @@ void MainWindow::on_actionInstanceSettings_triggered() if (view->selectionModel()->selectedIndexes().count() < 1) return; - BaseInstance *inst = selectedInstance(); - SettingsObject *s; - s = &inst->settings(); - InstanceSettings settings(s, this); + InstanceSettings settings(&m_selectedInstance->settings(), this); settings.setWindowTitle(QString("Instance settings")); settings.exec(); } -void MainWindow::instanceChanged(QModelIndex idx) { - ui->instanceToolBar->setEnabled(idx.isValid()); +void MainWindow::setRenameText ( QString text ) +{ + ui->actionRenameInstance->setText(text); + // FIXME: too much bullshit. + /* + QToolButton * toolbtn = (QToolButton *) ui->instanceToolBar->widgetForAction(ui->actionRenameInstance); + QLayout *layout = toolbtn->layout(); + if(!layout) + { + layout = new QHBoxLayout(); + renameLabel = new QLabel(); + renameLabel->setWordWrap(true); + renameLabel->setAlignment(Qt::AlignCenter); + layout->addWidget(renameLabel); + toolbtn->setText(" "); + toolbtn->setLayout(layout); + toolbtn->setMinimumWidth(120); + toolbtn->setMinimumHeight(renameLabel->minsize().height()); + } + if(renameLabel) + renameLabel->setText(text); + */ +} + + +void MainWindow::instanceChanged( const QModelIndex& current, const QModelIndex& previous ) +{ + QString iconKey = "infinity"; + + if(current.isValid() && nullptr != (m_selectedInstance = (BaseInstance *) current.data(InstanceModel::InstancePointerRole).value<void *>())) + { + ui->instanceToolBar->setEnabled(true); + iconKey = m_selectedInstance->iconKey(); + //ui->actionRenameInstance->setText(m_selectedInstance->name()); + setRenameText(m_selectedInstance->name()); + ui->actionChangeInstLWJGLVersion->setEnabled(m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); + ui->actionEditInstMods->setEnabled(m_selectedInstance->menuActionEnabled("actionEditInstMods")); + statusBar()->clearMessage(); + statusBar()->showMessage(m_selectedInstance->getStatusbarDescription()); + } + else + { + statusBar()->clearMessage(); + ui->instanceToolBar->setEnabled(false); + //ui->actionRenameInstance->setText("Rename Instance"); + setRenameText("Rename Instance"); + } + + IconList * iconListModel = IconList::instance(); + auto ico =iconListModel->getIcon(iconKey); + ui->actionChangeInstIcon->setIcon(ico); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 79716e5e..597cc750 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -22,6 +22,7 @@ #include "logic/tasks/LoginTask.h" #include "logic/BaseInstance.h" +class QLabel; class InstanceModel; class InstanceProxyModel; class KCategorizedView; @@ -39,11 +40,6 @@ class MainWindow : public QMainWindow { Q_OBJECT - /*! - * The currently selected instance. - */ - Q_PROPERTY(BaseInstance* selectedInstance READ selectedInstance STORED false) - public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); @@ -54,8 +50,6 @@ public: void openWebPage(QUrl url); - BaseInstance *selectedInstance(); - private slots: void on_actionAbout_triggered(); @@ -67,6 +61,8 @@ private slots: void on_actionViewInstanceFolder_triggered(); + void on_actionConfig_Folder_triggered(); + void on_actionViewSelectedInstFolder_triggered(); void on_actionRefresh_triggered(); @@ -116,7 +112,7 @@ private slots: public slots: void instanceActivated ( QModelIndex ); - void instanceChanged ( QModelIndex ); + void instanceChanged (const QModelIndex & current,const QModelIndex & previous); void startTask(Task *task); @@ -124,7 +120,7 @@ public slots: protected: bool eventFilter(QObject *obj, QEvent *ev); - + void setRenameText(QString text); private: Ui::MainWindow *ui; KCategoryDrawer * drawer; @@ -135,6 +131,9 @@ private: MinecraftProcess *proc; ConsoleWindow *console; OneSixAssets *assets_downloader; + QLabel * renameLabel; + + BaseInstance *m_selectedInstance; // A pointer to the instance we are actively doing stuff with. // This is set when the user launches an instance and is used to refer to that diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 893062a5..60e0f70b 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -45,6 +45,12 @@ <property name="allowedAreas"> <set>Qt::TopToolBarArea</set> </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonIconOnly</enum> + </property> + <property name="floatable"> + <bool>false</bool> + </property> <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> @@ -74,6 +80,15 @@ <property name="allowedAreas"> <set>Qt::LeftToolBarArea|Qt::RightToolBarArea</set> </property> + <property name="iconSize"> + <size> + <width>80</width> + <height>80</height> + </size> + </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonIconOnly</enum> + </property> <property name="floatable"> <bool>false</bool> </property> @@ -83,22 +98,19 @@ <attribute name="toolBarBreak"> <bool>false</bool> </attribute> + <addaction name="actionChangeInstIcon"/> + <addaction name="actionRenameInstance"/> + <addaction name="separator"/> <addaction name="actionLaunchInstance"/> <addaction name="separator"/> - <addaction name="actionRenameInstance"/> - <addaction name="actionChangeInstGroup"/> - <addaction name="actionChangeInstIcon"/> - <addaction name="actionChangeInstMCVersion"/> - <addaction name="actionChangeInstLWJGLVersion"/> <addaction name="actionEditInstNotes"/> - <addaction name="separator"/> - <addaction name="actionEditInstMods"/> - <addaction name="actionManageInstSaves"/> - <addaction name="actionRebuildInstJar"/> + <addaction name="actionChangeInstGroup"/> <addaction name="separator"/> <addaction name="actionInstanceSettings"/> - <addaction name="actionMakeDesktopShortcut"/> + <addaction name="actionChangeInstLWJGLVersion"/> + <addaction name="actionEditInstMods"/> <addaction name="actionViewSelectedInstFolder"/> + <addaction name="actionConfig_Folder"/> <addaction name="separator"/> <addaction name="actionDeleteInstance"/> </widget> @@ -256,7 +268,7 @@ </action> <action name="actionRenameInstance"> <property name="text"> - <string>Rename</string> + <string>Instance Name</string> </property> <property name="toolTip"> <string>Rename the selected instance.</string> @@ -280,6 +292,10 @@ <property name="enabled"> <bool>true</bool> </property> + <property name="icon"> + <iconset resource="../multimc.qrc"> + <normaloff>:/icons/instances/infinity</normaloff>:/icons/instances/infinity</iconset> + </property> <property name="text"> <string>Change Icon</string> </property> @@ -291,9 +307,6 @@ </property> </action> <action name="actionEditInstNotes"> - <property name="enabled"> - <bool>false</bool> - </property> <property name="text"> <string>Edit Notes</string> </property> @@ -385,26 +398,9 @@ <string>Change the version of LWJGL for the selected instance to use.</string> </property> </action> - <action name="actionRebuildInstJar"> - <property name="checkable"> - <bool>false</bool> - </property> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Rebuild Jar</string> - </property> - <property name="toolTip"> - <string>Reinstall the mods for the selected instance.</string> - </property> - <property name="statusTip"> - <string>Reinstall the mods for the selected instance.</string> - </property> - </action> <action name="actionViewSelectedInstFolder"> <property name="text"> - <string>View Folder</string> + <string>Instance Folder</string> </property> <property name="toolTip"> <string>Open the selected instance's root folder in a file browser.</string> @@ -424,6 +420,14 @@ <string>Delete the selected instance.</string> </property> </action> + <action name="actionConfig_Folder"> + <property name="text"> + <string>Config Folder</string> + </property> + <property name="toolTip"> + <string>Open the instance's config folder</string> + </property> + </action> </widget> <layoutdefault spacing="6" margin="11"/> <resources> |