Show last added action on Input Map and implement InputEvent "=="

This commit is contained in:
volzhs 2016-08-23 08:14:04 +09:00
parent 2cf781d3c6
commit 2e5a4cb5ca
4 changed files with 76 additions and 4 deletions

View file

@ -34,8 +34,52 @@
*/ */
bool InputEvent::operator==(const InputEvent &p_event) const { 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 { InputEvent::operator String() const {

View file

@ -3128,7 +3128,7 @@ void Tree::ensure_cursor_is_visible() {
int screenh=get_size().height-h_scroll->get_combined_minimum_size().height; int screenh=get_size().height-h_scroll->get_combined_minimum_size().height;
if (ofs+h>v_scroll->get_val()+screenh) 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()) else if (ofs < v_scroll->get_val())
v_scroll->set_val(ofs); v_scroll->set_val(ofs);
} }

View file

@ -245,7 +245,7 @@ void ProjectSettings::_device_input_add() {
undo_redo->add_undo_method(this,"_settings_changed"); undo_redo->add_undo_method(this,"_settings_changed");
undo_redo->commit_action(); 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->add_undo_method(this,"_settings_changed");
undo_redo->commit_action(); 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) { 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->add_button(0,get_icon("Remove","EditorIcons"),2);
action->set_metadata(0,i); action->set_metadata(0,i);
action->set_meta("__input", ie);
} }
} }
} }

View file

@ -111,7 +111,7 @@ class ProjectSettings : public AcceptDialog {
void _action_button_pressed(Object* p_obj, int p_column,int p_id); void _action_button_pressed(Object* p_obj, int p_column,int p_id);
void _wait_for_key(const InputEvent& p_event); void _wait_for_key(const InputEvent& p_event);
void _press_a_key_confirm(); void _press_a_key_confirm();
void _show_last_added(const InputEvent& p_event);
void _settings_prop_edited(const String& p_name); void _settings_prop_edited(const String& p_name);
void _settings_changed(); void _settings_changed();