summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorMarc Gilleron <marc.gilleron@gmail.com>2017-07-23 02:02:18 +0200
committerMarc Gilleron <marc.gilleron@gmail.com>2017-07-23 02:13:08 +0200
commit9d970b11aea7cfbeed48eba0cb4138bd50b82eec (patch)
treecb5d56db131c94def0d80f9e23aeb61272f83c27 /editor
parentaa798ebf8fcc0a72c837c7daea63e6d9ef51ff30 (diff)
Added configurable modifier key to activate freelook
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_settings.cpp6
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp60
2 files changed, 37 insertions, 29 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index e653502c0e..755ac75180 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -30,7 +30,6 @@
#include "editor_settings.h"
#include "editor_node.h"
-#include "project_settings.h"
#include "io/compression.h"
#include "io/config_file.h"
#include "io/file_access_memory.h"
@@ -41,6 +40,7 @@
#include "os/file_access.h"
#include "os/keyboard.h"
#include "os/os.h"
+#include "project_settings.h"
#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
#include "scene/main/viewport.h"
@@ -638,6 +638,10 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
set("editors/3d/warped_mouse_panning", true);
set("editors/3d/freelook_base_speed", 1);
+
+ set("editors/3d/freelook_activation_modifier", 0);
+ hints["editors/3d/freelook_activation_modifier"] = PropertyInfo(Variant::INT, "editors/3d/freelook_activation_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
+
set("editors/3d/freelook_modifier_speed_factor", 5.0);
set("editors/2d/bone_width", 5);
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 8e6e92d48b..ef7ed5f7f6 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -36,9 +36,9 @@
#include "editor/editor_settings.h"
#include "editor/plugins/animation_player_editor_plugin.h"
#include "editor/spatial_editor_gizmos.h"
-#include "project_settings.h"
#include "os/keyboard.h"
#include "print_string.h"
+#include "project_settings.h"
#include "scene/3d/camera.h"
#include "scene/3d/visual_instance.h"
#include "scene/resources/surface_tool.h"
@@ -518,7 +518,7 @@ void SpatialEditorViewport::_compute_edit(const Point2 &p_point) {
*/
}
-static int _get_key_modifier(const String &p_property) {
+static int _get_key_modifier_setting(const String &p_property) {
switch (EditorSettings::get_singleton()->get(p_property).operator int()) {
@@ -531,6 +531,18 @@ static int _get_key_modifier(const String &p_property) {
return 0;
}
+static int _get_key_modifier(Ref<InputEventWithModifiers> e) {
+ if (e->get_shift())
+ return KEY_SHIFT;
+ if (e->get_alt())
+ return KEY_ALT;
+ if (e->get_control())
+ return KEY_CONTROL;
+ if (e->get_metakey())
+ return KEY_META;
+ return 0;
+}
+
bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only) {
if (!spatial_editor->is_gizmo_visible())
@@ -774,7 +786,15 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
set_message(TTR("Transform Aborted."), 3);
}
- freelook_active = b->is_pressed();
+ if (b->is_pressed()) {
+ int mod = _get_key_modifier(b);
+ if (mod == _get_key_modifier_setting("editors/3d/freelook_activation_modifier")) {
+ freelook_active = true;
+ }
+ } else {
+ freelook_active = false;
+ }
+
if (freelook_active && !surface->has_focus()) {
// Focus usually doesn't trigger on right-click, but in case of freelook it should,
// otherwise using keyboard navigation would misbehave
@@ -1297,7 +1317,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (nav_scheme == NAVIGATION_MAYA && m->get_alt()) {
nav_mode = NAVIGATION_ZOOM;
- } else {
+ } else if (freelook_active) {
nav_mode = NAVIGATION_LOOK;
}
@@ -1305,21 +1325,13 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (nav_scheme == NAVIGATION_GODOT) {
- int mod = 0;
- if (m->get_shift())
- mod = KEY_SHIFT;
- if (m->get_alt())
- mod = KEY_ALT;
- if (m->get_control())
- mod = KEY_CONTROL;
- if (m->get_metakey())
- mod = KEY_META;
+ int mod = _get_key_modifier(m);
- if (mod == _get_key_modifier("editors/3d/pan_modifier"))
+ if (mod == _get_key_modifier_setting("editors/3d/pan_modifier"))
nav_mode = NAVIGATION_PAN;
- else if (mod == _get_key_modifier("editors/3d/zoom_modifier"))
+ else if (mod == _get_key_modifier_setting("editors/3d/zoom_modifier"))
nav_mode = NAVIGATION_ZOOM;
- else if (mod == _get_key_modifier("editors/3d/orbit_modifier"))
+ else if (mod == _get_key_modifier_setting("editors/3d/orbit_modifier"))
nav_mode = NAVIGATION_ORBIT;
} else if (nav_scheme == NAVIGATION_MAYA) {
@@ -1329,22 +1341,14 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
} else if (EditorSettings::get_singleton()->get("editors/3d/emulate_3_button_mouse")) {
// Handle trackpad (no external mouse) use case
- int mod = 0;
- if (m->get_shift())
- mod = KEY_SHIFT;
- if (m->get_alt())
- mod = KEY_ALT;
- if (m->get_control())
- mod = KEY_CONTROL;
- if (m->get_metakey())
- mod = KEY_META;
+ int mod = _get_key_modifier(m);
if (mod) {
- if (mod == _get_key_modifier("editors/3d/pan_modifier"))
+ if (mod == _get_key_modifier_setting("editors/3d/pan_modifier"))
nav_mode = NAVIGATION_PAN;
- else if (mod == _get_key_modifier("editors/3d/zoom_modifier"))
+ else if (mod == _get_key_modifier_setting("editors/3d/zoom_modifier"))
nav_mode = NAVIGATION_ZOOM;
- else if (mod == _get_key_modifier("editors/3d/orbit_modifier"))
+ else if (mod == _get_key_modifier_setting("editors/3d/orbit_modifier"))
nav_mode = NAVIGATION_ORBIT;
}
}