Add ability to edit command line arguments, and enable cheats

This commit is contained in:
Phillip Stephens 2019-01-26 15:22:16 -08:00
parent 39a8b1608d
commit 47a7383c6d
8 changed files with 210 additions and 5 deletions

View File

@ -0,0 +1,59 @@
#include "ArgumentEditor.hpp"
#include "ui_ArgumentEditor.h"
#include <QSettings>
#include <QInputDialog>
#include <QDebug>
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<QDialogButtonBox*>(sender());
if (button == buttonBox->button(QDialogButtonBox::Ok)) {
QSettings().setValue("urde_arguments", m_model.stringList());
accept();
} else {
reject();
}
}

View File

@ -0,0 +1,26 @@
#pragma once
#include <QDialog>
#include <QStringListModel>
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*);
};

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ArgumentEditor</class>
<widget class="QDialog" name="ArgumentEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>613</width>
<height>525</height>
</rect>
</property>
<property name="windowTitle">
<string>Argument Editor</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QPushButton" name="deleteButton">
<property name="text">
<string>&amp;Delete</string>
</property>
</widget>
</item>
<item row="3" column="1">
<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 row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="4">
<widget class="QListView" name="argumentEditor"/>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>&amp;Add</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="editButton">
<property name="text">
<string>&amp;Edit</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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

View File

@ -1,5 +1,7 @@
#include "LaunchMenu.hpp"
#include "hecl/CVarCommons.hpp"
#include "ArgumentEditor.hpp"
#include <QList>
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<QAction*>(sender())->text();
apiStr = apiStr.remove('&');
@ -110,6 +123,34 @@ void LaunchMenu::deepColorTriggered() {
}
void LaunchMenu::developerModeTriggered() {
hecl::CVarManager::instance()->setDeveloperMode(qobject_cast<QAction*>(sender())->isChecked(), true);
bool isChecked = qobject_cast<QAction*>(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<QAction*>(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();
}

View File

@ -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();
};

View File

@ -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);

View File

@ -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);