You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Rework input actions to be reliable
This commit is contained in:
@@ -127,16 +127,21 @@ List<StringName> InputMap::get_actions() const {
|
||||
return actions;
|
||||
}
|
||||
|
||||
List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
|
||||
List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const {
|
||||
ERR_FAIL_COND_V(!p_event.is_valid(), nullptr);
|
||||
|
||||
int i = 0;
|
||||
for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
|
||||
int device = E->get()->get_device();
|
||||
if (device == ALL_DEVICES || device == p_event->get_device()) {
|
||||
if (E->get()->action_match(p_event, p_exact_match, p_action.deadzone, r_pressed, r_strength, r_raw_strength)) {
|
||||
if (r_event_index) {
|
||||
*r_event_index = i;
|
||||
}
|
||||
return E;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@@ -179,6 +184,7 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve
|
||||
List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event, true);
|
||||
if (E) {
|
||||
input_map[p_action].inputs.erase(E);
|
||||
|
||||
if (Input::get_singleton()->is_action_pressed(p_action)) {
|
||||
Input::get_singleton()->action_release(p_action);
|
||||
}
|
||||
@@ -216,7 +222,13 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName
|
||||
return event_get_action_status(p_event, p_action, p_exact_match);
|
||||
}
|
||||
|
||||
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) const {
|
||||
int InputMap::event_get_index(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match) const {
|
||||
int index = -1;
|
||||
event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index);
|
||||
return index;
|
||||
}
|
||||
|
||||
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 {
|
||||
HashMap<StringName, Action>::Iterator E = input_map.find(p_action);
|
||||
ERR_FAIL_COND_V_MSG(!E, false, suggest_actions(p_action));
|
||||
|
||||
@@ -236,7 +248,7 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
|
||||
return input_event_action->get_action() == p_action;
|
||||
}
|
||||
|
||||
List<Ref<InputEvent>>::Element *event = _find_event(E->value, p_event, p_exact_match, r_pressed, r_strength, r_raw_strength);
|
||||
List<Ref<InputEvent>>::Element *event = _find_event(E->value, p_event, p_exact_match, r_pressed, r_strength, r_raw_strength, r_event_index);
|
||||
return event != nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user