Merge pull request #4538 from valentinvanelslande/profiles

Add multiple input profile support
This commit is contained in:
Weiyi Wang 2019-01-17 22:32:24 -05:00 committed by GitHub
commit 95a57a2fe3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 518 additions and 280 deletions

View file

@ -59,13 +59,17 @@ DirectionState GetStickDirectionState(s16 circle_pad_x, s16 circle_pad_y) {
}
void Module::LoadInputDevices() {
std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
std::transform(Settings::values.current_input_profile.buttons.begin() +
Settings::NativeButton::BUTTON_HID_BEGIN,
Settings::values.current_input_profile.buttons.begin() +
Settings::NativeButton::BUTTON_HID_END,
buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
circle_pad = Input::CreateDevice<Input::AnalogDevice>(
Settings::values.analogs[Settings::NativeAnalog::CirclePad]);
motion_device = Input::CreateDevice<Input::MotionDevice>(Settings::values.motion_device);
touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device);
Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CirclePad]);
motion_device = Input::CreateDevice<Input::MotionDevice>(
Settings::values.current_input_profile.motion_device);
touch_device = Input::CreateDevice<Input::TouchDevice>(
Settings::values.current_input_profile.touch_device);
}
void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {

View file

@ -263,11 +263,11 @@ void ExtraHID::RequestInputDevicesReload() {
void ExtraHID::LoadInputDevices() {
zl = Input::CreateDevice<Input::ButtonDevice>(
Settings::values.buttons[Settings::NativeButton::ZL]);
Settings::values.current_input_profile.buttons[Settings::NativeButton::ZL]);
zr = Input::CreateDevice<Input::ButtonDevice>(
Settings::values.buttons[Settings::NativeButton::ZR]);
Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]);
c_stick = Input::CreateDevice<Input::AnalogDevice>(
Settings::values.analogs[Settings::NativeAnalog::CStick]);
Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CStick]);
}
} // namespace Service::IR

View file

@ -35,11 +35,11 @@ static_assert(sizeof(SharedMem) == 0x98, "SharedMem has wrong size!");
void IR_RST::LoadInputDevices() {
zl_button = Input::CreateDevice<Input::ButtonDevice>(
Settings::values.buttons[Settings::NativeButton::ZL]);
Settings::values.current_input_profile.buttons[Settings::NativeButton::ZL]);
zr_button = Input::CreateDevice<Input::ButtonDevice>(
Settings::values.buttons[Settings::NativeButton::ZR]);
Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]);
c_stick = Input::CreateDevice<Input::AnalogDevice>(
Settings::values.analogs[Settings::NativeAnalog::CStick]);
Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CStick]);
}
void IR_RST::UnloadInputDevices() {

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"
@ -101,4 +102,32 @@ void LogSettings() {
LogSetting("Debugging_GdbstubPort", Settings::values.gdbstub_port);
}
void LoadProfile(int index) {
Settings::values.current_input_profile = Settings::values.input_profiles[index];
Settings::values.current_input_profile_index = index;
}
void SaveProfile(int index) {
Settings::values.input_profiles[index] = Settings::values.current_input_profile;
}
void CreateProfile(std::string name) {
Settings::InputProfile profile = values.current_input_profile;
profile.name = std::move(name);
Settings::values.input_profiles.push_back(std::move(profile));
Settings::values.current_input_profile_index =
static_cast<int>(Settings::values.input_profiles.size()) - 1;
Settings::LoadProfile(Settings::values.current_input_profile_index);
}
void DeleteProfile(int index) {
Settings::values.input_profiles.erase(Settings::values.input_profiles.begin() + index);
Settings::LoadProfile(0);
}
void RenameCurrentProfile(std::string new_name) {
Settings::values.input_profiles[Settings::values.current_input_profile_index].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"
@ -96,11 +97,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;
@ -108,6 +106,16 @@ struct Values {
std::string udp_input_address;
u16 udp_input_port;
u8 udp_pad_index;
};
struct Values {
// CheckNew3DS
bool is_new_3ds;
// Controls
InputProfile current_input_profile; ///< The current input profile
int current_input_profile_index; ///< The current input profile index
std::vector<InputProfile> input_profiles; ///< The list of input profiles
// Core
bool use_cpu_jit;
@ -182,4 +190,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