diff options
-rw-r--r-- | editor/plugins/path_2d_editor_plugin.cpp | 138 | ||||
-rw-r--r-- | scene/3d/vehicle_body.cpp | 18 | ||||
-rw-r--r-- | scene/3d/vehicle_body.h | 5 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 2 |
4 files changed, 77 insertions, 86 deletions
diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 38a2a0c462..f8d250334c 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -59,7 +59,6 @@ void Path2DEditor::_node_removed(Node *p_node) { } bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - if (!node) return false; @@ -76,11 +75,12 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = mb->get_pos(); - Vector2 cpoint = !mb->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); - //first check if a point is to be added (segment split) - real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + Vector2 cpoint = + !mb->get_alt() ? + canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : + node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); - // Test move point!! + real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); if (mb->is_pressed() && action == ACTION_NONE) { @@ -88,23 +88,43 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { for (int i = 0; i < curve->get_point_count(); i++) { - bool pointunder = false; - real_t dist_to_p = gpoint.distance_to(xform.xform(curve->get_point_pos(i))); real_t dist_to_p_out = gpoint.distance_to(xform.xform(curve->get_point_pos(i) + curve->get_point_out(i))); real_t dist_to_p_in = gpoint.distance_to(xform.xform(curve->get_point_pos(i) + curve->get_point_in(i))); - if (mb->get_button_index() == BUTTON_LEFT && !mb->get_shift() && mode == MODE_EDIT) { - if (dist_to_p < grab_threshold) { + // Check for point movement start (for point + in/out controls). + if (mb->get_button_index() == BUTTON_LEFT) { + if (!mb->get_shift() && mode == MODE_EDIT) { + // Point can only be moved in edit mode. + if (dist_to_p < grab_threshold) { - action = ACTION_MOVING_POINT; - action_point = i; - moving_from = curve->get_point_pos(i); - moving_screen_from = gpoint; - return true; + action = ACTION_MOVING_POINT; + action_point = i; + moving_from = curve->get_point_pos(i); + moving_screen_from = gpoint; + return true; + } + } else if (mode == MODE_EDIT || mode == MODE_EDIT_CURVE) { + // In/out controls can be moved in multiple modes. + if (dist_to_p_out < grab_threshold && i < (curve->get_point_count() - 1)) { + + action = ACTION_MOVING_OUT; + action_point = i; + moving_from = curve->get_point_out(i); + moving_screen_from = gpoint; + return true; + } else if (dist_to_p_in < grab_threshold && i > 0) { + + action = ACTION_MOVING_IN; + action_point = i; + moving_from = curve->get_point_in(i); + moving_screen_from = gpoint; + return true; + } } } + // Check for point deletion. if ((mb->get_button_index() == BUTTON_RIGHT && mode == MODE_EDIT) || (mb->get_button_index() == BUTTON_LEFT && mode == MODE_DELETE)) { if (dist_to_p < grab_threshold) { @@ -135,65 +155,10 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return true; } } - - if (dist_to_p < grab_threshold) - pointunder = true; - - if (mb->get_button_index() == BUTTON_LEFT && i < (curve->get_point_count() - 1)) { - if (dist_to_p_out < grab_threshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) { - - action_point = i; - moving_from = curve->get_point_pos(i); - moving_screen_from = gpoint; - return true; - } else if ((mb->get_button_index() == BUTTON_RIGHT && mode == MODE_EDIT) || (mb->get_button_index() == BUTTON_LEFT && mode == MODE_DELETE)) { - - undo_redo->create_action(TTR("Remove Point from Curve")); - undo_redo->add_do_method(curve.ptr(), "remove_point", i); - undo_redo->add_undo_method(curve.ptr(), "add_point", curve->get_point_pos(i), curve->get_point_in(i), curve->get_point_out(i), i); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - return true; - } else - pointunder = true; - } - - if (pointunder) - return true; } -#if 0 -I think i broke this, was this not suposed to go somewhere? - if (mb->get_button_index() == BUTTON_LEFT && i < (curve->get_point_count() - 1)) { - Point2 p = xform.xform(curve->get_point_pos(i) + curve->get_point_out(i)); - if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) { - action = ACTION_MOVING_OUT; - action_point = i; - moving_from = curve->get_point_out(i); - moving_screen_from = gpoint; - return true; - } - } - - if (mb->get_button_index() == BUTTON_LEFT && i > 0) { - Point2 p = xform.xform(curve->get_point_pos(i) + curve->get_point_in(i)); - if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) { - - action = ACTION_MOVING_IN; - action_point = i; - moving_from = curve->get_point_in(i); - moving_screen_from = gpoint; - return true; - } - } - - if (pointunder) - return true; -#endif } - // Test add point in empty space! - + // Check for point creation. if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && ((mb->get_command() && mode == MODE_EDIT) || mode == MODE_CREATE)) { Ref<Curve2D> curve = node->get_curve(); @@ -215,6 +180,7 @@ I think i broke this, was this not suposed to go somewhere? return true; } + // Check for point movement completion. if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && action != ACTION_NONE) { Ref<Curve2D> curve = node->get_curve(); @@ -222,6 +188,10 @@ I think i broke this, was this not suposed to go somewhere? Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); switch (action) { + case ACTION_NONE: + // N/A, handled in above condition. + break; + case ACTION_MOVING_POINT: { undo_redo->create_action(TTR("Move Point in Curve")); @@ -232,6 +202,7 @@ I think i broke this, was this not suposed to go somewhere? undo_redo->commit_action(); } break; + case ACTION_MOVING_IN: { undo_redo->create_action(TTR("Move In-Control in Curve")); @@ -242,6 +213,7 @@ I think i broke this, was this not suposed to go somewhere? undo_redo->commit_action(); } break; + case ACTION_MOVING_OUT: { undo_redo->create_action(TTR("Move Out-Control in Curve")); @@ -278,9 +250,6 @@ I think i broke this, was this not suposed to go somewhere? edited_point=1; return true; } else { - if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_threshold) { - //wip closed - _wip_close(); if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_treshold) { //wip closed _wip_close(); @@ -301,8 +270,6 @@ I think i broke this, was this not suposed to go somewhere? _wip_close(); } - - } break; case MODE_EDIT: { @@ -454,11 +421,8 @@ I think i broke this, was this not suposed to go somewhere? } - - } break; } - #endif } @@ -467,10 +431,13 @@ I think i broke this, was this not suposed to go somewhere? if (mm.is_valid()) { if (action != ACTION_NONE) { - + // Handle point/control movement. Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = mm->get_pos(); - Vector2 cpoint = !mm->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); + Vector2 cpoint = + !mm->get_alt() ? + canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : + node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); Ref<Curve2D> curve = node->get_curve(); @@ -478,19 +445,20 @@ I think i broke this, was this not suposed to go somewhere? switch (action) { - case ACTION_MOVING_POINT: { + case ACTION_NONE: + // N/A, handled in above condition. + break; + case ACTION_MOVING_POINT: { curve->set_point_pos(action_point, cpoint); } break; - case ACTION_MOVING_IN: { + case ACTION_MOVING_IN: { curve->set_point_in(action_point, new_pos); - } break; - case ACTION_MOVING_OUT: { + case ACTION_MOVING_OUT: { curve->set_point_out(action_point, new_pos); - } break; } diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body.cpp index 38e1ba1cd5..8d927e529e 100644 --- a/scene/3d/vehicle_body.cpp +++ b/scene/3d/vehicle_body.cpp @@ -214,6 +214,18 @@ float VehicleWheel::get_friction_slip() const { return m_frictionSlip; } +void VehicleWheel::set_roll_influence(float p_value) { + m_rollInfluence = p_value; +} + +float VehicleWheel::get_roll_influence() const { + return m_rollInfluence; +} + +bool VehicleWheel::is_in_contact() const { + return m_raycastInfo.m_isInContact; +} + void VehicleWheel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel::set_radius); @@ -246,9 +258,15 @@ void VehicleWheel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_friction_slip", "length"), &VehicleWheel::set_friction_slip); ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel::get_friction_slip); + ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel::is_in_contact); + + ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel::set_roll_influence); + ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel::get_roll_influence); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_traction"), "set_use_as_traction", "is_used_as_traction"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_steering"), "set_use_as_steering", "is_used_as_steering"); ADD_GROUP("Wheel", "wheel_"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_roll_influence"), "set_roll_influence", "get_roll_influence"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_radius"), "set_radius", "get_radius"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_rest_length"), "set_suspension_rest_length", "get_suspension_rest_length"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "wheel_friction_slip"), "set_friction_slip", "get_friction_slip"); diff --git a/scene/3d/vehicle_body.h b/scene/3d/vehicle_body.h index cdb2ebc0be..7ed9bce730 100644 --- a/scene/3d/vehicle_body.h +++ b/scene/3d/vehicle_body.h @@ -126,6 +126,11 @@ public: void set_use_as_steering(bool p_enabled); bool is_used_as_steering() const; + bool is_in_contact() const; + + void set_roll_influence(float p_value); + float get_roll_influence() const; + VehicleWheel(); }; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 67d440ca67..662ce63946 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -361,7 +361,7 @@ void ColorPicker::_w_input(const Ref<InputEvent> &ev) { if (!changing_color) return; - float y = CLAMP((float)bev->get_pos().y, 0, 256); + float y = CLAMP((float)mev->get_pos().y, 0, 256); h = 1.0 - y / 256.0; color.set_hsv(h, s, v, color.a); last_hsv = color; |