1
0
mirror of https://git.suyu.dev/suyu/suyu synced 2025-09-20 04:52:06 -05:00

Full rebrand

This commit is contained in:
JuanCStar
2024-03-08 09:06:48 +00:00
committed by Crimson Hawk
parent c445fa1e3e
commit 88b901a24e
427 changed files with 55946 additions and 56077 deletions

View File

@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include <type_traits>
#include <vector>
#include "suyu/configuration/configuration_shared.h"
namespace ConfigurationShared {
Tab::Tab(std::shared_ptr<std::vector<Tab*>> group, QWidget* parent) : QWidget(parent) {
if (group != nullptr) {
group->push_back(this);
}
}
Tab::~Tab() = default;
} // namespace ConfigurationShared

View File

@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <vector>
#include <QString>
#include <QWidget>
#include <qobjectdefs.h>
class QObject;
namespace ConfigurationShared {
class Tab : public QWidget {
Q_OBJECT
public:
explicit Tab(std::shared_ptr<std::vector<Tab*>> group, QWidget* parent = nullptr);
~Tab();
virtual void ApplyConfiguration() = 0;
virtual void SetConfiguration() = 0;
};
} // namespace ConfigurationShared

View File

@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureDialog</class>
<widget class="QDialog" name="ConfigureDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>650</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>650</height>
</size>
</property>
<property name="windowTitle">
<string>suyu Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="selectorList">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Some settings are only available when a game is not running.</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigureDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_applets.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_applets.h"
#include "suyu/configuration/shared_widget.h"
ConfigureApplets::ConfigureApplets(Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::Builder& builder, QWidget* parent)
: Tab(group_, parent), ui{std::make_unique<Ui::ConfigureApplets>()}, system{system_} {
ui->setupUi(this);
Setup(builder);
SetConfiguration();
}
ConfigureApplets::~ConfigureApplets() = default;
void ConfigureApplets::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureApplets::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureApplets::Setup(const ConfigurationShared::Builder& builder) {
auto& library_applets_layout = *ui->group_library_applet_modes->layout();
std::map<u32, QWidget*> applets_hold{};
std::vector<Settings::BasicSetting*> settings;
auto push = [&settings](auto& list) {
for (auto setting : list) {
settings.push_back(setting);
}
};
push(Settings::values.linkage.by_category[Settings::Category::LibraryApplet]);
for (auto setting : settings) {
ConfigurationShared::Widget* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
widget->deleteLater();
continue;
}
// Untested applets
if (setting->Id() == Settings::values.data_erase_applet_mode.Id() ||
setting->Id() == Settings::values.net_connect_applet_mode.Id() ||
setting->Id() == Settings::values.shop_applet_mode.Id() ||
setting->Id() == Settings::values.login_share_applet_mode.Id() ||
setting->Id() == Settings::values.wifi_web_auth_applet_mode.Id() ||
setting->Id() == Settings::values.my_page_applet_mode.Id()) {
widget->setHidden(true);
}
applets_hold.emplace(setting->Id(), widget);
}
for (const auto& [label, widget] : applets_hold) {
library_applets_layout.addWidget(widget);
}
}
void ConfigureApplets::SetConfiguration() {}
void ConfigureApplets::ApplyConfiguration() {
const bool powered_on = system.IsPoweredOn();
for (const auto& func : apply_funcs) {
func(powered_on);
}
}

View File

@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QWidget>
#include "suyu/configuration/configuration_shared.h"
class QCheckBox;
class QLineEdit;
class QComboBox;
class QDateTimeEdit;
namespace Core {
class System;
}
namespace Ui {
class ConfigureApplets;
}
namespace ConfigurationShared {
class Builder;
}
class ConfigureApplets : public ConfigurationShared::Tab {
public:
explicit ConfigureApplets(Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group,
const ConfigurationShared::Builder& builder,
QWidget* parent = nullptr);
~ConfigureApplets() override;
void ApplyConfiguration() override;
void SetConfiguration() override;
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void Setup(const ConfigurationShared::Builder& builder);
std::vector<std::function<void(bool)>> apply_funcs{};
std::unique_ptr<Ui::ConfigureApplets> ui;
bool enabled = false;
Core::System& system;
};

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureApplets</class>
<widget class="QWidget" name="ConfigureApplets">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>605</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>Applets</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="group_library_applet_modes">
<property name="title">
<string>Applet mode preference</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QWidget" name="applets_widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,278 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <map>
#include <memory>
#include <vector>
#include <QComboBox>
#include <QPushButton>
#include "audio_core/sink/sink.h"
#include "audio_core/sink/sink_details.h"
#include "common/common_types.h"
#include "common/settings.h"
#include "common/settings_common.h"
#include "core/core.h"
#include "ui_configure_audio.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_audio.h"
#include "suyu/configuration/shared_translation.h"
#include "suyu/configuration/shared_widget.h"
#include "suyu/uisettings.h"
ConfigureAudio::ConfigureAudio(const Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::Builder& builder, QWidget* parent)
: Tab(group_, parent), ui(std::make_unique<Ui::ConfigureAudio>()), system{system_} {
ui->setupUi(this);
Setup(builder);
SetConfiguration();
}
ConfigureAudio::~ConfigureAudio() = default;
void ConfigureAudio::Setup(const ConfigurationShared::Builder& builder) {
auto& layout = *ui->audio_widget->layout();
std::vector<Settings::BasicSetting*> settings;
std::map<u32, QWidget*> hold;
auto push_settings = [&](Settings::Category category) {
for (auto* setting : Settings::values.linkage.by_category[category]) {
settings.push_back(setting);
}
};
auto push_ui_settings = [&](Settings::Category category) {
for (auto* setting : UISettings::values.linkage.by_category[category]) {
settings.push_back(setting);
}
};
push_settings(Settings::Category::Audio);
push_settings(Settings::Category::SystemAudio);
push_ui_settings(Settings::Category::UiAudio);
for (auto* setting : settings) {
auto* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
widget->deleteLater();
continue;
}
hold.emplace(std::pair{setting->Id(), widget});
auto global_sink_match = [this] {
return static_cast<Settings::AudioEngine>(sink_combo_box->currentIndex()) ==
Settings::values.sink_id.GetValue(true);
};
if (setting->Id() == Settings::values.sink_id.Id()) {
// TODO (lat9nq): Let the system manage sink_id
sink_combo_box = widget->combobox;
InitializeAudioSinkComboBox();
if (Settings::IsConfiguringGlobal()) {
connect(sink_combo_box, qOverload<int>(&QComboBox::currentIndexChanged), this,
&ConfigureAudio::UpdateAudioDevices);
} else {
restore_sink_button = ConfigurationShared::Widget::CreateRestoreGlobalButton(
Settings::values.sink_id.UsingGlobal(), widget);
widget->layout()->addWidget(restore_sink_button);
connect(restore_sink_button, &QAbstractButton::clicked, [this](bool) {
Settings::values.sink_id.SetGlobal(true);
const int sink_index = static_cast<int>(Settings::values.sink_id.GetValue());
sink_combo_box->setCurrentIndex(sink_index);
ConfigureAudio::UpdateAudioDevices(sink_index);
Settings::values.audio_output_device_id.SetGlobal(true);
Settings::values.audio_input_device_id.SetGlobal(true);
restore_sink_button->setVisible(false);
});
connect(sink_combo_box, qOverload<int>(&QComboBox::currentIndexChanged),
[this, global_sink_match](const int slot) {
Settings::values.sink_id.SetGlobal(false);
Settings::values.audio_output_device_id.SetGlobal(false);
Settings::values.audio_input_device_id.SetGlobal(false);
restore_sink_button->setVisible(true);
restore_sink_button->setEnabled(true);
output_device_combo_box->setCurrentIndex(0);
restore_output_device_button->setVisible(true);
restore_output_device_button->setEnabled(global_sink_match());
input_device_combo_box->setCurrentIndex(0);
restore_input_device_button->setVisible(true);
restore_input_device_button->setEnabled(global_sink_match());
ConfigureAudio::UpdateAudioDevices(slot);
});
}
} else if (setting->Id() == Settings::values.audio_output_device_id.Id()) {
// Keep track of output (and input) device comboboxes to populate them with system
// devices, which are determined at run time
output_device_combo_box = widget->combobox;
if (!Settings::IsConfiguringGlobal()) {
restore_output_device_button =
ConfigurationShared::Widget::CreateRestoreGlobalButton(
Settings::values.audio_output_device_id.UsingGlobal(), widget);
restore_output_device_button->setEnabled(global_sink_match());
restore_output_device_button->setVisible(
!Settings::values.audio_output_device_id.UsingGlobal());
widget->layout()->addWidget(restore_output_device_button);
connect(restore_output_device_button, &QAbstractButton::clicked, [this](bool) {
Settings::values.audio_output_device_id.SetGlobal(true);
SetOutputDevicesFromDeviceID();
restore_output_device_button->setVisible(false);
});
connect(output_device_combo_box, qOverload<int>(&QComboBox::currentIndexChanged),
[this, global_sink_match](int) {
if (updating_devices) {
return;
}
Settings::values.audio_output_device_id.SetGlobal(false);
restore_output_device_button->setVisible(true);
restore_output_device_button->setEnabled(global_sink_match());
});
}
} else if (setting->Id() == Settings::values.audio_input_device_id.Id()) {
input_device_combo_box = widget->combobox;
if (!Settings::IsConfiguringGlobal()) {
restore_input_device_button =
ConfigurationShared::Widget::CreateRestoreGlobalButton(
Settings::values.audio_input_device_id.UsingGlobal(), widget);
widget->layout()->addWidget(restore_input_device_button);
connect(restore_input_device_button, &QAbstractButton::clicked, [this](bool) {
Settings::values.audio_input_device_id.SetGlobal(true);
SetInputDevicesFromDeviceID();
restore_input_device_button->setVisible(false);
});
connect(input_device_combo_box, qOverload<int>(&QComboBox::currentIndexChanged),
[this, global_sink_match](int) {
if (updating_devices) {
return;
}
Settings::values.audio_input_device_id.SetGlobal(false);
restore_input_device_button->setVisible(true);
restore_input_device_button->setEnabled(global_sink_match());
});
}
}
}
for (const auto& [id, widget] : hold) {
layout.addWidget(widget);
}
}
void ConfigureAudio::SetConfiguration() {
SetOutputSinkFromSinkID();
// The device list cannot be pre-populated (nor listed) until the output sink is known.
UpdateAudioDevices(sink_combo_box->currentIndex());
SetOutputDevicesFromDeviceID();
SetInputDevicesFromDeviceID();
}
void ConfigureAudio::SetOutputSinkFromSinkID() {
[[maybe_unused]] const QSignalBlocker blocker(sink_combo_box);
int new_sink_index = 0;
const QString sink_id = QString::fromStdString(Settings::values.sink_id.ToString());
for (int index = 0; index < sink_combo_box->count(); index++) {
if (sink_combo_box->itemText(index) == sink_id) {
new_sink_index = index;
break;
}
}
sink_combo_box->setCurrentIndex(new_sink_index);
}
void ConfigureAudio::SetOutputDevicesFromDeviceID() {
int new_device_index = 0;
const QString output_device_id =
QString::fromStdString(Settings::values.audio_output_device_id.GetValue());
for (int index = 0; index < output_device_combo_box->count(); index++) {
if (output_device_combo_box->itemText(index) == output_device_id) {
new_device_index = index;
break;
}
}
output_device_combo_box->setCurrentIndex(new_device_index);
}
void ConfigureAudio::SetInputDevicesFromDeviceID() {
int new_device_index = 0;
const QString input_device_id =
QString::fromStdString(Settings::values.audio_input_device_id.GetValue());
for (int index = 0; index < input_device_combo_box->count(); index++) {
if (input_device_combo_box->itemText(index) == input_device_id) {
new_device_index = index;
break;
}
}
input_device_combo_box->setCurrentIndex(new_device_index);
}
void ConfigureAudio::ApplyConfiguration() {
const bool is_powered_on = system.IsPoweredOn();
for (const auto& apply_func : apply_funcs) {
apply_func(is_powered_on);
}
Settings::values.sink_id.LoadString(
sink_combo_box->itemText(sink_combo_box->currentIndex()).toStdString());
Settings::values.audio_output_device_id.SetValue(
output_device_combo_box->itemText(output_device_combo_box->currentIndex()).toStdString());
Settings::values.audio_input_device_id.SetValue(
input_device_combo_box->itemText(input_device_combo_box->currentIndex()).toStdString());
}
void ConfigureAudio::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureAudio::UpdateAudioDevices(int sink_index) {
updating_devices = true;
output_device_combo_box->clear();
output_device_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name));
const auto sink_id =
Settings::ToEnum<Settings::AudioEngine>(sink_combo_box->itemText(sink_index).toStdString());
for (const auto& device : AudioCore::Sink::GetDeviceListForSink(sink_id, false)) {
output_device_combo_box->addItem(QString::fromStdString(device));
}
input_device_combo_box->clear();
input_device_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name));
for (const auto& device : AudioCore::Sink::GetDeviceListForSink(sink_id, true)) {
input_device_combo_box->addItem(QString::fromStdString(device));
}
updating_devices = false;
}
void ConfigureAudio::InitializeAudioSinkComboBox() {
sink_combo_box->clear();
sink_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name));
for (const auto& id : AudioCore::Sink::GetSinkIDs()) {
sink_combo_box->addItem(QString::fromStdString(Settings::CanonicalizeEnum(id)));
}
}
void ConfigureAudio::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <functional>
#include <memory>
#include <vector>
#include <QWidget>
#include "suyu/configuration/configuration_shared.h"
class QComboBox;
namespace Core {
class System;
}
namespace Ui {
class ConfigureAudio;
}
namespace ConfigurationShared {
class Builder;
}
class ConfigureAudio : public ConfigurationShared::Tab {
Q_OBJECT
public:
explicit ConfigureAudio(const Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group,
const ConfigurationShared::Builder& builder, QWidget* parent = nullptr);
~ConfigureAudio() override;
void ApplyConfiguration() override;
void SetConfiguration() override;
private:
void changeEvent(QEvent* event) override;
void InitializeAudioSinkComboBox();
void RetranslateUI();
void UpdateAudioDevices(int sink_index);
void SetOutputSinkFromSinkID();
void SetOutputDevicesFromDeviceID();
void SetInputDevicesFromDeviceID();
void Setup(const ConfigurationShared::Builder& builder);
std::unique_ptr<Ui::ConfigureAudio> ui;
const Core::System& system;
std::vector<std::function<void(bool)>> apply_funcs{};
bool updating_devices = false;
QComboBox* sink_combo_box;
QPushButton* restore_sink_button;
QComboBox* output_device_combo_box;
QPushButton* restore_output_device_button;
QComboBox* input_device_combo_box;
QPushButton* restore_input_device_button;
};

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureAudio</class>
<widget class="QWidget" name="ConfigureAudio">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>367</width>
<height>368</height>
</rect>
</property>
<property name="accessibleName">
<string>Audio</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Audio</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QWidget" name="audio_widget" native="true">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777213</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>167</width>
<height>55</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,163 @@
// Text : Copyright 2022 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include <memory>
#include <QtCore>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && SUYU_USE_QT_MULTIMEDIA
#include <QCameraImageCapture>
#include <QCameraInfo>
#endif
#include <QStandardItemModel>
#include <QTimer>
#include "common/settings.h"
#include "input_common/drivers/camera.h"
#include "input_common/main.h"
#include "ui_configure_camera.h"
#include "suyu/configuration/configure_camera.h"
ConfigureCamera::ConfigureCamera(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_)
: QDialog(parent), input_subsystem{input_subsystem_},
ui(std::make_unique<Ui::ConfigureCamera>()) {
ui->setupUi(this);
connect(ui->restore_defaults_button, &QPushButton::clicked, this,
&ConfigureCamera::RestoreDefaults);
connect(ui->preview_button, &QPushButton::clicked, this, &ConfigureCamera::PreviewCamera);
auto blank_image = QImage(320, 240, QImage::Format::Format_RGB32);
blank_image.fill(Qt::black);
DisplayCapturedFrame(0, blank_image);
LoadConfiguration();
resize(0, 0);
}
ConfigureCamera::~ConfigureCamera() = default;
void ConfigureCamera::PreviewCamera() {
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && SUYU_USE_QT_MULTIMEDIA
const auto index = ui->ir_sensor_combo_box->currentIndex();
bool camera_found = false;
const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
for (const QCameraInfo& cameraInfo : cameras) {
if (input_devices[index] == cameraInfo.deviceName().toStdString() ||
input_devices[index] == "Auto") {
LOG_INFO(Frontend, "Selected Camera {} {}", cameraInfo.description().toStdString(),
cameraInfo.deviceName().toStdString());
camera = std::make_unique<QCamera>(cameraInfo);
if (!camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureViewfinder) &&
!camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureStillImage)) {
LOG_ERROR(Frontend,
"Camera doesn't support CaptureViewfinder or CaptureStillImage");
continue;
}
camera_found = true;
break;
}
}
// Clear previous frame
auto blank_image = QImage(320, 240, QImage::Format::Format_RGB32);
blank_image.fill(Qt::black);
DisplayCapturedFrame(0, blank_image);
if (!camera_found) {
return;
}
camera_capture = std::make_unique<QCameraImageCapture>(camera.get());
if (!camera_capture->isCaptureDestinationSupported(
QCameraImageCapture::CaptureDestination::CaptureToBuffer)) {
LOG_ERROR(Frontend, "Camera doesn't support saving to buffer");
return;
}
camera_capture->setCaptureDestination(QCameraImageCapture::CaptureDestination::CaptureToBuffer);
connect(camera_capture.get(), &QCameraImageCapture::imageCaptured, this,
&ConfigureCamera::DisplayCapturedFrame);
camera->unload();
if (camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureViewfinder)) {
camera->setCaptureMode(QCamera::CaptureViewfinder);
} else if (camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureStillImage)) {
camera->setCaptureMode(QCamera::CaptureStillImage);
}
camera->load();
camera->start();
pending_snapshots = 0;
is_virtual_camera = false;
camera_timer = std::make_unique<QTimer>();
connect(camera_timer.get(), &QTimer::timeout, [this] {
// If the camera doesn't capture, test for virtual cameras
if (pending_snapshots > 5) {
is_virtual_camera = true;
}
// Virtual cameras like obs need to reset the camera every capture
if (is_virtual_camera) {
camera->stop();
camera->start();
}
pending_snapshots++;
camera_capture->capture();
});
camera_timer->start(250);
#endif
}
void ConfigureCamera::DisplayCapturedFrame(int requestId, const QImage& img) {
LOG_INFO(Frontend, "ImageCaptured {} {}", img.width(), img.height());
const auto converted = img.scaled(320, 240, Qt::AspectRatioMode::IgnoreAspectRatio,
Qt::TransformationMode::SmoothTransformation);
ui->preview_box->setPixmap(QPixmap::fromImage(converted));
pending_snapshots = 0;
}
void ConfigureCamera::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigureCamera::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureCamera::ApplyConfiguration() {
const auto index = ui->ir_sensor_combo_box->currentIndex();
Settings::values.ir_sensor_device.SetValue(input_devices[index]);
}
void ConfigureCamera::LoadConfiguration() {
input_devices.clear();
ui->ir_sensor_combo_box->clear();
input_devices.push_back("Auto");
ui->ir_sensor_combo_box->addItem(tr("Auto"));
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && SUYU_USE_QT_MULTIMEDIA
const auto cameras = QCameraInfo::availableCameras();
for (const QCameraInfo& cameraInfo : cameras) {
input_devices.push_back(cameraInfo.deviceName().toStdString());
ui->ir_sensor_combo_box->addItem(cameraInfo.description());
}
#endif
const auto current_device = Settings::values.ir_sensor_device.GetValue();
const auto devices_it = std::find_if(
input_devices.begin(), input_devices.end(),
[current_device](const std::string& device) { return device == current_device; });
const int device_index =
devices_it != input_devices.end()
? static_cast<int>(std::distance(input_devices.begin(), devices_it))
: 0;
ui->ir_sensor_combo_box->setCurrentIndex(device_index);
}
void ConfigureCamera::RestoreDefaults() {
ui->ir_sensor_combo_box->setCurrentIndex(0);
}

View File

@@ -0,0 +1,56 @@
// Text : Copyright 2022 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <memory>
#include <QDialog>
class QTimer;
class QCamera;
class QCameraImageCapture;
namespace InputCommon {
class InputSubsystem;
} // namespace InputCommon
namespace Ui {
class ConfigureCamera;
}
class ConfigureCamera : public QDialog {
Q_OBJECT
public:
explicit ConfigureCamera(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_);
~ConfigureCamera() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
/// Load configuration settings.
void LoadConfiguration();
/// Restore all buttons to their default values.
void RestoreDefaults();
void DisplayCapturedFrame(int requestId, const QImage& img);
/// Loads and signals the current selected camera to display a frame
void PreviewCamera();
InputCommon::InputSubsystem* input_subsystem;
bool is_virtual_camera;
int pending_snapshots;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && SUYU_USE_QT_MULTIMEDIA
std::unique_ptr<QCamera> camera;
std::unique_ptr<QCameraImageCapture> camera_capture;
#endif
std::unique_ptr<QTimer> camera_timer;
std::vector<std::string> input_devices;
std::unique_ptr<Ui::ConfigureCamera> ui;
};

View File

@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureCamera</class>
<widget class="QDialog" name="ConfigureCamera">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>298</width>
<height>339</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure Infrared Camera</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>280</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Select where the image of the emulated camera comes from. It may be a virtual camera or a real camera.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="gridGroupBox">
<property name="title">
<string>Camera Image Source:</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Input device:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="ir_sensor_combo_box"/>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item><item>
<widget class="QGroupBox" name="previewBox">
<property name="title">
<string>Preview</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="preview_box">
<property name="minimumSize">
<size>
<width>320</width>
<height>240</height>
</size>
</property>
<property name="toolTip">
<string>Resolution: 320*240</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="preview_button">
<property name="text">
<string>Click to preview</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="restore_defaults_button">
<property name="text">
<string>Restore Defaults</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigureCamera</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureCamera</receiver>
<slot>reject()</slot>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,114 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include <typeinfo>
#include <vector>
#include <QComboBox>
#include "common/common_types.h"
#include "common/settings.h"
#include "common/settings_enums.h"
#include "configuration/shared_widget.h"
#include "core/core.h"
#include "ui_configure_cpu.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_cpu.h"
ConfigureCpu::ConfigureCpu(const Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::Builder& builder, QWidget* parent)
: Tab(group_, parent), ui{std::make_unique<Ui::ConfigureCpu>()}, system{system_},
combobox_translations(builder.ComboboxTranslations()) {
ui->setupUi(this);
Setup(builder);
SetConfiguration();
connect(accuracy_combobox, qOverload<int>(&QComboBox::currentIndexChanged), this,
&ConfigureCpu::UpdateGroup);
connect(backend_combobox, qOverload<int>(&QComboBox::currentIndexChanged), this,
&ConfigureCpu::UpdateGroup);
#ifdef HAS_NCE
ui->backend_group->setVisible(true);
#endif
}
ConfigureCpu::~ConfigureCpu() = default;
void ConfigureCpu::SetConfiguration() {}
void ConfigureCpu::Setup(const ConfigurationShared::Builder& builder) {
auto* accuracy_layout = ui->widget_accuracy->layout();
auto* backend_layout = ui->widget_backend->layout();
auto* unsafe_layout = ui->unsafe_widget->layout();
std::map<u32, QWidget*> unsafe_hold{};
std::vector<Settings::BasicSetting*> settings;
const auto push = [&](Settings::Category category) {
for (const auto setting : Settings::values.linkage.by_category[category]) {
settings.push_back(setting);
}
};
push(Settings::Category::Cpu);
push(Settings::Category::CpuUnsafe);
for (const auto setting : settings) {
auto* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
widget->deleteLater();
continue;
}
if (setting->Id() == Settings::values.cpu_accuracy.Id()) {
// Keep track of cpu_accuracy combobox to display/hide the unsafe settings
accuracy_layout->addWidget(widget);
accuracy_combobox = widget->combobox;
} else if (setting->Id() == Settings::values.cpu_backend.Id()) {
backend_layout->addWidget(widget);
backend_combobox = widget->combobox;
} else {
// Presently, all other settings here are unsafe checkboxes
unsafe_hold.insert({setting->Id(), widget});
}
}
for (const auto& [label, widget] : unsafe_hold) {
unsafe_layout->addWidget(widget);
}
UpdateGroup(accuracy_combobox->currentIndex());
UpdateGroup(backend_combobox->currentIndex());
}
void ConfigureCpu::UpdateGroup(int index) {
const auto accuracy = static_cast<Settings::CpuAccuracy>(
combobox_translations.at(Settings::EnumMetadata<Settings::CpuAccuracy>::Index())[index]
.first);
ui->unsafe_group->setVisible(accuracy == Settings::CpuAccuracy::Unsafe);
}
void ConfigureCpu::ApplyConfiguration() {
const bool is_powered_on = system.IsPoweredOn();
for (const auto& apply_func : apply_funcs) {
apply_func(is_powered_on);
}
}
void ConfigureCpu::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureCpu::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <vector>
#include <QWidget>
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/shared_translation.h"
class QComboBox;
namespace Core {
class System;
}
namespace Ui {
class ConfigureCpu;
}
namespace ConfigurationShared {
class Builder;
}
class ConfigureCpu : public ConfigurationShared::Tab {
Q_OBJECT
public:
explicit ConfigureCpu(const Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group,
const ConfigurationShared::Builder& builder, QWidget* parent = nullptr);
~ConfigureCpu() override;
void ApplyConfiguration() override;
void SetConfiguration() override;
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void UpdateGroup(int index);
void Setup(const ConfigurationShared::Builder& builder);
std::unique_ptr<Ui::ConfigureCpu> ui;
const Core::System& system;
const ConfigurationShared::ComboboxTranslationMap& combobox_translations;
std::vector<std::function<void(bool)>> apply_funcs{};
QComboBox* accuracy_combobox;
QComboBox* backend_combobox;
};

View File

@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureCpu</class>
<widget class="QWidget" name="ConfigureCpu">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>448</width>
<height>439</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>CPU</string>
</property>
<layout class="QVBoxLayout" name="vboxlayout_2" stretch="0">
<item>
<layout class="QVBoxLayout" name="vboxlayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>General</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QWidget" name="widget_accuracy" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_recommended_accuracy">
<property name="text">
<string>We recommend setting accuracy to &quot;Auto&quot;.</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="backend_group">
<property name="title">
<string>CPU Backend</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QWidget" name="widget_backend" native="true">
<layout class="QVBoxLayout" name="verticalLayout1">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
<property name="visible">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="unsafe_group">
<property name="title">
<string>Unsafe CPU Optimization Settings</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label_accuracy_description">
<property name="text">
<string>These settings reduce accuracy for speed.</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="unsafe_widget" native="true">
<layout class="QVBoxLayout" name="unsafe_layout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,78 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_cpu_debug.h"
#include "suyu/configuration/configure_cpu_debug.h"
ConfigureCpuDebug::ConfigureCpuDebug(const Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigureCpuDebug>()}, system{system_} {
ui->setupUi(this);
SetConfiguration();
}
ConfigureCpuDebug::~ConfigureCpuDebug() = default;
void ConfigureCpuDebug::SetConfiguration() {
const bool runtime_lock = !system.IsPoweredOn();
ui->cpuopt_page_tables->setEnabled(runtime_lock);
ui->cpuopt_page_tables->setChecked(Settings::values.cpuopt_page_tables.GetValue());
ui->cpuopt_block_linking->setEnabled(runtime_lock);
ui->cpuopt_block_linking->setChecked(Settings::values.cpuopt_block_linking.GetValue());
ui->cpuopt_return_stack_buffer->setEnabled(runtime_lock);
ui->cpuopt_return_stack_buffer->setChecked(
Settings::values.cpuopt_return_stack_buffer.GetValue());
ui->cpuopt_fast_dispatcher->setEnabled(runtime_lock);
ui->cpuopt_fast_dispatcher->setChecked(Settings::values.cpuopt_fast_dispatcher.GetValue());
ui->cpuopt_context_elimination->setEnabled(runtime_lock);
ui->cpuopt_context_elimination->setChecked(
Settings::values.cpuopt_context_elimination.GetValue());
ui->cpuopt_const_prop->setEnabled(runtime_lock);
ui->cpuopt_const_prop->setChecked(Settings::values.cpuopt_const_prop.GetValue());
ui->cpuopt_misc_ir->setEnabled(runtime_lock);
ui->cpuopt_misc_ir->setChecked(Settings::values.cpuopt_misc_ir.GetValue());
ui->cpuopt_reduce_misalign_checks->setEnabled(runtime_lock);
ui->cpuopt_reduce_misalign_checks->setChecked(
Settings::values.cpuopt_reduce_misalign_checks.GetValue());
ui->cpuopt_fastmem->setEnabled(runtime_lock);
ui->cpuopt_fastmem->setChecked(Settings::values.cpuopt_fastmem.GetValue());
ui->cpuopt_fastmem_exclusives->setEnabled(runtime_lock);
ui->cpuopt_fastmem_exclusives->setChecked(
Settings::values.cpuopt_fastmem_exclusives.GetValue());
ui->cpuopt_recompile_exclusives->setEnabled(runtime_lock);
ui->cpuopt_recompile_exclusives->setChecked(
Settings::values.cpuopt_recompile_exclusives.GetValue());
ui->cpuopt_ignore_memory_aborts->setEnabled(runtime_lock);
ui->cpuopt_ignore_memory_aborts->setChecked(
Settings::values.cpuopt_ignore_memory_aborts.GetValue());
}
void ConfigureCpuDebug::ApplyConfiguration() {
Settings::values.cpuopt_page_tables = ui->cpuopt_page_tables->isChecked();
Settings::values.cpuopt_block_linking = ui->cpuopt_block_linking->isChecked();
Settings::values.cpuopt_return_stack_buffer = ui->cpuopt_return_stack_buffer->isChecked();
Settings::values.cpuopt_fast_dispatcher = ui->cpuopt_fast_dispatcher->isChecked();
Settings::values.cpuopt_context_elimination = ui->cpuopt_context_elimination->isChecked();
Settings::values.cpuopt_const_prop = ui->cpuopt_const_prop->isChecked();
Settings::values.cpuopt_misc_ir = ui->cpuopt_misc_ir->isChecked();
Settings::values.cpuopt_reduce_misalign_checks = ui->cpuopt_reduce_misalign_checks->isChecked();
Settings::values.cpuopt_fastmem = ui->cpuopt_fastmem->isChecked();
Settings::values.cpuopt_fastmem_exclusives = ui->cpuopt_fastmem_exclusives->isChecked();
Settings::values.cpuopt_recompile_exclusives = ui->cpuopt_recompile_exclusives->isChecked();
Settings::values.cpuopt_ignore_memory_aborts = ui->cpuopt_ignore_memory_aborts->isChecked();
}
void ConfigureCpuDebug::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureCpuDebug::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QWidget>
namespace Core {
class System;
}
namespace Ui {
class ConfigureCpuDebug;
}
class ConfigureCpuDebug : public QWidget {
Q_OBJECT
public:
explicit ConfigureCpuDebug(const Core::System& system_, QWidget* parent = nullptr);
~ConfigureCpuDebug() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void SetConfiguration();
std::unique_ptr<Ui::ConfigureCpuDebug> ui;
const Core::System& system;
};

View File

