mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2025-07-23 06:15:46 +00:00
input_common: Add VibrationDevice and VibrationDeviceFactory
A vibration device is an input device that returns an unsigned byte as status. It represents whether the vibration device supports vibration or not. If the status returns 1, it supports vibration. Otherwise, it does not support vibration.
This commit is contained in:
parent
cce389221b
commit
ad3905fe27
19 changed files with 327 additions and 101 deletions
|
@ -2,6 +2,12 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "common/param_package.h"
|
||||
#include "core/settings.h"
|
||||
#include "ui_configure_vibration.h"
|
||||
#include "yuzu/configuration/configure_vibration.h"
|
||||
|
@ -53,6 +59,80 @@ void ConfigureVibration::ApplyConfiguration() {
|
|||
ui->checkBoxAccurateVibration->isChecked());
|
||||
}
|
||||
|
||||
void ConfigureVibration::SetVibrationDevices(std::size_t player_index) {
|
||||
using namespace Settings::NativeButton;
|
||||
static constexpr std::array<std::array<Settings::NativeButton::Values, 6>, 2> buttons{{
|
||||
{DLeft, DUp, DRight, DDown, L, ZL}, // Left Buttons
|
||||
{A, B, X, Y, R, ZR}, // Right Buttons
|
||||
}};
|
||||
|
||||
auto& player = Settings::values.players.GetValue()[player_index];
|
||||
|
||||
for (std::size_t device_idx = 0; device_idx < buttons.size(); ++device_idx) {
|
||||
std::unordered_map<std::string, int> params_count;
|
||||
|
||||
for (const auto button_index : buttons[device_idx]) {
|
||||
const auto& player_button = player.buttons[button_index];
|
||||
|
||||
if (params_count.find(player_button) != params_count.end()) {
|
||||
++params_count[player_button];
|
||||
continue;
|
||||
}
|
||||
|
||||
params_count.insert_or_assign(player_button, 1);
|
||||
}
|
||||
|
||||
const auto it = std::max_element(
|
||||
params_count.begin(), params_count.end(),
|
||||
[](const auto& lhs, const auto& rhs) { return lhs.second < rhs.second; });
|
||||
|
||||
auto& vibration_param_str = player.vibrations[device_idx];
|
||||
vibration_param_str.clear();
|
||||
|
||||
if (it->first.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto param = Common::ParamPackage(it->first);
|
||||
|
||||
const auto engine = param.Get("engine", "");
|
||||
const auto guid = param.Get("guid", "");
|
||||
const auto port = param.Get("port", "");
|
||||
|
||||
if (engine.empty() || engine == "keyboard") {
|
||||
continue;
|
||||
}
|
||||
|
||||
vibration_param_str += fmt::format("engine:{}", engine);
|
||||
|
||||
if (!port.empty()) {
|
||||
vibration_param_str += fmt::format(",port:{}", port);
|
||||
}
|
||||
if (!guid.empty()) {
|
||||
vibration_param_str += fmt::format(",guid:{}", guid);
|
||||
}
|
||||
}
|
||||
|
||||
if (player.vibrations[0] != player.vibrations[1]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.vibrations[0].empty() &&
|
||||
player.controller_type != Settings::ControllerType::RightJoycon) {
|
||||
player.vibrations[1].clear();
|
||||
} else if (!player.vibrations[1].empty() &&
|
||||
player.controller_type == Settings::ControllerType::RightJoycon) {
|
||||
player.vibrations[0].clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigureVibration::SetAllVibrationDevices() {
|
||||
// Set vibration devices for all player indices including handheld
|
||||
for (std::size_t player_idx = 0; player_idx < NUM_PLAYERS + 1; ++player_idx) {
|
||||
SetVibrationDevices(player_idx);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigureVibration::changeEvent(QEvent* event) {
|
||||
if (event->type() == QEvent::LanguageChange) {
|
||||
RetranslateUI();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue