Skip to content

Commit

Permalink
Qt/Input: Introduce profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Dec 27, 2017
1 parent 8a3759f commit a123b26
Show file tree
Hide file tree
Showing 19 changed files with 867 additions and 592 deletions.
5 changes: 4 additions & 1 deletion rpcs3/Emu/Io/Null/NullPadHandler.h
Expand Up @@ -10,6 +10,10 @@ class NullPadHandler final : public PadHandlerBase
return true;
}

void init_config(pad_config* cfg, const std::string& name) override
{
}

std::vector<std::string> ListDevices() override
{
std::vector<std::string> nulllist;
Expand All @@ -25,5 +29,4 @@ class NullPadHandler final : public PadHandlerBase
void ThreadProc() override
{
}

};
59 changes: 55 additions & 4 deletions rpcs3/Emu/Io/PadHandler.h
Expand Up @@ -6,6 +6,7 @@
#include "stdafx.h"
#include "../../Utilities/Config.h"
#include "../../Utilities/types.h"
#include "Emu/System.h"

// TODO: HLE info (constants, structs, etc.) should not be available here

Expand Down Expand Up @@ -248,9 +249,53 @@ struct Pad
}
};

struct pad_config : cfg::node
struct player_config final : cfg::node
{
pad_handler def_handler = pad_handler::null;
player_config(node* owner, const std::string& name, pad_handler type) : cfg::node(owner, name), def_handler(type) {};

cfg::_enum<pad_handler> handler{ this, "Handler", def_handler };
cfg::string device{ this, "Device", handler.to_string() };
cfg::string profile{ this, "Profile", "Default Profile" };
};

struct input_config final : cfg::node
{
const std::string cfg_name = fs::get_config_dir() + "/config_input.yml";

player_config player1{ this, "Player 1 Input", pad_handler::keyboard };
player_config player2{ this, "Player 2 Input", pad_handler::null };
player_config player3{ this, "Player 3 Input", pad_handler::null };
player_config player4{ this, "Player 4 Input", pad_handler::null };
player_config player5{ this, "Player 5 Input", pad_handler::null };
player_config player6{ this, "Player 6 Input", pad_handler::null };
player_config player7{ this, "Player 7 Input", pad_handler::null };

player_config *player[7]{ &player1, &player2, &player3, &player4, &player5, &player6, &player7 }; // Thanks gcc!

bool load()
{
if (fs::file cfg_file{ cfg_name, fs::read })
{
return from_string(cfg_file.to_string());
}

return false;
}

void save()
{
fs::file(cfg_name, fs::rewrite).write(to_string());
}

bool exist()
{
return fs::is_file(cfg_name);
}
};

struct pad_config final : cfg::node
{
std::string cfg_type = "";
std::string cfg_name = "";

cfg::string ls_left { this, "Left Stick Left", "" };
Expand Down Expand Up @@ -314,6 +359,8 @@ struct pad_config : cfg::node
}
};

static input_config input_cfg;

class PadHandlerBase
{
protected:
Expand All @@ -327,7 +374,7 @@ class PadHandlerBase
bool b_has_deadzones = false;
bool b_has_rumble = false;
bool b_has_config = false;
pad_config m_pad_config;
std::array<pad_config, MAX_GAMEPADS> m_pad_configs;

template <typename T>
T lerp(T v0, T v1, T t) {
Expand Down Expand Up @@ -584,14 +631,17 @@ class PadHandlerBase
s32 vibration_max = 255;
u32 connected = 0;

pad_handler m_type = pad_handler::null;

virtual bool Init() { return true; };
virtual ~PadHandlerBase() = default;

//Does it have GUI Config?
bool has_config() { return b_has_config; };
bool has_rumble() { return b_has_rumble; };
bool has_deadzones() { return b_has_deadzones; };
pad_config* GetConfig() { return &m_pad_config; };
static std::string get_config_dir(pad_handler type) { return fs::get_config_dir() + "/InputConfigs/" + fmt::format("%s", type) + "/"; };
static std::string get_config_filename(const input_config& cfg, int i) { return fs::get_config_dir() + "/InputConfigs/" + cfg.player[i]->handler.to_string() + "/" + cfg.player[i]->profile.to_string() + ".yml"; };
//Sets window to config the controller(optional)
virtual void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) {};
virtual void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) {};
Expand All @@ -601,6 +651,7 @@ class PadHandlerBase
virtual void ThreadProc() = 0;
//Binds a Pad to a device
virtual bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) = 0;
virtual void init_config(pad_config* cfg, const std::string& name) = 0;

private:
virtual void TranslateButtonPress(u64 keyCode, bool& pressed, u16& val, bool ignore_threshold = false) {};
Expand Down

0 comments on commit a123b26

Please sign in to comment.