@@ -0,0 +1,223 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureCpuDebug</class>
<widget class="QWidget" name="ConfigureCpuDebug">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>592</width>
<height>503</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>CPU</string>
</property>
<layout class="QVBoxLayout">
<item>
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Toggle CPU Optimizations</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;For debugging only.&lt;/span&gt;&lt;br/&gt;If you're not sure what these do, keep all of these enabled. &lt;br/&gt;These settings, when disabled, only take effect when CPU Debugging is enabled. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_page_tables">
<property name="toolTip">
<string>
&lt;div style=&quot;white-space: nowrap&quot;&gt;This optimization speeds up memory accesses by the guest program.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;Enabling it inlines accesses to PageTable::pointers into emitted code.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;Disabling this forces all memory accesses to go through the Memory::Read/Memory::Write functions.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable inline page tables</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_block_linking">
<property name="toolTip">
<string>
&lt;div&gt;This optimization avoids dispatcher lookups by allowing emitted basic blocks to jump directly to other basic blocks if the destination PC is static.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable block linking</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_return_stack_buffer">
<property name="toolTip">
<string>
&lt;div&gt;This optimization avoids dispatcher lookups by keeping track potential return addresses of BL instructions. This approximates what happens with a return stack buffer on a real CPU.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable return stack buffer</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_fast_dispatcher">
<property name="toolTip">
<string>
&lt;div&gt;Enable a two-tiered dispatch system. A faster dispatcher written in assembly has a small MRU cache of jump destinations is used first. If that fails, dispatch falls back to the slower C++ dispatcher.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable fast dispatcher</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_context_elimination">
<property name="toolTip">
<string>
&lt;div&gt;Enables an IR optimization that reduces unnecessary accesses to the CPU context structure.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable context elimination</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_const_prop">
<property name="toolTip">
<string>
&lt;div&gt;Enables IR optimizations that involve constant propagation.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable constant propagation</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_misc_ir">
<property name="toolTip">
<string>
&lt;div&gt;Enables miscellaneous IR optimizations.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable miscellaneous optimizations</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_reduce_misalign_checks">
<property name="toolTip">
<string>
&lt;div style=&quot;white-space: nowrap&quot;&gt;When enabled, a misalignment is only triggered when an access crosses a page boundary.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;When disabled, a misalignment is triggered on all misaligned accesses.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable misalignment check reduction</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_fastmem">
<property name="toolTip">
<string>
&lt;div style=&quot;white-space: nowrap&quot;&gt;This optimization speeds up memory accesses by the guest program.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;Enabling it causes guest memory reads/writes to be done directly into memory and make use of Host's MMU.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;Disabling this forces all memory accesses to use Software MMU Emulation.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable Host MMU Emulation (general memory instructions)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_fastmem_exclusives">
<property name="toolTip">
<string>
&lt;div style=&quot;white-space: nowrap&quot;&gt;This optimization speeds up exclusive memory accesses by the guest program.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;Enabling it causes guest exclusive memory reads/writes to be done directly into memory and make use of Host's MMU.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;Disabling this forces all exclusive memory accesses to use Software MMU Emulation.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable Host MMU Emulation (exclusive memory instructions)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_recompile_exclusives">
<property name="toolTip">
<string>
&lt;div style=&quot;white-space: nowrap&quot;&gt;This optimization speeds up exclusive memory accesses by the guest program.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;Enabling it reduces the overhead of fastmem failure of exclusive memory accesses.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable recompilation of exclusive memory instructions</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_ignore_memory_aborts">
<property name="toolTip">
<string>
&lt;div style=&quot;white-space: nowrap&quot;&gt;This optimization speeds up memory accesses by allowing invalid memory accesses to succeed.&lt;/div&gt;
&lt;div style=&quot;white-space: nowrap&quot;&gt;Enabling it reduces the overhead of all memory accesses and has no impact on programs that don't access invalid memory.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Enable fallbacks for invalid memory accesses</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<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>
<widget class="QLabel" name="label_disable_info">
<property name="text">
<string>CPU settings are available only when game is not running.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,130 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QDesktopServices>
#include <QMessageBox>
#include <QUrl>
#include "common/fs/path_util.h"
#include "common/logging/backend.h"
#include "common/logging/filter.h"
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_debug.h"
#include "suyu/configuration/configure_debug.h"
#include "suyu/debugger/console.h"
#include "suyu/uisettings.h"
ConfigureDebug::ConfigureDebug(const Core::System& system_, QWidget* parent)
: QScrollArea(parent), ui{std::make_unique<Ui::ConfigureDebug>()}, system{system_} {
ui->setupUi(this);
SetConfiguration();
connect(ui->open_log_button, &QPushButton::clicked, []() {
const auto path =
QString::fromStdString(Common::FS::GetSuyuPathString(Common::FS::SuyuPath::LogDir));
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
});
connect(ui->toggle_gdbstub, &QCheckBox::toggled,
[&]() { ui->gdbport_spinbox->setEnabled(ui->toggle_gdbstub->isChecked()); });
}
ConfigureDebug::~ConfigureDebug() = default;
void ConfigureDebug::SetConfiguration() {
const bool runtime_lock = !system.IsPoweredOn();
ui->toggle_gdbstub->setChecked(Settings::values.use_gdbstub.GetValue());
ui->gdbport_spinbox->setEnabled(Settings::values.use_gdbstub.GetValue());
ui->gdbport_spinbox->setValue(Settings::values.gdbstub_port.GetValue());
ui->toggle_console->setEnabled(runtime_lock);
ui->toggle_console->setChecked(UISettings::values.show_console.GetValue());
ui->log_filter_edit->setText(QString::fromStdString(Settings::values.log_filter.GetValue()));
ui->homebrew_args_edit->setText(
QString::fromStdString(Settings::values.program_args.GetValue()));
ui->fs_access_log->setEnabled(runtime_lock);
ui->fs_access_log->setChecked(Settings::values.enable_fs_access_log.GetValue());
ui->reporting_services->setChecked(Settings::values.reporting_services.GetValue());
ui->dump_audio_commands->setChecked(Settings::values.dump_audio_commands.GetValue());
ui->quest_flag->setChecked(Settings::values.quest_flag.GetValue());
ui->use_debug_asserts->setChecked(Settings::values.use_debug_asserts.GetValue());
ui->use_auto_stub->setChecked(Settings::values.use_auto_stub.GetValue());
ui->enable_all_controllers->setChecked(Settings::values.enable_all_controllers.GetValue());
ui->enable_renderdoc_hotkey->setEnabled(runtime_lock);
ui->enable_renderdoc_hotkey->setChecked(Settings::values.enable_renderdoc_hotkey.GetValue());
ui->disable_buffer_reorder->setEnabled(runtime_lock);
ui->disable_buffer_reorder->setChecked(Settings::values.disable_buffer_reorder.GetValue());
ui->enable_graphics_debugging->setEnabled(runtime_lock);
ui->enable_graphics_debugging->setChecked(Settings::values.renderer_debug.GetValue());
ui->enable_shader_feedback->setEnabled(runtime_lock);
ui->enable_shader_feedback->setChecked(Settings::values.renderer_shader_feedback.GetValue());
ui->enable_cpu_debugging->setEnabled(runtime_lock);
ui->enable_cpu_debugging->setChecked(Settings::values.cpu_debug_mode.GetValue());
ui->enable_nsight_aftermath->setEnabled(runtime_lock);
ui->enable_nsight_aftermath->setChecked(Settings::values.enable_nsight_aftermath.GetValue());
ui->dump_shaders->setEnabled(runtime_lock);
ui->dump_shaders->setChecked(Settings::values.dump_shaders.GetValue());
ui->dump_macros->setEnabled(runtime_lock);
ui->dump_macros->setChecked(Settings::values.dump_macros.GetValue());
ui->disable_macro_jit->setEnabled(runtime_lock);
ui->disable_macro_jit->setChecked(Settings::values.disable_macro_jit.GetValue());
ui->disable_macro_hle->setEnabled(runtime_lock);
ui->disable_macro_hle->setChecked(Settings::values.disable_macro_hle.GetValue());
ui->disable_loop_safety_checks->setEnabled(runtime_lock);
ui->disable_loop_safety_checks->setChecked(
Settings::values.disable_shader_loop_safety_checks.GetValue());
ui->extended_logging->setChecked(Settings::values.extended_logging.GetValue());
ui->perform_vulkan_check->setChecked(Settings::values.perform_vulkan_check.GetValue());
#ifdef SUYU_USE_QT_WEB_ENGINE
ui->disable_web_applet->setChecked(UISettings::values.disable_web_applet.GetValue());
#else
ui->disable_web_applet->setEnabled(false);
ui->disable_web_applet->setText(tr("Web applet not compiled"));
#endif
}
void ConfigureDebug::ApplyConfiguration() {
Settings::values.use_gdbstub = ui->toggle_gdbstub->isChecked();
Settings::values.gdbstub_port = ui->gdbport_spinbox->value();
UISettings::values.show_console = ui->toggle_console->isChecked();
Settings::values.log_filter = ui->log_filter_edit->text().toStdString();
Settings::values.program_args = ui->homebrew_args_edit->text().toStdString();
Settings::values.enable_fs_access_log = ui->fs_access_log->isChecked();
Settings::values.reporting_services = ui->reporting_services->isChecked();
Settings::values.dump_audio_commands = ui->dump_audio_commands->isChecked();
Settings::values.quest_flag = ui->quest_flag->isChecked();
Settings::values.use_debug_asserts = ui->use_debug_asserts->isChecked();
Settings::values.use_auto_stub = ui->use_auto_stub->isChecked();
Settings::values.enable_all_controllers = ui->enable_all_controllers->isChecked();
Settings::values.renderer_debug = ui->enable_graphics_debugging->isChecked();
Settings::values.enable_renderdoc_hotkey = ui->enable_renderdoc_hotkey->isChecked();
Settings::values.disable_buffer_reorder = ui->disable_buffer_reorder->isChecked();
Settings::values.renderer_shader_feedback = ui->enable_shader_feedback->isChecked();
Settings::values.cpu_debug_mode = ui->enable_cpu_debugging->isChecked();
Settings::values.enable_nsight_aftermath = ui->enable_nsight_aftermath->isChecked();
Settings::values.dump_shaders = ui->dump_shaders->isChecked();
Settings::values.dump_macros = ui->dump_macros->isChecked();
Settings::values.disable_shader_loop_safety_checks =
ui->disable_loop_safety_checks->isChecked();
Settings::values.disable_macro_jit = ui->disable_macro_jit->isChecked();
Settings::values.disable_macro_hle = ui->disable_macro_hle->isChecked();
Settings::values.extended_logging = ui->extended_logging->isChecked();
Settings::values.perform_vulkan_check = ui->perform_vulkan_check->isChecked();
UISettings::values.disable_web_applet = ui->disable_web_applet->isChecked();
Debugger::ToggleConsole();
Common::Log::Filter filter;
filter.ParseFilterString(Settings::values.log_filter.GetValue());
Common::Log::SetGlobalFilter(filter);
}
void ConfigureDebug::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureDebug::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QScrollArea>
namespace Core {
class System;
}
namespace Ui {
class ConfigureDebug;
}
class ConfigureDebug : public QScrollArea {
Q_OBJECT
public:
explicit ConfigureDebug(const Core::System& system_, QWidget* parent = nullptr);
~ConfigureDebug() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void SetConfiguration();
std::unique_ptr<Ui::ConfigureDebug> ui;
const Core::System& system;
bool crash_dump_warning_shown{false};
};

View File

@@ -0,0 +1,576 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureDebug</class>
<widget class="QScrollArea" name="ConfigureDebug">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>831</width>
<height>760</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>842</width>
<height>741</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Debugger</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QWidget" name="debug_widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="toggle_gdbstub">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable GDB Stub</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="horizontalWidget_3" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_11">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="gdbport_spinbox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Logging</string>
</property>
<layout class="QGridLayout" name="gridLayout_1">
<item row="1" column="1">
<widget class="QPushButton" name="open_log_button">
<property name="text">
<string>Open Log Location</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QWidget" name="logging_widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_1">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Global Log Filter</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="log_filter_edit"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="extended_logging">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>When checked, the max size of the log increases from 100 MB to 1 GB</string>
</property>
<property name="text">
<string>Enable Extended Logging**</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="toggle_console">
<property name="text">
<string>Show Log in Console</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Homebrew</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Arguments String</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="homebrew_args_edit"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Graphics</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="0">
<widget class="QCheckBox" name="disable_loop_safety_checks">
<property name="toolTip">
<string>When checked, it executes shaders without loop logic changes</string>
</property>
<property name="text">
<string>Disable Loop safety checks</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="dump_macros">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>When checked, it will dump all the macro programs of the GPU</string>
</property>
<property name="text">
<string>Dump Maxwell Macros</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="enable_nsight_aftermath">
<property name="toolTip">
<string>When checked, it enables Nsight Aftermath crash dumps</string>
</property>
<property name="text">
<string>Enable Nsight Aftermath</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="dump_shaders">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>When checked, it will dump all the original assembler shaders from the disk shader cache or game as found</string>
</property>
<property name="text">
<string>Dump Game Shaders</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="enable_renderdoc_hotkey">
<property name="text">
<string>Enable Renderdoc Hotkey</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="disable_macro_jit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>When checked, it disables the macro Just In Time compiler. Enabling this makes games run slower</string>
</property>
<property name="text">
<string>Disable Macro JIT</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="disable_macro_hle">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>When checked, it disables the macro HLE functions. Enabling this makes games run slower</string>
</property>
<property name="text">
<string>Disable Macro HLE</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="enable_graphics_debugging">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>When checked, the graphics API enters a slower debugging mode</string>
</property>
<property name="text">
<string>Enable Graphics Debugging</string>
</property>
</widget>
</item>
<item row="10" column="0">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="enable_shader_feedback">
<property name="toolTip">
<string>When checked, suyu will log statistics about the compiled pipeline cache</string>
</property>
<property name="text">
<string>Enable Shader Feedback</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="disable_buffer_reorder">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;When checked, disables reordering of mapped memory uploads which allows to associate uploads with specific draws. May reduce performance in some cases.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Disable Buffer Reorder</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Advanced</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="3" column="0">
<widget class="QCheckBox" name="perform_vulkan_check">
<property name="toolTip">
<string>Enables suyu to check for a working Vulkan environment when the program starts up. Disable this if this is causing issues with external programs seeing suyu.</string>
</property>
<property name="text">
<string>Perform Startup Vulkan Check</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="disable_web_applet">
<property name="text">
<string>Disable Web Applet</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="enable_all_controllers">
<property name="text">
<string>Enable All Controller Types</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="use_auto_stub">
<property name="text">
<string>Enable Auto-Stub**</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="quest_flag">
<property name="text">
<string>Kiosk (Quest) Mode</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="enable_cpu_debugging">
<property name="text">
<string>Enable CPU Debugging</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="use_debug_asserts">
<property name="text">
<string>Enable Debug Asserts</string>
</property>
</widget>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Debugging</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="fs_access_log">
<property name="text">
<string>Enable FS Access Log</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="dump_audio_commands">
<property name="toolTip">
<string>Enable this to output the latest generated audio command list to the console. Only affects games using the audio renderer.</string>
</property>
<property name="text">
<string>Dump Audio Commands To Console**</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="reporting_services">
<property name="text">
<string>Enable Verbose Reporting Services**</string>
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>**This will be reset automatically when suyu closes.</string>
</property>
<property name="indent">
<number>20</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<tabstops>
<tabstop>log_filter_edit</tabstop>
<tabstop>toggle_console</tabstop>
<tabstop>extended_logging</tabstop>
<tabstop>open_log_button</tabstop>
<tabstop>homebrew_args_edit</tabstop>
<tabstop>enable_graphics_debugging</tabstop>
<tabstop>enable_shader_feedback</tabstop>
<tabstop>enable_nsight_aftermath</tabstop>
<tabstop>fs_access_log</tabstop>
<tabstop>reporting_services</tabstop>
<tabstop>quest_flag</tabstop>
<tabstop>enable_cpu_debugging</tabstop>
<tabstop>use_debug_asserts</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "hid_core/hid_core.h"
#include "ui_configure_debug_controller.h"
#include "suyu/configuration/configure_debug_controller.h"
#include "suyu/configuration/configure_input_player.h"
ConfigureDebugController::ConfigureDebugController(QWidget* parent,
InputCommon::InputSubsystem* input_subsystem,
InputProfiles* profiles,
Core::HID::HIDCore& hid_core, bool is_powered_on)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureDebugController>()),
debug_controller(new ConfigureInputPlayer(this, 9, nullptr, input_subsystem, profiles,
hid_core, is_powered_on, true)) {
ui->setupUi(this);
ui->controllerLayout->addWidget(debug_controller);
connect(ui->clear_all_button, &QPushButton::clicked, this,
[this] { debug_controller->ClearAll(); });
connect(ui->restore_defaults_button, &QPushButton::clicked, this,
[this] { debug_controller->RestoreDefaults(); });
RetranslateUI();
}
ConfigureDebugController::~ConfigureDebugController() = default;
void ConfigureDebugController::ApplyConfiguration() {
debug_controller->ApplyConfiguration();
}
void ConfigureDebugController::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigureDebugController::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,45 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QDialog>
class QPushButton;
class ConfigureInputPlayer;
class InputProfiles;
namespace Core::HID {
class HIDCore;
}
namespace InputCommon {
class InputSubsystem;
}
namespace Ui {
class ConfigureDebugController;
}
class ConfigureDebugController : public QDialog {
Q_OBJECT
public:
explicit ConfigureDebugController(QWidget* parent, InputCommon::InputSubsystem* input_subsystem,
InputProfiles* profiles, Core::HID::HIDCore& hid_core,
bool is_powered_on);
~ConfigureDebugController() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
std::unique_ptr<Ui::ConfigureDebugController> ui;
ConfigureInputPlayer* debug_controller;
};

View File

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureDebugController</class>
<widget class="QDialog" name="ConfigureDebugController">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>780</width>
<height>500</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure Debug Controller</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" name="controllerLayout"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="clear_all_button">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="restore_defaults_button">
<property name="text">
<string>Defaults</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigureDebugController</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureDebugController</receiver>
<slot>reject()</slot>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,45 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include "ui_configure_debug_tab.h"
#include "suyu/configuration/configure_cpu_debug.h"
#include "suyu/configuration/configure_debug.h"
#include "suyu/configuration/configure_debug_tab.h"
ConfigureDebugTab::ConfigureDebugTab(const Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigureDebugTab>()},
debug_tab{std::make_unique<ConfigureDebug>(system_, this)},
cpu_debug_tab{std::make_unique<ConfigureCpuDebug>(system_, this)} {
ui->setupUi(this);
ui->tabWidget->addTab(debug_tab.get(), tr("Debug"));
ui->tabWidget->addTab(cpu_debug_tab.get(), tr("CPU"));
SetConfiguration();
}
ConfigureDebugTab::~ConfigureDebugTab() = default;
void ConfigureDebugTab::ApplyConfiguration() {
debug_tab->ApplyConfiguration();
cpu_debug_tab->ApplyConfiguration();
}
void ConfigureDebugTab::SetCurrentIndex(int index) {
ui->tabWidget->setCurrentIndex(index);
}
void ConfigureDebugTab::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureDebugTab::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureDebugTab::SetConfiguration() {}

View File

@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QWidget>
class ConfigureDebug;
class ConfigureCpuDebug;
namespace Core {
class System;
}
namespace Ui {
class ConfigureDebugTab;
}
class ConfigureDebugTab : public QWidget {
Q_OBJECT
public:
explicit ConfigureDebugTab(const Core::System& system_, QWidget* parent = nullptr);
~ConfigureDebugTab() override;
void ApplyConfiguration();
void SetCurrentIndex(int index);
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void SetConfiguration();
std::unique_ptr<Ui::ConfigureDebugTab> ui;
std::unique_ptr<ConfigureDebug> debug_tab;
std::unique_ptr<ConfigureCpuDebug> cpu_debug_tab;
};

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureDebugTab</class>
<widget class="QWidget" name="ConfigureDebugTab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>320</width>
<height>240</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>Debug</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,213 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include "common/logging/log.h"
#include "common/settings.h"
#include "common/settings_enums.h"
#include "core/core.h"
#include "ui_configure.h"
#include "vk_device_info.h"
#include "suyu/configuration/configure_applets.h"
#include "suyu/configuration/configure_audio.h"
#include "suyu/configuration/configure_cpu.h"
#include "suyu/configuration/configure_debug_tab.h"
#include "suyu/configuration/configure_dialog.h"
#include "suyu/configuration/configure_filesystem.h"
#include "suyu/configuration/configure_general.h"
#include "suyu/configuration/configure_graphics.h"
#include "suyu/configuration/configure_graphics_advanced.h"
#include "suyu/configuration/configure_hotkeys.h"
#include "suyu/configuration/configure_input.h"
#include "suyu/configuration/configure_input_player.h"
#include "suyu/configuration/configure_network.h"
#include "suyu/configuration/configure_profile_manager.h"
#include "suyu/configuration/configure_system.h"
#include "suyu/configuration/configure_ui.h"
#include "suyu/configuration/configure_web.h"
#include "suyu/hotkeys.h"
#include "suyu/uisettings.h"
ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
InputCommon::InputSubsystem* input_subsystem,
std::vector<VkDeviceInfo::Record>& vk_device_records,
Core::System& system_, bool enable_web_config)
: QDialog(parent), ui{std::make_unique<Ui::ConfigureDialog>()},
registry(registry_), system{system_}, builder{std::make_unique<ConfigurationShared::Builder>(
this, !system_.IsPoweredOn())},
applets_tab{std::make_unique<ConfigureApplets>(system_, nullptr, *builder, this)},
audio_tab{std::make_unique<ConfigureAudio>(system_, nullptr, *builder, this)},
cpu_tab{std::make_unique<ConfigureCpu>(system_, nullptr, *builder, this)},
debug_tab_tab{std::make_unique<ConfigureDebugTab>(system_, this)},
filesystem_tab{std::make_unique<ConfigureFilesystem>(this)},
general_tab{std::make_unique<ConfigureGeneral>(system_, nullptr, *builder, this)},
graphics_advanced_tab{
std::make_unique<ConfigureGraphicsAdvanced>(system_, nullptr, *builder, this)},
ui_tab{std::make_unique<ConfigureUi>(system_, this)},
graphics_tab{std::make_unique<ConfigureGraphics>(
system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); },
[this](Settings::AspectRatio ratio, Settings::ResolutionSetup setup) {
ui_tab->UpdateScreenshotInfo(ratio, setup);
},
nullptr, *builder, this)},
hotkeys_tab{std::make_unique<ConfigureHotkeys>(system_.HIDCore(), this)},
input_tab{std::make_unique<ConfigureInput>(system_, this)},
network_tab{std::make_unique<ConfigureNetwork>(system_, this)},
profile_tab{std::make_unique<ConfigureProfileManager>(system_, this)},
system_tab{std::make_unique<ConfigureSystem>(system_, nullptr, *builder, this)},
web_tab{std::make_unique<ConfigureWeb>(this)} {
Settings::SetConfiguringGlobal(true);
ui->setupUi(this);
ui->tabWidget->addTab(applets_tab.get(), tr("Applets"));
ui->tabWidget->addTab(audio_tab.get(), tr("Audio"));
ui->tabWidget->addTab(cpu_tab.get(), tr("CPU"));
ui->tabWidget->addTab(debug_tab_tab.get(), tr("Debug"));
ui->tabWidget->addTab(filesystem_tab.get(), tr("Filesystem"));
ui->tabWidget->addTab(general_tab.get(), tr("General"));
ui->tabWidget->addTab(graphics_tab.get(), tr("Graphics"));
ui->tabWidget->addTab(graphics_advanced_tab.get(), tr("GraphicsAdvanced"));
ui->tabWidget->addTab(hotkeys_tab.get(), tr("Hotkeys"));
ui->tabWidget->addTab(input_tab.get(), tr("Controls"));
ui->tabWidget->addTab(profile_tab.get(), tr("Profiles"));
ui->tabWidget->addTab(network_tab.get(), tr("Network"));
ui->tabWidget->addTab(system_tab.get(), tr("System"));
ui->tabWidget->addTab(ui_tab.get(), tr("Game List"));
ui->tabWidget->addTab(web_tab.get(), tr("Web"));
web_tab->SetWebServiceConfigEnabled(enable_web_config);
hotkeys_tab->Populate(registry);
input_tab->Initialize(input_subsystem);
general_tab->SetResetCallback([&] { this->close(); });
SetConfiguration();
PopulateSelectionList();
connect(ui->tabWidget, &QTabWidget::currentChanged, this, [this](int index) {
if (index != -1) {
debug_tab_tab->SetCurrentIndex(0);
}
});
connect(ui_tab.get(), &ConfigureUi::LanguageChanged, this, &ConfigureDialog::OnLanguageChanged);
connect(ui->selectorList, &QListWidget::itemSelectionChanged, this,
&ConfigureDialog::UpdateVisibleTabs);
if (system.IsPoweredOn()) {
QPushButton* apply_button = ui->buttonBox->addButton(QDialogButtonBox::Apply);
connect(apply_button, &QAbstractButton::clicked, this,
&ConfigureDialog::HandleApplyButtonClicked);
}
adjustSize();
ui->selectorList->setCurrentRow(0);
// Selects the leftmost button on the bottom bar (Cancel as of writing)
ui->buttonBox->setFocus();
}
ConfigureDialog::~ConfigureDialog() = default;
void ConfigureDialog::SetConfiguration() {}
void ConfigureDialog::ApplyConfiguration() {
general_tab->ApplyConfiguration();
ui_tab->ApplyConfiguration();
system_tab->ApplyConfiguration();
profile_tab->ApplyConfiguration();
filesystem_tab->ApplyConfiguration();
input_tab->ApplyConfiguration();
hotkeys_tab->ApplyConfiguration(registry);
cpu_tab->ApplyConfiguration();
graphics_tab->ApplyConfiguration();
graphics_advanced_tab->ApplyConfiguration();
audio_tab->ApplyConfiguration();
debug_tab_tab->ApplyConfiguration();
web_tab->ApplyConfiguration();
network_tab->ApplyConfiguration();
applets_tab->ApplyConfiguration();
system.ApplySettings();
Settings::LogSettings();
}
void ConfigureDialog::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigureDialog::RetranslateUI() {
const int old_row = ui->selectorList->currentRow();
const int old_index = ui->tabWidget->currentIndex();
ui->retranslateUi(this);
PopulateSelectionList();
ui->selectorList->setCurrentRow(old_row);
UpdateVisibleTabs();
ui->tabWidget->setCurrentIndex(old_index);
}
void ConfigureDialog::HandleApplyButtonClicked() {
UISettings::values.configuration_applied = true;
ApplyConfiguration();
}
Q_DECLARE_METATYPE(QList<QWidget*>);
void ConfigureDialog::PopulateSelectionList() {
const std::array<std::pair<QString, QList<QWidget*>>, 6> items{
{{tr("General"),
{general_tab.get(), hotkeys_tab.get(), ui_tab.get(), web_tab.get(), debug_tab_tab.get()}},
{tr("System"),
{system_tab.get(), profile_tab.get(), network_tab.get(), filesystem_tab.get(),
applets_tab.get()}},
{tr("CPU"), {cpu_tab.get()}},
{tr("Graphics"), {graphics_tab.get(), graphics_advanced_tab.get()}},
{tr("Audio"), {audio_tab.get()}},
{tr("Controls"), input_tab->GetSubTabs()}},
};
[[maybe_unused]] const QSignalBlocker blocker(ui->selectorList);
ui->selectorList->clear();
for (const auto& entry : items) {
auto* const item = new QListWidgetItem(entry.first);
item->setData(Qt::UserRole, QVariant::fromValue(entry.second));
ui->selectorList->addItem(item);
}
}
void ConfigureDialog::OnLanguageChanged(const QString& locale) {
emit LanguageChanged(locale);
// Reloading the game list is needed to force retranslation.
UISettings::values.is_game_list_reload_pending = true;
// first apply the configuration, and then restore the display
ApplyConfiguration();
RetranslateUI();
SetConfiguration();
}
void ConfigureDialog::UpdateVisibleTabs() {
const auto items = ui->selectorList->selectedItems();
if (items.isEmpty()) {
return;
}
[[maybe_unused]] const QSignalBlocker blocker(ui->tabWidget);
ui->tabWidget->clear();
const auto tabs = qvariant_cast<QList<QWidget*>>(items[0]->data(Qt::UserRole));
for (auto* const tab : tabs) {
LOG_DEBUG(Frontend, "{}", tab->accessibleName().toStdString());
ui->tabWidget->addTab(tab, tab->accessibleName());
}
}

View File

@@ -0,0 +1,94 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <vector>
#include <QDialog>
#include "configuration/shared_widget.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/shared_translation.h"
#include "suyu/vk_device_info.h"
namespace Core {
class System;
}
class ConfigureApplets;
class ConfigureAudio;
class ConfigureCpu;
class ConfigureDebugTab;
class ConfigureFilesystem;
class ConfigureGeneral;
class ConfigureGraphics;
class ConfigureGraphicsAdvanced;
class ConfigureHotkeys;
class ConfigureInput;
class ConfigureProfileManager;
class ConfigureSystem;
class ConfigureNetwork;
class ConfigureUi;
class ConfigureWeb;
class HotkeyRegistry;
namespace InputCommon {
class InputSubsystem;
}
namespace Ui {
class ConfigureDialog;
}
class ConfigureDialog : public QDialog {
Q_OBJECT
public:
explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
InputCommon::InputSubsystem* input_subsystem,
std::vector<VkDeviceInfo::Record>& vk_device_records,
Core::System& system_, bool enable_web_config = true);
~ConfigureDialog() override;
void ApplyConfiguration();
private slots:
void OnLanguageChanged(const QString& locale);
signals:
void LanguageChanged(const QString& locale);
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void HandleApplyButtonClicked();
void SetConfiguration();
void UpdateVisibleTabs();
void PopulateSelectionList();
std::unique_ptr<Ui::ConfigureDialog> ui;
HotkeyRegistry& registry;
Core::System& system;
std::unique_ptr<ConfigurationShared::Builder> builder;
std::vector<ConfigurationShared::Tab*> tab_group;
std::unique_ptr<ConfigureApplets> applets_tab;
std::unique_ptr<ConfigureAudio> audio_tab;
std::unique_ptr<ConfigureCpu> cpu_tab;
std::unique_ptr<ConfigureDebugTab> debug_tab_tab;
std::unique_ptr<ConfigureFilesystem> filesystem_tab;
std::unique_ptr<ConfigureGeneral> general_tab;
std::unique_ptr<ConfigureGraphicsAdvanced> graphics_advanced_tab;
std::unique_ptr<ConfigureUi> ui_tab;
std::unique_ptr<ConfigureGraphics> graphics_tab;
std::unique_ptr<ConfigureHotkeys> hotkeys_tab;
std::unique_ptr<ConfigureInput> input_tab;
std::unique_ptr<ConfigureNetwork> network_tab;
std::unique_ptr<ConfigureProfileManager> profile_tab;
std::unique_ptr<ConfigureSystem> system_tab;
std::unique_ptr<ConfigureWeb> web_tab;
};

View File

@@ -0,0 +1,155 @@
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QFileDialog>
#include <QMessageBox>
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
#include "common/settings.h"
#include "ui_configure_filesystem.h"
#include "suyu/configuration/configure_filesystem.h"
#include "suyu/uisettings.h"
ConfigureFilesystem::ConfigureFilesystem(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureFilesystem>()) {
ui->setupUi(this);
SetConfiguration();
connect(ui->nand_directory_button, &QToolButton::pressed, this,
[this] { SetDirectory(DirectoryTarget::NAND, ui->nand_directory_edit); });
connect(ui->sdmc_directory_button, &QToolButton::pressed, this,
[this] { SetDirectory(DirectoryTarget::SD, ui->sdmc_directory_edit); });
connect(ui->gamecard_path_button, &QToolButton::pressed, this,
[this] { SetDirectory(DirectoryTarget::Gamecard, ui->gamecard_path_edit); });
connect(ui->dump_path_button, &QToolButton::pressed, this,
[this] { SetDirectory(DirectoryTarget::Dump, ui->dump_path_edit); });
connect(ui->load_path_button, &QToolButton::pressed, this,
[this] { SetDirectory(DirectoryTarget::Load, ui->load_path_edit); });
connect(ui->reset_game_list_cache, &QPushButton::pressed, this,
&ConfigureFilesystem::ResetMetadata);
connect(ui->gamecard_inserted, &QCheckBox::stateChanged, this,
&ConfigureFilesystem::UpdateEnabledControls);
connect(ui->gamecard_current_game, &QCheckBox::stateChanged, this,
&ConfigureFilesystem::UpdateEnabledControls);
}
ConfigureFilesystem::~ConfigureFilesystem() = default;
void ConfigureFilesystem::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureFilesystem::SetConfiguration() {
ui->nand_directory_edit->setText(
QString::fromStdString(Common::FS::GetSuyuPathString(Common::FS::SuyuPath::NANDDir)));
ui->sdmc_directory_edit->setText(
QString::fromStdString(Common::FS::GetSuyuPathString(Common::FS::SuyuPath::SDMCDir)));
ui->gamecard_path_edit->setText(
QString::fromStdString(Settings::values.gamecard_path.GetValue()));
ui->dump_path_edit->setText(
QString::fromStdString(Common::FS::GetSuyuPathString(Common::FS::SuyuPath::DumpDir)));
ui->load_path_edit->setText(
QString::fromStdString(Common::FS::GetSuyuPathString(Common::FS::SuyuPath::LoadDir)));
ui->gamecard_inserted->setChecked(Settings::values.gamecard_inserted.GetValue());
ui->gamecard_current_game->setChecked(Settings::values.gamecard_current_game.GetValue());
ui->dump_exefs->setChecked(Settings::values.dump_exefs.GetValue());
ui->dump_nso->setChecked(Settings::values.dump_nso.GetValue());
ui->cache_game_list->setChecked(UISettings::values.cache_game_list.GetValue());
UpdateEnabledControls();
}
void ConfigureFilesystem::ApplyConfiguration() {
Common::FS::SetSuyuPath(Common::FS::SuyuPath::NANDDir,
ui->nand_directory_edit->text().toStdString());
Common::FS::SetSuyuPath(Common::FS::SuyuPath::SDMCDir,
ui->sdmc_directory_edit->text().toStdString());
Common::FS::SetSuyuPath(Common::FS::SuyuPath::DumpDir,
ui->dump_path_edit->text().toStdString());
Common::FS::SetSuyuPath(Common::FS::SuyuPath::LoadDir,
ui->load_path_edit->text().toStdString());
Settings::values.gamecard_inserted = ui->gamecard_inserted->isChecked();
Settings::values.gamecard_current_game = ui->gamecard_current_game->isChecked();
Settings::values.dump_exefs = ui->dump_exefs->isChecked();
Settings::values.dump_nso = ui->dump_nso->isChecked();
UISettings::values.cache_game_list = ui->cache_game_list->isChecked();
}
void ConfigureFilesystem::SetDirectory(DirectoryTarget target, QLineEdit* edit) {
QString caption;
switch (target) {
case DirectoryTarget::NAND:
caption = tr("Select Emulated NAND Directory...");
break;
case DirectoryTarget::SD:
caption = tr("Select Emulated SD Directory...");
break;
case DirectoryTarget::Gamecard:
caption = tr("Select Gamecard Path...");
break;
case DirectoryTarget::Dump:
caption = tr("Select Dump Directory...");
break;
case DirectoryTarget::Load:
caption = tr("Select Mod Load Directory...");
break;
}
QString str;
if (target == DirectoryTarget::Gamecard) {
str = QFileDialog::getOpenFileName(this, caption, QFileInfo(edit->text()).dir().path(),
QStringLiteral("NX Gamecard;*.xci"));
} else {
str = QFileDialog::getExistingDirectory(this, caption, edit->text());
}
if (str.isNull() || str.isEmpty()) {
return;
}
if (str.back() != QChar::fromLatin1('/')) {
str.append(QChar::fromLatin1('/'));
}
edit->setText(str);
}
void ConfigureFilesystem::ResetMetadata() {
if (!Common::FS::Exists(Common::FS::GetSuyuPath(Common::FS::SuyuPath::CacheDir) /
"game_list/")) {
QMessageBox::information(this, tr("Reset Metadata Cache"),
tr("The metadata cache is already empty."));
} else if (Common::FS::RemoveDirRecursively(
Common::FS::GetSuyuPath(Common::FS::SuyuPath::CacheDir) / "game_list")) {
QMessageBox::information(this, tr("Reset Metadata Cache"),
tr("The operation completed successfully."));
UISettings::values.is_game_list_reload_pending.exchange(true);
} else {
QMessageBox::warning(
this, tr("Reset Metadata Cache"),
tr("The metadata cache couldn't be deleted. It might be in use or non-existent."));
}
}
void ConfigureFilesystem::UpdateEnabledControls() {
ui->gamecard_current_game->setEnabled(ui->gamecard_inserted->isChecked());
ui->gamecard_path_edit->setEnabled(ui->gamecard_inserted->isChecked() &&
!ui->gamecard_current_game->isChecked());
ui->gamecard_path_button->setEnabled(ui->gamecard_inserted->isChecked() &&
!ui->gamecard_current_game->isChecked());
}
void ConfigureFilesystem::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QWidget>
class QLineEdit;
namespace Ui {
class ConfigureFilesystem;
}
class ConfigureFilesystem : public QWidget {
Q_OBJECT
public:
explicit ConfigureFilesystem(QWidget* parent = nullptr);
~ConfigureFilesystem() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void SetConfiguration();
enum class DirectoryTarget {
NAND,
SD,
Gamecard,
Dump,
Load,
};
void SetDirectory(DirectoryTarget target, QLineEdit* edit);
void ResetMetadata();
void UpdateEnabledControls();
std::unique_ptr<Ui::ConfigureFilesystem> ui;
};

View File

