summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/register_core_types.cpp4
-rw-r--r--core/register_core_types.h1
-rw-r--r--editor/editor_settings_dialog.cpp5
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp79
-rw-r--r--editor/plugins/node_3d_editor_plugin.h3
-rw-r--r--main/main.cpp7
6 files changed, 55 insertions, 44 deletions
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 7ebffdb459..a4b6a589f3 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -316,11 +316,9 @@ void register_core_extensions() {
native_extension_manager->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_CORE);
}
-void unregister_core_extensions() {
+void unregister_core_types() {
native_extension_manager->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_CORE);
-}
-void unregister_core_types() {
memdelete(native_extension_manager);
memdelete(resource_uid);
diff --git a/core/register_core_types.h b/core/register_core_types.h
index dfb2d8ac80..0fd4e73c40 100644
--- a/core/register_core_types.h
+++ b/core/register_core_types.h
@@ -36,6 +36,5 @@ void register_core_settings();
void register_core_extensions();
void register_core_singletons();
void unregister_core_types();
-void unregister_core_extensions();
#endif // REGISTER_CORE_TYPES_H
diff --git a/editor/editor_settings_dialog.cpp b/editor/editor_settings_dialog.cpp
index 6a5ab91ba0..18324f9971 100644
--- a/editor/editor_settings_dialog.cpp
+++ b/editor/editor_settings_dialog.cpp
@@ -369,6 +369,11 @@ void EditorSettingsDialog::_update_shortcuts() {
Array events; // Need to get the list of events into an array so it can be set as metadata on the item.
Vector<String> event_strings;
+ // Skip non-builtin actions.
+ if (!InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().has(action_name)) {
+ continue;
+ }
+
List<Ref<InputEvent>> all_default_events = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(action_name).value();
List<Ref<InputEventKey>> key_default_events;
// Remove all non-key events from the defaults. Only check keys, since we are in the editor.
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 3d3738ad47..002c879cdc 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -32,6 +32,7 @@
#include "core/config/project_settings.h"
#include "core/input/input.h"
+#include "core/input/input_map.h"
#include "core/math/camera_matrix.h"
#include "core/math/math_funcs.h"
#include "core/os/keyboard.h"
@@ -2291,26 +2292,6 @@ Point2i Node3DEditorViewport::_get_warped_mouse_motion(const Ref<InputEventMouse
return relative;
}
-static bool is_shortcut_pressed(const String &p_path) {
- Ref<Shortcut> shortcut = ED_GET_SHORTCUT(p_path);
- if (shortcut.is_null()) {
- return false;
- }
-
- const Array shortcuts = shortcut->get_events();
- Ref<InputEventKey> k;
- if (shortcuts.size() > 0) {
- k = shortcuts.front();
- }
-
- if (k.is_null()) {
- return false;
- }
- const Input &input = *Input::get_singleton();
- Key keycode = k->get_keycode();
- return input.is_key_pressed(keycode);
-}
-
void Node3DEditorViewport::_update_freelook(real_t delta) {
if (!is_freelook_active()) {
return;
@@ -2340,31 +2321,34 @@ void Node3DEditorViewport::_update_freelook(real_t delta) {
Vector3 direction;
- if (is_shortcut_pressed("spatial_editor/freelook_left")) {
+ // Use actions from the inputmap, as this is the only way to reliably detect input in this method.
+ // See #54469 for more discussion and explanation.
+ Input *inp = Input::get_singleton();
+ if (inp->is_action_pressed("spatial_editor/freelook_left")) {
direction -= right;
}
- if (is_shortcut_pressed("spatial_editor/freelook_right")) {
+ if (inp->is_action_pressed("spatial_editor/freelook_right")) {
direction += right;
}
- if (is_shortcut_pressed("spatial_editor/freelook_forward")) {
+ if (inp->is_action_pressed("spatial_editor/freelook_forward")) {
direction += forward;
}
- if (is_shortcut_pressed("spatial_editor/freelook_backwards")) {
+ if (inp->is_action_pressed("spatial_editor/freelook_backwards")) {
direction -= forward;
}
- if (is_shortcut_pressed("spatial_editor/freelook_up")) {
+ if (inp->is_action_pressed("spatial_editor/freelook_up")) {
direction += up;
}
- if (is_shortcut_pressed("spatial_editor/freelook_down")) {
+ if (inp->is_action_pressed("spatial_editor/freelook_down")) {
direction -= up;
}
real_t speed = freelook_speed;
- if (is_shortcut_pressed("spatial_editor/freelook_speed_modifier")) {
+ if (inp->is_action_pressed("spatial_editor/freelook_speed_modifier")) {
speed *= 3.0;
}
- if (is_shortcut_pressed("spatial_editor/freelook_slow_modifier")) {
+ if (inp->is_action_pressed("spatial_editor/freelook_slow_modifier")) {
speed *= 0.333333;
}
@@ -4427,6 +4411,28 @@ void Node3DEditorViewport::finish_transform() {
surface->update();
}
+// 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);
+ 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), varray(sc, p_path));
+}
+
+// Update the action in the InputMap to the provided shortcut events.
+void Node3DEditorViewport::shortcut_changed_callback(const Ref<Shortcut> p_shortcut, const String &p_shortcut_path) {
+ InputMap *im = InputMap::get_singleton();
+ if (im->has_action(p_shortcut_path)) {
+ im->action_erase_events(p_shortcut_path);
+ } else {
+ im->add_action(p_shortcut_path);
+ }
+
+ for (int i = 0; i < p_shortcut->get_events().size(); i++) {
+ im->action_add_event(p_shortcut_path, p_shortcut->get_events()[i]);
+ }
+}
+
Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p_index) {
cpu_time_history_index = 0;
gpu_time_history_index = 0;
@@ -4586,14 +4592,15 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
view_menu->get_popup()->set_item_tooltip(shadeless_idx, unsupported_tooltip);
}
- ED_SHORTCUT("spatial_editor/freelook_left", TTR("Freelook Left"), Key::A);
- ED_SHORTCUT("spatial_editor/freelook_right", TTR("Freelook Right"), Key::D);
- ED_SHORTCUT("spatial_editor/freelook_forward", TTR("Freelook Forward"), Key::W);
- ED_SHORTCUT("spatial_editor/freelook_backwards", TTR("Freelook Backwards"), Key::S);
- ED_SHORTCUT("spatial_editor/freelook_up", TTR("Freelook Up"), Key::E);
- ED_SHORTCUT("spatial_editor/freelook_down", TTR("Freelook Down"), Key::Q);
- ED_SHORTCUT("spatial_editor/freelook_speed_modifier", TTR("Freelook Speed Modifier"), Key::SHIFT);
- ED_SHORTCUT("spatial_editor/freelook_slow_modifier", TTR("Freelook Slow Modifier"), Key::ALT);
+ 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_speed_modifier", TTR("Freelook Speed Modifier"), Key::SHIFT);
+ register_shortcut_action("spatial_editor/freelook_slow_modifier", TTR("Freelook Slow Modifier"), Key::ALT);
+
ED_SHORTCUT("spatial_editor/lock_transform_x", TTR("Lock Transformation to X axis"), Key::X);
ED_SHORTCUT("spatial_editor/lock_transform_y", TTR("Lock Transformation to Y axis"), Key::Y);
ED_SHORTCUT("spatial_editor/lock_transform_z", TTR("Lock Transformation to Z axis"), Key::Z);
diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h
index 9e92a1e9b3..48423d1c83 100644
--- a/editor/plugins/node_3d_editor_plugin.h
+++ b/editor/plugins/node_3d_editor_plugin.h
@@ -415,6 +415,9 @@ 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 shortcut_changed_callback(const Ref<Shortcut> p_shortcut, const String &p_shortcut_path);
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/main/main.cpp b/main/main.cpp
index f8877d0717..21199fe227 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -487,7 +487,6 @@ void Main::test_cleanup() {
}
unregister_core_driver_types();
- unregister_core_extensions();
unregister_core_types();
OS::get_singleton()->finalize_core();
@@ -555,7 +554,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
globals = memnew(ProjectSettings);
register_core_settings(); //here globals are present
- register_core_extensions(); // core extensions must be registered after core settings and before display
translation_server = memnew(TranslationServer);
performance = memnew(Performance);
@@ -636,6 +634,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
continue;
}
#endif
+
List<String>::Element *N = I->next();
if (I->get() == "-h" || I->get() == "--help" || I->get() == "/?") { // display help
@@ -1272,6 +1271,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
Logger::set_flush_stdout_on_print(ProjectSettings::get_singleton()->get("application/run/flush_stdout_on_print"));
OS::get_singleton()->set_cmdline(execpath, main_args);
+
+ register_core_extensions(); //before display
// possibly be worth changing the default from vulkan to something lower spec,
// for the project manager, depending on how smooth the fallback is.
GLOBAL_DEF_RST("rendering/driver/driver_name", "vulkan");
@@ -1528,7 +1529,6 @@ error:
}
unregister_core_driver_types();
- unregister_core_extensions();
unregister_core_types();
OS::get_singleton()->_cmdline.clear();
@@ -2888,7 +2888,6 @@ void Main::cleanup(bool p_force) {
memdelete(message_queue);
unregister_core_driver_types();
- unregister_core_extensions();
unregister_core_types();
OS::get_singleton()->finalize_core();