[3.x] Fix action exact match
This commit is contained in:
parent
e00a6d2b71
commit
2232168ede
@ -136,9 +136,7 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re
|
|||||||
|
|
||||||
int device = e->get_device();
|
int device = e->get_device();
|
||||||
if (device == ALL_DEVICES || device == p_event->get_device()) {
|
if (device == ALL_DEVICES || device == p_event->get_device()) {
|
||||||
if (p_exact_match && e->shortcut_match(p_event)) {
|
if (e->action_match(p_event, p_exact_match, p_pressed, p_strength, p_raw_strength, p_action.deadzone)) {
|
||||||
return E;
|
|
||||||
} else if (!p_exact_match && e->action_match(p_event, p_pressed, p_strength, p_raw_strength, p_action.deadzone)) {
|
|
||||||
return E;
|
return E;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ String InputEvent::as_text() const {
|
|||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,25 +288,21 @@ String InputEventKey::as_text() const {
|
|||||||
return kc;
|
return kc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
||||||
Ref<InputEventKey> key = p_event;
|
Ref<InputEventKey> key = p_event;
|
||||||
if (key.is_null()) {
|
if (key.is_null()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool match = false;
|
bool match;
|
||||||
if (get_scancode() == 0) {
|
if (scancode != 0) {
|
||||||
uint32_t code = get_physical_scancode_with_modifiers();
|
match = scancode == key->scancode;
|
||||||
uint32_t event_code = key->get_physical_scancode_with_modifiers();
|
|
||||||
|
|
||||||
match = get_physical_scancode() == key->get_physical_scancode() && (!key->is_pressed() || (code & event_code) == code);
|
|
||||||
} else {
|
} else {
|
||||||
uint32_t code = get_scancode_with_modifiers();
|
match = physical_scancode == key->physical_scancode;
|
||||||
uint32_t event_code = key->get_scancode_with_modifiers();
|
}
|
||||||
|
if (p_exact_match) {
|
||||||
match = get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code);
|
match &= get_modifiers_mask() == key->get_modifiers_mask();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
bool pressed = key->is_pressed();
|
bool pressed = key->is_pressed();
|
||||||
if (p_pressed != nullptr) {
|
if (p_pressed != nullptr) {
|
||||||
@ -466,13 +462,16 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co
|
|||||||
return mb;
|
return mb;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
||||||
Ref<InputEventMouseButton> mb = p_event;
|
Ref<InputEventMouseButton> mb = p_event;
|
||||||
if (mb.is_null()) {
|
if (mb.is_null()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool match = mb->button_index == button_index;
|
bool match = mb->button_index == button_index;
|
||||||
|
if (p_exact_match) {
|
||||||
|
match &= get_modifiers_mask() == mb->get_modifiers_mask();
|
||||||
|
}
|
||||||
if (match) {
|
if (match) {
|
||||||
bool pressed = mb->is_pressed();
|
bool pressed = mb->is_pressed();
|
||||||
if (p_pressed != nullptr) {
|
if (p_pressed != nullptr) {
|
||||||
@ -730,13 +729,17 @@ bool InputEventJoypadMotion::is_pressed() const {
|
|||||||
return Math::abs(axis_value) >= 0.5f;
|
return Math::abs(axis_value) >= 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
||||||
Ref<InputEventJoypadMotion> jm = p_event;
|
Ref<InputEventJoypadMotion> jm = p_event;
|
||||||
if (jm.is_null()) {
|
if (jm.is_null()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
|
// Matches even if not in the same direction, but returns a "not pressed" event.
|
||||||
|
bool match = (axis == jm->axis);
|
||||||
|
if (p_exact_match) {
|
||||||
|
match &= (axis_value < 0) == (jm->axis_value < 0);
|
||||||
|
}
|
||||||
if (match) {
|
if (match) {
|
||||||
float jm_abs_axis_value = Math::abs(jm->get_axis_value());
|
float jm_abs_axis_value = Math::abs(jm->get_axis_value());
|
||||||
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
|
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
|
||||||
@ -819,7 +822,7 @@ float InputEventJoypadButton::get_pressure() const {
|
|||||||
return pressure;
|
return pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
||||||
Ref<InputEventJoypadButton> jb = p_event;
|
Ref<InputEventJoypadButton> jb = p_event;
|
||||||
if (jb.is_null()) {
|
if (jb.is_null()) {
|
||||||
return false;
|
return false;
|
||||||
@ -1059,7 +1062,7 @@ bool InputEventAction::is_action(const StringName &p_action) const {
|
|||||||
return action == p_action;
|
return action == p_action;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
||||||
Ref<InputEventAction> act = p_event;
|
Ref<InputEventAction> act = p_event;
|
||||||
if (act.is_null()) {
|
if (act.is_null()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -224,7 +224,7 @@ public:
|
|||||||
|
|
||||||
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
|
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
|
||||||
|
|
||||||
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
||||||
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
||||||
virtual bool is_action_type() const;
|
virtual bool is_action_type() const;
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ public:
|
|||||||
uint32_t get_scancode_with_modifiers() const;
|
uint32_t get_scancode_with_modifiers() const;
|
||||||
uint32_t get_physical_scancode_with_modifiers() const;
|
uint32_t get_physical_scancode_with_modifiers() const;
|
||||||
|
|
||||||
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
||||||
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
||||||
|
|
||||||
virtual bool is_action_type() const { return true; }
|
virtual bool is_action_type() const { return true; }
|
||||||
@ -371,7 +371,7 @@ public:
|
|||||||
bool is_doubleclick() const;
|
bool is_doubleclick() const;
|
||||||
|
|
||||||
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
|
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
|
||||||
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
||||||
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
||||||
|
|
||||||
virtual bool is_action_type() const { return true; }
|
virtual bool is_action_type() const { return true; }
|
||||||
@ -429,7 +429,7 @@ public:
|
|||||||
|
|
||||||
virtual bool is_pressed() const;
|
virtual bool is_pressed() const;
|
||||||
|
|
||||||
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
||||||
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
||||||
|
|
||||||
virtual bool is_action_type() const { return true; }
|
virtual bool is_action_type() const { return true; }
|
||||||
@ -457,7 +457,7 @@ public:
|
|||||||
void set_pressure(float p_pressure);
|
void set_pressure(float p_pressure);
|
||||||
float get_pressure() const;
|
float get_pressure() const;
|
||||||
|
|
||||||
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
||||||
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
||||||
|
|
||||||
virtual bool is_action_type() const { return true; }
|
virtual bool is_action_type() const { return true; }
|
||||||
@ -544,9 +544,9 @@ public:
|
|||||||
|
|
||||||
virtual bool is_action(const StringName &p_action) const;
|
virtual bool is_action(const StringName &p_action) const;
|
||||||
|
|
||||||
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
|
||||||
|
|
||||||
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
virtual bool shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
|
||||||
|
|
||||||
virtual bool is_action_type() const { return true; }
|
virtual bool is_action_type() const { return true; }
|
||||||
virtual String as_text() const;
|
virtual String as_text() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user