From 265715f5b20e563832f21ac2e2197961d01e4028 Mon Sep 17 00:00:00 2001 From: volzhs Date: Tue, 23 Aug 2016 08:14:04 +0900 Subject: [PATCH] Show last added action on Input Map and implement InputEvent "==" (cherry picked from commit 2e5a4cb5ca33576ea81601f949b2e633ff92213c) --- core/os/input_event.cpp | 46 ++++++++++++++++++++++++++++++- scene/gui/tree.cpp | 2 +- tools/editor/project_settings.cpp | 30 +++++++++++++++++++- tools/editor/project_settings.h | 2 +- 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 8c79657c641..f4a6de0e967 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -34,8 +34,52 @@ */ bool InputEvent::operator==(const InputEvent &p_event) const { + if (type != p_event.type){ + return false; + } - return true; + switch(type) { + case KEY: + return key.unicode == p_event.key.unicode + && key.scancode == p_event.key.scancode + && key.echo == p_event.key.echo + && key.pressed == p_event.key.pressed + && key.mod == p_event.key.mod; + case MOUSE_MOTION: + return mouse_motion.x == p_event.mouse_motion.x + && mouse_motion.y == p_event.mouse_motion.y + && mouse_motion.relative_x == p_event.mouse_motion.relative_y + && mouse_motion.button_mask == p_event.mouse_motion.button_mask + && key.mod == p_event.key.mod; + case MOUSE_BUTTON: + return mouse_button.pressed == p_event.mouse_button.pressed + && mouse_button.x == p_event.mouse_button.x + && mouse_button.y == p_event.mouse_button.y + && mouse_button.button_index == p_event.mouse_button.button_index + && mouse_button.button_mask == p_event.mouse_button.button_mask + && key.mod == p_event.key.mod; + case JOYSTICK_MOTION: + return joy_motion.axis == p_event.joy_motion.axis + && joy_motion.axis_value == p_event.joy_motion.axis_value; + case JOYSTICK_BUTTON: + return joy_button.pressed == p_event.joy_button.pressed + && joy_button.button_index == p_event.joy_button.button_index + && joy_button.pressure == p_event.joy_button.pressure; + case SCREEN_TOUCH: + return screen_touch.pressed == p_event.screen_touch.pressed + && screen_touch.index == p_event.screen_touch.index + && screen_touch.x == p_event.screen_touch.x + && screen_touch.y == p_event.screen_touch.y; + case SCREEN_DRAG: + return screen_drag.index == p_event.screen_drag.index + && screen_drag.x == p_event.screen_drag.x + && screen_drag.y == p_event.screen_drag.y; + case ACTION: + return action.action == p_event.action.action + && action.pressed == p_event.action.pressed; + } + + return false; } InputEvent::operator String() const { diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index c631451ed55..76c133b0b98 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -3129,7 +3129,7 @@ void Tree::ensure_cursor_is_visible() { int screenh=get_size().height-h_scroll->get_combined_minimum_size().height; if (ofs+h>v_scroll->get_val()+screenh) - v_scroll->set_val(ofs-screenh+h); + v_scroll->call_deferred("set_val", ofs-screenh+h); else if (ofs < v_scroll->get_val()) v_scroll->set_val(ofs); } diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index 03eec960d27..02d95abfa21 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -245,7 +245,7 @@ void ProjectSettings::_device_input_add() { undo_redo->add_undo_method(this,"_settings_changed"); undo_redo->commit_action(); - + _show_last_added(ie); } @@ -283,7 +283,34 @@ void ProjectSettings::_press_a_key_confirm() { undo_redo->add_undo_method(this,"_settings_changed"); undo_redo->commit_action(); + _show_last_added(ie); +} +void ProjectSettings::_show_last_added(const InputEvent& p_event) { + TreeItem *r = input_editor->get_root(); + + if (!r) + return; + r=r->get_children(); + if (!r) + return; + bool found = false; + while(r){ + TreeItem *child = r->get_children(); + while(child){ + Variant input = child->get_meta("__input"); + if (p_event==input){ + child->select(0); + found = true; + break; + } + child=child->get_next(); + } + if (found) break; + r=r->get_next(); + } + + if (found) input_editor->ensure_cursor_is_visible(); } void ProjectSettings::_wait_for_key(const InputEvent& p_event) { @@ -543,6 +570,7 @@ void ProjectSettings::_update_actions() { } action->add_button(0,get_icon("Remove","EditorIcons"),2); action->set_metadata(0,i); + action->set_meta("__input", ie); } } } diff --git a/tools/editor/project_settings.h b/tools/editor/project_settings.h index 46e98f69ad6..61ad094d005 100644 --- a/tools/editor/project_settings.h +++ b/tools/editor/project_settings.h @@ -111,7 +111,7 @@ class ProjectSettings : public AcceptDialog { void _action_button_pressed(Object* p_obj, int p_column,int p_id); void _wait_for_key(const InputEvent& p_event); void _press_a_key_confirm(); - + void _show_last_added(const InputEvent& p_event); void _settings_prop_edited(const String& p_name); void _settings_changed();