summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/camera_2d.cpp1
-rw-r--r--scene/2d/physics_body_2d.cpp132
-rw-r--r--scene/2d/physics_body_2d.h64
-rw-r--r--scene/2d/tile_map.cpp2
-rw-r--r--scene/3d/light_3d.cpp9
-rw-r--r--scene/3d/physics_body_3d.cpp8
-rw-r--r--scene/3d/physics_body_3d.h2
-rw-r--r--scene/animation/animation_tree.cpp52
-rw-r--r--scene/animation/animation_tree.h8
-rw-r--r--scene/debugger/scene_debugger.cpp2
-rw-r--r--scene/gui/base_button.cpp12
-rw-r--r--scene/gui/base_button.h3
-rw-r--r--scene/gui/code_edit.cpp35
-rw-r--r--scene/gui/code_edit.h10
-rw-r--r--scene/gui/color_picker.cpp198
-rw-r--r--scene/gui/color_picker.h39
-rw-r--r--scene/gui/control.cpp85
-rw-r--r--scene/gui/control.h10
-rw-r--r--scene/gui/graph_edit.cpp105
-rw-r--r--scene/gui/graph_edit.h5
-rw-r--r--scene/gui/popup_menu.cpp7
-rw-r--r--scene/gui/rich_text_effect.cpp29
-rw-r--r--scene/gui/rich_text_effect.h32
-rw-r--r--scene/gui/rich_text_label.cpp4
-rw-r--r--scene/gui/shortcut.cpp2
-rw-r--r--scene/gui/text_edit.cpp51
-rw-r--r--scene/gui/text_edit.h18
-rw-r--r--scene/main/canvas_item.cpp6
-rw-r--r--scene/main/canvas_item.h1
-rw-r--r--scene/main/node.cpp39
-rw-r--r--scene/main/node.h8
-rw-r--r--scene/register_scene_types.cpp1
-rw-r--r--scene/resources/capsule_shape_2d.cpp12
-rw-r--r--scene/resources/capsule_shape_3d.cpp6
-rw-r--r--scene/resources/curve.cpp97
-rw-r--r--scene/resources/curve.h2
-rw-r--r--scene/resources/default_theme/default_theme.cpp52
-rw-r--r--scene/resources/particles_material.h7
-rw-r--r--scene/resources/skeleton_modification_2d.cpp12
-rw-r--r--scene/resources/skeleton_modification_2d.h4
-rw-r--r--scene/resources/skeleton_modification_3d.cpp16
-rw-r--r--scene/resources/skeleton_modification_3d.h3
-rw-r--r--scene/resources/syntax_highlighter.cpp24
-rw-r--r--scene/resources/syntax_highlighter.h9
-rw-r--r--scene/resources/visual_shader.cpp109
-rw-r--r--scene/resources/visual_shader.h14
46 files changed, 780 insertions, 567 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index 13b37aa2b2..bf91ce8e65 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -261,6 +261,7 @@ void Camera2D::_notification(int p_what) {
if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
viewport->set_canvas_transform(Transform2D());
clear_current();
+ current = true;
}
}
remove_from_group(group_name);
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index dd1a4671d9..a9d4877cbb 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -529,9 +529,9 @@ void RigidBody2D::_direct_state_changed(Object *p_state) {
sleeping = state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
}
- if (get_script_instance()) {
- get_script_instance()->call("_integrate_forces", state);
- }
+
+ GDVIRTUAL_CALL(_integrate_forces, state);
+
set_block_transform_notify(false); // want it back
if (contact_monitor) {
@@ -978,7 +978,7 @@ void RigidBody2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody2D::get_colliding_bodies);
- BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState2D")));
+ GDVIRTUAL_BIND(_integrate_forces, "state");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Dynamic,Static,DynamicLocked,Kinematic"), "set_mode", "get_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_RANGE, "0.01,65535,0.01,exp"), "set_mass", "get_mass");
@@ -1081,10 +1081,24 @@ bool CharacterBody2D::move_and_slide() {
}
}
- Vector2 motion = linear_velocity * delta;
+ if (motion_mode == MOTION_MODE_GROUNDED) {
+ _move_and_slide_grounded(delta, was_on_floor, current_platform_velocity);
+ } else {
+ _move_and_slide_free(delta);
+ }
+
+ if (!on_floor && !on_wall) {
+ // Add last platform velocity when just left a moving platform.
+ linear_velocity += current_platform_velocity;
+ }
+
+ return motion_results.size() > 0;
+}
+
+void CharacterBody2D::_move_and_slide_grounded(real_t p_delta, bool p_was_on_floor, const Vector2 &p_prev_platform_velocity) {
+ Vector2 motion = linear_velocity * p_delta;
Vector2 motion_slide_up = motion.slide(up_direction);
- Vector2 prev_platform_velocity = current_platform_velocity;
Vector2 prev_floor_normal = floor_normal;
RID prev_platform_rid = platform_rid;
int prev_platform_layer = platform_layer;
@@ -1095,7 +1109,7 @@ bool CharacterBody2D::move_and_slide() {
// No sliding on first attempt to keep floor motion stable when possible,
// When stop on slope is enabled or when there is no up direction.
- bool sliding_enabled = !floor_stop_on_slope || up_direction == Vector2();
+ bool sliding_enabled = !floor_stop_on_slope;
// Constant speed can be applied only the first time sliding is enabled.
bool can_apply_constant_speed = sliding_enabled;
bool first_slide = true;
@@ -1134,7 +1148,7 @@ bool CharacterBody2D::move_and_slide() {
// Move on floor only checks.
if (floor_block_on_wall && on_wall && motion_slide_up.dot(result.collision_normal) <= 0) {
// Avoid to move forward on a wall if floor_block_on_wall is true.
- if (was_on_floor && !on_floor && !vel_dir_facing_up) {
+ if (p_was_on_floor && !on_floor && !vel_dir_facing_up) {
// If the movement is large the body can be prevented from reaching the walls.
if (result.travel.length() <= margin) {
// Cancels the motion.
@@ -1145,8 +1159,7 @@ bool CharacterBody2D::move_and_slide() {
on_floor = true;
platform_rid = prev_platform_rid;
platform_layer = prev_platform_layer;
-
- platform_velocity = prev_platform_velocity;
+ platform_velocity = p_prev_platform_velocity;
floor_normal = prev_floor_normal;
linear_velocity = Vector2();
motion = Vector2();
@@ -1161,7 +1174,7 @@ bool CharacterBody2D::move_and_slide() {
}
}
// Constant Speed when the slope is upward.
- else if (floor_constant_speed && is_on_floor_only() && can_apply_constant_speed && was_on_floor && motion.dot(result.collision_normal) < 0) {
+ else if (floor_constant_speed && is_on_floor_only() && can_apply_constant_speed && p_was_on_floor && motion.dot(result.collision_normal) < 0) {
can_apply_constant_speed = false;
Vector2 motion_slide_norm = result.remainder.slide(result.collision_normal).normalized();
motion = motion_slide_norm * (motion_slide_up.length() - result.travel.slide(up_direction).length() - last_travel.slide(up_direction).length());
@@ -1197,7 +1210,7 @@ bool CharacterBody2D::move_and_slide() {
}
// When you move forward in a downward slope you don’t collide because you will be in the air.
// This test ensures that constant speed is applied, only if the player is still on the ground after the snap is applied.
- else if (floor_constant_speed && first_slide && _on_floor_if_snapped(was_on_floor, vel_dir_facing_up)) {
+ else if (floor_constant_speed && first_slide && _on_floor_if_snapped(p_was_on_floor, vel_dir_facing_up)) {
can_apply_constant_speed = false;
sliding_enabled = true;
Transform2D gt = get_global_transform();
@@ -1218,23 +1231,55 @@ bool CharacterBody2D::move_and_slide() {
}
}
- _snap_on_floor(was_on_floor, vel_dir_facing_up);
-
- if (!on_floor && !on_wall) {
- // Add last platform velocity when just left a moving platform.
- linear_velocity += current_platform_velocity;
- }
+ _snap_on_floor(p_was_on_floor, vel_dir_facing_up);
// Reset the gravity accumulation when touching the ground.
if (on_floor && !vel_dir_facing_up) {
linear_velocity = linear_velocity.slide(up_direction);
}
+}
- return motion_results.size() > 0;
+void CharacterBody2D::_move_and_slide_free(real_t p_delta) {
+ Vector2 motion = linear_velocity * p_delta;
+
+ platform_rid = RID();
+ floor_normal = Vector2();
+ platform_velocity = Vector2();
+
+ bool first_slide = true;
+ for (int iteration = 0; iteration < max_slides; ++iteration) {
+ PhysicsServer2D::MotionResult result;
+
+ bool collided = move_and_collide(motion, result, margin, false, false);
+
+ if (collided) {
+ motion_results.push_back(result);
+ _set_collision_direction(result);
+
+ if (free_mode_min_slide_angle != 0 && result.get_angle(-linear_velocity.normalized()) < free_mode_min_slide_angle + FLOOR_ANGLE_THRESHOLD) {
+ motion = Vector2();
+ } else if (first_slide) {
+ Vector2 motion_slide_norm = result.remainder.slide(result.collision_normal).normalized();
+ motion = motion_slide_norm * (motion.length() - result.travel.length());
+ } else {
+ motion = result.remainder.slide(result.collision_normal);
+ }
+
+ if (motion.dot(linear_velocity) <= 0.0) {
+ motion = Vector2();
+ }
+ }
+
+ first_slide = false;
+
+ if (!collided || motion.is_equal_approx(Vector2())) {
+ break;
+ }
+ }
}
void CharacterBody2D::_snap_on_floor(bool was_on_floor, bool vel_dir_facing_up) {
- if (Math::is_equal_approx(floor_snap_length, 0) || up_direction == Vector2() || on_floor || !was_on_floor || vel_dir_facing_up) {
+ if (Math::is_equal_approx(floor_snap_length, 0) || on_floor || !was_on_floor || vel_dir_facing_up) {
return;
}
@@ -1284,16 +1329,12 @@ bool CharacterBody2D::_on_floor_if_snapped(bool was_on_floor, bool vel_dir_facin
}
void CharacterBody2D::_set_collision_direction(const PhysicsServer2D::MotionResult &p_result) {
- if (up_direction == Vector2()) {
- return;
- }
-
- if (p_result.get_angle(up_direction) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //floor
+ if (motion_mode == MOTION_MODE_GROUNDED && p_result.get_angle(up_direction) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //floor
on_floor = true;
floor_normal = p_result.collision_normal;
platform_velocity = p_result.collider_velocity;
_set_platform_data(p_result);
- } else if (p_result.get_angle(-up_direction) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //ceiling
+ } else if (motion_mode == MOTION_MODE_GROUNDED && p_result.get_angle(-up_direction) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //ceiling
on_ceiling = true;
} else {
on_wall = true;
@@ -1435,6 +1476,14 @@ void CharacterBody2D::set_moving_platform_ignore_layers(uint32_t p_exclude_layer
moving_platform_ignore_layers = p_exclude_layers;
}
+void CharacterBody2D::set_motion_mode(MotionMode p_mode) {
+ motion_mode = p_mode;
+}
+
+CharacterBody2D::MotionMode CharacterBody2D::get_motion_mode() const {
+ return motion_mode;
+}
+
int CharacterBody2D::get_max_slides() const {
return max_slides;
}
@@ -1461,11 +1510,20 @@ void CharacterBody2D::set_floor_snap_length(real_t p_floor_snap_length) {
floor_snap_length = p_floor_snap_length;
}
+real_t CharacterBody2D::get_free_mode_min_slide_angle() const {
+ return free_mode_min_slide_angle;
+}
+
+void CharacterBody2D::set_free_mode_min_slide_angle(real_t p_radians) {
+ free_mode_min_slide_angle = p_radians;
+}
+
const Vector2 &CharacterBody2D::get_up_direction() const {
return up_direction;
}
void CharacterBody2D::set_up_direction(const Vector2 &p_up_direction) {
+ ERR_FAIL_COND_MSG(p_up_direction == Vector2(), "up_direction can't be equal to Vector2.ZERO, consider using Free motion mode instead.");
up_direction = p_up_direction.normalized();
}
@@ -1509,8 +1567,12 @@ void CharacterBody2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_floor_max_angle", "radians"), &CharacterBody2D::set_floor_max_angle);
ClassDB::bind_method(D_METHOD("get_floor_snap_length"), &CharacterBody2D::get_floor_snap_length);
ClassDB::bind_method(D_METHOD("set_floor_snap_length", "floor_snap_length"), &CharacterBody2D::set_floor_snap_length);
+ ClassDB::bind_method(D_METHOD("get_free_mode_min_slide_angle"), &CharacterBody2D::get_free_mode_min_slide_angle);
+ ClassDB::bind_method(D_METHOD("set_free_mode_min_slide_angle", "radians"), &CharacterBody2D::set_free_mode_min_slide_angle);
ClassDB::bind_method(D_METHOD("get_up_direction"), &CharacterBody2D::get_up_direction);
ClassDB::bind_method(D_METHOD("set_up_direction", "up_direction"), &CharacterBody2D::set_up_direction);
+ ClassDB::bind_method(D_METHOD("set_motion_mode", "mode"), &CharacterBody2D::set_motion_mode);
+ ClassDB::bind_method(D_METHOD("get_motion_mode"), &CharacterBody2D::get_motion_mode);
ClassDB::bind_method(D_METHOD("is_on_floor"), &CharacterBody2D::is_on_floor);
ClassDB::bind_method(D_METHOD("is_on_floor_only"), &CharacterBody2D::is_on_floor_only);
@@ -1525,10 +1587,13 @@ void CharacterBody2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &CharacterBody2D::_get_slide_collision);
ClassDB::bind_method(D_METHOD("get_last_slide_collision"), &CharacterBody2D::_get_last_slide_collision);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "motion_mode", PROPERTY_HINT_ENUM, "Grounded,Free", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_motion_mode", "get_motion_mode");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "slide_on_ceiling"), "set_slide_on_ceiling_enabled", "is_slide_on_ceiling_enabled");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_slides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_max_slides", "get_max_slides");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "up_direction"), "set_up_direction", "get_up_direction");
+ ADD_GROUP("Free Mode", "free_mode_");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "free_mode_min_slide_angle", PROPERTY_HINT_RANGE, "0,180,0.1,radians", PROPERTY_USAGE_DEFAULT), "set_free_mode_min_slide_angle", "get_free_mode_min_slide_angle");
ADD_GROUP("Floor", "floor_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "floor_stop_on_slope"), "set_floor_stop_on_slope_enabled", "is_floor_stop_on_slope_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "floor_constant_speed"), "set_floor_constant_speed_enabled", "is_floor_constant_speed_enabled");
@@ -1538,6 +1603,21 @@ void CharacterBody2D::_bind_methods() {
ADD_GROUP("Moving platform", "moving_platform");
ADD_PROPERTY(PropertyInfo(Variant::INT, "moving_platform_ignore_layers", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_moving_platform_ignore_layers", "get_moving_platform_ignore_layers");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision/safe_margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_safe_margin", "get_safe_margin");
+
+ BIND_ENUM_CONSTANT(MOTION_MODE_GROUNDED);
+ BIND_ENUM_CONSTANT(MOTION_MODE_FREE);
+}
+
+void CharacterBody2D::_validate_property(PropertyInfo &property) const {
+ if (motion_mode == MOTION_MODE_FREE) {
+ if (property.name.begins_with("floor_") || property.name == "up_direction" || property.name == "slide_on_ceiling") {
+ property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL;
+ }
+ } else {
+ if (property.name == "free_mode_min_slide_angle") {
+ property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL;
+ }
+ }
}
CharacterBody2D::CharacterBody2D() :
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 81c5067146..a999317953 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -189,6 +189,8 @@ protected:
void _notification(int p_what);
static void _bind_methods();
+ GDVIRTUAL1(_integrate_forces, PhysicsDirectBodyState2D *)
+
public:
void set_mode(Mode p_mode);
Mode get_mode() const;
@@ -268,8 +270,35 @@ VARIANT_ENUM_CAST(RigidBody2D::CCDMode);
class CharacterBody2D : public PhysicsBody2D {
GDCLASS(CharacterBody2D, PhysicsBody2D);
+public:
+ enum MotionMode {
+ MOTION_MODE_GROUNDED,
+ MOTION_MODE_FREE,
+ };
+ bool move_and_slide();
+
+ const Vector2 &get_linear_velocity() const;
+ void set_linear_velocity(const Vector2 &p_velocity);
+
+ bool is_on_floor() const;
+ bool is_on_floor_only() const;
+ bool is_on_wall() const;
+ bool is_on_wall_only() const;
+ bool is_on_ceiling() const;
+ bool is_on_ceiling_only() const;
+ Vector2 get_floor_normal() const;
+ real_t get_floor_angle(const Vector2 &p_up_direction = Vector2(0.0, -1.0)) const;
+ Vector2 get_platform_velocity() const;
+
+ int get_slide_collision_count() const;
+ PhysicsServer2D::MotionResult get_slide_collision(int p_bounce) const;
+
+ CharacterBody2D();
+ ~CharacterBody2D();
+
private:
real_t margin = 0.08;
+ MotionMode motion_mode = MOTION_MODE_GROUNDED;
bool floor_stop_on_slope = false;
bool floor_constant_speed = false;
@@ -279,6 +308,7 @@ private:
int platform_layer;
real_t floor_max_angle = Math::deg2rad((real_t)45.0);
float floor_snap_length = 0;
+ real_t free_mode_min_slide_angle = Math::deg2rad((real_t)15.0);
Vector2 up_direction = Vector2(0.0, -1.0);
uint32_t moving_platform_ignore_layers = 0;
Vector2 linear_velocity;
@@ -317,9 +347,18 @@ private:
real_t get_floor_snap_length();
void set_floor_snap_length(real_t p_floor_snap_length);
+ real_t get_free_mode_min_slide_angle() const;
+ void set_free_mode_min_slide_angle(real_t p_radians);
+
uint32_t get_moving_platform_ignore_layers() const;
void set_moving_platform_ignore_layers(const uint32_t p_exclude_layer);
+ void set_motion_mode(MotionMode p_mode);
+ MotionMode get_motion_mode() const;
+
+ void _move_and_slide_free(real_t p_delta);
+ void _move_and_slide_grounded(real_t p_delta, bool p_was_on_floor, const Vector2 &p_prev_platform_velocity);
+
Ref<KinematicCollision2D> _get_slide_collision(int p_bounce);
Ref<KinematicCollision2D> _get_last_slide_collision();
const Vector2 &get_up_direction() const;
@@ -332,30 +371,11 @@ private:
protected:
void _notification(int p_what);
static void _bind_methods();
-
-public:
- bool move_and_slide();
-
- const Vector2 &get_linear_velocity() const;
- void set_linear_velocity(const Vector2 &p_velocity);
-
- bool is_on_floor() const;
- bool is_on_floor_only() const;
- bool is_on_wall() const;
- bool is_on_wall_only() const;
- bool is_on_ceiling() const;
- bool is_on_ceiling_only() const;
- Vector2 get_floor_normal() const;
- real_t get_floor_angle(const Vector2 &p_up_direction = Vector2(0.0, -1.0)) const;
- Vector2 get_platform_velocity() const;
-
- int get_slide_collision_count() const;
- PhysicsServer2D::MotionResult get_slide_collision(int p_bounce) const;
-
- CharacterBody2D();
- ~CharacterBody2D();
+ virtual void _validate_property(PropertyInfo &property) const override;
};
+VARIANT_ENUM_CAST(CharacterBody2D::MotionMode);
+
class KinematicCollision2D : public RefCounted {
GDCLASS(KinematicCollision2D, RefCounted);
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 74eb3f2fc2..12aa1afc45 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -782,7 +782,7 @@ void TileMap::_rendering_update_dirty_quadrants(SelfList<TileMapQuadrant>::List
// Get the tile data.
TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(c.get_atlas_coords(), c.alternative_tile));
Ref<ShaderMaterial> mat = tile_data->tile_get_material();
- int z_index = layers[q.layer].z_index + tile_data->get_z_index();
+ int z_index = tile_data->get_z_index();
// Quandrant pos.
Vector2 position = map_to_world(q.coords * get_effective_quadrant_size(q.layer));
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp
index 508f8a70df..ab417fafdd 100644
--- a/scene/3d/light_3d.cpp
+++ b/scene/3d/light_3d.cpp
@@ -212,10 +212,6 @@ void Light3D::_validate_property(PropertyInfo &property) const {
property.usage = PROPERTY_USAGE_NONE;
}
- if (get_light_type() == RS::LIGHT_SPOT && property.name == "shadow_normal_bias") {
- property.usage = PROPERTY_USAGE_NONE;
- }
-
if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_projector") {
property.usage = PROPERTY_USAGE_NONE;
}
@@ -425,9 +421,7 @@ DirectionalLight3D::DirectionalLight3D() :
set_param(PARAM_SHADOW_MAX_DISTANCE, 100);
set_param(PARAM_SHADOW_FADE_START, 0.8);
// Increase the default shadow bias to better suit most scenes.
- // Leave normal bias untouched as it doesn't benefit DirectionalLight3D as much as OmniLight3D.
set_param(PARAM_SHADOW_BIAS, 0.1);
- set_param(PARAM_SHADOW_NORMAL_BIAS, 1.0);
set_shadow_mode(SHADOW_PARALLEL_4_SPLITS);
blend_splits = false;
}
@@ -468,8 +462,7 @@ OmniLight3D::OmniLight3D() :
Light3D(RenderingServer::LIGHT_OMNI) {
set_shadow_mode(SHADOW_CUBE);
// Increase the default shadow biases to better suit most scenes.
- set_param(PARAM_SHADOW_BIAS, 0.1);
- set_param(PARAM_SHADOW_NORMAL_BIAS, 2.0);
+ set_param(PARAM_SHADOW_BIAS, 0.2);
}
TypedArray<String> SpotLight3D::get_configuration_warnings() const {
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 092efc55d7..4c36618c99 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -599,9 +599,9 @@ void RigidBody3D::_direct_state_changed(Object *p_state) {
sleeping = state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
}
- if (get_script_instance()) {
- get_script_instance()->call("_integrate_forces", state);
- }
+
+ GDVIRTUAL_CALL(_integrate_forces, state);
+
set_ignore_transform_notification(false);
_on_transform_changed();
@@ -1022,7 +1022,7 @@ void RigidBody3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody3D::get_colliding_bodies);
- BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState3D")));
+ GDVIRTUAL_BIND(_integrate_forces, "state");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Dynamic,Static,DynamicLocked,Kinematic"), "set_mode", "get_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_RANGE, "0.01,65535,0.01,exp"), "set_mass", "get_mass");
diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h
index 9c40f92f06..26b9a39047 100644
--- a/scene/3d/physics_body_3d.h
+++ b/scene/3d/physics_body_3d.h
@@ -132,6 +132,8 @@ public:
MODE_KINEMATIC,
};
+ GDVIRTUAL1(_integrate_forces, PhysicsDirectBodyState3D *)
+
protected:
bool can_sleep = true;
PhysicsDirectBodyState3D *state = nullptr;
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index 543545b90f..88fb960164 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -36,8 +36,9 @@
#include "servers/audio/audio_stream.h"
void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const {
- if (get_script_instance()) {
- Array parameters = get_script_instance()->call("_get_parameter_list");
+ Array parameters;
+
+ if (GDVIRTUAL_CALL(_get_parameter_list, parameters)) {
for (int i = 0; i < parameters.size(); i++) {
Dictionary d = parameters[i];
ERR_CONTINUE(d.is_empty());
@@ -47,8 +48,9 @@ void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const {
}
Variant AnimationNode::get_parameter_default_value(const StringName &p_parameter) const {
- if (get_script_instance()) {
- return get_script_instance()->call("_get_parameter_default_value", p_parameter);
+ Variant ret;
+ if (GDVIRTUAL_CALL(_get_parameter_default_value, p_parameter, ret)) {
+ return ret;
}
return Variant();
}
@@ -72,8 +74,8 @@ Variant AnimationNode::get_parameter(const StringName &p_name) const {
}
void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) {
- if (get_script_instance()) {
- Dictionary cn = get_script_instance()->call("_get_child_nodes");
+ Dictionary cn;
+ if (GDVIRTUAL_CALL(_get_child_nodes, cn)) {
List<Variant> keys;
cn.get_key_list(&keys);
for (const Variant &E : keys) {
@@ -298,8 +300,9 @@ String AnimationNode::get_input_name(int p_input) {
}
String AnimationNode::get_caption() const {
- if (get_script_instance()) {
- return get_script_instance()->call("_get_caption");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_caption, ret)) {
+ return ret;
}
return "Node";
@@ -329,8 +332,9 @@ void AnimationNode::remove_input(int p_index) {
}
double AnimationNode::process(double p_time, bool p_seek) {
- if (get_script_instance()) {
- return get_script_instance()->call("_process", p_time, p_seek);
+ double ret;
+ if (GDVIRTUAL_CALL(_process, p_time, p_seek, ret)) {
+ return ret;
}
return 0;
@@ -357,8 +361,9 @@ bool AnimationNode::is_path_filtered(const NodePath &p_path) const {
}
bool AnimationNode::has_filter() const {
- if (get_script_instance()) {
- return get_script_instance()->call("_has_filter");
+ bool ret;
+ if (GDVIRTUAL_CALL(_has_filter, ret)) {
+ return ret;
}
return false;
@@ -390,8 +395,9 @@ void AnimationNode::_validate_property(PropertyInfo &property) const {
}
Ref<AnimationNode> AnimationNode::get_child_by_name(const StringName &p_name) {
- if (get_script_instance()) {
- return get_script_instance()->call("_get_child_by_name", p_name);
+ Ref<AnimationNode> ret;
+ if (GDVIRTUAL_CALL(_get_child_by_name, p_name, ret)) {
+ return ret;
}
return Ref<AnimationNode>();
}
@@ -422,17 +428,13 @@ void AnimationNode::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_filter_enabled", "is_filter_enabled");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "filters", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_filters", "_get_filters");
- BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_child_nodes"));
- BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_parameter_list"));
- BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_get_child_by_name", PropertyInfo(Variant::STRING, "name")));
- {
- MethodInfo mi = MethodInfo(Variant::NIL, "_get_parameter_default_value", PropertyInfo(Variant::STRING_NAME, "name"));
- mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
- BIND_VMETHOD(mi);
- }
- BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::FLOAT, "time"), PropertyInfo(Variant::BOOL, "seek")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_caption"));
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_filter"));
+ GDVIRTUAL_BIND(_get_child_nodes);
+ GDVIRTUAL_BIND(_get_parameter_list);
+ GDVIRTUAL_BIND(_get_child_by_name, "name");
+ GDVIRTUAL_BIND(_get_parameter_default_value, "parameter");
+ GDVIRTUAL_BIND(_process, "time", "seek");
+ GDVIRTUAL_BIND(_get_caption);
+ GDVIRTUAL_BIND(_has_filter);
ADD_SIGNAL(MethodInfo("removed_from_graph"));
diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h
index 59bbc5b4da..1e0267682e 100644
--- a/scene/animation/animation_tree.h
+++ b/scene/animation/animation_tree.h
@@ -112,6 +112,14 @@ protected:
void _set_parent(Object *p_parent);
+ GDVIRTUAL0RC(Dictionary, _get_child_nodes)
+ GDVIRTUAL0RC(Array, _get_parameter_list)
+ GDVIRTUAL1RC(Ref<AnimationNode>, _get_child_by_name, StringName)
+ GDVIRTUAL1RC(Variant, _get_parameter_default_value, StringName)
+ GDVIRTUAL2RC(double, _process, double, bool)
+ GDVIRTUAL0RC(String, _get_caption)
+ GDVIRTUAL0RC(bool, _has_filter)
+
public:
virtual void get_parameter_list(List<PropertyInfo> *r_list) const;
virtual Variant get_parameter_default_value(const StringName &p_parameter) const;
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
index df1aece80a..f4e477b613 100644
--- a/scene/debugger/scene_debugger.cpp
+++ b/scene/debugger/scene_debugger.cpp
@@ -88,7 +88,7 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra
} else if (p_msg == "override_camera_2D:transform") {
ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA);
- Transform2D transform = p_args[1];
+ Transform2D transform = p_args[0];
scene_tree->get_root()->set_canvas_transform_override(transform);
#ifndef _3D_DISABLED
} else if (p_msg == "override_camera_3D:set") {
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index d252a4507c..03c75b25f4 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -121,17 +121,13 @@ void BaseButton::_notification(int p_what) {
}
void BaseButton::_pressed() {
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_pressed);
- }
+ GDVIRTUAL_CALL(_pressed);
pressed();
emit_signal(SNAME("pressed"));
}
void BaseButton::_toggled(bool p_pressed) {
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, p_pressed);
- }
+ GDVIRTUAL_CALL(_toggled, p_pressed);
toggled(p_pressed);
emit_signal(SNAME("toggled"), p_pressed);
}
@@ -440,8 +436,8 @@ void BaseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shortcut_context", "node"), &BaseButton::set_shortcut_context);
ClassDB::bind_method(D_METHOD("get_shortcut_context"), &BaseButton::get_shortcut_context);
- BIND_VMETHOD(MethodInfo("_pressed"));
- BIND_VMETHOD(MethodInfo("_toggled", PropertyInfo(Variant::BOOL, "button_pressed")));
+ GDVIRTUAL_BIND(_pressed);
+ GDVIRTUAL_BIND(_toggled, "button_pressed");
ADD_SIGNAL(MethodInfo("pressed"));
ADD_SIGNAL(MethodInfo("button_up"));
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index d86b35daf0..cf1904344b 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -81,6 +81,9 @@ protected:
bool _is_focus_owner_in_shorcut_context() const;
+ GDVIRTUAL0(_pressed)
+ GDVIRTUAL1(_toggled, bool)
+
public:
enum DrawMode {
DRAW_NORMAL,
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 08dd7f28eb..7cc2352353 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -450,7 +450,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->is_action("ui_text_backspace", true)) {
backspace();
- _filter_code_completion_candidates();
+ _filter_code_completion_candidates_impl();
accept_event();
return;
}
@@ -522,7 +522,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
TextEdit::_gui_input(p_gui_input);
if (update_code_completion) {
- _filter_code_completion_candidates();
+ _filter_code_completion_candidates_impl();
}
}
@@ -557,7 +557,7 @@ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const {
/* Text manipulation */
// Overridable actions
-void CodeEdit::_handle_unicode_input(const uint32_t p_unicode) {
+void CodeEdit::_handle_unicode_input_internal(const uint32_t p_unicode) {
bool had_selection = has_selection();
if (had_selection) {
begin_complex_operation();
@@ -609,7 +609,7 @@ void CodeEdit::_handle_unicode_input(const uint32_t p_unicode) {
}
}
-void CodeEdit::_backspace() {
+void CodeEdit::_backspace_internal() {
if (!is_editable()) {
return;
}
@@ -1739,9 +1739,7 @@ String CodeEdit::get_text_for_code_completion() const {
}
void CodeEdit::request_code_completion(bool p_force) {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_request_code_completion")) {
- si->call("_request_code_completion", p_force);
+ if (GDVIRTUAL_CALL(_request_code_completion, p_force)) {
return;
}
@@ -1798,7 +1796,7 @@ void CodeEdit::update_code_completion_options(bool p_forced) {
code_completion_forced = p_forced;
code_completion_option_sources = code_completion_option_submitted;
code_completion_option_submitted.clear();
- _filter_code_completion_candidates();
+ _filter_code_completion_candidates_impl();
}
TypedArray<Dictionary> CodeEdit::get_code_completion_options() const {
@@ -1855,11 +1853,10 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
return;
}
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_confirm_code_completion")) {
- si->call("_confirm_code_completion", p_replace);
+ if (GDVIRTUAL_CALL(_confirm_code_completion, p_replace)) {
return;
}
+
begin_complex_operation();
int caret_line = get_caret_line();
@@ -2179,9 +2176,10 @@ void CodeEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_code_comletion_prefixes"), &CodeEdit::get_code_completion_prefixes);
// Overridable
- BIND_VMETHOD(MethodInfo("_confirm_code_completion", PropertyInfo(Variant::BOOL, "replace")));
- BIND_VMETHOD(MethodInfo("_request_code_completion", PropertyInfo(Variant::BOOL, "force")));
- BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_filter_code_completion_candidates", PropertyInfo(Variant::ARRAY, "candidates")));
+
+ GDVIRTUAL_BIND(_confirm_code_completion, "replace")
+ GDVIRTUAL_BIND(_request_code_completion, "force")
+ GDVIRTUAL_BIND(_filter_code_completion_candidates, "candidates")
/* Line length guidelines */
ClassDB::bind_method(D_METHOD("set_line_length_guidelines", "guideline_columns"), &CodeEdit::set_line_length_guidelines);
@@ -2650,11 +2648,10 @@ TypedArray<String> CodeEdit::_get_delimiters(DelimiterType p_type) const {
}
/* Code Completion */
-void CodeEdit::_filter_code_completion_candidates() {
- ScriptInstance *si = get_script_instance();
+void CodeEdit::_filter_code_completion_candidates_impl() {
int line_height = get_line_height();
- if (si && si->has_method("_filter_code_completion_candidates")) {
+ if (GDVIRTUAL_IS_OVERRIDEN(_filter_code_completion_candidates)) {
code_completion_options.clear();
code_completion_base = "";
@@ -2674,7 +2671,9 @@ void CodeEdit::_filter_code_completion_candidates() {
i++;
}
- TypedArray<Dictionary> completion_options = si->call("_filter_code_completion_candidates", completion_options_sources);
+ Array completion_options;
+
+ GDVIRTUAL_CALL(_filter_code_completion_candidates, completion_options_sources, completion_options);
/* No options to complete, cancel. */
if (completion_options.size() == 0) {
diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h
index 76ac15f553..aa62cbdf3c 100644
--- a/scene/gui/code_edit.h
+++ b/scene/gui/code_edit.h
@@ -219,7 +219,7 @@ private:
List<ScriptCodeCompletionOption> code_completion_option_sources;
String code_completion_base;
- void _filter_code_completion_candidates();
+ void _filter_code_completion_candidates_impl();
/* Line length guidelines */
TypedArray<int> line_length_guideline_columns;
@@ -256,8 +256,12 @@ protected:
/* Text manipulation */
// Overridable actions
- virtual void _handle_unicode_input(const uint32_t p_unicode) override;
- virtual void _backspace() override;
+ virtual void _handle_unicode_input_internal(const uint32_t p_unicode) override;
+ virtual void _backspace_internal() override;
+
+ GDVIRTUAL1(_confirm_code_completion, bool)
+ GDVIRTUAL1(_request_code_completion, bool)
+ GDVIRTUAL1RC(Array, _filter_code_completion_candidates, TypedArray<Dictionary>)
public:
/* General overrides */
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 261480bcdd..661e0dc648 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -46,13 +46,13 @@ void ColorPicker::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker")));
- bt_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
-
+ btn_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
+ _update_presets();
_update_controls();
} break;
case NOTIFICATION_ENTER_TREE: {
btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker")));
- bt_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
+ btn_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
_update_controls();
_update_color();
@@ -69,7 +69,6 @@ void ColorPicker::_notification(int p_what) {
for (int i = 0; i < preset_cache.size(); i++) {
presets.push_back(preset_cache[i]);
}
- preset->update();
}
#endif
} break;
@@ -372,22 +371,23 @@ void ColorPicker::_update_color(bool p_update_sliders) {
}
void ColorPicker::_update_presets() {
- return;
- //presets should be shown using buttons or something else, this method is not a good idea
-
- presets_per_row = 10;
- Size2 size = bt_add_preset->get_size();
- Size2 preset_size = Size2(MIN(size.width * presets.size(), presets_per_row * size.width), size.height * (Math::ceil((float)presets.size() / presets_per_row)));
- preset->set_custom_minimum_size(preset_size);
- preset_container->set_custom_minimum_size(preset_size);
- preset->draw_rect(Rect2(Point2(), preset_size), Color(1, 1, 1, 0));
-
- for (int i = 0; i < presets.size(); i++) {
- int x = (i % presets_per_row) * size.width;
- int y = (Math::floor((float)i / presets_per_row)) * size.height;
- preset->draw_rect(Rect2(Point2(x, y), size), presets[i]);
+ int preset_size = _get_preset_size();
+ // Only update the preset button size if it has changed.
+ if (preset_size != prev_preset_size) {
+ prev_preset_size = preset_size;
+ btn_add_preset->set_custom_minimum_size(Size2(preset_size, preset_size));
+ for (int i = 1; i < preset_container->get_child_count(); i++) {
+ ColorPresetButton *cpb = Object::cast_to<ColorPresetButton>(preset_container->get_child(i));
+ cpb->set_custom_minimum_size(Size2(preset_size, preset_size));
+ }
+ }
+ // Only load preset buttons when the only child is the add-preset button.
+ if (preset_container->get_child_count() == 1) {
+ for (int i = 0; i < preset_cache.size(); i++) {
+ _add_preset_button(preset_size, preset_cache[i]);
+ }
+ _notification(NOTIFICATION_VISIBILITY_CHANGED);
}
- _notification(NOTIFICATION_VISIBILITY_CHANGED);
}
void ColorPicker::_text_type_toggled() {
@@ -422,14 +422,37 @@ ColorPicker::PickerShapeType ColorPicker::get_picker_shape() const {
return picker_type;
}
+inline int ColorPicker::_get_preset_size() {
+ return (int(get_minimum_size().width) - (preset_container->get_theme_constant(SNAME("hseparation")) * (preset_column_count - 1))) / preset_column_count;
+}
+
+void ColorPicker::_add_preset_button(int p_size, const Color &p_color) {
+ ColorPresetButton *btn_preset = memnew(ColorPresetButton(p_color));
+ btn_preset->set_preset_color(p_color);
+ btn_preset->set_custom_minimum_size(Size2(p_size, p_size));
+ btn_preset->connect("gui_input", callable_mp(this, &ColorPicker::_preset_input), varray(p_color));
+ btn_preset->set_tooltip(vformat(RTR("Color: #%s\nLMB: Apply color\nRMB: Remove preset"), p_color.to_html(p_color.a < 1)));
+ preset_container->add_child(btn_preset);
+}
+
void ColorPicker::add_preset(const Color &p_color) {
if (presets.find(p_color)) {
presets.move_to_back(presets.find(p_color));
+
+ // Find button to move to the end.
+ for (int i = 1; i < preset_container->get_child_count(); i++) {
+ ColorPresetButton *current_btn = Object::cast_to<ColorPresetButton>(preset_container->get_child(i));
+ if (current_btn && p_color == current_btn->get_preset_color()) {
+ preset_container->move_child(current_btn, preset_container->get_child_count() - 1);
+ break;
+ }
+ }
} else {
presets.push_back(p_color);
preset_cache.push_back(p_color);
+
+ _add_preset_button(_get_preset_size(), p_color);
}
- preset->update();
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
@@ -443,7 +466,15 @@ void ColorPicker::erase_preset(const Color &p_color) {
if (presets.find(p_color)) {
presets.erase(presets.find(p_color));
preset_cache.erase(preset_cache.find(p_color));
- preset->update();
+
+ // Find preset button to remove.
+ for (int i = 1; i < preset_container->get_child_count(); i++) {
+ ColorPresetButton *current_btn = Object::cast_to<ColorPresetButton>(preset_container->get_child(i));
+ if (current_btn && p_color == current_btn->get_preset_color()) {
+ current_btn->queue_delete();
+ break;
+ }
+ }
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
@@ -560,7 +591,7 @@ void ColorPicker::_sample_draw() {
const Rect2 rect_old = Rect2(Point2(), Size2(sample->get_size().width * 0.5, sample->get_size().height * 0.95));
if (display_old_color && old_color.a < 1.0) {
- sample->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), rect_old, true);
+ sample->draw_texture_rect(get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), rect_old, true);
}
sample->draw_rect(rect_old, old_color);
@@ -574,7 +605,7 @@ void ColorPicker::_sample_draw() {
}
if (color.a < 1.0) {
- sample->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), rect_new, true);
+ sample->draw_texture_rect(get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), rect_new, true);
}
sample->draw_rect(rect_new, color);
@@ -734,7 +765,7 @@ void ColorPicker::_slider_draw(int p_which) {
#endif
if (p_which == 3) {
- scroll[p_which]->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), Rect2(Point2(0, margin), Size2(size.x, margin)), true);
+ scroll[p_which]->draw_texture_rect(get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), Rect2(Point2(0, margin), Size2(size.x, margin)), true);
left_color = color;
left_color.a = 0;
@@ -932,43 +963,19 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
}
}
-void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
+void ColorPicker::_preset_input(const Ref<InputEvent> &p_event, const Color &p_color) {
Ref<InputEventMouseButton> bev = p_event;
if (bev.is_valid()) {
- int index = 0;
if (bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_LEFT) {
- for (int i = 0; i < presets.size(); i++) {
- int x = (i % presets_per_row) * bt_add_preset->get_size().x;
- int y = (Math::floor((float)i / presets_per_row)) * bt_add_preset->get_size().y;
- if (bev->get_position().x > x && bev->get_position().x < x + preset->get_size().x && bev->get_position().y > y && bev->get_position().y < y + preset->get_size().y) {
- index = i;
- }
- }
- set_pick_color(presets[index]);
+ set_pick_color(p_color);
_update_color();
- emit_signal(SNAME("color_changed"), color);
+ emit_signal(SNAME("color_changed"), p_color);
} else if (bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_RIGHT && presets_enabled) {
- index = bev->get_position().x / (preset->get_size().x / presets.size());
- Color clicked_preset = presets[index];
- erase_preset(clicked_preset);
- emit_signal(SNAME("preset_removed"), clicked_preset);
- bt_add_preset->show();
+ erase_preset(p_color);
+ emit_signal(SNAME("preset_removed"), p_color);
}
}
-
- Ref<InputEventMouseMotion> mev = p_event;
-
- if (mev.is_valid()) {
- int index = mev->get_position().x * presets.size();
- if (preset->get_size().x != 0) {
- index /= preset->get_size().x;
- }
- if (index < 0 || index >= presets.size()) {
- return;
- }
- preset->set_tooltip(vformat(RTR("Color: #%s\nLMB: Set color\nRMB: Remove preset"), presets[index].to_html(presets[index].a < 1)));
- }
}
void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
@@ -1064,11 +1071,11 @@ void ColorPicker::_html_focus_exit() {
void ColorPicker::set_presets_enabled(bool p_enabled) {
presets_enabled = p_enabled;
if (!p_enabled) {
- bt_add_preset->set_disabled(true);
- bt_add_preset->set_focus_mode(FOCUS_NONE);
+ btn_add_preset->set_disabled(true);
+ btn_add_preset->set_focus_mode(FOCUS_NONE);
} else {
- bt_add_preset->set_disabled(false);
- bt_add_preset->set_focus_mode(FOCUS_ALL);
+ btn_add_preset->set_disabled(false);
+ btn_add_preset->set_focus_mode(FOCUS_ALL);
}
}
@@ -1080,7 +1087,6 @@ void ColorPicker::set_presets_visible(bool p_visible) {
presets_visible = p_visible;
preset_separator->set_visible(p_visible);
preset_container->set_visible(p_visible);
- preset_container2->set_visible(p_visible);
}
bool ColorPicker::are_presets_visible() const {
@@ -1266,17 +1272,13 @@ ColorPicker::ColorPicker() :
add_child(preset_separator);
preset_container->set_h_size_flags(SIZE_EXPAND_FILL);
+ preset_container->set_columns(preset_column_count);
add_child(preset_container);
- preset_container->add_child(preset);
- preset->connect("gui_input", callable_mp(this, &ColorPicker::_preset_input));
- preset->connect("draw", callable_mp(this, &ColorPicker::_update_presets));
-
- preset_container2->set_h_size_flags(SIZE_EXPAND_FILL);
- add_child(preset_container2);
- preset_container2->add_child(bt_add_preset);
- bt_add_preset->set_tooltip(RTR("Add current color as a preset."));
- bt_add_preset->connect("pressed", callable_mp(this, &ColorPicker::_add_preset_pressed));
+ btn_add_preset->set_icon_align(Button::ALIGN_CENTER);
+ btn_add_preset->set_tooltip(RTR("Add current color as a preset."));
+ btn_add_preset->connect("pressed", callable_mp(this, &ColorPicker::_add_preset_pressed));
+ preset_container->add_child(btn_add_preset);
}
/////////////////
@@ -1303,6 +1305,7 @@ void ColorPickerButton::pressed() {
_update_picker();
popup->set_as_minsize();
+ picker->_update_presets();
Rect2i usable_rect = popup->get_usable_parent_rect();
//let's try different positions to see which one we can use
@@ -1428,3 +1431,64 @@ void ColorPickerButton::_bind_methods() {
ColorPickerButton::ColorPickerButton() {
set_toggle_mode(true);
}
+
+/////////////////
+
+void ColorPresetButton::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ const Rect2 r = Rect2(Point2(0, 0), get_size());
+ Ref<StyleBox> sb_raw = get_theme_stylebox(SNAME("preset_fg"), SNAME("ColorPresetButton"))->duplicate();
+ Ref<StyleBoxFlat> sb_flat = sb_raw;
+ Ref<StyleBoxTexture> sb_texture = sb_raw;
+
+ if (sb_flat.is_valid()) {
+ if (preset_color.a < 1) {
+ // Draw a background pattern when the color is transparent.
+ sb_flat->set_bg_color(Color(1, 1, 1));
+ sb_flat->draw(get_canvas_item(), r);
+
+ Rect2 bg_texture_rect = r.grow_side(SIDE_LEFT, -sb_flat->get_margin(SIDE_LEFT));
+ bg_texture_rect = bg_texture_rect.grow_side(SIDE_RIGHT, -sb_flat->get_margin(SIDE_RIGHT));
+ bg_texture_rect = bg_texture_rect.grow_side(SIDE_TOP, -sb_flat->get_margin(SIDE_TOP));
+ bg_texture_rect = bg_texture_rect.grow_side(SIDE_BOTTOM, -sb_flat->get_margin(SIDE_BOTTOM));
+
+ draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPresetButton")), bg_texture_rect, true);
+ sb_flat->set_bg_color(preset_color);
+ }
+ sb_flat->set_bg_color(preset_color);
+ sb_flat->draw(get_canvas_item(), r);
+ } else if (sb_texture.is_valid()) {
+ if (preset_color.a < 1) {
+ // Draw a background pattern when the color is transparent.
+ bool use_tile_texture = (sb_texture->get_h_axis_stretch_mode() == StyleBoxTexture::AxisStretchMode::AXIS_STRETCH_MODE_TILE) || (sb_texture->get_h_axis_stretch_mode() == StyleBoxTexture::AxisStretchMode::AXIS_STRETCH_MODE_TILE_FIT);
+ draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPresetButton")), r, use_tile_texture);
+ }
+ sb_texture->set_modulate(preset_color);
+ sb_texture->draw(get_canvas_item(), r);
+ } else {
+ WARN_PRINT("Unsupported StyleBox used for ColorPresetButton. Use StyleBoxFlat or StyleBoxTexture instead.");
+ }
+ if (preset_color.r > 1 || preset_color.g > 1 || preset_color.b > 1) {
+ // Draw an indicator to denote that the color is "overbright" and can't be displayed accurately in the preview
+ draw_texture(Control::get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPresetButton")), Vector2(0, 0));
+ }
+
+ } break;
+ }
+}
+
+void ColorPresetButton::set_preset_color(const Color &p_color) {
+ preset_color = p_color;
+}
+
+Color ColorPresetButton::get_preset_color() const {
+ return preset_color;
+}
+
+ColorPresetButton::ColorPresetButton(Color p_color) {
+ preset_color = p_color;
+}
+
+ColorPresetButton::~ColorPresetButton() {
+}
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index 60da3957aa..67ca007eb5 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -35,6 +35,7 @@
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/check_button.h"
+#include "scene/gui/grid_container.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/popup.h"
@@ -43,6 +44,22 @@
#include "scene/gui/spin_box.h"
#include "scene/gui/texture_rect.h"
+class ColorPresetButton : public BaseButton {
+ GDCLASS(ColorPresetButton, BaseButton);
+
+ Color preset_color;
+
+protected:
+ void _notification(int);
+
+public:
+ void set_preset_color(const Color &p_color);
+ Color get_preset_color() const;
+
+ ColorPresetButton(Color p_color);
+ ~ColorPresetButton();
+};
+
class ColorPicker : public BoxContainer {
GDCLASS(ColorPicker, BoxContainer);
@@ -69,12 +86,9 @@ private:
Control *wheel = memnew(Control);
Control *wheel_uv = memnew(Control);
TextureRect *sample = memnew(TextureRect);
- TextureRect *preset = memnew(TextureRect);
- HBoxContainer *preset_container = memnew(HBoxContainer);
- HBoxContainer *preset_container2 = memnew(HBoxContainer);
+ GridContainer *preset_container = memnew(GridContainer);
HSeparator *preset_separator = memnew(HSeparator);
- Button *bt_add_preset = memnew(Button);
- List<Color> presets;
+ Button *btn_add_preset = memnew(Button);
Button *btn_pick = memnew(Button);
CheckButton *btn_hsv = memnew(CheckButton);
CheckButton *btn_raw = memnew(CheckButton);
@@ -83,14 +97,19 @@ private:
Label *labels[4];
Button *text_type = memnew(Button);
LineEdit *c_text = memnew(LineEdit);
+
bool edit_alpha = true;
Size2i ms;
bool text_is_constructor = false;
- int presets_per_row = 0;
PickerShapeType picker_type = SHAPE_HSV_WHEEL;
+ const int preset_column_count = 9;
+ int prev_preset_size = 0;
+ List<Color> presets;
+
Color color;
Color old_color;
+
bool display_old_color = false;
bool raw_mode_enabled = false;
bool hsv_mode_enabled = false;
@@ -100,6 +119,7 @@ private:
bool spinning = false;
bool presets_enabled = true;
bool presets_visible = true;
+
float h = 0.0;
float s = 0.0;
float v = 0.0;
@@ -109,7 +129,6 @@ private:
void _value_changed(double);
void _update_controls();
void _update_color(bool p_update_sliders = true);
- void _update_presets();
void _update_text_value();
void _text_type_toggled();
void _sample_input(const Ref<InputEvent> &p_event);
@@ -119,7 +138,7 @@ private:
void _uv_input(const Ref<InputEvent> &p_event, Control *c);
void _w_input(const Ref<InputEvent> &p_event);
- void _preset_input(const Ref<InputEvent> &p_event);
+ void _preset_input(const Ref<InputEvent> &p_event, const Color &p_color);
void _screen_input(const Ref<InputEvent> &p_event);
void _add_preset_pressed();
void _screen_pick_pressed();
@@ -127,6 +146,9 @@ private:
void _focus_exit();
void _html_focus_exit();
+ inline int _get_preset_size();
+ void _add_preset_button(int p_size, const Color &p_color);
+
protected:
void _notification(int);
static void _bind_methods();
@@ -152,6 +174,7 @@ public:
void add_preset(const Color &p_color);
void erase_preset(const Color &p_color);
PackedColorArray get_presets() const;
+ void _update_presets();
void set_hsv_mode(bool p_enabled);
bool is_hsv_mode() const;
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index f114e06c75..6dba23d3c7 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -730,14 +730,9 @@ Variant Control::get_drag_data(const Point2 &p_point) {
}
}
- if (get_script_instance()) {
- Variant v = p_point;
- const Variant *p = &v;
- Callable::CallError ce;
- Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_get_drag_data, &p, 1, ce);
- if (ce.error == Callable::CallError::CALL_OK) {
- return ret;
- }
+ Variant dd;
+ if (GDVIRTUAL_CALL(_get_drag_data, p_point, dd)) {
+ return dd;
}
return Variant();
@@ -752,16 +747,10 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const
}
}
- if (get_script_instance()) {
- Variant v = p_point;
- const Variant *p[2] = { &v, &p_data };
- Callable::CallError ce;
- Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_can_drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK) {
- return ret;
- }
+ bool ret;
+ if (GDVIRTUAL_CALL(_can_drop_data, p_point, p_data, ret)) {
+ return ret;
}
-
return false;
}
@@ -775,15 +764,7 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
}
}
- if (get_script_instance()) {
- Variant v = p_point;
- const Variant *p[2] = { &v, &p_data };
- Callable::CallError ce;
- Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK) {
- return;
- }
- }
+ GDVIRTUAL_CALL(_drop_data, p_point, p_data);
}
void Control::force_drag(const Variant &p_data, Control *p_control) {
@@ -800,15 +781,11 @@ void Control::set_drag_preview(Control *p_control) {
}
Size2 Control::get_minimum_size() const {
- ScriptInstance *si = const_cast<Control *>(this)->get_script_instance();
- if (si) {
- Callable::CallError ce;
- Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, nullptr, 0, ce);
- if (ce.error == Callable::CallError::CALL_OK) {
- return s;
- }
+ Vector2 ms;
+ if (GDVIRTUAL_CALL(_get_minimum_size, ms)) {
+ return ms;
}
- return Size2();
+ return Vector2();
}
template <class T>
@@ -2123,8 +2100,9 @@ String Control::get_tooltip(const Point2 &p_pos) const {
}
Control *Control::make_custom_tooltip(const String &p_text) const {
- if (get_script_instance()) {
- return const_cast<Control *>(this)->call("_make_custom_tooltip", p_text);
+ Object *ret = nullptr;
+ if (GDVIRTUAL_CALL(_make_custom_tooltip, p_text, ret)) {
+ return Object::cast_to<Control>(ret);
}
return nullptr;
}
@@ -2499,14 +2477,11 @@ Vector<Vector2i> Control::structured_text_parser(StructuredTextParser p_theme_ty
}
} break;
case STRUCTURED_TEXT_CUSTOM: {
- if (get_script_instance()) {
- Variant data = get_script_instance()->call(SceneStringNames::get_singleton()->_structured_text_parser, p_args, p_text);
- if (data.get_type() == Variant::ARRAY) {
- Array _data = data;
- for (int i = 0; i < _data.size(); i++) {
- if (_data[i].get_type() == Variant::VECTOR2I) {
- ret.push_back(Vector2i(_data[i]));
- }
+ Array r;
+ if (GDVIRTUAL_CALL(_structured_text_parser, p_args, p_text, r)) {
+ for (int i = 0; i < r.size(); i++) {
+ if (r[i].get_type() == Variant::VECTOR2I) {
+ ret.push_back(Vector2i(r[i]));
}
}
}
@@ -2823,20 +2798,7 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate);
ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating);
- BIND_VMETHOD(MethodInfo("_structured_text_parser", PropertyInfo(Variant::ARRAY, "args"), PropertyInfo(Variant::STRING, "text")));
-
BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
- BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size"));
-
- MethodInfo get_drag_data = MethodInfo("_get_drag_data", PropertyInfo(Variant::VECTOR2, "position"));
- get_drag_data.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
- BIND_VMETHOD(get_drag_data);
-
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data")));
- BIND_VMETHOD(MethodInfo("_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data")));
- BIND_VMETHOD(MethodInfo(
- PropertyInfo(Variant::OBJECT, "control", PROPERTY_HINT_RESOURCE_TYPE, "Control"),
- "_make_custom_tooltip", PropertyInfo(Variant::STRING, "for_text")));
ADD_GROUP("Anchor", "anchor_");
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_LEFT);
@@ -2994,5 +2956,12 @@ void Control::_bind_methods() {
ADD_SIGNAL(MethodInfo("minimum_size_changed"));
ADD_SIGNAL(MethodInfo("theme_changed"));
- GDVIRTUAL_BIND(_has_point);
+ GDVIRTUAL_BIND(_has_point, "position");
+ GDVIRTUAL_BIND(_structured_text_parser, "args", "text");
+ GDVIRTUAL_BIND(_get_minimum_size);
+
+ GDVIRTUAL_BIND(_get_drag_data, "at_position")
+ GDVIRTUAL_BIND(_can_drop_data, "at_position", "data")
+ GDVIRTUAL_BIND(_drop_data, "at_position", "data")
+ GDVIRTUAL_BIND(_make_custom_tooltip, "for_text")
}
diff --git a/scene/gui/control.h b/scene/gui/control.h
index a871a8e9fb..0d7a3b8de0 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -273,6 +273,16 @@ private:
_FORCE_INLINE_ void _get_theme_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) const;
GDVIRTUAL1RC(bool, _has_point, Vector2)
+ GDVIRTUAL2RC(Array, _structured_text_parser, Array, String)
+ GDVIRTUAL0RC(Vector2, _get_minimum_size)
+
+ GDVIRTUAL1RC(Variant, _get_drag_data, Vector2)
+ GDVIRTUAL2RC(bool, _can_drop_data, Vector2, Variant)
+ GDVIRTUAL2(_drop_data, Vector2, Variant)
+ GDVIRTUAL1RC(Object *, _make_custom_tooltip, String)
+
+ //GDVIRTUAL1(_gui_input, Ref<InputEvent>)
+
protected:
virtual void add_child_notify(Node *p_child) override;
virtual void remove_child_notify(Node *p_child) override;
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index fcecbb5fca..ac1dea5e94 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -805,68 +805,35 @@ bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos, c
return true;
}
-template <class Vector2>
-static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, Vector2 start, Vector2 control_1, Vector2 control_2, Vector2 end) {
- /* Formula from Wikipedia article on Bezier curves. */
- real_t omt = (1.0 - t);
- real_t omt2 = omt * omt;
- real_t omt3 = omt2 * omt;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3;
-}
-
-void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const {
- float mp = p_begin + (p_end - p_begin) * 0.5;
- Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b);
- Vector2 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b);
- Vector2 end = _bezier_interp(p_end, p_a, p_a + p_out, p_b + p_in, p_b);
-
- Vector2 na = (mid - beg).normalized();
- Vector2 nb = (end - mid).normalized();
- float dp = Math::rad2deg(Math::acos(na.dot(nb)));
-
- if (p_depth >= p_min_depth && (dp < p_tol || p_depth >= p_max_depth)) {
- points.push_back((beg + end) * 0.5);
- colors.push_back(p_color.lerp(p_to_color, mp));
- lines++;
- } else {
- _bake_segment2d(points, colors, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
- _bake_segment2d(points, colors, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
- }
-}
-
-void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_bezier_ratio) {
- //cubic bezier code
- float diff = p_to.x - p_from.x;
- float cp_offset;
- int cp_len = get_theme_constant(SNAME("bezier_len_pos")) * p_bezier_ratio;
- int cp_neg_len = get_theme_constant(SNAME("bezier_len_neg")) * p_bezier_ratio;
-
- if (diff > 0) {
- cp_offset = MIN(cp_len, diff * 0.5);
- } else {
- cp_offset = MAX(MIN(cp_len - diff, cp_neg_len), -diff * 0.5);
+PackedVector2Array GraphEdit::get_connection_line(const Vector2 &p_from, const Vector2 &p_to) {
+ if (get_script_instance() && get_script_instance()->get_script().is_valid() && get_script_instance()->has_method("_get_connection_line")) {
+ return get_script_instance()->call("_get_connection_line", p_from, p_to);
}
- Vector2 c1 = Vector2(cp_offset * zoom, 0);
- Vector2 c2 = Vector2(-cp_offset * zoom, 0);
-
- int lines = 0;
+ Curve2D curve;
+ Vector<Color> colors;
+ curve.add_point(p_from);
+ curve.set_point_out(0, Vector2(60, 0));
+ curve.add_point(p_to);
+ curve.set_point_in(1, Vector2(-60, 0));
+ return curve.tessellate();
+}
- Vector<Point2> points;
+void GraphEdit::_draw_connection_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_zoom) {
+ Vector<Vector2> points = get_connection_line(p_from / p_zoom, p_to / p_zoom);
+ Vector<Vector2> scaled_points;
Vector<Color> colors;
- points.push_back(p_from);
- colors.push_back(p_color);
- _bake_segment2d(points, colors, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 3, p_color, p_to_color, lines);
- points.push_back(p_to);
- colors.push_back(p_to_color);
+ float length = p_from.distance_to(p_to);
+ for (int i = 0; i < points.size(); i++) {
+ float d = p_from.distance_to(points[i]) / length;
+ colors.push_back(p_color.lerp(p_to_color, d));
+ scaled_points.push_back(points[i] * p_zoom);
+ }
#ifdef TOOLS_ENABLED
- p_where->draw_polyline_colors(points, colors, Math::floor(p_width * EDSCALE), lines_antialiased);
+ p_where->draw_polyline_colors(scaled_points, colors, Math::floor(p_width * EDSCALE), lines_antialiased);
#else
- p_where->draw_polyline_colors(points, colors, p_width, lines_antialiased);
+ p_where->draw_polyline_colors(scaled_points, colors, p_width, lines_antialiased);
#endif
}
@@ -913,7 +880,7 @@ void GraphEdit::_connections_layer_draw() {
color = color.lerp(activity_color, E->get().activity);
tocolor = tocolor.lerp(activity_color, E->get().activity);
}
- _draw_cos_line(connections_layer, frompos, topos, color, tocolor, lines_thickness);
+ _draw_connection_line(connections_layer, frompos, topos, color, tocolor, lines_thickness, zoom);
}
while (to_erase.size()) {
@@ -952,7 +919,7 @@ void GraphEdit::_top_layer_draw() {
if (!connecting_out) {
SWAP(pos, topos);
}
- _draw_cos_line(top_layer, pos, topos, col, col, lines_thickness);
+ _draw_connection_line(top_layer, pos, topos, col, col, lines_thickness, zoom);
}
if (box_selecting) {
@@ -1056,7 +1023,7 @@ void GraphEdit::_minimap_draw() {
from_color = from_color.lerp(activity_color, E.activity);
to_color = to_color.lerp(activity_color, E.activity);
}
- _draw_cos_line(minimap, from_position, to_position, from_color, to_color, 1.0, 0.5);
+ _draw_connection_line(minimap, from_position, to_position, from_color, to_color, 0.1, minimap->_convert_from_graph_position(Vector2(zoom, zoom)).length());
}
// Draw the "camera" viewport.
@@ -2048,7 +2015,6 @@ void GraphEdit::arrange_nodes() {
if (gn->is_selected()) {
selected_nodes.insert(gn->get_name());
- origin = origin < gn->get_position_offset() ? origin : gn->get_position_offset();
Set<StringName> s;
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
GraphNode *p_from = Object::cast_to<GraphNode>(node_names[E->get().from]);
@@ -2072,6 +2038,11 @@ void GraphEdit::arrange_nodes() {
}
}
+ if (!selected_nodes.size()) {
+ arranging_graph = false;
+ return;
+ }
+
HashMap<int, Vector<StringName>> layers = _layering(selected_nodes, upper_neighbours);
_crossing_minimisation(layers, upper_neighbours);
@@ -2098,16 +2069,16 @@ void GraphEdit::arrange_nodes() {
for (const Set<StringName>::Element *E = block_heads.front(); E; E = E->next()) {
_place_block(E->get(), gap_v, layers, root, align, node_names, inner_shift, sink, shift, new_positions);
}
+ origin.y = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().y - (new_positions[layers[0][0]].y + (float)inner_shift[layers[0][0]]);
+ origin.x = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().x;
for (const Set<StringName>::Element *E = block_heads.front(); E; E = E->next()) {
StringName u = E->get();
- StringName prev = u;
float start_from = origin.y + new_positions[E->get()].y;
do {
Vector2 cal_pos;
cal_pos.y = start_from + (real_t)inner_shift[u];
new_positions.set(u, cal_pos);
- prev = u;
u = align[u];
} while (u != E->get());
}
@@ -2130,10 +2101,11 @@ void GraphEdit::arrange_nodes() {
if (current_node_size == largest_node_size) {
cal_pos.x = start_from;
} else {
- float current_node_start_pos;
- if (current_node_size >= largest_node_size / 2) {
- current_node_start_pos = start_from;
- } else {
+ float current_node_start_pos = start_from;
+ if (current_node_size < largest_node_size / 2) {
+ if (!(i || j)) {
+ start_from -= (largest_node_size - current_node_size);
+ }
current_node_start_pos = start_from + largest_node_size - current_node_size;
}
cal_pos.x = current_node_start_pos;
@@ -2179,6 +2151,7 @@ void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_valid_connection_type", "from_type", "to_type"), &GraphEdit::add_valid_connection_type);
ClassDB::bind_method(D_METHOD("remove_valid_connection_type", "from_type", "to_type"), &GraphEdit::remove_valid_connection_type);
ClassDB::bind_method(D_METHOD("is_valid_connection_type", "from_type", "to_type"), &GraphEdit::is_valid_connection_type);
+ ClassDB::bind_method(D_METHOD("get_connection_line", "from", "to"), &GraphEdit::get_connection_line);
ClassDB::bind_method(D_METHOD("set_zoom", "zoom"), &GraphEdit::set_zoom);
ClassDB::bind_method(D_METHOD("get_zoom"), &GraphEdit::get_zoom);
@@ -2227,6 +2200,8 @@ void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_selected", "node"), &GraphEdit::set_selected);
+ BIND_VMETHOD(MethodInfo(Variant::PACKED_VECTOR2_ARRAY, "_get_connection_line", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to")));
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "right_disconnects"), "set_right_disconnects", "is_right_disconnects_enabled");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_offset"), "set_scroll_ofs", "get_scroll_ofs");
ADD_PROPERTY(PropertyInfo(Variant::INT, "snap_distance"), "set_snap", "get_snap");
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index 9fd7cbef22..7a9286be0f 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -169,9 +169,8 @@ private:
float lines_thickness = 2.0f;
bool lines_antialiased = true;
- void _bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const;
-
- void _draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_bezier_ratio = 1.0);
+ PackedVector2Array get_connection_line(const Vector2 &p_from, const Vector2 &p_to);
+ void _draw_connection_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_zoom);
void _graph_node_raised(Node *p_gn);
void _graph_node_moved(Node *p_gn);
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 4bd88fde5f..aff367e398 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -358,9 +358,10 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
int button_idx = b->get_button_index();
- if (b->is_pressed() || (!b->is_pressed() && during_grabbed_click)) {
- // Allow activating item by releasing the LMB or any that was down when the popup appeared.
- // However, if button was not held when opening menu, do not allow release to activate item.
+ if (!b->is_pressed()) {
+ // Activate the item on release of either the left mouse button or
+ // any mouse button held down when the popup was opened.
+ // This allows for opening the popup and triggering an action in a single mouse click.
if (button_idx == MOUSE_BUTTON_LEFT || (initial_button_mask & (1 << (button_idx - 1)))) {
bool was_during_grabbed_click = during_grabbed_click;
during_grabbed_click = false;
diff --git a/scene/gui/rich_text_effect.cpp b/scene/gui/rich_text_effect.cpp
index 39718a269a..236d106af8 100644
--- a/scene/gui/rich_text_effect.cpp
+++ b/scene/gui/rich_text_effect.cpp
@@ -32,8 +32,15 @@
#include "core/object/script_language.h"
-void RichTextEffect::_bind_methods() {
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_process_custom_fx", PropertyInfo(Variant::OBJECT, "char_fx", PROPERTY_HINT_RESOURCE_TYPE, "CharFXTransform")));
+CharFXTransform::CharFXTransform() {
+}
+
+CharFXTransform::~CharFXTransform() {
+ environment.clear();
+}
+
+void RichTextEffect::_bind_methods(){
+ GDVIRTUAL_BIND(_process_custom_fx, "char_fx")
}
Variant RichTextEffect::get_bbcode() const {
@@ -49,15 +56,10 @@ Variant RichTextEffect::get_bbcode() const {
bool RichTextEffect::_process_effect_impl(Ref<CharFXTransform> p_cfx) {
bool return_value = false;
- if (get_script_instance()) {
- Variant v = get_script_instance()->call("_process_custom_fx", p_cfx);
- if (v.get_type() != Variant::BOOL) {
- return_value = false;
- } else {
- return_value = (bool)v;
- }
+ if (GDVIRTUAL_CALL(_process_custom_fx, p_cfx, return_value)) {
+ return return_value;
}
- return return_value;
+ return false;
}
RichTextEffect::RichTextEffect() {
@@ -101,10 +103,3 @@ void CharFXTransform::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "glyph_index"), "set_glyph_index", "get_glyph_index");
ADD_PROPERTY(PropertyInfo(Variant::RID, "font"), "set_font", "get_font");
}
-
-CharFXTransform::CharFXTransform() {
-}
-
-CharFXTransform::~CharFXTransform() {
- environment.clear();
-}
diff --git a/scene/gui/rich_text_effect.h b/scene/gui/rich_text_effect.h
index 67323e7f93..e674b2f62f 100644
--- a/scene/gui/rich_text_effect.h
+++ b/scene/gui/rich_text_effect.h
@@ -32,20 +32,8 @@
#define RICH_TEXT_EFFECT_H
#include "core/io/resource.h"
-
-class RichTextEffect : public Resource {
- GDCLASS(RichTextEffect, Resource);
- OBJ_SAVE_TYPE(RichTextEffect);
-
-protected:
- static void _bind_methods();
-
-public:
- Variant get_bbcode() const;
- bool _process_effect_impl(Ref<class CharFXTransform> p_cfx);
-
- RichTextEffect();
-};
+#include "core/object/gdvirtual.gen.inc"
+#include "core/object/script_language.h"
class CharFXTransform : public RefCounted {
GDCLASS(CharFXTransform, RefCounted);
@@ -89,4 +77,20 @@ public:
void set_environment(Dictionary p_environment) { environment = p_environment; }
};
+class RichTextEffect : public Resource {
+ GDCLASS(RichTextEffect, Resource);
+ OBJ_SAVE_TYPE(RichTextEffect);
+
+protected:
+ static void _bind_methods();
+
+ GDVIRTUAL1RC(bool, _process_custom_fx, Ref<CharFXTransform>)
+
+public:
+ Variant get_bbcode() const;
+ bool _process_effect_impl(Ref<class CharFXTransform> p_cfx);
+
+ RichTextEffect();
+};
+
#endif // RICH_TEXT_EFFECT_H
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index cf2a1481a1..75c2da7ef9 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -1127,7 +1127,7 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
Point2 ofs = text_rect.get_position() + Vector2(0, main->lines[from_line].offset.y - vofs);
while (ofs.y < size.height && from_line < main->lines.size()) {
_find_click_in_line(p_frame, from_line, ofs, text_rect.size.x, p_click, r_click_frame, r_click_line, r_click_item, r_click_char);
- ofs.y += main->lines[from_line].text_buf->get_size().y;
+ ofs.y += main->lines[from_line].text_buf->get_size().y + get_theme_constant(SNAME("line_separation"));
if (((r_click_item != nullptr) && ((*r_click_item) != nullptr)) || ((r_click_frame != nullptr) && ((*r_click_frame) != nullptr))) {
if (r_outside != nullptr) {
*r_outside = false;
@@ -1435,7 +1435,7 @@ void RichTextLabel::_notification(int p_what) {
while (ofs.y < size.height && from_line < main->lines.size()) {
visible_paragraph_count++;
visible_line_count += _draw_line(main, from_line, ofs, text_rect.size.x, base_color, outline_size, outline_color, font_shadow_color, use_outline, shadow_ofs);
- ofs.y += main->lines[from_line].text_buf->get_size().y;
+ ofs.y += main->lines[from_line].text_buf->get_size().y + get_theme_constant(SNAME("line_separation"));
from_line++;
}
} break;
diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp
index c0aac6d91a..d0cb08724e 100644
--- a/scene/gui/shortcut.cpp
+++ b/scene/gui/shortcut.cpp
@@ -32,7 +32,7 @@
#include "core/os/keyboard.h"
void Shortcut::set_event(const Ref<InputEvent> &p_event) {
- ERR_FAIL_COND(Object::cast_to<InputEventShortcut>(*p_event));
+ ERR_FAIL_COND_MSG(Object::cast_to<InputEventShortcut>(*p_event), "Cannot set a shortcut event to an instance of InputEventShortcut.");
event = p_event;
emit_changed();
}
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 87f06445ac..a65abd5f49 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -2768,48 +2768,38 @@ Point2i TextEdit::get_next_visible_line_index_offset_from(int p_line_from, int p
// Overridable actions
void TextEdit::handle_unicode_input(const uint32_t p_unicode) {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_handle_unicode_input")) {
- si->call("_handle_unicode_input", p_unicode);
+ if (GDVIRTUAL_CALL(_handle_unicode_input, p_unicode)) {
return;
}
- _handle_unicode_input(p_unicode);
+ _handle_unicode_input_internal(p_unicode);
}
void TextEdit::backspace() {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_backspace")) {
- si->call("_backspace");
+ if (GDVIRTUAL_CALL(_backspace)) {
return;
}
- _backspace();
+ _backspace_internal();
}
void TextEdit::cut() {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_cut")) {
- si->call("_cut");
+ if (GDVIRTUAL_CALL(_cut)) {
return;
}
- _cut();
+ _cut_internal();
}
void TextEdit::copy() {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_copy")) {
- si->call("_copy");
+ if (GDVIRTUAL_CALL(_copy)) {
return;
}
- _copy();
+ _copy_internal();
}
void TextEdit::paste() {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_paste")) {
- si->call("_paste");
+ if (GDVIRTUAL_CALL(_paste)) {
return;
}
- _paste();
+ _paste_internal();
}
// Context menu.
@@ -4452,12 +4442,11 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("copy"), &TextEdit::copy);
ClassDB::bind_method(D_METHOD("paste"), &TextEdit::paste);
- BIND_VMETHOD(MethodInfo("_handle_unicode_input", PropertyInfo(Variant::INT, "unicode")))
- BIND_VMETHOD(MethodInfo("_backspace"));
-
- BIND_VMETHOD(MethodInfo("_cut"));
- BIND_VMETHOD(MethodInfo("_copy"));
- BIND_VMETHOD(MethodInfo("_paste"));
+ GDVIRTUAL_BIND(_handle_unicode_input, "unicode_char")
+ GDVIRTUAL_BIND(_backspace)
+ GDVIRTUAL_BIND(_cut)
+ GDVIRTUAL_BIND(_copy)
+ GDVIRTUAL_BIND(_paste)
// Context Menu
BIND_ENUM_CONSTANT(MENU_CUT);
@@ -4884,7 +4873,7 @@ void TextEdit::_set_symbol_lookup_word(const String &p_symbol) {
/* Text manipulation */
// Overridable actions
-void TextEdit::_handle_unicode_input(const uint32_t p_unicode) {
+void TextEdit::_handle_unicode_input_internal(const uint32_t p_unicode) {
if (!editable) {
return;
}
@@ -4915,7 +4904,7 @@ void TextEdit::_handle_unicode_input(const uint32_t p_unicode) {
}
}
-void TextEdit::_backspace() {
+void TextEdit::_backspace_internal() {
if (!editable) {
return;
}
@@ -4946,7 +4935,7 @@ void TextEdit::_backspace() {
set_caret_column(prev_column);
}
-void TextEdit::_cut() {
+void TextEdit::_cut_internal() {
if (!editable) {
return;
}
@@ -4976,7 +4965,7 @@ void TextEdit::_cut() {
cut_copy_line = clipboard;
}
-void TextEdit::_copy() {
+void TextEdit::_copy_internal() {
if (has_selection()) {
DisplayServer::get_singleton()->clipboard_set(get_selected_text());
cut_copy_line = "";
@@ -4991,7 +4980,7 @@ void TextEdit::_copy() {
}
}
-void TextEdit::_paste() {
+void TextEdit::_paste_internal() {
if (!editable) {
return;
}
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 69468978ab..7d00ce14af 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -562,12 +562,18 @@ protected:
/* Text manipulation */
// Overridable actions
- virtual void _handle_unicode_input(const uint32_t p_unicode);
- virtual void _backspace();
-
- virtual void _cut();
- virtual void _copy();
- virtual void _paste();
+ virtual void _handle_unicode_input_internal(const uint32_t p_unicode);
+ virtual void _backspace_internal();
+
+ virtual void _cut_internal();
+ virtual void _copy_internal();
+ virtual void _paste_internal();
+
+ GDVIRTUAL1(_handle_unicode_input, int)
+ GDVIRTUAL0(_backspace)
+ GDVIRTUAL0(_cut)
+ GDVIRTUAL0(_copy)
+ GDVIRTUAL0(_paste)
public:
/* General overrides. */
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index f2415eaf71..f329332725 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -151,9 +151,7 @@ void CanvasItem::_update_callback() {
current_item_drawn = this;
notification(NOTIFICATION_DRAW);
emit_signal(SceneStringNames::get_singleton()->draw);
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_draw);
- }
+ GDVIRTUAL_CALL(_draw);
current_item_drawn = nullptr;
drawing = false;
}
@@ -934,7 +932,7 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_clip_children", "enable"), &CanvasItem::set_clip_children);
ClassDB::bind_method(D_METHOD("is_clipping_children"), &CanvasItem::is_clipping_children);
- BIND_VMETHOD(MethodInfo("_draw"));
+ GDVIRTUAL_BIND(_draw);
ADD_GROUP("Visibility", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index dc7ad2bf5d..a591cab485 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -142,6 +142,7 @@ protected:
void _notification(int p_what);
static void _bind_methods();
+ GDVIRTUAL0(_draw)
public:
enum {
NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, //unique
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 155af30a6d..1d617d1ff7 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -54,16 +54,11 @@ int Node::orphan_node_count = 0;
void Node::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_PROCESS: {
- if (get_script_instance()) {
- Variant time = get_process_delta_time();
- get_script_instance()->call(SceneStringNames::get_singleton()->_process, time);
- }
+ GDVIRTUAL_CALL(_process, get_process_delta_time());
+
} break;
case NOTIFICATION_PHYSICS_PROCESS: {
- if (get_script_instance()) {
- Variant time = get_physics_process_delta_time();
- get_script_instance()->call(SceneStringNames::get_singleton()->_physics_process, time);
- }
+ GDVIRTUAL_CALL(_physics_process, get_process_delta_time());
} break;
case NOTIFICATION_ENTER_TREE: {
@@ -140,15 +135,14 @@ void Node::_notification(int p_notification) {
set_process_unhandled_key_input(true);
}
- if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_process)) {
+ if (GDVIRTUAL_IS_OVERRIDEN(_process)) {
set_process(true);
}
-
- if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_physics_process)) {
+ if (GDVIRTUAL_IS_OVERRIDEN(_physics_process)) {
set_physics_process(true);
}
- get_script_instance()->call(SceneStringNames::get_singleton()->_ready);
+ GDVIRTUAL_CALL(_ready);
}
if (data.filename.length()) {
ERR_FAIL_COND(!is_inside_tree());
@@ -221,9 +215,7 @@ void Node::_propagate_enter_tree() {
notification(NOTIFICATION_ENTER_TREE);
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_enter_tree);
- }
+ GDVIRTUAL_CALL(_enter_tree);
emit_signal(SceneStringNames::get_singleton()->tree_entered);
@@ -269,9 +261,8 @@ void Node::_propagate_exit_tree() {
data.blocked--;
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_exit_tree);
- }
+ GDVIRTUAL_CALL(_exit_tree);
+
emit_signal(SceneStringNames::get_singleton()->tree_exiting);
notification(NOTIFICATION_EXIT_TREE, true);
@@ -2737,11 +2728,13 @@ void Node::_bind_methods() {
ADD_GROUP("Editor Description", "editor_");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "set_editor_description", "get_editor_description");
- BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::FLOAT, "delta")));
- BIND_VMETHOD(MethodInfo("_physics_process", PropertyInfo(Variant::FLOAT, "delta")));
- BIND_VMETHOD(MethodInfo("_enter_tree"));
- BIND_VMETHOD(MethodInfo("_exit_tree"));
- BIND_VMETHOD(MethodInfo("_ready"));
+ GDVIRTUAL_BIND(_process, "delta");
+ GDVIRTUAL_BIND(_physics_process, "delta");
+ GDVIRTUAL_BIND(_enter_tree);
+ GDVIRTUAL_BIND(_exit_tree);
+ GDVIRTUAL_BIND(_ready);
+ GDVIRTUAL_BIND(_get_configuration_warnings);
+
BIND_VMETHOD(MethodInfo("_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo("_unhandled_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo("_unhandled_key_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEventKey")));
diff --git a/scene/main/node.h b/scene/main/node.h
index 9997f4e055..8aa56aa97f 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -202,12 +202,18 @@ protected:
static String _get_name_num_separator();
friend class SceneState;
- friend class MultiplayerAPI;
+ friend class MultiplayerReplicator;
void _add_child_nocheck(Node *p_child, const StringName &p_name);
void _set_owner_nocheck(Node *p_owner);
void _set_name_nocheck(const StringName &p_name);
+ GDVIRTUAL1(_process, double)
+ GDVIRTUAL1(_physics_process, double)
+ GDVIRTUAL0(_enter_tree)
+ GDVIRTUAL0(_exit_tree)
+ GDVIRTUAL0(_ready)
+ GDVIRTUAL0RC(Vector<String>, _get_configuration_warnings)
public:
enum {
// you can make your own, but don't use the same numbers as other notifications in other nodes
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 40ab439a51..6f8091c03f 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -812,7 +812,6 @@ void register_scene_types() {
GDREGISTER_CLASS(Font);
GDREGISTER_CLASS(Curve);
- GDREGISTER_CLASS(TextFile);
GDREGISTER_CLASS(TextLine);
GDREGISTER_CLASS(TextParagraph);
diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp
index 596fa70f15..0818e4fd99 100644
--- a/scene/resources/capsule_shape_2d.cpp
+++ b/scene/resources/capsule_shape_2d.cpp
@@ -59,7 +59,10 @@ void CapsuleShape2D::_update_shape() {
}
void CapsuleShape2D::set_radius(real_t p_radius) {
- radius = MIN(p_radius, height * 0.5);
+ radius = p_radius;
+ if (radius > height * 0.5) {
+ height = radius * 2.0;
+ }
_update_shape();
}
@@ -68,7 +71,10 @@ real_t CapsuleShape2D::get_radius() const {
}
void CapsuleShape2D::set_height(real_t p_height) {
- height = MAX(p_height, radius * 2);
+ height = p_height;
+ if (radius > height * 0.5) {
+ radius = height * 0.5;
+ }
_update_shape();
}
@@ -105,6 +111,8 @@ void CapsuleShape2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius"), "set_radius", "get_radius");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height"), "set_height", "get_height");
+ ADD_LINKED_PROPERTY("radius", "height");
+ ADD_LINKED_PROPERTY("height", "radius");
}
CapsuleShape2D::CapsuleShape2D() :
diff --git a/scene/resources/capsule_shape_3d.cpp b/scene/resources/capsule_shape_3d.cpp
index e267941d6a..afec7b1877 100644
--- a/scene/resources/capsule_shape_3d.cpp
+++ b/scene/resources/capsule_shape_3d.cpp
@@ -81,7 +81,7 @@ void CapsuleShape3D::_update_shape() {
void CapsuleShape3D::set_radius(float p_radius) {
radius = p_radius;
if (radius > height * 0.5) {
- radius = height * 0.5;
+ height = radius * 2.0;
}
_update_shape();
notify_change_to_owners();
@@ -94,7 +94,7 @@ float CapsuleShape3D::get_radius() const {
void CapsuleShape3D::set_height(float p_height) {
height = p_height;
if (radius > height * 0.5) {
- height = radius * 2;
+ radius = height * 0.5;
}
_update_shape();
notify_change_to_owners();
@@ -112,6 +112,8 @@ void CapsuleShape3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,4096,0.001"), "set_radius", "get_radius");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,4096,0.001"), "set_height", "get_height");
+ ADD_LINKED_PROPERTY("radius", "height");
+ ADD_LINKED_PROPERTY("height", "radius");
}
CapsuleShape3D::CapsuleShape3D() :
diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp
index 3b666640f8..a364a27e80 100644
--- a/scene/resources/curve.cpp
+++ b/scene/resources/curve.cpp
@@ -662,19 +662,27 @@ void Curve2D::_bake() const {
if (points.size() == 0) {
baked_point_cache.resize(0);
+ baked_dist_cache.resize(0);
return;
}
if (points.size() == 1) {
baked_point_cache.resize(1);
baked_point_cache.set(0, points[0].pos);
+
+ baked_dist_cache.resize(1);
+ baked_dist_cache.set(0, 0.0);
return;
}
Vector2 pos = points[0].pos;
+ float dist = 0.0;
+
List<Vector2> pointlist;
+ List<float> distlist;
pointlist.push_back(pos); //start always from origin
+ distlist.push_back(0.0);
for (int i = 0; i < points.size() - 1; i++) {
float step = 0.1; // at least 10 substeps ought to be enough?
@@ -712,7 +720,10 @@ void Curve2D::_bake() const {
pos = npp;
p = mid;
+ dist += d;
+
pointlist.push_back(pos);
+ distlist.push_back(dist);
} else {
p = np;
}
@@ -722,16 +733,20 @@ void Curve2D::_bake() const {
Vector2 lastpos = points[points.size() - 1].pos;
float rem = pos.distance_to(lastpos);
- baked_max_ofs = (pointlist.size() - 1) * bake_interval + rem;
+ dist += rem;
+ baked_max_ofs = dist;
pointlist.push_back(lastpos);
+ distlist.push_back(dist);
baked_point_cache.resize(pointlist.size());
+ baked_dist_cache.resize(distlist.size());
+
Vector2 *w = baked_point_cache.ptrw();
- int idx = 0;
+ float *wd = baked_dist_cache.ptrw();
- for (const Vector2 &E : pointlist) {
- w[idx] = E;
- idx++;
+ for (int i = 0; i < pointlist.size(); i++) {
+ w[i] = pointlist[i];
+ wd[i] = distlist[i];
}
}
@@ -766,19 +781,26 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const {
return r[bpc - 1];
}
- int idx = Math::floor((double)p_offset / (double)bake_interval);
- float frac = Math::fmod(p_offset, (float)bake_interval);
-
- if (idx >= bpc - 1) {
- return r[bpc - 1];
- } else if (idx == bpc - 2) {
- if (frac > 0) {
- frac /= Math::fmod(baked_max_ofs, bake_interval);
+ int start = 0, end = bpc, idx = (end + start) / 2;
+ // binary search to find baked points
+ while (start < idx) {
+ float offset = baked_dist_cache[idx];
+ if (p_offset <= offset) {
+ end = idx;
+ } else {
+ start = idx;
}
- } else {
- frac /= bake_interval;
+ idx = (end + start) / 2;
}
+ float offset_begin = baked_dist_cache[idx];
+ float offset_end = baked_dist_cache[idx + 1];
+
+ float idx_interval = offset_end - offset_begin;
+ ERR_FAIL_COND_V_MSG(p_offset < offset_begin || p_offset > offset_end, Vector2(), "failed to find baked segment");
+
+ float frac = (p_offset - offset_begin) / idx_interval;
+
if (p_cubic) {
Vector2 pre = idx > 0 ? r[idx - 1] : r[idx];
Vector2 post = (idx < (bpc - 2)) ? r[idx + 2] : r[idx + 1];
@@ -1145,6 +1167,7 @@ void Curve3D::_bake() const {
baked_point_cache.resize(0);
baked_tilt_cache.resize(0);
baked_up_vector_cache.resize(0);
+ baked_dist_cache.resize(0);
return;
}
@@ -1153,6 +1176,8 @@ void Curve3D::_bake() const {
baked_point_cache.set(0, points[0].pos);
baked_tilt_cache.resize(1);
baked_tilt_cache.set(0, points[0].tilt);
+ baked_dist_cache.resize(1);
+ baked_dist_cache.set(0, 0.0);
if (up_vector_enabled) {
baked_up_vector_cache.resize(1);
@@ -1165,8 +1190,12 @@ void Curve3D::_bake() const {
}
Vector3 pos = points[0].pos;
+ float dist = 0.0;
List<Plane> pointlist;
+ List<float> distlist;
+
pointlist.push_back(Plane(pos, points[0].tilt));
+ distlist.push_back(0.0);
for (int i = 0; i < points.size() - 1; i++) {
float step = 0.1; // at least 10 substeps ought to be enough?
@@ -1207,7 +1236,10 @@ void Curve3D::_bake() const {
Plane post;
post.normal = pos;
post.d = Math::lerp(points[i].tilt, points[i + 1].tilt, mid);
+ dist += d;
+
pointlist.push_back(post);
+ distlist.push_back(dist);
} else {
p = np;
}
@@ -1218,8 +1250,10 @@ void Curve3D::_bake() const {
float lastilt = points[points.size() - 1].tilt;
float rem = pos.distance_to(lastpos);
- baked_max_ofs = (pointlist.size() - 1) * bake_interval + rem;
+ dist += rem;
+ baked_max_ofs = dist;
pointlist.push_back(Plane(lastpos, lastilt));
+ distlist.push_back(dist);
baked_point_cache.resize(pointlist.size());
Vector3 *w = baked_point_cache.ptrw();
@@ -1231,6 +1265,9 @@ void Curve3D::_bake() const {
baked_up_vector_cache.resize(up_vector_enabled ? pointlist.size() : 0);
Vector3 *up_write = baked_up_vector_cache.ptrw();
+ baked_dist_cache.resize(pointlist.size());
+ float *wd = baked_dist_cache.ptrw();
+
Vector3 sideways;
Vector3 up;
Vector3 forward;
@@ -1242,6 +1279,7 @@ void Curve3D::_bake() const {
for (const Plane &E : pointlist) {
w[idx] = E.normal;
wt[idx] = E.d;
+ wd[idx] = distlist[idx];
if (!up_vector_enabled) {
idx++;
@@ -1308,19 +1346,26 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const {
return r[bpc - 1];
}
- int idx = Math::floor((double)p_offset / (double)bake_interval);
- float frac = Math::fmod(p_offset, bake_interval);
-
- if (idx >= bpc - 1) {
- return r[bpc - 1];
- } else if (idx == bpc - 2) {
- if (frac > 0) {
- frac /= Math::fmod(baked_max_ofs, bake_interval);
+ int start = 0, end = bpc, idx = (end + start) / 2;
+ // binary search to find baked points
+ while (start < idx) {
+ float offset = baked_dist_cache[idx];
+ if (p_offset <= offset) {
+ end = idx;
+ } else {
+ start = idx;
}
- } else {
- frac /= bake_interval;
+ idx = (end + start) / 2;
}
+ float offset_begin = baked_dist_cache[idx];
+ float offset_end = baked_dist_cache[idx + 1];
+
+ float idx_interval = offset_end - offset_begin;
+ ERR_FAIL_COND_V_MSG(p_offset < offset_begin || p_offset > offset_end, Vector3(), "failed to find baked segment");
+
+ float frac = (p_offset - offset_begin) / idx_interval;
+
if (p_cubic) {
Vector3 pre = idx > 0 ? r[idx - 1] : r[idx];
Vector3 post = (idx < (bpc - 2)) ? r[idx + 2] : r[idx + 1];
diff --git a/scene/resources/curve.h b/scene/resources/curve.h
index c25d307608..5808fd6508 100644
--- a/scene/resources/curve.h
+++ b/scene/resources/curve.h
@@ -161,6 +161,7 @@ class Curve2D : public Resource {
mutable bool baked_cache_dirty = false;
mutable PackedVector2Array baked_point_cache;
+ mutable PackedFloat32Array baked_dist_cache;
mutable float baked_max_ofs = 0.0;
void _bake() const;
@@ -224,6 +225,7 @@ class Curve3D : public Resource {
mutable PackedVector3Array baked_point_cache;
mutable Vector<real_t> baked_tilt_cache;
mutable PackedVector3Array baked_up_vector_cache;
+ mutable PackedFloat32Array baked_dist_cache;
mutable float baked_max_ofs = 0.0;
void _bake() const;
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 5f70a31844..dd7b348498 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -212,26 +212,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_constant("outline_size", "LinkButton", 0);
theme->set_constant("underline_spacing", "LinkButton", 2 * scale);
- // ColorPickerButton
-
- theme->set_stylebox("normal", "ColorPickerButton", sb_button_normal);
- theme->set_stylebox("pressed", "ColorPickerButton", sb_button_pressed);
- theme->set_stylebox("hover", "ColorPickerButton", sb_button_hover);
- theme->set_stylebox("disabled", "ColorPickerButton", sb_button_disabled);
- theme->set_stylebox("focus", "ColorPickerButton", sb_button_focus);
-
- theme->set_font("font", "ColorPickerButton", Ref<Font>());
- theme->set_font_size("font_size", "ColorPickerButton", -1);
-
- theme->set_color("font_color", "ColorPickerButton", Color(1, 1, 1, 1));
- theme->set_color("font_pressed_color", "ColorPickerButton", Color(0.8, 0.8, 0.8, 1));
- theme->set_color("font_hover_color", "ColorPickerButton", Color(1, 1, 1, 1));
- theme->set_color("font_disabled_color", "ColorPickerButton", Color(0.9, 0.9, 0.9, 0.3));
- theme->set_color("font_outline_color", "ColorPickerButton", Color(1, 1, 1));
-
- theme->set_constant("hseparation", "ColorPickerButton", 2 * scale);
- theme->set_constant("outline_size", "ColorPickerButton", 0);
-
// OptionButton
Ref<StyleBox> sb_optbutton_focus = sb_expand(make_stylebox(button_focus_png, 4, 4, 4, 4, 6, 2, 6, 2), 2, 2, 2, 2);
@@ -859,7 +839,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_icon("add_preset", "ColorPicker", make_icon(icon_add_png));
theme->set_icon("color_hue", "ColorPicker", make_icon(color_picker_hue_png));
theme->set_icon("color_sample", "ColorPicker", make_icon(color_picker_sample_png));
- theme->set_icon("preset_bg", "ColorPicker", make_icon(mini_checkerboard_png));
+ theme->set_icon("sample_bg", "ColorPicker", make_icon(mini_checkerboard_png));
theme->set_icon("overbright_indicator", "ColorPicker", make_icon(overbright_indicator_png));
theme->set_icon("bar_arrow", "ColorPicker", make_icon(bar_arrow_png));
theme->set_icon("picker_cursor", "ColorPicker", make_icon(picker_cursor_png));
@@ -867,6 +847,34 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
// ColorPickerButton
theme->set_icon("bg", "ColorPickerButton", make_icon(mini_checkerboard_png));
+ theme->set_stylebox("normal", "ColorPickerButton", sb_button_normal);
+ theme->set_stylebox("pressed", "ColorPickerButton", sb_button_pressed);
+ theme->set_stylebox("hover", "ColorPickerButton", sb_button_hover);
+ theme->set_stylebox("disabled", "ColorPickerButton", sb_button_disabled);
+ theme->set_stylebox("focus", "ColorPickerButton", sb_button_focus);
+
+ theme->set_font("font", "ColorPickerButton", Ref<Font>());
+ theme->set_font_size("font_size", "ColorPickerButton", -1);
+
+ theme->set_color("font_color", "ColorPickerButton", Color(1, 1, 1, 1));
+ theme->set_color("font_pressed_color", "ColorPickerButton", Color(0.8, 0.8, 0.8, 1));
+ theme->set_color("font_hover_color", "ColorPickerButton", Color(1, 1, 1, 1));
+ theme->set_color("font_disabled_color", "ColorPickerButton", Color(0.9, 0.9, 0.9, 0.3));
+ theme->set_color("font_outline_color", "ColorPickerButton", Color(1, 1, 1));
+
+ theme->set_constant("hseparation", "ColorPickerButton", 2 * scale);
+ theme->set_constant("outline_size", "ColorPickerButton", 0);
+
+ // ColorPresetButton
+
+ Ref<StyleBoxFlat> preset_sb = make_flat_stylebox(Color(1, 1, 1), 2, 2, 2, 2);
+ preset_sb->set_corner_radius_all(2);
+ preset_sb->set_corner_detail(2);
+ preset_sb->set_anti_aliased(false);
+
+ theme->set_stylebox("preset_fg", "ColorPresetButton", preset_sb);
+ theme->set_icon("preset_bg", "ColorPresetButton", make_icon(mini_checkerboard_png));
+ theme->set_icon("overbright_indicator", "ColorPresetButton", make_icon(overbright_indicator_png));
// TooltipPanel
@@ -917,7 +925,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_constant("shadow_offset_y", "RichTextLabel", 1 * scale);
theme->set_constant("shadow_as_outline", "RichTextLabel", 0 * scale);
- theme->set_constant("line_separation", "RichTextLabel", 1 * scale);
+ theme->set_constant("line_separation", "RichTextLabel", 0 * scale);
theme->set_constant("table_hseparation", "RichTextLabel", 3 * scale);
theme->set_constant("table_vseparation", "RichTextLabel", 3 * scale);
diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h
index ac7a500f73..1e1821024e 100644
--- a/scene/resources/particles_material.h
+++ b/scene/resources/particles_material.h
@@ -61,6 +61,7 @@ public:
PARAM_MAX
};
+ // When extending, make sure not to overflow the size of the MaterialKey below.
enum ParticleFlags {
PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY,
PARTICLE_FLAG_ROTATE_Y,
@@ -68,6 +69,7 @@ public:
PARTICLE_FLAG_MAX
};
+ // When extending, make sure not to overflow the size of the MaterialKey below.
enum EmissionShape {
EMISSION_SHAPE_POINT,
EMISSION_SHAPE_SPHERE,
@@ -78,6 +80,7 @@ public:
EMISSION_SHAPE_MAX
};
+ // When extending, make sure not to overflow the size of the MaterialKey below.
enum SubEmitterMode {
SUB_EMITTER_DISABLED,
SUB_EMITTER_CONSTANT,
@@ -88,11 +91,13 @@ public:
private:
union MaterialKey {
+ // The bit size of the struct must be kept below or equal to 32 bits.
+ // Consider this when extending ParticleFlags, EmissionShape, or SubEmitterMode.
struct {
uint32_t texture_mask : 16;
uint32_t texture_color : 1;
uint32_t particle_flags : 4;
- uint32_t emission_shape : 2;
+ uint32_t emission_shape : 3;
uint32_t invalid_key : 1;
uint32_t has_emission_color : 1;
uint32_t sub_emitter : 2;
diff --git a/scene/resources/skeleton_modification_2d.cpp b/scene/resources/skeleton_modification_2d.cpp
index 2d5b42ddf4..e533fb054a 100644
--- a/scene/resources/skeleton_modification_2d.cpp
+++ b/scene/resources/skeleton_modification_2d.cpp
@@ -44,7 +44,7 @@
///////////////////////////////////////
void SkeletonModification2D::_execute(float p_delta) {
- call("_execute", p_delta);
+ GDVIRTUAL_CALL(_execute, p_delta);
if (!enabled) {
return;
@@ -59,11 +59,11 @@ void SkeletonModification2D::_setup_modification(SkeletonModificationStack2D *p_
WARN_PRINT("Could not setup modification with name " + get_name());
}
- call("_setup_modification", p_stack);
+ GDVIRTUAL_CALL(_setup_modification, Ref<SkeletonModificationStack2D>(p_stack));
}
void SkeletonModification2D::_draw_editor_gizmo() {
- call("_draw_editor_gizmo");
+ GDVIRTUAL_CALL(_draw_editor_gizmo);
}
void SkeletonModification2D::set_enabled(bool p_enabled) {
@@ -228,9 +228,9 @@ bool SkeletonModification2D::get_editor_draw_gizmo() const {
}
void SkeletonModification2D::_bind_methods() {
- BIND_VMETHOD(MethodInfo("_execute", PropertyInfo(Variant::FLOAT, "delta")));
- BIND_VMETHOD(MethodInfo("_setup_modification", PropertyInfo(Variant::OBJECT, "modification_stack", PROPERTY_HINT_RESOURCE_TYPE, "SkeletonModificationStack2D")));
- BIND_VMETHOD(MethodInfo("_draw_editor_gizmo"));
+ GDVIRTUAL_BIND(_execute, "delta");
+ GDVIRTUAL_BIND(_setup_modification, "modification_stack")
+ GDVIRTUAL_BIND(_draw_editor_gizmo)
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &SkeletonModification2D::set_enabled);
ClassDB::bind_method(D_METHOD("get_enabled"), &SkeletonModification2D::get_enabled);
diff --git a/scene/resources/skeleton_modification_2d.h b/scene/resources/skeleton_modification_2d.h
index 18633e55cb..aaddb9136e 100644
--- a/scene/resources/skeleton_modification_2d.h
+++ b/scene/resources/skeleton_modification_2d.h
@@ -57,6 +57,10 @@ protected:
bool _print_execution_error(bool p_condition, String p_message);
+ GDVIRTUAL1(_execute, double)
+ GDVIRTUAL1(_setup_modification, Ref<SkeletonModificationStack2D>)
+ GDVIRTUAL0(_draw_editor_gizmo)
+
public:
virtual void _execute(float _delta);
virtual void _setup_modification(SkeletonModificationStack2D *p_stack);
diff --git a/scene/resources/skeleton_modification_3d.cpp b/scene/resources/skeleton_modification_3d.cpp
index 9306ee14cd..ee02ede2d5 100644
--- a/scene/resources/skeleton_modification_3d.cpp
+++ b/scene/resources/skeleton_modification_3d.cpp
@@ -32,11 +32,7 @@
#include "scene/3d/skeleton_3d.h"
void SkeletonModification3D::_execute(real_t p_delta) {
- if (get_script_instance()) {
- if (get_script_instance()->has_method("execute")) {
- get_script_instance()->call("execute", p_delta);
- }
- }
+ GDVIRTUAL_CALL(_execute, p_delta);
if (!enabled)
return;
@@ -50,11 +46,7 @@ void SkeletonModification3D::_setup_modification(SkeletonModificationStack3D *p_
WARN_PRINT("Could not setup modification with name " + this->get_name());
}
- if (get_script_instance()) {
- if (get_script_instance()->has_method("setup_modification")) {
- get_script_instance()->call("setup_modification", p_stack);
- }
- }
+ GDVIRTUAL_CALL(_setup_modification, Ref<SkeletonModificationStack3D>(p_stack));
}
void SkeletonModification3D::set_enabled(bool p_enabled) {
@@ -148,8 +140,8 @@ int SkeletonModification3D::get_execution_mode() const {
}
void SkeletonModification3D::_bind_methods() {
- BIND_VMETHOD(MethodInfo("_execute", PropertyInfo(Variant::FLOAT, "delta")));
- BIND_VMETHOD(MethodInfo("_setup_modification", PropertyInfo(Variant::OBJECT, "modification_stack", PROPERTY_HINT_RESOURCE_TYPE, "SkeletonModificationStack3D")));
+ GDVIRTUAL_BIND(_execute, "delta");
+ GDVIRTUAL_BIND(_setup_modification, "modification_stack")
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &SkeletonModification3D::set_enabled);
ClassDB::bind_method(D_METHOD("get_enabled"), &SkeletonModification3D::get_enabled);
diff --git a/scene/resources/skeleton_modification_3d.h b/scene/resources/skeleton_modification_3d.h
index 94ab0bf32c..fb1f3d33d1 100644
--- a/scene/resources/skeleton_modification_3d.h
+++ b/scene/resources/skeleton_modification_3d.h
@@ -53,6 +53,9 @@ protected:
bool _print_execution_error(bool p_condition, String p_message);
+ GDVIRTUAL1(_execute, double)
+ GDVIRTUAL1(_setup_modification, Ref<SkeletonModificationStack3D>)
+
public:
virtual void _execute(real_t p_delta);
virtual void _setup_modification(SkeletonModificationStack3D *p_stack);
diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp
index 173ce2adce..e1c5ebb005 100644
--- a/scene/resources/syntax_highlighter.cpp
+++ b/scene/resources/syntax_highlighter.cpp
@@ -43,12 +43,8 @@ Dictionary SyntaxHighlighter::get_line_syntax_highlighting(int p_line) {
return color_map;
}
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_get_line_syntax_highlighting")) {
- color_map = si->call("_get_line_syntax_highlighting", p_line);
- } else {
- color_map = _get_line_syntax_highlighting(p_line);
- }
+ GDVIRTUAL_CALL(_get_line_syntax_highlighting, p_line, color_map);
+
highlighting_cache[p_line] = color_map;
return color_map;
}
@@ -69,9 +65,7 @@ void SyntaxHighlighter::_lines_edited_from(int p_from_line, int p_to_line) {
void SyntaxHighlighter::clear_highlighting_cache() {
highlighting_cache.clear();
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_clear_highlighting_cache")) {
- si->call("_clear_highlighting_cache");
+ if (GDVIRTUAL_CALL(_clear_highlighting_cache)) {
return;
}
_clear_highlighting_cache();
@@ -83,9 +77,7 @@ void SyntaxHighlighter::update_cache() {
if (text_edit == nullptr) {
return;
}
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_update_cache")) {
- si->call("_update_cache");
+ if (GDVIRTUAL_CALL(_update_cache)) {
return;
}
_update_cache();
@@ -115,9 +107,9 @@ void SyntaxHighlighter::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_highlighting_cache"), &SyntaxHighlighter::clear_highlighting_cache);
ClassDB::bind_method(D_METHOD("get_text_edit"), &SyntaxHighlighter::get_text_edit);
- BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_line_syntax_highlighting", PropertyInfo(Variant::INT, "line")));
- BIND_VMETHOD(MethodInfo("_clear_highlighting_cache"));
- BIND_VMETHOD(MethodInfo("_update_cache"));
+ GDVIRTUAL_BIND(_get_line_syntax_highlighting, "line")
+ GDVIRTUAL_BIND(_clear_highlighting_cache)
+ GDVIRTUAL_BIND(_update_cache)
}
////////////////////////////////////////////////////////////////////////////////
@@ -130,7 +122,7 @@ static bool _is_hex_symbol(char32_t c) {
return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
}
-Dictionary CodeHighlighter::_get_line_syntax_highlighting(int p_line) {
+Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
Dictionary color_map;
bool prev_is_char = false;
diff --git a/scene/resources/syntax_highlighter.h b/scene/resources/syntax_highlighter.h
index f3964b0c8f..0fe39ccff6 100644
--- a/scene/resources/syntax_highlighter.h
+++ b/scene/resources/syntax_highlighter.h
@@ -32,6 +32,8 @@
#define SYNTAX_HIGHLIGHTER_H
#include "core/io/resource.h"
+#include "core/object/gdvirtual.gen.inc"
+#include "core/object/script_language.h"
class TextEdit;
@@ -48,9 +50,12 @@ protected:
static void _bind_methods();
+ GDVIRTUAL1RC(Dictionary, _get_line_syntax_highlighting, int)
+ GDVIRTUAL0(_clear_highlighting_cache)
+ GDVIRTUAL0(_update_cache)
public:
Dictionary get_line_syntax_highlighting(int p_line);
- virtual Dictionary _get_line_syntax_highlighting(int p_line) { return Dictionary(); }
+ virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) { return Dictionary(); }
void clear_highlighting_cache();
virtual void _clear_highlighting_cache() {}
@@ -93,7 +98,7 @@ protected:
static void _bind_methods();
public:
- virtual Dictionary _get_line_syntax_highlighting(int p_line) override;
+ virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override;
virtual void _clear_highlighting_cache() override;
virtual void _update_cache() override;
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index b00dcca004..a7f99a2113 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -261,54 +261,47 @@ VisualShaderNode::VisualShaderNode() {
/////////////////////////////////////////////////////////
void VisualShaderNodeCustom::update_ports() {
- ERR_FAIL_COND(!get_script_instance());
+ {
+ input_ports.clear();
+ int input_port_count;
+ if (GDVIRTUAL_CALL(_get_input_port_count, input_port_count)) {
+ for (int i = 0; i < input_port_count; i++) {
+ Port port;
+ if (!GDVIRTUAL_CALL(_get_input_port_name, i, port.name)) {
+ port.name = "in" + itos(i);
+ }
+ if (!GDVIRTUAL_CALL(_get_input_port_type, i, port.type)) {
+ port.type = (int)PortType::PORT_TYPE_SCALAR;
+ }
- input_ports.clear();
- if (get_script_instance()->has_method("_get_input_port_count")) {
- int input_port_count = (int)get_script_instance()->call("_get_input_port_count");
- bool has_name = get_script_instance()->has_method("_get_input_port_name");
- bool has_type = get_script_instance()->has_method("_get_input_port_type");
- for (int i = 0; i < input_port_count; i++) {
- Port port;
- if (has_name) {
- port.name = (String)get_script_instance()->call("_get_input_port_name", i);
- } else {
- port.name = "in" + itos(i);
+ input_ports.push_back(port);
}
- if (has_type) {
- port.type = (int)get_script_instance()->call("_get_input_port_type", i);
- } else {
- port.type = (int)PortType::PORT_TYPE_SCALAR;
- }
- input_ports.push_back(port);
}
}
- output_ports.clear();
- if (get_script_instance()->has_method("_get_output_port_count")) {
- int output_port_count = (int)get_script_instance()->call("_get_output_port_count");
- bool has_name = get_script_instance()->has_method("_get_output_port_name");
- bool has_type = get_script_instance()->has_method("_get_output_port_type");
- for (int i = 0; i < output_port_count; i++) {
- Port port;
- if (has_name) {
- port.name = (String)get_script_instance()->call("_get_output_port_name", i);
- } else {
- port.name = "out" + itos(i);
- }
- if (has_type) {
- port.type = (int)get_script_instance()->call("_get_output_port_type", i);
- } else {
- port.type = (int)PortType::PORT_TYPE_SCALAR;
+
+ {
+ output_ports.clear();
+ int output_port_count;
+ if (GDVIRTUAL_CALL(_get_output_port_count, output_port_count)) {
+ for (int i = 0; i < output_port_count; i++) {
+ Port port;
+ if (!GDVIRTUAL_CALL(_get_output_port_name, i, port.name)) {
+ port.name = "out" + itos(i);
+ }
+ if (!GDVIRTUAL_CALL(_get_output_port_type, i, port.type)) {
+ port.type = (int)PortType::PORT_TYPE_SCALAR;
+ }
+
+ output_ports.push_back(port);
}
- output_ports.push_back(port);
}
}
}
String VisualShaderNodeCustom::get_caption() const {
- ERR_FAIL_COND_V(!get_script_instance(), "");
- if (get_script_instance()->has_method("_get_name")) {
- return (String)get_script_instance()->call("_get_name");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_name, ret)) {
+ return ret;
}
return "Unnamed";
}
@@ -342,9 +335,8 @@ String VisualShaderNodeCustom::get_output_port_name(int p_port) const {
}
String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- ERR_FAIL_COND_V(!get_script_instance(), "");
- ERR_FAIL_COND_V(!get_script_instance()->has_method("_get_code"), "");
- Array input_vars;
+ ERR_FAIL_COND_V(!GDVIRTUAL_IS_OVERRIDEN(_get_code), "");
+ Vector<String> input_vars;
for (int i = 0; i < get_input_port_count(); i++) {
input_vars.push_back(p_input_vars[i]);
}
@@ -353,7 +345,8 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::
output_vars.push_back(p_output_vars[i]);
}
String code = " {\n";
- String _code = (String)get_script_instance()->call("_get_code", input_vars, output_vars, (int)p_mode, (int)p_type);
+ String _code;
+ GDVIRTUAL_CALL(_get_code, input_vars, output_vars, (int)p_mode, (int)p_type, _code);
bool nend = _code.ends_with("\n");
_code = _code.insert(0, " ");
_code = _code.replace("\n", "\n ");
@@ -369,10 +362,10 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::
}
String VisualShaderNodeCustom::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- ERR_FAIL_COND_V(!get_script_instance(), "");
- if (get_script_instance()->has_method("_get_global_code")) {
+ String ret;
+ if (GDVIRTUAL_CALL(_get_global_code, (int)p_mode, ret)) {
String code = "// " + get_caption() + "\n";
- code += (String)get_script_instance()->call("_get_global_code", (int)p_mode);
+ code += ret;
code += "\n";
return code;
}
@@ -416,19 +409,19 @@ void VisualShaderNodeCustom::_set_initialized(bool p_enabled) {
}
void VisualShaderNodeCustom::_bind_methods() {
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_description"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category"));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_return_icon_type"));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_port_count"));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_port_type", PropertyInfo(Variant::INT, "port")));
- BIND_VMETHOD(MethodInfo(Variant::STRING_NAME, "_get_input_port_name", PropertyInfo(Variant::INT, "port")));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_port_count"));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_port_type", PropertyInfo(Variant::INT, "port")));
- BIND_VMETHOD(MethodInfo(Variant::STRING_NAME, "_get_output_port_name", PropertyInfo(Variant::INT, "port")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_code", PropertyInfo(Variant::ARRAY, "input_vars"), PropertyInfo(Variant::ARRAY, "output_vars"), PropertyInfo(Variant::INT, "mode"), PropertyInfo(Variant::INT, "type")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_global_code", PropertyInfo(Variant::INT, "mode")));
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_highend"));
+ GDVIRTUAL_BIND(_get_name);
+ GDVIRTUAL_BIND(_get_description);
+ GDVIRTUAL_BIND(_get_category);
+ GDVIRTUAL_BIND(_get_return_icon_type);
+ GDVIRTUAL_BIND(_get_input_port_count);
+ GDVIRTUAL_BIND(_get_input_port_type, "port");
+ GDVIRTUAL_BIND(_get_input_port_name, "port");
+ GDVIRTUAL_BIND(_get_output_port_count);
+ GDVIRTUAL_BIND(_get_output_port_type, "port");
+ GDVIRTUAL_BIND(_get_output_port_name, "port");
+ GDVIRTUAL_BIND(_get_code, "input_vars", "output_vars", "mode", "type");
+ GDVIRTUAL_BIND(_get_global_code, "mode");
+ GDVIRTUAL_BIND(_is_highend);
ClassDB::bind_method(D_METHOD("_set_initialized", "enabled"), &VisualShaderNodeCustom::_set_initialized);
ClassDB::bind_method(D_METHOD("_is_initialized"), &VisualShaderNodeCustom::_is_initialized);
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index 31651318ae..b3efac02aa 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -314,6 +314,20 @@ protected:
virtual void remove_input_port_default_value(int p_port) override;
virtual void clear_default_input_values() override;
+ GDVIRTUAL0RC(String, _get_name)
+ GDVIRTUAL0RC(String, _get_description)
+ GDVIRTUAL0RC(String, _get_category)
+ GDVIRTUAL0RC(int, _get_return_icon_type)
+ GDVIRTUAL0RC(int, _get_input_port_count)
+ GDVIRTUAL1RC(int, _get_input_port_type, int)
+ GDVIRTUAL1RC(String, _get_input_port_name, int)
+ GDVIRTUAL0RC(int, _get_output_port_count)
+ GDVIRTUAL1RC(int, _get_output_port_type, int)
+ GDVIRTUAL1RC(String, _get_output_port_name, int)
+ GDVIRTUAL4RC(String, _get_code, Vector<String>, TypedArray<String>, int, int)
+ GDVIRTUAL1RC(String, _get_global_code, int)
+ GDVIRTUAL0RC(bool, _is_highend)
+
protected:
void _set_input_port_default_value(int p_port, const Variant &p_value);