diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-09-08 16:21:49 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-09-08 16:21:49 +0200 |
commit | 499ee1e36569fca73bdb809183242b03da69f3ef (patch) | |
tree | 8d29f00958da54ade7e560b98e43fae89dfff0d4 /gui | |
parent | 7e1cf22ce61e8a5450e5dc74993e471c20b2742f (diff) | |
parent | dab2bbe4e79cfd8b3b72b8d2fd0e5bd66e0281a9 (diff) | |
download | MultiMC-499ee1e36569fca73bdb809183242b03da69f3ef.tar MultiMC-499ee1e36569fca73bdb809183242b03da69f3ef.tar.gz MultiMC-499ee1e36569fca73bdb809183242b03da69f3ef.tar.lz MultiMC-499ee1e36569fca73bdb809183242b03da69f3ef.tar.xz MultiMC-499ee1e36569fca73bdb809183242b03da69f3ef.zip |
Merge branch 'master' of https://github.com/Stiepen22/MultiMC5 into develop
Conflicts:
AppSettings.cpp
MultiMC.pro
main.cpp
Diffstat (limited to 'gui')
-rw-r--r-- | gui/consolewindow.cpp | 40 | ||||
-rw-r--r-- | gui/consolewindow.h | 5 | ||||
-rw-r--r-- | gui/consolewindow.ui | 7 | ||||
-rw-r--r-- | gui/mainwindow.cpp | 25 | ||||
-rw-r--r-- | gui/mainwindow.h | 3 |
5 files changed, 74 insertions, 6 deletions
diff --git a/gui/consolewindow.cpp b/gui/consolewindow.cpp index 811900a2..8ea90d45 100644 --- a/gui/consolewindow.cpp +++ b/gui/consolewindow.cpp @@ -2,13 +2,16 @@ #include "ui_consolewindow.h" #include <QScrollBar> +#include <QMessageBox> -ConsoleWindow::ConsoleWindow(QWidget *parent) : +ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) : QDialog(parent), ui(new Ui::ConsoleWindow), - m_mayclose(true) + m_mayclose(true), + proc(mcproc) { ui->setupUi(this); + connect(mcproc, SIGNAL(ended()), this, SLOT(onEnded())); } ConsoleWindow::~ConsoleWindow() @@ -20,7 +23,7 @@ void ConsoleWindow::writeColor(QString text, const char *color) { // append a paragraph if (color != nullptr) - ui->text->appendHtml(QString("<font color=%1>%2</font>").arg(color).arg(text)); + ui->text->appendHtml(QString("<font color=\"%1\">%2</font>").arg(color).arg(text)); else ui->text->appendPlainText(text); // scroll down @@ -40,6 +43,15 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode) else if (mode == MessageLevel::Error) while(iter.hasNext()) writeColor(iter.next(), "red"); + else if (mode == MessageLevel::Warning) + while(iter.hasNext()) + writeColor(iter.next(), "orange"); + else if (mode == MessageLevel::Fatal) + while(iter.hasNext()) + writeColor(iter.next(), "pink"); + else if (mode == MessageLevel::Debug) + while(iter.hasNext()) + writeColor(iter.next(), "green"); // TODO: implement other MessageLevels else while(iter.hasNext()) @@ -72,3 +84,25 @@ void ConsoleWindow::closeEvent(QCloseEvent * event) else QDialog::closeEvent(event); } + +void ConsoleWindow::on_btnKillMinecraft_clicked() +{ + ui->btnKillMinecraft->setEnabled(false); + QMessageBox r_u_sure; + r_u_sure.setText("Kill Minecraft?"); + r_u_sure.setInformativeText("This can cause the instance to get corrupted and should only be used if Minecraft is frozen for some reason"); + r_u_sure.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + r_u_sure.setDefaultButton(QMessageBox::Yes); + if (r_u_sure.exec() == QMessageBox::Yes) + proc->killMinecraft(); + else + ui->btnKillMinecraft->setEnabled(true); + r_u_sure.close(); +} + +void ConsoleWindow::onEnded() +{ + ui->btnKillMinecraft->setEnabled(false); + // TODO: Check why this doesn't work + if (!proc->exitCode()) this->close(); +} diff --git a/gui/consolewindow.h b/gui/consolewindow.h index 60bec69f..6a6c9e50 100644 --- a/gui/consolewindow.h +++ b/gui/consolewindow.h @@ -13,7 +13,7 @@ class ConsoleWindow : public QDialog Q_OBJECT public: - explicit ConsoleWindow(QWidget *parent = 0); + explicit ConsoleWindow(MinecraftProcess *proc, QWidget *parent = 0); ~ConsoleWindow(); /** @@ -48,12 +48,15 @@ public slots: private slots: void on_closeButton_clicked(); + void on_btnKillMinecraft_clicked(); + void onEnded(); protected: void closeEvent(QCloseEvent *); private: Ui::ConsoleWindow *ui; + MinecraftProcess *proc; bool m_mayclose; }; diff --git a/gui/consolewindow.ui b/gui/consolewindow.ui index 9a766543..8dc80015 100644 --- a/gui/consolewindow.ui +++ b/gui/consolewindow.ui @@ -63,6 +63,13 @@ </spacer> </item> <item> + <widget class="QPushButton" name="btnKillMinecraft"> + <property name="text"> + <string>Kill Minecraft</string> + </property> + </widget> + </item> + <item> <widget class="QPushButton" name="closeButton"> <property name="text"> <string>Close</string> diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index c0b79108..7ddc66a9 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -488,7 +488,10 @@ void MainWindow::doLogin(const QString& errorMsg) } else { - m_activeLogin = {loginDlg->getUsername(), QString("Offline"), qint64(-1)}; + QString user = loginDlg->getUsername(); + if (user.length() == 0) + user = QString("Offline"); + m_activeLogin = {user, QString("Offline"), qint64(-1)}; m_activeInst = m_selectedInstance; launchInstance(m_activeInst, m_activeLogin); } @@ -534,10 +537,22 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) if(!proc) return; - console = new ConsoleWindow(); + // Prepare GUI: If it shall stay open disable the required parts + if (MMC->settings()->get("NoHide").toBool()) + { + ui->actionLaunchInstance->setEnabled(false); + } + else + { + this->hide(); + } + + console = new ConsoleWindow(proc); console->show(); connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, SLOT(write(QString, MessageLevel::Enum))); + connect(proc, SIGNAL(ended()), this, SLOT(instanceEnded())); + proc->setLogin(m_activeLogin.username, m_activeLogin.sessionID); proc->launch(); } @@ -664,3 +679,9 @@ void MainWindow::on_actionEditInstNotes_triggered() linst->setNotes(noteedit.getText()); } } + +void MainWindow::instanceEnded() +{ + this->show(); + ui->actionLaunchInstance->setEnabled(m_selectedInstance); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 3612dd0c..2b0e1d34 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -111,6 +111,8 @@ private slots: void on_actionChangeInstLWJGLVersion_triggered(); + void instanceEnded(); + void on_actionInstanceSettings_triggered(); public slots: @@ -128,6 +130,7 @@ protected: bool eventFilter(QObject *obj, QEvent *ev); void setCatBackground(bool enabled); private: + Ui::MainWindow *ui; KCategoryDrawer * drawer; KCategorizedView * view; |