mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-20 03:24:49 +00:00
Initial implementation of controller color config (#2411)
This commit is contained in:
parent
ad43ba5ec7
commit
1cc9e0d37f
5 changed files with 73 additions and 10 deletions
|
@ -71,6 +71,8 @@ static bool rdocEnable = false;
|
|||
static s16 cursorState = HideCursorState::Idle;
|
||||
static int cursorHideTimeout = 5; // 5 seconds (default)
|
||||
static bool useUnifiedInputConfig = true;
|
||||
static bool overrideControllerColor = false;
|
||||
static int controllerCustomColorRGB[3] = {0, 0, 255};
|
||||
static bool separateupdatefolder = false;
|
||||
static bool compatibilityData = false;
|
||||
static bool checkCompatibilityOnStartup = false;
|
||||
|
@ -115,6 +117,24 @@ void SetUseUnifiedInputConfig(bool use) {
|
|||
useUnifiedInputConfig = use;
|
||||
}
|
||||
|
||||
bool GetOverrideControllerColor() {
|
||||
return overrideControllerColor;
|
||||
}
|
||||
|
||||
void SetOverrideControllerColor(bool enable) {
|
||||
overrideControllerColor = enable;
|
||||
}
|
||||
|
||||
int* GetControllerCustomColor() {
|
||||
return controllerCustomColorRGB;
|
||||
}
|
||||
|
||||
void SetControllerCustomColor(int r, int b, int g) {
|
||||
controllerCustomColorRGB[0] = r;
|
||||
controllerCustomColorRGB[1] = b;
|
||||
controllerCustomColorRGB[2] = g;
|
||||
}
|
||||
|
||||
std::string getTrophyKey() {
|
||||
return trophyKey;
|
||||
}
|
||||
|
@ -1046,6 +1066,8 @@ axis_right_y = axis_right_y
|
|||
# Range of deadzones: 1 (almost none) to 127 (max)
|
||||
analog_deadzone = leftjoystick, 2, 127
|
||||
analog_deadzone = rightjoystick, 2, 127
|
||||
|
||||
override_controller_color = false, 0, 0, 255
|
||||
)";
|
||||
}
|
||||
std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id) {
|
||||
|
|
|
@ -47,6 +47,10 @@ int getSpecialPadClass();
|
|||
bool getIsMotionControlsEnabled();
|
||||
bool GetUseUnifiedInputConfig();
|
||||
void SetUseUnifiedInputConfig(bool use);
|
||||
bool GetOverrideControllerColor();
|
||||
void SetOverrideControllerColor(bool enable);
|
||||
int* GetControllerCustomColor();
|
||||
void SetControllerCustomColor(int r, int b, int g);
|
||||
|
||||
u32 getScreenWidth();
|
||||
u32 getScreenHeight();
|
||||
|
|
|
@ -261,6 +261,7 @@ int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenP
|
|||
if (type != ORBIS_PAD_PORT_TYPE_STANDARD && type != ORBIS_PAD_PORT_TYPE_REMOTE_CONTROL)
|
||||
return ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
scePadResetLightBar(1);
|
||||
return 1; // dummy
|
||||
}
|
||||
|
||||
|
@ -412,7 +413,13 @@ int PS4_SYSV_ABI scePadReadStateExt() {
|
|||
}
|
||||
|
||||
int PS4_SYSV_ABI scePadResetLightBar(s32 handle) {
|
||||
LOG_ERROR(Lib_Pad, "(STUBBED) called");
|
||||
LOG_INFO(Lib_Pad, "(DUMMY) called");
|
||||
if (handle != 1) {
|
||||
return ORBIS_PAD_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
auto* controller = Common::Singleton<GameController>::Instance();
|
||||
int* rgb = Config::GetControllerCustomColor();
|
||||
controller->SetLightBarRGB(rgb[0], rgb[1], rgb[2]);
|
||||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
|
@ -472,6 +479,9 @@ int PS4_SYSV_ABI scePadSetForceIntercepted() {
|
|||
}
|
||||
|
||||
int PS4_SYSV_ABI scePadSetLightBar(s32 handle, const OrbisPadLightBarParam* pParam) {
|
||||
if (Config::GetOverrideControllerColor()) {
|
||||
return ORBIS_OK;
|
||||
}
|
||||
if (pParam != nullptr) {
|
||||
LOG_DEBUG(Lib_Pad, "called handle = {} rgb = {} {} {}", handle, pParam->r, pParam->g,
|
||||
pParam->b);
|
||||
|
|
|
@ -214,6 +214,9 @@ void ParseInputConfig(const std::string game_id = "") {
|
|||
lefttrigger_deadzone = {1, 127};
|
||||
righttrigger_deadzone = {1, 127};
|
||||
|
||||
Config::SetOverrideControllerColor(false);
|
||||
Config::SetControllerCustomColor(0, 0, 255);
|
||||
|
||||
int lineCount = 0;
|
||||
|
||||
std::ifstream file(config_file);
|
||||
|
@ -254,6 +257,14 @@ void ParseInputConfig(const std::string game_id = "") {
|
|||
std::string input_string = line.substr(equal_pos + 1);
|
||||
std::size_t comma_pos = input_string.find(',');
|
||||
|
||||
auto parseInt = [](const std::string& s) -> std::optional<int> {
|
||||
try {
|
||||
return std::stoi(s);
|
||||
} catch (...) {
|
||||
return std::nullopt;
|
||||
}
|
||||
};
|
||||
|
||||
if (output_string == "mouse_to_joystick") {
|
||||
if (input_string == "left") {
|
||||
SetMouseToJoystick(1);
|
||||
|
@ -307,14 +318,6 @@ void ParseInputConfig(const std::string game_id = "") {
|
|||
continue;
|
||||
}
|
||||
|
||||
auto parseInt = [](const std::string& s) -> std::optional<int> {
|
||||
try {
|
||||
return std::stoi(s);
|
||||
} catch (...) {
|
||||
return std::nullopt;
|
||||
}
|
||||
};
|
||||
|
||||
auto inner_deadzone = parseInt(inner_deadzone_str);
|
||||
auto outer_deadzone = parseInt(outer_deadzone_str);
|
||||
|
||||
|
@ -341,6 +344,29 @@ void ParseInputConfig(const std::string game_id = "") {
|
|||
lineCount, line);
|
||||
}
|
||||
continue;
|
||||
} else if (output_string == "override_controller_color") {
|
||||
std::stringstream ss(input_string);
|
||||
std::string enable, r_s, g_s, b_s;
|
||||
std::optional<int> r, g, b;
|
||||
if (!std::getline(ss, enable, ',') || !std::getline(ss, r_s, ',') ||
|
||||
!std::getline(ss, g_s, ',') || !std::getline(ss, b_s)) {
|
||||
LOG_WARNING(Input, "Malformed controller color config at line {}: \"{}\"",
|
||||
lineCount, line);
|
||||
continue;
|
||||
}
|
||||
r = parseInt(r_s);
|
||||
g = parseInt(g_s);
|
||||
b = parseInt(b_s);
|
||||
if (!r || !g || !b) {
|
||||
LOG_WARNING(Input, "Invalid RGB values at line {}: \"{}\", skipping line.",
|
||||
lineCount, line);
|
||||
continue;
|
||||
}
|
||||
Config::SetOverrideControllerColor(enable == "true");
|
||||
Config::SetControllerCustomColor(*r, *g, *b);
|
||||
LOG_DEBUG(Input, "Parsed color settings: {} {} {} {}",
|
||||
enable == "true" ? "override" : "no override", *r, *b, *g);
|
||||
continue;
|
||||
}
|
||||
|
||||
// normal cases
|
||||
|
|
|
@ -129,7 +129,8 @@ void SDLInputEngine::Init() {
|
|||
};
|
||||
}
|
||||
SDL_free(gamepads);
|
||||
SetLightBarRGB(0, 0, 255);
|
||||
int* rgb = Config::GetControllerCustomColor();
|
||||
SetLightBarRGB(rgb[0], rgb[1], rgb[2]);
|
||||
}
|
||||
|
||||
void SDLInputEngine::SetLightBarRGB(u8 r, u8 g, u8 b) {
|
||||
|
|
Loading…
Add table
Reference in a new issue