@@ -0,0 +1,244 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureFilesystem</class>
<widget class="QWidget" name="ConfigureFilesystem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>453</width>
<height>561</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>Filesystem</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Storage Directories</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>NAND</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="nand_directory_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="nand_directory_edit"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="sdmc_directory_edit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>SD Card</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QToolButton" name="sdmc_directory_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>60</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Gamecard</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Path</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="gamecard_path_edit"/>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="gamecard_inserted">
<property name="text">
<string>Inserted</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="gamecard_current_game">
<property name="text">
<string>Current Game</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QToolButton" name="gamecard_path_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Patch Manager</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="2">
<widget class="QLineEdit" name="load_path_edit"/>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="dump_path_edit"/>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="dump_path_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QToolButton" name="load_path_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="dump_nso">
<property name="text">
<string>Dump Decompressed NSOs</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="dump_exefs">
<property name="text">
<string>Dump ExeFS</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Mod Load Root</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Dump Root</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Caching</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="cache_game_list">
<property name="text">
<string>Cache Game List Metadata</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reset_game_list_cache">
<property name="text">
<string>Reset Metadata Cache</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,128 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <functional>
#include <utility>
#include <vector>
#include <QMessageBox>
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_general.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_general.h"
#include "suyu/configuration/shared_widget.h"
#include "suyu/uisettings.h"
ConfigureGeneral::ConfigureGeneral(const Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::Builder& builder, QWidget* parent)
: Tab(group_, parent), ui{std::make_unique<Ui::ConfigureGeneral>()}, system{system_} {
ui->setupUi(this);
Setup(builder);
SetConfiguration();
connect(ui->button_reset_defaults, &QPushButton::clicked, this,
&ConfigureGeneral::ResetDefaults);
if (!Settings::IsConfiguringGlobal()) {
ui->button_reset_defaults->setVisible(false);
}
}
ConfigureGeneral::~ConfigureGeneral() = default;
void ConfigureGeneral::SetConfiguration() {}
void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) {
QLayout& general_layout = *ui->general_widget->layout();
QLayout& linux_layout = *ui->linux_widget->layout();
std::map<u32, QWidget*> general_hold{};
std::map<u32, QWidget*> linux_hold{};
std::vector<Settings::BasicSetting*> settings;
auto push = [&settings](auto& list) {
for (auto setting : list) {
settings.push_back(setting);
}
};
push(UISettings::values.linkage.by_category[Settings::Category::UiGeneral]);
push(Settings::values.linkage.by_category[Settings::Category::Linux]);
// Only show Linux group on Unix
#ifndef __unix__
ui->LinuxGroupBox->setVisible(false);
#endif
for (const auto setting : settings) {
auto* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
widget->deleteLater();
continue;
}
switch (setting->GetCategory()) {
case Settings::Category::UiGeneral:
general_hold.emplace(setting->Id(), widget);
break;
case Settings::Category::Linux:
linux_hold.emplace(setting->Id(), widget);
break;
default:
widget->deleteLater();
}
}
for (const auto& [id, widget] : general_hold) {
general_layout.addWidget(widget);
}
for (const auto& [id, widget] : linux_hold) {
linux_layout.addWidget(widget);
}
}
// Called to set the callback when resetting settings to defaults
void ConfigureGeneral::SetResetCallback(std::function<void()> callback) {
reset_callback = std::move(callback);
}
void ConfigureGeneral::ResetDefaults() {
QMessageBox::StandardButton answer = QMessageBox::question(
this, tr("suyu"),
tr("This reset all settings and remove all per-game configurations. This will not delete "
"game directories, profiles, or input profiles. Proceed?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (answer == QMessageBox::No) {
return;
}
UISettings::values.reset_to_defaults = true;
UISettings::values.is_game_list_reload_pending.exchange(true);
reset_callback();
}
void ConfigureGeneral::ApplyConfiguration() {
bool powered_on = system.IsPoweredOn();
for (const auto& func : apply_funcs) {
func(powered_on);
}
}
void ConfigureGeneral::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureGeneral::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <functional>
#include <memory>
#include <vector>
#include <QWidget>
#include "suyu/configuration/configuration_shared.h"
namespace Core {
class System;
}
class ConfigureDialog;
class HotkeyRegistry;
namespace Ui {
class ConfigureGeneral;
}
namespace ConfigurationShared {
class Builder;
}
class ConfigureGeneral : public ConfigurationShared::Tab {
Q_OBJECT
public:
explicit ConfigureGeneral(const Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group,
const ConfigurationShared::Builder& builder,
QWidget* parent = nullptr);
~ConfigureGeneral() override;
void SetResetCallback(std::function<void()> callback);
void ResetDefaults();
void ApplyConfiguration() override;
void SetConfiguration() override;
private:
void Setup(const ConfigurationShared::Builder& builder);
void changeEvent(QEvent* event) override;
void RetranslateUI();
std::function<void()> reset_callback;
std::unique_ptr<Ui::ConfigureGeneral> ui;
std::vector<std::function<void(bool)>> apply_funcs{};
const Core::System& system;
};

View File

@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureGeneral</class>
<widget class="QWidget" name="ConfigureGeneral">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>744</width>
<height>568</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>General</string>
</property>
<layout class="QHBoxLayout" name="HorizontalLayout">
<item>
<layout class="QVBoxLayout" name="VerticalLayout">
<item>
<widget class="QGroupBox" name="GeneralGroupBox">
<property name="title">
<string>General</string>
</property>
<layout class="QHBoxLayout" name="GeneralHorizontalLayout">
<item>
<widget class="QWidget" name="general_widget" native="true">
<layout class="QVBoxLayout" name="GeneralVerticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="LinuxGroupBox">
<property name="title">
<string>Linux</string>
</property>
<layout class="QVBoxLayout" name="LinuxVerticalLayout_1">
<item>
<widget class="QWidget" name="linux_widget" native="true">
<layout class="QVBoxLayout" name="LinuxVerticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<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>
<layout class="QHBoxLayout" name="layout_reset">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QPushButton" name="button_reset_defaults">
<property name="text">
<string>Reset All Settings</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer_reset">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,552 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include <functional>
#include <iosfwd>
#include <iterator>
#include <string>
#include <tuple>
#include <typeinfo>
#include <utility>
#include <vector>
#include <QBoxLayout>
#include <QCheckBox>
#include <QColorDialog>
#include <QComboBox>
#include <QIcon>
#include <QLabel>
#include <QLineEdit>
#include <QPixmap>
#include <QPushButton>
#include <QSlider>
#include <QStringLiteral>
#include <QtCore/qobjectdefs.h>
#include <qabstractbutton.h>
#include <qboxlayout.h>
#include <qcombobox.h>
#include <qcoreevent.h>
#include <qglobal.h>
#include <qgridlayout.h>
#include <vulkan/vulkan_core.h>
#include "common/common_types.h"
#include "common/dynamic_library.h"
#include "common/logging/log.h"
#include "common/settings.h"
#include "common/settings_enums.h"
#include "core/core.h"
#include "ui_configure_graphics.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_graphics.h"
#include "suyu/configuration/shared_widget.h"
#include "suyu/qt_common.h"
#include "suyu/uisettings.h"
#include "suyu/vk_device_info.h"
static const std::vector<VkPresentModeKHR> default_present_modes{VK_PRESENT_MODE_IMMEDIATE_KHR,
VK_PRESENT_MODE_FIFO_KHR};
// Converts a setting to a present mode (or vice versa)
static constexpr VkPresentModeKHR VSyncSettingToMode(Settings::VSyncMode mode) {
switch (mode) {
case Settings::VSyncMode::Immediate:
return VK_PRESENT_MODE_IMMEDIATE_KHR;
case Settings::VSyncMode::Mailbox:
return VK_PRESENT_MODE_MAILBOX_KHR;
case Settings::VSyncMode::Fifo:
return VK_PRESENT_MODE_FIFO_KHR;
case Settings::VSyncMode::FifoRelaxed:
return VK_PRESENT_MODE_FIFO_RELAXED_KHR;
default:
return VK_PRESENT_MODE_FIFO_KHR;
}
}
static constexpr Settings::VSyncMode PresentModeToSetting(VkPresentModeKHR mode) {
switch (mode) {
case VK_PRESENT_MODE_IMMEDIATE_KHR:
return Settings::VSyncMode::Immediate;
case VK_PRESENT_MODE_MAILBOX_KHR:
return Settings::VSyncMode::Mailbox;
case VK_PRESENT_MODE_FIFO_KHR:
return Settings::VSyncMode::Fifo;
case VK_PRESENT_MODE_FIFO_RELAXED_KHR:
return Settings::VSyncMode::FifoRelaxed;
default:
return Settings::VSyncMode::Fifo;
}
}
ConfigureGraphics::ConfigureGraphics(
const Core::System& system_, std::vector<VkDeviceInfo::Record>& records_,
const std::function<void()>& expose_compute_option_,
const std::function<void(Settings::AspectRatio, Settings::ResolutionSetup)>&
update_aspect_ratio_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::Builder& builder, QWidget* parent)
: ConfigurationShared::Tab(group_, parent), ui{std::make_unique<Ui::ConfigureGraphics>()},
records{records_}, expose_compute_option{expose_compute_option_},
update_aspect_ratio{update_aspect_ratio_}, system{system_},
combobox_translations{builder.ComboboxTranslations()},
shader_mapping{
combobox_translations.at(Settings::EnumMetadata<Settings::ShaderBackend>::Index())} {
vulkan_device = Settings::values.vulkan_device.GetValue();
RetrieveVulkanDevices();
ui->setupUi(this);
Setup(builder);
for (const auto& device : vulkan_devices) {
vulkan_device_combobox->addItem(device);
}
UpdateBackgroundColorButton(QColor::fromRgb(Settings::values.bg_red.GetValue(),
Settings::values.bg_green.GetValue(),
Settings::values.bg_blue.GetValue()));
UpdateAPILayout();
PopulateVSyncModeSelection(false); //< must happen after UpdateAPILayout
// VSync setting needs to be determined after populating the VSync combobox
const auto vsync_mode_setting = Settings::values.vsync_mode.GetValue();
const auto vsync_mode = VSyncSettingToMode(vsync_mode_setting);
int index{};
for (const auto mode : vsync_mode_combobox_enum_map) {
if (mode == vsync_mode) {
break;
}
index++;
}
if (static_cast<unsigned long>(index) < vsync_mode_combobox_enum_map.size()) {
vsync_mode_combobox->setCurrentIndex(index);
}
connect(api_combobox, qOverload<int>(&QComboBox::activated), this, [this] {
UpdateAPILayout();
PopulateVSyncModeSelection(false);
});
connect(vulkan_device_combobox, qOverload<int>(&QComboBox::activated), this,
[this](int device) {
UpdateDeviceSelection(device);
PopulateVSyncModeSelection(false);
});
connect(shader_backend_combobox, qOverload<int>(&QComboBox::activated), this,
[this](int backend) { UpdateShaderBackendSelection(backend); });
connect(ui->bg_button, &QPushButton::clicked, this, [this] {
const QColor new_bg_color = QColorDialog::getColor(bg_color);
if (!new_bg_color.isValid()) {
return;
}
UpdateBackgroundColorButton(new_bg_color);
});
const auto& update_screenshot_info = [this, &builder]() {
const auto& combobox_enumerations = builder.ComboboxTranslations().at(
Settings::EnumMetadata<Settings::AspectRatio>::Index());
const auto ratio_index = aspect_ratio_combobox->currentIndex();
const auto ratio =
static_cast<Settings::AspectRatio>(combobox_enumerations[ratio_index].first);
const auto& combobox_enumerations_resolution = builder.ComboboxTranslations().at(
Settings::EnumMetadata<Settings::ResolutionSetup>::Index());
const auto res_index = resolution_combobox->currentIndex();
const auto setup = static_cast<Settings::ResolutionSetup>(
combobox_enumerations_resolution[res_index].first);
update_aspect_ratio(ratio, setup);
};
connect(aspect_ratio_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged),
update_screenshot_info);
connect(resolution_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged),
update_screenshot_info);
api_combobox->setEnabled(!UISettings::values.has_broken_vulkan && api_combobox->isEnabled());
ui->api_widget->setEnabled(
(!UISettings::values.has_broken_vulkan || Settings::IsConfiguringGlobal()) &&
ui->api_widget->isEnabled());
if (Settings::IsConfiguringGlobal()) {
ui->bg_widget->setEnabled(Settings::values.bg_red.UsingGlobal());
}
}
void ConfigureGraphics::PopulateVSyncModeSelection(bool use_setting) {
const Settings::RendererBackend backend{GetCurrentGraphicsBackend()};
if (backend == Settings::RendererBackend::Null) {
vsync_mode_combobox->setEnabled(false);
return;
}
vsync_mode_combobox->setEnabled(true);
const int current_index = //< current selected vsync mode from combobox
vsync_mode_combobox->currentIndex();
const auto current_mode = //< current selected vsync mode as a VkPresentModeKHR
current_index == -1 || use_setting
? VSyncSettingToMode(Settings::values.vsync_mode.GetValue())
: vsync_mode_combobox_enum_map[current_index];
int index{};
const int device{vulkan_device_combobox->currentIndex()}; //< current selected Vulkan device
const auto& present_modes = //< relevant vector of present modes for the selected device or API
backend == Settings::RendererBackend::Vulkan && device > -1 ? device_present_modes[device]
: default_present_modes;
vsync_mode_combobox->clear();
vsync_mode_combobox_enum_map.clear();
vsync_mode_combobox_enum_map.reserve(present_modes.size());
for (const auto present_mode : present_modes) {
const auto mode_name = TranslateVSyncMode(present_mode, backend);
if (mode_name.isEmpty()) {
continue;
}
vsync_mode_combobox->insertItem(index, mode_name);
vsync_mode_combobox_enum_map.push_back(present_mode);
if (present_mode == current_mode) {
vsync_mode_combobox->setCurrentIndex(index);
}
index++;
}
if (!Settings::IsConfiguringGlobal()) {
vsync_restore_global_button->setVisible(!Settings::values.vsync_mode.UsingGlobal());
const Settings::VSyncMode global_vsync_mode = Settings::values.vsync_mode.GetValue(true);
vsync_restore_global_button->setEnabled(
(backend == Settings::RendererBackend::OpenGL &&
(global_vsync_mode == Settings::VSyncMode::Immediate ||
global_vsync_mode == Settings::VSyncMode::Fifo)) ||
backend == Settings::RendererBackend::Vulkan);
}
}
void ConfigureGraphics::UpdateVsyncSetting() const {
const Settings::RendererBackend backend{GetCurrentGraphicsBackend()};
if (backend == Settings::RendererBackend::Null) {
return;
}
const auto mode = vsync_mode_combobox_enum_map[vsync_mode_combobox->currentIndex()];
const auto vsync_mode = PresentModeToSetting(mode);
Settings::values.vsync_mode.SetValue(vsync_mode);
}
void ConfigureGraphics::UpdateDeviceSelection(int device) {
if (device == -1) {
return;
}
if (GetCurrentGraphicsBackend() == Settings::RendererBackend::Vulkan) {
vulkan_device = device;
}
}
void ConfigureGraphics::UpdateShaderBackendSelection(int backend) {
if (backend == -1) {
return;
}
if (GetCurrentGraphicsBackend() == Settings::RendererBackend::OpenGL) {
shader_backend = static_cast<Settings::ShaderBackend>(backend);
}
}
ConfigureGraphics::~ConfigureGraphics() = default;
void ConfigureGraphics::SetConfiguration() {}
void ConfigureGraphics::Setup(const ConfigurationShared::Builder& builder) {
QLayout* api_layout = ui->api_widget->layout();
QWidget* api_grid_widget = new QWidget(this);
QVBoxLayout* api_grid_layout = new QVBoxLayout(api_grid_widget);
api_grid_layout->setContentsMargins(0, 0, 0, 0);
api_layout->addWidget(api_grid_widget);
QLayout& graphics_layout = *ui->graphics_widget->layout();
std::map<u32, QWidget*> hold_graphics;
std::vector<QWidget*> hold_api;
for (const auto setting : Settings::values.linkage.by_category[Settings::Category::Renderer]) {
ConfigurationShared::Widget* widget = [&]() {
if (setting->Id() == Settings::values.fsr_sharpening_slider.Id()) {
// FSR needs a reversed slider and a 0.5 multiplier
return builder.BuildWidget(
setting, apply_funcs, ConfigurationShared::RequestType::ReverseSlider, true,
0.5f, nullptr, tr("%", "FSR sharpening percentage (e.g. 50%)"));
} else {
return builder.BuildWidget(setting, apply_funcs);
}
}();
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
widget->deleteLater();
continue;
}
if (setting->Id() == Settings::values.renderer_backend.Id()) {
// Add the renderer combobox now so it's at the top
api_grid_layout->addWidget(widget);
api_combobox = widget->combobox;
api_restore_global_button = widget->restore_button;
if (!Settings::IsConfiguringGlobal()) {
QObject::connect(api_restore_global_button, &QAbstractButton::clicked,
[this](bool) { UpdateAPILayout(); });
// Detach API's restore button and place it where we want
// Lets us put it on the side, and it will automatically scale if there's a
// second combobox (shader_backend, vulkan_device)
widget->layout()->removeWidget(api_restore_global_button);
api_layout->addWidget(api_restore_global_button);
}
} else if (setting->Id() == Settings::values.vulkan_device.Id()) {
// Keep track of vulkan_device's combobox so we can populate it
hold_api.push_back(widget);
vulkan_device_combobox = widget->combobox;
vulkan_device_widget = widget;
} else if (setting->Id() == Settings::values.shader_backend.Id()) {
// Keep track of shader_backend's combobox so we can populate it
hold_api.push_back(widget);
shader_backend_combobox = widget->combobox;
shader_backend_widget = widget;
} else if (setting->Id() == Settings::values.vsync_mode.Id()) {
// Keep track of vsync_mode's combobox so we can populate it
vsync_mode_combobox = widget->combobox;
// Since vsync is populated at runtime, we have to manually set up the button for
// restoring the global setting.
if (!Settings::IsConfiguringGlobal()) {
QPushButton* restore_button =
ConfigurationShared::Widget::CreateRestoreGlobalButton(
Settings::values.vsync_mode.UsingGlobal(), widget);
restore_button->setEnabled(true);
widget->layout()->addWidget(restore_button);
QObject::connect(restore_button, &QAbstractButton::clicked,
[restore_button, this](bool) {
Settings::values.vsync_mode.SetGlobal(true);
PopulateVSyncModeSelection(true);
restore_button->setVisible(false);
});
std::function<void()> set_non_global = [restore_button, this]() {
Settings::values.vsync_mode.SetGlobal(false);
UpdateVsyncSetting();
restore_button->setVisible(true);
};
QObject::connect(widget->combobox, QOverload<int>::of(&QComboBox::activated),
[set_non_global]() { set_non_global(); });
vsync_restore_global_button = restore_button;
}
hold_graphics.emplace(setting->Id(), widget);
} else if (setting->Id() == Settings::values.aspect_ratio.Id()) {
// Keep track of the aspect ratio combobox to update other UI tabs that need it
aspect_ratio_combobox = widget->combobox;
hold_graphics.emplace(setting->Id(), widget);
} else if (setting->Id() == Settings::values.resolution_setup.Id()) {
// Keep track of the resolution combobox to update other UI tabs that need it
resolution_combobox = widget->combobox;
hold_graphics.emplace(setting->Id(), widget);
} else {
hold_graphics.emplace(setting->Id(), widget);
}
}
for (const auto& [id, widget] : hold_graphics) {
graphics_layout.addWidget(widget);
}
for (auto widget : hold_api) {
api_grid_layout->addWidget(widget);
}
// Background color is too specific to build into the new system, so we manage it here
// (3 settings, all collected into a single widget with a QColor to manage on top)
if (Settings::IsConfiguringGlobal()) {
apply_funcs.push_back([this](bool powered_on) {
Settings::values.bg_red.SetValue(static_cast<u8>(bg_color.red()));
Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
});
} else {
QPushButton* bg_restore_button = ConfigurationShared::Widget::CreateRestoreGlobalButton(
Settings::values.bg_red.UsingGlobal(), ui->bg_widget);
ui->bg_widget->layout()->addWidget(bg_restore_button);
QObject::connect(bg_restore_button, &QAbstractButton::clicked,
[bg_restore_button, this](bool) {
const int r = Settings::values.bg_red.GetValue(true);
const int g = Settings::values.bg_green.GetValue(true);
const int b = Settings::values.bg_blue.GetValue(true);
UpdateBackgroundColorButton(QColor::fromRgb(r, g, b));
bg_restore_button->setVisible(false);
bg_restore_button->setEnabled(false);
});
QObject::connect(ui->bg_button, &QAbstractButton::clicked, [bg_restore_button](bool) {
bg_restore_button->setVisible(true);
bg_restore_button->setEnabled(true);
});
apply_funcs.push_back([bg_restore_button, this](bool powered_on) {
const bool using_global = !bg_restore_button->isEnabled();
Settings::values.bg_red.SetGlobal(using_global);
Settings::values.bg_green.SetGlobal(using_global);
Settings::values.bg_blue.SetGlobal(using_global);
if (!using_global) {
Settings::values.bg_red.SetValue(static_cast<u8>(bg_color.red()));
Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
}
});
}
}
const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode,
Settings::RendererBackend backend) const {
switch (mode) {
case VK_PRESENT_MODE_IMMEDIATE_KHR:
return backend == Settings::RendererBackend::OpenGL
? tr("Off")
: QStringLiteral("Immediate (%1)").arg(tr("VSync Off"));
case VK_PRESENT_MODE_MAILBOX_KHR:
return QStringLiteral("Mailbox (%1)").arg(tr("Recommended"));
case VK_PRESENT_MODE_FIFO_KHR:
return backend == Settings::RendererBackend::OpenGL
? tr("On")
: QStringLiteral("FIFO (%1)").arg(tr("VSync On"));
case VK_PRESENT_MODE_FIFO_RELAXED_KHR:
return QStringLiteral("FIFO Relaxed");
default:
return {};
break;
}
}
int ConfigureGraphics::FindIndex(u32 enumeration, int value) const {
for (u32 i = 0; i < combobox_translations.at(enumeration).size(); i++) {
if (combobox_translations.at(enumeration)[i].first == static_cast<u32>(value)) {
return i;
}
}
return -1;
}
void ConfigureGraphics::ApplyConfiguration() {
const bool powered_on = system.IsPoweredOn();
for (const auto& func : apply_funcs) {
func(powered_on);
}
UpdateVsyncSetting();
Settings::values.vulkan_device.SetGlobal(true);
Settings::values.shader_backend.SetGlobal(true);
if (Settings::IsConfiguringGlobal() ||
(!Settings::IsConfiguringGlobal() && api_restore_global_button->isEnabled())) {
auto backend = static_cast<Settings::RendererBackend>(
combobox_translations
.at(Settings::EnumMetadata<
Settings::RendererBackend>::Index())[api_combobox->currentIndex()]
.first);
switch (backend) {
case Settings::RendererBackend::OpenGL:
Settings::values.shader_backend.SetGlobal(Settings::IsConfiguringGlobal());
Settings::values.shader_backend.SetValue(static_cast<Settings::ShaderBackend>(
shader_mapping[shader_backend_combobox->currentIndex()].first));
break;
case Settings::RendererBackend::Vulkan:
Settings::values.vulkan_device.SetGlobal(Settings::IsConfiguringGlobal());
Settings::values.vulkan_device.SetValue(vulkan_device_combobox->currentIndex());
break;
case Settings::RendererBackend::Null:
break;
}
}
}
void ConfigureGraphics::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureGraphics::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureGraphics::UpdateBackgroundColorButton(QColor color) {
bg_color = color;
QPixmap pixmap(ui->bg_button->size());
pixmap.fill(bg_color);
const QIcon color_icon(pixmap);
ui->bg_button->setIcon(color_icon);
}
void ConfigureGraphics::UpdateAPILayout() {
bool runtime_lock = !system.IsPoweredOn();
bool need_global = !(Settings::IsConfiguringGlobal() || api_restore_global_button->isEnabled());
vulkan_device = Settings::values.vulkan_device.GetValue(need_global);
shader_backend = Settings::values.shader_backend.GetValue(need_global);
vulkan_device_widget->setEnabled(!need_global && runtime_lock);
shader_backend_widget->setEnabled(!need_global && runtime_lock);
const auto current_backend = GetCurrentGraphicsBackend();
const bool is_opengl = current_backend == Settings::RendererBackend::OpenGL;
const bool is_vulkan = current_backend == Settings::RendererBackend::Vulkan;
vulkan_device_widget->setVisible(is_vulkan);
shader_backend_widget->setVisible(is_opengl);
if (is_opengl) {
shader_backend_combobox->setCurrentIndex(
FindIndex(Settings::EnumMetadata<Settings::ShaderBackend>::Index(),
static_cast<int>(shader_backend)));
} else if (is_vulkan && static_cast<int>(vulkan_device) < vulkan_device_combobox->count()) {
vulkan_device_combobox->setCurrentIndex(vulkan_device);
}
}
void ConfigureGraphics::RetrieveVulkanDevices() {
vulkan_devices.clear();
vulkan_devices.reserve(records.size());
device_present_modes.clear();
device_present_modes.reserve(records.size());
for (const auto& record : records) {
vulkan_devices.push_back(QString::fromStdString(record.name));
device_present_modes.push_back(record.vsync_support);
if (record.has_broken_compute) {
expose_compute_option();
}
}
}
Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const {
const auto selected_backend = [&]() {
if (!Settings::IsConfiguringGlobal() && !api_restore_global_button->isEnabled()) {
return Settings::values.renderer_backend.GetValue(true);
}
return static_cast<Settings::RendererBackend>(
combobox_translations.at(Settings::EnumMetadata<Settings::RendererBackend>::Index())
.at(api_combobox->currentIndex())
.first);
}();
if (selected_backend == Settings::RendererBackend::Vulkan &&
UISettings::values.has_broken_vulkan) {
return Settings::RendererBackend::OpenGL;
}
return selected_backend;
}

View File

@@ -0,0 +1,116 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <functional>
#include <memory>
#include <type_traits>
#include <typeindex>
#include <vector>
#include <QColor>
#include <QString>
#include <QWidget>
#include <qobjectdefs.h>
#include <vulkan/vulkan_core.h>
#include "common/common_types.h"
#include "common/settings_enums.h"
#include "configuration/shared_translation.h"
#include "vk_device_info.h"
#include "suyu/configuration/configuration_shared.h"
class QPushButton;
class QEvent;
class QObject;
class QComboBox;
namespace Settings {
enum class NvdecEmulation : u32;
enum class RendererBackend : u32;
enum class ShaderBackend : u32;
} // namespace Settings
namespace Core {
class System;
}
namespace Ui {
class ConfigureGraphics;
}
namespace ConfigurationShared {
class Builder;
}
class ConfigureGraphics : public ConfigurationShared::Tab {
Q_OBJECT
public:
explicit ConfigureGraphics(
const Core::System& system_, std::vector<VkDeviceInfo::Record>& records,
const std::function<void()>& expose_compute_option,
const std::function<void(Settings::AspectRatio, Settings::ResolutionSetup)>&
update_aspect_ratio,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group,
const ConfigurationShared::Builder& builder, QWidget* parent = nullptr);
~ConfigureGraphics() override;
void ApplyConfiguration() override;
void SetConfiguration() override;
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void Setup(const ConfigurationShared::Builder& builder);
void PopulateVSyncModeSelection(bool use_setting);
void UpdateVsyncSetting() const;
void UpdateBackgroundColorButton(QColor color);
void UpdateAPILayout();
void UpdateDeviceSelection(int device);
void UpdateShaderBackendSelection(int backend);
void RetrieveVulkanDevices();
/* Turns a Vulkan present mode into a textual string for a UI
* (and eventually for a human to read) */
const QString TranslateVSyncMode(VkPresentModeKHR mode,
Settings::RendererBackend backend) const;
Settings::RendererBackend GetCurrentGraphicsBackend() const;
int FindIndex(u32 enumeration, int value) const;
std::unique_ptr<Ui::ConfigureGraphics> ui;
QColor bg_color;
std::vector<std::function<void(bool)>> apply_funcs{};
std::vector<VkDeviceInfo::Record>& records;
std::vector<QString> vulkan_devices;
std::vector<std::vector<VkPresentModeKHR>> device_present_modes;
std::vector<VkPresentModeKHR>
vsync_mode_combobox_enum_map{}; //< Keeps track of which present mode corresponds to which
// selection in the combobox
u32 vulkan_device{};
Settings::ShaderBackend shader_backend{};
const std::function<void()>& expose_compute_option;
const std::function<void(Settings::AspectRatio, Settings::ResolutionSetup)> update_aspect_ratio;
const Core::System& system;
const ConfigurationShared::ComboboxTranslationMap& combobox_translations;
const std::vector<std::pair<u32, QString>>& shader_mapping;
QPushButton* api_restore_global_button;
QComboBox* vulkan_device_combobox;
QComboBox* api_combobox;
QComboBox* shader_backend_combobox;
QComboBox* vsync_mode_combobox;
QPushButton* vsync_restore_global_button;
QWidget* vulkan_device_widget;
QWidget* api_widget;
QWidget* shader_backend_widget;
QComboBox* aspect_ratio_combobox;
QComboBox* resolution_combobox;
};

View File

@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureGraphics</class>
<widget class="QWidget" name="ConfigureGraphics">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>541</width>
<height>759</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>Graphics</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>API Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QWidget" name="api_widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="title">
<string>Graphics Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QWidget" name="graphics_widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="bg_widget" native="true">
<layout class="QHBoxLayout" name="bg_layout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Background Color:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="bg_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,82 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <vector>
#include <QLabel>
#include <qnamespace.h>
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_graphics_advanced.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_graphics_advanced.h"
#include "suyu/configuration/shared_translation.h"
#include "suyu/configuration/shared_widget.h"
ConfigureGraphicsAdvanced::ConfigureGraphicsAdvanced(
const Core::System& system_, std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::Builder& builder, QWidget* parent)
: Tab(group_, parent), ui{std::make_unique<Ui::ConfigureGraphicsAdvanced>()}, system{system_} {
ui->setupUi(this);
Setup(builder);
SetConfiguration();
checkbox_enable_compute_pipelines->setVisible(false);
}
ConfigureGraphicsAdvanced::~ConfigureGraphicsAdvanced() = default;
void ConfigureGraphicsAdvanced::SetConfiguration() {}
void ConfigureGraphicsAdvanced::Setup(const ConfigurationShared::Builder& builder) {
auto& layout = *ui->populate_target->layout();
std::map<u32, QWidget*> hold{}; // A map will sort the data for us
for (auto setting :
Settings::values.linkage.by_category[Settings::Category::RendererAdvanced]) {
ConfigurationShared::Widget* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
widget->deleteLater();
continue;
}
hold.emplace(setting->Id(), widget);
// Keep track of enable_compute_pipelines so we can display it when needed
if (setting->Id() == Settings::values.enable_compute_pipelines.Id()) {
checkbox_enable_compute_pipelines = widget;
}
}
for (const auto& [id, widget] : hold) {
layout.addWidget(widget);
}
}
void ConfigureGraphicsAdvanced::ApplyConfiguration() {
const bool is_powered_on = system.IsPoweredOn();
for (const auto& func : apply_funcs) {
func(is_powered_on);
}
}
void ConfigureGraphicsAdvanced::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureGraphicsAdvanced::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureGraphicsAdvanced::ExposeComputeOption() {
checkbox_enable_compute_pipelines->setVisible(true);
}

View File

@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <vector>
#include <QWidget>
#include "suyu/configuration/configuration_shared.h"
namespace Core {
class System;
}
namespace Ui {
class ConfigureGraphicsAdvanced;
}
namespace ConfigurationShared {
class Builder;
}
class ConfigureGraphicsAdvanced : public ConfigurationShared::Tab {
Q_OBJECT
public:
explicit ConfigureGraphicsAdvanced(
const Core::System& system_, std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group,
const ConfigurationShared::Builder& builder, QWidget* parent = nullptr);
~ConfigureGraphicsAdvanced() override;
void ApplyConfiguration() override;
void SetConfiguration() override;
void ExposeComputeOption();
private:
void Setup(const ConfigurationShared::Builder& builder);
void changeEvent(QEvent* event) override;
void RetranslateUI();
std::unique_ptr<Ui::ConfigureGraphicsAdvanced> ui;
const Core::System& system;
std::vector<std::function<void(bool)>> apply_funcs;
QWidget* checkbox_enable_compute_pipelines{};
};

View File

@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureGraphicsAdvanced</class>
<widget class="QWidget" name="ConfigureGraphicsAdvanced">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>404</width>
<height>376</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>Advanced</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox_1">
<property name="title">
<string>Advanced Graphics Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QWidget" name="populate_target" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,423 @@
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QMenu>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QTimer>
#include "hid_core/frontend/emulated_controller.h"
#include "hid_core/hid_core.h"
#include "frontend_common/config.h"
#include "ui_configure_hotkeys.h"
#include "suyu/configuration/configure_hotkeys.h"
#include "suyu/hotkeys.h"
#include "suyu/uisettings.h"
#include "suyu/util/sequence_dialog/sequence_dialog.h"
constexpr int name_column = 0;
constexpr int hotkey_column = 1;
constexpr int controller_column = 2;
ConfigureHotkeys::ConfigureHotkeys(Core::HID::HIDCore& hid_core, QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureHotkeys>()),
timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) {
ui->setupUi(this);
setFocusPolicy(Qt::ClickFocus);
model = new QStandardItemModel(this);
model->setColumnCount(3);
connect(ui->hotkey_list, &QTreeView::doubleClicked, this, &ConfigureHotkeys::Configure);
connect(ui->hotkey_list, &QTreeView::customContextMenuRequested, this,
&ConfigureHotkeys::PopupContextMenu);
ui->hotkey_list->setContextMenuPolicy(Qt::CustomContextMenu);
ui->hotkey_list->setModel(model);
ui->hotkey_list->header()->setStretchLastSection(false);
ui->hotkey_list->header()->setSectionResizeMode(name_column, QHeaderView::ResizeMode::Stretch);
ui->hotkey_list->header()->setMinimumSectionSize(150);
connect(ui->button_restore_defaults, &QPushButton::clicked, this,
&ConfigureHotkeys::RestoreDefaults);
connect(ui->button_clear_all, &QPushButton::clicked, this, &ConfigureHotkeys::ClearAll);
controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1);
connect(timeout_timer.get(), &QTimer::timeout, [this] {
const bool is_button_pressed = pressed_buttons != Core::HID::NpadButton::None ||
pressed_home_button || pressed_capture_button;
SetPollingResult(!is_button_pressed);
});
connect(poll_timer.get(), &QTimer::timeout, [this] {
pressed_buttons |= controller->GetNpadButtons().raw;
pressed_home_button |= this->controller->GetHomeButtons().home != 0;
pressed_capture_button |= this->controller->GetCaptureButtons().capture != 0;
if (pressed_buttons != Core::HID::NpadButton::None || pressed_home_button ||
pressed_capture_button) {
const QString button_name =
GetButtonCombinationName(pressed_buttons, pressed_home_button,
pressed_capture_button) +
QStringLiteral("...");
model->setData(button_model_index, button_name);
}
});
RetranslateUI();
}
ConfigureHotkeys::~ConfigureHotkeys() = default;
void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) {
for (const auto& group : registry.hotkey_groups) {
QString parent_item_data = QString::fromStdString(group.first);
auto* parent_item =
new QStandardItem(QCoreApplication::translate("Hotkeys", qPrintable(parent_item_data)));
parent_item->setEditable(false);
parent_item->setData(parent_item_data);
for (const auto& hotkey : group.second) {
QString hotkey_action_data = QString::fromStdString(hotkey.first);
auto* action = new QStandardItem(
QCoreApplication::translate("Hotkeys", qPrintable(hotkey_action_data)));
auto* keyseq =
new QStandardItem(hotkey.second.keyseq.toString(QKeySequence::NativeText));
auto* controller_keyseq =
new QStandardItem(QString::fromStdString(hotkey.second.controller_keyseq));
action->setEditable(false);
action->setData(hotkey_action_data);
keyseq->setEditable(false);
controller_keyseq->setEditable(false);
parent_item->appendRow({action, keyseq, controller_keyseq});
}
model->appendRow(parent_item);
}
ui->hotkey_list->expandAll();
ui->hotkey_list->resizeColumnToContents(hotkey_column);
ui->hotkey_list->resizeColumnToContents(controller_column);
}
void ConfigureHotkeys::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureHotkeys::RetranslateUI() {
ui->retranslateUi(this);
model->setHorizontalHeaderLabels({tr("Action"), tr("Hotkey"), tr("Controller Hotkey")});
for (int key_id = 0; key_id < model->rowCount(); key_id++) {
QStandardItem* parent = model->item(key_id, 0);
parent->setText(
QCoreApplication::translate("Hotkeys", qPrintable(parent->data().toString())));
for (int key_column_id = 0; key_column_id < parent->rowCount(); key_column_id++) {
QStandardItem* action = parent->child(key_column_id, name_column);
action->setText(
QCoreApplication::translate("Hotkeys", qPrintable(action->data().toString())));
}
}
}
void ConfigureHotkeys::Configure(QModelIndex index) {
if (!index.parent().isValid()) {
return;
}
// Controller configuration is selected
if (index.column() == controller_column) {
ConfigureController(index);
return;
}
// Swap to the hotkey column
index = index.sibling(index.row(), hotkey_column);
const auto previous_key = model->data(index);
SequenceDialog hotkey_dialog{this};
const int return_code = hotkey_dialog.exec();
const auto key_sequence = hotkey_dialog.GetSequence();
if (return_code == QDialog::Rejected || key_sequence.isEmpty()) {
return;
}
const auto [key_sequence_used, used_action] = IsUsedKey(key_sequence);
if (key_sequence_used && key_sequence != QKeySequence(previous_key.toString())) {
QMessageBox::warning(
this, tr("Conflicting Key Sequence"),
tr("The entered key sequence is already assigned to: %1").arg(used_action));
} else {
model->setData(index, key_sequence.toString(QKeySequence::NativeText));
}
}
void ConfigureHotkeys::ConfigureController(QModelIndex index) {
if (timeout_timer->isActive()) {
return;
}
const auto previous_key = model->data(index);
input_setter = [this, index, previous_key](const bool cancel) {
if (cancel) {
model->setData(index, previous_key);
return;
}
const QString button_string =
GetButtonCombinationName(pressed_buttons, pressed_home_button, pressed_capture_button);
const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string);
if (key_sequence_used) {
QMessageBox::warning(
this, tr("Conflicting Key Sequence"),
tr("The entered key sequence is already assigned to: %1").arg(used_action));
model->setData(index, previous_key);
} else {
model->setData(index, button_string);
}
};
button_model_index = index;
pressed_buttons = Core::HID::NpadButton::None;
pressed_home_button = false;
pressed_capture_button = false;
model->setData(index, tr("[waiting]"));
timeout_timer->start(2500); // Cancel after 2.5 seconds
poll_timer->start(100); // Check for new inputs every 100ms
// We need to disable configuration to be able to read npad buttons
controller->DisableConfiguration();
}
void ConfigureHotkeys::SetPollingResult(const bool cancel) {
timeout_timer->stop();
poll_timer->stop();
(*input_setter)(cancel);
// Re-Enable configuration
controller->EnableConfiguration();
input_setter = std::nullopt;
}
QString ConfigureHotkeys::GetButtonCombinationName(Core::HID::NpadButton button,
const bool home = false,
const bool capture = false) const {
Core::HID::NpadButtonState state{button};
QString button_combination;
if (home) {
button_combination.append(QStringLiteral("Home+"));
}
if (capture) {
button_combination.append(QStringLiteral("Screenshot+"));
}
if (state.a) {
button_combination.append(QStringLiteral("A+"));
}
if (state.b) {
button_combination.append(QStringLiteral("B+"));
}
if (state.x) {
button_combination.append(QStringLiteral("X+"));
}
if (state.y) {
button_combination.append(QStringLiteral("Y+"));
}
if (state.l || state.right_sl || state.left_sl) {
button_combination.append(QStringLiteral("L+"));
}
if (state.r || state.right_sr || state.left_sr) {
button_combination.append(QStringLiteral("R+"));
}
if (state.zl) {
button_combination.append(QStringLiteral("ZL+"));
}
if (state.zr) {
button_combination.append(QStringLiteral("ZR+"));
}
if (state.left) {
button_combination.append(QStringLiteral("Dpad_Left+"));
}
if (state.right) {
button_combination.append(QStringLiteral("Dpad_Right+"));
}
if (state.up) {
button_combination.append(QStringLiteral("Dpad_Up+"));
}
if (state.down) {
button_combination.append(QStringLiteral("Dpad_Down+"));
}
if (state.stick_l) {
button_combination.append(QStringLiteral("Left_Stick+"));
}
if (state.stick_r) {
button_combination.append(QStringLiteral("Right_Stick+"));
}
if (state.minus) {
button_combination.append(QStringLiteral("Minus+"));
}
if (state.plus) {
button_combination.append(QStringLiteral("Plus+"));
}
if (button_combination.isEmpty()) {
return tr("Invalid");
} else {
button_combination.chop(1);
return button_combination;
}
}
std::pair<bool, QString> ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const {
for (int r = 0; r < model->rowCount(); ++r) {
const QStandardItem* const parent = model->item(r, 0);
for (int r2 = 0; r2 < parent->rowCount(); ++r2) {
const QStandardItem* const key_seq_item = parent->child(r2, hotkey_column);
const auto key_seq_str = key_seq_item->text();
const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText);
if (key_sequence == key_seq) {
return std::make_pair(true, parent->child(r2, 0)->text());
}
}
}
return std::make_pair(false, QString());
}
std::pair<bool, QString> ConfigureHotkeys::IsUsedControllerKey(const QString& key_sequence) const {
for (int r = 0; r < model->rowCount(); ++r) {
const QStandardItem* const parent = model->item(r, 0);
for (int r2 = 0; r2 < parent->rowCount(); ++r2) {
const QStandardItem* const key_seq_item = parent->child(r2, controller_column);
const auto key_seq_str = key_seq_item->text();
if (key_sequence == key_seq_str) {
return std::make_pair(true, parent->child(r2, 0)->text());
}
}
}
return std::make_pair(false, QString());
}
void ConfigureHotkeys::ApplyConfiguration(HotkeyRegistry& registry) {
for (int key_id = 0; key_id < model->rowCount(); key_id++) {
const QStandardItem* parent = model->item(key_id, 0);
for (int key_column_id = 0; key_column_id < parent->rowCount(); key_column_id++) {
const QStandardItem* action = parent->child(key_column_id, name_column);
const QStandardItem* keyseq = parent->child(key_column_id, hotkey_column);
const QStandardItem* controller_keyseq =
parent->child(key_column_id, controller_column);
for (auto& [group, sub_actions] : registry.hotkey_groups) {
if (group != parent->data().toString().toStdString())
continue;
for (auto& [action_name, hotkey] : sub_actions) {
if (action_name != action->data().toString().toStdString())
continue;
hotkey.keyseq = QKeySequence(keyseq->text());
hotkey.controller_keyseq = controller_keyseq->text().toStdString();
}
}
}
}
registry.SaveHotkeys();
}
void ConfigureHotkeys::RestoreDefaults() {
for (int r = 0; r < model->rowCount(); ++r) {
const QStandardItem* parent = model->item(r, 0);
const int hotkey_size = static_cast<int>(UISettings::default_hotkeys.size());
if (hotkey_size != parent->rowCount()) {
QMessageBox::warning(this, tr("Invalid hotkey settings"),
tr("An error occurred. Please report this issue on github."));
return;
}
for (int r2 = 0; r2 < parent->rowCount(); ++r2) {
model->item(r, 0)
->child(r2, hotkey_column)
->setText(QString::fromStdString(UISettings::default_hotkeys[r2].shortcut.keyseq));
model->item(r, 0)
->child(r2, controller_column)
->setText(QString::fromStdString(
UISettings::default_hotkeys[r2].shortcut.controller_keyseq));
}
}
}
void ConfigureHotkeys::ClearAll() {
for (int r = 0; r < model->rowCount(); ++r) {
const QStandardItem* parent = model->item(r, 0);
for (int r2 = 0; r2 < parent->rowCount(); ++r2) {
model->item(r, 0)->child(r2, hotkey_column)->setText(QString{});
model->item(r, 0)->child(r2, controller_column)->setText(QString{});
}
}
}
void ConfigureHotkeys::PopupContextMenu(const QPoint& menu_location) {
QModelIndex index = ui->hotkey_list->indexAt(menu_location);
if (!index.parent().isValid()) {
return;
}
// Swap to the hotkey column if the controller hotkey column is not selected
if (index.column() != controller_column) {
index = index.sibling(index.row(), hotkey_column);
}
QMenu context_menu;
QAction* restore_default = context_menu.addAction(tr("Restore Default"));
QAction* clear = context_menu.addAction(tr("Clear"));
connect(restore_default, &QAction::triggered, [this, index] {
if (index.column() == controller_column) {
RestoreControllerHotkey(index);
return;
}
RestoreHotkey(index);
});
connect(clear, &QAction::triggered, [this, index] { model->setData(index, QString{}); });
context_menu.exec(ui->hotkey_list->viewport()->mapToGlobal(menu_location));
}
void ConfigureHotkeys::RestoreControllerHotkey(QModelIndex index) {
const QString& default_key_sequence =
QString::fromStdString(UISettings::default_hotkeys[index.row()].shortcut.controller_keyseq);
const auto [key_sequence_used, used_action] = IsUsedControllerKey(default_key_sequence);
if (key_sequence_used && default_key_sequence != model->data(index).toString()) {
QMessageBox::warning(
this, tr("Conflicting Button Sequence"),
tr("The default button sequence is already assigned to: %1").arg(used_action));
} else {
model->setData(index, default_key_sequence);
}
}
void ConfigureHotkeys::RestoreHotkey(QModelIndex index) {
const QKeySequence& default_key_sequence = QKeySequence::fromString(
QString::fromStdString(UISettings::default_hotkeys[index.row()].shortcut.keyseq),
QKeySequence::NativeText);
const auto [key_sequence_used, used_action] = IsUsedKey(default_key_sequence);
if (key_sequence_used && default_key_sequence != QKeySequence(model->data(index).toString())) {
QMessageBox::warning(
this, tr("Conflicting Key Sequence"),
tr("The default key sequence is already assigned to: %1").arg(used_action));
} else {
model->setData(index, default_key_sequence.toString(QKeySequence::NativeText));
}
}

