mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 03:18:37 +08:00
Use physical shortcuts for freelook navigation in the editor
This commit is contained in:
parent
6cde3fac32
commit
52de40310a
@ -474,10 +474,15 @@ String InputEventKey::to_string() {
|
||||
return vformat("InputEventKey: keycode=%s, mods=%s, physical=%s, pressed=%s, echo=%s", kc, mods, physical, p, e);
|
||||
}
|
||||
|
||||
Ref<InputEventKey> InputEventKey::create_reference(Key p_keycode) {
|
||||
Ref<InputEventKey> InputEventKey::create_reference(Key p_keycode, bool p_physical) {
|
||||
Ref<InputEventKey> ie;
|
||||
ie.instantiate();
|
||||
ie->set_keycode(p_keycode & KeyModifierMask::CODE_MASK);
|
||||
if (p_physical) {
|
||||
ie->set_physical_keycode(p_keycode & KeyModifierMask::CODE_MASK);
|
||||
} else {
|
||||
ie->set_keycode(p_keycode & KeyModifierMask::CODE_MASK);
|
||||
}
|
||||
|
||||
ie->set_unicode(char32_t(p_keycode & KeyModifierMask::CODE_MASK));
|
||||
|
||||
if ((p_keycode & KeyModifierMask::SHIFT) != Key::NONE) {
|
||||
|
@ -195,7 +195,7 @@ public:
|
||||
virtual String as_text() const override;
|
||||
virtual String to_string() override;
|
||||
|
||||
static Ref<InputEventKey> create_reference(Key p_keycode_with_modifier_masks);
|
||||
static Ref<InputEventKey> create_reference(Key p_keycode_with_modifier_masks, bool p_physical = false);
|
||||
|
||||
InputEventKey() {}
|
||||
};
|
||||
|
@ -1452,7 +1452,7 @@ Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path) {
|
||||
return sc;
|
||||
}
|
||||
|
||||
void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode) {
|
||||
void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode, bool p_physical) {
|
||||
ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet.");
|
||||
|
||||
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
|
||||
@ -1461,10 +1461,10 @@ void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_k
|
||||
PackedInt32Array arr;
|
||||
arr.push_back((int32_t)p_keycode);
|
||||
|
||||
ED_SHORTCUT_OVERRIDE_ARRAY(p_path, p_feature, arr);
|
||||
ED_SHORTCUT_OVERRIDE_ARRAY(p_path, p_feature, arr, p_physical);
|
||||
}
|
||||
|
||||
void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes) {
|
||||
void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical) {
|
||||
ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet.");
|
||||
|
||||
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
|
||||
@ -1489,7 +1489,7 @@ void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, c
|
||||
|
||||
Ref<InputEventKey> ie;
|
||||
if (keycode != Key::NONE) {
|
||||
ie = InputEventKey::create_reference(keycode);
|
||||
ie = InputEventKey::create_reference(keycode, p_physical);
|
||||
events.push_back(ie);
|
||||
}
|
||||
}
|
||||
@ -1502,13 +1502,13 @@ void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, c
|
||||
sc->set_meta("original", events.duplicate(true));
|
||||
}
|
||||
|
||||
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode) {
|
||||
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode, bool p_physical) {
|
||||
PackedInt32Array arr;
|
||||
arr.push_back((int32_t)p_keycode);
|
||||
return ED_SHORTCUT_ARRAY(p_path, p_name, arr);
|
||||
return ED_SHORTCUT_ARRAY(p_path, p_name, arr, p_physical);
|
||||
}
|
||||
|
||||
Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes) {
|
||||
Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical) {
|
||||
Array events;
|
||||
|
||||
for (int i = 0; i < p_keycodes.size(); i++) {
|
||||
@ -1523,7 +1523,7 @@ Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, cons
|
||||
|
||||
Ref<InputEventKey> ie;
|
||||
if (keycode != Key::NONE) {
|
||||
ie = InputEventKey::create_reference(keycode);
|
||||
ie = InputEventKey::create_reference(keycode, p_physical);
|
||||
events.push_back(ie);
|
||||
}
|
||||
}
|
||||
|
@ -195,10 +195,10 @@ Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_re
|
||||
Variant _EDITOR_GET(const String &p_setting);
|
||||
|
||||
#define ED_IS_SHORTCUT(p_name, p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name, p_ev))
|
||||
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode = Key::NONE);
|
||||
Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes);
|
||||
void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode = Key::NONE);
|
||||
void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes);
|
||||
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode = Key::NONE, bool p_physical = false);
|
||||
Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical = false);
|
||||
void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode = Key::NONE, bool p_physical = false);
|
||||
void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical = false);
|
||||
Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path);
|
||||
|
||||
#endif // EDITOR_SETTINGS_H
|
||||
|
@ -4862,8 +4862,8 @@ void Node3DEditorViewport::finish_transform() {
|
||||
}
|
||||
|
||||
// Register a shortcut and also add it as an input action with the same events.
|
||||
void Node3DEditorViewport::register_shortcut_action(const String &p_path, const String &p_name, Key p_keycode) {
|
||||
Ref<Shortcut> sc = ED_SHORTCUT(p_path, p_name, p_keycode);
|
||||
void Node3DEditorViewport::register_shortcut_action(const String &p_path, const String &p_name, Key p_keycode, bool p_physical) {
|
||||
Ref<Shortcut> sc = ED_SHORTCUT(p_path, p_name, p_keycode, p_physical);
|
||||
shortcut_changed_callback(sc, p_path);
|
||||
// Connect to the change event on the shortcut so the input binding can be updated.
|
||||
sc->connect("changed", callable_mp(this, &Node3DEditorViewport::shortcut_changed_callback).bind(sc, p_path));
|
||||
@ -5044,12 +5044,12 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
|
||||
view_menu->get_popup()->set_item_tooltip(shadeless_idx, unsupported_tooltip);
|
||||
}
|
||||
|
||||
register_shortcut_action("spatial_editor/freelook_left", TTR("Freelook Left"), Key::A);
|
||||
register_shortcut_action("spatial_editor/freelook_right", TTR("Freelook Right"), Key::D);
|
||||
register_shortcut_action("spatial_editor/freelook_forward", TTR("Freelook Forward"), Key::W);
|
||||
register_shortcut_action("spatial_editor/freelook_backwards", TTR("Freelook Backwards"), Key::S);
|
||||
register_shortcut_action("spatial_editor/freelook_up", TTR("Freelook Up"), Key::E);
|
||||
register_shortcut_action("spatial_editor/freelook_down", TTR("Freelook Down"), Key::Q);
|
||||
register_shortcut_action("spatial_editor/freelook_left", TTR("Freelook Left"), Key::A, true);
|
||||
register_shortcut_action("spatial_editor/freelook_right", TTR("Freelook Right"), Key::D, true);
|
||||
register_shortcut_action("spatial_editor/freelook_forward", TTR("Freelook Forward"), Key::W, true);
|
||||
register_shortcut_action("spatial_editor/freelook_backwards", TTR("Freelook Backwards"), Key::S, true);
|
||||
register_shortcut_action("spatial_editor/freelook_up", TTR("Freelook Up"), Key::E, true);
|
||||
register_shortcut_action("spatial_editor/freelook_down", TTR("Freelook Down"), Key::Q, true);
|
||||
register_shortcut_action("spatial_editor/freelook_speed_modifier", TTR("Freelook Speed Modifier"), Key::SHIFT);
|
||||
register_shortcut_action("spatial_editor/freelook_slow_modifier", TTR("Freelook Slow Modifier"), Key::ALT);
|
||||
|
||||
|
@ -440,7 +440,7 @@ private:
|
||||
void update_transform(Point2 p_mousepos, bool p_shift);
|
||||
void finish_transform();
|
||||
|
||||
void register_shortcut_action(const String &p_path, const String &p_name, Key p_keycode);
|
||||
void register_shortcut_action(const String &p_path, const String &p_name, Key p_keycode, bool p_physical = false);
|
||||
void shortcut_changed_callback(const Ref<Shortcut> p_shortcut, const String &p_shortcut_path);
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user