|
@@ -36,6 +36,7 @@
|
|
|
#include "core/object/message_queue.h"
|
|
|
#include "core/string/translation.h"
|
|
|
#include "core/templates/pair.h"
|
|
|
+#include "core/templates/sort_array.h"
|
|
|
#include "scene/2d/audio_listener_2d.h"
|
|
|
#include "scene/2d/camera_2d.h"
|
|
|
#include "scene/2d/collision_object_2d.h"
|
|
@@ -669,6 +670,25 @@ void Viewport::_process_picking() {
|
|
|
point_params.pick_point = true;
|
|
|
|
|
|
int rc = ss2d->intersect_point(point_params, res, 64);
|
|
|
+ if (physics_object_picking_sort) {
|
|
|
+ struct ComparatorCollisionObjects {
|
|
|
+ bool operator()(const PhysicsDirectSpaceState2D::ShapeResult &p_a, const PhysicsDirectSpaceState2D::ShapeResult &p_b) const {
|
|
|
+ CollisionObject2D *a = Object::cast_to<CollisionObject2D>(p_a.collider);
|
|
|
+ CollisionObject2D *b = Object::cast_to<CollisionObject2D>(p_b.collider);
|
|
|
+ if (!a || !b) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int za = a->get_effective_z_index();
|
|
|
+ int zb = b->get_effective_z_index();
|
|
|
+ if (za != zb) {
|
|
|
+ return zb < za;
|
|
|
+ }
|
|
|
+ return a->is_greater_than(b);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ SortArray<PhysicsDirectSpaceState2D::ShapeResult, ComparatorCollisionObjects> sorter;
|
|
|
+ sorter.sort(res, rc);
|
|
|
+ }
|
|
|
for (int i = 0; i < rc; i++) {
|
|
|
if (res[i].collider_id.is_valid() && res[i].collider) {
|
|
|
CollisionObject2D *co = Object::cast_to<CollisionObject2D>(res[i].collider);
|
|
@@ -2864,6 +2884,14 @@ bool Viewport::get_physics_object_picking() {
|
|
|
return physics_object_picking;
|
|
|
}
|
|
|
|
|
|
+void Viewport::set_physics_object_picking_sort(bool p_enable) {
|
|
|
+ physics_object_picking_sort = p_enable;
|
|
|
+}
|
|
|
+
|
|
|
+bool Viewport::get_physics_object_picking_sort() {
|
|
|
+ return physics_object_picking_sort;
|
|
|
+}
|
|
|
+
|
|
|
Vector2 Viewport::get_camera_coords(const Vector2 &p_viewport_coords) const {
|
|
|
Transform2D xf = stretch_transform * global_canvas_transform;
|
|
|
return xf.xform(p_viewport_coords);
|
|
@@ -3798,6 +3826,8 @@ void Viewport::_bind_methods() {
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_physics_object_picking", "enable"), &Viewport::set_physics_object_picking);
|
|
|
ClassDB::bind_method(D_METHOD("get_physics_object_picking"), &Viewport::get_physics_object_picking);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_physics_object_picking_sort", "enable"), &Viewport::set_physics_object_picking_sort);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_physics_object_picking_sort"), &Viewport::get_physics_object_picking_sort);
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_viewport_rid"), &Viewport::get_viewport_rid);
|
|
|
ClassDB::bind_method(D_METHOD("push_text_input", "text"), &Viewport::push_text_input);
|
|
@@ -3949,6 +3979,7 @@ void Viewport::_bind_methods() {
|
|
|
#endif
|
|
|
ADD_GROUP("Physics", "physics_");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics_object_picking"), "set_physics_object_picking", "get_physics_object_picking");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics_object_picking_sort"), "set_physics_object_picking_sort", "get_physics_object_picking_sort");
|
|
|
ADD_GROUP("GUI", "gui_");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_snap_controls_to_pixels"), "set_snap_controls_to_pixels", "is_snap_controls_to_pixels_enabled");
|