mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 13:44:58 +00:00
feat: Update gamepad input bindings for consistency and add logging in input service
This commit is contained in:
@@ -26,25 +26,25 @@
|
||||
"gamepad_move_y_axis": "lefty",
|
||||
"gamepad_look_x_axis": "rightx",
|
||||
"gamepad_look_y_axis": "righty",
|
||||
"gamepad_dpad_up": "dpad_up",
|
||||
"gamepad_dpad_down": "dpad_down",
|
||||
"gamepad_dpad_left": "dpad_left",
|
||||
"gamepad_dpad_right": "dpad_right",
|
||||
"gamepad_dpad_up": "dpup",
|
||||
"gamepad_dpad_down": "dpdown",
|
||||
"gamepad_dpad_left": "dpleft",
|
||||
"gamepad_dpad_right": "dpright",
|
||||
"gamepad_button_actions": {
|
||||
"south": "gamepad_a",
|
||||
"east": "gamepad_b",
|
||||
"west": "gamepad_x",
|
||||
"north": "gamepad_y",
|
||||
"left_shoulder": "gamepad_lb",
|
||||
"right_shoulder": "gamepad_rb",
|
||||
"left_stick": "gamepad_ls",
|
||||
"right_stick": "gamepad_rs",
|
||||
"a": "gamepad_a",
|
||||
"b": "gamepad_b",
|
||||
"x": "gamepad_x",
|
||||
"y": "gamepad_y",
|
||||
"leftshoulder": "gamepad_lb",
|
||||
"rightshoulder": "gamepad_rb",
|
||||
"leftstick": "gamepad_ls",
|
||||
"rightstick": "gamepad_rs",
|
||||
"back": "gamepad_back",
|
||||
"start": "gamepad_start"
|
||||
},
|
||||
"gamepad_axis_actions": {
|
||||
"left_trigger": "gamepad_lt",
|
||||
"right_trigger": "gamepad_rt"
|
||||
"lefttrigger": "gamepad_lt",
|
||||
"righttrigger": "gamepad_rt"
|
||||
},
|
||||
"gamepad_axis_action_threshold": 0.5
|
||||
},
|
||||
|
||||
@@ -45,6 +45,13 @@ local function rectContains(rect, x, y)
|
||||
return x >= rect.x and x <= rect.x + rect.width and y >= rect.y and y <= rect.y + rect.height
|
||||
end
|
||||
|
||||
local function log_trace(fmt, ...)
|
||||
if not lua_debug or not fmt then
|
||||
return
|
||||
end
|
||||
print(string.format(fmt, ...))
|
||||
end
|
||||
|
||||
local InputState = {}
|
||||
InputState.__index = InputState
|
||||
|
||||
@@ -382,7 +389,8 @@ function Gui.textbox(context, widgetId, rectDef, state, opts)
|
||||
end
|
||||
if context.input:isKeyDown("end") then
|
||||
state.cursor = #state.text
|
||||
context.input.keys.end = false
|
||||
context.input.keys["end"] = false
|
||||
log_trace("Textbox end key pressed, cursor=%d text_len=%d", state.cursor, #state.text)
|
||||
end
|
||||
if context.input:isKeyDown("enter") then
|
||||
if opts.onSubmit then
|
||||
|
||||
@@ -330,6 +330,12 @@ void SdlInputService::BuildActionKeyMapping() {
|
||||
SDL_GamepadButton button = SDL_GetGamepadButtonFromString(normalized.c_str());
|
||||
if (button != SDL_GAMEPAD_BUTTON_INVALID) {
|
||||
target = button;
|
||||
if (logger_) {
|
||||
logger_->Trace("SdlInputService", "BuildActionKeyMapping",
|
||||
"gamepadButton=" + std::string(bindingName) +
|
||||
", value=" + buttonValue +
|
||||
", buttonCode=" + std::to_string(static_cast<int>(button)));
|
||||
}
|
||||
} else if (logger_) {
|
||||
logger_->Error("SdlInputService: unknown gamepad button binding for " +
|
||||
std::string(bindingName) + " -> " + buttonValue);
|
||||
@@ -350,6 +356,12 @@ void SdlInputService::BuildActionKeyMapping() {
|
||||
SDL_GamepadAxis axis = SDL_GetGamepadAxisFromString(normalized.c_str());
|
||||
if (axis != SDL_GAMEPAD_AXIS_INVALID) {
|
||||
target = axis;
|
||||
if (logger_) {
|
||||
logger_->Trace("SdlInputService", "BuildActionKeyMapping",
|
||||
"gamepadAxis=" + std::string(axisName) +
|
||||
", value=" + axisValue +
|
||||
", axisCode=" + std::to_string(static_cast<int>(axis)));
|
||||
}
|
||||
} else if (logger_) {
|
||||
logger_->Error("SdlInputService: unknown gamepad axis binding for " +
|
||||
std::string(axisName) + " -> " + axisValue);
|
||||
@@ -375,6 +387,12 @@ void SdlInputService::BuildActionKeyMapping() {
|
||||
continue;
|
||||
}
|
||||
gamepadButtonActions_[button] = actionName;
|
||||
if (logger_) {
|
||||
logger_->Trace("SdlInputService", "BuildActionKeyMapping",
|
||||
"gamepadButtonAction=" + buttonName +
|
||||
", action=" + actionName +
|
||||
", buttonCode=" + std::to_string(static_cast<int>(button)));
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& [axisName, actionName] : bindings.gamepadAxisActions) {
|
||||
@@ -391,6 +409,12 @@ void SdlInputService::BuildActionKeyMapping() {
|
||||
continue;
|
||||
}
|
||||
gamepadAxisActions_[axis] = actionName;
|
||||
if (logger_) {
|
||||
logger_->Trace("SdlInputService", "BuildActionKeyMapping",
|
||||
"gamepadAxisAction=" + axisName +
|
||||
", action=" + actionName +
|
||||
", axisCode=" + std::to_string(static_cast<int>(axis)));
|
||||
}
|
||||
}
|
||||
|
||||
gamepadAxisActionThreshold_ = bindings.gamepadAxisActionThreshold;
|
||||
|
||||
@@ -23,25 +23,25 @@ struct InputBindings {
|
||||
std::string gamepadMoveYAxis = "lefty";
|
||||
std::string gamepadLookXAxis = "rightx";
|
||||
std::string gamepadLookYAxis = "righty";
|
||||
std::string gamepadDpadUpButton = "dpad_up";
|
||||
std::string gamepadDpadDownButton = "dpad_down";
|
||||
std::string gamepadDpadLeftButton = "dpad_left";
|
||||
std::string gamepadDpadRightButton = "dpad_right";
|
||||
std::string gamepadDpadUpButton = "dpup";
|
||||
std::string gamepadDpadDownButton = "dpdown";
|
||||
std::string gamepadDpadLeftButton = "dpleft";
|
||||
std::string gamepadDpadRightButton = "dpright";
|
||||
std::unordered_map<std::string, std::string> gamepadButtonActions = {
|
||||
{"south", "gamepad_a"},
|
||||
{"east", "gamepad_b"},
|
||||
{"west", "gamepad_x"},
|
||||
{"north", "gamepad_y"},
|
||||
{"left_shoulder", "gamepad_lb"},
|
||||
{"right_shoulder", "gamepad_rb"},
|
||||
{"left_stick", "gamepad_ls"},
|
||||
{"right_stick", "gamepad_rs"},
|
||||
{"a", "gamepad_a"},
|
||||
{"b", "gamepad_b"},
|
||||
{"x", "gamepad_x"},
|
||||
{"y", "gamepad_y"},
|
||||
{"leftshoulder", "gamepad_lb"},
|
||||
{"rightshoulder", "gamepad_rb"},
|
||||
{"leftstick", "gamepad_ls"},
|
||||
{"rightstick", "gamepad_rs"},
|
||||
{"back", "gamepad_back"},
|
||||
{"start", "gamepad_start"}
|
||||
};
|
||||
std::unordered_map<std::string, std::string> gamepadAxisActions = {
|
||||
{"left_trigger", "gamepad_lt"},
|
||||
{"right_trigger", "gamepad_rt"}
|
||||
{"lefttrigger", "gamepad_lt"},
|
||||
{"righttrigger", "gamepad_rt"}
|
||||
};
|
||||
float gamepadAxisActionThreshold = 0.5f;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user