feat: modules moved and engine moved to submodule
This commit is contained in:
parent
dfb5e645cd
commit
c33d2130cc
5136 changed files with 225275 additions and 64485 deletions
|
|
@ -6,4 +6,7 @@ Import("env")
|
|||
env.add_source_files(env.scene_sources, "*.cpp")
|
||||
|
||||
# Chain load SCsubs
|
||||
SConscript("physics/SCsub")
|
||||
if not env["disable_physics_2d"]:
|
||||
SConscript("physics/SCsub")
|
||||
if not env["disable_navigation_2d"]:
|
||||
SConscript("navigation/SCsub")
|
||||
|
|
|
|||
|
|
@ -167,6 +167,17 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &p_property) const {
|
|||
|
||||
void AnimatedSprite2D::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
|
||||
RID ae = get_accessibility_element();
|
||||
ERR_FAIL_COND(ae.is_null());
|
||||
|
||||
Rect2 dst_rect = _get_rect();
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_IMAGE);
|
||||
DisplayServer::get_singleton()->accessibility_update_set_transform(ae, get_transform());
|
||||
DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, dst_rect);
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_READY: {
|
||||
if (!Engine::get_singleton()->is_editor_hint() && frames.is_valid() && frames->has_animation(autoplay)) {
|
||||
play(autoplay);
|
||||
|
|
@ -301,7 +312,7 @@ void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
|
|||
|
||||
List<StringName> al;
|
||||
frames->get_animation_list(&al);
|
||||
if (al.size() == 0) {
|
||||
if (al.is_empty()) {
|
||||
set_animation(StringName());
|
||||
autoplay = String();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef ANIMATED_SPRITE_2D_H
|
||||
#define ANIMATED_SPRITE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/sprite_frames.h"
|
||||
|
|
@ -136,5 +135,3 @@ public:
|
|||
|
||||
AnimatedSprite2D();
|
||||
};
|
||||
|
||||
#endif // ANIMATED_SPRITE_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef AUDIO_LISTENER_2D_H
|
||||
#define AUDIO_LISTENER_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -56,5 +55,3 @@ public:
|
|||
|
||||
AudioListener2D();
|
||||
};
|
||||
|
||||
#endif // AUDIO_LISTENER_2D_H
|
||||
|
|
|
|||
|
|
@ -33,13 +33,16 @@
|
|||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "scene/2d/audio_listener_2d.h"
|
||||
#include "scene/2d/physics/area_2d.h"
|
||||
#include "scene/audio/audio_stream_player_internal.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/resources/world_2d.h"
|
||||
#include "servers/audio/audio_stream.h"
|
||||
#include "servers/audio_server.h"
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
#include "scene/2d/physics/area_2d.h"
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
void AudioStreamPlayer2D::_notification(int p_what) {
|
||||
internal->notification(p_what);
|
||||
|
||||
|
|
@ -76,6 +79,7 @@ void AudioStreamPlayer2D::_notification(int p_what) {
|
|||
|
||||
// Interacts with PhysicsServer2D, so can only be called during _physics_process.
|
||||
StringName AudioStreamPlayer2D::_get_actual_bus() {
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
Vector2 global_pos = get_global_position();
|
||||
|
||||
//check if any area is diverting sound into a bus
|
||||
|
|
@ -93,7 +97,6 @@ StringName AudioStreamPlayer2D::_get_actual_bus() {
|
|||
point_params.collide_with_areas = true;
|
||||
|
||||
int areas = space_state->intersect_point(point_params, sr, MAX_INTERSECT_AREAS);
|
||||
|
||||
for (int i = 0; i < areas; i++) {
|
||||
Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider);
|
||||
if (!area2d) {
|
||||
|
|
@ -106,6 +109,8 @@ StringName AudioStreamPlayer2D::_get_actual_bus() {
|
|||
|
||||
return area2d->get_audio_bus_name();
|
||||
}
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
return internal->bus;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef AUDIO_STREAM_PLAYER_2D_H
|
||||
#define AUDIO_STREAM_PLAYER_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "servers/audio_server.h"
|
||||
|
|
@ -149,5 +148,3 @@ public:
|
|||
AudioStreamPlayer2D();
|
||||
~AudioStreamPlayer2D();
|
||||
};
|
||||
|
||||
#endif // AUDIO_STREAM_PLAYER_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef BACK_BUFFER_COPY_H
|
||||
#define BACK_BUFFER_COPY_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -71,5 +70,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(BackBufferCopy::CopyMode);
|
||||
|
||||
#endif // BACK_BUFFER_COPY_H
|
||||
|
|
|
|||
|
|
@ -31,22 +31,67 @@
|
|||
#include "camera_2d.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/input/input.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
bool Camera2D::_is_editing_in_editor() const {
|
||||
#ifdef TOOLS_ENABLED
|
||||
return is_part_of_edited_scene();
|
||||
#else
|
||||
return false;
|
||||
#endif // TOOLS_ENABLED
|
||||
Dictionary Camera2D::_edit_get_state() const {
|
||||
Dictionary state = Node2D::_edit_get_state();
|
||||
state["limit_rect"] = get_limit_rect();
|
||||
return state;
|
||||
}
|
||||
|
||||
void Camera2D::_edit_set_state(const Dictionary &p_state) {
|
||||
if (p_state.has("limit_rect")) {
|
||||
_set_limit_rect(p_state["limit_rect"]);
|
||||
}
|
||||
Node2D::_edit_set_state(p_state);
|
||||
}
|
||||
|
||||
void Camera2D::_edit_set_position(const Point2 &p_position) {
|
||||
if (_is_dragging_limit_rect()) {
|
||||
Rect2 rect = get_limit_rect();
|
||||
rect.position = p_position;
|
||||
_set_limit_rect(rect);
|
||||
} else {
|
||||
Node2D::_edit_set_position(p_position);
|
||||
}
|
||||
}
|
||||
|
||||
Point2 Camera2D::_edit_get_position() const {
|
||||
return _is_dragging_limit_rect() ? get_limit_rect().position : Node2D::_edit_get_position();
|
||||
}
|
||||
|
||||
void Camera2D::_edit_set_rect(const Rect2 &p_rect) {
|
||||
ERR_FAIL_COND(limit_enabled && !_edit_use_rect());
|
||||
Rect2 rect = p_rect;
|
||||
Vector2 scl = get_global_scale().abs();
|
||||
rect.size *= scl;
|
||||
rect.position = (rect.position + get_global_position()) * scl;
|
||||
_set_limit_rect(rect);
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
Rect2 Camera2D::_edit_get_rect() const {
|
||||
Rect2 rect = get_limit_rect();
|
||||
Vector2 scl = get_global_scale().abs();
|
||||
rect.size /= scl;
|
||||
rect.position = (rect.position - get_global_position()) / scl;
|
||||
return rect;
|
||||
}
|
||||
|
||||
bool Camera2D::_edit_use_rect() const {
|
||||
return limit_enabled;
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void Camera2D::_update_scroll() {
|
||||
if (!is_inside_tree() || !viewport) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_is_editing_in_editor()) {
|
||||
if (is_part_of_edited_scene()) {
|
||||
queue_redraw();
|
||||
return;
|
||||
}
|
||||
|
|
@ -75,6 +120,10 @@ void Camera2D::_update_scroll() {
|
|||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
bool Camera2D::_is_dragging_limit_rect() const {
|
||||
return _edit_use_rect() && Input::get_singleton()->is_key_pressed(Key::CTRL);
|
||||
}
|
||||
|
||||
void Camera2D::_project_settings_changed() {
|
||||
if (screen_drawing_enabled) {
|
||||
queue_redraw();
|
||||
|
|
@ -92,7 +141,7 @@ void Camera2D::_update_process_callback() {
|
|||
WARN_PRINT_ONCE("Camera2D overridden to physics process mode due to use of physics interpolation.");
|
||||
}
|
||||
#endif
|
||||
} else if (_is_editing_in_editor()) {
|
||||
} else if (is_part_of_edited_scene()) {
|
||||
set_process_internal(false);
|
||||
set_physics_process_internal(false);
|
||||
} else {
|
||||
|
|
@ -107,7 +156,7 @@ void Camera2D::_update_process_callback() {
|
|||
}
|
||||
|
||||
void Camera2D::set_zoom(const Vector2 &p_zoom) {
|
||||
// Setting zoom to zero causes 'affine_invert' issues
|
||||
// Setting zoom to zero causes 'affine_invert' issues.
|
||||
ERR_FAIL_COND_MSG(Math::is_zero_approx(p_zoom.x) || Math::is_zero_approx(p_zoom.y), "Zoom level must be different from 0 (can be negative).");
|
||||
|
||||
zoom = p_zoom;
|
||||
|
|
@ -135,7 +184,7 @@ Transform2D Camera2D::get_camera_transform() {
|
|||
|
||||
if (!first) {
|
||||
if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) {
|
||||
if (drag_horizontal_enabled && !_is_editing_in_editor() && !drag_horizontal_offset_changed) {
|
||||
if (drag_horizontal_enabled && !is_part_of_edited_scene() && !drag_horizontal_offset_changed) {
|
||||
camera_pos.x = MIN(camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * zoom_scale.x * drag_margin[SIDE_LEFT]));
|
||||
camera_pos.x = MAX(camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * zoom_scale.x * drag_margin[SIDE_RIGHT]));
|
||||
} else {
|
||||
|
|
@ -148,7 +197,7 @@ Transform2D Camera2D::get_camera_transform() {
|
|||
drag_horizontal_offset_changed = false;
|
||||
}
|
||||
|
||||
if (drag_vertical_enabled && !_is_editing_in_editor() && !drag_vertical_offset_changed) {
|
||||
if (drag_vertical_enabled && !is_part_of_edited_scene() && !drag_vertical_offset_changed) {
|
||||
camera_pos.y = MIN(camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * zoom_scale.y * drag_margin[SIDE_TOP]));
|
||||
camera_pos.y = MAX(camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * zoom_scale.y * drag_margin[SIDE_BOTTOM]));
|
||||
|
||||
|
|
@ -169,7 +218,7 @@ Transform2D Camera2D::get_camera_transform() {
|
|||
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom_scale) : Point2());
|
||||
Rect2 screen_rect(-screen_offset + camera_pos, screen_size * zoom_scale);
|
||||
|
||||
if (limit_smoothing_enabled) {
|
||||
if (limit_enabled && limit_smoothing_enabled) {
|
||||
if (screen_rect.position.x < limit[SIDE_LEFT]) {
|
||||
camera_pos.x -= screen_rect.position.x - limit[SIDE_LEFT];
|
||||
}
|
||||
|
|
@ -192,7 +241,7 @@ Transform2D Camera2D::get_camera_transform() {
|
|||
// It may be called MULTIPLE TIMES on certain frames,
|
||||
// therefore smoothing is not currently applied only once per frame / tick,
|
||||
// which will result in some haphazard results.
|
||||
if (position_smoothing_enabled && !_is_editing_in_editor()) {
|
||||
if (position_smoothing_enabled && !is_part_of_edited_scene()) {
|
||||
bool physics_process = (process_callback == CAMERA2D_PROCESS_PHYSICS) || is_physics_interpolated_and_enabled();
|
||||
real_t delta = physics_process ? get_physics_process_delta_time() : get_process_delta_time();
|
||||
real_t c = position_smoothing_speed * delta;
|
||||
|
|
@ -211,7 +260,7 @@ Transform2D Camera2D::get_camera_transform() {
|
|||
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom_scale) : Point2());
|
||||
|
||||
if (!ignore_rotation) {
|
||||
if (rotation_smoothing_enabled && !_is_editing_in_editor()) {
|
||||
if (rotation_smoothing_enabled && !is_part_of_edited_scene()) {
|
||||
real_t step = rotation_smoothing_speed * (process_callback == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time());
|
||||
camera_angle = Math::lerp_angle(camera_angle, get_global_rotation(), step);
|
||||
} else {
|
||||
|
|
@ -222,7 +271,7 @@ Transform2D Camera2D::get_camera_transform() {
|
|||
|
||||
Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom_scale);
|
||||
|
||||
if (!position_smoothing_enabled || !limit_smoothing_enabled) {
|
||||
if (limit_enabled && (!position_smoothing_enabled || !limit_smoothing_enabled)) {
|
||||
if (screen_rect.position.x < limit[SIDE_LEFT]) {
|
||||
screen_rect.position.x = limit[SIDE_LEFT];
|
||||
}
|
||||
|
|
@ -311,7 +360,7 @@ void Camera2D::_notification(int p_what) {
|
|||
} break;
|
||||
|
||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||
if ((!position_smoothing_enabled && !is_physics_interpolated_and_enabled()) || _is_editing_in_editor()) {
|
||||
if ((!position_smoothing_enabled && !is_physics_interpolated_and_enabled()) || is_part_of_edited_scene()) {
|
||||
_update_scroll();
|
||||
}
|
||||
if (is_physics_interpolated_and_enabled()) {
|
||||
|
|
@ -339,7 +388,7 @@ void Camera2D::_notification(int p_what) {
|
|||
add_to_group(group_name);
|
||||
add_to_group(canvas_group_name);
|
||||
|
||||
if (!_is_editing_in_editor() && enabled && !viewport->get_camera_2d()) {
|
||||
if (!is_part_of_edited_scene() && enabled && !viewport->get_camera_2d()) {
|
||||
make_current();
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +419,7 @@ void Camera2D::_notification(int p_what) {
|
|||
|
||||
#ifdef TOOLS_ENABLED
|
||||
case NOTIFICATION_DRAW: {
|
||||
if (!is_inside_tree() || !_is_editing_in_editor()) {
|
||||
if (!is_inside_tree() || !is_part_of_edited_scene()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -398,8 +447,7 @@ void Camera2D::_notification(int p_what) {
|
|||
}
|
||||
}
|
||||
|
||||
if (limit_drawing_enabled) {
|
||||
Color limit_drawing_color(1, 1, 0.25, 0.63);
|
||||
if (limit_enabled && limit_drawing_enabled) {
|
||||
real_t limit_drawing_width = -1;
|
||||
if (is_current()) {
|
||||
limit_drawing_width = 3;
|
||||
|
|
@ -415,7 +463,7 @@ void Camera2D::_notification(int p_what) {
|
|||
};
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
draw_line(limit_points[i], limit_points[(i + 1) % 4], limit_drawing_color, limit_drawing_width);
|
||||
draw_line(limit_points[i], limit_points[(i + 1) % 4], Color(1, 1, 0.25, 0.63), limit_drawing_width);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -448,6 +496,9 @@ void Camera2D::_notification(int p_what) {
|
|||
}
|
||||
|
||||
void Camera2D::set_offset(const Vector2 &p_offset) {
|
||||
if (offset == p_offset) {
|
||||
return;
|
||||
}
|
||||
offset = p_offset;
|
||||
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
||||
_update_scroll();
|
||||
|
|
@ -459,6 +510,9 @@ Vector2 Camera2D::get_offset() const {
|
|||
}
|
||||
|
||||
void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode) {
|
||||
if (anchor_mode == p_anchor_mode) {
|
||||
return;
|
||||
}
|
||||
anchor_mode = p_anchor_mode;
|
||||
_update_scroll();
|
||||
}
|
||||
|
|
@ -468,6 +522,9 @@ Camera2D::AnchorMode Camera2D::get_anchor_mode() const {
|
|||
}
|
||||
|
||||
void Camera2D::set_ignore_rotation(bool p_ignore) {
|
||||
if (ignore_rotation == p_ignore) {
|
||||
return;
|
||||
}
|
||||
ignore_rotation = p_ignore;
|
||||
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
||||
|
||||
|
|
@ -484,6 +541,22 @@ bool Camera2D::is_ignoring_rotation() const {
|
|||
return ignore_rotation;
|
||||
}
|
||||
|
||||
void Camera2D::set_limit_enabled(bool p_limit_enabled) {
|
||||
if (limit_enabled == p_limit_enabled) {
|
||||
return;
|
||||
}
|
||||
limit_enabled = p_limit_enabled;
|
||||
_update_scroll();
|
||||
#ifdef TOOLS_ENABLED
|
||||
emit_signal("_camera_limit_enabled_updated"); // Used for Camera2DEditorPlugin.
|
||||
#endif
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
||||
bool Camera2D::is_limit_enabled() const {
|
||||
return limit_enabled;
|
||||
}
|
||||
|
||||
void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) {
|
||||
if (process_callback == p_mode) {
|
||||
return;
|
||||
|
|
@ -494,6 +567,9 @@ void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) {
|
|||
}
|
||||
|
||||
void Camera2D::set_enabled(bool p_enabled) {
|
||||
if (enabled == p_enabled) {
|
||||
return;
|
||||
}
|
||||
enabled = p_enabled;
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
|
|
@ -541,13 +617,25 @@ void Camera2D::_make_current(Object *p_which) {
|
|||
}
|
||||
|
||||
void Camera2D::_update_process_internal_for_smoothing() {
|
||||
bool is_not_in_scene_or_editor = !(is_inside_tree() && _is_editing_in_editor());
|
||||
bool is_not_in_scene_or_editor = !(is_inside_tree() && is_part_of_edited_scene());
|
||||
bool is_any_smoothing_valid = position_smoothing_speed > 0 || rotation_smoothing_speed > 0;
|
||||
|
||||
bool enable = is_any_smoothing_valid && is_not_in_scene_or_editor;
|
||||
set_process_internal(enable);
|
||||
}
|
||||
|
||||
void Camera2D::_set_limit_rect(const Rect2 &p_limit_rect) {
|
||||
Point2 limit_rect_end = p_limit_rect.get_end();
|
||||
set_limit(SIDE_LEFT, p_limit_rect.position.x);
|
||||
set_limit(SIDE_TOP, p_limit_rect.position.y);
|
||||
set_limit(SIDE_RIGHT, limit_rect_end.x);
|
||||
set_limit(SIDE_BOTTOM, limit_rect_end.y);
|
||||
}
|
||||
|
||||
Rect2 Camera2D::get_limit_rect() const {
|
||||
return Rect2(limit[SIDE_LEFT], limit[SIDE_TOP], limit[SIDE_RIGHT] - limit[SIDE_LEFT], limit[SIDE_BOTTOM] - limit[SIDE_TOP]);
|
||||
}
|
||||
|
||||
void Camera2D::make_current() {
|
||||
ERR_FAIL_COND(!enabled || !is_inside_tree());
|
||||
get_tree()->call_group(group_name, "_make_current", this);
|
||||
|
|
@ -586,6 +674,9 @@ bool Camera2D::is_current() const {
|
|||
|
||||
void Camera2D::set_limit(Side p_side, int p_limit) {
|
||||
ERR_FAIL_INDEX((int)p_side, 4);
|
||||
if (limit[p_side] == p_limit) {
|
||||
return;
|
||||
}
|
||||
limit[p_side] = p_limit;
|
||||
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
||||
_update_scroll();
|
||||
|
|
@ -597,8 +688,11 @@ int Camera2D::get_limit(Side p_side) const {
|
|||
return limit[p_side];
|
||||
}
|
||||
|
||||
void Camera2D::set_limit_smoothing_enabled(bool enable) {
|
||||
limit_smoothing_enabled = enable;
|
||||
void Camera2D::set_limit_smoothing_enabled(bool p_enabled) {
|
||||
if (limit_smoothing_enabled == p_enabled) {
|
||||
return;
|
||||
}
|
||||
limit_smoothing_enabled = p_enabled;
|
||||
_update_scroll();
|
||||
}
|
||||
|
||||
|
|
@ -608,6 +702,9 @@ bool Camera2D::is_limit_smoothing_enabled() const {
|
|||
|
||||
void Camera2D::set_drag_margin(Side p_side, real_t p_drag_margin) {
|
||||
ERR_FAIL_INDEX((int)p_side, 4);
|
||||
if (drag_margin[p_side] == p_drag_margin) {
|
||||
return;
|
||||
}
|
||||
drag_margin[p_side] = p_drag_margin;
|
||||
queue_redraw();
|
||||
}
|
||||
|
|
@ -655,6 +752,9 @@ void Camera2D::align() {
|
|||
}
|
||||
|
||||
void Camera2D::set_position_smoothing_speed(real_t p_speed) {
|
||||
if (position_smoothing_speed == p_speed) {
|
||||
return;
|
||||
}
|
||||
position_smoothing_speed = MAX(0, p_speed);
|
||||
_update_process_internal_for_smoothing();
|
||||
}
|
||||
|
|
@ -664,6 +764,9 @@ real_t Camera2D::get_position_smoothing_speed() const {
|
|||
}
|
||||
|
||||
void Camera2D::set_rotation_smoothing_speed(real_t p_speed) {
|
||||
if (rotation_smoothing_speed == p_speed) {
|
||||
return;
|
||||
}
|
||||
rotation_smoothing_speed = MAX(0, p_speed);
|
||||
_update_process_internal_for_smoothing();
|
||||
}
|
||||
|
|
@ -673,6 +776,9 @@ real_t Camera2D::get_rotation_smoothing_speed() const {
|
|||
}
|
||||
|
||||
void Camera2D::set_rotation_smoothing_enabled(bool p_enabled) {
|
||||
if (rotation_smoothing_enabled == p_enabled) {
|
||||
return;
|
||||
}
|
||||
rotation_smoothing_enabled = p_enabled;
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
|
@ -686,7 +792,7 @@ Point2 Camera2D::get_camera_screen_center() const {
|
|||
}
|
||||
|
||||
Size2 Camera2D::_get_camera_screen_size() const {
|
||||
if (_is_editing_in_editor()) {
|
||||
if (is_part_of_edited_scene()) {
|
||||
return Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
|
||||
}
|
||||
return get_viewport_rect().size;
|
||||
|
|
@ -709,6 +815,9 @@ bool Camera2D::is_drag_vertical_enabled() const {
|
|||
}
|
||||
|
||||
void Camera2D::set_drag_vertical_offset(real_t p_offset) {
|
||||
if (drag_vertical_offset == p_offset) {
|
||||
return;
|
||||
}
|
||||
drag_vertical_offset = p_offset;
|
||||
drag_vertical_offset_changed = true;
|
||||
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
||||
|
|
@ -721,6 +830,9 @@ real_t Camera2D::get_drag_vertical_offset() const {
|
|||
}
|
||||
|
||||
void Camera2D::set_drag_horizontal_offset(real_t p_offset) {
|
||||
if (drag_horizontal_offset == p_offset) {
|
||||
return;
|
||||
}
|
||||
drag_horizontal_offset = p_offset;
|
||||
drag_horizontal_offset_changed = true;
|
||||
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
||||
|
|
@ -732,15 +844,10 @@ real_t Camera2D::get_drag_horizontal_offset() const {
|
|||
return drag_horizontal_offset;
|
||||
}
|
||||
|
||||
void Camera2D::_set_old_smoothing(real_t p_enable) {
|
||||
//compatibility
|
||||
if (p_enable > 0) {
|
||||
position_smoothing_enabled = true;
|
||||
set_position_smoothing_speed(p_enable);
|
||||
}
|
||||
}
|
||||
|
||||
void Camera2D::set_position_smoothing_enabled(bool p_enabled) {
|
||||
if (position_smoothing_enabled == p_enabled) {
|
||||
return;
|
||||
}
|
||||
position_smoothing_enabled = p_enabled;
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
|
@ -751,6 +858,10 @@ bool Camera2D::is_position_smoothing_enabled() const {
|
|||
|
||||
void Camera2D::set_custom_viewport(Node *p_viewport) {
|
||||
ERR_FAIL_NULL(p_viewport);
|
||||
if (custom_viewport == p_viewport) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_inside_tree()) {
|
||||
remove_from_group(group_name);
|
||||
remove_from_group(canvas_group_name);
|
||||
|
|
@ -783,8 +894,8 @@ Node *Camera2D::get_custom_viewport() const {
|
|||
return custom_viewport;
|
||||
}
|
||||
|
||||
void Camera2D::set_screen_drawing_enabled(bool enable) {
|
||||
screen_drawing_enabled = enable;
|
||||
void Camera2D::set_screen_drawing_enabled(bool p_enabled) {
|
||||
screen_drawing_enabled = p_enabled;
|
||||
#ifdef TOOLS_ENABLED
|
||||
queue_redraw();
|
||||
#endif
|
||||
|
|
@ -794,8 +905,8 @@ bool Camera2D::is_screen_drawing_enabled() const {
|
|||
return screen_drawing_enabled;
|
||||
}
|
||||
|
||||
void Camera2D::set_limit_drawing_enabled(bool enable) {
|
||||
limit_drawing_enabled = enable;
|
||||
void Camera2D::set_limit_drawing_enabled(bool p_enabled) {
|
||||
limit_drawing_enabled = p_enabled;
|
||||
#ifdef TOOLS_ENABLED
|
||||
queue_redraw();
|
||||
#endif
|
||||
|
|
@ -805,8 +916,8 @@ bool Camera2D::is_limit_drawing_enabled() const {
|
|||
return limit_drawing_enabled;
|
||||
}
|
||||
|
||||
void Camera2D::set_margin_drawing_enabled(bool enable) {
|
||||
margin_drawing_enabled = enable;
|
||||
void Camera2D::set_margin_drawing_enabled(bool p_enabled) {
|
||||
margin_drawing_enabled = p_enabled;
|
||||
#ifdef TOOLS_ENABLED
|
||||
queue_redraw();
|
||||
#endif
|
||||
|
|
@ -817,6 +928,9 @@ bool Camera2D::is_margin_drawing_enabled() const {
|
|||
}
|
||||
|
||||
void Camera2D::_validate_property(PropertyInfo &p_property) const {
|
||||
if (!limit_enabled && (p_property.name == "limit_smoothed" || p_property.name == "limit_left" || p_property.name == "limit_top" || p_property.name == "limit_right" || p_property.name == "limit_bottom")) {
|
||||
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
|
||||
}
|
||||
if (!position_smoothing_enabled && p_property.name == "position_smoothing_speed") {
|
||||
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
|
||||
}
|
||||
|
|
@ -847,6 +961,9 @@ void Camera2D::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("is_current"), &Camera2D::is_current);
|
||||
ClassDB::bind_method(D_METHOD("_make_current"), &Camera2D::_make_current);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_limit_enabled", "limit_enabled"), &Camera2D::set_limit_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_limit_enabled"), &Camera2D::is_limit_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_limit", "margin", "limit"), &Camera2D::set_limit);
|
||||
ClassDB::bind_method(D_METHOD("get_limit", "margin"), &Camera2D::get_limit);
|
||||
|
||||
|
|
@ -893,8 +1010,6 @@ void Camera2D::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("reset_smoothing"), &Camera2D::reset_smoothing);
|
||||
ClassDB::bind_method(D_METHOD("align"), &Camera2D::align);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_set_old_smoothing", "follow_smoothing"), &Camera2D::_set_old_smoothing);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_screen_drawing_enabled", "screen_drawing_enabled"), &Camera2D::set_screen_drawing_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_screen_drawing_enabled"), &Camera2D::is_screen_drawing_enabled);
|
||||
|
||||
|
|
@ -913,6 +1028,7 @@ void Camera2D::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback");
|
||||
|
||||
ADD_GROUP("Limit", "limit_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "limit_enabled"), "set_limit_enabled", "is_limit_enabled");
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_left", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_LEFT);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_top", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_TOP);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_right", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_RIGHT);
|
||||
|
|
@ -949,16 +1065,10 @@ void Camera2D::_bind_methods() {
|
|||
}
|
||||
|
||||
Camera2D::Camera2D() {
|
||||
limit[SIDE_LEFT] = -10000000;
|
||||
limit[SIDE_TOP] = -10000000;
|
||||
limit[SIDE_RIGHT] = 10000000;
|
||||
limit[SIDE_BOTTOM] = 10000000;
|
||||
|
||||
drag_margin[SIDE_LEFT] = 0.2;
|
||||
drag_margin[SIDE_TOP] = 0.2;
|
||||
drag_margin[SIDE_RIGHT] = 0.2;
|
||||
drag_margin[SIDE_BOTTOM] = 0.2;
|
||||
|
||||
set_notify_transform(true);
|
||||
set_hide_clip_children(true);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
add_user_signal(MethodInfo("_camera_limit_enabled_updated")); // Camera2DEditorPlugin listens to this.
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CAMERA_2D_H
|
||||
#define CAMERA_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -53,7 +52,7 @@ protected:
|
|||
bool first = true;
|
||||
bool just_exited_tree = false;
|
||||
|
||||
ObjectID custom_viewport_id; // to check validity
|
||||
ObjectID custom_viewport_id; // To check validity.
|
||||
Viewport *custom_viewport = nullptr;
|
||||
Viewport *viewport = nullptr;
|
||||
|
||||
|
|
@ -73,10 +72,11 @@ protected:
|
|||
real_t rotation_smoothing_speed = 5.0;
|
||||
bool rotation_smoothing_enabled = false;
|
||||
|
||||
int limit[4];
|
||||
bool limit_enabled = true;
|
||||
int limit[4] = { -10000000, -10000000, 10000000, 10000000 }; // Left, top, right, bottom.
|
||||
bool limit_smoothing_enabled = false;
|
||||
|
||||
real_t drag_margin[4];
|
||||
real_t drag_margin[4] = { 0.2, 0.2, 0.2, 0.2 };
|
||||
bool drag_horizontal_enabled = false;
|
||||
bool drag_vertical_enabled = false;
|
||||
real_t drag_horizontal_offset = 0.0;
|
||||
|
|
@ -88,17 +88,19 @@ protected:
|
|||
bool _is_editing_in_editor() const;
|
||||
void _update_process_callback();
|
||||
void _update_scroll();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
bool _is_dragging_limit_rect() const;
|
||||
void _project_settings_changed();
|
||||
#endif
|
||||
|
||||
void _make_current(Object *p_which);
|
||||
void _reset_just_exited() { just_exited_tree = false; }
|
||||
|
||||
void _set_old_smoothing(real_t p_enable);
|
||||
|
||||
void _update_process_internal_for_smoothing();
|
||||
|
||||
void _set_limit_rect(const Rect2 &p_limit_rect);
|
||||
|
||||
bool screen_drawing_enabled = true;
|
||||
bool limit_drawing_enabled = false;
|
||||
bool margin_drawing_enabled = false;
|
||||
|
|
@ -123,6 +125,24 @@ protected:
|
|||
void _validate_property(PropertyInfo &p_property) const;
|
||||
|
||||
public:
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual Dictionary _edit_get_state() const override;
|
||||
virtual void _edit_set_state(const Dictionary &p_state) override;
|
||||
|
||||
virtual void _edit_set_position(const Point2 &p_position) override;
|
||||
virtual Point2 _edit_get_position() const override;
|
||||
|
||||
virtual void _edit_set_rect(const Rect2 &p_rect) override;
|
||||
virtual Size2 _edit_get_minimum_size() const override { return Size2(); }
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual Rect2 _edit_get_rect() const override;
|
||||
virtual bool _edit_use_rect() const override;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
Rect2 get_limit_rect() const;
|
||||
|
||||
void set_offset(const Vector2 &p_offset);
|
||||
Vector2 get_offset() const;
|
||||
|
||||
|
|
@ -132,10 +152,13 @@ public:
|
|||
void set_ignore_rotation(bool p_ignore);
|
||||
bool is_ignoring_rotation() const;
|
||||
|
||||
void set_limit_enabled(bool p_limit_enabled);
|
||||
bool is_limit_enabled() const;
|
||||
|
||||
void set_limit(Side p_side, int p_limit);
|
||||
int get_limit(Side p_side) const;
|
||||
|
||||
void set_limit_smoothing_enabled(bool enable);
|
||||
void set_limit_smoothing_enabled(bool p_enabled);
|
||||
bool is_limit_smoothing_enabled() const;
|
||||
|
||||
void set_drag_horizontal_enabled(bool p_enabled);
|
||||
|
|
@ -188,13 +211,13 @@ public:
|
|||
void reset_smoothing();
|
||||
void align();
|
||||
|
||||
void set_screen_drawing_enabled(bool enable);
|
||||
void set_screen_drawing_enabled(bool p_enabled);
|
||||
bool is_screen_drawing_enabled() const;
|
||||
|
||||
void set_limit_drawing_enabled(bool enable);
|
||||
void set_limit_drawing_enabled(bool p_enabled);
|
||||
bool is_limit_drawing_enabled() const;
|
||||
|
||||
void set_margin_drawing_enabled(bool enable);
|
||||
void set_margin_drawing_enabled(bool p_enabled);
|
||||
bool is_margin_drawing_enabled() const;
|
||||
|
||||
Camera2D();
|
||||
|
|
@ -202,5 +225,3 @@ public:
|
|||
|
||||
VARIANT_ENUM_CAST(Camera2D::AnchorMode);
|
||||
VARIANT_ENUM_CAST(Camera2D::Camera2DProcessCallback);
|
||||
|
||||
#endif // CAMERA_2D_H
|
||||
|
|
|
|||
|
|
@ -64,6 +64,38 @@ bool CanvasGroup::is_using_mipmaps() const {
|
|||
return use_mipmaps;
|
||||
}
|
||||
|
||||
PackedStringArray CanvasGroup::get_configuration_warnings() const {
|
||||
PackedStringArray warnings = Node2D::get_configuration_warnings();
|
||||
|
||||
if (is_inside_tree()) {
|
||||
bool warned_about_ancestor_clipping = false;
|
||||
bool warned_about_canvasgroup_ancestor = false;
|
||||
Node *n = get_parent();
|
||||
while (n) {
|
||||
CanvasItem *as_canvas_item = Object::cast_to<CanvasItem>(n);
|
||||
if (!warned_about_ancestor_clipping && as_canvas_item && as_canvas_item->get_clip_children_mode() != CLIP_CHILDREN_DISABLED) {
|
||||
warnings.push_back(vformat(RTR("Ancestor \"%s\" clips its children, so this CanvasGroup will not function properly."), as_canvas_item->get_name()));
|
||||
warned_about_ancestor_clipping = true;
|
||||
}
|
||||
|
||||
CanvasGroup *as_canvas_group = Object::cast_to<CanvasGroup>(n);
|
||||
if (!warned_about_canvasgroup_ancestor && as_canvas_group) {
|
||||
warnings.push_back(vformat(RTR("Ancestor \"%s\" is a CanvasGroup, so this CanvasGroup will not function properly."), as_canvas_group->get_name()));
|
||||
warned_about_canvasgroup_ancestor = true;
|
||||
}
|
||||
|
||||
// Only break out early once both warnings have been triggered, so
|
||||
// that the user is aware of both possible reasons for clipping not working.
|
||||
if (warned_about_ancestor_clipping && warned_about_canvasgroup_ancestor) {
|
||||
break;
|
||||
}
|
||||
n = n->get_parent();
|
||||
}
|
||||
}
|
||||
|
||||
return warnings;
|
||||
}
|
||||
|
||||
void CanvasGroup::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_fit_margin", "fit_margin"), &CanvasGroup::set_fit_margin);
|
||||
ClassDB::bind_method(D_METHOD("get_fit_margin"), &CanvasGroup::get_fit_margin);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CANVAS_GROUP_H
|
||||
#define CANVAS_GROUP_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -52,8 +51,8 @@ public:
|
|||
void set_use_mipmaps(bool p_use_mipmaps);
|
||||
bool is_using_mipmaps() const;
|
||||
|
||||
virtual PackedStringArray get_configuration_warnings() const override;
|
||||
|
||||
CanvasGroup();
|
||||
~CanvasGroup();
|
||||
};
|
||||
|
||||
#endif // CANVAS_GROUP_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CANVAS_MODULATE_H
|
||||
#define CANVAS_MODULATE_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -59,5 +58,3 @@ public:
|
|||
CanvasModulate();
|
||||
~CanvasModulate();
|
||||
};
|
||||
|
||||
#endif // CANVAS_MODULATE_H
|
||||
|
|
|
|||
|
|
@ -116,7 +116,14 @@ void CPUParticles2D::set_use_local_coordinates(bool p_enable) {
|
|||
|
||||
// We only need NOTIFICATION_TRANSFORM_CHANGED
|
||||
// when following an interpolated target.
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
set_notify_transform(_interpolation_data.interpolated_follow || (Engine::get_singleton()->is_editor_hint() && !local_coords));
|
||||
#else
|
||||
set_notify_transform(_interpolation_data.interpolated_follow);
|
||||
#endif
|
||||
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void CPUParticles2D::set_speed_scale(double p_scale) {
|
||||
|
|
@ -474,14 +481,35 @@ void CPUParticles2D::set_emission_shape(EmissionShape p_shape) {
|
|||
ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX);
|
||||
emission_shape = p_shape;
|
||||
notify_property_list_changed();
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
queue_redraw();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CPUParticles2D::set_emission_sphere_radius(real_t p_radius) {
|
||||
if (p_radius == emission_sphere_radius) {
|
||||
return;
|
||||
}
|
||||
emission_sphere_radius = p_radius;
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
queue_redraw();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CPUParticles2D::set_emission_rect_extents(Vector2 p_extents) {
|
||||
if (p_extents == emission_rect_extents) {
|
||||
return;
|
||||
}
|
||||
emission_rect_extents = p_extents;
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
queue_redraw();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CPUParticles2D::set_emission_points(const Vector<Vector2> &p_points) {
|
||||
|
|
@ -569,6 +597,16 @@ void CPUParticles2D::set_seed(uint32_t p_seed) {
|
|||
seed = p_seed;
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
void CPUParticles2D::set_show_gizmos(bool p_show_gizmos) {
|
||||
if (show_gizmos == p_show_gizmos) {
|
||||
return;
|
||||
}
|
||||
show_gizmos = p_show_gizmos;
|
||||
queue_redraw();
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t CPUParticles2D::get_seed() const {
|
||||
return seed;
|
||||
}
|
||||
|
|
@ -637,7 +675,7 @@ static real_t rand_from_seed(uint32_t &seed) {
|
|||
}
|
||||
|
||||
void CPUParticles2D::_update_internal() {
|
||||
if (particles.size() == 0 || !is_visible_in_tree()) {
|
||||
if (particles.is_empty() || !is_visible_in_tree()) {
|
||||
_set_do_redraw(false);
|
||||
return;
|
||||
}
|
||||
|
|
@ -853,12 +891,12 @@ void CPUParticles2D::_particles_process(double p_delta) {
|
|||
//do none
|
||||
} break;
|
||||
case EMISSION_SHAPE_SPHERE: {
|
||||
real_t t = Math_TAU * rng->randf();
|
||||
real_t t = Math::TAU * rng->randf();
|
||||
real_t radius = emission_sphere_radius * rng->randf();
|
||||
p.transform[2] = Vector2(Math::cos(t), Math::sin(t)) * radius;
|
||||
} break;
|
||||
case EMISSION_SHAPE_SPHERE_SURFACE: {
|
||||
real_t s = rng->randf(), t = Math_TAU * rng->randf();
|
||||
real_t s = rng->randf(), t = Math::TAU * rng->randf();
|
||||
real_t radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
|
||||
p.transform[2] = Vector2(Math::cos(t), Math::sin(t)) * radius;
|
||||
} break;
|
||||
|
|
@ -975,7 +1013,7 @@ void CPUParticles2D::_particles_process(double p_delta) {
|
|||
//orbit velocity
|
||||
real_t orbit_amount = tex_orbit_velocity * Math::lerp(parameters_min[PARAM_ORBIT_VELOCITY], parameters_max[PARAM_ORBIT_VELOCITY], rand_from_seed(_seed));
|
||||
if (orbit_amount != 0.0) {
|
||||
real_t ang = orbit_amount * local_delta * Math_TAU;
|
||||
real_t ang = orbit_amount * local_delta * Math::TAU;
|
||||
// Not sure why the ParticleProcessMaterial code uses a clockwise rotation matrix,
|
||||
// but we use -ang here to reproduce its behavior.
|
||||
Transform2D rot = Transform2D(-ang, Vector2());
|
||||
|
|
@ -1029,7 +1067,7 @@ void CPUParticles2D::_particles_process(double p_delta) {
|
|||
tex_hue_variation = curve_parameters[PARAM_HUE_VARIATION]->sample(tv);
|
||||
}
|
||||
|
||||
real_t hue_rot_angle = (tex_hue_variation)*Math_TAU * Math::lerp(parameters_min[PARAM_HUE_VARIATION], parameters_max[PARAM_HUE_VARIATION], p.hue_rot_rand);
|
||||
real_t hue_rot_angle = (tex_hue_variation)*Math::TAU * Math::lerp(parameters_min[PARAM_HUE_VARIATION], parameters_max[PARAM_HUE_VARIATION], p.hue_rot_rand);
|
||||
real_t hue_rot_c = Math::cos(hue_rot_angle);
|
||||
real_t hue_rot_s = Math::sin(hue_rot_angle);
|
||||
|
||||
|
|
@ -1194,8 +1232,6 @@ void CPUParticles2D::_notification(int p_what) {
|
|||
|
||||
_refresh_interpolation_state();
|
||||
|
||||
set_physics_process_internal(emitting && _interpolation_data.interpolated_follow);
|
||||
|
||||
// If we are interpolated following, then reset physics interpolation
|
||||
// when first appearing. This won't be called by canvas item, as in the
|
||||
// following mode, is_physics_interpolated() is actually FALSE.
|
||||
|
|
@ -1224,6 +1260,13 @@ void CPUParticles2D::_notification(int p_what) {
|
|||
}
|
||||
|
||||
RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (show_gizmos) {
|
||||
_draw_emission_gizmo();
|
||||
}
|
||||
#endif
|
||||
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
|
|
@ -1245,6 +1288,11 @@ void CPUParticles2D::_notification(int p_what) {
|
|||
_interpolation_data.global_xform_curr = get_global_transform();
|
||||
}
|
||||
}
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (!local_coords) {
|
||||
queue_redraw();
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
|
||||
|
|
@ -1255,6 +1303,30 @@ void CPUParticles2D::_notification(int p_what) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
void CPUParticles2D::_draw_emission_gizmo() {
|
||||
Color emission_ring_color = Color(0.8, 0.7, 0.4, 0.4);
|
||||
Transform2D gizmo_transform;
|
||||
if (!local_coords) {
|
||||
gizmo_transform = get_global_transform();
|
||||
}
|
||||
|
||||
draw_set_transform_matrix(gizmo_transform);
|
||||
|
||||
switch (emission_shape) {
|
||||
case CPUParticles2D::EMISSION_SHAPE_RECTANGLE:
|
||||
draw_rect(Rect2(-emission_rect_extents, emission_rect_extents * 2.0), emission_ring_color, false);
|
||||
break;
|
||||
case CPUParticles2D::EMISSION_SHAPE_SPHERE:
|
||||
case CPUParticles2D::EMISSION_SHAPE_SPHERE_SURFACE:
|
||||
draw_circle(Vector2(), emission_sphere_radius, emission_ring_color, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void CPUParticles2D::convert_from_particles(Node *p_particles) {
|
||||
GPUParticles2D *gpu_particles = Object::cast_to<GPUParticles2D>(p_particles);
|
||||
ERR_FAIL_NULL_MSG(gpu_particles, "Only GPUParticles2D nodes can be converted to CPUParticles2D.");
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CPU_PARTICLES_2D_H
|
||||
#define CPU_PARTICLES_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -148,6 +147,10 @@ private:
|
|||
|
||||
Transform2D inv_emission_transform;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
bool show_gizmos = false;
|
||||
#endif
|
||||
|
||||
DrawOrder draw_order = DRAW_ORDER_INDEX;
|
||||
|
||||
Ref<Texture2D> texture;
|
||||
|
|
@ -212,6 +215,9 @@ private:
|
|||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
#ifdef TOOLS_ENABLED
|
||||
void _draw_emission_gizmo();
|
||||
#endif
|
||||
void _validate_property(PropertyInfo &p_property) const;
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
|
|
@ -258,6 +264,9 @@ public:
|
|||
bool get_use_fixed_seed() const;
|
||||
|
||||
void set_seed(uint32_t p_seed);
|
||||
#ifdef TOOLS_ENABLED
|
||||
void set_show_gizmos(bool p_show_gizmos);
|
||||
#endif
|
||||
uint32_t get_seed() const;
|
||||
|
||||
void request_particles_process(real_t p_requested_process_time);
|
||||
|
|
@ -328,5 +337,3 @@ VARIANT_ENUM_CAST(CPUParticles2D::DrawOrder)
|
|||
VARIANT_ENUM_CAST(CPUParticles2D::Parameter)
|
||||
VARIANT_ENUM_CAST(CPUParticles2D::ParticleFlags)
|
||||
VARIANT_ENUM_CAST(CPUParticles2D::EmissionShape)
|
||||
|
||||
#endif // CPU_PARTICLES_2D_H
|
||||
|
|
|
|||
|
|
@ -144,7 +144,22 @@ void GPUParticles2D::_update_particle_emission_transform() {
|
|||
}
|
||||
|
||||
void GPUParticles2D::set_process_material(const Ref<Material> &p_material) {
|
||||
if (process_material == p_material) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (process_material.is_valid() && process_material->is_class("ParticleProcessMaterial")) {
|
||||
process_material->disconnect("emission_shape_changed", callable_mp((CanvasItem *)this, &GPUParticles2D::queue_redraw));
|
||||
}
|
||||
|
||||
process_material = p_material;
|
||||
|
||||
if (process_material.is_valid() && process_material->is_class("ParticleProcessMaterial")) {
|
||||
process_material->connect("emission_shape_changed", callable_mp((CanvasItem *)this, &GPUParticles2D::queue_redraw));
|
||||
}
|
||||
|
||||
queue_redraw();
|
||||
|
||||
Ref<ParticleProcessMaterial> pm = p_material;
|
||||
if (pm.is_valid() && !pm->get_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_DISABLE_Z) && pm->get_gravity() == Vector3(0, -9.8, 0)) {
|
||||
// Likely a new (3D) material, modify it to match 2D space
|
||||
|
|
@ -198,8 +213,11 @@ void GPUParticles2D::set_interp_to_end(float p_interp) {
|
|||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
void GPUParticles2D::set_show_visibility_rect(bool p_show_visibility_rect) {
|
||||
show_visibility_rect = p_show_visibility_rect;
|
||||
void GPUParticles2D::set_show_gizmos(bool p_show_gizmos) {
|
||||
if (show_gizmos == p_show_gizmos) {
|
||||
return;
|
||||
}
|
||||
show_gizmos = p_show_gizmos;
|
||||
queue_redraw();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -370,11 +388,11 @@ PackedStringArray GPUParticles2D::get_configuration_warnings() const {
|
|||
}
|
||||
}
|
||||
|
||||
if (trail_enabled && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
|
||||
if (trail_enabled && (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" || OS::get_singleton()->get_current_rendering_method() == "dummy")) {
|
||||
warnings.push_back(RTR("Particle trails are only available when using the Forward+ or Mobile renderers."));
|
||||
}
|
||||
|
||||
if (sub_emitter != NodePath() && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
|
||||
if (sub_emitter != NodePath() && (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" || OS::get_singleton()->get_current_rendering_method() == "dummy")) {
|
||||
warnings.push_back(RTR("Particle sub-emitters are not available when using the Compatibility renderer."));
|
||||
}
|
||||
|
||||
|
|
@ -707,8 +725,9 @@ void GPUParticles2D::_notification(int p_what) {
|
|||
RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (show_visibility_rect) {
|
||||
if (show_gizmos) {
|
||||
draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false);
|
||||
_draw_emission_gizmo();
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
|
|
@ -784,6 +803,60 @@ void GPUParticles2D::_notification(int p_what) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
void GPUParticles2D::_draw_emission_gizmo() {
|
||||
Ref<ParticleProcessMaterial> pm = process_material;
|
||||
Color emission_ring_color = Color(0.8, 0.7, 0.4, 0.4);
|
||||
if (pm.is_null()) {
|
||||
return;
|
||||
}
|
||||
draw_set_transform(
|
||||
Vector2(pm->get_emission_shape_offset().x, pm->get_emission_shape_offset().y),
|
||||
0.0,
|
||||
Vector2(pm->get_emission_shape_scale().x, pm->get_emission_shape_scale().y));
|
||||
|
||||
switch (pm->get_emission_shape()) {
|
||||
case ParticleProcessMaterial::EmissionShape::EMISSION_SHAPE_BOX: {
|
||||
Vector2 extents2d = Vector2(pm->get_emission_box_extents().x, pm->get_emission_box_extents().y);
|
||||
draw_rect(Rect2(-extents2d, extents2d * 2.0), emission_ring_color, false);
|
||||
break;
|
||||
}
|
||||
case ParticleProcessMaterial::EmissionShape::EMISSION_SHAPE_SPHERE:
|
||||
case ParticleProcessMaterial::EmissionShape::EMISSION_SHAPE_SPHERE_SURFACE: {
|
||||
draw_circle(Vector2(), pm->get_emission_sphere_radius(), emission_ring_color, false);
|
||||
break;
|
||||
}
|
||||
case ParticleProcessMaterial::EmissionShape::EMISSION_SHAPE_RING: {
|
||||
Vector3 ring_axis = pm->get_emission_ring_axis();
|
||||
if (ring_axis.is_equal_approx(Vector3(0.0, 0.0, 1.0)) || ring_axis.is_zero_approx()) {
|
||||
draw_circle(Vector2(), pm->get_emission_ring_inner_radius(), emission_ring_color, false);
|
||||
draw_circle(Vector2(), pm->get_emission_ring_radius(), emission_ring_color, false);
|
||||
} else {
|
||||
Vector2 a = Vector2(pm->get_emission_ring_height() / -2.0, pm->get_emission_ring_radius() / -1.0);
|
||||
Vector2 b = Vector2(-a.x, MIN(a.y + tan((90.0 - pm->get_emission_ring_cone_angle()) * 0.01745329) * pm->get_emission_ring_height(), 0.0));
|
||||
Vector2 c = Vector2(b.x, -b.y);
|
||||
Vector2 d = Vector2(a.x, -a.y);
|
||||
if (ring_axis.is_equal_approx(Vector3(1.0, 0.0, 0.0))) {
|
||||
Vector<Vector2> pos = { a, b, b, c, c, d, d, a };
|
||||
draw_multiline(pos, emission_ring_color);
|
||||
} else if (ring_axis.is_equal_approx(Vector3(0.0, 1.0, 0.0))) {
|
||||
a = Vector2(a.y, a.x);
|
||||
b = Vector2(b.y, b.x);
|
||||
c = Vector2(c.y, c.x);
|
||||
d = Vector2(d.y, d.x);
|
||||
Vector<Vector2> pos = { a, b, b, c, c, d, d, a };
|
||||
draw_multiline(pos, emission_ring_color);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void GPUParticles2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &GPUParticles2D::set_emitting);
|
||||
ClassDB::bind_method(D_METHOD("set_amount", "amount"), &GPUParticles2D::set_amount);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef GPU_PARTICLES_2D_H
|
||||
#define GPU_PARTICLES_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -69,7 +68,7 @@ private:
|
|||
uint32_t seed = 0;
|
||||
bool use_fixed_seed = false;
|
||||
#ifdef TOOLS_ENABLED
|
||||
bool show_visibility_rect = false;
|
||||
bool show_gizmos = false;
|
||||
#endif
|
||||
Ref<Material> process_material;
|
||||
|
||||
|
|
@ -101,6 +100,9 @@ protected:
|
|||
static void _bind_methods();
|
||||
void _validate_property(PropertyInfo &p_property) const;
|
||||
void _notification(int p_what);
|
||||
#ifdef TOOLS_ENABLED
|
||||
void _draw_emission_gizmo();
|
||||
#endif
|
||||
void _update_collision_size();
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
|
|
@ -129,7 +131,7 @@ public:
|
|||
void request_particles_process(real_t p_requested_process_time);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
void set_show_visibility_rect(bool p_show_visibility_rect);
|
||||
void set_show_gizmos(bool p_show_gizmos);
|
||||
#endif
|
||||
|
||||
bool is_emitting() const;
|
||||
|
|
@ -200,5 +202,3 @@ public:
|
|||
|
||||
VARIANT_ENUM_CAST(GPUParticles2D::DrawOrder)
|
||||
VARIANT_ENUM_CAST(GPUParticles2D::EmitFlags)
|
||||
|
||||
#endif // GPU_PARTICLES_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef LIGHT_2D_H
|
||||
#define LIGHT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -197,5 +196,3 @@ public:
|
|||
|
||||
DirectionalLight2D();
|
||||
};
|
||||
|
||||
#endif // LIGHT_2D_H
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ Rect2 OccluderPolygon2D::_edit_get_rect() const {
|
|||
}
|
||||
rect_cache_dirty = false;
|
||||
} else {
|
||||
if (polygon.size() == 0) {
|
||||
if (polygon.is_empty()) {
|
||||
item_rect = Rect2();
|
||||
} else {
|
||||
Vector2 d = Vector2(LINE_GRAB_WIDTH, LINE_GRAB_WIDTH);
|
||||
|
|
@ -74,7 +74,7 @@ bool OccluderPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, double
|
|||
const real_t d = LINE_GRAB_WIDTH / 2 + p_tolerance;
|
||||
const Vector2 *points = polygon.ptr();
|
||||
for (int i = 0; i < polygon.size() - 1; i++) {
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, &points[i]);
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, points[i], points[i + 1]);
|
||||
if (p.distance_to(p_point) <= d) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -270,7 +270,7 @@ PackedStringArray LightOccluder2D::get_configuration_warnings() const {
|
|||
warnings.push_back(RTR("An occluder polygon must be set (or drawn) for this occluder to take effect."));
|
||||
}
|
||||
|
||||
if (occluder_polygon.is_valid() && occluder_polygon->get_polygon().size() == 0) {
|
||||
if (occluder_polygon.is_valid() && occluder_polygon->get_polygon().is_empty()) {
|
||||
warnings.push_back(RTR("The occluder polygon for this occluder is empty. Please draw a polygon."));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef LIGHT_OCCLUDER_2D_H
|
||||
#define LIGHT_OCCLUDER_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -111,5 +110,3 @@ public:
|
|||
LightOccluder2D();
|
||||
~LightOccluder2D();
|
||||
};
|
||||
|
||||
#endif // LIGHT_OCCLUDER_2D_H
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ Line2D::Line2D() {
|
|||
|
||||
#ifdef DEBUG_ENABLED
|
||||
Rect2 Line2D::_edit_get_rect() const {
|
||||
if (_points.size() == 0) {
|
||||
if (_points.is_empty()) {
|
||||
return Rect2(0, 0, 0, 0);
|
||||
}
|
||||
Vector2 min = _points[0];
|
||||
|
|
@ -58,14 +58,14 @@ bool Line2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc
|
|||
const real_t d = _width / 2 + p_tolerance;
|
||||
const Vector2 *points = _points.ptr();
|
||||
for (int i = 0; i < _points.size() - 1; i++) {
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, &points[i]);
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, points[i], points[i + 1]);
|
||||
if (p_point.distance_to(p) <= d) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Closing segment between the first and last point.
|
||||
if (_closed && _points.size() > 2) {
|
||||
const Vector2 closing_segment[2] = { points[0], points[_points.size() - 1] };
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, closing_segment);
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, points[0], points[_points.size() - 1]);
|
||||
if (p_point.distance_to(p) <= d) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef LINE_2D_H
|
||||
#define LINE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "node_2d.h"
|
||||
|
||||
|
|
@ -146,5 +145,3 @@ private:
|
|||
VARIANT_ENUM_CAST(Line2D::LineJointMode)
|
||||
VARIANT_ENUM_CAST(Line2D::LineCapMode)
|
||||
VARIANT_ENUM_CAST(Line2D::LineTextureMode)
|
||||
|
||||
#endif // LINE_2D_H
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ void LineBuilder::build() {
|
|||
} else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
|
||||
uvx0 = width * width_factor / total_distance;
|
||||
}
|
||||
new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, uvx0 * 2, 1.f));
|
||||
new_arc(pos0, pos_up0 - pos0, -Math::PI, color0, Rect2(0.f, 0.f, uvx0 * 2, 1.f));
|
||||
current_distance0 += modified_hw;
|
||||
current_distance1 = current_distance0;
|
||||
}
|
||||
|
|
@ -426,7 +426,7 @@ void LineBuilder::build() {
|
|||
} else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
|
||||
dist = width * width_factor / total_distance;
|
||||
}
|
||||
new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f * dist, 0.f, dist, 1.f));
|
||||
new_arc(pos1, pos_up1 - pos1, Math::PI, color, Rect2(uvx1 - 0.5f * dist, 0.f, dist, 1.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -509,7 +509,7 @@ void LineBuilder::strip_add_arc(Vector2 center, float angle_delta, Orientation o
|
|||
Orientation opposite_orientation = orientation == UP ? DOWN : UP;
|
||||
Vector2 vbegin = vertices[_last_index[opposite_orientation]] - center;
|
||||
float radius = vbegin.length();
|
||||
float angle_step = Math_PI / static_cast<float>(round_precision);
|
||||
float angle_step = Math::PI / static_cast<float>(round_precision);
|
||||
float steps = Math::abs(angle_delta) / angle_step;
|
||||
|
||||
if (angle_delta < 0.f) {
|
||||
|
|
@ -536,7 +536,7 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col
|
|||
// with undistorted UVs from within a square section
|
||||
|
||||
float radius = vbegin.length();
|
||||
float angle_step = Math_PI / static_cast<float>(round_precision);
|
||||
float angle_step = Math::PI / static_cast<float>(round_precision);
|
||||
float steps = Math::abs(angle_delta) / angle_step;
|
||||
|
||||
if (angle_delta < 0.f) {
|
||||
|
|
@ -546,7 +546,7 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col
|
|||
float t = Vector2(1, 0).angle_to(vbegin);
|
||||
float end_angle = t + angle_delta;
|
||||
Vector2 rpos(0, 0);
|
||||
float tt_begin = -Math_PI / 2.0f;
|
||||
float tt_begin = -Math::PI / 2.0f;
|
||||
float tt = tt_begin;
|
||||
|
||||
// Center vertice
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef LINE_BUILDER_H
|
||||
#define LINE_BUILDER_H
|
||||
#pragma once
|
||||
|
||||
#include "line_2d.h"
|
||||
|
||||
|
|
@ -82,5 +81,3 @@ private:
|
|||
bool _interpolate_color = false;
|
||||
int _last_index[2] = {}; // Index of last up and down vertices of the strip
|
||||
};
|
||||
|
||||
#endif // LINE_BUILDER_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef MARKER_2D_H
|
||||
#define MARKER_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -55,5 +54,3 @@ public:
|
|||
|
||||
Marker2D();
|
||||
};
|
||||
|
||||
#endif // MARKER_2D_H
|
||||
|
|
|
|||
|
|
@ -30,13 +30,14 @@
|
|||
|
||||
#include "mesh_instance_2d.h"
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
#include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"
|
||||
#include "scene/resources/2d/navigation_polygon.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
|
||||
#include "thirdparty/clipper2/include/clipper2/clipper.h"
|
||||
#include "thirdparty/misc/polypartition.h"
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
Callable MeshInstance2D::_navmesh_source_geometry_parsing_callback;
|
||||
RID MeshInstance2D::_navmesh_source_geometry_parser;
|
||||
|
|
@ -117,6 +118,7 @@ bool MeshInstance2D::_edit_use_rect() const {
|
|||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void MeshInstance2D::navmesh_parse_init() {
|
||||
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
|
||||
if (!_navmesh_source_geometry_parser.is_valid()) {
|
||||
|
|
@ -211,6 +213,7 @@ void MeshInstance2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon>
|
|||
p_source_geometry_data->add_obstruction_outline(shape_outline);
|
||||
}
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
MeshInstance2D::MeshInstance2D() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef MESH_INSTANCE_2D_H
|
||||
#define MESH_INSTANCE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -64,10 +63,10 @@ private:
|
|||
static RID _navmesh_source_geometry_parser;
|
||||
|
||||
public:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
static void navmesh_parse_init();
|
||||
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
MeshInstance2D();
|
||||
};
|
||||
|
||||
#endif // MESH_INSTANCE_2D_H
|
||||
|
|
|
|||
|
|
@ -30,13 +30,14 @@
|
|||
|
||||
#include "multimesh_instance_2d.h"
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
#include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"
|
||||
#include "scene/resources/2d/navigation_polygon.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
|
||||
#include "thirdparty/clipper2/include/clipper2/clipper.h"
|
||||
#include "thirdparty/misc/polypartition.h"
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
Callable MultiMeshInstance2D::_navmesh_source_geometry_parsing_callback;
|
||||
RID MultiMeshInstance2D::_navmesh_source_geometry_parser;
|
||||
|
|
@ -106,6 +107,7 @@ Rect2 MultiMeshInstance2D::_edit_get_rect() const {
|
|||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void MultiMeshInstance2D::navmesh_parse_init() {
|
||||
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
|
||||
if (!_navmesh_source_geometry_parser.is_valid()) {
|
||||
|
|
@ -209,6 +211,7 @@ void MultiMeshInstance2D::navmesh_parse_source_geometry(const Ref<NavigationPoly
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
MultiMeshInstance2D::MultiMeshInstance2D() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef MULTIMESH_INSTANCE_2D_H
|
||||
#define MULTIMESH_INSTANCE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/multimesh.h"
|
||||
|
|
@ -64,11 +63,11 @@ private:
|
|||
static RID _navmesh_source_geometry_parser;
|
||||
|
||||
public:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
static void navmesh_parse_init();
|
||||
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
MultiMeshInstance2D();
|
||||
~MultiMeshInstance2D();
|
||||
};
|
||||
|
||||
#endif // MULTIMESH_INSTANCE_2D_H
|
||||
|
|
|
|||
6
engine/scene/2d/navigation/SCsub
Normal file
6
engine/scene/2d/navigation/SCsub
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.scene_sources, "*.cpp")
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
#include "navigation_agent_2d.h"
|
||||
|
||||
#include "core/math/geometry_2d.h"
|
||||
#include "scene/2d/navigation_link_2d.h"
|
||||
#include "scene/2d/navigation/navigation_link_2d.h"
|
||||
#include "scene/resources/world_2d.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
|
||||
|
|
@ -594,7 +594,7 @@ Vector2 NavigationAgent2D::get_next_path_position() {
|
|||
_update_navigation();
|
||||
|
||||
const Vector<Vector2> &navigation_path = navigation_result->get_path();
|
||||
if (navigation_path.size() == 0) {
|
||||
if (navigation_path.is_empty()) {
|
||||
ERR_FAIL_NULL_V_MSG(agent_parent, Vector2(), "The agent has no parent.");
|
||||
return agent_parent->get_global_position();
|
||||
} else {
|
||||
|
|
@ -632,7 +632,7 @@ Vector2 NavigationAgent2D::get_final_position() {
|
|||
|
||||
Vector2 NavigationAgent2D::_get_final_position() const {
|
||||
const Vector<Vector2> &navigation_path = navigation_result->get_path();
|
||||
if (navigation_path.size() == 0) {
|
||||
if (navigation_path.is_empty()) {
|
||||
return Vector2();
|
||||
}
|
||||
return navigation_path[navigation_path.size() - 1];
|
||||
|
|
@ -685,17 +685,16 @@ void NavigationAgent2D::_update_navigation() {
|
|||
|
||||
if (NavigationServer2D::get_singleton()->agent_is_map_changed(agent)) {
|
||||
reload_path = true;
|
||||
} else if (navigation_result->get_path().size() == 0) {
|
||||
} else if (navigation_result->get_path().is_empty()) {
|
||||
reload_path = true;
|
||||
} else {
|
||||
// Check if too far from the navigation path
|
||||
if (navigation_path_index > 0) {
|
||||
const Vector<Vector2> &navigation_path = navigation_result->get_path();
|
||||
|
||||
Vector2 segment[2];
|
||||
segment[0] = navigation_path[navigation_path_index - 1];
|
||||
segment[1] = navigation_path[navigation_path_index];
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(origin, segment);
|
||||
const Vector2 segment_a = navigation_path[navigation_path_index - 1];
|
||||
const Vector2 segment_b = navigation_path[navigation_path_index];
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(origin, segment_a, segment_b);
|
||||
if (origin.distance_to(p) >= path_max_distance) {
|
||||
// To faraway, reload path
|
||||
reload_path = true;
|
||||
|
|
@ -725,7 +724,7 @@ void NavigationAgent2D::_update_navigation() {
|
|||
emit_signal(SNAME("path_changed"));
|
||||
}
|
||||
|
||||
if (navigation_result->get_path().size() == 0) {
|
||||
if (navigation_result->get_path().is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef NAVIGATION_AGENT_2D_H
|
||||
#define NAVIGATION_AGENT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/main/node.h"
|
||||
#include "servers/navigation/navigation_path_query_parameters_2d.h"
|
||||
|
|
@ -260,5 +259,3 @@ private:
|
|||
void _update_debug_path();
|
||||
#endif // DEBUG_ENABLED
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_AGENT_2D_H
|
||||
|
|
@ -146,9 +146,7 @@ Rect2 NavigationLink2D::_edit_get_rect() const {
|
|||
}
|
||||
|
||||
bool NavigationLink2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
|
||||
Point2 segment[2] = { get_start_position(), get_end_position() };
|
||||
|
||||
Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, segment);
|
||||
Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, get_start_position(), get_end_position());
|
||||
return p_point.distance_to(closest_point) < p_tolerance;
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
|
@ -398,8 +396,8 @@ void NavigationLink2D::_update_debug_mesh() {
|
|||
real_t radius = NavigationServer2D::get_singleton()->map_get_link_connection_radius(get_world_2d()->get_navigation_map());
|
||||
|
||||
draw_line(get_start_position(), get_end_position(), color);
|
||||
draw_arc(get_start_position(), radius, 0, Math_TAU, 10, color);
|
||||
draw_arc(get_end_position(), radius, 0, Math_TAU, 10, color);
|
||||
draw_arc(get_start_position(), radius, 0, Math::TAU, 10, color);
|
||||
draw_arc(get_end_position(), radius, 0, Math::TAU, 10, color);
|
||||
|
||||
const Vector2 link_segment = end_position - start_position;
|
||||
const float arror_len = 5.0;
|
||||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef NAVIGATION_LINK_2D_H
|
||||
#define NAVIGATION_LINK_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -111,5 +110,3 @@ private:
|
|||
void _link_exit_navigation_map();
|
||||
void _link_update_transform();
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_LINK_2D_H
|
||||
|
|
@ -382,7 +382,7 @@ void NavigationObstacle2D::navmesh_parse_source_geometry(const Ref<NavigationPol
|
|||
|
||||
obstruction_circle_vertices.resize(circle_points);
|
||||
Vector2 *circle_vertices_ptrw = obstruction_circle_vertices.ptrw();
|
||||
const real_t circle_point_step = Math_TAU / circle_points;
|
||||
const real_t circle_point_step = Math::TAU / circle_points;
|
||||
|
||||
for (int i = 0; i < circle_points; i++) {
|
||||
const float angle = i * circle_point_step;
|
||||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef NAVIGATION_OBSTACLE_2D_H
|
||||
#define NAVIGATION_OBSTACLE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -131,5 +130,3 @@ private:
|
|||
void _update_position(const Vector2 p_position);
|
||||
void _update_transform();
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_OBSTACLE_2D_H
|
||||
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "navigation_region_2d.h"
|
||||
|
||||
#include "core/math/random_pcg.h"
|
||||
#include "scene/resources/world_2d.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
|
||||
|
|
@ -181,7 +182,7 @@ void NavigationRegion2D::_notification(int p_what) {
|
|||
|
||||
case NOTIFICATION_DRAW: {
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) && navigation_polygon.is_valid()) {
|
||||
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || (NavigationServer2D::get_singleton()->get_debug_enabled() && NavigationServer2D::get_singleton()->get_debug_navigation_enabled())) && navigation_polygon.is_valid()) {
|
||||
_update_debug_mesh();
|
||||
_update_debug_edge_connections_mesh();
|
||||
_update_debug_baking_rect();
|
||||
|
|
@ -197,27 +198,12 @@ void NavigationRegion2D::set_navigation_polygon(const Ref<NavigationPolygon> &p_
|
|||
}
|
||||
|
||||
navigation_polygon = p_navigation_polygon;
|
||||
#ifdef DEBUG_ENABLED
|
||||
debug_mesh_dirty = true;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
_update_bounds();
|
||||
|
||||
NavigationServer2D::get_singleton()->region_set_navigation_polygon(region, p_navigation_polygon);
|
||||
|
||||
if (navigation_polygon.is_valid()) {
|
||||
navigation_polygon->connect_changed(callable_mp(this, &NavigationRegion2D::_navigation_polygon_changed));
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (navigation_polygon.is_null()) {
|
||||
_set_debug_visible(false);
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
_navigation_polygon_changed();
|
||||
|
||||
update_configuration_warnings();
|
||||
}
|
||||
|
||||
Ref<NavigationPolygon> NavigationRegion2D::get_navigation_polygon() const {
|
||||
|
|
@ -253,19 +239,18 @@ void NavigationRegion2D::bake_navigation_polygon(bool p_on_thread) {
|
|||
NavigationServer2D::get_singleton()->parse_source_geometry_data(navigation_polygon, source_geometry_data, this);
|
||||
|
||||
if (p_on_thread) {
|
||||
NavigationServer2D::get_singleton()->bake_from_source_geometry_data_async(navigation_polygon, source_geometry_data, callable_mp(this, &NavigationRegion2D::_bake_finished).bind(navigation_polygon));
|
||||
NavigationServer2D::get_singleton()->bake_from_source_geometry_data_async(navigation_polygon, source_geometry_data, callable_mp(this, &NavigationRegion2D::_bake_finished));
|
||||
} else {
|
||||
NavigationServer2D::get_singleton()->bake_from_source_geometry_data(navigation_polygon, source_geometry_data, callable_mp(this, &NavigationRegion2D::_bake_finished).bind(navigation_polygon));
|
||||
NavigationServer2D::get_singleton()->bake_from_source_geometry_data(navigation_polygon, source_geometry_data, callable_mp(this, &NavigationRegion2D::_bake_finished));
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationRegion2D::_bake_finished(Ref<NavigationPolygon> p_navigation_polygon) {
|
||||
void NavigationRegion2D::_bake_finished() {
|
||||
if (!Thread::is_main_thread()) {
|
||||
callable_mp(this, &NavigationRegion2D::_bake_finished).call_deferred(p_navigation_polygon);
|
||||
callable_mp(this, &NavigationRegion2D::_bake_finished).call_deferred();
|
||||
return;
|
||||
}
|
||||
|
||||
set_navigation_polygon(p_navigation_polygon);
|
||||
emit_signal(SNAME("bake_finished"));
|
||||
}
|
||||
|
||||
|
|
@ -274,12 +259,25 @@ bool NavigationRegion2D::is_baking() const {
|
|||
}
|
||||
|
||||
void NavigationRegion2D::_navigation_polygon_changed() {
|
||||
_update_bounds();
|
||||
|
||||
NavigationServer2D::get_singleton()->region_set_navigation_polygon(region, navigation_polygon);
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
debug_mesh_dirty = true;
|
||||
|
||||
if (navigation_polygon.is_null()) {
|
||||
_set_debug_visible(false);
|
||||
}
|
||||
|
||||
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) {
|
||||
queue_redraw();
|
||||
}
|
||||
if (navigation_polygon.is_valid()) {
|
||||
NavigationServer2D::get_singleton()->region_set_navigation_polygon(region, navigation_polygon);
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
emit_signal(SNAME("navigation_polygon_changed"));
|
||||
|
||||
update_configuration_warnings();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
|
@ -625,8 +623,8 @@ void NavigationRegion2D::_update_debug_edge_connections_mesh() {
|
|||
|
||||
// Draw a circle to illustrate the margins.
|
||||
real_t angle = a.angle_to_point(b);
|
||||
draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, debug_edge_connection_color);
|
||||
draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, debug_edge_connection_color);
|
||||
draw_arc(a, radius, angle + Math::PI / 2.0, angle - Math::PI / 2.0 + Math::TAU, 10, debug_edge_connection_color);
|
||||
draw_arc(b, radius, angle - Math::PI / 2.0, angle + Math::PI / 2.0, 10, debug_edge_connection_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef NAVIGATION_REGION_2D_H
|
||||
#define NAVIGATION_REGION_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/resources/2d/navigation_polygon.h"
|
||||
|
||||
|
|
@ -112,7 +111,7 @@ public:
|
|||
PackedStringArray get_configuration_warnings() const override;
|
||||
|
||||
void bake_navigation_polygon(bool p_on_thread);
|
||||
void _bake_finished(Ref<NavigationPolygon> p_navigation_polygon);
|
||||
void _bake_finished();
|
||||
bool is_baking() const;
|
||||
|
||||
Rect2 get_bounds() const { return bounds; }
|
||||
|
|
@ -126,5 +125,3 @@ private:
|
|||
void _region_exit_navigation_map();
|
||||
void _region_update_transform();
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_REGION_2D_H
|
||||
|
|
@ -429,6 +429,13 @@ Point2 Node2D::to_global(Point2 p_local) const {
|
|||
|
||||
void Node2D::_notification(int p_notification) {
|
||||
switch (p_notification) {
|
||||
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
|
||||
RID ae = get_accessibility_element();
|
||||
ERR_FAIL_COND(ae.is_null());
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_CONTAINER);
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
ERR_MAIN_THREAD_GUARD;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef NODE_2D_H
|
||||
#define NODE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/main/canvas_item.h"
|
||||
|
||||
|
|
@ -119,5 +118,3 @@ public:
|
|||
|
||||
Node2D() {}
|
||||
};
|
||||
|
||||
#endif // NODE_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PARALLAX_2D_H
|
||||
#define PARALLAX_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -96,5 +95,3 @@ public:
|
|||
|
||||
Parallax2D();
|
||||
};
|
||||
|
||||
#endif // PARALLAX_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PARALLAX_BACKGROUND_H
|
||||
#define PARALLAX_BACKGROUND_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/main/canvas_layer.h"
|
||||
|
||||
|
|
@ -81,5 +80,3 @@ public:
|
|||
|
||||
ParallaxBackground();
|
||||
};
|
||||
|
||||
#endif // PARALLAX_BACKGROUND_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PARALLAX_LAYER_H
|
||||
#define PARALLAX_LAYER_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -62,5 +61,3 @@ public:
|
|||
PackedStringArray get_configuration_warnings() const override;
|
||||
ParallaxLayer();
|
||||
};
|
||||
|
||||
#endif // PARALLAX_LAYER_H
|
||||
|
|
|
|||
|
|
@ -66,19 +66,18 @@ bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc
|
|||
}
|
||||
|
||||
for (int i = 0; i < curve->get_point_count(); i++) {
|
||||
Vector2 s[2];
|
||||
s[0] = curve->get_point_position(i);
|
||||
Vector2 segment_a = curve->get_point_position(i);
|
||||
|
||||
for (int j = 1; j <= 8; j++) {
|
||||
real_t frac = j / 8.0;
|
||||
s[1] = curve->sample(i, frac);
|
||||
const Vector2 segment_b = curve->sample(i, frac);
|
||||
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, s);
|
||||
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, segment_a, segment_b);
|
||||
if (p.distance_to(p_point) <= p_tolerance) {
|
||||
return true;
|
||||
}
|
||||
|
||||
s[0] = s[1];
|
||||
segment_a = segment_b;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PATH_2D_H
|
||||
#define PATH_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/curve.h"
|
||||
|
|
@ -110,5 +109,3 @@ public:
|
|||
|
||||
PathFollow2D() {}
|
||||
};
|
||||
|
||||
#endif // PATH_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef ANIMATABLE_BODY_2D_H
|
||||
#define ANIMATABLE_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/static_body_2d.h"
|
||||
|
||||
|
|
@ -57,5 +56,3 @@ private:
|
|||
void set_sync_to_physics(bool p_enable);
|
||||
bool is_sync_to_physics_enabled() const;
|
||||
};
|
||||
|
||||
#endif // ANIMATABLE_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef AREA_2D_H
|
||||
#define AREA_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "core/templates/vset.h"
|
||||
#include "scene/2d/physics/collision_object_2d.h"
|
||||
|
|
@ -198,5 +197,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(Area2D::SpaceOverride);
|
||||
|
||||
#endif // AREA_2D_H
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ void CharacterBody2D::_set_collision_direction(const PhysicsServer2D::MotionResu
|
|||
on_wall = true;
|
||||
wall_normal = p_result.collision_normal;
|
||||
// Don't apply wall velocity when the collider is a CharacterBody2D.
|
||||
if (Object::cast_to<CharacterBody2D>(ObjectDB::get_instance(p_result.collider_id)) == nullptr) {
|
||||
if (ObjectDB::get_instance<CharacterBody2D>(p_result.collider_id) == nullptr) {
|
||||
_set_platform_data(p_result);
|
||||
}
|
||||
}
|
||||
|
|
@ -509,7 +509,7 @@ Ref<KinematicCollision2D> CharacterBody2D::_get_slide_collision(int p_bounce) {
|
|||
}
|
||||
|
||||
Ref<KinematicCollision2D> CharacterBody2D::_get_last_slide_collision() {
|
||||
if (motion_results.size() == 0) {
|
||||
if (motion_results.is_empty()) {
|
||||
return Ref<KinematicCollision2D>();
|
||||
}
|
||||
return _get_slide_collision(motion_results.size() - 1);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CHARACTER_BODY_2D_H
|
||||
#define CHARACTER_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/kinematic_collision_2d.h"
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
|
@ -168,5 +167,3 @@ protected:
|
|||
|
||||
VARIANT_ENUM_CAST(CharacterBody2D::MotionMode);
|
||||
VARIANT_ENUM_CAST(CharacterBody2D::PlatformOnLeave);
|
||||
|
||||
#endif // CHARACTER_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) {
|
|||
ShapeData sd;
|
||||
uint32_t id;
|
||||
|
||||
if (shapes.size() == 0) {
|
||||
if (shapes.is_empty()) {
|
||||
id = 0;
|
||||
} else {
|
||||
id = shapes.back()->key() + 1;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef COLLISION_OBJECT_2D_H
|
||||
#define COLLISION_OBJECT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
|
@ -175,5 +174,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(CollisionObject2D::DisableMode);
|
||||
|
||||
#endif // COLLISION_OBJECT_2D_H
|
||||
|
|
|
|||
|
|
@ -157,8 +157,8 @@ void CollisionPolygon2D::_notification(int p_what) {
|
|||
|
||||
Vector<Vector2> pts = {
|
||||
line_to + Vector2(0, tsize),
|
||||
line_to + Vector2(Math_SQRT12 * tsize, 0),
|
||||
line_to + Vector2(-Math_SQRT12 * tsize, 0)
|
||||
line_to + Vector2(Math::SQRT12 * tsize, 0),
|
||||
line_to + Vector2(-Math::SQRT12 * tsize, 0)
|
||||
};
|
||||
|
||||
Vector<Color> cols{ dcol, dcol, dcol };
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef COLLISION_POLYGON_2D_H
|
||||
#define COLLISION_POLYGON_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -92,5 +91,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(CollisionPolygon2D::BuildMode);
|
||||
|
||||
#endif // COLLISION_POLYGON_2D_H
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ void CollisionShape2D::_notification(int p_what) {
|
|||
|
||||
Vector<Vector2> pts{
|
||||
line_to + Vector2(0, tsize),
|
||||
line_to + Vector2(Math_SQRT12 * tsize, 0),
|
||||
line_to + Vector2(-Math_SQRT12 * tsize, 0)
|
||||
line_to + Vector2(Math::SQRT12 * tsize, 0),
|
||||
line_to + Vector2(-Math::SQRT12 * tsize, 0)
|
||||
};
|
||||
|
||||
Vector<Color> cols{ draw_col, draw_col, draw_col };
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef COLLISION_SHAPE_2D_H
|
||||
#define COLLISION_SHAPE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/2d/shape_2d.h"
|
||||
|
|
@ -91,5 +90,3 @@ public:
|
|||
|
||||
CollisionShape2D();
|
||||
};
|
||||
|
||||
#endif // COLLISION_SHAPE_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef DAMPED_SPRING_JOINT_2D_H
|
||||
#define DAMPED_SPRING_JOINT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/joints/joint_2d.h"
|
||||
|
||||
|
|
@ -63,5 +62,3 @@ public:
|
|||
|
||||
DampedSpringJoint2D();
|
||||
};
|
||||
|
||||
#endif // DAMPED_SPRING_JOINT_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef GROOVE_JOINT_2D_H
|
||||
#define GROOVE_JOINT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/joints/joint_2d.h"
|
||||
|
||||
|
|
@ -55,5 +54,3 @@ public:
|
|||
|
||||
GrooveJoint2D();
|
||||
};
|
||||
|
||||
#endif // GROOVE_JOINT_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef JOINT_2D_H
|
||||
#define JOINT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -80,5 +79,3 @@ public:
|
|||
Joint2D();
|
||||
~Joint2D();
|
||||
};
|
||||
|
||||
#endif // JOINT_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PIN_JOINT_2D_H
|
||||
#define PIN_JOINT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/joints/joint_2d.h"
|
||||
|
||||
|
|
@ -67,5 +66,3 @@ public:
|
|||
|
||||
PinJoint2D();
|
||||
};
|
||||
|
||||
#endif // PIN_JOINT_2D_H
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ real_t KinematicCollision2D::get_depth() const {
|
|||
}
|
||||
|
||||
Object *KinematicCollision2D::get_local_shape() const {
|
||||
PhysicsBody2D *owner = Object::cast_to<PhysicsBody2D>(ObjectDB::get_instance(owner_id));
|
||||
PhysicsBody2D *owner = ObjectDB::get_instance<PhysicsBody2D>(owner_id);
|
||||
if (!owner) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef KINEMATIC_COLLISION_2D_H
|
||||
#define KINEMATIC_COLLISION_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/ref_counted.h"
|
||||
#include "servers/physics_server_2d.h"
|
||||
|
|
@ -63,5 +62,3 @@ public:
|
|||
int get_collider_shape_index() const;
|
||||
Vector2 get_collider_velocity() const;
|
||||
};
|
||||
|
||||
#endif // KINEMATIC_COLLISION_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PHYSICAL_BONE_2D_H
|
||||
#define PHYSICAL_BONE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/rigid_body_2d.h"
|
||||
#include "scene/2d/skeleton_2d.h"
|
||||
|
|
@ -84,5 +83,3 @@ public:
|
|||
PhysicalBone2D();
|
||||
~PhysicalBone2D();
|
||||
};
|
||||
|
||||
#endif // PHYSICAL_BONE_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PHYSICS_BODY_2D_H
|
||||
#define PHYSICS_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/collision_object_2d.h"
|
||||
#include "scene/2d/physics/kinematic_collision_2d.h"
|
||||
|
|
@ -56,5 +55,3 @@ public:
|
|||
void add_collision_exception_with(Node *p_node); //must be physicsbody
|
||||
void remove_collision_exception_with(Node *p_node);
|
||||
};
|
||||
|
||||
#endif // PHYSICS_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef RAY_CAST_2D_H
|
||||
#define RAY_CAST_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -105,5 +104,3 @@ public:
|
|||
|
||||
RayCast2D();
|
||||
};
|
||||
|
||||
#endif // RAY_CAST_2D_H
|
||||
|
|
|
|||
|
|
@ -498,6 +498,7 @@ bool RigidBody2D::is_sleeping() const {
|
|||
}
|
||||
|
||||
void RigidBody2D::set_max_contacts_reported(int p_amount) {
|
||||
ERR_FAIL_INDEX_MSG(p_amount, MAX_CONTACTS_REPORTED_2D_MAX, "Max contacts reported allocates memory (about 100 bytes each), and therefore must not be set too high.");
|
||||
max_contacts_reported = p_amount;
|
||||
PhysicsServer2D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount);
|
||||
}
|
||||
|
|
@ -643,7 +644,7 @@ PackedStringArray RigidBody2D::get_configuration_warnings() const {
|
|||
|
||||
PackedStringArray warnings = PhysicsBody2D::get_configuration_warnings();
|
||||
|
||||
if (ABS(t.columns[0].length() - 1.0) > 0.05 || ABS(t.columns[1].length() - 1.0) > 0.05) {
|
||||
if (Math::abs(t.columns[0].length() - 1.0) > 0.05 || Math::abs(t.columns[1].length() - 1.0) > 0.05) {
|
||||
warnings.push_back(RTR("Size changes to RigidBody2D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef RIGID_BODY_2D_H
|
||||
#define RIGID_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "core/templates/vset.h"
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
|
@ -246,5 +245,3 @@ VARIANT_ENUM_CAST(RigidBody2D::FreezeMode);
|
|||
VARIANT_ENUM_CAST(RigidBody2D::CenterOfMassMode);
|
||||
VARIANT_ENUM_CAST(RigidBody2D::DampMode);
|
||||
VARIANT_ENUM_CAST(RigidBody2D::CCDMode);
|
||||
|
||||
#endif // RIGID_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef SHAPE_CAST_2D_H
|
||||
#define SHAPE_CAST_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/2d/shape_2d.h"
|
||||
|
|
@ -122,5 +121,3 @@ public:
|
|||
|
||||
ShapeCast2D();
|
||||
};
|
||||
|
||||
#endif // SHAPE_CAST_2D_H
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "static_body_2d.h"
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
#include "scene/resources/2d/capsule_shape_2d.h"
|
||||
#include "scene/resources/2d/circle_shape_2d.h"
|
||||
#include "scene/resources/2d/concave_polygon_shape_2d.h"
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
#include "scene/resources/2d/navigation_polygon.h"
|
||||
#include "scene/resources/2d/rectangle_shape_2d.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
Callable StaticBody2D::_navmesh_source_geometry_parsing_callback;
|
||||
RID StaticBody2D::_navmesh_source_geometry_parser;
|
||||
|
|
@ -89,6 +91,7 @@ void StaticBody2D::_reload_physics_characteristics() {
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void StaticBody2D::navmesh_parse_init() {
|
||||
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
|
||||
if (!_navmesh_source_geometry_parser.is_valid()) {
|
||||
|
|
@ -156,7 +159,7 @@ void StaticBody2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
|
|||
const real_t capsule_radius = capsule_shape->get_radius();
|
||||
|
||||
Vector<Vector2> shape_outline;
|
||||
const real_t turn_step = Math_TAU / 12.0;
|
||||
const real_t turn_step = Math::TAU / 12.0;
|
||||
shape_outline.resize(14);
|
||||
int shape_outline_inx = 0;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
|
|
@ -181,7 +184,7 @@ void StaticBody2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
|
|||
int circle_edge_count = 12;
|
||||
shape_outline.resize(circle_edge_count);
|
||||
|
||||
const real_t turn_step = Math_TAU / real_t(circle_edge_count);
|
||||
const real_t turn_step = Math::TAU / real_t(circle_edge_count);
|
||||
for (int i = 0; i < circle_edge_count; i++) {
|
||||
shape_outline.write[i] = static_body_xform.xform(Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * circle_radius);
|
||||
}
|
||||
|
|
@ -213,6 +216,7 @@ void StaticBody2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
void StaticBody2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody2D::set_constant_linear_velocity);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef STATIC_BODY_2D_H
|
||||
#define STATIC_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
||||
|
|
@ -64,12 +63,12 @@ private:
|
|||
static Callable _navmesh_source_geometry_parsing_callback;
|
||||
static RID _navmesh_source_geometry_parser;
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
public:
|
||||
static void navmesh_parse_init();
|
||||
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
private:
|
||||
void _reload_physics_characteristics();
|
||||
};
|
||||
|
||||
#endif // STATIC_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -112,8 +112,27 @@ bool TouchScreenButton::is_shape_centered() const {
|
|||
return shape_centered;
|
||||
}
|
||||
|
||||
void TouchScreenButton::_accessibility_action_click(const Variant &p_data) {
|
||||
_press(0);
|
||||
_release();
|
||||
}
|
||||
|
||||
void TouchScreenButton::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
|
||||
RID ae = get_accessibility_element();
|
||||
ERR_FAIL_COND(ae.is_null());
|
||||
|
||||
Rect2 dst_rect(Point2(), texture_normal.is_valid() ? texture_normal->get_size() : Size2());
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_BUTTON);
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_CLICK, callable_mp(this, &TouchScreenButton::_accessibility_action_click));
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_transform(ae, get_transform());
|
||||
DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, dst_rect);
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TOUCH_SCREEN_BUTTON_H
|
||||
#define TOUCH_SCREEN_BUTTON_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/2d/rectangle_shape_2d.h"
|
||||
|
|
@ -75,6 +74,8 @@ protected:
|
|||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
void _accessibility_action_click(const Variant &p_data);
|
||||
|
||||
public:
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual Rect2 _edit_get_rect() const override;
|
||||
|
|
@ -116,5 +117,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(TouchScreenButton::VisibilityMode);
|
||||
|
||||
#endif // TOUCH_SCREEN_BUTTON_H
|
||||
|
|
@ -31,13 +31,17 @@
|
|||
#include "polygon_2d.h"
|
||||
|
||||
#include "core/math/geometry_2d.h"
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
#include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"
|
||||
#include "scene/resources/2d/navigation_polygon.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#include "skeleton_2d.h"
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
Callable Polygon2D::_navmesh_source_geometry_parsing_callback;
|
||||
RID Polygon2D::_navmesh_source_geometry_parser;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
Dictionary Polygon2D::_edit_get_state() const {
|
||||
|
|
@ -153,7 +157,7 @@ void Polygon2D::_notification(int p_what) {
|
|||
Vector<float> weights;
|
||||
|
||||
int len = polygon.size();
|
||||
if ((invert || polygons.size() == 0) && internal_vertices > 0) {
|
||||
if ((invert || polygons.is_empty()) && internal_vertices > 0) {
|
||||
//if no polygons are around, internal vertices must not be drawn, else let them be
|
||||
len -= internal_vertices;
|
||||
}
|
||||
|
|
@ -323,7 +327,7 @@ void Polygon2D::_notification(int p_what) {
|
|||
|
||||
Vector<int> index_array;
|
||||
|
||||
if (invert || polygons.size() == 0) {
|
||||
if (invert || polygons.is_empty()) {
|
||||
index_array = Geometry2D::triangulate_polygon(points);
|
||||
} else {
|
||||
//draw individual polygons
|
||||
|
|
@ -610,6 +614,7 @@ NodePath Polygon2D::get_skeleton() const {
|
|||
return skeleton;
|
||||
}
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void Polygon2D::navmesh_parse_init() {
|
||||
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
|
||||
if (!_navmesh_source_geometry_parser.is_valid()) {
|
||||
|
|
@ -639,6 +644,7 @@ void Polygon2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_na
|
|||
p_source_geometry_data->add_obstruction_outline(shape_outline);
|
||||
}
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
void Polygon2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &Polygon2D::set_polygon);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef POLYGON_2D_H
|
||||
#define POLYGON_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -153,16 +152,18 @@ public:
|
|||
void set_skeleton(const NodePath &p_skeleton);
|
||||
NodePath get_skeleton() const;
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
private:
|
||||
static Callable _navmesh_source_geometry_parsing_callback;
|
||||
static RID _navmesh_source_geometry_parser;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
public:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
static void navmesh_parse_init();
|
||||
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
Polygon2D();
|
||||
~Polygon2D();
|
||||
};
|
||||
|
||||
#endif // POLYGON_2D_H
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ void RemoteTransform2D::_update_remote() {
|
|||
return;
|
||||
}
|
||||
|
||||
Node2D *n = Object::cast_to<Node2D>(ObjectDB::get_instance(cache));
|
||||
Node2D *n = ObjectDB::get_instance<Node2D>(cache);
|
||||
if (!n) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ void RemoteTransform2D::_notification(int p_what) {
|
|||
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
|
||||
if (cache.is_valid()) {
|
||||
_update_remote();
|
||||
Node2D *n = Object::cast_to<Node2D>(ObjectDB::get_instance(cache));
|
||||
Node2D *n = ObjectDB::get_instance<Node2D>(cache);
|
||||
if (n) {
|
||||
n->reset_physics_interpolation();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef REMOTE_TRANSFORM_2D_H
|
||||
#define REMOTE_TRANSFORM_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -74,5 +73,3 @@ public:
|
|||
|
||||
RemoteTransform2D();
|
||||
};
|
||||
|
||||
#endif // REMOTE_TRANSFORM_2D_H
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ bool Bone2D::_editor_get_bone_shape(Vector<Vector2> *p_shape, Vector<Vector2> *p
|
|||
rel = Vector2(Math::cos(bone_angle), Math::sin(bone_angle)) * length * get_global_scale();
|
||||
}
|
||||
|
||||
Vector2 relt = rel.rotated(Math_PI * 0.5).normalized() * bone_width;
|
||||
Vector2 relt = rel.rotated(Math::PI * 0.5).normalized() * bone_width;
|
||||
Vector2 reln = rel.normalized();
|
||||
Vector2 reltn = relt.normalized();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef SKELETON_2D_H
|
||||
#define SKELETON_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
|
||||
|
|
@ -174,5 +173,3 @@ public:
|
|||
Skeleton2D();
|
||||
~Skeleton2D();
|
||||
};
|
||||
|
||||
#endif // SKELETON_2D_H
|
||||
|
|
|
|||
|
|
@ -115,6 +115,17 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c
|
|||
|
||||
void Sprite2D::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
|
||||
RID ae = get_accessibility_element();
|
||||
ERR_FAIL_COND(ae.is_null());
|
||||
|
||||
Rect2 dst_rect = get_rect();
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_IMAGE);
|
||||
DisplayServer::get_singleton()->accessibility_update_set_transform(ae, get_transform());
|
||||
DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, dst_rect);
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
if (texture.is_null()) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef SPRITE_2D_H
|
||||
#define SPRITE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
|
@ -127,5 +126,3 @@ public:
|
|||
Sprite2D();
|
||||
~Sprite2D();
|
||||
};
|
||||
|
||||
#endif // SPRITE_2D_H
|
||||
|
|
|
|||
|
|
@ -46,16 +46,20 @@ TileMap::VisibilityMode TileMap::_get_collision_visibility_mode_bind_compat_8711
|
|||
return get_collision_visibility_mode();
|
||||
}
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
TileMap::VisibilityMode TileMap::_get_navigation_visibility_mode_bind_compat_87115() {
|
||||
return get_navigation_visibility_mode();
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
void TileMap::_bind_compatibility_methods() {
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_used_rect"), &TileMap::_get_used_rect_bind_compat_78328);
|
||||
ClassDB::bind_compatibility_method(D_METHOD("set_quadrant_size", "quadrant_size"), &TileMap::_set_quadrant_size_compat_81070);
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_quadrant_size"), &TileMap::_get_quadrant_size_compat_81070);
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_collision_visibility_mode"), &TileMap::_get_collision_visibility_mode_bind_compat_87115);
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
ClassDB::bind_compatibility_method(D_METHOD("get_navigation_visibility_mode"), &TileMap::_get_navigation_visibility_mode_bind_compat_87115);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -32,8 +32,10 @@
|
|||
#include "tile_map.compat.inc"
|
||||
|
||||
#include "core/io/marshalls.h"
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
#include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
#define TILEMAP_CALL_FOR_LAYER(layer, function, ...) \
|
||||
if (layer < 0) { \
|
||||
|
|
@ -49,8 +51,10 @@
|
|||
ERR_FAIL_INDEX_V(layer, (int)layers.size(), err_value); \
|
||||
return layers[layer]->function(__VA_ARGS__);
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
Callable TileMap::_navmesh_source_geometry_parsing_callback;
|
||||
RID TileMap::_navmesh_source_geometry_parser;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
void TileMap::_tile_set_changed() {
|
||||
update_configuration_warnings();
|
||||
|
|
@ -376,6 +380,7 @@ int TileMap::get_layer_z_index(int p_layer) const {
|
|||
TILEMAP_CALL_FOR_LAYER_V(p_layer, 0, get_z_index);
|
||||
}
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void TileMap::set_layer_navigation_enabled(int p_layer, bool p_enabled) {
|
||||
TILEMAP_CALL_FOR_LAYER(p_layer, set_navigation_enabled, p_enabled);
|
||||
}
|
||||
|
|
@ -391,6 +396,7 @@ void TileMap::set_layer_navigation_map(int p_layer, RID p_map) {
|
|||
RID TileMap::get_layer_navigation_map(int p_layer) const {
|
||||
TILEMAP_CALL_FOR_LAYER_V(p_layer, RID(), get_navigation_map);
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
void TileMap::set_collision_animatable(bool p_collision_animatable) {
|
||||
if (collision_animatable == p_collision_animatable) {
|
||||
|
|
@ -423,6 +429,7 @@ TileMap::VisibilityMode TileMap::get_collision_visibility_mode() const {
|
|||
return collision_visibility_mode;
|
||||
}
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void TileMap::set_navigation_visibility_mode(TileMap::VisibilityMode p_show_navigation) {
|
||||
if (navigation_visibility_mode == p_show_navigation) {
|
||||
return;
|
||||
|
|
@ -437,6 +444,7 @@ void TileMap::set_navigation_visibility_mode(TileMap::VisibilityMode p_show_navi
|
|||
TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() const {
|
||||
return navigation_visibility_mode;
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
void TileMap::set_y_sort_enabled(bool p_enable) {
|
||||
if (is_y_sort_enabled() == p_enable) {
|
||||
|
|
@ -597,6 +605,7 @@ TileMapCell TileMap::get_cell(int p_layer, const Vector2i &p_coords, bool p_use_
|
|||
TILEMAP_CALL_FOR_LAYER_V(p_layer, TileMapCell(), get_cell, p_coords);
|
||||
}
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
Vector2i TileMap::get_coords_for_body_rid(RID p_physics_body) {
|
||||
for (const TileMapLayer *layer : layers) {
|
||||
if (layer->has_body_rid(p_physics_body)) {
|
||||
|
|
@ -614,6 +623,7 @@ int TileMap::get_layer_for_body_rid(RID p_physics_body) {
|
|||
}
|
||||
ERR_FAIL_V_MSG(-1, vformat("No tiles for the given body RID %d.", p_physics_body.get_id()));
|
||||
}
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
void TileMap::fix_invalid_tiles() {
|
||||
for (TileMapLayer *layer : layers) {
|
||||
|
|
@ -896,8 +906,10 @@ PackedStringArray TileMap::get_configuration_warnings() const {
|
|||
|
||||
void TileMap::_bind_methods() {
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_map", "layer", "map"), &TileMap::set_layer_navigation_map);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_map", "layer"), &TileMap::get_layer_navigation_map);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
ClassDB::bind_method(D_METHOD("force_update", "layer"), &TileMap::force_update, DEFVAL(-1));
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
|
|
@ -923,18 +935,22 @@ void TileMap::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_layer_y_sort_origin", "layer"), &TileMap::get_layer_y_sort_origin);
|
||||
ClassDB::bind_method(D_METHOD("set_layer_z_index", "layer", "z_index"), &TileMap::set_layer_z_index);
|
||||
ClassDB::bind_method(D_METHOD("get_layer_z_index", "layer"), &TileMap::get_layer_z_index);
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
ClassDB::bind_method(D_METHOD("set_layer_navigation_enabled", "layer", "enabled"), &TileMap::set_layer_navigation_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_layer_navigation_enabled", "layer"), &TileMap::is_layer_navigation_enabled);
|
||||
ClassDB::bind_method(D_METHOD("set_layer_navigation_map", "layer", "map"), &TileMap::set_layer_navigation_map);
|
||||
ClassDB::bind_method(D_METHOD("get_layer_navigation_map", "layer"), &TileMap::get_layer_navigation_map);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_collision_animatable", "enabled"), &TileMap::set_collision_animatable);
|
||||
ClassDB::bind_method(D_METHOD("is_collision_animatable"), &TileMap::is_collision_animatable);
|
||||
ClassDB::bind_method(D_METHOD("set_collision_visibility_mode", "collision_visibility_mode"), &TileMap::set_collision_visibility_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_collision_visibility_mode"), &TileMap::get_collision_visibility_mode);
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_visibility_mode", "navigation_visibility_mode"), &TileMap::set_navigation_visibility_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_visibility_mode"), &TileMap::get_navigation_visibility_mode);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_cell", "layer", "coords", "source_id", "atlas_coords", "alternative_tile"), &TileMap::set_cell, DEFVAL(TileSet::INVALID_SOURCE), DEFVAL(TileSetSource::INVALID_ATLAS_COORDS), DEFVAL(0));
|
||||
ClassDB::bind_method(D_METHOD("erase_cell", "layer", "coords"), &TileMap::erase_cell);
|
||||
|
|
@ -947,8 +963,10 @@ void TileMap::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("is_cell_flipped_v", "layer", "coords", "use_proxies"), &TileMap::is_cell_flipped_v, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("is_cell_transposed", "layer", "coords", "use_proxies"), &TileMap::is_cell_transposed, DEFVAL(false));
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
ClassDB::bind_method(D_METHOD("get_coords_for_body_rid", "body"), &TileMap::get_coords_for_body_rid);
|
||||
ClassDB::bind_method(D_METHOD("get_layer_for_body_rid", "body"), &TileMap::get_layer_for_body_rid);
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_pattern", "layer", "coords_array"), &TileMap::get_pattern);
|
||||
ClassDB::bind_method(D_METHOD("map_pattern", "position_in_tilemap", "coords_in_pattern", "pattern"), &TileMap::map_pattern);
|
||||
|
|
@ -982,7 +1000,9 @@ void TileMap::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "rendering_quadrant_size", PROPERTY_HINT_RANGE, "1,128,1"), "set_rendering_quadrant_size", "get_rendering_quadrant_size");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_animatable"), "set_collision_animatable", "is_collision_animatable");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_visibility_mode", PROPERTY_HINT_ENUM, "Default,Force Show,Force Hide"), "set_collision_visibility_mode", "get_collision_visibility_mode");
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_visibility_mode", PROPERTY_HINT_ENUM, "Default,Force Show,Force Hide"), "set_navigation_visibility_mode", "get_navigation_visibility_mode");
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
ADD_ARRAY("layers", "layer_");
|
||||
|
||||
|
|
@ -1017,7 +1037,9 @@ TileMap::TileMap() {
|
|||
base_property_helper.register_property(PropertyInfo(Variant::BOOL, "y_sort_enabled"), defaults->is_y_sort_enabled(), &TileMap::set_layer_y_sort_enabled, &TileMap::is_layer_y_sort_enabled);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::INT, "y_sort_origin", PROPERTY_HINT_NONE, "suffix:px"), defaults->get_y_sort_origin(), &TileMap::set_layer_y_sort_origin, &TileMap::get_layer_y_sort_origin);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::INT, "z_index"), defaults->get_z_index(), &TileMap::set_layer_z_index, &TileMap::get_layer_z_index);
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
base_property_helper.register_property(PropertyInfo(Variant::BOOL, "navigation_enabled"), defaults->is_navigation_enabled(), &TileMap::set_layer_navigation_enabled, &TileMap::is_layer_navigation_enabled);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
base_property_helper.register_property(PropertyInfo(Variant::PACKED_INT32_ARRAY, "tile_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), Vector<int>(), &TileMap::_set_layer_tile_data, &TileMap::_get_tile_map_data_using_compatibility_format);
|
||||
PropertyListHelper::register_base_helper(&base_property_helper);
|
||||
|
||||
|
|
@ -1027,6 +1049,7 @@ TileMap::TileMap() {
|
|||
property_helper.setup_for_instance(base_property_helper, this);
|
||||
}
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void TileMap::navmesh_parse_init() {
|
||||
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
|
||||
if (!_navmesh_source_geometry_parser.is_valid()) {
|
||||
|
|
@ -1054,6 +1077,7 @@ void TileMap::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navi
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
#undef TILEMAP_CALL_FOR_LAYER
|
||||
#undef TILEMAP_CALL_FOR_LAYER_V
|
||||
|
|
|
|||
|
|
@ -28,15 +28,16 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TILE_MAP_H
|
||||
#define TILE_MAP_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/tile_map_layer.h"
|
||||
#include "scene/property_list_helper.h"
|
||||
#include "scene/resources/2d/tile_set.h"
|
||||
|
||||
class Control;
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
class NavigationMeshSourceGeometryData2D;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
class TileMapLayer;
|
||||
class TerrainConstraint;
|
||||
|
||||
|
|
@ -59,8 +60,6 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
friend class TileSetPlugin;
|
||||
|
||||
// A compatibility enum to specify how is the data if formatted.
|
||||
mutable TileMapDataFormat format = TileMapDataFormat::TILE_MAP_DATA_FORMAT_3;
|
||||
|
||||
|
|
@ -69,7 +68,9 @@ private:
|
|||
int rendering_quadrant_size = 16;
|
||||
bool collision_animatable = false;
|
||||
VisibilityMode collision_visibility_mode = VISIBILITY_MODE_DEFAULT;
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
VisibilityMode navigation_visibility_mode = VISIBILITY_MODE_DEFAULT;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
// Layers.
|
||||
LocalVector<TileMapLayer *> layers;
|
||||
|
|
@ -105,7 +106,9 @@ protected:
|
|||
void _set_quadrant_size_compat_81070(int p_quadrant_size);
|
||||
int _get_quadrant_size_compat_81070() const;
|
||||
VisibilityMode _get_collision_visibility_mode_bind_compat_87115();
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
VisibilityMode _get_navigation_visibility_mode_bind_compat_87115();
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
static void _bind_compatibility_methods();
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
|
@ -144,10 +147,12 @@ public:
|
|||
int get_layer_y_sort_origin(int p_layer) const;
|
||||
void set_layer_z_index(int p_layer, int p_z_index);
|
||||
int get_layer_z_index(int p_layer) const;
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void set_layer_navigation_enabled(int p_layer, bool p_enabled);
|
||||
bool is_layer_navigation_enabled(int p_layer) const;
|
||||
void set_layer_navigation_map(int p_layer, RID p_map);
|
||||
RID get_layer_navigation_map(int p_layer) const;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
void set_collision_animatable(bool p_collision_animatable);
|
||||
bool is_collision_animatable() const;
|
||||
|
|
@ -156,8 +161,10 @@ public:
|
|||
void set_collision_visibility_mode(VisibilityMode p_show_collision);
|
||||
VisibilityMode get_collision_visibility_mode() const;
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void set_navigation_visibility_mode(VisibilityMode p_show_navigation);
|
||||
VisibilityMode get_navigation_visibility_mode() const;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
// Cells accessors.
|
||||
void set_cell(int p_layer, const Vector2i &p_coords, int p_source_id = TileSet::INVALID_SOURCE, const Vector2i p_atlas_coords = TileSetSource::INVALID_ATLAS_COORDS, int p_alternative_tile = 0);
|
||||
|
|
@ -208,10 +215,12 @@ public:
|
|||
virtual void set_texture_filter(CanvasItem::TextureFilter p_texture_filter) override;
|
||||
virtual void set_texture_repeat(CanvasItem::TextureRepeat p_texture_repeat) override;
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
// For finding tiles from collision.
|
||||
Vector2i get_coords_for_body_rid(RID p_physics_body);
|
||||
// For getting their layers as well.
|
||||
int get_layer_for_body_rid(RID p_physics_body);
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
// Fixing and clearing methods.
|
||||
void fix_invalid_tiles();
|
||||
|
|
@ -239,17 +248,19 @@ public:
|
|||
// Configuration warnings.
|
||||
PackedStringArray get_configuration_warnings() const override;
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
private:
|
||||
static Callable _navmesh_source_geometry_parsing_callback;
|
||||
static RID _navmesh_source_geometry_parser;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
public:
|
||||
static void navmesh_parse_init();
|
||||
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
TileMap();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(TileMap::VisibilityMode);
|
||||
|
||||
#endif // TILE_MAP_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -28,12 +28,13 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TILE_MAP_LAYER_H
|
||||
#define TILE_MAP_LAYER_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/resources/2d/tile_set.h"
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
class NavigationMeshSourceGeometryData2D;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
class TileSetAtlasSource;
|
||||
class TileMap;
|
||||
|
||||
|
|
@ -98,21 +99,22 @@ public:
|
|||
class DebugQuadrant;
|
||||
#endif // DEBUG_ENABLED
|
||||
class RenderingQuadrant;
|
||||
class PhysicsQuadrant;
|
||||
|
||||
struct CellData {
|
||||
Vector2i coords;
|
||||
TileMapCell cell;
|
||||
|
||||
// Debug.
|
||||
SelfList<CellData> debug_quadrant_list_element;
|
||||
|
||||
// Rendering.
|
||||
Ref<RenderingQuadrant> rendering_quadrant;
|
||||
SelfList<CellData> rendering_quadrant_list_element;
|
||||
LocalVector<LocalVector<RID>> occluders;
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
// Physics.
|
||||
LocalVector<RID> bodies;
|
||||
Ref<PhysicsQuadrant> physics_quadrant;
|
||||
SelfList<CellData> physics_quadrant_list_element;
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
// Navigation.
|
||||
LocalVector<RID> navigation_regions;
|
||||
|
|
@ -135,28 +137,30 @@ struct CellData {
|
|||
coords = p_other.coords;
|
||||
cell = p_other.cell;
|
||||
occluders = p_other.occluders;
|
||||
bodies = p_other.bodies;
|
||||
navigation_regions = p_other.navigation_regions;
|
||||
scene = p_other.scene;
|
||||
runtime_tile_data_cache = p_other.runtime_tile_data_cache;
|
||||
}
|
||||
|
||||
CellData(const CellData &p_other) :
|
||||
debug_quadrant_list_element(this),
|
||||
rendering_quadrant_list_element(this),
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
physics_quadrant_list_element(this),
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
dirty_list_element(this) {
|
||||
coords = p_other.coords;
|
||||
cell = p_other.cell;
|
||||
occluders = p_other.occluders;
|
||||
bodies = p_other.bodies;
|
||||
navigation_regions = p_other.navigation_regions;
|
||||
scene = p_other.scene;
|
||||
runtime_tile_data_cache = p_other.runtime_tile_data_cache;
|
||||
}
|
||||
|
||||
CellData() :
|
||||
debug_quadrant_list_element(this),
|
||||
rendering_quadrant_list_element(this),
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
physics_quadrant_list_element(this),
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
dirty_list_element(this) {
|
||||
}
|
||||
};
|
||||
|
|
@ -177,6 +181,11 @@ public:
|
|||
SelfList<CellData>::List cells;
|
||||
RID canvas_item;
|
||||
|
||||
RID physics_mesh;
|
||||
|
||||
// Used to deleted unused quadrants.
|
||||
bool drawn_to = false;
|
||||
|
||||
SelfList<DebugQuadrant> dirty_quadrant_list_element;
|
||||
|
||||
DebugQuadrant() :
|
||||
|
|
@ -220,6 +229,90 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
class PhysicsQuadrant : public RefCounted {
|
||||
GDCLASS(PhysicsQuadrant, RefCounted);
|
||||
|
||||
public:
|
||||
struct PhysicsBodyKey {
|
||||
int physics_layer = 0;
|
||||
Vector2 linear_velocity;
|
||||
real_t angular_velocity = 0.0;
|
||||
bool one_way_collision = false;
|
||||
real_t one_way_collision_margin = 0.0;
|
||||
|
||||
bool operator<(const PhysicsBodyKey &p_other) const {
|
||||
if (physics_layer == p_other.physics_layer) {
|
||||
if (linear_velocity == p_other.linear_velocity) {
|
||||
if (angular_velocity == p_other.angular_velocity) {
|
||||
if (one_way_collision == p_other.one_way_collision) {
|
||||
return one_way_collision_margin < p_other.one_way_collision_margin;
|
||||
}
|
||||
return one_way_collision < p_other.one_way_collision;
|
||||
}
|
||||
return angular_velocity < p_other.angular_velocity;
|
||||
}
|
||||
return linear_velocity < p_other.linear_velocity;
|
||||
}
|
||||
return physics_layer < p_other.physics_layer;
|
||||
}
|
||||
|
||||
bool operator!=(const PhysicsBodyKey &p_other) const {
|
||||
return !this->operator==(p_other);
|
||||
}
|
||||
bool operator==(const PhysicsBodyKey &p_other) const {
|
||||
return physics_layer == p_other.physics_layer &&
|
||||
linear_velocity == p_other.linear_velocity &&
|
||||
angular_velocity == p_other.angular_velocity &&
|
||||
one_way_collision == p_other.one_way_collision &&
|
||||
one_way_collision_margin == p_other.one_way_collision_margin;
|
||||
}
|
||||
};
|
||||
|
||||
struct PhysicsBodyKeyHasher {
|
||||
static uint32_t hash(const PhysicsBodyKey &p_hash) {
|
||||
uint32_t h = hash_murmur3_one_32(p_hash.physics_layer);
|
||||
h = hash_murmur3_one_real(p_hash.linear_velocity.x);
|
||||
h = hash_murmur3_one_real(p_hash.linear_velocity.y, h);
|
||||
h = hash_murmur3_one_real(p_hash.angular_velocity, h);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
struct PhysicsBodyValue {
|
||||
RID body;
|
||||
Vector<Vector<Vector2>> polygons;
|
||||
};
|
||||
|
||||
struct CoordsWorldComparator {
|
||||
_ALWAYS_INLINE_ bool operator()(const Vector2 &p_a, const Vector2 &p_b) const {
|
||||
// We sort the cells by their local coords, as it is needed by rendering.
|
||||
if (p_a.y == p_b.y) {
|
||||
return p_a.x > p_b.x;
|
||||
} else {
|
||||
return p_a.y < p_b.y;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Vector2i quadrant_coords;
|
||||
SelfList<CellData>::List cells;
|
||||
|
||||
HashMap<PhysicsBodyKey, PhysicsBodyValue, PhysicsBodyKeyHasher> bodies;
|
||||
LocalVector<Ref<ConvexPolygonShape2D>> shapes;
|
||||
|
||||
SelfList<PhysicsQuadrant> dirty_quadrant_list_element;
|
||||
|
||||
PhysicsQuadrant() :
|
||||
dirty_quadrant_list_element(this) {
|
||||
}
|
||||
|
||||
~PhysicsQuadrant() {
|
||||
cells.clear();
|
||||
}
|
||||
};
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
class TileMapLayer : public Node2D {
|
||||
GDCLASS(TileMapLayer, Node2D);
|
||||
|
||||
|
|
@ -254,6 +347,7 @@ public:
|
|||
DIRTY_FLAGS_LAYER_RENDERING_QUADRANT_SIZE,
|
||||
DIRTY_FLAGS_LAYER_COLLISION_ENABLED,
|
||||
DIRTY_FLAGS_LAYER_USE_KINEMATIC_BODIES,
|
||||
DIRTY_FLAGS_LAYER_PHYSICS_QUADRANT_SIZE,
|
||||
DIRTY_FLAGS_LAYER_COLLISION_VISIBILITY_MODE,
|
||||
DIRTY_FLAGS_LAYER_OCCLUSION_ENABLED,
|
||||
DIRTY_FLAGS_LAYER_NAVIGATION_ENABLED,
|
||||
|
|
@ -288,6 +382,7 @@ private:
|
|||
|
||||
bool collision_enabled = true;
|
||||
bool use_kinematic_bodies = false;
|
||||
int physics_quadrant_size = 16;
|
||||
DebugVisibilityMode collision_visibility_mode = DEBUG_VISIBILITY_MODE_DEFAULT;
|
||||
|
||||
bool occlusion_enabled = true;
|
||||
|
|
@ -324,13 +419,16 @@ private:
|
|||
void _clear_runtime_update_tile_data_for_cell(CellData &r_cell_data);
|
||||
void _update_cells_callback(bool p_force_cleanup);
|
||||
|
||||
// Coords to quadrant coords
|
||||
Vector2i _coords_to_quadrant_coords(const Vector2i &p_coords, const int p_quadrant_size) const;
|
||||
|
||||
// Per-system methods.
|
||||
#ifdef DEBUG_ENABLED
|
||||
HashMap<Vector2i, Ref<DebugQuadrant>> debug_quadrant_map;
|
||||
Vector2i _coords_to_debug_quadrant_coords(const Vector2i &p_coords) const;
|
||||
bool _debug_was_cleaned_up = false;
|
||||
void _debug_update(bool p_force_cleanup);
|
||||
void _debug_quadrants_update_cell(CellData &r_cell_data, SelfList<DebugQuadrant>::List &r_dirty_debug_quadrant_list);
|
||||
void _debug_quadrants_update_cell(CellData &r_cell_data);
|
||||
void _get_debug_quadrant_for_cell(const Vector2i &p_coords);
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
HashMap<Vector2i, Ref<RenderingQuadrant>> rendering_quadrant_map;
|
||||
|
|
@ -344,16 +442,21 @@ private:
|
|||
void _rendering_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data);
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
HashMap<Vector2i, Ref<PhysicsQuadrant>> physics_quadrant_map;
|
||||
HashMap<RID, Vector2i> bodies_coords; // Mapping for RID to coords.
|
||||
bool _physics_was_cleaned_up = false;
|
||||
void _physics_update(bool p_force_cleanup);
|
||||
void _physics_notification(int p_what);
|
||||
void _physics_quadrants_update_cell(CellData &r_cell_data, SelfList<PhysicsQuadrant>::List &r_dirty_physics_quadrant_list);
|
||||
void _physics_clear_cell(CellData &r_cell_data);
|
||||
void _physics_update_cell(CellData &r_cell_data);
|
||||
#ifdef DEBUG_ENABLED
|
||||
void _physics_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data);
|
||||
void _physics_draw_quadrant_debug(const RID &p_canvas_item, DebugQuadrant &r_debug_quadrant);
|
||||
#endif // DEBUG_ENABLED
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
bool _navigation_was_cleaned_up = false;
|
||||
void _navigation_update(bool p_force_cleanup);
|
||||
void _navigation_notification(int p_what);
|
||||
|
|
@ -362,6 +465,7 @@ private:
|
|||
#ifdef DEBUG_ENABLED
|
||||
void _navigation_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data);
|
||||
#endif // DEBUG_ENABLED
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
bool _scenes_was_cleaned_up = false;
|
||||
void _scenes_update(bool p_force_cleanup);
|
||||
|
|
@ -423,7 +527,7 @@ public:
|
|||
// Not exposed to users.
|
||||
TileMapCell get_cell(const Vector2i &p_coords) const;
|
||||
|
||||
static void draw_tile(RID p_canvas_item, const Vector2 &p_position, const Ref<TileSet> p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame = -1, Color p_modulation = Color(1.0, 1.0, 1.0, 1.0), const TileData *p_tile_data_override = nullptr, real_t p_normalized_animation_offset = 0.0);
|
||||
static void draw_tile(RID p_canvas_item, const Vector2 &p_position, const Ref<TileSet> p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame = -1, const TileData *p_tile_data_override = nullptr, real_t p_normalized_animation_offset = 0.0);
|
||||
|
||||
////////////// Exposed functions //////////////
|
||||
|
||||
|
|
@ -455,9 +559,11 @@ public:
|
|||
void set_cells_terrain_connect(TypedArray<Vector2i> p_cells, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains = true);
|
||||
void set_cells_terrain_path(TypedArray<Vector2i> p_path, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains = true);
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
// --- Physics helpers ---
|
||||
bool has_body_rid(RID p_physics_body) const;
|
||||
Vector2i get_coords_for_body_rid(RID p_physics_body) const; // For finding tiles from collision.
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
// --- Runtime ---
|
||||
void update_internals();
|
||||
|
|
@ -502,6 +608,8 @@ public:
|
|||
bool is_using_kinematic_bodies() const;
|
||||
void set_collision_visibility_mode(DebugVisibilityMode p_show_collision);
|
||||
DebugVisibilityMode get_collision_visibility_mode() const;
|
||||
void set_physics_quadrant_size(int p_size);
|
||||
int get_physics_quadrant_size() const;
|
||||
|
||||
void set_occlusion_enabled(bool p_enabled);
|
||||
bool is_occlusion_enabled() const;
|
||||
|
|
@ -514,17 +622,19 @@ public:
|
|||
DebugVisibilityMode get_navigation_visibility_mode() const;
|
||||
|
||||
private:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
static Callable _navmesh_source_geometry_parsing_callback;
|
||||
static RID _navmesh_source_geometry_parser;
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
public:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
static void navmesh_parse_init();
|
||||
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
TileMapLayer();
|
||||
~TileMapLayer();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(TileMapLayer::DebugVisibilityMode);
|
||||
|
||||
#endif // TILE_MAP_LAYER_H
|
||||
|
|
|
|||
|
|
@ -30,13 +30,31 @@
|
|||
|
||||
#include "visible_on_screen_notifier_2d.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
Dictionary VisibleOnScreenNotifier2D::_edit_get_state() const {
|
||||
Dictionary state = Node2D::_edit_get_state();
|
||||
state["rect"] = rect;
|
||||
return state;
|
||||
}
|
||||
|
||||
void VisibleOnScreenNotifier2D::_edit_set_state(const Dictionary &p_state) {
|
||||
ERR_FAIL_COND(p_state.is_empty() || !p_state.has("rect"));
|
||||
set_rect(p_state["rect"]);
|
||||
Node2D::_edit_set_state(p_state);
|
||||
}
|
||||
|
||||
void VisibleOnScreenNotifier2D::_edit_set_rect(const Rect2 &p_edit_rect) {
|
||||
set_rect(p_edit_rect);
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
Rect2 VisibleOnScreenNotifier2D::_edit_get_rect() const {
|
||||
return rect;
|
||||
}
|
||||
|
||||
bool VisibleOnScreenNotifier2D::_edit_use_rect() const {
|
||||
return true;
|
||||
return show_rect;
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
|
|
@ -71,6 +89,18 @@ Rect2 VisibleOnScreenNotifier2D::get_rect() const {
|
|||
return rect;
|
||||
}
|
||||
|
||||
void VisibleOnScreenNotifier2D::set_show_rect(bool p_show_rect) {
|
||||
if (show_rect == p_show_rect) {
|
||||
return;
|
||||
}
|
||||
show_rect = p_show_rect;
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
bool VisibleOnScreenNotifier2D::is_showing_rect() const {
|
||||
return show_rect;
|
||||
}
|
||||
|
||||
void VisibleOnScreenNotifier2D::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
|
|
@ -79,7 +109,7 @@ void VisibleOnScreenNotifier2D::_notification(int p_what) {
|
|||
} break;
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
if (show_rect && Engine::get_singleton()->is_editor_hint()) {
|
||||
draw_rect(rect, Color(1, 0.5, 1, 0.2));
|
||||
}
|
||||
} break;
|
||||
|
|
@ -98,9 +128,12 @@ bool VisibleOnScreenNotifier2D::is_on_screen() const {
|
|||
void VisibleOnScreenNotifier2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_rect", "rect"), &VisibleOnScreenNotifier2D::set_rect);
|
||||
ClassDB::bind_method(D_METHOD("get_rect"), &VisibleOnScreenNotifier2D::get_rect);
|
||||
ClassDB::bind_method(D_METHOD("set_show_rect", "show_rect"), &VisibleOnScreenNotifier2D::set_show_rect);
|
||||
ClassDB::bind_method(D_METHOD("is_showing_rect"), &VisibleOnScreenNotifier2D::is_showing_rect);
|
||||
ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibleOnScreenNotifier2D::is_on_screen);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect", PROPERTY_HINT_NONE, "suffix:px"), "set_rect", "get_rect");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_rect"), "set_show_rect", "is_showing_rect");
|
||||
|
||||
ADD_SIGNAL(MethodInfo("screen_entered"));
|
||||
ADD_SIGNAL(MethodInfo("screen_exited"));
|
||||
|
|
@ -154,7 +187,7 @@ NodePath VisibleOnScreenEnabler2D::get_enable_node_path() {
|
|||
}
|
||||
|
||||
void VisibleOnScreenEnabler2D::_update_enable_mode(bool p_enable) {
|
||||
Node *node = static_cast<Node *>(ObjectDB::get_instance(node_id));
|
||||
Node *node = ObjectDB::get_instance<Node>(node_id);
|
||||
if (node) {
|
||||
if (p_enable) {
|
||||
switch (enable_mode) {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VISIBLE_ON_SCREEN_NOTIFIER_2D_H
|
||||
#define VISIBLE_ON_SCREEN_NOTIFIER_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -40,6 +39,7 @@ class VisibleOnScreenNotifier2D : public Node2D {
|
|||
HashSet<Viewport *> viewports;
|
||||
|
||||
Rect2 rect;
|
||||
bool show_rect = true;
|
||||
|
||||
private:
|
||||
bool on_screen = false;
|
||||
|
|
@ -54,14 +54,27 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual Dictionary _edit_get_state() const override;
|
||||
virtual void _edit_set_state(const Dictionary &p_state) override;
|
||||
|
||||
virtual Vector2 _edit_get_minimum_size() const override { return Vector2(); }
|
||||
|
||||
virtual void _edit_set_rect(const Rect2 &p_edit_rect) override;
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual Rect2 _edit_get_rect() const override;
|
||||
|
||||
virtual bool _edit_use_rect() const override;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void set_rect(const Rect2 &p_rect);
|
||||
Rect2 get_rect() const;
|
||||
|
||||
void set_show_rect(bool p_show_rect);
|
||||
bool is_showing_rect() const;
|
||||
|
||||
bool is_on_screen() const;
|
||||
|
||||
VisibleOnScreenNotifier2D();
|
||||
|
|
@ -101,5 +114,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(VisibleOnScreenEnabler2D::EnableMode);
|
||||
|
||||
#endif // VISIBLE_ON_SCREEN_NOTIFIER_2D_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue