Merge pull request #44355 from EricEzaM/PR/fix-action-false-positives-and-allow-checking-exact-matches
Allow checking for exact matches with Action events.
This commit is contained in:
@ -44,31 +44,31 @@ int InputEvent::get_device() const {
|
||||
return device;
|
||||
}
|
||||
|
||||
bool InputEvent::is_action(const StringName &p_action) const {
|
||||
return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action);
|
||||
bool InputEvent::is_action(const StringName &p_action, bool p_exact_match) const {
|
||||
return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action, p_exact_match);
|
||||
}
|
||||
|
||||
bool InputEvent::is_action_pressed(const StringName &p_action, bool p_allow_echo) const {
|
||||
bool InputEvent::is_action_pressed(const StringName &p_action, bool p_allow_echo, bool p_exact_match) const {
|
||||
bool pressed;
|
||||
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
|
||||
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, p_exact_match, &pressed, nullptr, nullptr);
|
||||
return valid && pressed && (p_allow_echo || !is_echo());
|
||||
}
|
||||
|
||||
bool InputEvent::is_action_released(const StringName &p_action) const {
|
||||
bool InputEvent::is_action_released(const StringName &p_action, bool p_exact_match) const {
|
||||
bool pressed;
|
||||
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
|
||||
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, p_exact_match, &pressed, nullptr, nullptr);
|
||||
return valid && !pressed;
|
||||
}
|
||||
|
||||
float InputEvent::get_action_strength(const StringName &p_action) const {
|
||||
float InputEvent::get_action_strength(const StringName &p_action, bool p_exact_match) const {
|
||||
float strength;
|
||||
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, nullptr, &strength);
|
||||
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, p_exact_match, nullptr, &strength, nullptr);
|
||||
return valid ? strength : 0.0f;
|
||||
}
|
||||
|
||||
float InputEvent::get_action_raw_strength(const StringName &p_action) const {
|
||||
float InputEvent::get_action_raw_strength(const StringName &p_action, bool p_exact_match) const {
|
||||
float raw_strength;
|
||||
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, nullptr, nullptr, &raw_strength);
|
||||
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, p_exact_match, nullptr, nullptr, &raw_strength);
|
||||
return valid ? raw_strength : 0.0f;
|
||||
}
|
||||
|
||||
@ -100,10 +100,10 @@ void InputEvent::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
|
||||
ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("is_action", "action"), &InputEvent::is_action);
|
||||
ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "allow_echo"), &InputEvent::is_action_pressed, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("is_action_released", "action"), &InputEvent::is_action_released);
|
||||
ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &InputEvent::get_action_strength);
|
||||
ClassDB::bind_method(D_METHOD("is_action", "action", "exact_match"), &InputEvent::is_action, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "allow_echo", "exact_match"), &InputEvent::is_action_pressed, DEFVAL(false), DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("is_action_released", "action", "exact_match"), &InputEvent::is_action_released, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("get_action_strength", "action", "exact_match"), &InputEvent::get_action_strength, DEFVAL(false));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("is_pressed"), &InputEvent::is_pressed);
|
||||
ClassDB::bind_method(D_METHOD("is_echo"), &InputEvent::is_echo);
|
||||
|
||||
Reference in New Issue
Block a user