Skip to content

Commit

Permalink
Expose InputMap.load_default() and have it fully reload default inp…
Browse files Browse the repository at this point in the history
…uts including editor-specific ones
  • Loading branch information
ryevdokimov committed Jan 8, 2025
1 parent 02e4605 commit 05f24ce
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
6 changes: 6 additions & 0 deletions core/input/input_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("action_get_events", "action"), &InputMap::_action_get_events);
ClassDB::bind_method(D_METHOD("event_is_action", "event", "action", "exact_match"), &InputMap::event_is_action, DEFVAL(false));
ClassDB::bind_method(D_METHOD("load_from_project_settings"), &InputMap::load_from_project_settings);
ClassDB::bind_method(D_METHOD("load_default"), &InputMap::load_default);

ADD_SIGNAL(MethodInfo("default_loaded"));
}

/**
Expand Down Expand Up @@ -839,6 +842,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins_with_featur
}

void InputMap::load_default() {
input_map.clear();
HashMap<String, List<Ref<InputEvent>>> builtins = get_builtins_with_feature_overrides_applied();

for (const KeyValue<String, List<Ref<InputEvent>>> &E : builtins) {
Expand All @@ -856,6 +860,8 @@ void InputMap::load_default() {
}
}
}

emit_signal("default_loaded");
}

InputMap::InputMap() {
Expand Down
13 changes: 13 additions & 0 deletions doc/classes/InputMap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
<description>
Returns [code]true[/code] if the [InputMap] has a registered action with the given name.
</description>
</method>
<method name="load_default">
<return type="void" />
<description>
Clears all [InputEventAction] in the [InputMap] and load it anew from default settings.
</description>
</method>
<method name="load_from_project_settings">
<return type="void" />
Expand All @@ -110,4 +116,11 @@
</description>
</method>
</methods>
<signals>
<signal name="default_loaded">
<description>
Emitted when the default [InputMap] has been loaded.
</description>
</signal>
</signals>
</class>
37 changes: 21 additions & 16 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5469,6 +5469,25 @@ void Node3DEditorViewport::_set_lock_view_rotation(bool p_lock_rotation) {
}
}

void Node3DEditorViewport::_load_viewport_inputs() {
// Registering with Key::NONE intentionally creates an empty Array.
register_shortcut_action("spatial_editor/viewport_orbit_modifier_1", TTRC("Viewport Orbit Modifier 1"), Key::NONE);
register_shortcut_action("spatial_editor/viewport_orbit_modifier_2", TTRC("Viewport Orbit Modifier 2"), Key::NONE);
register_shortcut_action("spatial_editor/viewport_pan_modifier_1", TTRC("Viewport Pan Modifier 1"), Key::SHIFT);
register_shortcut_action("spatial_editor/viewport_pan_modifier_2", TTRC("Viewport Pan Modifier 2"), Key::NONE);
register_shortcut_action("spatial_editor/viewport_zoom_modifier_1", TTRC("Viewport Zoom Modifier 1"), Key::SHIFT);
register_shortcut_action("spatial_editor/viewport_zoom_modifier_2", TTRC("Viewport Zoom Modifier 2"), Key::CTRL);

register_shortcut_action("spatial_editor/freelook_left", TTRC("Freelook Left"), Key::A, true);
register_shortcut_action("spatial_editor/freelook_right", TTRC("Freelook Right"), Key::D, true);
register_shortcut_action("spatial_editor/freelook_forward", TTRC("Freelook Forward"), Key::W, true);
register_shortcut_action("spatial_editor/freelook_backwards", TTRC("Freelook Backwards"), Key::S, true);
register_shortcut_action("spatial_editor/freelook_up", TTRC("Freelook Up"), Key::E, true);
register_shortcut_action("spatial_editor/freelook_down", TTRC("Freelook Down"), Key::Q, true);
register_shortcut_action("spatial_editor/freelook_speed_modifier", TTRC("Freelook Speed Modifier"), Key::SHIFT);
register_shortcut_action("spatial_editor/freelook_slow_modifier", TTRC("Freelook Slow Modifier"), Key::ALT);
}

Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p_index) {
cpu_time_history_index = 0;
gpu_time_history_index = 0;
Expand Down Expand Up @@ -5634,22 +5653,8 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
view_menu->get_popup()->set_item_tooltip(shadeless_idx, unsupported_tooltip);
}

// Registering with Key::NONE intentionally creates an empty Array.
register_shortcut_action("spatial_editor/viewport_orbit_modifier_1", TTRC("Viewport Orbit Modifier 1"), Key::NONE);
register_shortcut_action("spatial_editor/viewport_orbit_modifier_2", TTRC("Viewport Orbit Modifier 2"), Key::NONE);
register_shortcut_action("spatial_editor/viewport_pan_modifier_1", TTRC("Viewport Pan Modifier 1"), Key::SHIFT);
register_shortcut_action("spatial_editor/viewport_pan_modifier_2", TTRC("Viewport Pan Modifier 2"), Key::NONE);
register_shortcut_action("spatial_editor/viewport_zoom_modifier_1", TTRC("Viewport Zoom Modifier 1"), Key::SHIFT);
register_shortcut_action("spatial_editor/viewport_zoom_modifier_2", TTRC("Viewport Zoom Modifier 2"), Key::CTRL);

register_shortcut_action("spatial_editor/freelook_left", TTRC("Freelook Left"), Key::A, true);
register_shortcut_action("spatial_editor/freelook_right", TTRC("Freelook Right"), Key::D, true);
register_shortcut_action("spatial_editor/freelook_forward", TTRC("Freelook Forward"), Key::W, true);
register_shortcut_action("spatial_editor/freelook_backwards", TTRC("Freelook Backwards"), Key::S, true);
register_shortcut_action("spatial_editor/freelook_up", TTRC("Freelook Up"), Key::E, true);
register_shortcut_action("spatial_editor/freelook_down", TTRC("Freelook Down"), Key::Q, true);
register_shortcut_action("spatial_editor/freelook_speed_modifier", TTRC("Freelook Speed Modifier"), Key::SHIFT);
register_shortcut_action("spatial_editor/freelook_slow_modifier", TTRC("Freelook Slow Modifier"), Key::ALT);
_load_viewport_inputs();
InputMap::get_singleton()->connect("default_loaded", callable_mp(this, &Node3DEditorViewport::_load_viewport_inputs));

ED_SHORTCUT("spatial_editor/lock_transform_x", TTRC("Lock Transformation to X axis"), Key::X);
ED_SHORTCUT("spatial_editor/lock_transform_y", TTRC("Lock Transformation to Y axis"), Key::Y);
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/node_3d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ class Node3DEditorViewport : public Control {
void update_transform_numeric();
void finish_transform();

void _load_viewport_inputs();
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);

Expand Down

0 comments on commit 05f24ce

Please sign in to comment.