ja permet mapejar botons tipo trigger
This commit is contained in:
@@ -72,6 +72,9 @@ void DefineButtons::handleEvents(const SDL_Event &event) {
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_UP:
|
||||
checkEnd();
|
||||
break;
|
||||
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
|
||||
doControllerAxisMotion(event.gaxis);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -86,6 +89,8 @@ auto DefineButtons::enable(Options::Gamepad *options_gamepad) -> bool {
|
||||
index_button_ = 0;
|
||||
message_shown_ = false;
|
||||
closing_ = false;
|
||||
l2_was_pressed_ = false;
|
||||
r2_was_pressed_ = false;
|
||||
clearButtons();
|
||||
updateWindowMessage();
|
||||
|
||||
@@ -104,6 +109,8 @@ void DefineButtons::disable() {
|
||||
finished_ = false;
|
||||
message_shown_ = false;
|
||||
closing_ = false;
|
||||
l2_was_pressed_ = false;
|
||||
r2_was_pressed_ = false;
|
||||
|
||||
if (window_message_) {
|
||||
window_message_->hide();
|
||||
@@ -125,6 +132,44 @@ void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event)
|
||||
}
|
||||
}
|
||||
|
||||
void DefineButtons::doControllerAxisMotion(const SDL_GamepadAxisEvent &event) {
|
||||
auto gamepad = input_->getGamepad(event.which);
|
||||
|
||||
if (!gamepad || gamepad != options_gamepad_->instance) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Solo manejamos L2 y R2 como botones con lógica de transición
|
||||
if (event.axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER) {
|
||||
bool l2_is_pressed_now = event.value > 16384;
|
||||
|
||||
// Solo actuar en la transición de no presionado a presionado
|
||||
if (l2_is_pressed_now && !l2_was_pressed_) {
|
||||
const auto TRIGGER_BUTTON = Input::TRIGGER_L2_AS_BUTTON;
|
||||
if (checkTriggerNotInUse(TRIGGER_BUTTON)) {
|
||||
buttons_.at(index_button_).button = TRIGGER_BUTTON;
|
||||
incIndexButton();
|
||||
updateWindowMessage();
|
||||
}
|
||||
}
|
||||
l2_was_pressed_ = l2_is_pressed_now;
|
||||
|
||||
} else if (event.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) {
|
||||
bool r2_is_pressed_now = event.value > 16384;
|
||||
|
||||
// Solo actuar en la transición de no presionado a presionado
|
||||
if (r2_is_pressed_now && !r2_was_pressed_) {
|
||||
const auto TRIGGER_BUTTON = Input::TRIGGER_R2_AS_BUTTON;
|
||||
if (checkTriggerNotInUse(TRIGGER_BUTTON)) {
|
||||
buttons_.at(index_button_).button = TRIGGER_BUTTON;
|
||||
incIndexButton();
|
||||
updateWindowMessage();
|
||||
}
|
||||
}
|
||||
r2_was_pressed_ = r2_is_pressed_now;
|
||||
}
|
||||
}
|
||||
|
||||
void DefineButtons::bindButtons(Options::Gamepad *options_gamepad) {
|
||||
for (const auto &button : buttons_) {
|
||||
Input::bindGameControllerButton(options_gamepad->instance, button.action, button.button);
|
||||
@@ -148,6 +193,12 @@ auto DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) -> bool {
|
||||
});
|
||||
}
|
||||
|
||||
auto DefineButtons::checkTriggerNotInUse(SDL_GamepadButton trigger_button) -> bool {
|
||||
return std::ranges::all_of(buttons_, [trigger_button](const auto &b) {
|
||||
return b.button != trigger_button;
|
||||
});
|
||||
}
|
||||
|
||||
void DefineButtons::clearButtons() {
|
||||
buttons_.clear();
|
||||
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_LEFT"), Input::Action::FIRE_LEFT, SDL_GAMEPAD_BUTTON_INVALID);
|
||||
|
||||
Reference in New Issue
Block a user