1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-15 13:51:40 +00:00

Fix InputMap::event_get_index to handle unmatched events correctly

This commit is contained in:
mosquito chang
2024-08-18 14:46:34 +02:00
parent 1bd740d18d
commit b32395ade9

View File

@@ -253,8 +253,8 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName
int InputMap::event_get_index(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match) const { int InputMap::event_get_index(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match) const {
int index = -1; int index = -1;
event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index); bool valid = event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index);
return index; return valid ? index : -1;
} }
bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const { bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const {