metaforce/hecl-gui/LaunchMenu.cpp

153 lines
5.2 KiB
C++
Raw Normal View History

2018-01-10 06:19:48 +00:00
#include "LaunchMenu.hpp"
#include "hecl/CVarCommons.hpp"
#include "ArgumentEditor.hpp"
#include <QList>
2018-01-10 06:19:48 +00:00
2018-01-22 02:42:06 +00:00
extern hecl::CVar* hecl::com_developer;
2018-01-10 06:19:48 +00:00
LaunchMenu::LaunchMenu(hecl::CVarCommons& commons, QWidget* parent)
: QMenu(tr("Launch Menu"), parent)
2018-12-08 05:19:40 +00:00
, m_commons(commons)
, m_apiMenu(tr("Graphics API"), this)
, m_msaaMenu(tr("Anti-Aliasing"), this)
, m_anisoMenu(tr("Anisotropic Filtering"), this)
2018-12-08 05:19:40 +00:00
, m_apiGroup(this)
, m_msaaGroup(this)
, m_anisoGroup(this) {
setToolTipsVisible(true);
2018-01-10 06:19:48 +00:00
#ifdef _WIN32
2018-12-08 05:19:40 +00:00
initApiAction(QStringLiteral("D3D11"));
initApiAction(QStringLiteral("Vulkan"));
initApiAction(QStringLiteral("OpenGL"));
2018-01-10 06:19:48 +00:00
#elif defined(__APPLE__)
2018-12-08 05:19:40 +00:00
initApiAction(QStringLiteral("Metal"));
initApiAction(QStringLiteral("OpenGL"));
2018-01-10 06:19:48 +00:00
#else
2018-12-08 05:19:40 +00:00
initApiAction(QStringLiteral("OpenGL"));
initApiAction(QStringLiteral("Vulkan"));
2018-01-10 06:19:48 +00:00
#endif
2018-12-08 05:19:40 +00:00
initMsaaAction(QStringLiteral("1"));
initMsaaAction(QStringLiteral("2"));
initMsaaAction(QStringLiteral("4"));
initMsaaAction(QStringLiteral("8"));
initMsaaAction(QStringLiteral("16"));
initAnisoAction(QStringLiteral("1"));
initAnisoAction(QStringLiteral("2"));
initAnisoAction(QStringLiteral("4"));
initAnisoAction(QStringLiteral("8"));
initAnisoAction(QStringLiteral("16"));
m_apiMenu.addActions(m_apiGroup.actions());
m_msaaMenu.addActions(m_msaaGroup.actions());
m_anisoMenu.addActions(m_anisoGroup.actions());
addMenu(&m_apiMenu)->setToolTip(QString::fromUtf8(m_commons.m_graphicsApi->rawHelp().data()));
addMenu(&m_msaaMenu)->setToolTip(QString::fromUtf8(m_commons.m_drawSamples->rawHelp().data()));
addMenu(&m_anisoMenu)->setToolTip(QString::fromUtf8(m_commons.m_texAnisotropy->rawHelp().data()));
const QAction* argumentEditor = addAction(tr("Edit Runtime Arguments"));
connect(argumentEditor, &QAction::triggered, this, &LaunchMenu::editRuntimeArgs);
2018-12-08 05:19:40 +00:00
initDeepColor();
initDeveloperMode();
initCheats();
2018-01-10 06:19:48 +00:00
}
LaunchMenu::~LaunchMenu() = default;
2018-12-08 05:19:40 +00:00
void LaunchMenu::initApiAction(const QString& action) {
QAction* act = m_apiGroup.addAction(action);
connect(act, &QAction::triggered, this, &LaunchMenu::apiTriggered);
2018-12-08 05:19:40 +00:00
act->setCheckable(true);
if (!action.compare(QString::fromStdString(m_commons.getGraphicsApi()), Qt::CaseInsensitive))
act->setChecked(true);
2018-01-10 06:19:48 +00:00
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::initMsaaAction(const QString& action) {
QAction* act = m_msaaGroup.addAction(action);
connect(act, &QAction::triggered, this, &LaunchMenu::msaaTriggered);
2018-12-08 05:19:40 +00:00
act->setCheckable(true);
if (!action.compare(QString::number(m_commons.getSamples()), Qt::CaseInsensitive))
act->setChecked(true);
2018-01-10 06:19:48 +00:00
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::initAnisoAction(const QString& action) {
QAction* act = m_anisoGroup.addAction(action);
connect(act, &QAction::triggered, this, &LaunchMenu::anisoTriggered);
2018-12-08 05:19:40 +00:00
act->setCheckable(true);
if (!action.compare(QString::number(m_commons.getAnisotropy()), Qt::CaseInsensitive))
act->setChecked(true);
2018-01-10 06:19:48 +00:00
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::initDeepColor() {
QAction* act = addAction(tr("Deep Color"));
act->setToolTip(QString::fromUtf8(m_commons.m_deepColor->rawHelp().data()));
2018-12-08 05:19:40 +00:00
act->setCheckable(true);
act->setChecked(m_commons.getDeepColor());
connect(act, &QAction::triggered, this, &LaunchMenu::deepColorTriggered);
2018-01-16 06:41:52 +00:00
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::initDeveloperMode() {
m_developerMode = addAction(tr("Developer Mode"));
m_developerMode->setToolTip(QString::fromUtf8(hecl::com_developer->rawHelp().data()));
m_developerMode->setCheckable(true);
m_developerMode->setChecked(hecl::com_developer->toBoolean());
connect(m_developerMode, &QAction::triggered, this, &LaunchMenu::developerModeTriggered);
}
void LaunchMenu::initCheats() {
m_enableCheats = addAction(tr("Enable Cheats"));
m_enableCheats->setToolTip(QString::fromUtf8(hecl::com_enableCheats->rawHelp().data()));
m_enableCheats->setCheckable(true);
m_enableCheats->setChecked(hecl::com_enableCheats->toBoolean());
connect(m_enableCheats, &QAction::triggered, this, &LaunchMenu::cheatsTriggered);
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::apiTriggered() {
QString apiStr = qobject_cast<QAction*>(sender())->text();
apiStr = apiStr.remove(QLatin1Char{'&'});
2018-12-08 05:19:40 +00:00
m_commons.setGraphicsApi(apiStr.toStdString());
m_commons.serialize();
2018-01-10 06:19:48 +00:00
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::msaaTriggered() {
m_commons.setSamples(qobject_cast<QAction*>(sender())->text().toUInt());
m_commons.serialize();
2018-01-10 06:19:48 +00:00
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::anisoTriggered() {
m_commons.setAnisotropy(qobject_cast<QAction*>(sender())->text().toUInt());
m_commons.serialize();
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::deepColorTriggered() {
m_commons.setDeepColor(qobject_cast<QAction*>(sender())->isChecked());
m_commons.serialize();
2018-01-16 06:41:52 +00:00
}
2018-12-08 05:19:40 +00:00
void LaunchMenu::developerModeTriggered() {
const bool isChecked = qobject_cast<QAction*>(sender())->isChecked();
if (hecl::com_enableCheats->toBoolean() && !isChecked) {
m_enableCheats->setChecked(false);
}
hecl::CVarManager::instance()->setDeveloperMode(isChecked, true);
2018-12-08 05:19:40 +00:00
m_commons.serialize();
2018-01-10 06:19:48 +00:00
}
void LaunchMenu::cheatsTriggered() {
const bool isChecked = qobject_cast<QAction*>(sender())->isChecked();
if (!hecl::com_developer->toBoolean() && isChecked) {
m_developerMode->setChecked(false);
}
hecl::CVarManager::instance()->setCheatsEnabled(isChecked, true);
m_commons.serialize();
}
void LaunchMenu::editRuntimeArgs() {
ArgumentEditor editor(this);
editor.exec();
}