View File

@@ -0,0 +1,74 @@
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QStandardItemModel>
#include <QWidget>
namespace Common {
class ParamPackage;
}
namespace Core::HID {
class HIDCore;
class EmulatedController;
enum class NpadButton : u64;
} // namespace Core::HID
namespace Ui {
class ConfigureHotkeys;
}
class HotkeyRegistry;
class QStandardItemModel;
class ConfigureHotkeys : public QWidget {
Q_OBJECT
public:
explicit ConfigureHotkeys(Core::HID::HIDCore& hid_core_, QWidget* parent = nullptr);
~ConfigureHotkeys() override;
void ApplyConfiguration(HotkeyRegistry& registry);
/**
* Populates the hotkey list widget using data from the provided registry.
* Called every time the Configure dialog is opened.
* @param registry The HotkeyRegistry whose data is used to populate the list.
*/
void Populate(const HotkeyRegistry& registry);
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void Configure(QModelIndex index);
void ConfigureController(QModelIndex index);
std::pair<bool, QString> IsUsedKey(QKeySequence key_sequence) const;
std::pair<bool, QString> IsUsedControllerKey(const QString& key_sequence) const;
void RestoreDefaults();
void ClearAll();
void PopupContextMenu(const QPoint& menu_location);
void RestoreControllerHotkey(QModelIndex index);
void RestoreHotkey(QModelIndex index);
void SetPollingResult(bool cancel);
QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const;
std::unique_ptr<Ui::ConfigureHotkeys> ui;
QStandardItemModel* model;
bool pressed_home_button;
bool pressed_capture_button;
QModelIndex button_model_index;
Core::HID::NpadButton pressed_buttons;
Core::HID::EmulatedController* controller;
std::unique_ptr<QTimer> timeout_timer;
std::unique_ptr<QTimer> poll_timer;
std::optional<std::function<void(bool)>> input_setter;
};

View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureHotkeys</class>
<widget class="QWidget" name="ConfigureHotkeys">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>439</width>
<height>510</height>
</rect>
</property>
<property name="windowTitle">
<string>Hotkey Settings</string>
</property>
<property name="accessibleName">
<string>Hotkeys</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Double-click on a binding to change it.</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="button_clear_all">
<property name="text">
<string>Clear All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_restore_defaults">
<property name="text">
<string>Restore Defaults</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTreeView" name="hotkey_list">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,309 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include <thread>
#include "common/settings.h"
#include "common/settings_enums.h"
#include "core/core.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/am/applet_manager.h"
#include "core/hle/service/sm/sm.h"
#include "hid_core/frontend/emulated_controller.h"
#include "hid_core/hid_core.h"
#include "ui_configure_input.h"
#include "ui_configure_input_advanced.h"
#include "ui_configure_input_player.h"
#include "suyu/configuration/configure_camera.h"
#include "suyu/configuration/configure_debug_controller.h"
#include "suyu/configuration/configure_input.h"
#include "suyu/configuration/configure_input_advanced.h"
#include "suyu/configuration/configure_input_player.h"
#include "suyu/configuration/configure_motion_touch.h"
#include "suyu/configuration/configure_ringcon.h"
#include "suyu/configuration/configure_touchscreen_advanced.h"
#include "suyu/configuration/configure_vibration.h"
#include "suyu/configuration/input_profiles.h"
namespace {
template <typename Dialog, typename... Args>
void CallConfigureDialog(ConfigureInput& parent, Args&&... args) {
Dialog dialog(&parent, std::forward<Args>(args)...);
const auto res = dialog.exec();
if (res == QDialog::Accepted) {
dialog.ApplyConfiguration();
}
}
} // Anonymous namespace
void OnDockedModeChanged(bool last_state, bool new_state, Core::System& system) {
if (last_state == new_state) {
return;
}
if (!system.IsPoweredOn()) {
return;
}
system.GetAppletManager().OperationModeChanged();
}
ConfigureInput::ConfigureInput(Core::System& system_, QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()),
profiles(std::make_unique<InputProfiles>()), system{system_} {
ui->setupUi(this);
}
ConfigureInput::~ConfigureInput() = default;
void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem,
std::size_t max_players) {
const bool is_powered_on = system.IsPoweredOn();
auto& hid_core = system.HIDCore();
player_controllers = {
new ConfigureInputPlayer(this, 0, ui->consoleInputSettings, input_subsystem, profiles.get(),
hid_core, is_powered_on),
new ConfigureInputPlayer(this, 1, ui->consoleInputSettings, input_subsystem, profiles.get(),
hid_core, is_powered_on),
new ConfigureInputPlayer(this, 2, ui->consoleInputSettings, input_subsystem, profiles.get(),
hid_core, is_powered_on),
new ConfigureInputPlayer(this, 3, ui->consoleInputSettings, input_subsystem, profiles.get(),
hid_core, is_powered_on),
new ConfigureInputPlayer(this, 4, ui->consoleInputSettings, input_subsystem, profiles.get(),
hid_core, is_powered_on),
new ConfigureInputPlayer(this, 5, ui->consoleInputSettings, input_subsystem, profiles.get(),
hid_core, is_powered_on),
new ConfigureInputPlayer(this, 6, ui->consoleInputSettings, input_subsystem, profiles.get(),
hid_core, is_powered_on),
new ConfigureInputPlayer(this, 7, ui->consoleInputSettings, input_subsystem, profiles.get(),
hid_core, is_powered_on),
};
player_tabs = {
ui->tabPlayer1, ui->tabPlayer2, ui->tabPlayer3, ui->tabPlayer4,
ui->tabPlayer5, ui->tabPlayer6, ui->tabPlayer7, ui->tabPlayer8,
};
connected_controller_checkboxes = {
ui->checkboxPlayer1Connected, ui->checkboxPlayer2Connected, ui->checkboxPlayer3Connected,
ui->checkboxPlayer4Connected, ui->checkboxPlayer5Connected, ui->checkboxPlayer6Connected,
ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected,
};
std::array<QLabel*, 8> connected_controller_labels = {
ui->label, ui->label_3, ui->label_4, ui->label_5,
ui->label_6, ui->label_7, ui->label_8, ui->label_9,
};
for (std::size_t i = 0; i < player_tabs.size(); ++i) {
player_tabs[i]->setLayout(new QHBoxLayout(player_tabs[i]));
player_tabs[i]->layout()->addWidget(player_controllers[i]);
connect(player_controllers[i], &ConfigureInputPlayer::Connected, [this, i](bool checked) {
// Ensures that connecting a controller changes the number of players
if (connected_controller_checkboxes[i]->isChecked() != checked) {
// Ensures that the players are always connected in sequential order
PropagatePlayerNumberChanged(i, checked);
}
});
connect(connected_controller_checkboxes[i], &QCheckBox::clicked, [this, i](bool checked) {
// Reconnect current controller if it was the last one checked
// (player number was reduced by more than one)
const bool reconnect_first = !checked &&
i < connected_controller_checkboxes.size() - 1 &&
connected_controller_checkboxes[i + 1]->isChecked();
// Ensures that the players are always connected in sequential order
PropagatePlayerNumberChanged(i, checked, reconnect_first);
});
connect(player_controllers[i], &ConfigureInputPlayer::RefreshInputDevices, this,
&ConfigureInput::UpdateAllInputDevices);
connect(player_controllers[i], &ConfigureInputPlayer::RefreshInputProfiles, this,
&ConfigureInput::UpdateAllInputProfiles, Qt::QueuedConnection);
connect(connected_controller_checkboxes[i], &QCheckBox::stateChanged, [this, i](int state) {
// Keep activated controllers synced with the "Connected Controllers" checkboxes
player_controllers[i]->ConnectPlayer(state == Qt::Checked);
});
// Remove/hide all the elements that exceed max_players, if applicable.
if (i >= max_players) {
ui->tabWidget->removeTab(static_cast<int>(max_players));
connected_controller_checkboxes[i]->hide();
connected_controller_labels[i]->hide();
}
}
// Only the first player can choose handheld mode so connect the signal just to player 1
connect(player_controllers[0], &ConfigureInputPlayer::HandheldStateChanged,
[this](bool is_handheld) { UpdateDockedState(is_handheld); });
advanced = new ConfigureInputAdvanced(hid_core, this);
ui->tabAdvanced->setLayout(new QHBoxLayout(ui->tabAdvanced));
ui->tabAdvanced->layout()->addWidget(advanced);
connect(advanced, &ConfigureInputAdvanced::CallDebugControllerDialog,
[this, input_subsystem, &hid_core, is_powered_on] {
CallConfigureDialog<ConfigureDebugController>(
*this, input_subsystem, profiles.get(), hid_core, is_powered_on);
});
connect(advanced, &ConfigureInputAdvanced::CallTouchscreenConfigDialog,
[this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); });
connect(advanced, &ConfigureInputAdvanced::CallMotionTouchConfigDialog,
[this, input_subsystem] {
CallConfigureDialog<ConfigureMotionTouch>(*this, input_subsystem);
});
connect(advanced, &ConfigureInputAdvanced::CallRingControllerDialog,
[this, input_subsystem, &hid_core] {
CallConfigureDialog<ConfigureRingController>(*this, input_subsystem, hid_core);
});
connect(advanced, &ConfigureInputAdvanced::CallCameraDialog, [this, input_subsystem] {
CallConfigureDialog<ConfigureCamera>(*this, input_subsystem);
});
connect(ui->vibrationButton, &QPushButton::clicked,
[this, &hid_core] { CallConfigureDialog<ConfigureVibration>(*this, hid_core); });
connect(ui->motionButton, &QPushButton::clicked, [this, input_subsystem] {
CallConfigureDialog<ConfigureMotionTouch>(*this, input_subsystem);
});
connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); });
connect(ui->buttonRestoreDefaults, &QPushButton::clicked, [this] { RestoreDefaults(); });
RetranslateUI();
LoadConfiguration();
}
void ConfigureInput::PropagatePlayerNumberChanged(size_t player_index, bool checked,
bool reconnect_current) {
connected_controller_checkboxes[player_index]->setChecked(checked);
if (checked) {
// Check all previous buttons when checked
if (player_index > 0) {
PropagatePlayerNumberChanged(player_index - 1, checked);
}
} else {
// Unchecked all following buttons when unchecked
if (player_index < connected_controller_checkboxes.size() - 1) {
PropagatePlayerNumberChanged(player_index + 1, checked);
}
}
if (reconnect_current) {
connected_controller_checkboxes[player_index]->setCheckState(Qt::Checked);
}
}
QList<QWidget*> ConfigureInput::GetSubTabs() const {
return {
ui->tabPlayer1, ui->tabPlayer2, ui->tabPlayer3, ui->tabPlayer4, ui->tabPlayer5,
ui->tabPlayer6, ui->tabPlayer7, ui->tabPlayer8, ui->tabAdvanced,
};
}
void ConfigureInput::ApplyConfiguration() {
const bool was_global = Settings::values.players.UsingGlobal();
Settings::values.players.SetGlobal(true);
for (auto* controller : player_controllers) {
controller->ApplyConfiguration();
}
advanced->ApplyConfiguration();
const bool pre_docked_mode = Settings::IsDockedMode();
const bool docked_mode_selected = ui->radioDocked->isChecked();
Settings::values.use_docked_mode.SetValue(
docked_mode_selected ? Settings::ConsoleMode::Docked : Settings::ConsoleMode::Handheld);
OnDockedModeChanged(pre_docked_mode, docked_mode_selected, system);
Settings::values.vibration_enabled.SetValue(ui->vibrationGroup->isChecked());
Settings::values.motion_enabled.SetValue(ui->motionGroup->isChecked());
Settings::values.players.SetGlobal(was_global);
}
void ConfigureInput::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureInput::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureInput::LoadConfiguration() {
const auto* handheld = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
LoadPlayerControllerIndices();
UpdateDockedState(handheld->IsConnected());
ui->vibrationGroup->setChecked(Settings::values.vibration_enabled.GetValue());
ui->motionGroup->setChecked(Settings::values.motion_enabled.GetValue());
}
void ConfigureInput::LoadPlayerControllerIndices() {
for (std::size_t i = 0; i < connected_controller_checkboxes.size(); ++i) {
if (i == 0) {
auto* handheld =
system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
if (handheld->IsConnected()) {
connected_controller_checkboxes[i]->setChecked(true);
continue;
}
}
const auto* controller = system.HIDCore().GetEmulatedControllerByIndex(i);
connected_controller_checkboxes[i]->setChecked(controller->IsConnected());
}
}
void ConfigureInput::ClearAll() {
// We don't have a good way to know what tab is active, but we can find out by getting the
// parent of the consoleInputSettings
auto* player_tab = static_cast<ConfigureInputPlayer*>(ui->consoleInputSettings->parent());
player_tab->ClearAll();
}
void ConfigureInput::RestoreDefaults() {
// We don't have a good way to know what tab is active, but we can find out by getting the
// parent of the consoleInputSettings
auto* player_tab = static_cast<ConfigureInputPlayer*>(ui->consoleInputSettings->parent());
player_tab->RestoreDefaults();
ui->radioDocked->setChecked(true);
ui->radioUndocked->setChecked(false);
ui->vibrationGroup->setChecked(true);
ui->motionGroup->setChecked(true);
}
void ConfigureInput::UpdateDockedState(bool is_handheld) {
// Disallow changing the console mode if the controller type is handheld.
ui->radioDocked->setEnabled(!is_handheld);
ui->radioUndocked->setEnabled(!is_handheld);
ui->radioDocked->setChecked(Settings::IsDockedMode());
ui->radioUndocked->setChecked(!Settings::IsDockedMode());
// Also force into undocked mode if the controller type is handheld.
if (is_handheld) {
ui->radioUndocked->setChecked(true);
}
}
void ConfigureInput::UpdateAllInputDevices() {
for (const auto& player : player_controllers) {
player->UpdateInputDeviceCombobox();
}
}
void ConfigureInput::UpdateAllInputProfiles(std::size_t player_index) {
for (std::size_t i = 0; i < player_controllers.size(); ++i) {
if (i == player_index) {
continue;
}
player_controllers[i]->UpdateInputProfiles();
}
}

View File

@@ -0,0 +1,81 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include <memory>
#include <QKeyEvent>
#include <QList>
#include <QWidget>
namespace Core {
class System;
}
class QCheckBox;
class QString;
class QTimer;
class ConfigureInputAdvanced;
class ConfigureInputPlayer;
class InputProfiles;
namespace InputCommon {
class InputSubsystem;
}
namespace Ui {
class ConfigureInput;
}
void OnDockedModeChanged(bool last_state, bool new_state, Core::System& system);
class ConfigureInput : public QWidget {
Q_OBJECT
public:
explicit ConfigureInput(Core::System& system_, QWidget* parent = nullptr);
~ConfigureInput() override;
/// Initializes the input dialog with the given input subsystem.
void Initialize(InputCommon::InputSubsystem* input_subsystem_, std::size_t max_players = 8);
/// Save all button configurations to settings file.
void ApplyConfiguration();
QList<QWidget*> GetSubTabs() const;
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void ClearAll();
void UpdateDockedState(bool is_handheld);
void UpdateAllInputDevices();
void UpdateAllInputProfiles(std::size_t player_index);
// Enable preceding controllers or disable following ones
void PropagatePlayerNumberChanged(size_t player_index, bool checked,
bool reconnect_current = false);
/// Load configuration settings.
void LoadConfiguration();
void LoadPlayerControllerIndices();
/// Restore all buttons to their default values.
void RestoreDefaults();
std::unique_ptr<Ui::ConfigureInput> ui;
std::unique_ptr<InputProfiles> profiles;
std::array<ConfigureInputPlayer*, 8> player_controllers;
std::array<QWidget*, 8> player_tabs;
// Checkboxes representing the "Connected Controllers".
std::array<QCheckBox*, 8> connected_controller_checkboxes;
ConfigureInputAdvanced* advanced;
Core::System& system;
};

View File

@@ -0,0 +1,548 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureInput</class>
<widget class="QWidget" name="ConfigureInput">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>680</width>
<height>540</height>
</rect>
</property>
<property name="windowTitle">
<string>ConfigureInput</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabPlayer1">
<property name="accessibleName">
<string>Player 1</string>
</property>
<attribute name="title">
<string>Player 1</string>
</attribute>
</widget>
<widget class="QWidget" name="tabPlayer2">
<property name="accessibleName">
<string>Player 2</string>
</property>
<attribute name="title">
<string>Player 2</string>
</attribute>
</widget>
<widget class="QWidget" name="tabPlayer3">
<property name="accessibleName">
<string>Player 3</string>
</property>
<attribute name="title">
<string>Player 3</string>
</attribute>
</widget>
<widget class="QWidget" name="tabPlayer4">
<property name="accessibleName">
<string>Player 4</string>
</property>
<attribute name="title">
<string>Player 4</string>
</attribute>
</widget>
<widget class="QWidget" name="tabPlayer5">
<property name="accessibleName">
<string>Player 5</string>
</property>
<attribute name="title">
<string>Player 5</string>
</attribute>
</widget>
<widget class="QWidget" name="tabPlayer6">
<property name="accessibleName">
<string>Player 6</string>
</property>
<attribute name="title">
<string>Player 6</string>
</attribute>
</widget>
<widget class="QWidget" name="tabPlayer7">
<property name="accessibleName">
<string>Player 7</string>
</property>
<attribute name="title">
<string>Player 7</string>
</attribute>
</widget>
<widget class="QWidget" name="tabPlayer8">
<property name="accessibleName">
<string>Player 8</string>
</property>
<attribute name="title">
<string>Player 8</string>
</attribute>
</widget>
<widget class="QWidget" name="tabAdvanced">
<property name="accessibleName">
<string>Advanced</string>
</property>
<attribute name="title">
<string>Advanced</string>
</attribute>
</widget>
</widget>
</item>
<item alignment="Qt::AlignVCenter">
<widget class="QWidget" name="consoleInputSettings" native="true">
<layout class="QHBoxLayout" name="buttonsBottomRightHorizontalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignVCenter">
<widget class="QGroupBox" name="handheldGroup">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="title">
<string>Console Mode</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<widget class="QRadioButton" name="radioDocked">
<property name="text">
<string>Docked</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioUndocked">
<property name="text">
<string>Handheld</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="vibrationGroup">
<property name="title">
<string>Vibration</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QPushButton" name="vibrationButton">
<property name="minimumSize">
<size>
<width>68</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>68</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">min-width: 68px;</string>
</property>
<property name="text">
<string>Configure</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="motionGroup">
<property name="title">
<string>Motion</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QPushButton" name="motionButton">
<property name="minimumSize">
<size>
<width>68</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>68</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">min-width: 68px;</string>
</property>
<property name="text">
<string>Configure</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item alignment="Qt::AlignVCenter">
<widget class="QWidget" name="connectedControllers" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>3</number>
</property>
<item row="1" column="2">
<widget class="QCheckBox" name="checkboxPlayer2Connected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Controllers</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QCheckBox" name="checkboxPlayer4Connected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QCheckBox" name="checkboxPlayer3Connected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QCheckBox" name="checkboxPlayer5Connected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>1</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="7">
<widget class="QCheckBox" name="checkboxPlayer7Connected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QCheckBox" name="checkboxPlayer6Connected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkboxPlayer1Connected">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="8">
<widget class="QCheckBox" name="checkboxPlayer8Connected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>2</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_4">
<property name="text">
<string>3</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="label_5">
<property name="text">
<string>4</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QLabel" name="label_6">
<property name="text">
<string>5</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QLabel" name="label_7">
<property name="text">
<string>6</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="QLabel" name="label_8">
<property name="text">
<string>7</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QLabel" name="label_9">
<property name="text">
<string>8</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Connected</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignBottom">
<widget class="QPushButton" name="buttonRestoreDefaults">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>68</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>68</width>
<height>16777215</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="styleSheet">
<string notr="true">min-width: 68px;</string>
</property>
<property name="text">
<string>Defaults</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignBottom">
<widget class="QPushButton" name="buttonClearAll">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>68</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>68</width>
<height>16777215</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="styleSheet">
<string notr="true">min-width: 68px;</string>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,204 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QColorDialog>
#include "common/settings.h"
#include "core/core.h"
#include "hid_core/frontend/emulated_controller.h"
#include "hid_core/hid_core.h"
#include "ui_configure_input_advanced.h"
#include "suyu/configuration/configure_input_advanced.h"
ConfigureInputAdvanced::ConfigureInputAdvanced(Core::HID::HIDCore& hid_core_, QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInputAdvanced>()), hid_core{hid_core_} {
ui->setupUi(this);
controllers_color_buttons = {{
{
ui->player1_left_body_button,
ui->player1_left_buttons_button,
ui->player1_right_body_button,
ui->player1_right_buttons_button,
},
{
ui->player2_left_body_button,
ui->player2_left_buttons_button,
ui->player2_right_body_button,
ui->player2_right_buttons_button,
},
{
ui->player3_left_body_button,
ui->player3_left_buttons_button,
ui->player3_right_body_button,
ui->player3_right_buttons_button,
},
{
ui->player4_left_body_button,
ui->player4_left_buttons_button,
ui->player4_right_body_button,
ui->player4_right_buttons_button,
},
{
ui->player5_left_body_button,
ui->player5_left_buttons_button,
ui->player5_right_body_button,
ui->player5_right_buttons_button,
},
{
ui->player6_left_body_button,
ui->player6_left_buttons_button,
ui->player6_right_body_button,
ui->player6_right_buttons_button,
},
{
ui->player7_left_body_button,
ui->player7_left_buttons_button,
ui->player7_right_body_button,
ui->player7_right_buttons_button,
},
{
ui->player8_left_body_button,
ui->player8_left_buttons_button,
ui->player8_right_body_button,
ui->player8_right_buttons_button,
},
}};
for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
auto& color_buttons = controllers_color_buttons[player_idx];
for (std::size_t button_idx = 0; button_idx < color_buttons.size(); ++button_idx) {
connect(color_buttons[button_idx], &QPushButton::clicked, this,
[this, player_idx, button_idx] {
OnControllerButtonClick(player_idx, button_idx);
});
}
}
connect(ui->mouse_enabled, &QCheckBox::stateChanged, this,
&ConfigureInputAdvanced::UpdateUIEnabled);
connect(ui->debug_enabled, &QCheckBox::stateChanged, this,
&ConfigureInputAdvanced::UpdateUIEnabled);
connect(ui->touchscreen_enabled, &QCheckBox::stateChanged, this,
&ConfigureInputAdvanced::UpdateUIEnabled);
connect(ui->enable_ring_controller, &QCheckBox::stateChanged, this,
&ConfigureInputAdvanced::UpdateUIEnabled);
connect(ui->debug_configure, &QPushButton::clicked, this,
[this] { CallDebugControllerDialog(); });
connect(ui->touchscreen_advanced, &QPushButton::clicked, this,
[this] { CallTouchscreenConfigDialog(); });
connect(ui->buttonMotionTouch, &QPushButton::clicked, this,
[this] { CallMotionTouchConfigDialog(); });
connect(ui->ring_controller_configure, &QPushButton::clicked, this,
[this] { CallRingControllerDialog(); });
connect(ui->camera_configure, &QPushButton::clicked, this, [this] { CallCameraDialog(); });
#ifndef _WIN32
ui->enable_raw_input->setVisible(false);
#endif
LoadConfiguration();
}
ConfigureInputAdvanced::~ConfigureInputAdvanced() = default;
void ConfigureInputAdvanced::OnControllerButtonClick(std::size_t player_idx,
std::size_t button_idx) {
const QColor new_bg_color = QColorDialog::getColor(controllers_colors[player_idx][button_idx]);
if (!new_bg_color.isValid()) {
return;
}
controllers_colors[player_idx][button_idx] = new_bg_color;
controllers_color_buttons[player_idx][button_idx]->setStyleSheet(
QStringLiteral("background-color: %1; min-width: 60px;")
.arg(controllers_colors[player_idx][button_idx].name()));
}
void ConfigureInputAdvanced::ApplyConfiguration() {
for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
auto& player = Settings::values.players.GetValue()[player_idx];
std::array<u32, 4> colors{};
std::transform(controllers_colors[player_idx].begin(), controllers_colors[player_idx].end(),
colors.begin(), [](QColor color) { return color.rgb(); });
player.body_color_left = colors[0];
player.button_color_left = colors[1];
player.body_color_right = colors[2];
player.button_color_right = colors[3];
hid_core.GetEmulatedControllerByIndex(player_idx)->ReloadColorsFromSettings();
}
Settings::values.debug_pad_enabled = ui->debug_enabled->isChecked();
Settings::values.mouse_enabled = ui->mouse_enabled->isChecked();
Settings::values.keyboard_enabled = ui->keyboard_enabled->isChecked();
Settings::values.emulate_analog_keyboard = ui->emulate_analog_keyboard->isChecked();
Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked();
Settings::values.enable_raw_input = ui->enable_raw_input->isChecked();
Settings::values.enable_udp_controller = ui->enable_udp_controller->isChecked();
Settings::values.controller_navigation = ui->controller_navigation->isChecked();
Settings::values.enable_ring_controller = ui->enable_ring_controller->isChecked();
Settings::values.enable_ir_sensor = ui->enable_ir_sensor->isChecked();
Settings::values.enable_joycon_driver = ui->enable_joycon_driver->isChecked();
Settings::values.enable_procon_driver = ui->enable_procon_driver->isChecked();
Settings::values.random_amiibo_id = ui->random_amiibo_id->isChecked();
}
void ConfigureInputAdvanced::LoadConfiguration() {
for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
auto& player = Settings::values.players.GetValue()[player_idx];
std::array<u32, 4> colors = {
player.body_color_left,
player.button_color_left,
player.body_color_right,
player.button_color_right,
};
std::transform(colors.begin(), colors.end(), controllers_colors[player_idx].begin(),
[](u32 rgb) { return QColor::fromRgb(rgb); });
for (std::size_t button_idx = 0; button_idx < colors.size(); ++button_idx) {
controllers_color_buttons[player_idx][button_idx]->setStyleSheet(
QStringLiteral("background-color: %1; min-width: 60px;")
.arg(controllers_colors[player_idx][button_idx].name()));
}
}
ui->debug_enabled->setChecked(Settings::values.debug_pad_enabled.GetValue());
ui->mouse_enabled->setChecked(Settings::values.mouse_enabled.GetValue());
ui->keyboard_enabled->setChecked(Settings::values.keyboard_enabled.GetValue());
ui->emulate_analog_keyboard->setChecked(Settings::values.emulate_analog_keyboard.GetValue());
ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled);
ui->enable_raw_input->setChecked(Settings::values.enable_raw_input.GetValue());
ui->enable_udp_controller->setChecked(Settings::values.enable_udp_controller.GetValue());
ui->controller_navigation->setChecked(Settings::values.controller_navigation.GetValue());
ui->enable_ring_controller->setChecked(Settings::values.enable_ring_controller.GetValue());
ui->enable_ir_sensor->setChecked(Settings::values.enable_ir_sensor.GetValue());
ui->enable_joycon_driver->setChecked(Settings::values.enable_joycon_driver.GetValue());
ui->enable_procon_driver->setChecked(Settings::values.enable_procon_driver.GetValue());
ui->random_amiibo_id->setChecked(Settings::values.random_amiibo_id.GetValue());
UpdateUIEnabled();
}
void ConfigureInputAdvanced::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureInputAdvanced::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureInputAdvanced::UpdateUIEnabled() {
ui->debug_configure->setEnabled(ui->debug_enabled->isChecked());
ui->touchscreen_advanced->setEnabled(ui->touchscreen_enabled->isChecked());
ui->ring_controller_configure->setEnabled(ui->enable_ring_controller->isChecked());
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) || !defined(SUYU_USE_QT_MULTIMEDIA)
ui->enable_ir_sensor->setEnabled(false);
ui->camera_configure->setEnabled(false);
#endif
}

View File

@@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include <memory>
#include <QWidget>
class QColor;
class QPushButton;
namespace Ui {
class ConfigureInputAdvanced;
}
namespace Core::HID {
class HIDCore;
} // namespace Core::HID
class ConfigureInputAdvanced : public QWidget {
Q_OBJECT
public:
explicit ConfigureInputAdvanced(Core::HID::HIDCore& hid_core_, QWidget* parent = nullptr);
~ConfigureInputAdvanced() override;
void ApplyConfiguration();
signals:
void CallDebugControllerDialog();
void CallMouseConfigDialog();
void CallTouchscreenConfigDialog();
void CallMotionTouchConfigDialog();
void CallRingControllerDialog();
void CallCameraDialog();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void UpdateUIEnabled();
void OnControllerButtonClick(std::size_t player_idx, std::size_t button_idx);
void LoadConfiguration();
std::unique_ptr<Ui::ConfigureInputAdvanced> ui;
std::array<std::array<QColor, 4>, 8> controllers_colors;
std::array<std::array<QPushButton*, 4>, 8> controllers_color_buttons;
Core::HID::HIDCore& hid_core;
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
#include "core/core.h"
#include "frontend_common/config.h"
#include "hid_core/frontend/emulated_controller.h"
#include "hid_core/hid_core.h"
#include "ui_configure_input_per_game.h"
#include "suyu/configuration/configure_input_per_game.h"
#include "suyu/configuration/input_profiles.h"
ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QtConfig* config_,
QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInputPerGame>()),
profiles(std::make_unique<InputProfiles>()), system{system_}, config{config_} {
ui->setupUi(this);
const std::array labels = {
ui->label_player_1, ui->label_player_2, ui->label_player_3, ui->label_player_4,
ui->label_player_5, ui->label_player_6, ui->label_player_7, ui->label_player_8,
};
profile_comboboxes = {
ui->profile_player_1, ui->profile_player_2, ui->profile_player_3, ui->profile_player_4,
ui->profile_player_5, ui->profile_player_6, ui->profile_player_7, ui->profile_player_8,
};
Settings::values.players.SetGlobal(false);
const auto& profile_names = profiles->GetInputProfileNames();
const auto populate_profiles = [this, &profile_names](size_t player_index) {
const auto previous_profile =
Settings::values.players.GetValue()[player_index].profile_name;
auto* const player_combobox = profile_comboboxes[player_index];
player_combobox->addItem(tr("Use global input configuration"));
for (size_t index = 0; index < profile_names.size(); ++index) {
const auto& profile_name = profile_names[index];
player_combobox->addItem(QString::fromStdString(profile_name));
if (profile_name == previous_profile) {
// offset by 1 since the first element is the global config
player_combobox->setCurrentIndex(static_cast<int>(index + 1));
}
}
};
for (size_t index = 0; index < profile_comboboxes.size(); ++index) {
labels[index]->setText(tr("Player %1 profile").arg(index + 1));
populate_profiles(index);
}
LoadConfiguration();
}
void ConfigureInputPerGame::ApplyConfiguration() {
LoadConfiguration();
SaveConfiguration();
}
void ConfigureInputPerGame::LoadConfiguration() {
static constexpr size_t HANDHELD_INDEX = 8;
auto& hid_core = system.HIDCore();
for (size_t player_index = 0; player_index < profile_comboboxes.size(); ++player_index) {
Settings::values.players.SetGlobal(false);
auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index);
auto* const player_combobox = profile_comboboxes[player_index];
const auto selection_index = player_combobox->currentIndex();
if (selection_index == 0) {
Settings::values.players.GetValue()[player_index].profile_name = "";
if (player_index == 0) {
Settings::values.players.GetValue()[HANDHELD_INDEX] = {};
}
Settings::values.players.SetGlobal(true);
emulated_controller->ReloadFromSettings();
continue;
}
const auto profile_name = player_combobox->itemText(selection_index).toStdString();
if (profile_name.empty()) {
continue;
}
auto& player = Settings::values.players.GetValue()[player_index];
player.profile_name = profile_name;
// Read from the profile into the custom player settings
profiles->LoadProfile(profile_name, player_index);
// Make sure the controller is connected
player.connected = true;
emulated_controller->ReloadFromSettings();
if (player_index > 0) {
continue;
}
// Handle Handheld cases
auto& handheld_player = Settings::values.players.GetValue()[HANDHELD_INDEX];
auto* handheld_controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld);
if (player.controller_type == Settings::ControllerType::Handheld) {
handheld_player = player;
} else {
handheld_player = {};
}
handheld_controller->ReloadFromSettings();
}
}
void ConfigureInputPerGame::SaveConfiguration() {
Settings::values.players.SetGlobal(false);
// Clear all controls from the config in case the user reverted back to globals
config->ClearControlPlayerValues();
for (size_t index = 0; index < Settings::values.players.GetValue().size(); ++index) {
config->SaveQtControlPlayerValues(index);
}
}

