diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-05-20 12:38:03 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-05-20 17:05:38 -0300 |
commit | 5b3709d3096df737b8bb2344446be818b0389bfe (patch) | |
tree | 649a0989b1494f3c4687d59e503310f4e6bbeb40 /modules/gridmap | |
parent | 93f9a83062dbe74474a4a7928758c5cf5588238e (diff) |
Removal of InputEvent as built-in Variant type..
this might cause bugs I haven't found yet..
Diffstat (limited to 'modules/gridmap')
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.cpp | 206 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.h | 4 |
2 files changed, 107 insertions, 103 deletions
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index d8993710a4..e567e08c79 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -508,146 +508,150 @@ void GridMapEditor::_duplicate_paste() { } } -bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { +bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { if (!node) { return false; } if (edit_mode->get_selected() == 0) { // regular click - switch (p_event.type) { - case InputEvent::MOUSE_BUTTON: { - if (p_event.mouse_button.button_index == BUTTON_WHEEL_UP && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { - if (p_event.mouse_button.pressed) - floor->set_value(floor->get_value() + p_event.mouse_button.factor); + Ref<InputEventMouseButton> mb = p_event; - return true; //eaten - } else if (p_event.mouse_button.button_index == BUTTON_WHEEL_DOWN && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { - if (p_event.mouse_button.pressed) - floor->set_value(floor->get_value() - p_event.mouse_button.factor); - return true; - } + if (mb.is_valid()) { - if (p_event.mouse_button.pressed) { + if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) { + if (mb->is_pressed()) + floor->set_value(floor->get_value() + mb->get_factor()); - if (p_event.mouse_button.button_index == BUTTON_LEFT) { + return true; //eaten + } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { + if (mb->is_pressed()) + floor->set_value(floor->get_value() - mb->get_factor()); + return true; + } - if (input_action == INPUT_DUPLICATE) { + if (mb->is_pressed()) { - //paste - _duplicate_paste(); - input_action = INPUT_NONE; - _update_duplicate_indicator(); - } else if (p_event.mouse_button.mod.shift) { - input_action = INPUT_SELECT; - } else if (p_event.mouse_button.mod.command) - input_action = INPUT_COPY; - else { - input_action = INPUT_PAINT; - set_items.clear(); - } - } else if (p_event.mouse_button.button_index == BUTTON_RIGHT) - if (input_action == INPUT_DUPLICATE) { - - input_action = INPUT_NONE; - _update_duplicate_indicator(); - } else { - input_action = INPUT_ERASE; - set_items.clear(); - } - else - return false; + if (mb->get_button_index() == BUTTON_LEFT) { - return do_input_action(p_camera, Point2(p_event.mouse_button.x, p_event.mouse_button.y), true); - } else { + if (input_action == INPUT_DUPLICATE) { - if ( - (p_event.mouse_button.button_index == BUTTON_RIGHT && input_action == INPUT_ERASE) || - (p_event.mouse_button.button_index == BUTTON_LEFT && input_action == INPUT_PAINT)) { + //paste + _duplicate_paste(); + input_action = INPUT_NONE; + _update_duplicate_indicator(); + } else if (mb->get_shift()) { + input_action = INPUT_SELECT; + } else if (mb->get_command()) + input_action = INPUT_COPY; + else { + input_action = INPUT_PAINT; + set_items.clear(); + } + } else if (mb->get_button_index() == BUTTON_RIGHT) + if (input_action == INPUT_DUPLICATE) { - if (set_items.size()) { - undo_redo->create_action("GridMap Paint"); - for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { + input_action = INPUT_NONE; + _update_duplicate_indicator(); + } else { + input_action = INPUT_ERASE; + set_items.clear(); + } + else + return false; + + return do_input_action(p_camera, Point2(mb->get_pos().x, mb->get_pos().y), true); + } else { - const SetItem &si = E->get(); - undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); - } - for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { + if ( + (mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || + (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) { - const SetItem &si = E->get(); - undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); - } + if (set_items.size()) { + undo_redo->create_action("GridMap Paint"); + for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { - undo_redo->commit_action(); + const SetItem &si = E->get(); + undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); } - set_items.clear(); - input_action = INPUT_NONE; - return true; - } + for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { - if (p_event.mouse_button.button_index == BUTTON_LEFT && input_action != INPUT_NONE) { + const SetItem &si = E->get(); + undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); + } - set_items.clear(); - input_action = INPUT_NONE; - return true; - } - if (p_event.mouse_button.button_index == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { - input_action = INPUT_NONE; - return true; + undo_redo->commit_action(); } + set_items.clear(); + input_action = INPUT_NONE; + return true; + } + + if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) { + + set_items.clear(); + input_action = INPUT_NONE; + return true; + } + if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { + input_action = INPUT_NONE; + return true; } - } break; - case InputEvent::MOUSE_MOTION: { + } + } + + Ref<InputEventMouseMotion> mm = p_event; - return do_input_action(p_camera, Point2(p_event.mouse_motion.x, p_event.mouse_motion.y), false); - } break; + if (mm.is_valid()) { + + return do_input_action(p_camera, mm->get_pos(), false); } } else if (edit_mode->get_selected() == 1) { //area mode, select an area - switch (p_event.type) { - case InputEvent::MOUSE_BUTTON: { + Ref<InputEventMouseButton> mb = p_event; - if (p_event.mouse_button.button_index == BUTTON_LEFT && p_event.mouse_button.pressed) { + if (mb.is_valid()) { - Point2 point = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y); + if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - Camera *camera = p_camera; - Vector3 from = camera->project_ray_origin(point); - Vector3 normal = camera->project_ray_normal(point); - Transform local_xform = node->get_global_transform().affine_inverse(); - from = local_xform.xform(from); - normal = local_xform.basis.xform(normal).normalized(); + Point2 point = mb->get_pos(); - List<int> areas; - node->get_area_list(&areas); + Camera *camera = p_camera; + Vector3 from = camera->project_ray_origin(point); + Vector3 normal = camera->project_ray_normal(point); + Transform local_xform = node->get_global_transform().affine_inverse(); + from = local_xform.xform(from); + normal = local_xform.basis.xform(normal).normalized(); - float min_d = 1e10; - int min_area = -1; + List<int> areas; + node->get_area_list(&areas); - for (List<int>::Element *E = areas.front(); E; E = E->next()) { + float min_d = 1e10; + int min_area = -1; - int area = E->get(); - Rect3 aabb = node->area_get_bounds(area); - aabb.pos *= node->get_cell_size(); - aabb.size *= node->get_cell_size(); + for (List<int>::Element *E = areas.front(); E; E = E->next()) { - Vector3 rclip, rnormal; - if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal)) - continue; + int area = E->get(); + Rect3 aabb = node->area_get_bounds(area); + aabb.pos *= node->get_cell_size(); + aabb.size *= node->get_cell_size(); - float d = normal.dot(rclip); - if (d < min_d) { - min_d = d; - min_area = area; - } - } + Vector3 rclip, rnormal; + if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal)) + continue; - selected_area = min_area; - update_areas(); + float d = normal.dot(rclip); + if (d < min_d) { + min_d = d; + min_area = area; + } } - } break; + + selected_area = min_area; + update_areas(); + } } } diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index d928e6afac..1572f4fbe5 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -220,7 +220,7 @@ protected: static void _bind_methods(); public: - bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event); + bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event); void edit(GridMap *p_gridmap); GridMapEditor() {} @@ -236,7 +236,7 @@ class GridMapEditorPlugin : public EditorPlugin { EditorNode *editor; public: - virtual bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); } + virtual bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); } virtual String get_name() const { return "GridMap"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); |