From 47a7383c6d74f7ba76540c685781b7672cd298fa Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 26 Jan 2019 15:22:16 -0800 Subject: [PATCH] Add ability to edit command line arguments, and enable cheats --- hecl-gui/ArgumentEditor.cpp | 59 ++++++++++++++++++++++++++++++++ hecl-gui/ArgumentEditor.hpp | 26 ++++++++++++++ hecl-gui/ArgumentEditor.ui | 68 +++++++++++++++++++++++++++++++++++++ hecl-gui/CMakeLists.txt | 1 + hecl-gui/LaunchMenu.cpp | 45 ++++++++++++++++++++++-- hecl-gui/LaunchMenu.hpp | 3 ++ hecl-gui/MainWindow.cpp | 10 ++++-- hecl-gui/main.cpp | 3 ++ 8 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 hecl-gui/ArgumentEditor.cpp create mode 100644 hecl-gui/ArgumentEditor.hpp create mode 100644 hecl-gui/ArgumentEditor.ui diff --git a/hecl-gui/ArgumentEditor.cpp b/hecl-gui/ArgumentEditor.cpp new file mode 100644 index 000000000..f4cb3c793 --- /dev/null +++ b/hecl-gui/ArgumentEditor.cpp @@ -0,0 +1,59 @@ +#include "ArgumentEditor.hpp" +#include "ui_ArgumentEditor.h" +#include +#include +#include + +ArgumentEditor::ArgumentEditor(QWidget* parent) +: QDialog(parent) +, m_ui(new Ui::ArgumentEditor) { + m_ui->setupUi(this); + m_model.setStringList(QSettings().value("urde_arguments").toStringList()); + m_ui->argumentEditor->setModel(&m_model); +} + +ArgumentEditor::~ArgumentEditor() { + delete m_ui; + m_ui = nullptr; +} + +void ArgumentEditor::on_addButton_clicked() { + QInputDialog input(this); + int code = input.exec(); + if (code == DialogCode::Accepted) { + QStringList list = m_model.stringList(); + list << input.textValue(); + m_model.setStringList(list); + } +} + +void ArgumentEditor::on_editButton_clicked() { + QModelIndex index = m_ui->argumentEditor->currentIndex(); + if (!index.isValid()) + return; + + QInputDialog input(this); + input.setTextValue(m_model.stringList().value(index.row())); + int code = input.exec(); + if (code == DialogCode::Accepted) { + QStringList list = m_model.stringList(); + list[index.row()] = input.textValue(); + m_model.setStringList(list); + } +} + +void ArgumentEditor::on_deleteButton_clicked() { + QModelIndex index = m_ui->argumentEditor->currentIndex(); + if (index.isValid()) + m_model.removeRows(index.row(), 1); +} + +void ArgumentEditor::on_buttonBox_clicked(QAbstractButton* button) { + QDialogButtonBox* buttonBox = qobject_cast(sender()); + if (button == buttonBox->button(QDialogButtonBox::Ok)) { + QSettings().setValue("urde_arguments", m_model.stringList()); + accept(); + } else { + reject(); + } +} \ No newline at end of file diff --git a/hecl-gui/ArgumentEditor.hpp b/hecl-gui/ArgumentEditor.hpp new file mode 100644 index 000000000..deff4ae87 --- /dev/null +++ b/hecl-gui/ArgumentEditor.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +class QAbstractButton; + +namespace Ui { +class ArgumentEditor; +} + +class ArgumentEditor : public QDialog { + Q_OBJECT + Ui::ArgumentEditor* m_ui; + QStringListModel m_model; +public: + explicit ArgumentEditor(QWidget* parent = 0); + virtual ~ArgumentEditor(); + +private slots: + void on_addButton_clicked(); + void on_editButton_clicked(); + void on_deleteButton_clicked(); + void on_buttonBox_clicked(QAbstractButton*); +}; + diff --git a/hecl-gui/ArgumentEditor.ui b/hecl-gui/ArgumentEditor.ui new file mode 100644 index 000000000..aef4a721c --- /dev/null +++ b/hecl-gui/ArgumentEditor.ui @@ -0,0 +1,68 @@ + + + ArgumentEditor + + + + 0 + 0 + 613 + 525 + + + + Argument Editor + + + + + + &Delete + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + + + + &Add + + + + + + + &Edit + + + + + + + + diff --git a/hecl-gui/CMakeLists.txt b/hecl-gui/CMakeLists.txt index e59e0f76c..7a9ee5794 100644 --- a/hecl-gui/CMakeLists.txt +++ b/hecl-gui/CMakeLists.txt @@ -38,6 +38,7 @@ include_directories(quazip/quazip) add_definitions(-DQUAZIP_STATIC=1) add_executable(hecl-gui WIN32 MACOSX_BUNDLE + ArgumentEditor.ui ArgumentEditor.cpp ArgumentEditor.hpp MainWindow.ui MainWindow.hpp MainWindow.cpp LaunchMenu.hpp LaunchMenu.cpp EscapeSequenceParser.hpp EscapeSequenceParser.cpp diff --git a/hecl-gui/LaunchMenu.cpp b/hecl-gui/LaunchMenu.cpp index 01f9dac3f..ab7475045 100644 --- a/hecl-gui/LaunchMenu.cpp +++ b/hecl-gui/LaunchMenu.cpp @@ -1,5 +1,7 @@ #include "LaunchMenu.hpp" #include "hecl/CVarCommons.hpp" +#include "ArgumentEditor.hpp" +#include extern hecl::CVar* hecl::com_developer; @@ -12,6 +14,7 @@ LaunchMenu::LaunchMenu(hecl::CVarCommons& commons, QWidget* parent) , m_apiGroup(this) , m_msaaGroup(this) , m_anisoGroup(this) { + setToolTipsVisible(true); #ifdef _WIN32 initApiAction(QStringLiteral("D3D11")); initApiAction(QStringLiteral("Vulkan")); @@ -42,9 +45,11 @@ LaunchMenu::LaunchMenu(hecl::CVarCommons& commons, QWidget* parent) addMenu(&m_apiMenu)->setToolTip(m_commons.m_graphicsApi->rawHelp().data()); addMenu(&m_msaaMenu)->setToolTip(m_commons.m_drawSamples->rawHelp().data()); addMenu(&m_anisoMenu)->setToolTip(m_commons.m_texAnisotropy->rawHelp().data()); - + QAction* argumentEditor = addAction("Edit Runtime Arguments"); + connect(argumentEditor, SIGNAL(triggered()), this, SLOT(editRuntimeArgs())); initDeepColor(); initDeveloperMode(); + initCheats(); } void LaunchMenu::initApiAction(const QString& action) { @@ -87,6 +92,14 @@ void LaunchMenu::initDeveloperMode() { connect(act, SIGNAL(triggered()), this, SLOT(developerModeTriggered())); } +void LaunchMenu::initCheats() { + QAction* act = addAction("Enable Cheats"); + act->setToolTip(hecl::com_enableCheats->rawHelp().data()); + act->setCheckable(true); + act->setChecked(hecl::com_enableCheats->toBoolean()); + connect(act, SIGNAL(triggered()), this, SLOT(cheatsTriggered())); +} + void LaunchMenu::apiTriggered() { QString apiStr = qobject_cast(sender())->text(); apiStr = apiStr.remove('&'); @@ -110,6 +123,34 @@ void LaunchMenu::deepColorTriggered() { } void LaunchMenu::developerModeTriggered() { - hecl::CVarManager::instance()->setDeveloperMode(qobject_cast(sender())->isChecked(), true); + bool isChecked = qobject_cast(sender())->isChecked(); + if (hecl::com_enableCheats->toBoolean() && !isChecked) { + for (QAction* action : actions()) { + QString text = action->text().remove('&'); + if (text == "Enable Cheats" && action->isChecked()) + action->setChecked(false); + } + } + + hecl::CVarManager::instance()->setDeveloperMode(isChecked, true); m_commons.serialize(); } + +void LaunchMenu::cheatsTriggered() { + bool isChecked = qobject_cast(sender())->isChecked(); + if (!hecl::com_developer->toBoolean() && isChecked) { + for (QAction* action : actions()) { + QString text = action->text().remove('&'); + if (text == "Developer Mode" && !action->isChecked()) + action->setChecked(true); + } + } + + hecl::CVarManager::instance()->setCheatsEnabled(isChecked, true); + m_commons.serialize(); +} + +void LaunchMenu::editRuntimeArgs() { + ArgumentEditor editor(this); + editor.exec(); +} diff --git a/hecl-gui/LaunchMenu.hpp b/hecl-gui/LaunchMenu.hpp index d7c45e4f1..cd436529f 100644 --- a/hecl-gui/LaunchMenu.hpp +++ b/hecl-gui/LaunchMenu.hpp @@ -22,6 +22,7 @@ class LaunchMenu : public QMenu { void initAnisoAction(const QString& action); void initDeepColor(); void initDeveloperMode(); + void initCheats(); public: LaunchMenu(hecl::CVarCommons& commons, QWidget* parent = Q_NULLPTR); @@ -32,4 +33,6 @@ public slots: void anisoTriggered(); void deepColorTriggered(); void developerModeTriggered(); + void cheatsTriggered(); + void editRuntimeArgs(); }; diff --git a/hecl-gui/MainWindow.cpp b/hecl-gui/MainWindow.cpp index ca6e3aad5..8611f9df7 100644 --- a/hecl-gui/MainWindow.cpp +++ b/hecl-gui/MainWindow.cpp @@ -59,8 +59,10 @@ MainWindow::MainWindow(QWidget* parent) , m_ui(new Ui::MainWindow) , m_heclProc(this) , m_dlManager(this) -, m_launchMenu(m_cvarCommons, this) -, m_settings("AxioDL", "HECL", this) { +, m_launchMenu(m_cvarCommons, this) { + if (m_settings.value("urde_arguments").isNull()) + m_settings.setValue("urde_arguments", QStringList() << "--no-shader-warmup"); + m_ui->setupUi(this); m_ui->heclTabs->setCurrentIndex(0); @@ -187,7 +189,9 @@ void MainWindow::onLaunch() { m_heclProc.setProcessEnvironment(env); disconnect(&m_heclProc, SIGNAL(finished(int)), nullptr, nullptr); connect(&m_heclProc, SIGNAL(finished(int)), this, SLOT(onLaunchFinished(int))); - m_heclProc.start(m_urdePath, {"--no-shader-warmup", m_path + "/out"}, QIODevice::ReadOnly | QIODevice::Unbuffered); + m_heclProc.start(m_urdePath, QStringList() << (m_path + "/out") + << m_settings.value("urde_arguments").toStringList().join(' ').split(' '), + QIODevice::ReadOnly | QIODevice::Unbuffered); m_ui->heclTabs->setCurrentIndex(0); diff --git a/hecl-gui/main.cpp b/hecl-gui/main.cpp index 6ed538434..168357710 100644 --- a/hecl-gui/main.cpp +++ b/hecl-gui/main.cpp @@ -25,6 +25,9 @@ static QIcon MakeAppIcon() { int main(int argc, char* argv[]) { InitializePlatform(); + QApplication::setOrganizationName("AxioDL"); + QApplication::setApplicationName("HECL"); + #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);