View File

@@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QWidget>
#include "ui_configure_input_per_game.h"
#include "suyu/configuration/input_profiles.h"
#include "suyu/configuration/qt_config.h"
class QComboBox;
namespace Core {
class System;
} // namespace Core
class Config;
class ConfigureInputPerGame : public QWidget {
Q_OBJECT
public:
explicit ConfigureInputPerGame(Core::System& system_, QtConfig* config_,
QWidget* parent = nullptr);
/// Load and Save configurations to settings file.
void ApplyConfiguration();
private:
/// Load configuration from settings file.
void LoadConfiguration();
/// Save configuration to settings file.
void SaveConfiguration();
std::unique_ptr<Ui::ConfigureInputPerGame> ui;
std::unique_ptr<InputProfiles> profiles;
std::array<QComboBox*, 8> profile_comboboxes;
Core::System& system;
QtConfig* config;
};

View File

@@ -0,0 +1,333 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureInputPerGame</class>
<widget class="QWidget" name="PerGameInput">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>541</width>
<height>759</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>Graphics</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Input Profiles</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QWidget" name="player_1" native="true">
<layout class="QHBoxLayout" name="input_profile_layout_1">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_player_1">
<property name="text">
<string>Player 1 Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="profile_player_1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="player_2" native="true">
<layout class="QHBoxLayout" name="input_profile_layout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_player_2">
<property name="text">
<string>Player 2 Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="profile_player_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="player_3" native="true">
<layout class="QHBoxLayout" name="input_profile_layout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_player_3">
<property name="text">
<string>Player 3 Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="profile_player_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="player_4" native="true">
<layout class="QHBoxLayout" name="input_profile_layout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_player_4">
<property name="text">
<string>Player 4 Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="profile_player_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="player_5" native="true">
<layout class="QHBoxLayout" name="input_profile_layout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_player_5">
<property name="text">
<string>Player 5 Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="profile_player_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="player_6" native="true">
<layout class="QHBoxLayout" name="input_profile_layout_6">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_player_6">
<property name="text">
<string>Player 6 Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="profile_player_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="player_7" native="true">
<layout class="QHBoxLayout" name="input_profile_layout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_player_7">
<property name="text">
<string>Player 7 Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="profile_player_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="player_8" native="true">
<layout class="QHBoxLayout" name="input_profile_layout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_player_8">
<property name="text">
<string>Player 8 Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="profile_player_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,228 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <QWidget>
#include "common/param_package.h"
#include "common/settings.h"
#include "ui_configure_input.h"
class QCheckBox;
class QKeyEvent;
class QLabel;
class QPushButton;
class QSlider;
class QSpinBox;
class QString;
class QTimer;
class QWidget;
class InputProfiles;
namespace InputCommon {
class InputSubsystem;
}
namespace InputCommon::Polling {
enum class InputType;
} // namespace InputCommon::Polling
namespace Ui {
class ConfigureInputPlayer;
} // namespace Ui
namespace Core::HID {
class HIDCore;
class EmulatedController;
enum class NpadStyleIndex : u8;
} // namespace Core::HID
class ConfigureInputPlayer : public QWidget {
Q_OBJECT
public:
explicit ConfigureInputPlayer(QWidget* parent, std::size_t player_index, QWidget* bottom_row,
InputCommon::InputSubsystem* input_subsystem_,
InputProfiles* profiles_, Core::HID::HIDCore& hid_core_,
bool is_powered_on_, bool debug = false);
~ConfigureInputPlayer() override;
/// Save all button configurations to settings file.
void ApplyConfiguration();
/// Set the connection state checkbox (used to sync state).
void ConnectPlayer(bool connected);
/// Update the input devices combobox.
void UpdateInputDeviceCombobox();
/// Updates the list of controller profiles.
void UpdateInputProfiles();
/// Restore all buttons to their default values.
void RestoreDefaults();
/// Clear all input configuration.
void ClearAll();
signals:
/// Emitted when this controller is (dis)connected by the user.
void Connected(bool connected);
/// Emitted when the Handheld mode is selected (undocked with dual joycons attached).
void HandheldStateChanged(bool is_handheld);
/// Emitted when the input devices combobox is being refreshed.
void RefreshInputDevices();
/**
* Emitted when the input profiles combobox is being refreshed.
* The player_index represents the current player's index, and the profile combobox
* will not be updated for this index as they are already updated by other mechanisms.
*/
void RefreshInputProfiles(std::size_t player_index);
protected:
void showEvent(QShowEvent* event) override;
private:
QString ButtonToText(const Common::ParamPackage& param);
QString AnalogToText(const Common::ParamPackage& param, const std::string& dir);
void changeEvent(QEvent* event) override;
void RetranslateUI();
/// Load configuration settings.
void LoadConfiguration();
/// Called when the button was pressed.
void HandleClick(QPushButton* button, std::size_t button_id,
std::function<void(const Common::ParamPackage&)> new_input_setter,
InputCommon::Polling::InputType type);
/// Finish polling and configure input using the input_setter.
void SetPollingResult(const Common::ParamPackage& params, bool abort);
/// Checks whether a given input can be accepted.
bool IsInputAcceptable(const Common::ParamPackage& params) const;
/// Handle mouse button press events.
void mousePressEvent(QMouseEvent* event) override;
/// Handle mouse wheel move events.
void wheelEvent(QWheelEvent* event) override;
/// Handle key press events.
void keyPressEvent(QKeyEvent* event) override;
/// Handle combobox list refresh
bool eventFilter(QObject* object, QEvent* event) override;
/// Update UI to reflect current configuration.
void UpdateUI();
/// Sets the available controllers.
void SetConnectableControllers();
/// Gets the Controller Type for a given controller combobox index.
Core::HID::NpadStyleIndex GetControllerTypeFromIndex(int index) const;
/// Gets the controller combobox index for a given Controller Type.
int GetIndexFromControllerType(Core::HID::NpadStyleIndex type) const;
/// Update the available input devices.
void UpdateInputDevices();
/// Hides and disables controller settings based on the current controller type.
void UpdateControllerAvailableButtons();
/// Disables controller settings based on the current controller type.
void UpdateControllerEnabledButtons();
/// Shows or hides motion groupboxes based on the current controller type.
void UpdateMotionButtons();
/// Alters the button names based on the current controller type.
void UpdateControllerButtonNames();
/// Gets the default controller mapping for this device and auto configures the input to match.
void UpdateMappingWithDefaults();
/// Creates a controller profile.
void CreateProfile();
/// Deletes the selected controller profile.
void DeleteProfile();
/// Loads the selected controller profile.
void LoadProfile();
/// Saves the current controller configuration into a selected controller profile.
void SaveProfile();
std::unique_ptr<Ui::ConfigureInputPlayer> ui;
std::size_t player_index;
bool debug;
bool is_powered_on;
InputCommon::InputSubsystem* input_subsystem;
InputProfiles* profiles;
std::unique_ptr<QTimer> timeout_timer;
std::unique_ptr<QTimer> poll_timer;
/// Stores a pair of "Connected Controllers" combobox index and Controller Type enum.
std::vector<std::pair<int, Core::HID::NpadStyleIndex>> index_controller_type_pairs;
/// This will be the the setting function when an input is awaiting configuration.
std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
Core::HID::EmulatedController* emulated_controller;
static constexpr int ANALOG_SUB_BUTTONS_NUM = 4;
/// Each button input is represented by a QPushButton.
std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map;
/// A group of four QPushButtons represent one analog input. The buttons each represent up,
/// down, left, right, respectively.
std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs>
analog_map_buttons;
/// Each motion input is represented by a QPushButton.
std::array<QPushButton*, Settings::NativeMotion::NumMotions> motion_map;
std::array<QLabel*, Settings::NativeAnalog::NumAnalogs> analog_map_deadzone_label;
std::array<QSlider*, Settings::NativeAnalog::NumAnalogs> analog_map_deadzone_slider;
std::array<QGroupBox*, Settings::NativeAnalog::NumAnalogs> analog_map_modifier_groupbox;
std::array<QPushButton*, Settings::NativeAnalog::NumAnalogs> analog_map_modifier_button;
std::array<QLabel*, Settings::NativeAnalog::NumAnalogs> analog_map_modifier_label;
std::array<QSlider*, Settings::NativeAnalog::NumAnalogs> analog_map_modifier_slider;
std::array<QGroupBox*, Settings::NativeAnalog::NumAnalogs> analog_map_range_groupbox;
std::array<QSpinBox*, Settings::NativeAnalog::NumAnalogs> analog_map_range_spinbox;
static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
/// A flag to indicate that the "Map Analog Stick" pop-up has been shown and accepted once.
bool map_analog_stick_accepted{};
/// List of physical devices users can map with. If a SDL backed device is selected, then you
/// can use this device to get a default mapping.
std::vector<Common::ParamPackage> input_devices;
/// Bottom row is where console wide settings are held, and its "owned" by the parent
/// ConfigureInput widget. On show, add this widget to the main layout. This will change the
/// parent of the widget to this widget (but that's fine).
QWidget* bottom_row;
Core::HID::HIDCore& hid_core;
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,230 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include <QFrame>
#include <QPointer>
#include "common/input.h"
#include "common/settings_input.h"
#include "common/vector_math.h"
#include "hid_core/frontend/emulated_controller.h"
#include "hid_core/hid_types.h"
class QLabel;
using AnalogParam = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>;
using ButtonParam = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>;
// Widget for representing controller animations
class PlayerControlPreview : public QFrame {
Q_OBJECT
public:
explicit PlayerControlPreview(QWidget* parent);
~PlayerControlPreview() override;
// Sets the emulated controller to be displayed
void SetController(Core::HID::EmulatedController* controller);
// Disables events from the emulated controller
void UnloadController();
// Starts blinking animation at the button specified
void BeginMappingButton(std::size_t button_id);
// Starts moving animation at the stick specified
void BeginMappingAnalog(std::size_t stick_id);
// Stops any ongoing animation
void EndMapping();
// Handles emulated controller events
void ControllerUpdate(Core::HID::ControllerTriggerType type);
// Updates input on scheduled interval
void UpdateInput();
protected:
void paintEvent(QPaintEvent* event) override;
private:
enum class Direction : std::size_t {
None,
Up,
Right,
Down,
Left,
};
enum class Symbol {
House,
A,
B,
X,
Y,
L,
R,
C,
SL,
ZL,
ZR,
SR,
Charging,
};
struct ColorMapping {
QColor outline{};
QColor primary{};
QColor left{};
QColor right{};
QColor button{};
QColor button2{};
QColor button_turbo{};
QColor font{};
QColor font2{};
QColor highlight{};
QColor highlight2{};
QColor transparent{};
QColor indicator{};
QColor indicator2{};
QColor led_on{};
QColor led_off{};
QColor slider{};
QColor slider_button{};
QColor slider_arrow{};
QColor deadzone{};
QColor charging{};
};
void UpdateColors();
void ResetInputs();
// Draw controller functions
void DrawHandheldController(QPainter& p, QPointF center);
void DrawDualController(QPainter& p, QPointF center);
void DrawLeftController(QPainter& p, QPointF center);
void DrawRightController(QPainter& p, QPointF center);
void DrawProController(QPainter& p, QPointF center);
void DrawGCController(QPainter& p, QPointF center);
// Draw body functions
void DrawHandheldBody(QPainter& p, QPointF center);
void DrawDualBody(QPainter& p, QPointF center);
void DrawLeftBody(QPainter& p, QPointF center);
void DrawRightBody(QPainter& p, QPointF center);
void DrawProBody(QPainter& p, QPointF center);
void DrawGCBody(QPainter& p, QPointF center);
// Draw triggers functions
void DrawProTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed,
const Common::Input::ButtonStatus& right_pressed);
void DrawGCTriggers(QPainter& p, QPointF center, Common::Input::TriggerStatus left_trigger,
Common::Input::TriggerStatus right_trigger);
void DrawHandheldTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed,
const Common::Input::ButtonStatus& right_pressed);
void DrawDualTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed,
const Common::Input::ButtonStatus& right_pressed);
void DrawDualTriggersTopView(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed,
const Common::Input::ButtonStatus& right_pressed);
void DrawDualZTriggersTopView(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed,
const Common::Input::ButtonStatus& right_pressed);
void DrawLeftTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed);
void DrawLeftZTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed);
void DrawLeftTriggersTopView(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed);
void DrawLeftZTriggersTopView(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed);
void DrawRightTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& right_pressed);
void DrawRightZTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& right_pressed);
void DrawRightTriggersTopView(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& right_pressed);
void DrawRightZTriggersTopView(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& right_pressed);
// Draw joystick functions
void DrawJoystick(QPainter& p, QPointF center, float size,
const Common::Input::ButtonStatus& pressed);
void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size,
const Common::Input::ButtonStatus& pressed);
void DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right);
void DrawJoystickProperties(QPainter& p, QPointF center,
const Common::Input::AnalogProperties& properties);
void DrawJoystickDot(QPainter& p, QPointF center, const Common::Input::StickStatus& stick,
bool raw);
void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar,
const Common::Input::ButtonStatus& pressed);
void DrawGCJoystick(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
// Draw button functions
void DrawCircleButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
float button_size);
void DrawRoundButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
float width, float height, Direction direction = Direction::None,
float radius = 2);
void DrawMinusButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
int button_size);
void DrawPlusButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
int button_size);
void DrawGCButtonX(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
void DrawGCButtonY(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
void DrawGCButtonZ(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
void DrawArrowButtonOutline(QPainter& p, const QPointF center, float size = 1.0f);
void DrawArrowButton(QPainter& p, QPointF center, Direction direction,
const Common::Input::ButtonStatus& pressed, float size = 1.0f);
void DrawTriggerButton(QPainter& p, QPointF center, Direction direction,
const Common::Input::ButtonStatus& pressed);
QColor GetButtonColor(QColor default_color, bool is_pressed, bool turbo);
// Draw battery functions
void DrawBattery(QPainter& p, QPointF center, Common::Input::BatteryLevel battery);
// Draw icon functions
void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size);
void DrawArrow(QPainter& p, QPointF center, Direction direction, float size);
// Draw motion functions
void Draw3dCube(QPainter& p, QPointF center, const Common::Vec3f& euler, float size);
// Draw primitive types
template <size_t N>
void DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon);
void DrawCircle(QPainter& p, QPointF center, float size);
void DrawRectangle(QPainter& p, QPointF center, float width, float height);
void DrawRoundRectangle(QPainter& p, QPointF center, float width, float height, float round);
void DrawText(QPainter& p, QPointF center, float text_size, const QString& text);
void SetTextFont(QPainter& p, float text_size,
const QString& font_family = QStringLiteral("sans-serif"));
bool is_controller_set{};
bool is_connected{};
bool needs_redraw{};
Core::HID::NpadStyleIndex controller_type;
bool mapping_active{};
int blink_counter{};
int callback_key;
QColor button_color{};
ColorMapping colors{};
Core::HID::LedPattern led_pattern{0, 0, 0, 0};
std::size_t player_index{};
Core::HID::EmulatedController* controller;
std::size_t button_mapping_index{Settings::NativeButton::NumButtons};
std::size_t analog_mapping_index{Settings::NativeAnalog::NumAnalogs};
Core::HID::ButtonValues button_values{};
Core::HID::SticksValues stick_values{};
Core::HID::TriggerValues trigger_values{};
Core::HID::BatteryValues battery_values{};
Core::HID::MotionState motion_values{};
};

View File

@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core.h"
#include "ui_configure_input_profile_dialog.h"
#include "suyu/configuration/configure_input_player.h"
#include "suyu/configuration/configure_input_profile_dialog.h"
ConfigureInputProfileDialog::ConfigureInputProfileDialog(
QWidget* parent, InputCommon::InputSubsystem* input_subsystem, InputProfiles* profiles,
Core::System& system)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureInputProfileDialog>()),
profile_widget(new ConfigureInputPlayer(this, 9, nullptr, input_subsystem, profiles,
system.HIDCore(), system.IsPoweredOn(), false)) {
ui->setupUi(this);
ui->controllerLayout->addWidget(profile_widget);
connect(ui->clear_all_button, &QPushButton::clicked, this,
[this] { profile_widget->ClearAll(); });
connect(ui->restore_defaults_button, &QPushButton::clicked, this,
[this] { profile_widget->RestoreDefaults(); });
RetranslateUI();
}
ConfigureInputProfileDialog::~ConfigureInputProfileDialog() = default;
void ConfigureInputProfileDialog::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigureInputProfileDialog::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QDialog>
class QPushButton;
class ConfigureInputPlayer;
class InputProfiles;
namespace Core {
class System;
}
namespace InputCommon {
class InputSubsystem;
}
namespace Ui {
class ConfigureInputProfileDialog;
}
class ConfigureInputProfileDialog : public QDialog {
Q_OBJECT
public:
explicit ConfigureInputProfileDialog(QWidget* parent,
InputCommon::InputSubsystem* input_subsystem,
InputProfiles* profiles, Core::System& system);
~ConfigureInputProfileDialog() override;
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
std::unique_ptr<Ui::ConfigureInputProfileDialog> ui;
ConfigureInputPlayer* profile_widget;
};

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureInputProfileDialog</class>
<widget class="QDialog" name="ConfigureInputProfileDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>70</width>
<height>540</height>
</rect>
</property>
<property name="windowTitle">
<string>Create Input Profile</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" name="controllerLayout"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="clear_all_button">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="restore_defaults_button">
<property name="text">
<string>Defaults</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigureInputProfileDialog</receiver>
<slot>accept()</slot>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,75 @@
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_linux_tab.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_linux_tab.h"
#include "suyu/configuration/shared_widget.h"
ConfigureLinuxTab::ConfigureLinuxTab(const Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::Builder& builder, QWidget* parent)
: Tab(group_, parent), ui(std::make_unique<Ui::ConfigureLinuxTab>()), system{system_} {
ui->setupUi(this);
Setup(builder);
SetConfiguration();
}
ConfigureLinuxTab::~ConfigureLinuxTab() = default;
void ConfigureLinuxTab::SetConfiguration() {}
void ConfigureLinuxTab::Setup(const ConfigurationShared::Builder& builder) {
QLayout& linux_layout = *ui->linux_widget->layout();
std::map<u32, QWidget*> linux_hold{};
std::vector<Settings::BasicSetting*> settings;
const auto push = [&](Settings::Category category) {
for (const auto setting : Settings::values.linkage.by_category[category]) {
settings.push_back(setting);
}
};
push(Settings::Category::Linux);
for (auto* setting : settings) {
auto* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
widget->deleteLater();
continue;
}
linux_hold.insert({setting->Id(), widget});
}
for (const auto& [id, widget] : linux_hold) {
linux_layout.addWidget(widget);
}
}
void ConfigureLinuxTab::ApplyConfiguration() {
const bool is_powered_on = system.IsPoweredOn();
for (const auto& apply_func : apply_funcs) {
apply_func(is_powered_on);
}
}
void ConfigureLinuxTab::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureLinuxTab::RetranslateUI() {
ui->retranslateUi(this);
}

View File

@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QWidget>
namespace Core {
class System;
}
namespace Ui {
class ConfigureLinuxTab;
}
namespace ConfigurationShared {
class Builder;
}
class ConfigureLinuxTab : public ConfigurationShared::Tab {
Q_OBJECT
public:
explicit ConfigureLinuxTab(const Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group,
const ConfigurationShared::Builder& builder,
QWidget* parent = nullptr);
~ConfigureLinuxTab() override;
void ApplyConfiguration() override;
void SetConfiguration() override;
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void Setup(const ConfigurationShared::Builder& builder);
std::unique_ptr<Ui::ConfigureLinuxTab> ui;
const Core::System& system;
std::vector<std::function<void(bool)>> apply_funcs{};
};

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureLinuxTab</class>
<widget class="QWidget" name="ConfigureLinuxTab">
<property name="accessibleName">
<string>Linux</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="LinuxGroupBox">
<property name="title">
<string>Linux</string>
</property>
<layout class="QVBoxLayout" name="LinuxVerticalLayout_1">
<item>
<widget class="QWidget" name="linux_widget" native="true">
<layout class="QVBoxLayout" name="LinuxVerticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,326 @@
// SPDX-FileCopyrightText: 2018 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <sstream>
#include <QCloseEvent>
#include <QMessageBox>
#include <QStringListModel>
#include "common/logging/log.h"
#include "common/settings.h"
#include "input_common/drivers/udp_client.h"
#include "input_common/helpers/udp_protocol.h"
#include "input_common/main.h"
#include "ui_configure_motion_touch.h"
#include "suyu/configuration/configure_motion_touch.h"
#include "suyu/configuration/configure_touch_from_button.h"
CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent,
const std::string& host, u16 port)
: QDialog(parent) {
layout = new QVBoxLayout;
status_label = new QLabel(tr("Communicating with the server..."));
cancel_button = new QPushButton(tr("Cancel"));
connect(cancel_button, &QPushButton::clicked, this, [this] {
if (!completed) {
job->Stop();
}
accept();
});
layout->addWidget(status_label);
layout->addWidget(cancel_button);
setLayout(layout);
using namespace InputCommon::CemuhookUDP;
job = std::make_unique<CalibrationConfigurationJob>(
host, port,
[this](CalibrationConfigurationJob::Status status) {
QMetaObject::invokeMethod(this, [status, this] {
QString text;
switch (status) {
case CalibrationConfigurationJob::Status::Ready:
text = tr("Touch the top left corner <br>of your touchpad.");
break;
case CalibrationConfigurationJob::Status::Stage1Completed:
text = tr("Now touch the bottom right corner <br>of your touchpad.");
break;
case CalibrationConfigurationJob::Status::Completed:
text = tr("Configuration completed!");
break;
default:
break;
}
UpdateLabelText(text);
});
if (status == CalibrationConfigurationJob::Status::Completed) {
QMetaObject::invokeMethod(this, [this] { UpdateButtonText(tr("OK")); });
}
},
[this](u16 min_x_, u16 min_y_, u16 max_x_, u16 max_y_) {
completed = true;
min_x = min_x_;
min_y = min_y_;
max_x = max_x_;
max_y = max_y_;
});
}
CalibrationConfigurationDialog::~CalibrationConfigurationDialog() = default;
void CalibrationConfigurationDialog::UpdateLabelText(const QString& text) {
status_label->setText(text);
}
void CalibrationConfigurationDialog::UpdateButtonText(const QString& text) {
cancel_button->setText(text);
}
ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent,
InputCommon::InputSubsystem* input_subsystem_)
: QDialog(parent), input_subsystem{input_subsystem_},
ui(std::make_unique<Ui::ConfigureMotionTouch>()) {
ui->setupUi(this);
ui->udp_learn_more->setOpenExternalLinks(true);
ui->udp_learn_more->setText(
tr("<a "
"href='https://suyu.dev/wiki/"
"using-a-controller-or-android-phone-for-motion-or-touch-input'><span "
"style=\"text-decoration: underline; color:#039be5;\">Learn More</span></a>"));
SetConfiguration();
UpdateUiDisplay();
ConnectEvents();
}
ConfigureMotionTouch::~ConfigureMotionTouch() = default;
void ConfigureMotionTouch::SetConfiguration() {
const Common::ParamPackage touch_param(Settings::values.touch_device.GetValue());
touch_from_button_maps = Settings::values.touch_from_button_maps;
for (const auto& touch_map : touch_from_button_maps) {
ui->touch_from_button_map->addItem(QString::fromStdString(touch_map.name));
}
ui->touch_from_button_map->setCurrentIndex(
Settings::values.touch_from_button_map_index.GetValue());
min_x = touch_param.Get("min_x", 100);
min_y = touch_param.Get("min_y", 50);
max_x = touch_param.Get("max_x", 1800);
max_y = touch_param.Get("max_y", 850);
ui->udp_server->setText(QString::fromStdString("127.0.0.1"));
ui->udp_port->setText(QString::number(26760));
udp_server_list_model = new QStringListModel(this);
udp_server_list_model->setStringList({});
ui->udp_server_list->setModel(udp_server_list_model);
std::stringstream ss(Settings::values.udp_input_servers.GetValue());
std::string token;
while (std::getline(ss, token, ',')) {
const int row = udp_server_list_model->rowCount();
udp_server_list_model->insertRows(row, 1);
const QModelIndex index = udp_server_list_model->index(row);
udp_server_list_model->setData(index, QString::fromStdString(token));
}
}
void ConfigureMotionTouch::UpdateUiDisplay() {
const QString cemuhook_udp = QStringLiteral("cemuhookudp");
ui->touch_calibration->setVisible(true);
ui->touch_calibration_config->setVisible(true);
ui->touch_calibration_label->setVisible(true);
ui->touch_calibration->setText(
QStringLiteral("(%1, %2) - (%3, %4)").arg(min_x).arg(min_y).arg(max_x).arg(max_y));
ui->udp_config_group_box->setVisible(true);
}
void ConfigureMotionTouch::ConnectEvents() {
connect(ui->udp_test, &QPushButton::clicked, this, &ConfigureMotionTouch::OnCemuhookUDPTest);
connect(ui->udp_add, &QPushButton::clicked, this, &ConfigureMotionTouch::OnUDPAddServer);
connect(ui->udp_remove, &QPushButton::clicked, this, &ConfigureMotionTouch::OnUDPDeleteServer);
connect(ui->touch_calibration_config, &QPushButton::clicked, this,
&ConfigureMotionTouch::OnConfigureTouchCalibration);
connect(ui->touch_from_button_config_btn, &QPushButton::clicked, this,
&ConfigureMotionTouch::OnConfigureTouchFromButton);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this,
&ConfigureMotionTouch::ApplyConfiguration);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [this] {
if (CanCloseDialog()) {
reject();
}
});
}
void ConfigureMotionTouch::OnUDPAddServer() {
// Validator for IP address
const QRegularExpression re(QStringLiteral(
R"re(^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$)re"));
bool ok;
const QString port_text = ui->udp_port->text();
const QString server_text = ui->udp_server->text();
const QString server_string = tr("%1:%2").arg(server_text, port_text);
const int port_number = port_text.toInt(&ok, 10);
const int row = udp_server_list_model->rowCount();
if (!ok) {
QMessageBox::warning(this, tr("suyu"), tr("Port number has invalid characters"));
return;
}
if (port_number < 0 || port_number > 65353) {
QMessageBox::warning(this, tr("suyu"), tr("Port has to be in range 0 and 65353"));
return;
}
if (!re.match(server_text).hasMatch()) {
QMessageBox::warning(this, tr("suyu"), tr("IP address is not valid"));
return;
}
// Search for duplicates
for (const auto& item : udp_server_list_model->stringList()) {
if (item == server_string) {
QMessageBox::warning(this, tr("suyu"), tr("This UDP server already exists"));
return;
}
}
// Limit server count to 8
if (row == 8) {
QMessageBox::warning(this, tr("suyu"), tr("Unable to add more than 8 servers"));
return;
}
udp_server_list_model->insertRows(row, 1);
QModelIndex index = udp_server_list_model->index(row);
udp_server_list_model->setData(index, server_string);
ui->udp_server_list->setCurrentIndex(index);
}
void ConfigureMotionTouch::OnUDPDeleteServer() {
udp_server_list_model->removeRows(ui->udp_server_list->currentIndex().row(), 1);
}
void ConfigureMotionTouch::OnCemuhookUDPTest() {
ui->udp_test->setEnabled(false);
ui->udp_test->setText(tr("Testing"));
udp_test_in_progress = true;
InputCommon::CemuhookUDP::TestCommunication(
ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toInt()),
[this] {
LOG_INFO(Frontend, "UDP input test success");
QMetaObject::invokeMethod(this, [this] { ShowUDPTestResult(true); });
},
[this] {
LOG_ERROR(Frontend, "UDP input test failed");
QMetaObject::invokeMethod(this, [this] { ShowUDPTestResult(false); });
});
}
void ConfigureMotionTouch::OnConfigureTouchCalibration() {
ui->touch_calibration_config->setEnabled(false);
ui->touch_calibration_config->setText(tr("Configuring"));
CalibrationConfigurationDialog dialog(this, ui->udp_server->text().toStdString(),
static_cast<u16>(ui->udp_port->text().toUInt()));
dialog.exec();
if (dialog.completed) {
min_x = dialog.min_x;
min_y = dialog.min_y;
max_x = dialog.max_x;
max_y = dialog.max_y;
LOG_INFO(Frontend,
"UDP touchpad calibration config success: min_x={}, min_y={}, max_x={}, max_y={}",
min_x, min_y, max_x, max_y);
UpdateUiDisplay();
} else {
LOG_ERROR(Frontend, "UDP touchpad calibration config failed");
}
ui->touch_calibration_config->setEnabled(true);
ui->touch_calibration_config->setText(tr("Configure"));
}
void ConfigureMotionTouch::closeEvent(QCloseEvent* event) {
if (CanCloseDialog()) {
event->accept();
} else {
event->ignore();
}
}
void ConfigureMotionTouch::ShowUDPTestResult(bool result) {
udp_test_in_progress = false;
if (result) {
QMessageBox::information(this, tr("Test Successful"),
tr("Successfully received data from the server."));
} else {
QMessageBox::warning(this, tr("Test Failed"),
tr("Could not receive valid data from the server.<br>Please verify "
"that the server is set up correctly and "
"the address and port are correct."));
}
ui->udp_test->setEnabled(true);
ui->udp_test->setText(tr("Test"));
}
void ConfigureMotionTouch::OnConfigureTouchFromButton() {
ConfigureTouchFromButton dialog{this, touch_from_button_maps, input_subsystem,
ui->touch_from_button_map->currentIndex()};
if (dialog.exec() != QDialog::Accepted) {
return;
}
touch_from_button_maps = dialog.GetMaps();
while (ui->touch_from_button_map->count() > 0) {
ui->touch_from_button_map->removeItem(0);
}
for (const auto& touch_map : touch_from_button_maps) {
ui->touch_from_button_map->addItem(QString::fromStdString(touch_map.name));
}
ui->touch_from_button_map->setCurrentIndex(dialog.GetSelectedIndex());
}
bool ConfigureMotionTouch::CanCloseDialog() {
if (udp_test_in_progress) {
QMessageBox::warning(this, tr("suyu"),
tr("UDP Test or calibration configuration is in progress.<br>Please "
"wait for them to finish."));
return false;
}
return true;
}
void ConfigureMotionTouch::ApplyConfiguration() {
if (!CanCloseDialog()) {
return;
}
Common::ParamPackage touch_param{};
touch_param.Set("min_x", min_x);
touch_param.Set("min_y", min_y);
touch_param.Set("max_x", max_x);
touch_param.Set("max_y", max_y);
Settings::values.touch_device = touch_param.Serialize();
Settings::values.touch_from_button_map_index = ui->touch_from_button_map->currentIndex();
Settings::values.touch_from_button_maps = touch_from_button_maps;
Settings::values.udp_input_servers = GetUDPServerString();
input_subsystem->ReloadInputDevices();
accept();
}
std::string ConfigureMotionTouch::GetUDPServerString() const {
QString input_servers;
for (const auto& item : udp_server_list_model->stringList()) {
input_servers += item;
input_servers += QLatin1Char{','};
}
// Remove last comma
input_servers.chop(1);
return input_servers.toStdString();
}

View File

@@ -0,0 +1,93 @@
// SPDX-FileCopyrightText: 2018 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QDialog>
class QLabel;
class QPushButton;
class QStringListModel;
class QVBoxLayout;
namespace InputCommon {
class InputSubsystem;
}
namespace InputCommon::CemuhookUDP {
class CalibrationConfigurationJob;
}
namespace Ui {
class ConfigureMotionTouch;
}
/// A dialog for touchpad calibration configuration.
class CalibrationConfigurationDialog : public QDialog {
Q_OBJECT
public:
explicit CalibrationConfigurationDialog(QWidget* parent, const std::string& host, u16 port);
~CalibrationConfigurationDialog() override;
private:
Q_INVOKABLE void UpdateLabelText(const QString& text);
Q_INVOKABLE void UpdateButtonText(const QString& text);
QVBoxLayout* layout;
QLabel* status_label;
QPushButton* cancel_button;
std::unique_ptr<InputCommon::CemuhookUDP::CalibrationConfigurationJob> job;
// Configuration results
bool completed{};
u16 min_x{};
u16 min_y{};
u16 max_x{};
u16 max_y{};
friend class ConfigureMotionTouch;
};
class ConfigureMotionTouch : public QDialog {
Q_OBJECT
public:
explicit ConfigureMotionTouch(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_);
~ConfigureMotionTouch() override;
public slots:
void ApplyConfiguration();
private slots:
void OnUDPAddServer();
void OnUDPDeleteServer();
void OnCemuhookUDPTest();
void OnConfigureTouchCalibration();
void OnConfigureTouchFromButton();
private:
void closeEvent(QCloseEvent* event) override;
Q_INVOKABLE void ShowUDPTestResult(bool result);
void SetConfiguration();
void UpdateUiDisplay();
void ConnectEvents();
bool CanCloseDialog();
std::string GetUDPServerString() const;
InputCommon::InputSubsystem* input_subsystem;
std::unique_ptr<Ui::ConfigureMotionTouch> ui;
QStringListModel* udp_server_list_model;
// Coordinate system of the CemuhookUDP touch provider
int min_x{};
int min_y{};
int max_x{};
int max_y{};
bool udp_test_in_progress{};
std::vector<Settings::TouchFromButtonMap> touch_from_button_maps;
};

View File

