Fix shortcuts, make them visible again and work.
This commit is contained in:
parent
54815b9dde
commit
3f2cd75c6f
|
@ -89,6 +89,11 @@ bool InputEvent::action_match(const Ref<InputEvent> &p_event) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputEvent::is_action_type() const {
|
||||
|
||||
return false;
|
||||
|
@ -130,6 +135,7 @@ void InputEvent::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("action_match", "event:InputEvent"), &InputEvent::action_match);
|
||||
ClassDB::bind_method(D_METHOD("shortcut_match", "event:InputEvent"), &InputEvent::shortcut_match);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
|
||||
|
||||
|
@ -276,6 +282,27 @@ uint32_t InputEventKey::get_scancode_with_modifiers() const {
|
|||
return sc;
|
||||
}
|
||||
|
||||
String InputEventKey::as_text() const {
|
||||
|
||||
String kc = keycode_get_string(scancode);
|
||||
if (kc == String())
|
||||
return kc;
|
||||
|
||||
if (get_metakey()) {
|
||||
kc = "Meta+" + kc;
|
||||
}
|
||||
if (get_alt()) {
|
||||
kc = "Alt+" + kc;
|
||||
}
|
||||
if (get_shift()) {
|
||||
kc = "Shift+" + kc;
|
||||
}
|
||||
if (get_control()) {
|
||||
kc = "Ctrl+" + kc;
|
||||
}
|
||||
return kc;
|
||||
}
|
||||
|
||||
bool InputEventKey::action_match(const Ref<InputEvent> &p_event) const {
|
||||
|
||||
Ref<InputEventKey> key = p_event;
|
||||
|
@ -288,6 +315,18 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event) const {
|
|||
return get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code);
|
||||
}
|
||||
|
||||
bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
|
||||
|
||||
Ref<InputEventKey> key = p_event;
|
||||
if (key.is_null())
|
||||
return false;
|
||||
|
||||
uint32_t code = get_scancode_with_modifiers();
|
||||
uint32_t event_code = key->get_scancode_with_modifiers();
|
||||
|
||||
return code == event_code;
|
||||
}
|
||||
|
||||
void InputEventKey::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
|
||||
|
|
|
@ -165,6 +165,7 @@ public:
|
|||
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) const;
|
||||
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
|
||||
virtual bool is_action_type() const;
|
||||
|
||||
InputEvent();
|
||||
|
@ -243,9 +244,12 @@ public:
|
|||
uint32_t get_scancode_with_modifiers() const;
|
||||
|
||||
virtual bool action_match(const Ref<InputEvent> &p_event) const;
|
||||
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
|
||||
|
||||
virtual bool is_action_type() const { return true; }
|
||||
|
||||
virtual String as_text() const;
|
||||
|
||||
InputEventKey();
|
||||
};
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ Ref<InputEvent> ShortCut::get_shortcut() const {
|
|||
|
||||
bool ShortCut::is_shortcut(const Ref<InputEvent> &p_event) const {
|
||||
|
||||
return shortcut.is_valid() && shortcut->action_match(p_event);
|
||||
return shortcut.is_valid() && shortcut->shortcut_match(p_event);
|
||||
}
|
||||
|
||||
String ShortCut::get_as_text() const {
|
||||
|
|
Loading…
Reference in New Issue