metaforce/hecl-gui/LaunchMenu.cpp

157 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)
2018-12-08 05:19:40 +00:00
: QMenu("Launch Menu", parent)
, m_commons(commons)
, m_apiMenu("Graphics API", this)
, m_msaaMenu("Anti-Aliasing", this)
, m_anisoMenu("Anisotropic Filtering", this)
, 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(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, &QAction::triggered, this, &LaunchMenu::editRuntimeArgs);
2018-12-08 05:19:40 +00:00
initDeepColor();
initDeveloperMode();
initCheats();
2018-01-10 06:19:48 +00:00
}
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("Deep Color");
act->setToolTip(m_commons.m_deepColor->rawHelp().data());
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() {
QAction* act = addAction("Developer Mode");
act->setToolTip(hecl::com_developer->rawHelp().data());
act->setCheckable(true);
act->setChecked(hecl::com_developer->toBoolean());
connect(act, &QAction::triggered, this, &LaunchMenu::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, &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('&');
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() {
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);
2018-12-08 05:19:40 +00:00
m_commons.serialize();
2018-01-10 06:19:48 +00:00
}
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();
}