@@ -0,0 +1,297 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureMotionTouch</class>
<widget class="QDialog" name="ConfigureMotionTouch">
<property name="windowTitle">
<string>Configure Motion / Touch</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="touch_group_box">
<property name="title">
<string>Touch</string>
</property>
<layout class="QVBoxLayout">
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="touch_calibration_label">
<property name="text">
<string>UDP Calibration:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="touch_calibration">
<property name="text">
<string>(100, 50) - (1800, 850)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="touch_calibration_config">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Configure</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="touch_from_button_label">
<property name="text">
<string>Touch from button profile:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="touch_from_button_map"/>
</item>
<item>
<widget class="QPushButton" name="touch_from_button_config_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Configure</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="udp_config_group_box">
<property name="title">
<string>CemuhookUDP Config</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="udp_help">
<property name="text">
<string>You may use any Cemuhook compatible UDP input source to provide motion and touch input.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListView" name="udp_server_list"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="udp_server_label">
<property name="text">
<string>Server:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="udp_server">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<property name="leftMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="udp_port_label">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="udp_port">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<property name="leftMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="udp_learn_more">
<property name="text">
<string>Learn More</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="udp_test">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="udp_add">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Add Server</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<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>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="udp_remove">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remove Server</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>167</width>
<height>55</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,90 @@
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QCloseEvent>
#include <QMessageBox>
#include "common/settings.h"
#include "ui_configure_mouse_panning.h"
#include "suyu/configuration/configure_mouse_panning.h"
ConfigureMousePanning::ConfigureMousePanning(QWidget* parent,
InputCommon::InputSubsystem* input_subsystem_,
float right_stick_deadzone, float right_stick_range)
: QDialog(parent), input_subsystem{input_subsystem_},
ui(std::make_unique<Ui::ConfigureMousePanning>()) {
ui->setupUi(this);
SetConfiguration(right_stick_deadzone, right_stick_range);
ConnectEvents();
}
ConfigureMousePanning::~ConfigureMousePanning() = default;
void ConfigureMousePanning::closeEvent(QCloseEvent* event) {
event->accept();
}
void ConfigureMousePanning::SetConfiguration(float right_stick_deadzone, float right_stick_range) {
ui->enable->setChecked(Settings::values.mouse_panning.GetValue());
ui->x_sensitivity->setValue(Settings::values.mouse_panning_x_sensitivity.GetValue());
ui->y_sensitivity->setValue(Settings::values.mouse_panning_y_sensitivity.GetValue());
ui->deadzone_counterweight->setValue(
Settings::values.mouse_panning_deadzone_counterweight.GetValue());
ui->decay_strength->setValue(Settings::values.mouse_panning_decay_strength.GetValue());
ui->min_decay->setValue(Settings::values.mouse_panning_min_decay.GetValue());
if (right_stick_deadzone > 0.0f || right_stick_range != 1.0f) {
const QString right_stick_deadzone_str =
QString::fromStdString(std::to_string(static_cast<int>(right_stick_deadzone * 100.0f)));
const QString right_stick_range_str =
QString::fromStdString(std::to_string(static_cast<int>(right_stick_range * 100.0f)));
ui->warning_label->setText(
tr("Mouse panning works better with a deadzone of 0% and a range of 100%.\nCurrent "
"values are %1% and %2% respectively.")
.arg(right_stick_deadzone_str, right_stick_range_str));
}
if (Settings::values.mouse_enabled) {
ui->warning_label->setText(
tr("Emulated mouse is enabled. This is incompatible with mouse panning."));
}
}
void ConfigureMousePanning::SetDefaultConfiguration() {
ui->x_sensitivity->setValue(Settings::values.mouse_panning_x_sensitivity.GetDefault());
ui->y_sensitivity->setValue(Settings::values.mouse_panning_y_sensitivity.GetDefault());
ui->deadzone_counterweight->setValue(
Settings::values.mouse_panning_deadzone_counterweight.GetDefault());
ui->decay_strength->setValue(Settings::values.mouse_panning_decay_strength.GetDefault());
ui->min_decay->setValue(Settings::values.mouse_panning_min_decay.GetDefault());
}
void ConfigureMousePanning::ConnectEvents() {
connect(ui->default_button, &QPushButton::clicked, this,
&ConfigureMousePanning::SetDefaultConfiguration);
connect(ui->button_box, &QDialogButtonBox::accepted, this,
&ConfigureMousePanning::ApplyConfiguration);
connect(ui->button_box, &QDialogButtonBox::rejected, this, [this] { reject(); });
}
void ConfigureMousePanning::ApplyConfiguration() {
Settings::values.mouse_panning = ui->enable->isChecked();
Settings::values.mouse_panning_x_sensitivity = static_cast<float>(ui->x_sensitivity->value());
Settings::values.mouse_panning_y_sensitivity = static_cast<float>(ui->y_sensitivity->value());
Settings::values.mouse_panning_deadzone_counterweight =
static_cast<float>(ui->deadzone_counterweight->value());
Settings::values.mouse_panning_decay_strength = static_cast<float>(ui->decay_strength->value());
Settings::values.mouse_panning_min_decay = static_cast<float>(ui->min_decay->value());
if (Settings::values.mouse_enabled && Settings::values.mouse_panning) {
Settings::values.mouse_panning = false;
QMessageBox::critical(
this, tr("Emulated mouse is enabled"),
tr("Real mouse input and mouse panning are incompatible. Please disable the "
"emulated mouse in input advanced settings to allow mouse panning."));
return;
}
accept();
}

View File

@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QDialog>
namespace InputCommon {
class InputSubsystem;
}
namespace Ui {
class ConfigureMousePanning;
}
class ConfigureMousePanning : public QDialog {
Q_OBJECT
public:
explicit ConfigureMousePanning(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_,
float right_stick_deadzone, float right_stick_range);
~ConfigureMousePanning() override;
public slots:
void ApplyConfiguration();
private:
void closeEvent(QCloseEvent* event) override;
void SetConfiguration(float right_stick_deadzone, float right_stick_range);
void SetDefaultConfiguration();
void ConnectEvents();
InputCommon::InputSubsystem* input_subsystem;
std::unique_ptr<Ui::ConfigureMousePanning> ui;
};

View File

@@ -0,0 +1,212 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureMousePanning</class>
<widget class="QDialog" name="configure_mouse_panning">
<property name="windowTitle">
<string>Configure mouse panning</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QCheckBox" name="enable">
<property name="text">
<string>Enable mouse panning</string>
</property>
<property name="toolTip">
<string>Can be toggled via a hotkey. Default hotkey is Ctrl + F9</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QGroupBox" name="sensitivity_box">
<property name="title">
<string>Sensitivity</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="x_sensitivity_label">
<property name="text">
<string>Horizontal</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="x_sensitivity">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="y_sensitivity_label">
<property name="text">
<string>Vertical</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="y_sensitivity">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="deadzone_counterweight_box">
<property name="title">
<string>Deadzone counterweight</string>
</property>
<property name="toolTip">
<string>Counteracts a game's built-in deadzone</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="deadzone_counterweight_label">
<property name="text">
<string>Deadzone</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="deadzone_counterweight">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="decay_box">
<property name="title">
<string>Stick decay</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="decay_strength_label">
<property name="text">
<string>Strength</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="decay_strength">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>22</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="min_decay_label">
<property name="text">
<string>Minimum</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="min_decay">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="warning_label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QPushButton" name="default_button">
<property name="text">
<string>Default</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QtConcurrent/QtConcurrent>
#include "common/settings.h"
#include "core/core.h"
#include "core/internal_network/network_interface.h"
#include "ui_configure_network.h"
#include "suyu/configuration/configure_network.h"
ConfigureNetwork::ConfigureNetwork(const Core::System& system_, QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureNetwork>()), system{system_} {
ui->setupUi(this);
ui->network_interface->addItem(tr("None"));
for (const auto& iface : Network::GetAvailableNetworkInterfaces()) {
ui->network_interface->addItem(QString::fromStdString(iface.name));
}
this->SetConfiguration();
}
ConfigureNetwork::~ConfigureNetwork() = default;
void ConfigureNetwork::ApplyConfiguration() {
Settings::values.network_interface = ui->network_interface->currentText().toStdString();
}
void ConfigureNetwork::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureNetwork::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureNetwork::SetConfiguration() {
const bool runtime_lock = !system.IsPoweredOn();
const std::string& network_interface = Settings::values.network_interface.GetValue();
ui->network_interface->setCurrentText(QString::fromStdString(network_interface));
ui->network_interface->setEnabled(runtime_lock);
}

View File

@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QWidget>
namespace Ui {
class ConfigureNetwork;
}
class ConfigureNetwork : public QWidget {
Q_OBJECT
public:
explicit ConfigureNetwork(const Core::System& system_, QWidget* parent = nullptr);
~ConfigureNetwork() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent*) override;
void RetranslateUI();
void SetConfiguration();
std::unique_ptr<Ui::ConfigureNetwork> ui;
const Core::System& system;
};

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureNetwork</class>
<widget class="QWidget" name="ConfigureNetwork">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>433</width>
<height>561</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>Network</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>General</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QComboBox" name="network_interface"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Network Interface</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,204 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include <filesystem>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <fmt/format.h>
#include <QAbstractButton>
#include <QCheckBox>
#include <QPushButton>
#include <QString>
#include <QTimer>
#include "common/fs/fs_util.h"
#include "common/settings_enums.h"
#include "common/settings_input.h"
#include "configuration/shared_widget.h"
#include "core/core.h"
#include "core/file_sys/control_metadata.h"
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/xts_archive.h"
#include "core/loader/loader.h"
#include "frontend_common/config.h"
#include "ui_configure_per_game.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_audio.h"
#include "suyu/configuration/configure_cpu.h"
#include "suyu/configuration/configure_graphics.h"
#include "suyu/configuration/configure_graphics_advanced.h"
#include "suyu/configuration/configure_input_per_game.h"
#include "suyu/configuration/configure_linux_tab.h"
#include "suyu/configuration/configure_per_game.h"
#include "suyu/configuration/configure_per_game_addons.h"
#include "suyu/configuration/configure_system.h"
#include "suyu/uisettings.h"
#include "suyu/util/util.h"
#include "suyu/vk_device_info.h"
ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::string& file_name,
std::vector<VkDeviceInfo::Record>& vk_device_records,
Core::System& system_)
: QDialog(parent),
ui(std::make_unique<Ui::ConfigurePerGame>()), title_id{title_id_}, system{system_},
builder{std::make_unique<ConfigurationShared::Builder>(this, !system_.IsPoweredOn())},
tab_group{std::make_shared<std::vector<ConfigurationShared::Tab*>>()} {
const auto file_path = std::filesystem::path(Common::FS::ToU8String(file_name));
const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename())
: fmt::format("{:016X}", title_id);
game_config = std::make_unique<QtConfig>(config_file_name, Config::ConfigType::PerGameConfig);
addons_tab = std::make_unique<ConfigurePerGameAddons>(system_, this);
audio_tab = std::make_unique<ConfigureAudio>(system_, tab_group, *builder, this);
cpu_tab = std::make_unique<ConfigureCpu>(system_, tab_group, *builder, this);
graphics_advanced_tab =
std::make_unique<ConfigureGraphicsAdvanced>(system_, tab_group, *builder, this);
graphics_tab = std::make_unique<ConfigureGraphics>(
system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); },
[](Settings::AspectRatio, Settings::ResolutionSetup) {}, tab_group, *builder, this);
input_tab = std::make_unique<ConfigureInputPerGame>(system_, game_config.get(), this);
linux_tab = std::make_unique<ConfigureLinuxTab>(system_, tab_group, *builder, this);
system_tab = std::make_unique<ConfigureSystem>(system_, tab_group, *builder, this);
ui->setupUi(this);
ui->tabWidget->addTab(addons_tab.get(), tr("Add-Ons"));
ui->tabWidget->addTab(system_tab.get(), tr("System"));
ui->tabWidget->addTab(cpu_tab.get(), tr("CPU"));
ui->tabWidget->addTab(graphics_tab.get(), tr("Graphics"));
ui->tabWidget->addTab(graphics_advanced_tab.get(), tr("Adv. Graphics"));
ui->tabWidget->addTab(audio_tab.get(), tr("Audio"));
ui->tabWidget->addTab(input_tab.get(), tr("Input Profiles"));
// Only show Linux tab on Unix
linux_tab->setVisible(false);
#ifdef __unix__
linux_tab->setVisible(true);
ui->tabWidget->addTab(linux_tab.get(), tr("Linux"));
#endif
setFocusPolicy(Qt::ClickFocus);
setWindowTitle(tr("Properties"));
addons_tab->SetTitleId(title_id);
scene = new QGraphicsScene;
ui->icon_view->setScene(scene);
if (system.IsPoweredOn()) {
QPushButton* apply_button = ui->buttonBox->addButton(QDialogButtonBox::Apply);
connect(apply_button, &QAbstractButton::clicked, this,
&ConfigurePerGame::HandleApplyButtonClicked);
}
LoadConfiguration();
}
ConfigurePerGame::~ConfigurePerGame() = default;
void ConfigurePerGame::ApplyConfiguration() {
for (const auto tab : *tab_group) {
tab->ApplyConfiguration();
}
addons_tab->ApplyConfiguration();
input_tab->ApplyConfiguration();
if (Settings::IsDockedMode() && Settings::values.players.GetValue()[0].controller_type ==
Settings::ControllerType::Handheld) {
Settings::values.use_docked_mode.SetValue(Settings::ConsoleMode::Handheld);
Settings::values.use_docked_mode.SetGlobal(true);
}
system.ApplySettings();
Settings::LogSettings();
game_config->SaveAllValues();
}
void ConfigurePerGame::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigurePerGame::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigurePerGame::HandleApplyButtonClicked() {
UISettings::values.configuration_applied = true;
ApplyConfiguration();
}
void ConfigurePerGame::LoadFromFile(FileSys::VirtualFile file_) {
file = std::move(file_);
LoadConfiguration();
}
void ConfigurePerGame::LoadConfiguration() {
if (file == nullptr) {
return;
}
addons_tab->LoadFromFile(file);
ui->display_title_id->setText(
QStringLiteral("%1").arg(title_id, 16, 16, QLatin1Char{'0'}).toUpper());
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
system.GetContentProvider()};
const auto control = pm.GetControlMetadata();
const auto loader = Loader::GetLoader(system, file);
if (control.first != nullptr) {
ui->display_version->setText(QString::fromStdString(control.first->GetVersionString()));
ui->display_name->setText(QString::fromStdString(control.first->GetApplicationName()));
ui->display_developer->setText(QString::fromStdString(control.first->GetDeveloperName()));
} else {
std::string title;
if (loader->ReadTitle(title) == Loader::ResultStatus::Success)
ui->display_name->setText(QString::fromStdString(title));
FileSys::NACP nacp;
if (loader->ReadControlData(nacp) == Loader::ResultStatus::Success)
ui->display_developer->setText(QString::fromStdString(nacp.GetDeveloperName()));
ui->display_version->setText(QStringLiteral("1.0.0"));
}
if (control.second != nullptr) {
scene->clear();
QPixmap map;
const auto bytes = control.second->ReadAllBytes();
map.loadFromData(bytes.data(), static_cast<u32>(bytes.size()));
scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
} else {
std::vector<u8> bytes;
if (loader->ReadIcon(bytes) == Loader::ResultStatus::Success) {
scene->clear();
QPixmap map;
map.loadFromData(bytes.data(), static_cast<u32>(bytes.size()));
scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
}
ui->display_filename->setText(QString::fromStdString(file->GetName()));
ui->display_format->setText(
QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType())));
const auto valueText = ReadableByteSize(file->GetSize());
ui->display_size->setText(valueText);
}

View File

@@ -0,0 +1,91 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <string>
#include <vector>
#include <QDialog>
#include <QList>
#include "configuration/shared_widget.h"
#include "core/file_sys/vfs/vfs_types.h"
#include "frontend_common/config.h"
#include "vk_device_info.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/qt_config.h"
#include "suyu/configuration/shared_translation.h"
namespace Core {
class System;
}
namespace InputCommon {
class InputSubsystem;
}
class ConfigurePerGameAddons;
class ConfigureAudio;
class ConfigureCpu;
class ConfigureGraphics;
class ConfigureGraphicsAdvanced;
class ConfigureInputPerGame;
class ConfigureLinuxTab;
class ConfigureSystem;
class QGraphicsScene;
class QStandardItem;
class QStandardItemModel;
class QTreeView;
class QVBoxLayout;
namespace Ui {
class ConfigurePerGame;
}
class ConfigurePerGame : public QDialog {
Q_OBJECT
public:
// Cannot use std::filesystem::path due to https://bugreports.qt.io/browse/QTBUG-73263
explicit ConfigurePerGame(QWidget* parent, u64 title_id_, const std::string& file_name,
std::vector<VkDeviceInfo::Record>& vk_device_records,
Core::System& system_);
~ConfigurePerGame() override;
/// Save all button configurations to settings file
void ApplyConfiguration();
void LoadFromFile(FileSys::VirtualFile file_);
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void HandleApplyButtonClicked();
void LoadConfiguration();
std::unique_ptr<Ui::ConfigurePerGame> ui;
FileSys::VirtualFile file;
u64 title_id;
QGraphicsScene* scene;
std::unique_ptr<QtConfig> game_config;
Core::System& system;
std::unique_ptr<ConfigurationShared::Builder> builder;
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> tab_group;
std::unique_ptr<ConfigurePerGameAddons> addons_tab;
std::unique_ptr<ConfigureAudio> audio_tab;
std::unique_ptr<ConfigureCpu> cpu_tab;
std::unique_ptr<ConfigureGraphicsAdvanced> graphics_advanced_tab;
std::unique_ptr<ConfigureGraphics> graphics_tab;
std::unique_ptr<ConfigureInputPerGame> input_tab;
std::unique_ptr<ConfigureLinuxTab> linux_tab;
std::unique_ptr<ConfigureSystem> system_tab;
};

View File

@@ -0,0 +1,299 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigurePerGame</class>
<widget class="QDialog" name="ConfigurePerGame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>900</width>
<height>607</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>900</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Info</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item alignment="Qt::AlignHCenter">
<widget class="QGraphicsView" name="icon_view">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="interactive">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="6" column="1">
<widget class="QLineEdit" name="display_size">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="display_version">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Title ID</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="display_title_id">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="display_filename">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="display_format">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Filename</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="display_name">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="display_developer">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Version</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Developer</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<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>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="VerticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
</property>
<property name="documentMode">
<bool>false</bool>
</property>
<property name="tabsClosable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Some settings are only available when a game is not running.</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigurePerGame</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigurePerGame</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,143 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include <memory>
#include <utility>
#include <QHeaderView>
#include <QMenu>
#include <QStandardItemModel>
#include <QString>
#include <QTimer>
#include <QTreeView>
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
#include "core/core.h"
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/xts_archive.h"
#include "core/loader/loader.h"
#include "ui_configure_per_game_addons.h"
#include "suyu/configuration/configure_input.h"
#include "suyu/configuration/configure_per_game_addons.h"
#include "suyu/uisettings.h"
ConfigurePerGameAddons::ConfigurePerGameAddons(Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigurePerGameAddons>()}, system{system_} {
ui->setupUi(this);
layout = new QVBoxLayout;
tree_view = new QTreeView;
item_model = new QStandardItemModel(tree_view);
tree_view->setModel(item_model);
tree_view->setAlternatingRowColors(true);
tree_view->setSelectionMode(QHeaderView::SingleSelection);
tree_view->setSelectionBehavior(QHeaderView::SelectRows);
tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel);
tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel);
tree_view->setSortingEnabled(true);
tree_view->setEditTriggers(QHeaderView::NoEditTriggers);
tree_view->setUniformRowHeights(true);
tree_view->setContextMenuPolicy(Qt::NoContextMenu);
item_model->insertColumns(0, 2);
item_model->setHeaderData(0, Qt::Horizontal, tr("Patch Name"));
item_model->setHeaderData(1, Qt::Horizontal, tr("Version"));
tree_view->header()->setStretchLastSection(false);
tree_view->header()->setSectionResizeMode(0, QHeaderView::ResizeMode::Stretch);
tree_view->header()->setMinimumSectionSize(150);
// We must register all custom types with the Qt Automoc system so that we are able to use it
// with signals/slots. In this case, QList falls under the umbrella of custom types.
qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(tree_view);
ui->scrollArea->setLayout(layout);
ui->scrollArea->setEnabled(!system.IsPoweredOn());
connect(item_model, &QStandardItemModel::itemChanged,
[] { UISettings::values.is_game_list_reload_pending.exchange(true); });
}
ConfigurePerGameAddons::~ConfigurePerGameAddons() = default;
void ConfigurePerGameAddons::ApplyConfiguration() {
std::vector<std::string> disabled_addons;
for (const auto& item : list_items) {
const auto disabled = item.front()->checkState() == Qt::Unchecked;
if (disabled)
disabled_addons.push_back(item.front()->text().toStdString());
}
auto current = Settings::values.disabled_addons[title_id];
std::sort(disabled_addons.begin(), disabled_addons.end());
std::sort(current.begin(), current.end());
if (disabled_addons != current) {
Common::FS::RemoveFile(Common::FS::GetSuyuPath(Common::FS::SuyuPath::CacheDir) /
"game_list" / fmt::format("{:016X}.pv.txt", title_id));
}
Settings::values.disabled_addons[title_id] = disabled_addons;
}
void ConfigurePerGameAddons::LoadFromFile(FileSys::VirtualFile file_) {
file = std::move(file_);
LoadConfiguration();
}
void ConfigurePerGameAddons::SetTitleId(u64 id) {
this->title_id = id;
}
void ConfigurePerGameAddons::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigurePerGameAddons::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigurePerGameAddons::LoadConfiguration() {
if (file == nullptr) {
return;
}
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
system.GetContentProvider()};
const auto loader = Loader::GetLoader(system, file);
FileSys::VirtualFile update_raw;
loader->ReadUpdateRaw(update_raw);
const auto& disabled = Settings::values.disabled_addons[title_id];
for (const auto& patch : pm.GetPatches(update_raw)) {
const auto name = QString::fromStdString(patch.name);
auto* const first_item = new QStandardItem;
first_item->setText(name);
first_item->setCheckable(true);
const auto patch_disabled =
std::find(disabled.begin(), disabled.end(), name.toStdString()) != disabled.end();
first_item->setCheckState(patch_disabled ? Qt::Unchecked : Qt::Checked);
list_items.push_back(QList<QStandardItem*>{
first_item, new QStandardItem{QString::fromStdString(patch.version)}});
item_model->appendRow(list_items.back());
}
tree_view->resizeColumnToContents(1);
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <vector>
#include <QList>
#include "core/file_sys/vfs/vfs_types.h"
namespace Core {
class System;
}
class QGraphicsScene;
class QStandardItem;
class QStandardItemModel;
class QTreeView;
class QVBoxLayout;
namespace Ui {
class ConfigurePerGameAddons;
}
class ConfigurePerGameAddons : public QWidget {
Q_OBJECT
public:
explicit ConfigurePerGameAddons(Core::System& system_, QWidget* parent = nullptr);
~ConfigurePerGameAddons() override;
/// Save all button configurations to settings file
void ApplyConfiguration();
void LoadFromFile(FileSys::VirtualFile file_);
void SetTitleId(u64 id);
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void LoadConfiguration();
std::unique_ptr<Ui::ConfigurePerGameAddons> ui;
FileSys::VirtualFile file;
u64 title_id;
QVBoxLayout* layout;
QTreeView* tree_view;
QStandardItemModel* item_model;
std::vector<QList<QStandardItem*>> list_items;
Core::System& system;
};

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigurePerGameAddons</class>
<widget class="QWidget" name="ConfigurePerGameAddons">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleDescription">
<string>Add-Ons</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<height>280</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,372 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include <functional>
#include <QDialog>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QGraphicsItem>
#include <QHeaderView>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QTreeView>
#include "common/assert.h"
#include "common/fs/path_util.h"
#include "common/settings.h"
#include "common/string_util.h"
#include "core/core.h"
#include "core/hle/service/acc/profile_manager.h"
#include "ui_configure_profile_manager.h"
#include "suyu/configuration/configure_profile_manager.h"
#include "suyu/util/limitable_input_dialog.h"
namespace {
// Same backup JPEG used by acc IProfile::GetImage if no jpeg found
constexpr std::array<u8, 107> backup_jpeg{
0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02,
0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05,
0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e,
0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13,
0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01,
0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08,
0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
};
QString GetImagePath(const Common::UUID& uuid) {
const auto path =
Common::FS::GetSuyuPath(Common::FS::SuyuPath::NANDDir) /
fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormattedString());
return QString::fromStdString(Common::FS::PathToUTF8String(path));
}
QString GetAccountUsername(const Service::Account::ProfileManager& manager, Common::UUID uuid) {
Service::Account::ProfileBase profile{};
if (!manager.GetProfileBase(uuid, profile)) {
return {};
}
const auto text = Common::StringFromFixedZeroTerminatedBuffer(
reinterpret_cast<const char*>(profile.username.data()), profile.username.size());
return QString::fromStdString(text);
}
QString FormatUserEntryText(const QString& username, Common::UUID uuid) {
return ConfigureProfileManager::tr("%1\n%2",
"%1 is the profile username, %2 is the formatted UUID (e.g. "
"00112233-4455-6677-8899-AABBCCDDEEFF))")
.arg(username, QString::fromStdString(uuid.FormattedString()));
}
QPixmap GetIcon(const Common::UUID& uuid) {
QPixmap icon{GetImagePath(uuid)};
if (!icon) {
icon.fill(Qt::black);
icon.loadFromData(backup_jpeg.data(), static_cast<u32>(backup_jpeg.size()));
}
return icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_text) {
return LimitableInputDialog::GetText(parent, ConfigureProfileManager::tr("Enter Username"),
description_text, 1,
static_cast<int>(Service::Account::profile_username_size));
}
} // Anonymous namespace
ConfigureProfileManager::ConfigureProfileManager(Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigureProfileManager>()},
profile_manager{system_.GetProfileManager()}, system{system_} {
ui->setupUi(this);
tree_view = new QTreeView;
item_model = new QStandardItemModel(tree_view);
item_model->insertColumns(0, 1);
tree_view->setModel(item_model);
tree_view->setAlternatingRowColors(true);
tree_view->setSelectionMode(QHeaderView::SingleSelection);
tree_view->setSelectionBehavior(QHeaderView::SelectRows);
tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel);
tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel);
tree_view->setSortingEnabled(true);
tree_view->setEditTriggers(QHeaderView::NoEditTriggers);
tree_view->setUniformRowHeights(true);
tree_view->setIconSize({64, 64});
tree_view->setContextMenuPolicy(Qt::NoContextMenu);
// We must register all custom types with the Qt Automoc system so that we are able to use it
// with signals/slots. In this case, QList falls under the umbrells of custom types.
qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(tree_view);
ui->scrollArea->setLayout(layout);
connect(tree_view, &QTreeView::clicked, this, &ConfigureProfileManager::SelectUser);
connect(ui->pm_add, &QPushButton::clicked, this, &ConfigureProfileManager::AddUser);
connect(ui->pm_rename, &QPushButton::clicked, this, &ConfigureProfileManager::RenameUser);
connect(ui->pm_remove, &QPushButton::clicked, this,
&ConfigureProfileManager::ConfirmDeleteUser);
connect(ui->pm_set_image, &QPushButton::clicked, this, &ConfigureProfileManager::SetUserImage);
confirm_dialog = new ConfigureProfileManagerDeleteDialog(this);
scene = new QGraphicsScene;
ui->current_user_icon->setScene(scene);
RetranslateUI();
SetConfiguration();
}
ConfigureProfileManager::~ConfigureProfileManager() = default;
void ConfigureProfileManager::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureProfileManager::RetranslateUI() {
ui->retranslateUi(this);
item_model->setHeaderData(0, Qt::Horizontal, tr("Users"));
}
void ConfigureProfileManager::SetConfiguration() {
enabled = !system.IsPoweredOn();
item_model->removeRows(0, item_model->rowCount());
list_items.clear();
PopulateUserList();
UpdateCurrentUser();
}
void ConfigureProfileManager::PopulateUserList() {
const auto& profiles = profile_manager.GetAllUsers();
for (const auto& user : profiles) {
Service::Account::ProfileBase profile{};
if (!profile_manager.GetProfileBase(user, profile))
continue;
const auto username = Common::StringFromFixedZeroTerminatedBuffer(
reinterpret_cast<const char*>(profile.username.data()), profile.username.size());
list_items.push_back(QList<QStandardItem*>{new QStandardItem{
GetIcon(user), FormatUserEntryText(QString::fromStdString(username), user)}});
}
for (const auto& item : list_items)
item_model->appendRow(item);
}
void ConfigureProfileManager::UpdateCurrentUser() {
ui->pm_add->setEnabled(profile_manager.GetUserCount() < Service::Account::MAX_USERS);
const auto& current_user = profile_manager.GetUser(Settings::values.current_user.GetValue());
ASSERT(current_user);
const auto username = GetAccountUsername(profile_manager, *current_user);
scene->clear();
scene->addPixmap(
GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
ui->current_user_username->setText(username);
}
void ConfigureProfileManager::ApplyConfiguration() {
if (!enabled) {
return;
}
}
void ConfigureProfileManager::SelectUser(const QModelIndex& index) {
Settings::values.current_user =
std::clamp<s32>(index.row(), 0, static_cast<s32>(profile_manager.GetUserCount() - 1));
UpdateCurrentUser();
ui->pm_remove->setEnabled(profile_manager.GetUserCount() >= 2);
ui->pm_rename->setEnabled(true);
ui->pm_set_image->setEnabled(true);
}
void ConfigureProfileManager::AddUser() {
const auto username =
GetProfileUsernameFromUser(this, tr("Enter a username for the new user:"));
if (username.isEmpty()) {
return;
}
const auto uuid = Common::UUID::MakeRandom();
profile_manager.CreateNewUser(uuid, username.toStdString());
profile_manager.WriteUserSaveFile();
item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)});
}
void ConfigureProfileManager::RenameUser() {
const auto user = tree_view->currentIndex().row();
const auto uuid = profile_manager.GetUser(user);
ASSERT(uuid);
Service::Account::ProfileBase profile{};
if (!profile_manager.GetProfileBase(*uuid, profile))
return;
const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:"));
if (new_username.isEmpty()) {
return;
}
const auto username_std = new_username.toStdString();
std::fill(profile.username.begin(), profile.username.end(), '\0');
std::copy(username_std.begin(), username_std.end(), profile.username.begin());
profile_manager.SetProfileBase(*uuid, profile);
profile_manager.WriteUserSaveFile();
item_model->setItem(
user, 0,
new QStandardItem{GetIcon(*uuid),
FormatUserEntryText(QString::fromStdString(username_std), *uuid)});
UpdateCurrentUser();
}
void ConfigureProfileManager::ConfirmDeleteUser() {
const auto index = tree_view->currentIndex().row();
const auto uuid = profile_manager.GetUser(index);
ASSERT(uuid);
const auto username = GetAccountUsername(profile_manager, *uuid);
confirm_dialog->SetInfo(username, *uuid, [this, uuid]() { DeleteUser(*uuid); });
confirm_dialog->show();
}
void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
if (Settings::values.current_user.GetValue() == tree_view->currentIndex().row()) {
Settings::values.current_user = 0;
}
UpdateCurrentUser();
if (!profile_manager.RemoveUser(uuid)) {
return;
}
profile_manager.WriteUserSaveFile();
item_model->removeRows(tree_view->currentIndex().row(), 1);
tree_view->clearSelection();
ui->pm_remove->setEnabled(false);
ui->pm_rename->setEnabled(false);
}
void ConfigureProfileManager::SetUserImage() {
const auto index = tree_view->currentIndex().row();
const auto uuid = profile_manager.GetUser(index);
ASSERT(uuid);
const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
tr("JPEG Images (*.jpg *.jpeg)"));
if (file.isEmpty()) {
return;
}
const auto image_path = GetImagePath(*uuid);
if (QFile::exists(image_path) && !QFile::remove(image_path)) {
QMessageBox::warning(
this, tr("Error deleting image"),
tr("Error occurred attempting to overwrite previous image at: %1.").arg(image_path));
return;
}
const auto raw_path = QString::fromStdString(Common::FS::PathToUTF8String(
Common::FS::GetSuyuPath(Common::FS::SuyuPath::NANDDir) / "system/save/8000000000000010"));
const QFileInfo raw_info{raw_path};
if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) {
QMessageBox::warning(this, tr("Error deleting file"),
tr("Unable to delete existing file: %1.").arg(raw_path));
return;
}
const QString absolute_dst_path = QFileInfo{image_path}.absolutePath();
if (!QDir{raw_path}.mkpath(absolute_dst_path)) {
QMessageBox::warning(
this, tr("Error creating user image directory"),
tr("Unable to create directory %1 for storing user images.").arg(absolute_dst_path));
return;
}
if (!QFile::copy(file, image_path)) {
QMessageBox::warning(this, tr("Error copying user image"),
tr("Unable to copy image from %1 to %2").arg(file, image_path));
return;
}
// Profile image must be 256x256
QImage image(image_path);
if (image.width() != 256 || image.height() != 256) {
image = image.scaled(256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
if (!image.save(image_path)) {
QMessageBox::warning(this, tr("Error resizing user image"),
tr("Unable to resize image"));
return;
}
}
const auto username = GetAccountUsername(profile_manager, *uuid);
item_model->setItem(index, 0,
new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)});
UpdateCurrentUser();
}
ConfigureProfileManagerDeleteDialog::ConfigureProfileManagerDeleteDialog(QWidget* parent)
: QDialog{parent} {
auto dialog_vbox_layout = new QVBoxLayout(this);
dialog_button_box =
new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No, Qt::Horizontal, parent);
auto label_message =
new QLabel(tr("Delete this user? All of the user's save data will be deleted."), this);
label_info = new QLabel(this);
auto dialog_hbox_layout_widget = new QWidget(this);
auto dialog_hbox_layout = new QHBoxLayout(dialog_hbox_layout_widget);
icon_scene = new QGraphicsScene(0, 0, 64, 64, this);
auto icon_view = new QGraphicsView(icon_scene, this);
dialog_hbox_layout_widget->setLayout(dialog_hbox_layout);
icon_view->setMaximumSize(64, 64);
icon_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
icon_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setLayout(dialog_vbox_layout);
this->setWindowTitle(tr("Confirm Delete"));
this->setSizeGripEnabled(false);
dialog_vbox_layout->addWidget(label_message);
dialog_vbox_layout->addWidget(dialog_hbox_layout_widget);
dialog_vbox_layout->addWidget(dialog_button_box);
dialog_hbox_layout->addWidget(icon_view);
dialog_hbox_layout->addWidget(label_info);
connect(dialog_button_box, &QDialogButtonBox::rejected, this, [this]() { close(); });
}
ConfigureProfileManagerDeleteDialog::~ConfigureProfileManagerDeleteDialog() = default;
void ConfigureProfileManagerDeleteDialog::SetInfo(const QString& username, const Common::UUID& uuid,
std::function<void()> accept_callback) {
label_info->setText(
tr("Name: %1\nUUID: %2").arg(username, QString::fromStdString(uuid.FormattedString())));
icon_scene->clear();
icon_scene->addPixmap(GetIcon(uuid));
connect(dialog_button_box, &QDialogButtonBox::accepted, this, [this, accept_callback]() {
close();
accept_callback();
});
}

View File

@@ -0,0 +1,90 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <functional>
#include <memory>
#include <QDialog>
#include <QList>
#include <QWidget>
namespace Common {
struct UUID;
}
namespace Core {
class System;
}
class QGraphicsScene;
class QDialogButtonBox;
class QLabel;
class QStandardItem;
class QStandardItemModel;
class QTreeView;
class QVBoxLayout;
namespace Service::Account {
class ProfileManager;
}
namespace Ui {
class ConfigureProfileManager;
}
class ConfigureProfileManagerDeleteDialog : public QDialog {
public:
explicit ConfigureProfileManagerDeleteDialog(QWidget* parent);
~ConfigureProfileManagerDeleteDialog();
void SetInfo(const QString& username, const Common::UUID& uuid,
std::function<void()> accept_callback);
private:
QDialogButtonBox* dialog_button_box;
QGraphicsScene* icon_scene;
QLabel* label_info;
};
class ConfigureProfileManager : public QWidget {
Q_OBJECT
public:
explicit ConfigureProfileManager(Core::System& system_, QWidget* parent = nullptr);
~ConfigureProfileManager() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void SetConfiguration();
void PopulateUserList();
void UpdateCurrentUser();
void SelectUser(const QModelIndex& index);
void AddUser();
void RenameUser();
void ConfirmDeleteUser();
void DeleteUser(const Common::UUID& uuid);
void SetUserImage();
QVBoxLayout* layout;
QTreeView* tree_view;
QStandardItemModel* item_model;
QGraphicsScene* scene;
ConfigureProfileManagerDeleteDialog* confirm_dialog;
std::vector<QList<QStandardItem*>> list_items;
std::unique_ptr<Ui::ConfigureProfileManager> ui;
bool enabled = false;
Service::Account::ProfileManager& profile_manager;
const Core::System& system;
};

View File

