Add multiple input profile support

Only supported in the Qt frontend.
This commit is contained in:
Valentin Vanelslande 2018-12-28 19:24:56 -05:00
parent 3989c17cb0
commit 7c95032e3a
10 changed files with 415 additions and 165 deletions

View file

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <utility>
#include "audio_core/dsp_interface.h"
#include "core/core.h"
#include "core/gdbstub/gdbstub.h"
@ -99,4 +100,51 @@ void LogSettings() {
LogSetting("Debugging_GdbstubPort", Settings::values.gdbstub_port);
}
void LoadProfile(int index) {
const auto& profile = values.profiles[index];
values.profile = index;
values.analogs = profile.analogs;
values.buttons = profile.buttons;
values.motion_device = profile.motion_device;
values.touch_device = profile.touch_device;
values.udp_input_address = profile.udp_input_address;
values.udp_input_port = profile.udp_input_port;
values.udp_pad_index = profile.udp_pad_index;
}
void SaveProfile(int index) {
auto& profile = values.profiles[index];
profile.analogs = values.analogs;
profile.buttons = values.buttons;
profile.motion_device = values.motion_device;
profile.touch_device = values.touch_device;
profile.udp_input_address = values.udp_input_address;
profile.udp_input_port = values.udp_input_port;
profile.udp_pad_index = values.udp_pad_index;
}
void CreateProfile(std::string name) {
InputProfile profile;
profile.name = std::move(name);
profile.analogs = values.analogs;
profile.buttons = values.buttons;
profile.motion_device = values.motion_device;
profile.touch_device = values.touch_device;
profile.udp_input_address = values.udp_input_address;
profile.udp_input_port = values.udp_input_port;
profile.udp_pad_index = values.udp_pad_index;
values.profiles.push_back(profile);
values.profile = static_cast<int>(values.profiles.size()) - 1;
LoadProfile(values.profile);
}
void DeleteProfile(int index) {
values.profiles.erase(values.profiles.begin() + index);
LoadProfile(0);
}
void RenameCurrentProfile(std::string new_name) {
values.profiles[values.profile].name = std::move(new_name);
}
} // namespace Settings

View file

@ -7,6 +7,7 @@
#include <array>
#include <string>
#include <unordered_map>
#include <vector>
#include "common/common_types.h"
#include "core/hle/service/cam/cam.h"
@ -92,11 +93,8 @@ static const std::array<const char*, NumAnalogs> mapping = {{
}};
} // namespace NativeAnalog
struct Values {
// CheckNew3DS
bool is_new_3ds;
// Controls
struct InputProfile {
std::string name;
std::array<std::string, NativeButton::NumButtons> buttons;
std::array<std::string, NativeAnalog::NumAnalogs> analogs;
std::string motion_device;
@ -104,6 +102,23 @@ struct Values {
std::string udp_input_address;
u16 udp_input_port;
u8 udp_pad_index;
};
struct Values {
// CheckNew3DS
bool is_new_3ds;
// Current controls
std::array<std::string, NativeButton::NumButtons> buttons;
std::array<std::string, NativeAnalog::NumAnalogs> analogs;
std::string motion_device;
std::string touch_device;
std::string udp_input_address;
u16 udp_input_port;
u8 udp_pad_index;
int profile; ///< The current input profile index
std::vector<InputProfile> profiles; ///< The list of input profiles
// Core
bool use_cpu_jit;
@ -176,4 +191,11 @@ static constexpr int REGION_VALUE_AUTO_SELECT = -1;
void Apply();
void LogSettings();
// input profiles
void LoadProfile(int index);
void SaveProfile(int index);
void CreateProfile(std::string name);
void DeleteProfile(int index);
void RenameCurrentProfile(std::string new_name);
} // namespace Settings