@@ -0,0 +1,181 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureProfileManager</class>
<widget class="QWidget" name="ConfigureProfileManager">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>483</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>Profiles</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="gridGroupBox">
<property name="title">
<string>Profile Manager</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Current User</string>
</property>
</widget>
</item>
<item>
<widget class="QGraphicsView" name="current_user_icon">
<property name="minimumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="interactive">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="current_user_username">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="widgetResizable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pm_set_image">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Set Image</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pm_add">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pm_rename">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Rename</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pm_remove">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_disable_info">
<property name="text">
<string>Profile management is available only when game is not running.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,497 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include <QKeyEvent>
#include <QMenu>
#include <QMessageBox>
#include <QTimer>
#include <fmt/format.h>
#include "configuration/qt_config.h"
#include "hid_core/frontend/emulated_controller.h"
#include "hid_core/hid_core.h"
#include "input_common/drivers/keyboard.h"
#include "input_common/drivers/mouse.h"
#include "input_common/main.h"
#include "ui_configure_ringcon.h"
#include "suyu/bootmanager.h"
#include "suyu/configuration/configure_ringcon.h"
const std::array<std::string, ConfigureRingController::ANALOG_SUB_BUTTONS_NUM>
ConfigureRingController::analog_sub_buttons{{
"left",
"right",
}};
namespace {
QString GetKeyName(int key_code) {
switch (key_code) {
case Qt::Key_Shift:
return QObject::tr("Shift");
case Qt::Key_Control:
return QObject::tr("Ctrl");
case Qt::Key_Alt:
return QObject::tr("Alt");
case Qt::Key_Meta:
return {};
default:
return QKeySequence(key_code).toString();
}
}
QString GetButtonName(Common::Input::ButtonNames button_name) {
switch (button_name) {
case Common::Input::ButtonNames::ButtonLeft:
return QObject::tr("Left");
case Common::Input::ButtonNames::ButtonRight:
return QObject::tr("Right");
case Common::Input::ButtonNames::ButtonDown:
return QObject::tr("Down");
case Common::Input::ButtonNames::ButtonUp:
return QObject::tr("Up");
case Common::Input::ButtonNames::TriggerZ:
return QObject::tr("Z");
case Common::Input::ButtonNames::TriggerR:
return QObject::tr("R");
case Common::Input::ButtonNames::TriggerL:
return QObject::tr("L");
case Common::Input::ButtonNames::ButtonA:
return QObject::tr("A");
case Common::Input::ButtonNames::ButtonB:
return QObject::tr("B");
case Common::Input::ButtonNames::ButtonX:
return QObject::tr("X");
case Common::Input::ButtonNames::ButtonY:
return QObject::tr("Y");
case Common::Input::ButtonNames::ButtonStart:
return QObject::tr("Start");
case Common::Input::ButtonNames::L1:
return QObject::tr("L1");
case Common::Input::ButtonNames::L2:
return QObject::tr("L2");
case Common::Input::ButtonNames::L3:
return QObject::tr("L3");
case Common::Input::ButtonNames::R1:
return QObject::tr("R1");
case Common::Input::ButtonNames::R2:
return QObject::tr("R2");
case Common::Input::ButtonNames::R3:
return QObject::tr("R3");
case Common::Input::ButtonNames::Circle:
return QObject::tr("Circle");
case Common::Input::ButtonNames::Cross:
return QObject::tr("Cross");
case Common::Input::ButtonNames::Square:
return QObject::tr("Square");
case Common::Input::ButtonNames::Triangle:
return QObject::tr("Triangle");
case Common::Input::ButtonNames::Share:
return QObject::tr("Share");
case Common::Input::ButtonNames::Options:
return QObject::tr("Options");
default:
return QObject::tr("[undefined]");
}
}
void SetAnalogParam(const Common::ParamPackage& input_param, Common::ParamPackage& analog_param,
const std::string& button_name) {
// The poller returned a complete axis, so set all the buttons
if (input_param.Has("axis_x") && input_param.Has("axis_y")) {
analog_param = input_param;
return;
}
// Check if the current configuration has either no engine or an axis binding.
// Clears out the old binding and adds one with analog_from_button.
if (!analog_param.Has("engine") || analog_param.Has("axis_x") || analog_param.Has("axis_y")) {
analog_param = {
{"engine", "analog_from_button"},
};
}
analog_param.Set(button_name, input_param.Serialize());
}
} // namespace
ConfigureRingController::ConfigureRingController(QWidget* parent,
InputCommon::InputSubsystem* input_subsystem_,
Core::HID::HIDCore& hid_core_)
: QDialog(parent), timeout_timer(std::make_unique<QTimer>()),
poll_timer(std::make_unique<QTimer>()), input_subsystem{input_subsystem_},
ui(std::make_unique<Ui::ConfigureRingController>()) {
ui->setupUi(this);
analog_map_buttons = {
ui->buttonRingAnalogPull,
ui->buttonRingAnalogPush,
};
emulated_controller = hid_core_.GetEmulatedController(Core::HID::NpadIdType::Player1);
emulated_controller->SaveCurrentConfig();
emulated_controller->EnableConfiguration();
Core::HID::ControllerUpdateCallback engine_callback{
.on_change = [this](Core::HID::ControllerTriggerType type) { ControllerUpdate(type); },
.is_npad_service = false,
};
callback_key = emulated_controller->SetCallback(engine_callback);
is_controller_set = true;
LoadConfiguration();
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
auto* const analog_button = analog_map_buttons[sub_button_id];
if (analog_button == nullptr) {
continue;
}
connect(analog_button, &QPushButton::clicked, [=, this] {
HandleClick(
analog_map_buttons[sub_button_id],
[=, this](const Common::ParamPackage& params) {
Common::ParamPackage param = emulated_controller->GetRingParam();
SetAnalogParam(params, param, analog_sub_buttons[sub_button_id]);
emulated_controller->SetRingParam(param);
},
InputCommon::Polling::InputType::Stick);
});
analog_button->setContextMenuPolicy(Qt::CustomContextMenu);
connect(analog_button, &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) {
QMenu context_menu;
Common::ParamPackage param = emulated_controller->GetRingParam();
context_menu.addAction(tr("Clear"), [&] {
emulated_controller->SetRingParam(param);
analog_map_buttons[sub_button_id]->setText(tr("[not set]"));
});
context_menu.addAction(tr("Invert axis"), [&] {
const bool invert_value = param.Get("invert_x", "+") == "-";
const std::string invert_str = invert_value ? "+" : "-";
param.Set("invert_x", invert_str);
emulated_controller->SetRingParam(param);
for (int sub_button_id2 = 0; sub_button_id2 < ANALOG_SUB_BUTTONS_NUM;
++sub_button_id2) {
analog_map_buttons[sub_button_id2]->setText(
AnalogToText(param, analog_sub_buttons[sub_button_id2]));
}
});
context_menu.exec(
analog_map_buttons[sub_button_id]->mapToGlobal(menu_location));
});
}
connect(ui->sliderRingAnalogDeadzone, &QSlider::valueChanged, [=, this] {
Common::ParamPackage param = emulated_controller->GetRingParam();
const auto slider_value = ui->sliderRingAnalogDeadzone->value();
ui->labelRingAnalogDeadzone->setText(tr("Deadzone: %1%").arg(slider_value));
param.Set("deadzone", slider_value / 100.0f);
emulated_controller->SetRingParam(param);
});
connect(ui->restore_defaults_button, &QPushButton::clicked, this,
&ConfigureRingController::RestoreDefaults);
connect(ui->enable_ring_controller_button, &QPushButton::clicked, this,
&ConfigureRingController::EnableRingController);
timeout_timer->setSingleShot(true);
connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this] {
const auto& params = input_subsystem->GetNextInput();
if (params.Has("engine") && IsInputAcceptable(params)) {
SetPollingResult(params, false);
return;
}
});
resize(0, 0);
}
ConfigureRingController::~ConfigureRingController() {
emulated_controller->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Active);
emulated_controller->DisableConfiguration();
if (is_controller_set) {
emulated_controller->DeleteCallback(callback_key);
is_controller_set = false;
}
};
void ConfigureRingController::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigureRingController::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureRingController::UpdateUI() {
RetranslateUI();
const Common::ParamPackage param = emulated_controller->GetRingParam();
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
auto* const analog_button = analog_map_buttons[sub_button_id];
if (analog_button == nullptr) {
continue;
}
analog_button->setText(AnalogToText(param, analog_sub_buttons[sub_button_id]));
}
const auto deadzone_label = ui->labelRingAnalogDeadzone;
const auto deadzone_slider = ui->sliderRingAnalogDeadzone;
int slider_value = static_cast<int>(param.Get("deadzone", 0.15f) * 100);
deadzone_label->setText(tr("Deadzone: %1%").arg(slider_value));
deadzone_slider->setValue(slider_value);
}
void ConfigureRingController::ApplyConfiguration() {
emulated_controller->DisableConfiguration();
emulated_controller->SaveCurrentConfig();
emulated_controller->EnableConfiguration();
}
void ConfigureRingController::LoadConfiguration() {
UpdateUI();
}
void ConfigureRingController::RestoreDefaults() {
const std::string default_ring_string = InputCommon::GenerateAnalogParamFromKeys(
0, 0, QtConfig::default_ringcon_analogs[0], QtConfig::default_ringcon_analogs[1], 0, 0.05f);
emulated_controller->SetRingParam(Common::ParamPackage(default_ring_string));
UpdateUI();
}
void ConfigureRingController::EnableRingController() {
const auto dialog_title = tr("Error enabling ring input");
is_ring_enabled = false;
ui->ring_controller_sensor_value->setText(tr("Not connected"));
if (!Settings::values.enable_joycon_driver) {
QMessageBox::warning(this, dialog_title, tr("Direct Joycon driver is not enabled"));
return;
}
ui->enable_ring_controller_button->setEnabled(false);
ui->enable_ring_controller_button->setText(tr("Configuring"));
// SetPollingMode is blocking. Allow to update the button status before calling the command
repaint();
const auto result = emulated_controller->SetPollingMode(
Core::HID::EmulatedDeviceIndex::RightIndex, Common::Input::PollingMode::Ring);
switch (result) {
case Common::Input::DriverResult::Success:
is_ring_enabled = true;
break;
case Common::Input::DriverResult::NotSupported:
QMessageBox::warning(this, dialog_title,
tr("The current mapped device doesn't support the ring controller"));
break;
case Common::Input::DriverResult::NoDeviceDetected:
QMessageBox::warning(this, dialog_title,
tr("The current mapped device doesn't have a ring attached"));
break;
case Common::Input::DriverResult::InvalidHandle:
QMessageBox::warning(this, dialog_title, tr("The current mapped device is not connected"));
break;
default:
QMessageBox::warning(this, dialog_title,
tr("Unexpected driver result %1").arg(static_cast<int>(result)));
break;
}
ui->enable_ring_controller_button->setEnabled(true);
ui->enable_ring_controller_button->setText(tr("Enable"));
}
void ConfigureRingController::ControllerUpdate(Core::HID::ControllerTriggerType type) {
if (!is_ring_enabled) {
return;
}
if (type != Core::HID::ControllerTriggerType::RingController) {
return;
}
const auto value = emulated_controller->GetRingSensorValues();
const auto tex_value = QString::fromStdString(fmt::format("{:.3f}", value.raw_value));
ui->ring_controller_sensor_value->setText(tex_value);
}
void ConfigureRingController::HandleClick(
QPushButton* button, std::function<void(const Common::ParamPackage&)> new_input_setter,
InputCommon::Polling::InputType type) {
button->setText(tr("[waiting]"));
button->setFocus();
input_setter = new_input_setter;
input_subsystem->BeginMapping(type);
QWidget::grabMouse();
QWidget::grabKeyboard();
timeout_timer->start(2500); // Cancel after 2.5 seconds
poll_timer->start(25); // Check for new inputs every 25ms
}
void ConfigureRingController::SetPollingResult(const Common::ParamPackage& params, bool abort) {
timeout_timer->stop();
poll_timer->stop();
input_subsystem->StopMapping();
QWidget::releaseMouse();
QWidget::releaseKeyboard();
if (!abort) {
(*input_setter)(params);
}
UpdateUI();
input_setter = std::nullopt;
}
bool ConfigureRingController::IsInputAcceptable(const Common::ParamPackage& params) const {
return true;
}
void ConfigureRingController::mousePressEvent(QMouseEvent* event) {
if (!input_setter || !event) {
return;
}
const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
input_subsystem->GetMouse()->PressButton(0, 0, button);
}
void ConfigureRingController::keyPressEvent(QKeyEvent* event) {
if (!input_setter || !event) {
return;
}
event->ignore();
if (event->key() != Qt::Key_Escape) {
input_subsystem->GetKeyboard()->PressKey(event->key());
}
}
QString ConfigureRingController::ButtonToText(const Common::ParamPackage& param) {
if (!param.Has("engine")) {
return QObject::tr("[not set]");
}
const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : "");
const QString inverted = QString::fromStdString(param.Get("inverted", false) ? "!" : "");
const auto common_button_name = input_subsystem->GetButtonName(param);
// Retrieve the names from Qt
if (param.Get("engine", "") == "keyboard") {
const QString button_str = GetKeyName(param.Get("code", 0));
return QObject::tr("%1%2").arg(toggle, button_str);
}
if (common_button_name == Common::Input::ButtonNames::Invalid) {
return QObject::tr("[invalid]");
}
if (common_button_name == Common::Input::ButtonNames::Engine) {
return QString::fromStdString(param.Get("engine", ""));
}
if (common_button_name == Common::Input::ButtonNames::Value) {
if (param.Has("hat")) {
const QString hat = QString::fromStdString(param.Get("direction", ""));
return QObject::tr("%1%2Hat %3").arg(toggle, inverted, hat);
}
if (param.Has("axis")) {
const QString axis = QString::fromStdString(param.Get("axis", ""));
return QObject::tr("%1%2Axis %3").arg(toggle, inverted, axis);
}
if (param.Has("axis_x") && param.Has("axis_y") && param.Has("axis_z")) {
const QString axis_x = QString::fromStdString(param.Get("axis_x", ""));
const QString axis_y = QString::fromStdString(param.Get("axis_y", ""));
const QString axis_z = QString::fromStdString(param.Get("axis_z", ""));
return QObject::tr("%1%2Axis %3,%4,%5").arg(toggle, inverted, axis_x, axis_y, axis_z);
}
if (param.Has("motion")) {
const QString motion = QString::fromStdString(param.Get("motion", ""));
return QObject::tr("%1%2Motion %3").arg(toggle, inverted, motion);
}
if (param.Has("button")) {
const QString button = QString::fromStdString(param.Get("button", ""));
return QObject::tr("%1%2Button %3").arg(toggle, inverted, button);
}
}
QString button_name = GetButtonName(common_button_name);
if (param.Has("hat")) {
return QObject::tr("%1%2Hat %3").arg(toggle, inverted, button_name);
}
if (param.Has("axis")) {
return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name);
}
if (param.Has("motion")) {
return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name);
}
if (param.Has("button")) {
return QObject::tr("%1%2Button %3").arg(toggle, inverted, button_name);
}
return QObject::tr("[unknown]");
}
QString ConfigureRingController::AnalogToText(const Common::ParamPackage& param,
const std::string& dir) {
if (!param.Has("engine")) {
return QObject::tr("[not set]");
}
if (param.Get("engine", "") == "analog_from_button") {
return ButtonToText(Common::ParamPackage{param.Get(dir, "")});
}
if (!param.Has("axis_x") || !param.Has("axis_y")) {
return QObject::tr("[unknown]");
}
const auto engine_str = param.Get("engine", "");
const QString axis_x_str = QString::fromStdString(param.Get("axis_x", ""));
const QString axis_y_str = QString::fromStdString(param.Get("axis_y", ""));
const bool invert_x = param.Get("invert_x", "+") == "-";
const bool invert_y = param.Get("invert_y", "+") == "-";
if (dir == "modifier") {
return QObject::tr("[unused]");
}
if (dir == "left") {
const QString invert_x_str = QString::fromStdString(invert_x ? "+" : "-");
return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str);
}
if (dir == "right") {
const QString invert_x_str = QString::fromStdString(invert_x ? "-" : "+");
return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str);
}
if (dir == "up") {
const QString invert_y_str = QString::fromStdString(invert_y ? "-" : "+");
return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str);
}
if (dir == "down") {
const QString invert_y_str = QString::fromStdString(invert_y ? "+" : "-");
return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str);
}
return QObject::tr("[unknown]");
}

View File

@@ -0,0 +1,94 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <functional>
#include <memory>
#include <QDialog>
namespace InputCommon {
class InputSubsystem;
} // namespace InputCommon
namespace Core::HID {
class HIDCore;
class EmulatedController;
} // namespace Core::HID
namespace Ui {
class ConfigureRingController;
} // namespace Ui
class ConfigureRingController : public QDialog {
Q_OBJECT
public:
explicit ConfigureRingController(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_,
Core::HID::HIDCore& hid_core_);
~ConfigureRingController() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void UpdateUI();
/// Load configuration settings.
void LoadConfiguration();
/// Restore all buttons to their default values.
void RestoreDefaults();
/// Sets current polling mode to ring input
void EnableRingController();
// Handles emulated controller events
void ControllerUpdate(Core::HID::ControllerTriggerType type);
/// Called when the button was pressed.
void HandleClick(QPushButton* button,
std::function<void(const Common::ParamPackage&)> new_input_setter,
InputCommon::Polling::InputType type);
/// Finish polling and configure input using the input_setter.
void SetPollingResult(const Common::ParamPackage& params, bool abort);
/// Checks whether a given input can be accepted.
bool IsInputAcceptable(const Common::ParamPackage& params) const;
/// Handle mouse button press events.
void mousePressEvent(QMouseEvent* event) override;
/// Handle key press events.
void keyPressEvent(QKeyEvent* event) override;
QString ButtonToText(const Common::ParamPackage& param);
QString AnalogToText(const Common::ParamPackage& param, const std::string& dir);
static constexpr int ANALOG_SUB_BUTTONS_NUM = 2;
// A group of four QPushButtons represent one analog input. The buttons each represent left,
// right, respectively.
std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM> analog_map_buttons;
static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
std::unique_ptr<QTimer> timeout_timer;
std::unique_ptr<QTimer> poll_timer;
/// This will be the the setting function when an input is awaiting configuration.
std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
InputCommon::InputSubsystem* input_subsystem;
Core::HID::EmulatedController* emulated_controller;
bool is_ring_enabled{};
bool is_controller_set{};
int callback_key;
std::unique_ptr<Ui::ConfigureRingController> ui;
};

View File

@@ -0,0 +1,374 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureRingController</class>
<widget class="QDialog" name="ConfigureRingController">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>315</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure Ring Controller</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>280</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>To use Ring-Con, configure player 1 as right Joy-Con (both physical and emulated), and player 2 as left Joy-Con (left physical and dual emulated) before starting the game.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="RingAnalog">
<property name="title">
<string>Virtual Ring Sensor Parameters</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<layout class="QVBoxLayout" name="verticalLayout_1">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="buttonRingAnalogPullHorizontaLayout">
<property name="spacing">
<number>3</number>
</property>
<item alignment="Qt::AlignHCenter">
<widget class="QGroupBox" name="buttonRingAnalogPullGroup">
<property name="title">
<string>Pull</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<layout class="QVBoxLayout" name="buttonRingAnalogPullVerticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QPushButton" name="buttonRingAnalogPull">
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>68</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">min-width: 68px;</string>
</property>
<property name="text">
<string>Pull</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QGroupBox" name="buttonRingAnalogPushGroup">
<property name="title">
<string>Push</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<layout class="QVBoxLayout" name="buttonRingAnalogPushVerticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QPushButton" name="buttonRingAnalogPush">
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>68</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">min-width: 68px;</string>
</property>
<property name="text">
<string>Push</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="sliderRingAnalogDeadzoneVerticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<layout class="QHBoxLayout" name="sliderRingAnalogDeadzoneHorizontalLayout">
<item>
<widget class="QLabel" name="labelRingAnalogDeadzone">
<property name="text">
<string>Deadzone: 0%</string>
</property>
<property name="alignment">
<set>Qt::AlignHCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="sliderRingAnalogDeadzone">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="RingDriver">
<property name="title">
<string>Direct Joycon Driver</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<property name="verticalSpacing">
<number>10</number>
</property>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>76</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="enable_ring_controller_label">
<property name="text">
<string>Enable Ring Input</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="enable_ring_controller_button">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="ring_controller_sensor_label">
<property name="text">
<string>Ring Sensor Value</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="ring_controller_sensor_value">
<property name="text">
<string>Not connected</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="restore_defaults_button">
<property name="text">
<string>Restore Defaults</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigureRingController</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureRingController</receiver>
<slot>reject()</slot>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,206 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <chrono>
#include <optional>
#include <vector>
#include <QCheckBox>
#include <QComboBox>
#include <QDateTimeEdit>
#include <QFileDialog>
#include <QGraphicsItem>
#include <QLineEdit>
#include <QMessageBox>
#include <QSpinBox>
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_system.h"
#include "suyu/configuration/configuration_shared.h"
#include "suyu/configuration/configure_system.h"
#include "suyu/configuration/shared_widget.h"
constexpr std::array<u32, 7> LOCALE_BLOCKLIST{
// pzzefezrpnkzeidfej
// thhsrnhutlohsternp
// BHH4CG U
// Raa1AB S
// nn9
// ts
0b0100011100001100000, // Japan
0b0000001101001100100, // Americas
0b0100110100001000010, // Europe
0b0100110100001000010, // Australia
0b0000000000000000000, // China
0b0100111100001000000, // Korea
0b0100111100001000000, // Taiwan
};
static bool IsValidLocale(u32 region_index, u32 language_index) {
if (region_index >= LOCALE_BLOCKLIST.size()) {
return false;
}
return ((LOCALE_BLOCKLIST.at(region_index) >> language_index) & 1) == 0;
}
ConfigureSystem::ConfigureSystem(Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::Builder& builder, QWidget* parent)
: Tab(group_, parent), ui{std::make_unique<Ui::ConfigureSystem>()}, system{system_} {
ui->setupUi(this);
const auto posix_time = std::chrono::system_clock::now().time_since_epoch();
const auto current_time_s =
std::chrono::duration_cast<std::chrono::seconds>(posix_time).count();
previous_time = current_time_s + Settings::values.custom_rtc_offset.GetValue();
Setup(builder);
const auto locale_check = [this]() {
const auto region_index = combo_region->currentIndex();
const auto language_index = combo_language->currentIndex();
const bool valid_locale = IsValidLocale(region_index, language_index);
ui->label_warn_invalid_locale->setVisible(!valid_locale);
if (!valid_locale) {
ui->label_warn_invalid_locale->setText(
tr("Warning: \"%1\" is not a valid language for region \"%2\"")
.arg(combo_language->currentText())
.arg(combo_region->currentText()));
}
};
const auto update_date_offset = [this]() {
if (!checkbox_rtc->isChecked()) {
return;
}
auto offset = date_rtc_offset->value();
offset += date_rtc->dateTime().toSecsSinceEpoch() - previous_time;
previous_time = date_rtc->dateTime().toSecsSinceEpoch();
date_rtc_offset->setValue(offset);
};
const auto update_rtc_date = [this]() { UpdateRtcTime(); };
connect(combo_language, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check);
connect(combo_region, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check);
connect(checkbox_rtc, qOverload<int>(&QCheckBox::stateChanged), this, update_rtc_date);
connect(date_rtc_offset, qOverload<int>(&QSpinBox::valueChanged), this, update_rtc_date);
connect(date_rtc, &QDateTimeEdit::dateTimeChanged, this, update_date_offset);
ui->label_warn_invalid_locale->setVisible(false);
locale_check();
SetConfiguration();
UpdateRtcTime();
}
ConfigureSystem::~ConfigureSystem() = default;
void ConfigureSystem::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureSystem::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) {
auto& core_layout = *ui->core_widget->layout();
auto& system_layout = *ui->system_widget->layout();
std::map<u32, QWidget*> core_hold{};
std::map<u32, QWidget*> system_hold{};
std::vector<Settings::BasicSetting*> settings;
auto push = [&settings](auto& list) {
for (auto setting : list) {
settings.push_back(setting);
}
};
push(Settings::values.linkage.by_category[Settings::Category::Core]);
push(Settings::values.linkage.by_category[Settings::Category::System]);
for (auto setting : settings) {
if (setting->Id() == Settings::values.use_docked_mode.Id() &&
Settings::IsConfiguringGlobal()) {
continue;
}
ConfigurationShared::Widget* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
widget->deleteLater();
continue;
}
// Keep track of the region_index (and language_index) combobox to validate the selected
// settings
if (setting->Id() == Settings::values.region_index.Id()) {
combo_region = widget->combobox;
}
if (setting->Id() == Settings::values.language_index.Id()) {
combo_language = widget->combobox;
}
if (setting->Id() == Settings::values.custom_rtc.Id()) {
checkbox_rtc = widget->checkbox;
}
if (setting->Id() == Settings::values.custom_rtc.Id()) {
date_rtc = widget->date_time_edit;
}
if (setting->Id() == Settings::values.custom_rtc_offset.Id()) {
date_rtc_offset = widget->spinbox;
}
switch (setting->GetCategory()) {
case Settings::Category::Core:
core_hold.emplace(setting->Id(), widget);
break;
case Settings::Category::System:
system_hold.emplace(setting->Id(), widget);
break;
default:
widget->deleteLater();
}
}
for (const auto& [label, widget] : core_hold) {
core_layout.addWidget(widget);
}
for (const auto& [id, widget] : system_hold) {
system_layout.addWidget(widget);
}
}
void ConfigureSystem::UpdateRtcTime() {
const auto posix_time = std::chrono::system_clock::now().time_since_epoch();
previous_time = std::chrono::duration_cast<std::chrono::seconds>(posix_time).count();
date_rtc_offset->setEnabled(checkbox_rtc->isChecked());
if (checkbox_rtc->isChecked()) {
previous_time += date_rtc_offset->value();
}
const auto date = QDateTime::fromSecsSinceEpoch(previous_time);
date_rtc->setDateTime(date);
}
void ConfigureSystem::SetConfiguration() {}
void ConfigureSystem::ApplyConfiguration() {
const bool powered_on = system.IsPoweredOn();
for (const auto& func : apply_funcs) {
func(powered_on);
}
UpdateRtcTime();
}

View File

@@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <functional>
#include <memory>
#include <vector>
#include <QWidget>
#include "suyu/configuration/configuration_shared.h"
class QCheckBox;
class QLineEdit;
class QComboBox;
class QDateTimeEdit;
namespace Core {
class System;
}
namespace Ui {
class ConfigureSystem;
}
namespace ConfigurationShared {
class Builder;
}
class ConfigureSystem : public ConfigurationShared::Tab {
Q_OBJECT
public:
explicit ConfigureSystem(Core::System& system_,
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> group,
const ConfigurationShared::Builder& builder,
QWidget* parent = nullptr);
~ConfigureSystem() override;
void ApplyConfiguration() override;
void SetConfiguration() override;
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void Setup(const ConfigurationShared::Builder& builder);
void UpdateRtcTime();
std::vector<std::function<void(bool)>> apply_funcs{};
std::unique_ptr<Ui::ConfigureSystem> ui;
bool enabled = false;
Core::System& system;
QComboBox* combo_region;
QComboBox* combo_language;
QCheckBox* checkbox_rtc;
QDateTimeEdit* date_rtc;
QSpinBox* date_rtc_offset;
u64 previous_time;
};

View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureSystem</class>
<widget class="QWidget" name="ConfigureSystem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>605</width>
<height>483</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="accessibleName">
<string>System</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="group_system_settings">
<property name="title">
<string>System</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="system_widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_warn_invalid_locale">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="coreGroup">
<property name="title">
<string>Core</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QWidget" name="core_widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<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>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,81 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QFileDialog>
#include <QMessageBox>
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
#include "common/settings.h"
#include "ui_configure_tas.h"
#include "suyu/configuration/configure_tas.h"
#include "suyu/uisettings.h"
ConfigureTasDialog::ConfigureTasDialog(QWidget* parent)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureTas>()) {
ui->setupUi(this);
setFocusPolicy(Qt::ClickFocus);
setWindowTitle(tr("TAS Configuration"));
connect(ui->tas_path_button, &QToolButton::pressed, this,
[this] { SetDirectory(DirectoryTarget::TAS, ui->tas_path_edit); });
LoadConfiguration();
}
ConfigureTasDialog::~ConfigureTasDialog() = default;
void ConfigureTasDialog::LoadConfiguration() {
ui->tas_path_edit->setText(
QString::fromStdString(Common::FS::GetSuyuPathString(Common::FS::SuyuPath::TASDir)));
ui->tas_enable->setChecked(Settings::values.tas_enable.GetValue());
ui->tas_loop_script->setChecked(Settings::values.tas_loop.GetValue());
ui->tas_pause_on_load->setChecked(Settings::values.pause_tas_on_load.GetValue());
}
void ConfigureTasDialog::ApplyConfiguration() {
Common::FS::SetSuyuPath(Common::FS::SuyuPath::TASDir, ui->tas_path_edit->text().toStdString());
Settings::values.tas_enable.SetValue(ui->tas_enable->isChecked());
Settings::values.tas_loop.SetValue(ui->tas_loop_script->isChecked());
Settings::values.pause_tas_on_load.SetValue(ui->tas_pause_on_load->isChecked());
}
void ConfigureTasDialog::SetDirectory(DirectoryTarget target, QLineEdit* edit) {
QString caption;
switch (target) {
case DirectoryTarget::TAS:
caption = tr("Select TAS Load Directory...");
break;
}
QString str = QFileDialog::getExistingDirectory(this, caption, edit->text());
if (str.isEmpty()) {
return;
}
if (str.back() != QChar::fromLatin1('/')) {
str.append(QChar::fromLatin1('/'));
}
edit->setText(str);
}
void ConfigureTasDialog::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigureTasDialog::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureTasDialog::HandleApplyButtonClicked() {
UISettings::values.configuration_applied = true;
ApplyConfiguration();
}

View File

@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QDialog>
class QLineEdit;
namespace Ui {
class ConfigureTas;
}
class ConfigureTasDialog : public QDialog {
Q_OBJECT
public:
explicit ConfigureTasDialog(QWidget* parent);
~ConfigureTasDialog() override;
/// Save all button configurations to settings file
void ApplyConfiguration();
private:
enum class DirectoryTarget {
TAS,
};
void LoadConfiguration();
void SetDirectory(DirectoryTarget target, QLineEdit* edit);
void changeEvent(QEvent* event) override;
void RetranslateUI();
void HandleApplyButtonClicked();
std::unique_ptr<Ui::ConfigureTas> ui;
};

View File

@@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureTas</class>
<widget class="QDialog" name="ConfigureTas">
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_1">
<item>
<widget class="QGroupBox" name="groupBox_1">
<property name="title">
<string>TAS</string>
</property>
<layout class="QGridLayout" name="gridLayout_1">
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label_1">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Reads controller input from scripts in the same format as TAS-nx scripts.&lt;br/&gt;For a more detailed explanation, please consult the &lt;a href=&quot;https://suyu.dev/help/feature/tas/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#039be5;&quot;&gt;help page&lt;/span&gt;&lt;/a&gt; on the suyu website.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QLabel" name="label_2">
<property name="text">
<string>To check which hotkeys control the playback/recording, please refer to the Hotkey settings (Configure -&gt; General -&gt; Hotkeys).</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QLabel" name="label_3">
<property name="text">
<string>WARNING: This is an experimental feature.&lt;br/&gt;It will not play back scripts frame perfectly with the current, imperfect syncing method.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="4">
<widget class="QCheckBox" name="tas_enable">
<property name="text">
<string>Enable TAS features</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QCheckBox" name="tas_loop_script">
<property name="text">
<string>Loop script</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QCheckBox" name="tas_pause_on_load">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Pause execution during loads</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Script Directory</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Path</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="tas_path_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="tas_path_edit"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<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>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigureTas</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureTas</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,617 @@
// SPDX-FileCopyrightText: 2020 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QInputDialog>
#include <QKeyEvent>
#include <QMessageBox>
#include <QMouseEvent>
#include <QStandardItemModel>
#include <QTimer>
#include "common/param_package.h"
#include "common/settings.h"
#include "core/frontend/framebuffer_layout.h"
#include "input_common/main.h"
#include "ui_configure_touch_from_button.h"
#include "suyu/configuration/configure_touch_from_button.h"
#include "suyu/configuration/configure_touch_widget.h"
static QString GetKeyName(int key_code) {
switch (key_code) {
case Qt::Key_Shift:
return QObject::tr("Shift");
case Qt::Key_Control:
return QObject::tr("Ctrl");
case Qt::Key_Alt:
return QObject::tr("Alt");
case Qt::Key_Meta:
return QString{};
default:
return QKeySequence(key_code).toString();
}
}
static QString ButtonToText(const Common::ParamPackage& param) {
if (!param.Has("engine")) {
return QObject::tr("[not set]");
}
if (param.Get("engine", "") == "keyboard") {
return GetKeyName(param.Get("code", 0));
}
if (param.Get("engine", "") == "sdl") {
if (param.Has("hat")) {
const QString hat_str = QString::fromStdString(param.Get("hat", ""));
const QString direction_str = QString::fromStdString(param.Get("direction", ""));
return QObject::tr("Hat %1 %2").arg(hat_str, direction_str);
}
if (param.Has("axis")) {
const QString axis_str = QString::fromStdString(param.Get("axis", ""));
const QString direction_str = QString::fromStdString(param.Get("direction", ""));
return QObject::tr("Axis %1%2").arg(axis_str, direction_str);
}
if (param.Has("button")) {
const QString button_str = QString::fromStdString(param.Get("button", ""));
return QObject::tr("Button %1").arg(button_str);
}
return {};
}
return QObject::tr("[unknown]");
}
ConfigureTouchFromButton::ConfigureTouchFromButton(
QWidget* parent, const std::vector<Settings::TouchFromButtonMap>& touch_maps_,
InputCommon::InputSubsystem* input_subsystem_, const int default_index)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureTouchFromButton>()),
touch_maps{touch_maps_}, input_subsystem{input_subsystem_}, selected_index{default_index},
timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) {
ui->setupUi(this);
binding_list_model = new QStandardItemModel(0, 3, this);
binding_list_model->setHorizontalHeaderLabels(
{tr("Button"), tr("X", "X axis"), tr("Y", "Y axis")});
ui->binding_list->setModel(binding_list_model);
ui->bottom_screen->SetCoordLabel(ui->coord_label);
SetConfiguration();
UpdateUiDisplay();
ConnectEvents();
}
ConfigureTouchFromButton::~ConfigureTouchFromButton() = default;
void ConfigureTouchFromButton::showEvent(QShowEvent* ev) {
QWidget::showEvent(ev);
// width values are not valid in the constructor
const int w =
ui->binding_list->viewport()->contentsRect().width() / binding_list_model->columnCount();
if (w <= 0) {
return;
}
ui->binding_list->setColumnWidth(0, w);
ui->binding_list->setColumnWidth(1, w);
ui->binding_list->setColumnWidth(2, w);
}
void ConfigureTouchFromButton::SetConfiguration() {
for (const auto& touch_map : touch_maps) {
ui->mapping->addItem(QString::fromStdString(touch_map.name));
}
ui->mapping->setCurrentIndex(selected_index);
}
void ConfigureTouchFromButton::UpdateUiDisplay() {
ui->button_delete->setEnabled(touch_maps.size() > 1);
ui->button_delete_bind->setEnabled(false);
binding_list_model->removeRows(0, binding_list_model->rowCount());
for (const auto& button_str : touch_maps[selected_index].buttons) {
Common::ParamPackage package{button_str};
QStandardItem* button = new QStandardItem(ButtonToText(package));
button->setData(QString::fromStdString(button_str));
button->setEditable(false);
QStandardItem* xcoord = new QStandardItem(QString::number(package.Get("x", 0)));
QStandardItem* ycoord = new QStandardItem(QString::number(package.Get("y", 0)));
binding_list_model->appendRow({button, xcoord, ycoord});
const int dot = ui->bottom_screen->AddDot(package.Get("x", 0), package.Get("y", 0));
button->setData(dot, DataRoleDot);
}
}
void ConfigureTouchFromButton::ConnectEvents() {
connect(ui->mapping, qOverload<int>(&QComboBox::currentIndexChanged), this, [this](int index) {
SaveCurrentMapping();
selected_index = index;
UpdateUiDisplay();
});
connect(ui->button_new, &QPushButton::clicked, this, &ConfigureTouchFromButton::NewMapping);
connect(ui->button_delete, &QPushButton::clicked, this,
&ConfigureTouchFromButton::DeleteMapping);
connect(ui->button_rename, &QPushButton::clicked, this,
&ConfigureTouchFromButton::RenameMapping);
connect(ui->button_delete_bind, &QPushButton::clicked, this,
&ConfigureTouchFromButton::DeleteBinding);
connect(ui->binding_list, &QTreeView::doubleClicked, this,
&ConfigureTouchFromButton::EditBinding);
connect(ui->binding_list->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ConfigureTouchFromButton::OnBindingSelection);
connect(binding_list_model, &QStandardItemModel::itemChanged, this,
&ConfigureTouchFromButton::OnBindingChanged);
connect(ui->binding_list->model(), &QStandardItemModel::rowsAboutToBeRemoved, this,
&ConfigureTouchFromButton::OnBindingDeleted);
connect(ui->bottom_screen, &TouchScreenPreview::DotAdded, this,
&ConfigureTouchFromButton::NewBinding);
connect(ui->bottom_screen, &TouchScreenPreview::DotSelected, this,
&ConfigureTouchFromButton::SetActiveBinding);
connect(ui->bottom_screen, &TouchScreenPreview::DotMoved, this,
&ConfigureTouchFromButton::SetCoordinates);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this,
&ConfigureTouchFromButton::ApplyConfiguration);
connect(timeout_timer.get(), &QTimer::timeout, [this]() { SetPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this]() {
const auto& params = input_subsystem->GetNextInput();
if (params.Has("engine")) {
SetPollingResult(params, false);
return;
}
});
}
void ConfigureTouchFromButton::SaveCurrentMapping() {
auto& map = touch_maps[selected_index];
map.buttons.clear();
for (int i = 0, rc = binding_list_model->rowCount(); i < rc; ++i) {
const auto bind_str = binding_list_model->index(i, 0)
.data(Qt::ItemDataRole::UserRole + 1)
.toString()
.toStdString();
if (bind_str.empty()) {
continue;
}
Common::ParamPackage params{bind_str};
if (!params.Has("engine")) {
continue;
}
params.Set("x", binding_list_model->index(i, 1).data().toInt());
params.Set("y", binding_list_model->index(i, 2).data().toInt());
map.buttons.emplace_back(params.Serialize());
}
}
void ConfigureTouchFromButton::NewMapping() {
const QString name =
QInputDialog::getText(this, tr("New Profile"), tr("Enter the name for the new profile."));
if (name.isEmpty()) {
return;
}
touch_maps.emplace_back(Settings::TouchFromButtonMap{name.toStdString(), {}});
ui->mapping->addItem(name);
ui->mapping->setCurrentIndex(ui->mapping->count() - 1);
}
void ConfigureTouchFromButton::DeleteMapping() {
const auto answer = QMessageBox::question(
this, tr("Delete Profile"), tr("Delete profile %1?").arg(ui->mapping->currentText()));
if (answer != QMessageBox::Yes) {
return;
}
const bool blocked = ui->mapping->blockSignals(true);
ui->mapping->removeItem(selected_index);
ui->mapping->blockSignals(blocked);
touch_maps.erase(touch_maps.begin() + selected_index);
selected_index = ui->mapping->currentIndex();
UpdateUiDisplay();
}
void ConfigureTouchFromButton::RenameMapping() {
const QString new_name = QInputDialog::getText(this, tr("Rename Profile"), tr("New name:"));
if (new_name.isEmpty()) {
return;
}
ui->mapping->setItemText(selected_index, new_name);
touch_maps[selected_index].name = new_name.toStdString();
}
void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is_new) {
if (timeout_timer->isActive()) {
return;
}
binding_list_model->item(row_index, 0)->setText(tr("[press key]"));
input_setter = [this, row_index, is_new](const Common::ParamPackage& params,
const bool cancel) {
auto* cell = binding_list_model->item(row_index, 0);
if (cancel) {
if (is_new) {
binding_list_model->removeRow(row_index);
} else {
cell->setText(
ButtonToText(Common::ParamPackage{cell->data().toString().toStdString()}));
}
} else {
cell->setText(ButtonToText(params));
cell->setData(QString::fromStdString(params.Serialize()));
}
};
input_subsystem->BeginMapping(InputCommon::Polling::InputType::Button);
grabKeyboard();
grabMouse();
qApp->setOverrideCursor(QCursor(Qt::CursorShape::ArrowCursor));
timeout_timer->start(5000); // Cancel after 5 seconds
poll_timer->start(200); // Check for new inputs every 200ms
}
void ConfigureTouchFromButton::NewBinding(const QPoint& pos) {
auto* button = new QStandardItem();
button->setEditable(false);
auto* x_coord = new QStandardItem(QString::number(pos.x()));
auto* y_coord = new QStandardItem(QString::number(pos.y()));
const int dot_id = ui->bottom_screen->AddDot(pos.x(), pos.y());
button->setData(dot_id, DataRoleDot);
binding_list_model->appendRow({button, x_coord, y_coord});
ui->binding_list->setFocus();
ui->binding_list->setCurrentIndex(button->index());
GetButtonInput(binding_list_model->rowCount() - 1, true);
}
void ConfigureTouchFromButton::EditBinding(const QModelIndex& qi) {
if (qi.row() >= 0 && qi.column() == 0) {
GetButtonInput(qi.row(), false);
}
}
void ConfigureTouchFromButton::DeleteBinding() {
const int row_index = ui->binding_list->currentIndex().row();
if (row_index < 0) {
return;
}
ui->bottom_screen->RemoveDot(binding_list_model->index(row_index, 0).data(DataRoleDot).toInt());
binding_list_model->removeRow(row_index);
}
void ConfigureTouchFromButton::OnBindingSelection(const QItemSelection& selected,
const QItemSelection& deselected) {
ui->button_delete_bind->setEnabled(!selected.isEmpty());
if (!selected.isEmpty()) {
const auto dot_data = selected.indexes().first().data(DataRoleDot);
if (dot_data.isValid()) {
ui->bottom_screen->HighlightDot(dot_data.toInt());
}
}
if (!deselected.isEmpty()) {
const auto dot_data = deselected.indexes().first().data(DataRoleDot);
if (dot_data.isValid()) {
ui->bottom_screen->HighlightDot(dot_data.toInt(), false);
}
}
}
void ConfigureTouchFromButton::OnBindingChanged(QStandardItem* item) {
if (item->column() == 0) {
return;
}
const bool blocked = binding_list_model->blockSignals(true);
item->setText(QString::number(
std::clamp(item->text().toInt(), 0,
static_cast<int>((item->column() == 1 ? Layout::ScreenUndocked::Width
: Layout::ScreenUndocked::Height) -
1))));
binding_list_model->blockSignals(blocked);
const auto dot_data = binding_list_model->index(item->row(), 0).data(DataRoleDot);
if (dot_data.isValid()) {
ui->bottom_screen->MoveDot(dot_data.toInt(),
binding_list_model->item(item->row(), 1)->text().toInt(),
binding_list_model->item(item->row(), 2)->text().toInt());
}
}
void ConfigureTouchFromButton::OnBindingDeleted(const QModelIndex& parent, int first, int last) {
for (int i = first; i <= last; ++i) {
const auto ix = binding_list_model->index(i, 0);
if (!ix.isValid()) {
return;
}
const auto dot_data = ix.data(DataRoleDot);
if (dot_data.isValid()) {
ui->bottom_screen->RemoveDot(dot_data.toInt());
}
}
}
void ConfigureTouchFromButton::SetActiveBinding(const int dot_id) {
for (int i = 0; i < binding_list_model->rowCount(); ++i) {
if (binding_list_model->index(i, 0).data(DataRoleDot) == dot_id) {
ui->binding_list->setCurrentIndex(binding_list_model->index(i, 0));
ui->binding_list->setFocus();
return;
}
}
}
void ConfigureTouchFromButton::SetCoordinates(const int dot_id, const QPoint& pos) {
for (int i = 0; i < binding_list_model->rowCount(); ++i) {
if (binding_list_model->item(i, 0)->data(DataRoleDot) == dot_id) {
binding_list_model->item(i, 1)->setText(QString::number(pos.x()));
binding_list_model->item(i, 2)->setText(QString::number(pos.y()));
return;
}
}
}
void ConfigureTouchFromButton::SetPollingResult(const Common::ParamPackage& params,
const bool cancel) {
timeout_timer->stop();
poll_timer->stop();
input_subsystem->StopMapping();
releaseKeyboard();
releaseMouse();
qApp->restoreOverrideCursor();
if (input_setter) {
(*input_setter)(params, cancel);
input_setter.reset();
}
}
void ConfigureTouchFromButton::keyPressEvent(QKeyEvent* event) {
if (!input_setter && event->key() == Qt::Key_Delete) {
DeleteBinding();
return;
}
if (!input_setter) {
return QDialog::keyPressEvent(event);
}
if (event->key() != Qt::Key_Escape) {
SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())},
false);
} else {
SetPollingResult({}, true);
}
}
void ConfigureTouchFromButton::ApplyConfiguration() {
SaveCurrentMapping();
accept();
}
int ConfigureTouchFromButton::GetSelectedIndex() const {
return selected_index;
}
std::vector<Settings::TouchFromButtonMap> ConfigureTouchFromButton::GetMaps() const {
return touch_maps;
}
TouchScreenPreview::TouchScreenPreview(QWidget* parent) : QFrame(parent) {
setBackgroundRole(QPalette::ColorRole::Base);
}
TouchScreenPreview::~TouchScreenPreview() = default;
void TouchScreenPreview::SetCoordLabel(QLabel* const label) {
coord_label = label;
}
int TouchScreenPreview::AddDot(const int device_x, const int device_y) {
QFont dot_font{QStringLiteral("monospace")};
dot_font.setStyleHint(QFont::Monospace);
dot_font.setPointSize(20);
auto* dot = new QLabel(this);
dot->setAttribute(Qt::WA_TranslucentBackground);
dot->setFont(dot_font);
dot->setText(QChar(0xD7)); // U+00D7 Multiplication Sign
dot->setAlignment(Qt::AlignmentFlag::AlignCenter);
dot->setProperty(PropId, ++max_dot_id);
dot->setProperty(PropX, device_x);
dot->setProperty(PropY, device_y);
dot->setCursor(Qt::CursorShape::PointingHandCursor);
dot->setMouseTracking(true);
dot->installEventFilter(this);
dot->show();
PositionDot(dot, device_x, device_y);
dots.emplace_back(max_dot_id, dot);
return max_dot_id;
}
void TouchScreenPreview::RemoveDot(const int id) {
const auto iter = std::find_if(dots.begin(), dots.end(),
[id](const auto& entry) { return entry.first == id; });
if (iter == dots.cend()) {
return;
}
iter->second->deleteLater();
dots.erase(iter);
}
void TouchScreenPreview::HighlightDot(const int id, const bool active) const {
for (const auto& dot : dots) {
if (dot.first == id) {
// use color property from the stylesheet, or fall back to the default palette
if (dot_highlight_color.isValid()) {
dot.second->setStyleSheet(
active ? QStringLiteral("color: %1").arg(dot_highlight_color.name())
: QString{});
} else {
dot.second->setForegroundRole(active ? QPalette::ColorRole::LinkVisited
: QPalette::ColorRole::NoRole);
}
if (active) {
dot.second->raise();
}
return;
}
}
}
void TouchScreenPreview::MoveDot(const int id, const int device_x, const int device_y) const {
const auto iter = std::find_if(dots.begin(), dots.end(),
[id](const auto& entry) { return entry.first == id; });
if (iter == dots.cend()) {
return;
}
iter->second->setProperty(PropX, device_x);
iter->second->setProperty(PropY, device_y);
PositionDot(iter->second, device_x, device_y);
}
void TouchScreenPreview::resizeEvent(QResizeEvent* event) {
if (ignore_resize) {
return;
}
const int target_width = std::min(width(), height() * 4 / 3);
const int target_height = std::min(height(), width() * 3 / 4);
if (target_width == width() && target_height == height()) {
return;
}
ignore_resize = true;
setGeometry((parentWidget()->contentsRect().width() - target_width) / 2, y(), target_width,
target_height);
ignore_resize = false;
if (event->oldSize().width() != target_width || event->oldSize().height() != target_height) {
for (const auto& dot : dots) {
PositionDot(dot.second);
}
}
}
void TouchScreenPreview::mouseMoveEvent(QMouseEvent* event) {
if (!coord_label) {
return;
}
const auto pos = MapToDeviceCoords(event->x(), event->y());
if (pos) {
coord_label->setText(QStringLiteral("X: %1, Y: %2").arg(pos->x()).arg(pos->y()));
} else {
coord_label->clear();
}
}
void TouchScreenPreview::leaveEvent(QEvent* event) {
if (coord_label) {
coord_label->clear();
}
}
void TouchScreenPreview::mousePressEvent(QMouseEvent* event) {
if (event->button() != Qt::MouseButton::LeftButton) {
return;
}
const auto pos = MapToDeviceCoords(event->x(), event->y());
if (pos) {
emit DotAdded(*pos);
}
}
bool TouchScreenPreview::eventFilter(QObject* obj, QEvent* event) {
switch (event->type()) {
case QEvent::Type::MouseButtonPress: {
const auto mouse_event = static_cast<QMouseEvent*>(event);
if (mouse_event->button() != Qt::MouseButton::LeftButton) {
break;
}
emit DotSelected(obj->property(PropId).toInt());
drag_state.dot = qobject_cast<QLabel*>(obj);
drag_state.start_pos = mouse_event->globalPos();
return true;
}
case QEvent::Type::MouseMove: {
if (!drag_state.dot) {
break;
}
const auto mouse_event = static_cast<QMouseEvent*>(event);
if (!drag_state.active) {
drag_state.active =
(mouse_event->globalPos() - drag_state.start_pos).manhattanLength() >=
QApplication::startDragDistance();
if (!drag_state.active) {
break;
}
}
auto current_pos = mapFromGlobal(mouse_event->globalPos());
current_pos.setX(std::clamp(current_pos.x(), contentsMargins().left(),
contentsMargins().left() + contentsRect().width() - 1));
current_pos.setY(std::clamp(current_pos.y(), contentsMargins().top(),
contentsMargins().top() + contentsRect().height() - 1));
const auto device_coord = MapToDeviceCoords(current_pos.x(), current_pos.y());
if (device_coord) {
drag_state.dot->setProperty(PropX, device_coord->x());
drag_state.dot->setProperty(PropY, device_coord->y());
PositionDot(drag_state.dot, device_coord->x(), device_coord->y());
emit DotMoved(drag_state.dot->property(PropId).toInt(), *device_coord);
if (coord_label) {
coord_label->setText(
QStringLiteral("X: %1, Y: %2").arg(device_coord->x()).arg(device_coord->y()));
}
}
return true;
}
case QEvent::Type::MouseButtonRelease: {
drag_state.dot.clear();
drag_state.active = false;
return true;
}
default:
break;
}
return obj->eventFilter(obj, event);
}
std::optional<QPoint> TouchScreenPreview::MapToDeviceCoords(const int screen_x,
const int screen_y) const {
const float t_x = 0.5f + static_cast<float>(screen_x - contentsMargins().left()) *
(Layout::ScreenUndocked::Width - 1) / (contentsRect().width() - 1);
const float t_y = 0.5f + static_cast<float>(screen_y - contentsMargins().top()) *
(Layout::ScreenUndocked::Height - 1) /
(contentsRect().height() - 1);
if (t_x >= 0.5f && t_x < Layout::ScreenUndocked::Width && t_y >= 0.5f &&
t_y < Layout::ScreenUndocked::Height) {
return QPoint{static_cast<int>(t_x), static_cast<int>(t_y)};
}
return std::nullopt;
}
void TouchScreenPreview::PositionDot(QLabel* const dot, const int device_x,
const int device_y) const {
const float device_coord_x =
static_cast<float>(device_x >= 0 ? device_x : dot->property(PropX).toInt());
int x_coord = static_cast<int>(
device_coord_x * (contentsRect().width() - 1) / (Layout::ScreenUndocked::Width - 1) +
contentsMargins().left() - static_cast<float>(dot->width()) / 2 + 0.5f);
const float device_coord_y =
static_cast<float>(device_y >= 0 ? device_y : dot->property(PropY).toInt());
const int y_coord = static_cast<int>(
device_coord_y * (contentsRect().height() - 1) / (Layout::ScreenUndocked::Height - 1) +
contentsMargins().top() - static_cast<float>(dot->height()) / 2 + 0.5f);
dot->move(x_coord, y_coord);
}

View File

@@ -0,0 +1,86 @@
// SPDX-FileCopyrightText: 2020 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <functional>
#include <memory>
#include <optional>
#include <vector>
#include <QDialog>
class QItemSelection;
class QModelIndex;
class QStandardItemModel;
class QStandardItem;
class QTimer;
namespace Common {
class ParamPackage;
}
namespace InputCommon {
class InputSubsystem;
}
namespace Settings {
struct TouchFromButtonMap;
}
namespace Ui {
class ConfigureTouchFromButton;
}
class ConfigureTouchFromButton : public QDialog {
Q_OBJECT
public:
explicit ConfigureTouchFromButton(QWidget* parent,
const std::vector<Settings::TouchFromButtonMap>& touch_maps_,
InputCommon::InputSubsystem* input_subsystem_,
int default_index = 0);
~ConfigureTouchFromButton() override;
int GetSelectedIndex() const;
std::vector<Settings::TouchFromButtonMap> GetMaps() const;
public slots:
void ApplyConfiguration();
void NewBinding(const QPoint& pos);
void SetActiveBinding(int dot_id);
void SetCoordinates(int dot_id, const QPoint& pos);
protected:
void showEvent(QShowEvent* ev) override;
void keyPressEvent(QKeyEvent* event) override;
private slots:
void NewMapping();
void DeleteMapping();
void RenameMapping();
void EditBinding(const QModelIndex& qi);
void DeleteBinding();
void OnBindingSelection(const QItemSelection& selected, const QItemSelection& deselected);
void OnBindingChanged(QStandardItem* item);
void OnBindingDeleted(const QModelIndex& parent, int first, int last);
private:
void SetConfiguration();
void UpdateUiDisplay();
void ConnectEvents();
void GetButtonInput(int row_index, bool is_new);
void SetPollingResult(const Common::ParamPackage& params, bool cancel);
void SaveCurrentMapping();
std::unique_ptr<Ui::ConfigureTouchFromButton> ui;
std::vector<Settings::TouchFromButtonMap> touch_maps;
QStandardItemModel* binding_list_model;
InputCommon::InputSubsystem* input_subsystem;
int selected_index;
std::unique_ptr<QTimer> timeout_timer;
std::unique_ptr<QTimer> poll_timer;
std::optional<std::function<void(const Common::ParamPackage&, bool)>> input_setter;
static constexpr int DataRoleDot = Qt::ItemDataRole::UserRole + 2;
};

View File

@@ -0,0 +1,221 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureTouchFromButton</class>
<widget class="QDialog" name="ConfigureTouchFromButton">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>500</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure Touchscreen Mappings</string>
</property>
<layout class="QVBoxLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Mapping:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mapping">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_new">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>New</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_delete">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_rename">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Rename</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Click the bottom area to add a point, then press a button to bind.
Drag points to change position, or double-click table cells to edit values.</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="button_delete_bind">
<property name="text">
<string>Delete Point</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="binding_list">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="TouchScreenPreview" name="bottom_screen">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>160</width>
<height>120</height>
</size>
</property>
<property name="baseSize">
<size>
<width>320</width>
<height>240</height>
</size>
</property>
<property name="cursor">
<cursorShape>CrossCursor</cursorShape>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="coord_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TouchScreenPreview</class>
<extends>QFrame</extends>
<header>suyu/configuration/configure_touch_widget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureTouchFromButton</receiver>
<slot>reject()</slot>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: 2020 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <optional>
#include <utility>
#include <vector>
#include <QFrame>
#include <QPointer>
class QLabel;
// Widget for representing touchscreen coordinates
class TouchScreenPreview : public QFrame {
Q_OBJECT
Q_PROPERTY(QColor dotHighlightColor MEMBER dot_highlight_color)
public:
explicit TouchScreenPreview(QWidget* parent);
~TouchScreenPreview() override;
void SetCoordLabel(QLabel*);
int AddDot(int device_x, int device_y);
void RemoveDot(int id);
void HighlightDot(int id, bool active = true) const;
void MoveDot(int id, int device_x, int device_y) const;
signals:
void DotAdded(const QPoint& pos);
void DotSelected(int dot_id);
void DotMoved(int dot_id, const QPoint& pos);
protected:
void resizeEvent(QResizeEvent*) override;
void mouseMoveEvent(QMouseEvent*) override;
void leaveEvent(QEvent*) override;
void mousePressEvent(QMouseEvent*) override;
bool eventFilter(QObject*, QEvent*) override;
private:
std::optional<QPoint> MapToDeviceCoords(int screen_x, int screen_y) const;
void PositionDot(QLabel* dot, int device_x = -1, int device_y = -1) const;
bool ignore_resize = false;
QPointer<QLabel> coord_label;
std::vector<std::pair<int, QLabel*>> dots;
int max_dot_id = 0;
QColor dot_highlight_color;
static constexpr char PropId[] = "dot_id";
static constexpr char PropX[] = "device_x";
static constexpr char PropY[] = "device_y";
struct DragState {
bool active = false;
QPointer<QLabel> dot;
QPoint start_pos;
};
DragState drag_state;
};

View File

@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include "common/settings.h"
#include "ui_configure_touchscreen_advanced.h"
#include "suyu/configuration/configure_touchscreen_advanced.h"
ConfigureTouchscreenAdvanced::ConfigureTouchscreenAdvanced(QWidget* parent)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureTouchscreenAdvanced>()) {
ui->setupUi(this);
connect(ui->restore_defaults_button, &QPushButton::clicked, this,
&ConfigureTouchscreenAdvanced::RestoreDefaults);
LoadConfiguration();
resize(0, 0);
}
ConfigureTouchscreenAdvanced::~ConfigureTouchscreenAdvanced() = default;
void ConfigureTouchscreenAdvanced::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QDialog::changeEvent(event);
}
void ConfigureTouchscreenAdvanced::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureTouchscreenAdvanced::ApplyConfiguration() {
Settings::values.touchscreen.diameter_x = ui->diameter_x_box->value();
Settings::values.touchscreen.diameter_y = ui->diameter_y_box->value();
Settings::values.touchscreen.rotation_angle = ui->angle_box->value();
}
void ConfigureTouchscreenAdvanced::LoadConfiguration() {
ui->diameter_x_box->setValue(Settings::values.touchscreen.diameter_x);
ui->diameter_y_box->setValue(Settings::values.touchscreen.diameter_y);
ui->angle_box->setValue(Settings::values.touchscreen.rotation_angle);
}
void ConfigureTouchscreenAdvanced::RestoreDefaults() {
ui->diameter_x_box->setValue(15);
ui->diameter_y_box->setValue(15);
ui->angle_box->setValue(0);
}

View File

@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QDialog>
namespace Ui {
class ConfigureTouchscreenAdvanced;
}
class ConfigureTouchscreenAdvanced : public QDialog {
Q_OBJECT
public:
explicit ConfigureTouchscreenAdvanced(QWidget* parent);
~ConfigureTouchscreenAdvanced() override;
void ApplyConfiguration();
private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
/// Load configuration settings.
void LoadConfiguration();
/// Restore all buttons to their default values.
void RestoreDefaults();
std::unique_ptr<Ui::ConfigureTouchscreenAdvanced> ui;
};

View File

@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureTouchscreenAdvanced</class>
<widget class="QDialog" name="ConfigureTouchscreenAdvanced">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>298</width>
<height>339</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure Touchscreen</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>280</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Warning: The settings in this page affect the inner workings of suyu's emulated touchscreen. Changing them may result in undesirable behavior, such as the touchscreen partially or not working. You should only use this page if you know what you are doing.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="gridGroupBox">
<property name="title">
<string>Touch Parameters</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Touch Diameter Y</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Touch Diameter X</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Rotational Angle</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="diameter_x_box"/>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="diameter_y_box"/>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="angle_box"/>
</item>
</layout>
</widget>
</item>
<item>
<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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="restore_defaults_button">
<property name="text">
<string>Restore Defaults</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigureTouchscreenAdvanced</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureTouchscreenAdvanced</receiver>
<slot>reject()</slot>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,354 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "suyu/configuration/configure_ui.h"
#include <array>
#include <cstdlib>
#include <set>
#include <stdexcept>
#include <string>
#include <utility>
#include <QCheckBox>
#include <QComboBox>
#include <QCoreApplication>
#include <QDirIterator>
#include <QFileDialog>
#include <QString>
#include <QToolButton>
#include <QVariant>
#include "common/common_types.h"
#include "common/fs/path_util.h"
#include "common/logging/log.h"
#include "common/settings.h"
#include "common/settings_enums.h"
#include "core/core.h"
#include "core/frontend/framebuffer_layout.h"
#include "ui_configure_ui.h"
#include "suyu/uisettings.h"
namespace {
constexpr std::array default_game_icon_sizes{
std::make_pair(0, QT_TRANSLATE_NOOP("ConfigureUI", "None")),
std::make_pair(32, QT_TRANSLATE_NOOP("ConfigureUI", "Small (32x32)")),
std::make_pair(64, QT_TRANSLATE_NOOP("ConfigureUI", "Standard (64x64)")),
std::make_pair(128, QT_TRANSLATE_NOOP("ConfigureUI", "Large (128x128)")),
std::make_pair(256, QT_TRANSLATE_NOOP("ConfigureUI", "Full Size (256x256)")),
};
constexpr std::array default_folder_icon_sizes{
std::make_pair(0, QT_TRANSLATE_NOOP("ConfigureUI", "None")),
std::make_pair(24, QT_TRANSLATE_NOOP("ConfigureUI", "Small (24x24)")),
std::make_pair(48, QT_TRANSLATE_NOOP("ConfigureUI", "Standard (48x48)")),
std::make_pair(72, QT_TRANSLATE_NOOP("ConfigureUI", "Large (72x72)")),
};
// clang-format off
constexpr std::array row_text_names{
QT_TRANSLATE_NOOP("ConfigureUI", "Filename"),
QT_TRANSLATE_NOOP("ConfigureUI", "Filetype"),
QT_TRANSLATE_NOOP("ConfigureUI", "Title ID"),
QT_TRANSLATE_NOOP("ConfigureUI", "Title Name"),
QT_TRANSLATE_NOOP("ConfigureUI", "None"),
};
// clang-format on
QString GetTranslatedGameIconSize(size_t index) {
return QCoreApplication::translate("ConfigureUI", default_game_icon_sizes[index].second);
}
QString GetTranslatedFolderIconSize(size_t index) {
return QCoreApplication::translate("ConfigureUI", default_folder_icon_sizes[index].second);
}
QString GetTranslatedRowTextName(size_t index) {
return QCoreApplication::translate("ConfigureUI", row_text_names[index]);
}
} // Anonymous namespace
static float GetUpFactor(Settings::ResolutionSetup res_setup) {
Settings::ResolutionScalingInfo info{};
Settings::TranslateResolutionInfo(res_setup, info);
return info.up_factor;
}
static void PopulateResolutionComboBox(QComboBox* screenshot_height, QWidget* parent) {
screenshot_height->clear();
const auto& enumeration =
Settings::EnumMetadata<Settings::ResolutionSetup>::Canonicalizations();
std::set<u32> resolutions{};
for (const auto& [name, value] : enumeration) {
const float up_factor = GetUpFactor(value);
u32 height_undocked = Layout::ScreenUndocked::Height * up_factor;
u32 height_docked = Layout::ScreenDocked::Height * up_factor;
resolutions.emplace(height_undocked);
resolutions.emplace(height_docked);
}
screenshot_height->addItem(parent->tr("Auto", "Screenshot height option"));
for (const auto res : resolutions) {
screenshot_height->addItem(QString::fromStdString(std::to_string(res)));
}
}
static u32 ScreenshotDimensionToInt(const QString& height) {
return std::strtoul(height.toUtf8(), nullptr, 0);
}
ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()},
ratio{Settings::values.aspect_ratio.GetValue()},
resolution_setting{Settings::values.resolution_setup.GetValue()}, system{system_} {
ui->setupUi(this);
InitializeLanguageComboBox();
for (const auto& theme : UISettings::themes) {
ui->theme_combobox->addItem(QString::fromUtf8(theme.first),
QString::fromUtf8(theme.second));
}
InitializeIconSizeComboBox();
InitializeRowComboBoxes();
PopulateResolutionComboBox(ui->screenshot_height, this);
SetConfiguration();
// Force game list reload if any of the relevant settings are changed.
connect(ui->show_add_ons, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_compat, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_size, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_types, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_play_time, &QCheckBox::stateChanged, this,
&ConfigureUi::RequestGameListUpdate);
connect(ui->game_icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ConfigureUi::RequestGameListUpdate);
connect(ui->folder_icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &ConfigureUi::RequestGameListUpdate);
connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ConfigureUi::RequestGameListUpdate);
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ConfigureUi::RequestGameListUpdate);
// Update text ComboBoxes after user interaction.
connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::activated),
[this] { ConfigureUi::UpdateSecondRowComboBox(); });
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::activated),
[this] { ConfigureUi::UpdateFirstRowComboBox(); });
// Set screenshot path to user specification.
connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] {
auto dir =
QFileDialog::getExistingDirectory(this, tr("Select Screenshots Path..."),
QString::fromStdString(Common::FS::GetSuyuPathString(
Common::FS::SuyuPath::ScreenshotsDir)));
if (!dir.isEmpty()) {
if (dir.back() != QChar::fromLatin1('/')) {
dir.append(QChar::fromLatin1('/'));
}
ui->screenshot_path_edit->setText(dir);
}
});
connect(ui->screenshot_height, &QComboBox::currentTextChanged, [this]() { UpdateWidthText(); });
UpdateWidthText();
}
ConfigureUi::~ConfigureUi() = default;
void ConfigureUi::ApplyConfiguration() {
UISettings::values.theme =
ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString().toStdString();
UISettings::values.show_add_ons = ui->show_add_ons->isChecked();
UISettings::values.show_compat = ui->show_compat->isChecked();
UISettings::values.show_size = ui->show_size->isChecked();
UISettings::values.show_types = ui->show_types->isChecked();
UISettings::values.show_play_time = ui->show_play_time->isChecked();
UISettings::values.game_icon_size = ui->game_icon_size_combobox->currentData().toUInt();
UISettings::values.folder_icon_size = ui->folder_icon_size_combobox->currentData().toUInt();
UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt();
UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt();
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
Common::FS::SetSuyuPath(Common::FS::SuyuPath::ScreenshotsDir,
ui->screenshot_path_edit->text().toStdString());
const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText());
UISettings::values.screenshot_height.SetValue(height);
RequestGameListUpdate();
system.ApplySettings();
}
void ConfigureUi::RequestGameListUpdate() {
UISettings::values.is_game_list_reload_pending.exchange(true);
}
void ConfigureUi::SetConfiguration() {
ui->theme_combobox->setCurrentIndex(
ui->theme_combobox->findData(QString::fromStdString(UISettings::values.theme)));
ui->language_combobox->setCurrentIndex(ui->language_combobox->findData(
QString::fromStdString(UISettings::values.language.GetValue())));
ui->show_add_ons->setChecked(UISettings::values.show_add_ons.GetValue());
ui->show_compat->setChecked(UISettings::values.show_compat.GetValue());
ui->show_size->setChecked(UISettings::values.show_size.GetValue());
ui->show_types->setChecked(UISettings::values.show_types.GetValue());
ui->show_play_time->setChecked(UISettings::values.show_play_time.GetValue());
ui->game_icon_size_combobox->setCurrentIndex(
ui->game_icon_size_combobox->findData(UISettings::values.game_icon_size.GetValue()));
ui->folder_icon_size_combobox->setCurrentIndex(
ui->folder_icon_size_combobox->findData(UISettings::values.folder_icon_size.GetValue()));
ui->enable_screenshot_save_as->setChecked(
UISettings::values.enable_screenshot_save_as.GetValue());
ui->screenshot_path_edit->setText(QString::fromStdString(
Common::FS::GetSuyuPathString(Common::FS::SuyuPath::ScreenshotsDir)));
const auto height = UISettings::values.screenshot_height.GetValue();
if (height == 0) {
ui->screenshot_height->setCurrentIndex(0);
} else {
ui->screenshot_height->setCurrentText(QStringLiteral("%1").arg(height));
}
}
void ConfigureUi::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureUi::RetranslateUI() {
ui->retranslateUi(this);
for (int i = 0; i < ui->game_icon_size_combobox->count(); i++) {
ui->game_icon_size_combobox->setItemText(i,
GetTranslatedGameIconSize(static_cast<size_t>(i)));
}
for (int i = 0; i < ui->folder_icon_size_combobox->count(); i++) {
ui->folder_icon_size_combobox->setItemText(
i, GetTranslatedFolderIconSize(static_cast<size_t>(i)));
}
for (int i = 0; i < ui->row_1_text_combobox->count(); i++) {
const QString name = GetTranslatedRowTextName(static_cast<size_t>(i));
ui->row_1_text_combobox->setItemText(i, name);
ui->row_2_text_combobox->setItemText(i, name);
}
}
void ConfigureUi::InitializeLanguageComboBox() {
ui->language_combobox->addItem(tr("<System>"), QString{});
ui->language_combobox->addItem(tr("English"), QStringLiteral("en"));
QDirIterator it(QStringLiteral(":/languages"), QDirIterator::NoIteratorFlags);
while (it.hasNext()) {
QString locale = it.next();
locale.truncate(locale.lastIndexOf(QLatin1Char{'.'}));
locale.remove(0, locale.lastIndexOf(QLatin1Char{'/'}) + 1);
const QString lang = QLocale::languageToString(QLocale(locale).language());
const QString country = QLocale::countryToString(QLocale(locale).country());
ui->language_combobox->addItem(QStringLiteral("%1 (%2)").arg(lang, country), locale);
}
// Unlike other configuration changes, interface language changes need to be reflected on the
// interface immediately. This is done by passing a signal to the main window, and then
// retranslating when passing back.
connect(ui->language_combobox, qOverload<int>(&QComboBox::currentIndexChanged), this,
&ConfigureUi::OnLanguageChanged);
}
void ConfigureUi::InitializeIconSizeComboBox() {
for (size_t i = 0; i < default_game_icon_sizes.size(); i++) {
const auto size = default_game_icon_sizes[i].first;
ui->game_icon_size_combobox->addItem(GetTranslatedGameIconSize(i), size);
}
for (size_t i = 0; i < default_folder_icon_sizes.size(); i++) {
const auto size = default_folder_icon_sizes[i].first;
ui->folder_icon_size_combobox->addItem(GetTranslatedFolderIconSize(i), size);
}
}
void ConfigureUi::InitializeRowComboBoxes() {
UpdateFirstRowComboBox(true);
UpdateSecondRowComboBox(true);
}
void ConfigureUi::UpdateFirstRowComboBox(bool init) {
const int currentIndex =
init ? UISettings::values.row_1_text_id.GetValue()
: ui->row_1_text_combobox->findData(ui->row_1_text_combobox->currentData());
ui->row_1_text_combobox->clear();
for (std::size_t i = 0; i < row_text_names.size(); i++) {
const QString row_text_name = GetTranslatedRowTextName(i);
ui->row_1_text_combobox->addItem(row_text_name, QVariant::fromValue(i));
}
ui->row_1_text_combobox->setCurrentIndex(ui->row_1_text_combobox->findData(currentIndex));
ui->row_1_text_combobox->removeItem(4); // None
ui->row_1_text_combobox->removeItem(
ui->row_1_text_combobox->findData(ui->row_2_text_combobox->currentData()));
}
void ConfigureUi::UpdateSecondRowComboBox(bool init) {
const int currentIndex =
init ? UISettings::values.row_2_text_id.GetValue()
: ui->row_2_text_combobox->findData(ui->row_2_text_combobox->currentData());
ui->row_2_text_combobox->clear();
for (std::size_t i = 0; i < row_text_names.size(); ++i) {
const QString row_text_name = GetTranslatedRowTextName(i);
ui->row_2_text_combobox->addItem(row_text_name, QVariant::fromValue(i));
}
ui->row_2_text_combobox->setCurrentIndex(ui->row_2_text_combobox->findData(currentIndex));
ui->row_2_text_combobox->removeItem(
ui->row_2_text_combobox->findData(ui->row_1_text_combobox->currentData()));
}
void ConfigureUi::OnLanguageChanged(int index) {
if (index == -1)
return;
emit LanguageChanged(ui->language_combobox->itemData(index).toString());
}
void ConfigureUi::UpdateWidthText() {
const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText());
const u32 width = UISettings::CalculateWidth(height, ratio);
if (height == 0) {
const auto up_factor = GetUpFactor(resolution_setting);
const u32 height_docked = Layout::ScreenDocked::Height * up_factor;
const u32 width_docked = UISettings::CalculateWidth(height_docked, ratio);
const u32 height_undocked = Layout::ScreenUndocked::Height * up_factor;
const u32 width_undocked = UISettings::CalculateWidth(height_undocked, ratio);
ui->screenshot_width->setText(tr("Auto (%1 x %2, %3 x %4)", "Screenshot width value")
.arg(width_undocked)
.arg(height_undocked)
.arg(width_docked)
.arg(height_docked));
} else {
ui->screenshot_width->setText(QStringLiteral("%1 x").arg(width));
}
}
void ConfigureUi::UpdateScreenshotInfo(Settings::AspectRatio ratio_,
Settings::ResolutionSetup resolution_setting_) {
ratio = ratio_;
resolution_setting = resolution_setting_;
UpdateWidthText();
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QWidget>
#include "common/settings_enums.h"
namespace Core {
class System;
}
namespace Ui {
class ConfigureUi;
}
class ConfigureUi : public QWidget {
Q_OBJECT
public:
explicit ConfigureUi(Core::System& system_, QWidget* parent = nullptr);
~ConfigureUi() override;
void ApplyConfiguration();
void UpdateScreenshotInfo(Settings::AspectRatio ratio,
Settings::ResolutionSetup resolution_info);
private slots:
void OnLanguageChanged(int index);
signals:
void LanguageChanged(const QString& locale);
private:
void RequestGameListUpdate();
void SetConfiguration();
void changeEvent(QEvent*) override;
void RetranslateUI();
void InitializeLanguageComboBox();
void InitializeIconSizeComboBox();
void InitializeRowComboBoxes();
void UpdateFirstRowComboBox(bool init = false);
void UpdateSecondRowComboBox(bool init = false);
void UpdateWidthText();
std::unique_ptr<Ui::ConfigureUi> ui;
Settings::AspectRatio ratio;
Settings::ResolutionSetup resolution_setting;
Core::System& system;
};

Some files were not shown because too many files have changed in this diff Show More