summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/animated_sprite_2d.cpp2
-rw-r--r--scene/2d/audio_stream_player_2d.cpp2
-rw-r--r--scene/2d/camera_2d.cpp42
-rw-r--r--scene/2d/camera_2d.h2
-rw-r--r--scene/2d/collision_object_2d.cpp16
-rw-r--r--scene/2d/collision_object_2d.h5
-rw-r--r--scene/2d/cpu_particles_2d.cpp4
-rw-r--r--scene/2d/navigation_agent_2d.cpp8
-rw-r--r--scene/2d/physics_body_2d.cpp300
-rw-r--r--scene/2d/physics_body_2d.h22
-rw-r--r--scene/2d/skeleton_2d.cpp6
-rw-r--r--scene/2d/tile_map.cpp122
-rw-r--r--scene/2d/tile_map.h8
-rw-r--r--scene/2d/touch_screen_button.cpp4
-rw-r--r--scene/3d/audio_stream_player_3d.cpp6
-rw-r--r--scene/3d/camera_3d.cpp28
-rw-r--r--scene/3d/collision_object_3d.cpp12
-rw-r--r--scene/3d/collision_object_3d.h5
-rw-r--r--scene/3d/collision_polygon_3d.cpp6
-rw-r--r--scene/3d/collision_shape_3d.cpp6
-rw-r--r--scene/3d/cpu_particles_3d.cpp82
-rw-r--r--scene/3d/cpu_particles_3d.h13
-rw-r--r--scene/3d/decal.cpp29
-rw-r--r--scene/3d/decal.h2
-rw-r--r--scene/3d/gpu_particles_3d.cpp2
-rw-r--r--scene/3d/gpu_particles_collision_3d.cpp26
-rw-r--r--scene/3d/light_3d.cpp4
-rw-r--r--scene/3d/lightmap_gi.cpp4
-rw-r--r--scene/3d/mesh_instance_3d.cpp18
-rw-r--r--scene/3d/mesh_instance_3d.h4
-rw-r--r--scene/3d/navigation_agent_3d.cpp8
-rw-r--r--scene/3d/navigation_region_3d.cpp14
-rw-r--r--scene/3d/node_3d.cpp153
-rw-r--r--scene/3d/node_3d.h20
-rw-r--r--scene/3d/occluder_instance_3d.cpp4
-rw-r--r--scene/3d/path_3d.cpp4
-rw-r--r--scene/3d/physics_body_3d.cpp203
-rw-r--r--scene/3d/physics_body_3d.h14
-rw-r--r--scene/3d/physics_joint_3d.cpp20
-rw-r--r--scene/3d/proximity_group_3d.cpp3
-rw-r--r--scene/3d/ray_cast_3d.cpp6
-rw-r--r--scene/3d/reflection_probe.cpp4
-rw-r--r--scene/3d/skeleton_3d.cpp14
-rw-r--r--scene/3d/soft_body_3d.cpp7
-rw-r--r--scene/3d/spring_arm_3d.cpp2
-rw-r--r--scene/3d/sprite_3d.cpp16
-rw-r--r--scene/3d/vehicle_body_3d.cpp4
-rw-r--r--scene/3d/visible_on_screen_notifier_3d.cpp2
-rw-r--r--scene/3d/visual_instance_3d.cpp3
-rw-r--r--scene/3d/voxel_gi.cpp8
-rw-r--r--scene/3d/voxelizer.cpp6
-rw-r--r--scene/3d/xr_nodes.cpp8
-rw-r--r--scene/animation/animation_blend_space_1d.cpp8
-rw-r--r--scene/animation/animation_blend_space_2d.cpp24
-rw-r--r--scene/animation/animation_blend_tree.cpp22
-rw-r--r--scene/animation/animation_cache.cpp10
-rw-r--r--scene/animation/animation_node_state_machine.cpp25
-rw-r--r--scene/animation/animation_player.cpp39
-rw-r--r--scene/animation/animation_tree.cpp56
-rw-r--r--scene/animation/tween.cpp22
-rw-r--r--scene/audio/audio_stream_player.cpp2
-rw-r--r--scene/debugger/scene_debugger.cpp17
-rw-r--r--scene/gui/base_button.cpp25
-rw-r--r--scene/gui/base_button.h3
-rw-r--r--scene/gui/box_container.cpp5
-rw-r--r--scene/gui/button.cpp114
-rw-r--r--scene/gui/check_box.cpp20
-rw-r--r--scene/gui/check_button.cpp8
-rw-r--r--scene/gui/code_edit.cpp85
-rw-r--r--scene/gui/color_picker.cpp160
-rw-r--r--scene/gui/container.cpp6
-rw-r--r--scene/gui/control.cpp220
-rw-r--r--scene/gui/control.h12
-rw-r--r--scene/gui/dialogs.cpp22
-rw-r--r--scene/gui/file_dialog.cpp50
-rw-r--r--scene/gui/gradient_edit.cpp14
-rw-r--r--scene/gui/graph_edit.cpp180
-rw-r--r--scene/gui/graph_node.cpp76
-rw-r--r--scene/gui/grid_container.cpp8
-rw-r--r--scene/gui/item_list.cpp80
-rw-r--r--scene/gui/label.cpp171
-rw-r--r--scene/gui/label.h27
-rw-r--r--scene/gui/line_edit.cpp240
-rw-r--r--scene/gui/line_edit.h4
-rw-r--r--scene/gui/link_button.cpp24
-rw-r--r--scene/gui/margin_container.cpp16
-rw-r--r--scene/gui/menu_button.cpp54
-rw-r--r--scene/gui/menu_button.h4
-rw-r--r--scene/gui/option_button.cpp44
-rw-r--r--scene/gui/panel.cpp2
-rw-r--r--scene/gui/panel_container.cpp18
-rw-r--r--scene/gui/popup.cpp7
-rw-r--r--scene/gui/popup_menu.cpp116
-rw-r--r--scene/gui/popup_menu.h1
-rw-r--r--scene/gui/progress_bar.cpp22
-rw-r--r--scene/gui/range.cpp4
-rw-r--r--scene/gui/rich_text_label.cpp148
-rw-r--r--scene/gui/scroll_bar.cpp52
-rw-r--r--scene/gui/scroll_container.cpp14
-rw-r--r--scene/gui/separator.cpp6
-rw-r--r--scene/gui/slider.cpp10
-rw-r--r--scene/gui/spin_box.cpp10
-rw-r--r--scene/gui/split_container.cpp28
-rw-r--r--scene/gui/tab_container.cpp120
-rw-r--r--scene/gui/tabs.cpp126
-rw-r--r--scene/gui/text_edit.cpp254
-rw-r--r--scene/gui/text_edit.h15
-rw-r--r--scene/gui/tree.cpp258
-rw-r--r--scene/main/canvas_item.cpp52
-rw-r--r--scene/main/canvas_item.h2
-rw-r--r--scene/main/http_request.cpp54
-rw-r--r--scene/main/instance_placeholder.cpp22
-rw-r--r--scene/main/node.cpp82
-rw-r--r--scene/main/node.h4
-rw-r--r--scene/main/scene_tree.cpp161
-rw-r--r--scene/main/scene_tree.h41
-rw-r--r--scene/main/timer.cpp12
-rw-r--r--scene/main/timer.h10
-rw-r--r--scene/main/viewport.cpp264
-rw-r--r--scene/main/viewport.h33
-rw-r--r--scene/main/window.cpp80
-rw-r--r--scene/main/window.h7
-rw-r--r--scene/register_scene_types.cpp947
-rw-r--r--scene/resources/animation.h8
-rw-r--r--scene/resources/curve.cpp14
-rw-r--r--scene/resources/default_theme/default_theme.cpp11
-rw-r--r--scene/resources/default_theme/default_theme.h2
-rw-r--r--scene/resources/immediate_mesh.cpp2
-rw-r--r--scene/resources/material.cpp440
-rw-r--r--scene/resources/mesh.cpp31
-rw-r--r--scene/resources/mesh.h6
-rw-r--r--scene/resources/navigation_mesh.cpp8
-rw-r--r--scene/resources/packed_scene.cpp34
-rw-r--r--scene/resources/particles_material.cpp103
-rw-r--r--scene/resources/particles_material.h17
-rw-r--r--scene/resources/primitive_meshes.cpp37
-rw-r--r--scene/resources/primitive_meshes.h8
-rw-r--r--scene/resources/resource_format_text.cpp327
-rw-r--r--scene/resources/resource_format_text.h25
-rw-r--r--scene/resources/shader.cpp5
-rw-r--r--scene/resources/sky_material.cpp429
-rw-r--r--scene/resources/sky_material.h25
-rw-r--r--scene/resources/sprite_frames.cpp4
-rw-r--r--scene/resources/syntax_highlighter.cpp6
-rw-r--r--scene/resources/texture.cpp58
-rw-r--r--scene/resources/texture.h8
-rw-r--r--scene/resources/theme.cpp153
-rw-r--r--scene/resources/theme.h12
-rw-r--r--scene/resources/tile_set.cpp626
-rw-r--r--scene/resources/tile_set.h63
-rw-r--r--scene/resources/visual_shader.cpp318
-rw-r--r--scene/resources/visual_shader.h1
-rw-r--r--scene/resources/visual_shader_nodes.cpp652
-rw-r--r--scene/resources/visual_shader_nodes.h33
-rw-r--r--scene/resources/visual_shader_particle_nodes.cpp80
-rw-r--r--scene/resources/visual_shader_sdf_nodes.cpp58
-rw-r--r--scene/scene_string_names.cpp5
-rw-r--r--scene/scene_string_names.h5
158 files changed, 5834 insertions, 3972 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp
index 9ee37670d1..da2ab6ada8 100644
--- a/scene/2d/animated_sprite_2d.cpp
+++ b/scene/2d/animated_sprite_2d.cpp
@@ -123,7 +123,7 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &property) const {
}
property.hint_string += String(E->get());
- if (animation == E->get()) {
+ if (animation == E) {
current_found = true;
}
}
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp
index 860ccfec64..4b96689613 100644
--- a/scene/2d/audio_stream_player_2d.cpp
+++ b/scene/2d/audio_stream_player_2d.cpp
@@ -255,7 +255,7 @@ void AudioStreamPlayer2D::_notification(int p_what) {
//stop playing if no longer active
if (!active.is_set()) {
set_physics_process_internal(false);
- emit_signal("finished");
+ emit_signal(SNAME("finished"));
}
}
}
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index f293081987..0e55915957 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -241,6 +241,10 @@ void Camera2D::_notification(int p_what) {
viewport = get_viewport();
}
+ if (is_current()) {
+ viewport->_camera_2d_set(this);
+ }
+
canvas = get_canvas();
RID vp = viewport->get_viewport_rid();
@@ -259,6 +263,7 @@ void Camera2D::_notification(int p_what) {
if (is_current()) {
if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
viewport->set_canvas_transform(Transform2D());
+ clear_current();
}
}
remove_from_group(group_name);
@@ -392,18 +397,29 @@ Camera2D::Camera2DProcessCallback Camera2D::get_process_callback() const {
void Camera2D::_make_current(Object *p_which) {
if (p_which == this) {
current = true;
+ if (is_inside_tree()) {
+ get_viewport()->_camera_2d_set(this);
+ update();
+ }
} else {
current = false;
+ if (is_inside_tree()) {
+ if (get_viewport()->get_camera_2d() == this) {
+ get_viewport()->_camera_2d_set(nullptr);
+ }
+ update();
+ }
}
}
-void Camera2D::_set_current(bool p_current) {
+void Camera2D::set_current(bool p_current) {
if (p_current) {
make_current();
+ } else {
+ if (current) {
+ clear_current();
+ }
}
-
- current = p_current;
- update();
}
bool Camera2D::is_current() const {
@@ -411,18 +427,19 @@ bool Camera2D::is_current() const {
}
void Camera2D::make_current() {
- if (!is_inside_tree()) {
- current = true;
- } else {
+ if (is_inside_tree()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", this);
+ } else {
+ current = true;
}
_update_scroll();
}
void Camera2D::clear_current() {
- current = false;
if (is_inside_tree()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", (Object *)nullptr);
+ } else {
+ current = false;
}
}
@@ -659,17 +676,14 @@ void Camera2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_rotating", "rotating"), &Camera2D::set_rotating);
ClassDB::bind_method(D_METHOD("is_rotating"), &Camera2D::is_rotating);
- ClassDB::bind_method(D_METHOD("make_current"), &Camera2D::make_current);
- ClassDB::bind_method(D_METHOD("clear_current"), &Camera2D::clear_current);
- ClassDB::bind_method(D_METHOD("_make_current"), &Camera2D::_make_current);
-
ClassDB::bind_method(D_METHOD("_update_scroll"), &Camera2D::_update_scroll);
ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &Camera2D::set_process_callback);
ClassDB::bind_method(D_METHOD("get_process_callback"), &Camera2D::get_process_callback);
- ClassDB::bind_method(D_METHOD("_set_current", "current"), &Camera2D::_set_current);
+ ClassDB::bind_method(D_METHOD("set_current", "current"), &Camera2D::set_current);
ClassDB::bind_method(D_METHOD("is_current"), &Camera2D::is_current);
+ ClassDB::bind_method(D_METHOD("_make_current"), &Camera2D::_make_current);
ClassDB::bind_method(D_METHOD("set_limit", "margin", "limit"), &Camera2D::set_limit);
ClassDB::bind_method(D_METHOD("get_limit", "margin"), &Camera2D::get_limit);
@@ -725,7 +739,7 @@ void Camera2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "anchor_mode", PROPERTY_HINT_ENUM, "Fixed TopLeft,Drag Center"), "set_anchor_mode", "get_anchor_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rotating"), "set_rotating", "is_rotating");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "_set_current", "is_current");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "set_current", "is_current");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom"), "set_zoom", "get_zoom");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", PROPERTY_USAGE_NONE), "set_custom_viewport", "get_custom_viewport");
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback");
diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h
index 7494e526cc..95b49cf076 100644
--- a/scene/2d/camera_2d.h
+++ b/scene/2d/camera_2d.h
@@ -83,7 +83,7 @@ protected:
void _update_scroll();
void _make_current(Object *p_which);
- void _set_current(bool p_current);
+ void set_current(bool p_current);
void _set_old_smoothing(real_t p_enable);
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index 93d154bb01..3ba3a4eec5 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -498,6 +498,20 @@ void CollisionObject2D::_mouse_exit() {
emit_signal(SceneStringNames::get_singleton()->mouse_exited);
}
+void CollisionObject2D::_mouse_shape_enter(int p_shape) {
+ if (get_script_instance()) {
+ get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_shape_enter, p_shape);
+ }
+ emit_signal(SceneStringNames::get_singleton()->mouse_shape_entered, p_shape);
+}
+
+void CollisionObject2D::_mouse_shape_exit(int p_shape) {
+ if (get_script_instance()) {
+ get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_shape_exit, p_shape);
+ }
+ emit_signal(SceneStringNames::get_singleton()->mouse_shape_exited, p_shape);
+}
+
void CollisionObject2D::set_only_update_transform_changes(bool p_enable) {
only_update_transform_changes = p_enable;
}
@@ -584,6 +598,8 @@ void CollisionObject2D::_bind_methods() {
ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "viewport", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::INT, "shape_idx")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
ADD_SIGNAL(MethodInfo("mouse_exited"));
+ ADD_SIGNAL(MethodInfo("mouse_shape_entered", PropertyInfo(Variant::INT, "shape_idx")));
+ ADD_SIGNAL(MethodInfo("mouse_shape_exited", PropertyInfo(Variant::INT, "shape_idx")));
ADD_PROPERTY(PropertyInfo(Variant::INT, "disable_mode", PROPERTY_HINT_ENUM, "Remove,MakeStatic,KeepActive"), "set_disable_mode", "get_disable_mode");
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index 7a71affbb5..eca53eecfc 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -75,7 +75,7 @@ private:
int total_subshapes = 0;
Map<uint32_t, ShapeData> shapes;
- bool only_update_transform_changes = false; //this is used for sync physics in CharacterBody2D
+ bool only_update_transform_changes = false; // This is used for sync to physics.
void _apply_disabled();
void _apply_enabled();
@@ -92,6 +92,9 @@ protected:
void _mouse_enter();
void _mouse_exit();
+ void _mouse_shape_enter(int p_shape);
+ void _mouse_shape_exit(int p_shape);
+
void set_only_update_transform_changes(bool p_enable);
bool is_only_update_transform_changes_enabled() const;
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index 24f3301ce1..a341ba69ac 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -463,10 +463,6 @@ Vector2 CPUParticles2D::get_gravity() const {
}
void CPUParticles2D::_validate_property(PropertyInfo &property) const {
- if (property.name == "color" && color_ramp.is_valid()) {
- property.usage = PROPERTY_USAGE_NONE;
- }
-
if (property.name == "emission_sphere_radius" && emission_shape != EMISSION_SHAPE_SPHERE) {
property.usage = PROPERTY_USAGE_NONE;
}
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp
index f9cbdbf377..e9a95b680c 100644
--- a/scene/2d/navigation_agent_2d.cpp
+++ b/scene/2d/navigation_agent_2d.cpp
@@ -235,7 +235,7 @@ void NavigationAgent2D::_avoidance_done(Vector3 p_new_velocity) {
}
velocity_submitted = false;
- emit_signal("velocity_computed", velocity);
+ emit_signal(SNAME("velocity_computed"), velocity);
}
TypedArray<String> NavigationAgent2D::get_configuration_warnings() const {
@@ -287,7 +287,7 @@ void NavigationAgent2D::update_navigation() {
navigation_path = NavigationServer2D::get_singleton()->map_get_path(agent_parent->get_world_2d()->get_navigation_map(), o, target_location, true, navigable_layers);
navigation_finished = false;
nav_path_index = 0;
- emit_signal("path_changed");
+ emit_signal(SNAME("path_changed"));
}
if (navigation_path.size() == 0) {
@@ -303,7 +303,7 @@ void NavigationAgent2D::update_navigation() {
_check_distance_to_target();
nav_path_index -= 1;
navigation_finished = true;
- emit_signal("navigation_finished");
+ emit_signal(SNAME("navigation_finished"));
break;
}
}
@@ -313,7 +313,7 @@ void NavigationAgent2D::update_navigation() {
void NavigationAgent2D::_check_distance_to_target() {
if (!target_reached) {
if (distance_to_target() < target_desired_distance) {
- emit_signal("target_reached");
+ emit_signal(SNAME("target_reached"));
target_reached = true;
}
}
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index be619ed60d..561207c24c 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -76,21 +76,21 @@ Ref<KinematicCollision2D> PhysicsBody2D::_move(const Vector2 &p_motion, bool p_i
return Ref<KinematicCollision2D>();
}
-bool PhysicsBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only, bool p_cancel_sliding) {
+bool PhysicsBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only, bool p_cancel_sliding, const Set<RID> &p_exclude) {
if (is_only_update_transform_changes_enabled()) {
ERR_PRINT("Move functions do not work together with 'sync to physics' option. Please read the documentation.");
}
Transform2D gt = get_global_transform();
- bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, p_margin, &r_result, p_exclude_raycast_shapes);
+ bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, p_margin, &r_result, p_exclude_raycast_shapes, p_exclude);
// Restore direction of motion to be along original motion,
// in order to avoid sliding due to recovery,
// but only if collision depth is low enough to avoid tunneling.
- real_t motion_length = p_motion.length();
- if (motion_length > CMP_EPSILON) {
+ if (p_cancel_sliding) {
+ real_t motion_length = p_motion.length();
real_t precision = 0.001;
- if (colliding && p_cancel_sliding) {
+ if (colliding) {
// Can't just use margin as a threshold because collision depth is calculated on unsafe motion,
// so even in normal resting cases the depth can be a bit more than the margin.
precision += motion_length * (r_result.collision_unsafe_fraction - r_result.collision_safe_fraction);
@@ -101,16 +101,21 @@ bool PhysicsBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_in
}
if (p_cancel_sliding) {
+ // When motion is null, recovery is the resulting motion.
+ Vector2 motion_normal;
+ if (motion_length > CMP_EPSILON) {
+ motion_normal = p_motion / motion_length;
+ }
+
// Check depth of recovery.
- Vector2 motion_normal = p_motion / motion_length;
- real_t dot = r_result.motion.dot(motion_normal);
- Vector2 recovery = r_result.motion - motion_normal * dot;
+ real_t projected_length = r_result.motion.dot(motion_normal);
+ Vector2 recovery = r_result.motion - motion_normal * projected_length;
real_t recovery_length = recovery.length();
// Fixes cases where canceling slide causes the motion to go too deep into the ground,
- // Becauses we're only taking rest information into account and not general recovery.
+ // because we're only taking rest information into account and not general recovery.
if (recovery_length < (real_t)p_margin + precision) {
// Apply adjustment to motion.
- r_result.motion = motion_normal * dot;
+ r_result.motion = motion_normal * projected_length;
r_result.remainder = p_motion - r_result.motion;
}
}
@@ -140,8 +145,7 @@ TypedArray<PhysicsBody2D> PhysicsBody2D::get_collision_exceptions() {
List<RID> exceptions;
PhysicsServer2D::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions);
Array ret;
- for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) {
- RID body = E->get();
+ for (const RID &body : exceptions) {
ObjectID instance_id = PhysicsServer2D::get_singleton()->body_get_object_instance_id(body);
Object *obj = ObjectDB::get_instance(instance_id);
PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(obj);
@@ -224,6 +228,13 @@ void StaticBody2D::set_kinematic_motion_enabled(bool p_enabled) {
set_body_mode(PhysicsServer2D::BODY_MODE_STATIC);
}
+#ifdef TOOLS_ENABLED
+ if (Engine::get_singleton()->is_editor_hint()) {
+ update_configuration_warnings();
+ return;
+ }
+#endif
+
_update_kinematic_motion();
}
@@ -231,8 +242,75 @@ bool StaticBody2D::is_kinematic_motion_enabled() const {
return kinematic_motion;
}
+void StaticBody2D::set_sync_to_physics(bool p_enable) {
+ if (sync_to_physics == p_enable) {
+ return;
+ }
+
+ sync_to_physics = p_enable;
+
+#ifdef TOOLS_ENABLED
+ if (Engine::get_singleton()->is_editor_hint()) {
+ update_configuration_warnings();
+ return;
+ }
+#endif
+
+ if (kinematic_motion) {
+ _update_kinematic_motion();
+ }
+}
+
+bool StaticBody2D::is_sync_to_physics_enabled() const {
+ return sync_to_physics;
+}
+
+void StaticBody2D::_direct_state_changed(Object *p_state) {
+ if (!sync_to_physics) {
+ return;
+ }
+
+ PhysicsDirectBodyState2D *state = Object::cast_to<PhysicsDirectBodyState2D>(p_state);
+ ERR_FAIL_NULL_MSG(state, "Method '_direct_state_changed' must receive a valid PhysicsDirectBodyState2D object as argument");
+
+ last_valid_transform = state->get_transform();
+ set_notify_local_transform(false);
+ set_global_transform(last_valid_transform);
+ set_notify_local_transform(true);
+}
+
+TypedArray<String> StaticBody2D::get_configuration_warnings() const {
+ TypedArray<String> warnings = PhysicsBody2D::get_configuration_warnings();
+
+ if (sync_to_physics && !kinematic_motion) {
+ warnings.push_back(TTR("Sync to physics works only when kinematic motion is enabled."));
+ }
+
+ return warnings;
+}
+
void StaticBody2D::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ last_valid_transform = get_global_transform();
+ } break;
+
+ case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
+ // Used by sync to physics, send the new transform to the physics...
+ Transform2D new_transform = get_global_transform();
+
+ real_t delta_time = get_physics_process_delta_time();
+ new_transform.translate(constant_linear_velocity * delta_time);
+ new_transform.set_rotation(new_transform.get_rotation() + constant_angular_velocity * delta_time);
+
+ PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform);
+
+ // ... but then revert changes.
+ set_notify_local_transform(false);
+ set_global_transform(last_valid_transform);
+ set_notify_local_transform(true);
+ } break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
@@ -242,19 +320,23 @@ void StaticBody2D::_notification(int p_what) {
ERR_FAIL_COND(!kinematic_motion);
- real_t delta_time = get_physics_process_delta_time();
-
Transform2D new_transform = get_global_transform();
+ real_t delta_time = get_physics_process_delta_time();
new_transform.translate(constant_linear_velocity * delta_time);
new_transform.set_rotation(new_transform.get_rotation() + constant_angular_velocity * delta_time);
- PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform);
+ if (sync_to_physics) {
+ // Propagate transform change to node.
+ set_global_transform(new_transform);
+ } else {
+ PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform);
- // Propagate transform change to node.
- set_block_transform_notify(true);
- set_global_transform(new_transform);
- set_block_transform_notify(false);
+ // Propagate transform change to node.
+ set_block_transform_notify(true);
+ set_global_transform(new_transform);
+ set_block_transform_notify(false);
+ }
} break;
}
}
@@ -271,10 +353,14 @@ void StaticBody2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &StaticBody2D::set_physics_material_override);
ClassDB::bind_method(D_METHOD("get_physics_material_override"), &StaticBody2D::get_physics_material_override);
+ ClassDB::bind_method(D_METHOD("set_sync_to_physics", "enable"), &StaticBody2D::set_sync_to_physics);
+ ClassDB::bind_method(D_METHOD("is_sync_to_physics_enabled"), &StaticBody2D::is_sync_to_physics_enabled);
+
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "physics_material_override", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), "set_physics_material_override", "get_physics_material_override");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "constant_linear_velocity"), "set_constant_linear_velocity", "get_constant_linear_velocity");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "constant_angular_velocity"), "set_constant_angular_velocity", "get_constant_angular_velocity");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "kinematic_motion"), "set_kinematic_motion_enabled", "is_kinematic_motion_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync_to_physics"), "set_sync_to_physics", "is_sync_to_physics_enabled");
}
StaticBody2D::StaticBody2D() :
@@ -298,14 +384,24 @@ void StaticBody2D::_update_kinematic_motion() {
}
#endif
+ if (kinematic_motion && sync_to_physics) {
+ PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), callable_mp(this, &StaticBody2D::_direct_state_changed));
+ set_only_update_transform_changes(true);
+ set_notify_local_transform(true);
+ } else {
+ PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), Callable());
+ set_only_update_transform_changes(false);
+ set_notify_local_transform(false);
+ }
+
+ bool needs_physics_process = false;
if (kinematic_motion) {
if (!Math::is_zero_approx(constant_angular_velocity) || !constant_linear_velocity.is_equal_approx(Vector2())) {
- set_physics_process_internal(true);
- return;
+ needs_physics_process = true;
}
}
- set_physics_process_internal(false);
+ set_physics_process_internal(needs_physics_process);
}
void RigidBody2D::_body_enter_tree(ObjectID p_id) {
@@ -955,11 +1051,14 @@ void RigidBody2D::_reload_physics_characteristics() {
void CharacterBody2D::move_and_slide() {
Vector2 body_velocity_normal = linear_velocity.normalized();
-
bool was_on_floor = on_floor;
+ // Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
+ float delta = Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time();
+
Vector2 current_floor_velocity = floor_velocity;
- if (on_floor && on_floor_body.is_valid()) {
+
+ if ((on_floor || on_wall) && on_floor_body.is_valid()) {
//this approach makes sure there is less delay between the actual body velocity and the one we saved
PhysicsDirectBodyState2D *bs = PhysicsServer2D::get_singleton()->body_get_direct_state(on_floor_body);
if (bs) {
@@ -967,19 +1066,30 @@ void CharacterBody2D::move_and_slide() {
}
}
- // Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
- Vector2 motion = (current_floor_velocity + linear_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
-
+ motion_results.clear();
on_floor = false;
- on_floor_body = RID();
on_ceiling = false;
on_wall = false;
- motion_results.clear();
floor_normal = Vector2();
floor_velocity = Vector2();
- // No sliding on first attempt to keep floor motion stable when possible.
- bool sliding_enabled = false;
+ if (current_floor_velocity != Vector2()) {
+ PhysicsServer2D::MotionResult floor_result;
+ Set<RID> exclude;
+ exclude.insert(on_floor_body);
+ if (move_and_collide(current_floor_velocity * delta, infinite_inertia, floor_result, true, false, false, false, exclude)) {
+ motion_results.push_back(floor_result);
+ _set_collision_direction(floor_result);
+ }
+ }
+
+ on_floor_body = RID();
+ Vector2 motion = linear_velocity * delta;
+
+ // No sliding on first attempt to keep floor motion stable when possible,
+ // when stop on slope is enabled.
+ bool sliding_enabled = !stop_on_slope;
+
for (int iteration = 0; iteration < max_slides; ++iteration) {
PhysicsServer2D::MotionResult result;
bool found_collision = false;
@@ -1003,31 +1113,19 @@ void CharacterBody2D::move_and_slide() {
found_collision = true;
motion_results.push_back(result);
-
- if (up_direction == Vector2()) {
- //all is a wall
- on_wall = true;
- } else {
- if (Math::acos(result.collision_normal.dot(up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //floor
-
- on_floor = true;
- floor_normal = result.collision_normal;
- on_floor_body = result.collider;
- floor_velocity = result.collider_velocity;
-
- if (stop_on_slope) {
- if ((body_velocity_normal + up_direction).length() < 0.01) {
- Transform2D gt = get_global_transform();
- gt.elements[2] -= result.motion.slide(up_direction);
- set_global_transform(gt);
- linear_velocity = Vector2();
- return;
- }
+ _set_collision_direction(result);
+
+ if (on_floor && stop_on_slope) {
+ if ((body_velocity_normal + up_direction).length() < 0.01) {
+ Transform2D gt = get_global_transform();
+ if (result.motion.length() > margin) {
+ gt.elements[2] -= result.motion.slide(up_direction);
+ } else {
+ gt.elements[2] -= result.motion;
}
- } else if (Math::acos(result.collision_normal.dot(-up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //ceiling
- on_ceiling = true;
- } else {
- on_wall = true;
+ set_global_transform(gt);
+ linear_velocity = Vector2();
+ return;
}
}
@@ -1047,6 +1145,11 @@ void CharacterBody2D::move_and_slide() {
}
}
+ if (!on_floor && !on_wall) {
+ // Add last platform velocity when just left a moving platform.
+ linear_velocity += current_floor_velocity;
+ }
+
if (!was_on_floor || snap == Vector2()) {
return;
}
@@ -1054,7 +1157,7 @@ void CharacterBody2D::move_and_slide() {
// Apply snap.
Transform2D gt = get_global_transform();
PhysicsServer2D::MotionResult result;
- if (move_and_collide(snap, infinite_inertia, result, margin, false, true)) {
+ if (move_and_collide(snap, infinite_inertia, result, margin, false, true, false)) {
bool apply = true;
if (up_direction != Vector2()) {
if (Math::acos(result.collision_normal.dot(up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) {
@@ -1065,9 +1168,12 @@ void CharacterBody2D::move_and_slide() {
if (stop_on_slope) {
// move and collide may stray the object a bit because of pre un-stucking,
// so only ensure that motion happens on floor direction in this case.
- result.motion = up_direction * up_direction.dot(result.motion);
+ if (result.motion.length() > margin) {
+ result.motion = up_direction * up_direction.dot(result.motion);
+ } else {
+ result.motion = Vector2();
+ }
}
-
} else {
apply = false;
}
@@ -1080,6 +1186,29 @@ void CharacterBody2D::move_and_slide() {
}
}
+void CharacterBody2D::_set_collision_direction(const PhysicsServer2D::MotionResult &p_result) {
+ on_floor = false;
+ on_ceiling = false;
+ on_wall = false;
+ if (up_direction == Vector2()) {
+ //all is a wall
+ on_wall = true;
+ } else {
+ if (Math::acos(p_result.collision_normal.dot(up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //floor
+ on_floor = true;
+ floor_normal = p_result.collision_normal;
+ on_floor_body = p_result.collider;
+ floor_velocity = p_result.collider_velocity;
+ } else if (Math::acos(p_result.collision_normal.dot(-up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //ceiling
+ on_ceiling = true;
+ } else {
+ on_wall = true;
+ on_floor_body = p_result.collider;
+ floor_velocity = p_result.collider_velocity;
+ }
+ }
+}
+
bool CharacterBody2D::separate_raycast_shapes(PhysicsServer2D::MotionResult &r_result) {
PhysicsServer2D::SeparationResult sep_res[8]; //max 8 rays
@@ -1168,45 +1297,6 @@ Ref<KinematicCollision2D> CharacterBody2D::_get_slide_collision(int p_bounce) {
return slide_colliders[p_bounce];
}
-void CharacterBody2D::set_sync_to_physics(bool p_enable) {
- if (sync_to_physics == p_enable) {
- return;
- }
- sync_to_physics = p_enable;
-
- if (Engine::get_singleton()->is_editor_hint()) {
- return;
- }
-
- if (p_enable) {
- PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), callable_mp(this, &CharacterBody2D::_direct_state_changed));
- set_only_update_transform_changes(true);
- set_notify_local_transform(true);
- } else {
- PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), Callable());
- set_only_update_transform_changes(false);
- set_notify_local_transform(false);
- }
-}
-
-bool CharacterBody2D::is_sync_to_physics_enabled() const {
- return sync_to_physics;
-}
-
-void CharacterBody2D::_direct_state_changed(Object *p_state) {
- if (!sync_to_physics) {
- return;
- }
-
- PhysicsDirectBodyState2D *state = Object::cast_to<PhysicsDirectBodyState2D>(p_state);
- ERR_FAIL_NULL_MSG(state, "Method '_direct_state_changed' must receive a valid PhysicsDirectBodyState2D object as argument");
-
- last_valid_transform = state->get_transform();
- set_notify_local_transform(false);
- set_global_transform(last_valid_transform);
- set_notify_local_transform(true);
-}
-
void CharacterBody2D::set_safe_margin(real_t p_margin) {
margin = p_margin;
}
@@ -1266,8 +1356,6 @@ void CharacterBody2D::set_up_direction(const Vector2 &p_up_direction) {
void CharacterBody2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- last_valid_transform = get_global_transform();
-
// Reset move_and_slide() data.
on_floor = false;
on_floor_body = RID();
@@ -1276,16 +1364,6 @@ void CharacterBody2D::_notification(int p_what) {
motion_results.clear();
floor_velocity = Vector2();
} break;
-
- case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
- // Used by sync to physics, send the new transform to the physics.
- Transform2D new_transform = get_global_transform();
- PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform);
- // But then revert changes.
- set_notify_local_transform(false);
- set_global_transform(last_valid_transform);
- set_notify_local_transform(true);
- } break;
}
}
@@ -1318,9 +1396,6 @@ void CharacterBody2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_slide_count"), &CharacterBody2D::get_slide_count);
ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &CharacterBody2D::_get_slide_collision);
- ClassDB::bind_method(D_METHOD("set_sync_to_physics", "enable"), &CharacterBody2D::set_sync_to_physics);
- ClassDB::bind_method(D_METHOD("is_sync_to_physics_enabled"), &CharacterBody2D::is_sync_to_physics_enabled);
-
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stop_on_slope"), "set_stop_on_slope_enabled", "is_stop_on_slope_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "infinite_inertia"), "set_infinite_inertia_enabled", "is_infinite_inertia_enabled");
@@ -1329,7 +1404,6 @@ void CharacterBody2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "snap"), "set_snap", "get_snap");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "up_direction"), "set_up_direction", "get_up_direction");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "motion/sync_to_physics"), "set_sync_to_physics", "is_sync_to_physics_enabled");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision/safe_margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_safe_margin", "get_safe_margin");
}
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 5a5417eaf3..7a319aabc9 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -50,7 +50,7 @@ protected:
Ref<KinematicCollision2D> _move(const Vector2 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false, real_t p_margin = 0.08);
public:
- bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false, bool p_cancel_sliding = true);
+ bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false, bool p_cancel_sliding = true, const Set<RID> &p_exclude = Set<RID>());
bool test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, const Ref<KinematicCollision2D> &r_collision = Ref<KinematicCollision2D>(), real_t p_margin = 0.08);
TypedArray<PhysicsBody2D> get_collision_exceptions();
@@ -69,6 +69,11 @@ class StaticBody2D : public PhysicsBody2D {
Ref<PhysicsMaterial> physics_material_override;
bool kinematic_motion = false;
+ bool sync_to_physics = false;
+
+ Transform2D last_valid_transform;
+
+ void _direct_state_changed(Object *p_state);
protected:
void _notification(int p_what);
@@ -84,6 +89,8 @@ public:
Vector2 get_constant_linear_velocity() const;
real_t get_constant_angular_velocity() const;
+ virtual TypedArray<String> get_configuration_warnings() const override;
+
StaticBody2D();
private:
@@ -93,6 +100,9 @@ private:
void set_kinematic_motion_enabled(bool p_enabled);
bool is_kinematic_motion_enabled() const;
+
+ void set_sync_to_physics(bool p_enable);
+ bool is_sync_to_physics_enabled() const;
};
class RigidBody2D : public PhysicsBody2D {
@@ -243,7 +253,7 @@ public:
TypedArray<Node2D> get_colliding_bodies() const; //function for script
- TypedArray<String> get_configuration_warnings() const override;
+ virtual TypedArray<String> get_configuration_warnings() const override;
RigidBody2D();
~RigidBody2D();
@@ -276,7 +286,6 @@ private:
bool on_floor = false;
bool on_ceiling = false;
bool on_wall = false;
- bool sync_to_physics = false;
Vector<PhysicsServer2D::MotionResult> motion_results;
Vector<Ref<KinematicCollision2D>> slide_colliders;
@@ -285,9 +294,6 @@ private:
bool separate_raycast_shapes(PhysicsServer2D::MotionResult &r_result);
- Transform2D last_valid_transform;
- void _direct_state_changed(Object *p_state);
-
void set_safe_margin(real_t p_margin);
real_t get_safe_margin() const;
@@ -308,6 +314,7 @@ private:
const Vector2 &get_up_direction() const;
void set_up_direction(const Vector2 &p_up_direction);
+ void _set_collision_direction(const PhysicsServer2D::MotionResult &p_result);
protected:
void _notification(int p_what);
@@ -328,9 +335,6 @@ public:
int get_slide_count() const;
PhysicsServer2D::MotionResult get_slide_collision(int p_bounce) const;
- void set_sync_to_physics(bool p_enable);
- bool is_sync_to_physics_enabled() const;
-
CharacterBody2D();
~CharacterBody2D();
};
diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp
index 8f1f5fadbc..15cbdf535e 100644
--- a/scene/2d/skeleton_2d.cpp
+++ b/scene/2d/skeleton_2d.cpp
@@ -568,7 +568,7 @@ void Skeleton2D::_make_bone_setup_dirty() {
}
bone_setup_dirty = true;
if (is_inside_tree()) {
- call_deferred("_update_bone_setup");
+ call_deferred(SNAME("_update_bone_setup"));
}
}
@@ -597,7 +597,7 @@ void Skeleton2D::_update_bone_setup() {
transform_dirty = true;
_update_transform();
- emit_signal("bone_setup_changed");
+ emit_signal(SNAME("bone_setup_changed"));
}
void Skeleton2D::_make_transform_dirty() {
@@ -606,7 +606,7 @@ void Skeleton2D::_make_transform_dirty() {
}
transform_dirty = true;
if (is_inside_tree()) {
- call_deferred("_update_transform");
+ call_deferred(SNAME("_update_transform"));
}
}
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index e39c8841cd..e9efa1cf84 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -58,7 +58,7 @@ void TileMapPattern::remove_cell(const Vector2i &p_coords, bool p_update_size) {
}
int TileMapPattern::get_cell_source_id(const Vector2i &p_coords) const {
- ERR_FAIL_COND_V(!pattern.has(p_coords), -1);
+ ERR_FAIL_COND_V(!pattern.has(p_coords), TileSet::INVALID_SOURCE);
return pattern[p_coords].source_id;
}
@@ -113,7 +113,7 @@ void TileMapPattern::clear() {
};
void TileMapPattern::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_cell", "coords", "source_id", "atlas_coords", "alternative_tile"), &TileMapPattern::set_cell, DEFVAL(-1), DEFVAL(TileSetSource::INVALID_ATLAS_COORDS), DEFVAL(TileSetSource::INVALID_TILE_ALTERNATIVE));
+ ClassDB::bind_method(D_METHOD("set_cell", "coords", "source_id", "atlas_coords", "alternative_tile"), &TileMapPattern::set_cell, DEFVAL(TileSet::INVALID_SOURCE), DEFVAL(TileSetSource::INVALID_ATLAS_COORDS), DEFVAL(TileSetSource::INVALID_TILE_ALTERNATIVE));
ClassDB::bind_method(D_METHOD("has_cell", "coords"), &TileMapPattern::has_cell);
ClassDB::bind_method(D_METHOD("remove_cell", "coords"), &TileMapPattern::remove_cell);
ClassDB::bind_method(D_METHOD("get_cell_source_id", "coords"), &TileMapPattern::get_cell_source_id);
@@ -299,7 +299,7 @@ void TileMap::set_tileset(const Ref<TileSet> &p_tileset) {
_recreate_quadrants();
}
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
int TileMap::get_quadrant_size() const {
@@ -311,13 +311,13 @@ void TileMap::set_quadrant_size(int p_size) {
quadrant_size = p_size;
_recreate_quadrants();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileMap::set_collision_visibility_mode(TileMap::VisibilityMode p_show_collision) {
show_collision = p_show_collision;
_recreate_quadrants();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
TileMap::VisibilityMode TileMap::get_collision_visibility_mode() {
@@ -327,7 +327,7 @@ TileMap::VisibilityMode TileMap::get_collision_visibility_mode() {
void TileMap::set_navigation_visibility_mode(TileMap::VisibilityMode p_show_navigation) {
show_navigation = p_show_navigation;
_recreate_quadrants();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() {
@@ -337,7 +337,7 @@ TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() {
void TileMap::set_y_sort_enabled(bool p_enable) {
Node2D::set_y_sort_enabled(p_enable);
_recreate_quadrants();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileMap::update_dirty_quadrants() {
@@ -480,7 +480,7 @@ void TileMap::_make_all_quadrants_dirty(bool p_update) {
return;
}
if (p_update) {
- call_deferred("update_dirty_quadrants");
+ call_deferred(SNAME("update_dirty_quadrants"));
}
}
@@ -500,7 +500,7 @@ void TileMap::_make_quadrant_dirty(Map<Vector2i, TileMapQuadrant>::Element *Q, b
}
if (p_update) {
- call_deferred("update_dirty_quadrants");
+ call_deferred(SNAME("update_dirty_quadrants"));
}
}
@@ -513,15 +513,15 @@ void TileMap::set_cell(const Vector2i &p_coords, int p_source_id, const Vector2i
Vector2i atlas_coords = p_atlas_coords;
int alternative_tile = p_alternative_tile;
- if ((source_id == -1 || atlas_coords == TileSetSource::INVALID_ATLAS_COORDS || alternative_tile == TileSetSource::INVALID_TILE_ALTERNATIVE) &&
- (source_id != -1 || atlas_coords != TileSetSource::INVALID_ATLAS_COORDS || alternative_tile != TileSetSource::INVALID_TILE_ALTERNATIVE)) {
+ if ((source_id == TileSet::INVALID_SOURCE || atlas_coords == TileSetSource::INVALID_ATLAS_COORDS || alternative_tile == TileSetSource::INVALID_TILE_ALTERNATIVE) &&
+ (source_id != TileSet::INVALID_SOURCE || atlas_coords != TileSetSource::INVALID_ATLAS_COORDS || alternative_tile != TileSetSource::INVALID_TILE_ALTERNATIVE)) {
WARN_PRINT("Setting a cell a cell as empty requires both source_id, atlas_coord and alternative_tile to be set to their respective \"invalid\" values. Values were thus changes accordingly.");
- source_id = -1;
+ source_id = TileSet::INVALID_SOURCE;
atlas_coords = TileSetSource::INVALID_ATLAS_COORDS;
alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE;
}
- if (!E && source_id == -1) {
+ if (!E && source_id == TileSet::INVALID_SOURCE) {
return; // Nothing to do, the tile is already empty.
}
@@ -530,7 +530,7 @@ void TileMap::set_cell(const Vector2i &p_coords, int p_source_id, const Vector2i
Map<Vector2i, TileMapQuadrant>::Element *Q = quadrant_map.find(qk);
- if (source_id == -1) {
+ if (source_id == TileSet::INVALID_SOURCE) {
// Erase existing cell in the tile map.
tile_map.erase(pk);
@@ -579,18 +579,23 @@ void TileMap::set_cell(const Vector2i &p_coords, int p_source_id, const Vector2i
}
}
-int TileMap::get_cell_source_id(const Vector2i &p_coords) const {
+int TileMap::get_cell_source_id(const Vector2i &p_coords, bool p_use_proxies) const {
// Get a cell source id from position
const Map<Vector2i, TileMapCell>::Element *E = tile_map.find(p_coords);
if (!E) {
- return -1;
+ return TileSet::INVALID_SOURCE;
+ }
+
+ if (p_use_proxies && tile_set.is_valid()) {
+ Array proxyed = tile_set->map_tile_proxy(E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ return proxyed[0];
}
return E->get().source_id;
}
-Vector2i TileMap::get_cell_atlas_coords(const Vector2i &p_coords) const {
+Vector2i TileMap::get_cell_atlas_coords(const Vector2i &p_coords, bool p_use_proxies) const {
// Get a cell source id from position
const Map<Vector2i, TileMapCell>::Element *E = tile_map.find(p_coords);
@@ -598,10 +603,15 @@ Vector2i TileMap::get_cell_atlas_coords(const Vector2i &p_coords) const {
return TileSetSource::INVALID_ATLAS_COORDS;
}
+ if (p_use_proxies && tile_set.is_valid()) {
+ Array proxyed = tile_set->map_tile_proxy(E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ return proxyed[1];
+ }
+
return E->get().get_atlas_coords();
}
-int TileMap::get_cell_alternative_tile(const Vector2i &p_coords) const {
+int TileMap::get_cell_alternative_tile(const Vector2i &p_coords, bool p_use_proxies) const {
// Get a cell source id from position
const Map<Vector2i, TileMapCell>::Element *E = tile_map.find(p_coords);
@@ -609,6 +619,11 @@ int TileMap::get_cell_alternative_tile(const Vector2i &p_coords) const {
return TileSetSource::INVALID_TILE_ALTERNATIVE;
}
+ if (p_use_proxies && tile_set.is_valid()) {
+ Array proxyed = tile_set->map_tile_proxy(E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ return proxyed[2];
+ }
+
return E->get().alternative_tile;
}
@@ -697,11 +712,18 @@ void TileMap::set_pattern(Vector2i p_position, const TileMapPattern *p_pattern)
}
}
-TileMapCell TileMap::get_cell(const Vector2i &p_coords) const {
+TileMapCell TileMap::get_cell(const Vector2i &p_coords, bool p_use_proxies) const {
if (!tile_map.has(p_coords)) {
return TileMapCell();
} else {
- return tile_map.find(p_coords)->get();
+ TileMapCell c = tile_map.find(p_coords)->get();
+ if (p_use_proxies && tile_set.is_valid()) {
+ Array proxyed = tile_set->map_tile_proxy(c.source_id, c.get_atlas_coords(), c.alternative_tile);
+ c.source_id = proxyed[0];
+ c.set_atlas_coords(proxyed[1]);
+ c.alternative_tile = proxyed[2];
+ }
+ return c;
}
}
@@ -720,7 +742,7 @@ void TileMap::fix_invalid_tiles() {
}
}
for (Set<Vector2i>::Element *E = coords.front(); E; E = E->next()) {
- set_cell(E->get(), -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE);
+ set_cell(E->get(), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE);
}
}
@@ -773,6 +795,7 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) {
const int *r = p_data.ptr();
int offset = (format >= FORMAT_2) ? 3 : 2;
+ ERR_FAIL_COND_MSG(c % offset != 0, "Corrupted tile data.");
clear();
@@ -799,25 +822,28 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) {
SWAP(local[9], local[10]);
}
#endif
+ // Extracts position in TileMap.
int16_t x = decode_uint16(&local[0]);
int16_t y = decode_uint16(&local[2]);
if (format == FORMAT_3) {
uint16_t source_id = decode_uint16(&local[4]);
uint16_t atlas_coords_x = decode_uint16(&local[6]);
- uint16_t atlas_coords_y = decode_uint32(&local[8]);
+ uint16_t atlas_coords_y = decode_uint16(&local[8]);
uint16_t alternative_tile = decode_uint16(&local[10]);
set_cell(Vector2i(x, y), source_id, Vector2i(atlas_coords_x, atlas_coords_y), alternative_tile);
} else {
#ifndef DISABLE_DEPRECATED
- uint32_t v = decode_uint32(&local[4]);
- v &= (1 << 29) - 1;
+ // Previous decated format.
- // We generate an alternative tile number out of the the flags
- // An option should create the alternative in the tileset for compatibility
+ uint32_t v = decode_uint32(&local[4]);
+ // Extract the transform flags that used to be in the tilemap.
bool flip_h = v & (1 << 29);
bool flip_v = v & (1 << 30);
bool transpose = v & (1 << 31);
+ v &= (1 << 29) - 1;
+
+ // Extract autotile/atlas coords.
int16_t coord_x = 0;
int16_t coord_y = 0;
if (format == FORMAT_2) {
@@ -825,13 +851,17 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) {
coord_y = decode_uint16(&local[10]);
}
- int compatibility_alternative_tile = ((int)flip_h) + ((int)flip_v << 1) + ((int)transpose << 2);
-
if (tile_set.is_valid()) {
- v = tile_set->compatibility_get_source_for_tile_id(v);
+ Array a = tile_set->compatibility_tilemap_map(v, Vector2i(coord_x, coord_y), flip_h, flip_v, transpose);
+ if (a.size() == 3) {
+ set_cell(Vector2i(x, y), a[0], a[1], a[2]);
+ } else {
+ ERR_PRINT(vformat("No valid tile in Tileset for: tile:%s coords:%s flip_h:%s flip_v:%s transpose:%s", v, Vector2i(coord_x, coord_y), flip_h, flip_v, transpose));
+ }
+ } else {
+ int compatibility_alternative_tile = ((int)flip_h) + ((int)flip_v << 1) + ((int)transpose << 2);
+ set_cell(Vector2i(x, y), v, Vector2i(coord_x, coord_y), compatibility_alternative_tile);
}
-
- set_cell(Vector2i(x, y), v, Vector2i(coord_x, coord_y), compatibility_alternative_tile);
#endif
}
}
@@ -1567,8 +1597,8 @@ void TileMap::set_light_mask(int p_light_mask) {
// Occlusion: set light mask.
CanvasItem::set_light_mask(p_light_mask);
for (Map<Vector2i, TileMapQuadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- for (List<RID>::Element *F = E->get().canvas_items.front(); F; F = F->next()) {
- RenderingServer::get_singleton()->canvas_item_set_light_mask(F->get(), get_light_mask());
+ for (const RID &F : E->get().canvas_items) {
+ RenderingServer::get_singleton()->canvas_item_set_light_mask(F, get_light_mask());
}
}
}
@@ -1580,8 +1610,8 @@ void TileMap::set_material(const Ref<Material> &p_material) {
// Update material for the whole tilemap.
for (Map<Vector2i, TileMapQuadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
TileMapQuadrant &q = E->get();
- for (List<RID>::Element *F = q.canvas_items.front(); F; F = F->next()) {
- RS::get_singleton()->canvas_item_set_use_parent_material(F->get(), get_use_parent_material() || get_material().is_valid());
+ for (const RID &F : q.canvas_items) {
+ RS::get_singleton()->canvas_item_set_use_parent_material(F, get_use_parent_material() || get_material().is_valid());
}
}
}
@@ -1593,8 +1623,8 @@ void TileMap::set_use_parent_material(bool p_use_parent_material) {
// Update use_parent_material for the whole tilemap.
for (Map<Vector2i, TileMapQuadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
TileMapQuadrant &q = E->get();
- for (List<RID>::Element *F = q.canvas_items.front(); F; F = F->next()) {
- RS::get_singleton()->canvas_item_set_use_parent_material(F->get(), get_use_parent_material() || get_material().is_valid());
+ for (const RID &F : q.canvas_items) {
+ RS::get_singleton()->canvas_item_set_use_parent_material(F, get_use_parent_material() || get_material().is_valid());
}
}
}
@@ -1604,8 +1634,8 @@ void TileMap::set_texture_filter(TextureFilter p_texture_filter) {
CanvasItem::set_texture_filter(p_texture_filter);
for (Map<Vector2i, TileMapQuadrant>::Element *F = quadrant_map.front(); F; F = F->next()) {
TileMapQuadrant &q = F->get();
- for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
- RenderingServer::get_singleton()->canvas_item_set_default_texture_filter(E->get(), RS::CanvasItemTextureFilter(p_texture_filter));
+ for (const RID &E : q.canvas_items) {
+ RenderingServer::get_singleton()->canvas_item_set_default_texture_filter(E, RS::CanvasItemTextureFilter(p_texture_filter));
_make_quadrant_dirty(F);
}
}
@@ -1616,8 +1646,8 @@ void TileMap::set_texture_repeat(CanvasItem::TextureRepeat p_texture_repeat) {
CanvasItem::set_texture_repeat(p_texture_repeat);
for (Map<Vector2i, TileMapQuadrant>::Element *F = quadrant_map.front(); F; F = F->next()) {
TileMapQuadrant &q = F->get();
- for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
- RenderingServer::get_singleton()->canvas_item_set_default_texture_repeat(E->get(), RS::CanvasItemTextureRepeat(p_texture_repeat));
+ for (const RID &E : q.canvas_items) {
+ RenderingServer::get_singleton()->canvas_item_set_default_texture_repeat(E, RS::CanvasItemTextureRepeat(p_texture_repeat));
_make_quadrant_dirty(F);
}
}
@@ -1727,10 +1757,10 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_navigation_visibility_mode", "show_navigation"), &TileMap::set_navigation_visibility_mode);
ClassDB::bind_method(D_METHOD("get_navigation_visibility_mode"), &TileMap::get_navigation_visibility_mode);
- ClassDB::bind_method(D_METHOD("set_cell", "coords", "source_id", "atlas_coords", "alternative_tile"), &TileMap::set_cell, DEFVAL(-1), DEFVAL(TileSetSource::INVALID_ATLAS_COORDS), DEFVAL(TileSetSource::INVALID_TILE_ALTERNATIVE));
- ClassDB::bind_method(D_METHOD("get_cell_source_id", "coords"), &TileMap::get_cell_source_id);
- ClassDB::bind_method(D_METHOD("get_cell_atlas_coords", "coords"), &TileMap::get_cell_atlas_coords);
- ClassDB::bind_method(D_METHOD("get_cell_alternative_tile", "coords"), &TileMap::get_cell_alternative_tile);
+ ClassDB::bind_method(D_METHOD("set_cell", "coords", "source_id", "atlas_coords", "alternative_tile"), &TileMap::set_cell, DEFVAL(TileSet::INVALID_SOURCE), DEFVAL(TileSetSource::INVALID_ATLAS_COORDS), DEFVAL(TileSetSource::INVALID_TILE_ALTERNATIVE));
+ ClassDB::bind_method(D_METHOD("get_cell_source_id", "coords", "use_proxies"), &TileMap::get_cell_source_id);
+ ClassDB::bind_method(D_METHOD("get_cell_atlas_coords", "coords", "use_proxies"), &TileMap::get_cell_atlas_coords);
+ ClassDB::bind_method(D_METHOD("get_cell_alternative_tile", "coords", "use_proxies"), &TileMap::get_cell_alternative_tile);
ClassDB::bind_method(D_METHOD("fix_invalid_tiles"), &TileMap::fix_invalid_tiles);
ClassDB::bind_method(D_METHOD("get_surrounding_tiles", "coords"), &TileMap::get_surrounding_tiles);
@@ -1764,7 +1794,7 @@ void TileMap::_bind_methods() {
}
void TileMap::_tile_set_changed() {
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
_make_all_quadrants_dirty(true);
}
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index 3001e6b471..9e35e73ad8 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -265,16 +265,16 @@ public:
VisibilityMode get_navigation_visibility_mode();
void set_cell(const Vector2i &p_coords, int p_source_id = -1, const Vector2i p_atlas_coords = TileSetSource::INVALID_ATLAS_COORDS, int p_alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE);
- int get_cell_source_id(const Vector2i &p_coords) const;
- Vector2i get_cell_atlas_coords(const Vector2i &p_coords) const;
- int get_cell_alternative_tile(const Vector2i &p_coords) const;
+ int get_cell_source_id(const Vector2i &p_coords, bool p_use_proxies = false) const;
+ Vector2i get_cell_atlas_coords(const Vector2i &p_coords, bool p_use_proxies = false) const;
+ int get_cell_alternative_tile(const Vector2i &p_coords, bool p_use_proxies = false) const;
TileMapPattern *get_pattern(TypedArray<Vector2i> p_coords_array);
Vector2i map_pattern(Vector2i p_position_in_tilemap, Vector2i p_coords_in_pattern, const TileMapPattern *p_pattern);
void set_pattern(Vector2i p_position, const TileMapPattern *p_pattern);
// Not exposed to users
- TileMapCell get_cell(const Vector2i &p_coords) const;
+ TileMapCell get_cell(const Vector2i &p_coords, bool p_use_proxies = false) const;
Map<Vector2i, TileMapQuadrant> &get_quadrant_map();
int get_effective_quadrant_size() const;
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp
index 0a6393551c..7c345ad377 100644
--- a/scene/2d/touch_screen_button.cpp
+++ b/scene/2d/touch_screen_button.cpp
@@ -294,7 +294,7 @@ void TouchScreenButton::_press(int p_finger_pressed) {
get_viewport()->input(iea, true);
}
- emit_signal("pressed");
+ emit_signal(SNAME("pressed"));
update();
}
@@ -313,7 +313,7 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
}
if (!p_exiting_tree) {
- emit_signal("released");
+ emit_signal(SNAME("released"));
update();
}
}
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index ba559b4ecb..bb8f9f8ccb 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -607,7 +607,7 @@ void AudioStreamPlayer3D::_notification(int p_what) {
//stop playing if no longer active
if (!active.is_set()) {
set_physics_process_internal(false);
- emit_signal("finished");
+ emit_signal(SNAME("finished"));
}
}
}
@@ -794,7 +794,7 @@ uint32_t AudioStreamPlayer3D::get_area_mask() const {
void AudioStreamPlayer3D::set_emission_angle_enabled(bool p_enable) {
emission_angle_enabled = p_enable;
- update_gizmo();
+ update_gizmos();
}
bool AudioStreamPlayer3D::is_emission_angle_enabled() const {
@@ -804,7 +804,7 @@ bool AudioStreamPlayer3D::is_emission_angle_enabled() const {
void AudioStreamPlayer3D::set_emission_angle(float p_angle) {
ERR_FAIL_COND(p_angle < 0 || p_angle > 90);
emission_angle = p_angle;
- update_gizmo();
+ update_gizmos();
}
float AudioStreamPlayer3D::get_emission_angle() const {
diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp
index 1ed8c0b4eb..2e962b96c3 100644
--- a/scene/3d/camera_3d.cpp
+++ b/scene/3d/camera_3d.cpp
@@ -85,14 +85,14 @@ void Camera3D::_update_camera() {
// here goes listener stuff
/*
if (viewport_ptr && is_inside_scene() && is_current())
- get_viewport()->_camera_transform_changed_notify();
+ get_viewport()->_camera_3d_transform_changed_notify();
*/
if (get_tree()->is_node_being_edited(this) || !is_current()) {
return;
}
- get_viewport()->_camera_transform_changed_notify();
+ get_viewport()->_camera_3d_transform_changed_notify();
}
void Camera3D::_notification(int p_what) {
@@ -104,9 +104,9 @@ void Camera3D::_notification(int p_what) {
viewport = get_viewport();
ERR_FAIL_COND(!viewport);
- bool first_camera = viewport->_camera_add(this);
+ bool first_camera = viewport->_camera_3d_add(this);
if (current || first_camera) {
- viewport->_camera_set(this);
+ viewport->_camera_3d_set(this);
}
} break;
@@ -128,7 +128,7 @@ void Camera3D::_notification(int p_what) {
}
if (viewport) {
- viewport->_camera_remove(this);
+ viewport->_camera_3d_remove(this);
viewport = nullptr;
}
@@ -164,7 +164,7 @@ void Camera3D::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_f
mode = PROJECTION_PERSPECTIVE;
RenderingServer::get_singleton()->camera_set_perspective(camera, fov, near, far);
- update_gizmo();
+ update_gizmos();
force_change = false;
}
@@ -181,7 +181,7 @@ void Camera3D::set_orthogonal(float p_size, float p_z_near, float p_z_far) {
force_change = false;
RenderingServer::get_singleton()->camera_set_orthogonal(camera, size, near, far);
- update_gizmo();
+ update_gizmos();
}
void Camera3D::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) {
@@ -198,7 +198,7 @@ void Camera3D::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float
force_change = false;
RenderingServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far);
- update_gizmo();
+ update_gizmos();
}
void Camera3D::set_projection(Camera3D::Projection p_mode) {
@@ -220,7 +220,7 @@ void Camera3D::make_current() {
return;
}
- get_viewport()->_camera_set(this);
+ get_viewport()->_camera_3d_set(this);
//get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this);
}
@@ -231,11 +231,11 @@ void Camera3D::clear_current(bool p_enable_next) {
return;
}
- if (get_viewport()->get_camera() == this) {
- get_viewport()->_camera_set(nullptr);
+ if (get_viewport()->get_camera_3d() == this) {
+ get_viewport()->_camera_3d_set(nullptr);
if (p_enable_next) {
- get_viewport()->_camera_make_next_current(this);
+ get_viewport()->_camera_3d_make_next_current(this);
}
}
}
@@ -250,7 +250,7 @@ void Camera3D::set_current(bool p_current) {
bool Camera3D::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
- return get_viewport()->get_camera() == this;
+ return get_viewport()->get_camera_3d() == this;
} else {
return current;
}
@@ -755,7 +755,7 @@ void ClippedCamera3D::_notification(int p_what) {
}
if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) {
- update_gizmo();
+ update_gizmos();
}
}
diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp
index 40e3f7c764..dd1f25da68 100644
--- a/scene/3d/collision_object_3d.cpp
+++ b/scene/3d/collision_object_3d.cpp
@@ -77,6 +77,10 @@ void CollisionObject3D::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
+ if (only_update_transform_changes) {
+ return;
+ }
+
if (area) {
PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform());
} else {
@@ -284,6 +288,14 @@ void CollisionObject3D::set_body_mode(PhysicsServer3D::BodyMode p_mode) {
PhysicsServer3D::get_singleton()->body_set_mode(rid, p_mode);
}
+void CollisionObject3D::set_only_update_transform_changes(bool p_enable) {
+ only_update_transform_changes = p_enable;
+}
+
+bool CollisionObject3D::is_only_update_transform_changes_enabled() const {
+ return only_update_transform_changes;
+}
+
void CollisionObject3D::_update_pickable() {
if (!is_inside_tree()) {
return;
diff --git a/scene/3d/collision_object_3d.h b/scene/3d/collision_object_3d.h
index a3a890db75..7c30a5cd98 100644
--- a/scene/3d/collision_object_3d.h
+++ b/scene/3d/collision_object_3d.h
@@ -74,6 +74,8 @@ private:
Map<uint32_t, ShapeData> shapes;
+ bool only_update_transform_changes = false; // This is used for sync to physics.
+
bool capture_input_on_drag = false;
bool ray_pickable = true;
@@ -107,6 +109,9 @@ protected:
void set_body_mode(PhysicsServer3D::BodyMode p_mode);
+ void set_only_update_transform_changes(bool p_enable);
+ bool is_only_update_transform_changes_enabled() const;
+
public:
void set_collision_layer(uint32_t p_layer);
uint32_t get_collision_layer() const;
diff --git a/scene/3d/collision_polygon_3d.cpp b/scene/3d/collision_polygon_3d.cpp
index 8a4f8b639b..42645f47d4 100644
--- a/scene/3d/collision_polygon_3d.cpp
+++ b/scene/3d/collision_polygon_3d.cpp
@@ -122,7 +122,7 @@ void CollisionPolygon3D::set_polygon(const Vector<Point2> &p_polygon) {
_build_polygon();
}
update_configuration_warnings();
- update_gizmo();
+ update_gizmos();
}
Vector<Point2> CollisionPolygon3D::get_polygon() const {
@@ -136,7 +136,7 @@ AABB CollisionPolygon3D::get_item_rect() const {
void CollisionPolygon3D::set_depth(real_t p_depth) {
depth = p_depth;
_build_polygon();
- update_gizmo();
+ update_gizmos();
}
real_t CollisionPolygon3D::get_depth() const {
@@ -145,7 +145,7 @@ real_t CollisionPolygon3D::get_depth() const {
void CollisionPolygon3D::set_disabled(bool p_disabled) {
disabled = p_disabled;
- update_gizmo();
+ update_gizmos();
if (parent) {
parent->shape_owner_set_disabled(owner_id, p_disabled);
diff --git a/scene/3d/collision_shape_3d.cpp b/scene/3d/collision_shape_3d.cpp
index be3fde8013..9643d33c86 100644
--- a/scene/3d/collision_shape_3d.cpp
+++ b/scene/3d/collision_shape_3d.cpp
@@ -117,7 +117,7 @@ void CollisionShape3D::_notification(int p_what) {
}
void CollisionShape3D::resource_changed(RES res) {
- update_gizmo();
+ update_gizmos();
}
TypedArray<String> CollisionShape3D::get_configuration_warnings() const {
@@ -166,7 +166,7 @@ void CollisionShape3D::set_shape(const Ref<Shape3D> &p_shape) {
if (!shape.is_null()) {
shape->register_owner(this);
}
- update_gizmo();
+ update_gizmos();
if (parent) {
parent->shape_owner_clear_shapes(owner_id);
if (shape.is_valid()) {
@@ -187,7 +187,7 @@ Ref<Shape3D> CollisionShape3D::get_shape() const {
void CollisionShape3D::set_disabled(bool p_disabled) {
disabled = p_disabled;
- update_gizmo();
+ update_gizmos();
if (parent) {
parent->shape_owner_set_disabled(owner_id, p_disabled);
}
diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp
index 6dc865ec0e..60f8ad8f36 100644
--- a/scene/3d/cpu_particles_3d.cpp
+++ b/scene/3d/cpu_particles_3d.cpp
@@ -401,6 +401,22 @@ void CPUParticles3D::set_emission_colors(const Vector<Color> &p_colors) {
emission_colors = p_colors;
}
+void CPUParticles3D::set_emission_ring_axis(Vector3 p_axis) {
+ emission_ring_axis = p_axis;
+}
+
+void CPUParticles3D::set_emission_ring_height(float p_height) {
+ emission_ring_height = p_height;
+}
+
+void CPUParticles3D::set_emission_ring_radius(float p_radius) {
+ emission_ring_radius = p_radius;
+}
+
+void CPUParticles3D::set_emission_ring_inner_radius(float p_radius) {
+ emission_ring_inner_radius = p_radius;
+}
+
float CPUParticles3D::get_emission_sphere_radius() const {
return emission_sphere_radius;
}
@@ -421,6 +437,22 @@ Vector<Color> CPUParticles3D::get_emission_colors() const {
return emission_colors;
}
+Vector3 CPUParticles3D::get_emission_ring_axis() const {
+ return emission_ring_axis;
+}
+
+float CPUParticles3D::get_emission_ring_height() const {
+ return emission_ring_height;
+}
+
+float CPUParticles3D::get_emission_ring_radius() const {
+ return emission_ring_radius;
+}
+
+float CPUParticles3D::get_emission_ring_inner_radius() const {
+ return emission_ring_inner_radius;
+}
+
CPUParticles3D::EmissionShape CPUParticles3D::get_emission_shape() const {
return emission_shape;
}
@@ -434,10 +466,6 @@ Vector3 CPUParticles3D::get_gravity() const {
}
void CPUParticles3D::_validate_property(PropertyInfo &property) const {
- if (property.name == "color" && color_ramp.is_valid()) {
- property.usage = PROPERTY_USAGE_NONE;
- }
-
if (property.name == "emission_sphere_radius" && emission_shape != EMISSION_SHAPE_SPHERE) {
property.usage = PROPERTY_USAGE_NONE;
}
@@ -446,7 +474,7 @@ void CPUParticles3D::_validate_property(PropertyInfo &property) const {
property.usage = PROPERTY_USAGE_NONE;
}
- if ((property.name == "emission_point_texture" || property.name == "emission_color_texture") && (emission_shape < EMISSION_SHAPE_POINTS)) {
+ if ((property.name == "emission_point_texture" || property.name == "emission_color_texture" || property.name == "emission_points") && (emission_shape != EMISSION_SHAPE_POINTS && (emission_shape != EMISSION_SHAPE_DIRECTED_POINTS))) {
property.usage = PROPERTY_USAGE_NONE;
}
@@ -454,6 +482,10 @@ void CPUParticles3D::_validate_property(PropertyInfo &property) const {
property.usage = PROPERTY_USAGE_NONE;
}
+ if (property.name.begins_with("emission_ring_") && emission_shape != EMISSION_SHAPE_RING) {
+ property.usage = PROPERTY_USAGE_NONE;
+ }
+
if (property.name.begins_with("orbit_") && !particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
property.usage = PROPERTY_USAGE_NONE;
}
@@ -750,6 +782,21 @@ void CPUParticles3D::_particles_process(float p_delta) {
p.base_color = emission_colors.get(random_idx);
}
} break;
+ case EMISSION_SHAPE_RING: {
+ float ring_random_angle = Math::randf() * 2.0 * Math_PI;
+ float ring_random_radius = Math::randf() * (emission_ring_radius - emission_ring_inner_radius) + emission_ring_inner_radius;
+ Vector3 axis = emission_ring_axis.normalized();
+ Vector3 ortho_axis = Vector3();
+ if (axis == Vector3(1.0, 0.0, 0.0)) {
+ ortho_axis = Vector3(0.0, 1.0, 0.0).cross(axis);
+ } else {
+ ortho_axis = Vector3(1.0, 0.0, 0.0).cross(axis);
+ }
+ ortho_axis = ortho_axis.normalized();
+ ortho_axis.rotate(axis, ring_random_angle);
+ ortho_axis = ortho_axis.normalized();
+ p.transform.origin = ortho_axis * ring_random_radius + (Math::randf() * emission_ring_height - emission_ring_height / 2.0) * axis;
+ } break;
case EMISSION_SHAPE_MAX: { // Max value for validity check.
break;
}
@@ -1007,7 +1054,7 @@ void CPUParticles3D::_update_particle_data_buffer() {
sorter.sort(order, pc);
} else if (draw_order == DRAW_ORDER_VIEW_DEPTH) {
ERR_FAIL_NULL(get_viewport());
- Camera3D *c = get_viewport()->get_camera();
+ Camera3D *c = get_viewport()->get_camera_3d();
if (c) {
Vector3 dir = c->get_global_transform().basis.get_axis(2); //far away to close
@@ -1340,18 +1387,34 @@ void CPUParticles3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_emission_colors", "array"), &CPUParticles3D::set_emission_colors);
ClassDB::bind_method(D_METHOD("get_emission_colors"), &CPUParticles3D::get_emission_colors);
+ ClassDB::bind_method(D_METHOD("set_emission_ring_axis", "axis"), &CPUParticles3D::set_emission_ring_axis);
+ ClassDB::bind_method(D_METHOD("get_emission_ring_axis"), &CPUParticles3D::get_emission_ring_axis);
+
+ ClassDB::bind_method(D_METHOD("set_emission_ring_height", "height"), &CPUParticles3D::set_emission_ring_height);
+ ClassDB::bind_method(D_METHOD("get_emission_ring_height"), &CPUParticles3D::get_emission_ring_height);
+
+ ClassDB::bind_method(D_METHOD("set_emission_ring_radius", "radius"), &CPUParticles3D::set_emission_ring_radius);
+ ClassDB::bind_method(D_METHOD("get_emission_ring_radius"), &CPUParticles3D::get_emission_ring_radius);
+
+ ClassDB::bind_method(D_METHOD("set_emission_ring_inner_radius", "inner_radius"), &CPUParticles3D::set_emission_ring_inner_radius);
+ ClassDB::bind_method(D_METHOD("get_emission_ring_inner_radius"), &CPUParticles3D::get_emission_ring_inner_radius);
+
ClassDB::bind_method(D_METHOD("get_gravity"), &CPUParticles3D::get_gravity);
ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &CPUParticles3D::set_gravity);
ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles3D::convert_from_particles);
ADD_GROUP("Emission Shape", "emission_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Box,Points,Directed Points", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_emission_shape", "get_emission_shape");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Box,Points,Directed Points,Ring", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_emission_shape", "get_emission_shape");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_sphere_radius", PROPERTY_HINT_RANGE, "0.01,128,0.01"), "set_emission_sphere_radius", "get_emission_sphere_radius");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_box_extents"), "set_emission_box_extents", "get_emission_box_extents");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "emission_points"), "set_emission_points", "get_emission_points");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "emission_normals"), "set_emission_normals", "get_emission_normals");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "emission_colors"), "set_emission_colors", "get_emission_colors");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_ring_axis"), "set_emission_ring_axis", "get_emission_ring_axis");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_height"), "set_emission_ring_height", "get_emission_ring_height");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_radius"), "set_emission_ring_radius", "get_emission_ring_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_inner_radius"), "set_emission_ring_inner_radius", "get_emission_ring_inner_radius");
ADD_GROUP("Particle Flags", "particle_flag_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_align_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_rotate_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ROTATE_Y);
@@ -1437,6 +1500,7 @@ void CPUParticles3D::_bind_methods() {
BIND_ENUM_CONSTANT(EMISSION_SHAPE_BOX);
BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINTS);
BIND_ENUM_CONSTANT(EMISSION_SHAPE_DIRECTED_POINTS);
+ BIND_ENUM_CONSTANT(EMISSION_SHAPE_RING);
BIND_ENUM_CONSTANT(EMISSION_SHAPE_MAX);
}
@@ -1465,6 +1529,10 @@ CPUParticles3D::CPUParticles3D() {
set_emission_shape(EMISSION_SHAPE_POINT);
set_emission_sphere_radius(1);
set_emission_box_extents(Vector3(1, 1, 1));
+ set_emission_ring_axis(Vector3(0, 0, 1.0));
+ set_emission_ring_height(1);
+ set_emission_ring_radius(1);
+ set_emission_ring_inner_radius(0);
set_gravity(Vector3(0, -9.8, 0));
diff --git a/scene/3d/cpu_particles_3d.h b/scene/3d/cpu_particles_3d.h
index b35e659757..07d345ba2c 100644
--- a/scene/3d/cpu_particles_3d.h
+++ b/scene/3d/cpu_particles_3d.h
@@ -76,6 +76,7 @@ public:
EMISSION_SHAPE_BOX,
EMISSION_SHAPE_POINTS,
EMISSION_SHAPE_DIRECTED_POINTS,
+ EMISSION_SHAPE_RING,
EMISSION_SHAPE_MAX
};
@@ -171,6 +172,10 @@ private:
Vector<Vector3> emission_normals;
Vector<Color> emission_colors;
int emission_point_count = 0;
+ Vector3 emission_ring_axis;
+ float emission_ring_height;
+ float emission_ring_radius;
+ float emission_ring_inner_radius;
Vector3 gravity = Vector3(0, -9.8, 0);
@@ -268,6 +273,10 @@ public:
void set_emission_normals(const Vector<Vector3> &p_normals);
void set_emission_colors(const Vector<Color> &p_colors);
void set_emission_point_count(int p_count);
+ void set_emission_ring_axis(Vector3 p_axis);
+ void set_emission_ring_height(float p_height);
+ void set_emission_ring_radius(float p_radius);
+ void set_emission_ring_inner_radius(float p_radius);
EmissionShape get_emission_shape() const;
float get_emission_sphere_radius() const;
@@ -276,6 +285,10 @@ public:
Vector<Vector3> get_emission_normals() const;
Vector<Color> get_emission_colors() const;
int get_emission_point_count() const;
+ Vector3 get_emission_ring_axis() const;
+ float get_emission_ring_height() const;
+ float get_emission_ring_radius() const;
+ float get_emission_ring_inner_radius() const;
void set_gravity(const Vector3 &p_gravity);
Vector3 get_gravity() const;
diff --git a/scene/3d/decal.cpp b/scene/3d/decal.cpp
index 7d6abe458a..05f023721b 100644
--- a/scene/3d/decal.cpp
+++ b/scene/3d/decal.cpp
@@ -33,7 +33,7 @@
void Decal::set_extents(const Vector3 &p_extents) {
extents = p_extents;
RS::get_singleton()->decal_set_extents(decal, p_extents);
- update_gizmo();
+ update_gizmos();
}
Vector3 Decal::get_extents() const {
@@ -45,6 +45,7 @@ void Decal::set_texture(DecalTexture p_type, const Ref<Texture2D> &p_texture) {
textures[p_type] = p_texture;
RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
RS::get_singleton()->decal_set_texture(decal, RS::DecalTexture(p_type), texture_rid);
+ update_configuration_warnings();
}
Ref<Texture2D> Decal::get_texture(DecalTexture p_type) const {
@@ -137,6 +138,7 @@ float Decal::get_distance_fade_length() const {
void Decal::set_cull_mask(uint32_t p_layers) {
cull_mask = p_layers;
RS::get_singleton()->decal_set_cull_mask(decal, cull_mask);
+ update_configuration_warnings();
}
uint32_t Decal::get_cull_mask() const {
@@ -160,6 +162,27 @@ void Decal::_validate_property(PropertyInfo &property) const {
}
}
+TypedArray<String> Decal::get_configuration_warnings() const {
+ TypedArray<String> warnings = Node::get_configuration_warnings();
+
+ if (textures[TEXTURE_ALBEDO].is_null() && textures[TEXTURE_NORMAL].is_null() && textures[TEXTURE_ORM].is_null() && textures[TEXTURE_EMISSION].is_null()) {
+ warnings.push_back(TTR("The decal has no textures loaded into any of its texture properties, and will therefore not be visible."));
+ }
+
+ if ((textures[TEXTURE_NORMAL].is_valid() || textures[TEXTURE_ORM].is_valid()) && textures[TEXTURE_ALBEDO].is_null()) {
+ warnings.push_back(TTR("The decal has a Normal and/or ORM texture, but no Albedo texture is set.\nAn Albedo texture with an alpha channel is required to blend the normal/ORM maps onto the underlying surface.\nIf you don't want the Albedo texture to be visible, set Albedo Mix to 0."));
+ }
+
+ if (cull_mask == 0) {
+ // NOTE: This warning will not be emitted if none of the 20 checkboxes
+ // exposed in the editor are checked. This is because there are
+ // currently 12 unexposed layers in the editor inspector.
+ warnings.push_back(TTR("The decal's Cull Mask has no bits enabled, which means the decal will not paint objects on any layer.\nTo resolve this, enable at least one bit in the Cull Mask property."));
+ }
+
+ return warnings;
+}
+
void Decal::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_extents", "extents"), &Decal::set_extents);
ClassDB::bind_method(D_METHOD("get_extents"), &Decal::get_extents);
@@ -207,7 +230,9 @@ void Decal::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_energy", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_emission_energy", "get_emission_energy");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "albedo_mix", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_albedo_mix", "get_albedo_mix");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "normal_fade", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_normal_fade", "get_normal_fade");
+ // A Normal Fade of 1.0 causes the decal to be invisible even if fully perpendicular to a surface.
+ // Due to this, limit Normal Fade to 0.999.
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "normal_fade", PROPERTY_HINT_RANGE, "0,0.999,0.001"), "set_normal_fade", "get_normal_fade");
ADD_GROUP("Vertical Fade", "");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "upper_fade", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_upper_fade", "get_upper_fade");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lower_fade", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_lower_fade", "get_lower_fade");
diff --git a/scene/3d/decal.h b/scene/3d/decal.h
index ce19e76de1..31a6315213 100644
--- a/scene/3d/decal.h
+++ b/scene/3d/decal.h
@@ -67,6 +67,8 @@ protected:
void _validate_property(PropertyInfo &property) const override;
public:
+ virtual TypedArray<String> get_configuration_warnings() const override;
+
void set_extents(const Vector3 &p_extents);
Vector3 get_extents() const;
diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp
index f78027e6c7..44cd7c10d8 100644
--- a/scene/3d/gpu_particles_3d.cpp
+++ b/scene/3d/gpu_particles_3d.cpp
@@ -99,7 +99,7 @@ void GPUParticles3D::set_randomness_ratio(float p_ratio) {
void GPUParticles3D::set_visibility_aabb(const AABB &p_aabb) {
visibility_aabb = p_aabb;
RS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb);
- update_gizmo();
+ update_gizmos();
}
void GPUParticles3D::set_use_local_coordinates(bool p_enable) {
diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp
index c1e71b9565..cc1b620025 100644
--- a/scene/3d/gpu_particles_collision_3d.cpp
+++ b/scene/3d/gpu_particles_collision_3d.cpp
@@ -73,7 +73,7 @@ void GPUParticlesCollisionSphere::_bind_methods() {
void GPUParticlesCollisionSphere::set_radius(float p_radius) {
radius = p_radius;
RS::get_singleton()->particles_collision_set_sphere_radius(_get_collision(), radius);
- update_gizmo();
+ update_gizmos();
}
float GPUParticlesCollisionSphere::get_radius() const {
@@ -103,7 +103,7 @@ void GPUParticlesCollisionBox::_bind_methods() {
void GPUParticlesCollisionBox::set_extents(const Vector3 &p_extents) {
extents = p_extents;
RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
- update_gizmo();
+ update_gizmos();
}
Vector3 GPUParticlesCollisionBox::get_extents() const {
@@ -397,9 +397,7 @@ Ref<Image> GPUParticlesCollisionSDF::bake() {
bake_step_function(0, "Finding Meshes");
}
- for (List<PlotMesh>::Element *E = plot_meshes.front(); E; E = E->next()) {
- const PlotMesh &pm = E->get();
-
+ for (const PlotMesh &pm : plot_meshes) {
for (int i = 0; i < pm.mesh->get_surface_count(); i++) {
if (pm.mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
continue; //only triangles
@@ -545,7 +543,7 @@ float GPUParticlesCollisionSDF::get_thickness() const {
void GPUParticlesCollisionSDF::set_extents(const Vector3 &p_extents) {
extents = p_extents;
RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
- update_gizmo();
+ update_gizmos();
}
Vector3 GPUParticlesCollisionSDF::get_extents() const {
@@ -554,7 +552,7 @@ Vector3 GPUParticlesCollisionSDF::get_extents() const {
void GPUParticlesCollisionSDF::set_resolution(Resolution p_resolution) {
resolution = p_resolution;
- update_gizmo();
+ update_gizmos();
}
GPUParticlesCollisionSDF::Resolution GPUParticlesCollisionSDF::get_resolution() const {
@@ -596,7 +594,7 @@ void GPUParticlesCollisionHeightField::_notification(int p_what) {
}
if (follow_camera_mode && get_viewport()) {
- Camera3D *cam = get_viewport()->get_camera();
+ Camera3D *cam = get_viewport()->get_camera_3d();
if (cam) {
Transform3D xform = get_global_transform();
Vector3 x_axis = xform.basis.get_axis(Vector3::AXIS_X).normalized();
@@ -680,7 +678,7 @@ float GPUParticlesCollisionHeightField::get_follow_camera_push_ratio() const {
void GPUParticlesCollisionHeightField::set_extents(const Vector3 &p_extents) {
extents = p_extents;
RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
- update_gizmo();
+ update_gizmos();
RS::get_singleton()->particles_collision_height_field_update(_get_collision());
}
@@ -691,7 +689,7 @@ Vector3 GPUParticlesCollisionHeightField::get_extents() const {
void GPUParticlesCollisionHeightField::set_resolution(Resolution p_resolution) {
resolution = p_resolution;
RS::get_singleton()->particles_collision_set_height_field_resolution(_get_collision(), RS::ParticlesCollisionHeightfieldResolution(resolution));
- update_gizmo();
+ update_gizmos();
RS::get_singleton()->particles_collision_height_field_update(_get_collision());
}
@@ -761,7 +759,7 @@ float GPUParticlesAttractor3D::get_attenuation() const {
void GPUParticlesAttractor3D::set_directionality(float p_directionality) {
directionality = p_directionality;
RS::get_singleton()->particles_collision_set_attractor_directionality(collision, p_directionality);
- update_gizmo();
+ update_gizmos();
}
float GPUParticlesAttractor3D::get_directionality() const {
@@ -808,7 +806,7 @@ void GPUParticlesAttractorSphere::_bind_methods() {
void GPUParticlesAttractorSphere::set_radius(float p_radius) {
radius = p_radius;
RS::get_singleton()->particles_collision_set_sphere_radius(_get_collision(), radius);
- update_gizmo();
+ update_gizmos();
}
float GPUParticlesAttractorSphere::get_radius() const {
@@ -838,7 +836,7 @@ void GPUParticlesAttractorBox::_bind_methods() {
void GPUParticlesAttractorBox::set_extents(const Vector3 &p_extents) {
extents = p_extents;
RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
- update_gizmo();
+ update_gizmos();
}
Vector3 GPUParticlesAttractorBox::get_extents() const {
@@ -872,7 +870,7 @@ void GPUParticlesAttractorVectorField::_bind_methods() {
void GPUParticlesAttractorVectorField::set_extents(const Vector3 &p_extents) {
extents = p_extents;
RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
- update_gizmo();
+ update_gizmos();
}
Vector3 GPUParticlesAttractorVectorField::get_extents() const {
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp
index 8478821ba1..c2943a9606 100644
--- a/scene/3d/light_3d.cpp
+++ b/scene/3d/light_3d.cpp
@@ -45,7 +45,7 @@ void Light3D::set_param(Param p_param, float p_value) {
RS::get_singleton()->light_set_param(light, RS::LightParam(p_param), p_value);
if (p_param == PARAM_SPOT_ANGLE || p_param == PARAM_RANGE) {
- update_gizmo();
+ update_gizmos();
if (p_param == PARAM_SPOT_ANGLE) {
update_configuration_warnings();
@@ -95,7 +95,7 @@ void Light3D::set_color(const Color &p_color) {
color = p_color;
RS::get_singleton()->light_set_color(light, p_color);
// The gizmo color depends on the light color, so update it.
- update_gizmo();
+ update_gizmos();
}
Color Light3D::get_color() const {
diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp
index 66e3535fc4..0085c8933d 100644
--- a/scene/3d/lightmap_gi.cpp
+++ b/scene/3d/lightmap_gi.cpp
@@ -599,7 +599,7 @@ void LightmapGI::_gen_new_positions_from_octree(const GenProbesOctree *p_cell, f
const Vector3 *pp = probe_positions.ptr();
bool exists = false;
for (int j = 0; j < ppcount; j++) {
- if (pp[j].distance_to(real_pos) < CMP_EPSILON) {
+ if (pp[j].is_equal_approx(real_pos)) {
exists = true;
break;
}
@@ -1250,7 +1250,7 @@ void LightmapGI::set_light_data(const Ref<LightmapGIData> &p_data) {
}
}
- update_gizmo();
+ update_gizmos();
}
Ref<LightmapGIData> LightmapGI::get_light_data() const {
diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp
index 279a1fb7de..9ca1d55d0b 100644
--- a/scene/3d/mesh_instance_3d.cpp
+++ b/scene/3d/mesh_instance_3d.cpp
@@ -94,8 +94,8 @@ void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const {
ls.sort();
- for (List<String>::Element *E = ls.front(); E; E = E->next()) {
- p_list->push_back(PropertyInfo(Variant::FLOAT, E->get(), PROPERTY_HINT_RANGE, "-1,1,0.00001"));
+ for (const String &E : ls) {
+ p_list->push_back(PropertyInfo(Variant::FLOAT, E, PROPERTY_HINT_RANGE, "-1,1,0.00001"));
}
if (mesh.is_valid()) {
@@ -133,7 +133,7 @@ void MeshInstance3D::set_mesh(const Ref<Mesh> &p_mesh) {
set_base(RID());
}
- update_gizmo();
+ update_gizmos();
notify_property_list_changed();
}
@@ -241,12 +241,12 @@ void MeshInstance3D::create_trimesh_collision() {
}
}
-Node *MeshInstance3D::create_convex_collision_node() {
+Node *MeshInstance3D::create_convex_collision_node(bool p_clean, bool p_simplify) {
if (mesh.is_null()) {
return nullptr;
}
- Ref<Shape3D> shape = mesh->create_convex_shape();
+ Ref<Shape3D> shape = mesh->create_convex_shape(p_clean, p_simplify);
if (shape.is_null()) {
return nullptr;
}
@@ -258,8 +258,8 @@ Node *MeshInstance3D::create_convex_collision_node() {
return static_body;
}
-void MeshInstance3D::create_convex_collision() {
- StaticBody3D *static_body = Object::cast_to<StaticBody3D>(create_convex_collision_node());
+void MeshInstance3D::create_convex_collision(bool p_clean, bool p_simplify) {
+ StaticBody3D *static_body = Object::cast_to<StaticBody3D>(create_convex_collision_node(p_clean, p_simplify));
ERR_FAIL_COND(!static_body);
static_body->set_name(String(get_name()) + "_col");
@@ -356,7 +356,7 @@ Ref<Material> MeshInstance3D::get_active_material(int p_surface) const {
void MeshInstance3D::_mesh_changed() {
ERR_FAIL_COND(mesh.is_null());
surface_override_materials.resize(mesh->get_surface_count());
- update_gizmo();
+ update_gizmos();
}
void MeshInstance3D::create_debug_tangents() {
@@ -451,7 +451,7 @@ void MeshInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance3D::create_trimesh_collision);
ClassDB::set_method_flags("MeshInstance3D", "create_trimesh_collision", METHOD_FLAGS_DEFAULT);
- ClassDB::bind_method(D_METHOD("create_convex_collision"), &MeshInstance3D::create_convex_collision);
+ ClassDB::bind_method(D_METHOD("create_convex_collision", "clean", "simplify"), &MeshInstance3D::create_convex_collision, DEFVAL(true), DEFVAL(false));
ClassDB::set_method_flags("MeshInstance3D", "create_convex_collision", METHOD_FLAGS_DEFAULT);
ClassDB::bind_method(D_METHOD("create_multiple_convex_collisions"), &MeshInstance3D::create_multiple_convex_collisions);
ClassDB::set_method_flags("MeshInstance3D", "create_multiple_convex_collisions", METHOD_FLAGS_DEFAULT);
diff --git a/scene/3d/mesh_instance_3d.h b/scene/3d/mesh_instance_3d.h
index 9dea5804e0..e2d20d0a90 100644
--- a/scene/3d/mesh_instance_3d.h
+++ b/scene/3d/mesh_instance_3d.h
@@ -83,8 +83,8 @@ public:
Node *create_trimesh_collision_node();
void create_trimesh_collision();
- Node *create_convex_collision_node();
- void create_convex_collision();
+ Node *create_convex_collision_node(bool p_clean = true, bool p_simplify = false);
+ void create_convex_collision(bool p_clean = true, bool p_simplify = false);
Node *create_multiple_convex_collisions_node();
void create_multiple_convex_collisions();
diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp
index 64cfe4dca7..f890ceeb95 100644
--- a/scene/3d/navigation_agent_3d.cpp
+++ b/scene/3d/navigation_agent_3d.cpp
@@ -242,7 +242,7 @@ void NavigationAgent3D::_avoidance_done(Vector3 p_new_velocity) {
}
velocity_submitted = false;
- emit_signal("velocity_computed", p_new_velocity);
+ emit_signal(SNAME("velocity_computed"), p_new_velocity);
}
TypedArray<String> NavigationAgent3D::get_configuration_warnings() const {
@@ -296,7 +296,7 @@ void NavigationAgent3D::update_navigation() {
navigation_path = NavigationServer3D::get_singleton()->map_get_path(agent_parent->get_world_3d()->get_navigation_map(), o, target_location, true);
navigation_finished = false;
nav_path_index = 0;
- emit_signal("path_changed");
+ emit_signal(SNAME("path_changed"));
}
if (navigation_path.size() == 0) {
@@ -312,7 +312,7 @@ void NavigationAgent3D::update_navigation() {
_check_distance_to_target();
nav_path_index -= 1;
navigation_finished = true;
- emit_signal("navigation_finished");
+ emit_signal(SNAME("navigation_finished"));
break;
}
}
@@ -322,7 +322,7 @@ void NavigationAgent3D::update_navigation() {
void NavigationAgent3D::_check_distance_to_target() {
if (!target_reached) {
if (distance_to_target() < target_desired_distance) {
- emit_signal("target_reached");
+ emit_signal(SNAME("target_reached"));
target_reached = true;
}
}
diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp
index 0afad62404..2976dad39d 100644
--- a/scene/3d/navigation_region_3d.cpp
+++ b/scene/3d/navigation_region_3d.cpp
@@ -59,7 +59,7 @@ void NavigationRegion3D::set_enabled(bool p_enabled) {
}
}
- update_gizmo();
+ update_gizmos();
}
bool NavigationRegion3D::is_enabled() const {
@@ -132,9 +132,9 @@ void NavigationRegion3D::set_navigation_mesh(const Ref<NavigationMesh> &p_navmes
Object::cast_to<MeshInstance3D>(debug_view)->set_mesh(navmesh->get_debug_mesh());
}
- emit_signal("navigation_mesh_changed");
+ emit_signal(SNAME("navigation_mesh_changed"));
- update_gizmo();
+ update_gizmos();
update_configuration_warnings();
}
@@ -153,11 +153,11 @@ void _bake_navigation_mesh(void *p_user_data) {
Ref<NavigationMesh> nav_mesh = args->nav_region->get_navigation_mesh()->duplicate();
NavigationServer3D::get_singleton()->region_bake_navmesh(nav_mesh, args->nav_region);
- args->nav_region->call_deferred("_bake_finished", nav_mesh);
+ args->nav_region->call_deferred(SNAME("_bake_finished"), nav_mesh);
memdelete(args);
} else {
ERR_PRINT("Can't bake the navigation mesh if the `NavigationMesh` resource doesn't exist");
- args->nav_region->call_deferred("_bake_finished", Ref<NavigationMesh>());
+ args->nav_region->call_deferred(SNAME("_bake_finished"), Ref<NavigationMesh>());
memdelete(args);
}
}
@@ -174,7 +174,7 @@ void NavigationRegion3D::bake_navigation_mesh() {
void NavigationRegion3D::_bake_finished(Ref<NavigationMesh> p_nav_mesh) {
set_navigation_mesh(p_nav_mesh);
bake_thread.wait_to_finish();
- emit_signal("bake_finished");
+ emit_signal(SNAME("bake_finished"));
}
TypedArray<String> NavigationRegion3D::get_configuration_warnings() const {
@@ -211,7 +211,7 @@ void NavigationRegion3D::_bind_methods() {
}
void NavigationRegion3D::_navigation_changed() {
- update_gizmo();
+ update_gizmos();
update_configuration_warnings();
}
diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp
index d6c6ec75b4..0daee69ee5 100644
--- a/scene/3d/node_3d.cpp
+++ b/scene/3d/node_3d.cpp
@@ -76,7 +76,7 @@ Node3DGizmo::Node3DGizmo() {
void Node3D::_notify_dirty() {
#ifdef TOOLS_ENABLED
- if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
+ if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
#else
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
@@ -103,14 +103,14 @@ void Node3D::_propagate_transform_changed(Node3D *p_origin) {
data.children_lock++;
- for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) {
- if (E->get()->data.top_level_active) {
+ for (Node3D *&E : data.children) {
+ if (E->data.top_level_active) {
continue; //don't propagate to a top_level
}
- E->get()->_propagate_transform_changed(p_origin);
+ E->_propagate_transform_changed(p_origin);
}
#ifdef TOOLS_ENABLED
- if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
+ if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
#else
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
#endif
@@ -181,15 +181,14 @@ void Node3D::_notification(int p_what) {
}
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
- //get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,SceneStringNames::get_singleton()->_spatial_editor_group,SceneStringNames::get_singleton()->_request_gizmo,this);
get_tree()->call_group_flags(0, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
- if (!data.gizmo_disabled) {
- if (data.gizmo.is_valid()) {
- data.gizmo->create();
+ if (!data.gizmos_disabled) {
+ for (int i = 0; i < data.gizmos.size(); i++) {
+ data.gizmos.write[i]->create();
if (is_visible_in_tree()) {
- data.gizmo->redraw();
+ data.gizmos.write[i]->redraw();
}
- data.gizmo->transform();
+ data.gizmos.write[i]->transform();
}
}
}
@@ -198,10 +197,7 @@ void Node3D::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_WORLD: {
#ifdef TOOLS_ENABLED
- if (data.gizmo.is_valid()) {
- data.gizmo->free();
- data.gizmo.unref();
- }
+ clear_gizmos();
#endif
if (get_script_instance()) {
@@ -215,8 +211,8 @@ void Node3D::_notification(int p_what) {
case NOTIFICATION_TRANSFORM_CHANGED: {
#ifdef TOOLS_ENABLED
- if (data.gizmo.is_valid()) {
- data.gizmo->transform();
+ for (int i = 0; i < data.gizmos.size(); i++) {
+ data.gizmos.write[i]->transform();
}
#endif
} break;
@@ -368,80 +364,119 @@ Vector3 Node3D::get_scale() const {
return data.scale;
}
-void Node3D::update_gizmo() {
+void Node3D::update_gizmos() {
#ifdef TOOLS_ENABLED
if (!is_inside_world()) {
return;
}
- if (!data.gizmo.is_valid()) {
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
+
+ if (data.gizmos.is_empty()) {
+ return;
}
- if (!data.gizmo.is_valid()) {
+ data.gizmos_dirty = true;
+ MessageQueue::get_singleton()->push_callable(callable_mp(this, &Node3D::_update_gizmos));
+#endif
+}
+
+void Node3D::clear_subgizmo_selection() {
+#ifdef TOOLS_ENABLED
+ if (!is_inside_world()) {
return;
}
- if (data.gizmo_dirty) {
+
+ if (data.gizmos.is_empty()) {
return;
}
- data.gizmo_dirty = true;
- MessageQueue::get_singleton()->push_call(this, "_update_gizmo");
+
+ if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
+ get_tree()->call_group_flags(0, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_clear_subgizmo_selection, this);
+ }
#endif
}
-void Node3D::set_gizmo(const Ref<Node3DGizmo> &p_gizmo) {
+void Node3D::add_gizmo(Ref<Node3DGizmo> p_gizmo) {
#ifdef TOOLS_ENABLED
- if (data.gizmo_disabled) {
+ if (data.gizmos_disabled || p_gizmo.is_null()) {
return;
}
- if (data.gizmo.is_valid() && is_inside_world()) {
- data.gizmo->free();
- }
- data.gizmo = p_gizmo;
- if (data.gizmo.is_valid() && is_inside_world()) {
- data.gizmo->create();
+ data.gizmos.push_back(p_gizmo);
+
+ if (p_gizmo.is_valid() && is_inside_world()) {
+ p_gizmo->create();
if (is_visible_in_tree()) {
- data.gizmo->redraw();
+ p_gizmo->redraw();
}
- data.gizmo->transform();
+ p_gizmo->transform();
}
+#endif
+}
+
+void Node3D::remove_gizmo(Ref<Node3DGizmo> p_gizmo) {
+#ifdef TOOLS_ENABLED
+ int idx = data.gizmos.find(p_gizmo);
+ if (idx != -1) {
+ p_gizmo->free();
+ data.gizmos.remove(idx);
+ }
+#endif
+}
+
+void Node3D::clear_gizmos() {
+#ifdef TOOLS_ENABLED
+ for (int i = 0; i < data.gizmos.size(); i++) {
+ data.gizmos.write[i]->free();
+ }
+ data.gizmos.clear();
+#endif
+}
+
+Array Node3D::get_gizmos_bind() const {
+ Array ret;
+
+#ifdef TOOLS_ENABLED
+ for (int i = 0; i < data.gizmos.size(); i++) {
+ ret.push_back(Variant(data.gizmos[i].ptr()));
+ }
#endif
+
+ return ret;
}
-Ref<Node3DGizmo> Node3D::get_gizmo() const {
+Vector<Ref<Node3DGizmo>> Node3D::get_gizmos() const {
#ifdef TOOLS_ENABLED
- return data.gizmo;
+ return data.gizmos;
#else
- return Ref<Node3DGizmo>();
+ return Vector<Ref<Node3DGizmo>>();
#endif
}
-void Node3D::_update_gizmo() {
+void Node3D::_update_gizmos() {
#ifdef TOOLS_ENABLED
- if (!is_inside_world()) {
+ if (data.gizmos_disabled || !is_inside_world() || !data.gizmos_dirty) {
return;
}
- data.gizmo_dirty = false;
- if (data.gizmo.is_valid()) {
+ data.gizmos_dirty = false;
+ for (int i = 0; i < data.gizmos.size(); i++) {
if (is_visible_in_tree()) {
- data.gizmo->redraw();
+ data.gizmos.write[i]->redraw();
} else {
- data.gizmo->clear();
+ data.gizmos.write[i]->clear();
}
}
#endif
}
#ifdef TOOLS_ENABLED
-void Node3D::set_disable_gizmo(bool p_enabled) {
- data.gizmo_disabled = p_enabled;
- if (!p_enabled && data.gizmo.is_valid()) {
- data.gizmo = Ref<Node3DGizmo>();
+void Node3D::set_disable_gizmos(bool p_enabled) {
+ data.gizmos_disabled = p_enabled;
+ if (!p_enabled) {
+ clear_gizmos();
}
}
-
#endif
void Node3D::set_disable_scale(bool p_enabled) {
@@ -486,13 +521,13 @@ void Node3D::_propagate_visibility_changed() {
notification(NOTIFICATION_VISIBILITY_CHANGED);
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
#ifdef TOOLS_ENABLED
- if (data.gizmo.is_valid()) {
- _update_gizmo();
+ if (!data.gizmos.is_empty()) {
+ data.gizmos_dirty = true;
+ _update_gizmos();
}
#endif
- for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) {
- Node3D *c = E->get();
+ for (Node3D *c : data.children) {
if (!c || !c->data.visible) {
continue;
}
@@ -717,8 +752,7 @@ void Node3D::_update_visibility_parent(bool p_update_root) {
RS::get_singleton()->instance_set_visibility_parent(vi->get_instance(), data.visibility_parent);
}
- for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) {
- Node3D *c = E->get();
+ for (Node3D *c : data.children) {
c->_update_visibility_parent(false);
}
}
@@ -758,11 +792,11 @@ void Node3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_visibility_parent", "path"), &Node3D::set_visibility_parent);
ClassDB::bind_method(D_METHOD("get_visibility_parent"), &Node3D::get_visibility_parent);
- ClassDB::bind_method(D_METHOD("_update_gizmo"), &Node3D::_update_gizmo);
-
- ClassDB::bind_method(D_METHOD("update_gizmo"), &Node3D::update_gizmo);
- ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo"), &Node3D::set_gizmo);
- ClassDB::bind_method(D_METHOD("get_gizmo"), &Node3D::get_gizmo);
+ ClassDB::bind_method(D_METHOD("update_gizmos"), &Node3D::update_gizmos);
+ ClassDB::bind_method(D_METHOD("add_gizmo", "gizmo"), &Node3D::add_gizmo);
+ ClassDB::bind_method(D_METHOD("get_gizmos"), &Node3D::get_gizmos_bind);
+ ClassDB::bind_method(D_METHOD("clear_gizmos"), &Node3D::clear_gizmos);
+ ClassDB::bind_method(D_METHOD("clear_subgizmo_selection"), &Node3D::clear_subgizmo_selection);
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Node3D::set_visible);
ClassDB::bind_method(D_METHOD("is_visible"), &Node3D::is_visible);
@@ -813,7 +847,6 @@ void Node3D::_bind_methods() {
ADD_GROUP("Visibility", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "visibility_parent", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GeometryInstance3D"), "set_visibility_parent", "get_visibility_parent");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "Node3DGizmo", PROPERTY_USAGE_NONE), "set_gizmo", "get_gizmo");
ADD_SIGNAL(MethodInfo("visibility_changed"));
}
diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h
index fe6324c796..282f4805cc 100644
--- a/scene/3d/node_3d.h
+++ b/scene/3d/node_3d.h
@@ -90,16 +90,16 @@ class Node3D : public Node {
bool disable_scale = false;
#ifdef TOOLS_ENABLED
- Ref<Node3DGizmo> gizmo;
- bool gizmo_disabled = false;
- bool gizmo_dirty = false;
+ Vector<Ref<Node3DGizmo>> gizmos;
+ bool gizmos_disabled = false;
+ bool gizmos_dirty = false;
#endif
} data;
NodePath visibility_parent_path;
- void _update_gizmo();
+ void _update_gizmos();
void _notify_dirty();
void _propagate_transform_changed(Node3D *p_origin);
@@ -154,10 +154,14 @@ public:
void set_disable_scale(bool p_enabled);
bool is_scale_disabled() const;
- void set_disable_gizmo(bool p_enabled);
- void update_gizmo();
- void set_gizmo(const Ref<Node3DGizmo> &p_gizmo);
- Ref<Node3DGizmo> get_gizmo() const;
+ void set_disable_gizmos(bool p_enabled);
+ void update_gizmos();
+ void clear_subgizmo_selection();
+ Vector<Ref<Node3DGizmo>> get_gizmos() const;
+ Array get_gizmos_bind() const;
+ void add_gizmo(Ref<Node3DGizmo> p_gizmo);
+ void remove_gizmo(Ref<Node3DGizmo> p_gizmo);
+ void clear_gizmos();
_FORCE_INLINE_ bool is_inside_world() const { return data.inside_world; }
diff --git a/scene/3d/occluder_instance_3d.cpp b/scene/3d/occluder_instance_3d.cpp
index 7b736e689c..3d1a27911b 100644
--- a/scene/3d/occluder_instance_3d.cpp
+++ b/scene/3d/occluder_instance_3d.cpp
@@ -173,12 +173,12 @@ void OccluderInstance3D::set_occluder(const Ref<Occluder3D> &p_occluder) {
set_base(RID());
}
- update_gizmo();
+ update_gizmos();
update_configuration_warnings();
}
void OccluderInstance3D::_occluder_changed() {
- update_gizmo();
+ update_gizmos();
update_configuration_warnings();
}
diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp
index de115b35e3..6af2e7f879 100644
--- a/scene/3d/path_3d.cpp
+++ b/scene/3d/path_3d.cpp
@@ -38,10 +38,10 @@ void Path3D::_notification(int p_what) {
void Path3D::_curve_changed() {
if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
- update_gizmo();
+ update_gizmos();
}
if (is_inside_tree()) {
- emit_signal("curve_changed");
+ emit_signal(SNAME("curve_changed"));
}
// update the configuration warnings of all children of type PathFollow
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index e7482d35e7..93ecb2cd3a 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -78,8 +78,7 @@ TypedArray<PhysicsBody3D> PhysicsBody3D::get_collision_exceptions() {
List<RID> exceptions;
PhysicsServer3D::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions);
Array ret;
- for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) {
- RID body = E->get();
+ for (const RID &body : exceptions) {
ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body);
Object *obj = ObjectDB::get_instance(instance_id);
PhysicsBody3D *physics_body = Object::cast_to<PhysicsBody3D>(obj);
@@ -125,11 +124,11 @@ bool PhysicsBody3D::move_and_collide(const Vector3 &p_motion, bool p_infinite_in
// Restore direction of motion to be along original motion,
// in order to avoid sliding due to recovery,
// but only if collision depth is low enough to avoid tunneling.
- real_t motion_length = p_motion.length();
- if (motion_length > CMP_EPSILON) {
- real_t precision = CMP_EPSILON;
+ if (p_cancel_sliding) {
+ real_t motion_length = p_motion.length();
+ real_t precision = 0.001;
- if (colliding && p_cancel_sliding) {
+ if (colliding) {
// Can't just use margin as a threshold because collision depth is calculated on unsafe motion,
// so even in normal resting cases the depth can be a bit more than the margin.
precision += motion_length * (r_result.collision_unsafe_fraction - r_result.collision_safe_fraction);
@@ -140,16 +139,21 @@ bool PhysicsBody3D::move_and_collide(const Vector3 &p_motion, bool p_infinite_in
}
if (p_cancel_sliding) {
+ // When motion is null, recovery is the resulting motion.
+ Vector3 motion_normal;
+ if (motion_length > CMP_EPSILON) {
+ motion_normal = p_motion / motion_length;
+ }
+
// Check depth of recovery.
- Vector3 motion_normal = p_motion / motion_length;
- real_t dot = r_result.motion.dot(motion_normal);
- Vector3 recovery = r_result.motion - motion_normal * dot;
+ real_t projected_length = r_result.motion.dot(motion_normal);
+ Vector3 recovery = r_result.motion - motion_normal * projected_length;
real_t recovery_length = recovery.length();
// Fixes cases where canceling slide causes the motion to go too deep into the ground,
- // Becauses we're only taking rest information into account and not general recovery.
+ // because we're only taking rest information into account and not general recovery.
if (recovery_length < (real_t)p_margin + precision) {
// Apply adjustment to motion.
- r_result.motion = motion_normal * dot;
+ r_result.motion = motion_normal * projected_length;
r_result.remainder = p_motion - r_result.motion;
}
}
@@ -238,6 +242,13 @@ void StaticBody3D::set_kinematic_motion_enabled(bool p_enabled) {
set_body_mode(PhysicsServer3D::BODY_MODE_STATIC);
}
+#ifdef TOOLS_ENABLED
+ if (Engine::get_singleton()->is_editor_hint()) {
+ update_configuration_warnings();
+ return;
+ }
+#endif
+
_update_kinematic_motion();
}
@@ -255,6 +266,57 @@ void StaticBody3D::set_constant_linear_velocity(const Vector3 &p_vel) {
}
}
+void StaticBody3D::set_sync_to_physics(bool p_enable) {
+ if (sync_to_physics == p_enable) {
+ return;
+ }
+
+ sync_to_physics = p_enable;
+
+#ifdef TOOLS_ENABLED
+ if (Engine::get_singleton()->is_editor_hint()) {
+ update_configuration_warnings();
+ return;
+ }
+#endif
+
+ if (kinematic_motion) {
+ _update_kinematic_motion();
+ }
+}
+
+bool StaticBody3D::is_sync_to_physics_enabled() const {
+ return sync_to_physics;
+}
+
+void StaticBody3D::_direct_state_changed(Object *p_state) {
+ PhysicsDirectBodyState3D *state = Object::cast_to<PhysicsDirectBodyState3D>(p_state);
+ ERR_FAIL_NULL_MSG(state, "Method '_direct_state_changed' must receive a valid PhysicsDirectBodyState3D object as argument");
+
+ linear_velocity = state->get_linear_velocity();
+ angular_velocity = state->get_angular_velocity();
+
+ if (!sync_to_physics) {
+ return;
+ }
+
+ last_valid_transform = state->get_transform();
+ set_notify_local_transform(false);
+ set_global_transform(last_valid_transform);
+ set_notify_local_transform(true);
+ _on_transform_changed();
+}
+
+TypedArray<String> StaticBody3D::get_configuration_warnings() const {
+ TypedArray<String> warnings = PhysicsBody3D::get_configuration_warnings();
+
+ if (sync_to_physics && !kinematic_motion) {
+ warnings.push_back(TTR("Sync to physics works only when kinematic motion is enabled."));
+ }
+
+ return warnings;
+}
+
void StaticBody3D::set_constant_angular_velocity(const Vector3 &p_vel) {
constant_angular_velocity = p_vel;
@@ -283,6 +345,34 @@ Vector3 StaticBody3D::get_angular_velocity() const {
void StaticBody3D::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ last_valid_transform = get_global_transform();
+ } break;
+
+ case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
+ // Used by sync to physics, send the new transform to the physics...
+ Transform3D new_transform = get_global_transform();
+
+ real_t delta_time = get_physics_process_delta_time();
+ new_transform.origin += constant_linear_velocity * delta_time;
+
+ real_t ang_vel = constant_angular_velocity.length();
+ if (!Math::is_zero_approx(ang_vel)) {
+ Vector3 ang_vel_axis = constant_angular_velocity / ang_vel;
+ Basis rot(ang_vel_axis, ang_vel * delta_time);
+ new_transform.basis = rot * new_transform.basis;
+ new_transform.orthonormalize();
+ }
+
+ PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_TRANSFORM, new_transform);
+
+ // ... but then revert changes.
+ set_notify_local_transform(false);
+ set_global_transform(last_valid_transform);
+ set_notify_local_transform(true);
+ _on_transform_changed();
+ } break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
@@ -292,9 +382,9 @@ void StaticBody3D::_notification(int p_what) {
ERR_FAIL_COND(!kinematic_motion);
- real_t delta_time = get_physics_process_delta_time();
-
Transform3D new_transform = get_global_transform();
+
+ real_t delta_time = get_physics_process_delta_time();
new_transform.origin += constant_linear_velocity * delta_time;
real_t ang_vel = constant_angular_velocity.length();
@@ -305,13 +395,18 @@ void StaticBody3D::_notification(int p_what) {
new_transform.orthonormalize();
}
- PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_TRANSFORM, new_transform);
+ if (sync_to_physics) {
+ // Propagate transform change to node.
+ set_global_transform(new_transform);
+ } else {
+ PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_TRANSFORM, new_transform);
- // Propagate transform change to node.
- set_ignore_transform_notification(true);
- set_global_transform(new_transform);
- set_ignore_transform_notification(false);
- _on_transform_changed();
+ // Propagate transform change to node.
+ set_ignore_transform_notification(true);
+ set_global_transform(new_transform);
+ set_ignore_transform_notification(false);
+ _on_transform_changed();
+ }
} break;
}
}
@@ -328,22 +423,14 @@ void StaticBody3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &StaticBody3D::set_physics_material_override);
ClassDB::bind_method(D_METHOD("get_physics_material_override"), &StaticBody3D::get_physics_material_override);
+ ClassDB::bind_method(D_METHOD("set_sync_to_physics", "enable"), &StaticBody3D::set_sync_to_physics);
+ ClassDB::bind_method(D_METHOD("is_sync_to_physics_enabled"), &StaticBody3D::is_sync_to_physics_enabled);
+
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "physics_material_override", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), "set_physics_material_override", "get_physics_material_override");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_linear_velocity"), "set_constant_linear_velocity", "get_constant_linear_velocity");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_angular_velocity"), "set_constant_angular_velocity", "get_constant_angular_velocity");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "kinematic_motion"), "set_kinematic_motion_enabled", "is_kinematic_motion_enabled");
-}
-
-void StaticBody3D::_direct_state_changed(Object *p_state) {
-#ifdef DEBUG_ENABLED
- PhysicsDirectBodyState3D *state = Object::cast_to<PhysicsDirectBodyState3D>(p_state);
- ERR_FAIL_NULL_MSG(state, "Method '_direct_state_changed' must receive a valid PhysicsDirectBodyState3D object as argument");
-#else
- PhysicsDirectBodyState3D *state = (PhysicsDirectBodyState3D *)p_state; //trust it
-#endif
-
- linear_velocity = state->get_linear_velocity();
- angular_velocity = state->get_angular_velocity();
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync_to_physics"), "set_sync_to_physics", "is_sync_to_physics_enabled");
}
StaticBody3D::StaticBody3D() :
@@ -367,18 +454,26 @@ void StaticBody3D::_update_kinematic_motion() {
}
#endif
+ if (kinematic_motion && sync_to_physics) {
+ set_only_update_transform_changes(true);
+ set_notify_local_transform(true);
+ } else {
+ set_only_update_transform_changes(false);
+ set_notify_local_transform(false);
+ }
+
+ bool needs_physics_process = false;
if (kinematic_motion) {
PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), callable_mp(this, &StaticBody3D::_direct_state_changed));
if (!constant_angular_velocity.is_equal_approx(Vector3()) || !constant_linear_velocity.is_equal_approx(Vector3())) {
- set_physics_process_internal(true);
- return;
+ needs_physics_process = true;
}
} else {
PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), Callable());
}
- set_physics_process_internal(false);
+ set_physics_process_internal(needs_physics_process);
}
void RigidBody3D::_body_enter_tree(ObjectID p_id) {
@@ -1001,6 +1096,15 @@ void CharacterBody3D::move_and_slide() {
}
}
+ Vector3 current_floor_velocity = floor_velocity;
+ if (on_floor && on_floor_body.is_valid()) {
+ //this approach makes sure there is less delay between the actual body velocity and the one we saved
+ PhysicsDirectBodyState3D *bs = PhysicsServer3D::get_singleton()->body_get_direct_state(on_floor_body);
+ if (bs) {
+ current_floor_velocity = bs->get_linear_velocity();
+ }
+ }
+
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
Vector3 motion = (floor_velocity + linear_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
@@ -1012,8 +1116,9 @@ void CharacterBody3D::move_and_slide() {
floor_normal = Vector3();
floor_velocity = Vector3();
- // No sliding on first attempt to keep motion stable when possible.
- bool sliding_enabled = false;
+ // No sliding on first attempt to keep floor motion stable when possible,
+ // when stop on slope is enabled.
+ bool sliding_enabled = !stop_on_slope;
for (int iteration = 0; iteration < max_slides; ++iteration) {
PhysicsServer3D::MotionResult result;
bool found_collision = false;
@@ -1052,7 +1157,11 @@ void CharacterBody3D::move_and_slide() {
if (stop_on_slope) {
if ((body_velocity_normal + up_direction).length() < 0.01) {
Transform3D gt = get_global_transform();
- gt.origin -= result.motion.slide(up_direction);
+ if (result.motion.length() > margin) {
+ gt.origin -= result.motion.slide(up_direction);
+ } else {
+ gt.origin -= result.motion;
+ }
set_global_transform(gt);
linear_velocity = Vector3();
return;
@@ -1094,7 +1203,7 @@ void CharacterBody3D::move_and_slide() {
// Apply snap.
Transform3D gt = get_global_transform();
PhysicsServer3D::MotionResult result;
- if (move_and_collide(snap, infinite_inertia, result, margin, false, true)) {
+ if (move_and_collide(snap, infinite_inertia, result, margin, false, true, false)) {
bool apply = true;
if (up_direction != Vector3()) {
if (Math::acos(result.collision_normal.dot(up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) {
@@ -1105,7 +1214,11 @@ void CharacterBody3D::move_and_slide() {
if (stop_on_slope) {
// move and collide may stray the object a bit because of pre un-stucking,
// so only ensure that motion happens on floor direction in this case.
- result.motion = result.motion.project(up_direction);
+ if (result.motion.length() > margin) {
+ result.motion = result.motion.project(up_direction);
+ } else {
+ result.motion = Vector3();
+ }
}
} else {
apply = false; //snapped with floor direction, but did not snap to a floor, do not snap.
@@ -2067,9 +2180,7 @@ bool PhysicalBone3D::_set(const StringName &p_name, const Variant &p_value) {
if (joint_data) {
if (joint_data->_set(p_name, p_value, joint)) {
#ifdef TOOLS_ENABLED
- if (get_gizmo().is_valid()) {
- get_gizmo()->redraw();
- }
+ update_gizmos();
#endif
return true;
}
@@ -2257,9 +2368,7 @@ void PhysicalBone3D::_update_joint_offset() {
set_ignore_transform_notification(false);
#ifdef TOOLS_ENABLED
- if (get_gizmo().is_valid()) {
- get_gizmo()->redraw();
- }
+ update_gizmos();
#endif
}
@@ -2426,9 +2535,7 @@ void PhysicalBone3D::set_joint_type(JointType p_joint_type) {
#ifdef TOOLS_ENABLED
notify_property_list_changed();
- if (get_gizmo().is_valid()) {
- get_gizmo()->redraw();
- }
+ update_gizmos();
#endif
}
diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h
index 9d45ce3799..0ef9c78f3b 100644
--- a/scene/3d/physics_body_3d.h
+++ b/scene/3d/physics_body_3d.h
@@ -82,13 +82,16 @@ class StaticBody3D : public PhysicsBody3D {
Ref<PhysicsMaterial> physics_material_override;
bool kinematic_motion = false;
+ bool sync_to_physics = false;
+
+ Transform3D last_valid_transform;
+
+ void _direct_state_changed(Object *p_state);
protected:
void _notification(int p_what);
static void _bind_methods();
- void _direct_state_changed(Object *p_state);
-
public:
void set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override);
Ref<PhysicsMaterial> get_physics_material_override() const;
@@ -102,6 +105,8 @@ public:
virtual Vector3 get_linear_velocity() const override;
virtual Vector3 get_angular_velocity() const override;
+ virtual TypedArray<String> get_configuration_warnings() const override;
+
StaticBody3D();
private:
@@ -111,6 +116,9 @@ private:
void set_kinematic_motion_enabled(bool p_enabled);
bool is_kinematic_motion_enabled() const;
+
+ void set_sync_to_physics(bool p_enable);
+ bool is_sync_to_physics_enabled() const;
};
class RigidBody3D : public PhysicsBody3D {
@@ -251,7 +259,7 @@ public:
void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
void apply_torque_impulse(const Vector3 &p_impulse);
- TypedArray<String> get_configuration_warnings() const override;
+ virtual TypedArray<String> get_configuration_warnings() const override;
RigidBody3D();
~RigidBody3D();
diff --git a/scene/3d/physics_joint_3d.cpp b/scene/3d/physics_joint_3d.cpp
index 01f10c171f..59440bd1a8 100644
--- a/scene/3d/physics_joint_3d.cpp
+++ b/scene/3d/physics_joint_3d.cpp
@@ -348,7 +348,7 @@ void HingeJoint3D::set_param(Param p_param, real_t p_value) {
PhysicsServer3D::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer3D::HingeJointParam(p_param), p_value);
}
- update_gizmo();
+ update_gizmos();
}
real_t HingeJoint3D::get_param(Param p_param) const {
@@ -363,7 +363,7 @@ void HingeJoint3D::set_flag(Flag p_flag, bool p_value) {
PhysicsServer3D::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer3D::HingeJointFlag(p_flag), p_value);
}
- update_gizmo();
+ update_gizmos();
}
bool HingeJoint3D::get_flag(Flag p_flag) const {
@@ -497,7 +497,7 @@ void SliderJoint3D::set_param(Param p_param, real_t p_value) {
if (is_configured()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer3D::SliderJointParam(p_param), p_value);
}
- update_gizmo();
+ update_gizmos();
}
real_t SliderJoint3D::get_param(Param p_param) const {
@@ -602,7 +602,7 @@ void ConeTwistJoint3D::set_param(Param p_param, real_t p_value) {
PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer3D::ConeTwistJointParam(p_param), p_value);
}
- update_gizmo();
+ update_gizmos();
}
real_t ConeTwistJoint3D::get_param(Param p_param) const {
@@ -857,7 +857,7 @@ void Generic6DOFJoint3D::set_param_x(Param p_param, real_t p_value) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
}
- update_gizmo();
+ update_gizmos();
}
real_t Generic6DOFJoint3D::get_param_x(Param p_param) const {
@@ -871,7 +871,7 @@ void Generic6DOFJoint3D::set_param_y(Param p_param, real_t p_value) {
if (is_configured()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
}
- update_gizmo();
+ update_gizmos();
}
real_t Generic6DOFJoint3D::get_param_y(Param p_param) const {
@@ -885,7 +885,7 @@ void Generic6DOFJoint3D::set_param_z(Param p_param, real_t p_value) {
if (is_configured()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
}
- update_gizmo();
+ update_gizmos();
}
real_t Generic6DOFJoint3D::get_param_z(Param p_param) const {
@@ -899,7 +899,7 @@ void Generic6DOFJoint3D::set_flag_x(Flag p_flag, bool p_enabled) {
if (is_configured()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
}
- update_gizmo();
+ update_gizmos();
}
bool Generic6DOFJoint3D::get_flag_x(Flag p_flag) const {
@@ -913,7 +913,7 @@ void Generic6DOFJoint3D::set_flag_y(Flag p_flag, bool p_enabled) {
if (is_configured()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
}
- update_gizmo();
+ update_gizmos();
}
bool Generic6DOFJoint3D::get_flag_y(Flag p_flag) const {
@@ -927,7 +927,7 @@ void Generic6DOFJoint3D::set_flag_z(Flag p_flag, bool p_enabled) {
if (is_configured()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
}
- update_gizmo();
+ update_gizmos();
}
bool Generic6DOFJoint3D::get_flag_z(Flag p_flag) const {
diff --git a/scene/3d/proximity_group_3d.cpp b/scene/3d/proximity_group_3d.cpp
index 9d9fea68b0..c8c61a9f00 100644
--- a/scene/3d/proximity_group_3d.cpp
+++ b/scene/3d/proximity_group_3d.cpp
@@ -128,9 +128,10 @@ void ProximityGroup3D::broadcast(String p_method, Variant p_parameters) {
void ProximityGroup3D::_proximity_group_broadcast(String p_method, Variant p_parameters) {
if (dispatch_mode == MODE_PROXY) {
+ ERR_FAIL_COND(!is_inside_tree());
get_parent()->call(p_method, p_parameters);
} else {
- emit_signal("broadcast", p_method, p_parameters);
+ emit_signal(SNAME("broadcast"), p_method, p_parameters);
}
}
diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp
index dfab3d4a17..7356ce478b 100644
--- a/scene/3d/ray_cast_3d.cpp
+++ b/scene/3d/ray_cast_3d.cpp
@@ -37,7 +37,7 @@
void RayCast3D::set_target_position(const Vector3 &p_point) {
target_position = p_point;
- update_gizmo();
+ update_gizmos();
if (Engine::get_singleton()->is_editor_hint()) {
if (is_inside_tree()) {
@@ -102,7 +102,7 @@ Vector3 RayCast3D::get_collision_normal() const {
void RayCast3D::set_enabled(bool p_enabled) {
enabled = p_enabled;
- update_gizmo();
+ update_gizmos();
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(p_enabled);
@@ -366,7 +366,7 @@ void RayCast3D::_update_debug_shape_vertices() {
void RayCast3D::set_debug_shape_thickness(const float p_debug_shape_thickness) {
debug_shape_thickness = p_debug_shape_thickness;
- update_gizmo();
+ update_gizmos();
if (Engine::get_singleton()->is_editor_hint()) {
if (is_inside_tree()) {
diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp
index c289fc4fd7..719dbedd94 100644
--- a/scene/3d/reflection_probe.cpp
+++ b/scene/3d/reflection_probe.cpp
@@ -101,7 +101,7 @@ void ReflectionProbe::set_extents(const Vector3 &p_extents) {
RS::get_singleton()->reflection_probe_set_extents(probe, extents);
RS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset);
- update_gizmo();
+ update_gizmos();
}
Vector3 ReflectionProbe::get_extents() const {
@@ -119,7 +119,7 @@ void ReflectionProbe::set_origin_offset(const Vector3 &p_extents) {
RS::get_singleton()->reflection_probe_set_extents(probe, extents);
RS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset);
- update_gizmo();
+ update_gizmos();
}
Vector3 ReflectionProbe::get_origin_offset() const {
diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp
index fa3b16935c..9ce4c37457 100644
--- a/scene/3d/skeleton_3d.cpp
+++ b/scene/3d/skeleton_3d.cpp
@@ -264,8 +264,8 @@ void Skeleton3D::_notification(int p_what) {
b.global_pose_override_amount = 0.0;
}
- for (List<ObjectID>::Element *E = b.nodes_bound.front(); E; E = E->next()) {
- Object *obj = ObjectDB::get_instance(E->get());
+ for (const ObjectID &E : b.nodes_bound) {
+ Object *obj = ObjectDB::get_instance(E);
ERR_CONTINUE(!obj);
Node3D *node_3d = Object::cast_to<Node3D>(obj);
ERR_CONTINUE(!node_3d);
@@ -404,7 +404,7 @@ void Skeleton3D::add_bone(const String &p_name) {
process_order_dirty = true;
version++;
_make_dirty();
- update_gizmo();
+ update_gizmos();
}
int Skeleton3D::find_bone(const String &p_name) const {
@@ -524,8 +524,8 @@ void Skeleton3D::bind_child_node_to_bone(int p_bone, Node *p_node) {
ObjectID id = p_node->get_instance_id();
- for (const List<ObjectID>::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) {
- if (E->get() == id) {
+ for (const ObjectID &E : bones[p_bone].nodes_bound) {
+ if (E == id) {
return; // already here
}
}
@@ -544,8 +544,8 @@ void Skeleton3D::unbind_child_node_from_bone(int p_bone, Node *p_node) {
void Skeleton3D::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const {
ERR_FAIL_INDEX(p_bone, bones.size());
- for (const List<ObjectID>::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) {
- Object *obj = ObjectDB::get_instance(E->get());
+ for (const ObjectID &E : bones[p_bone].nodes_bound) {
+ Object *obj = ObjectDB::get_instance(E);
ERR_CONTINUE(!obj);
p_bound->push_back(Object::cast_to<Node>(obj));
}
diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp
index efd8a2b50c..a7ff0842d2 100644
--- a/scene/3d/soft_body_3d.cpp
+++ b/scene/3d/soft_body_3d.cpp
@@ -425,8 +425,8 @@ void SoftBody3D::_draw_soft_mesh() {
/// Necessary in order to render the mesh correctly (Soft body nodes are in global space)
simulation_started = true;
- call_deferred("set_as_top_level", true);
- call_deferred("set_transform", Transform3D());
+ call_deferred(SNAME("set_as_top_level"), true);
+ call_deferred(SNAME("set_transform"), Transform3D());
}
_update_physics_server();
@@ -592,8 +592,7 @@ Array SoftBody3D::get_collision_exceptions() {
List<RID> exceptions;
PhysicsServer3D::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions);
Array ret;
- for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) {
- RID body = E->get();
+ for (const RID &body : exceptions) {
ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body);
Object *obj = ObjectDB::get_instance(instance_id);
PhysicsBody3D *physics_body = Object::cast_to<PhysicsBody3D>(obj);
diff --git a/scene/3d/spring_arm_3d.cpp b/scene/3d/spring_arm_3d.cpp
index 1911e14d54..5e9265b4c3 100644
--- a/scene/3d/spring_arm_3d.cpp
+++ b/scene/3d/spring_arm_3d.cpp
@@ -84,7 +84,7 @@ real_t SpringArm3D::get_length() const {
void SpringArm3D::set_length(real_t p_length) {
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) {
- update_gizmo();
+ update_gizmos();
}
spring_length = p_length;
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index 13f8002721..a901920dbe 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -60,8 +60,8 @@ void SpriteBase3D::_propagate_color_changed() {
color_dirty = true;
_queue_update();
- for (List<SpriteBase3D *>::Element *E = children.front(); E; E = E->next()) {
- E->get()->_propagate_color_changed();
+ for (SpriteBase3D *&E : children) {
+ E->_propagate_color_changed();
}
}
@@ -174,7 +174,7 @@ void SpriteBase3D::_queue_update() {
}
triangle_mesh.unref();
- update_gizmo();
+ update_gizmos();
pending_update = true;
call_deferred(SceneStringNames::get_singleton()->_im_update);
@@ -583,10 +583,10 @@ void Sprite3D::_draw() {
aabb.expand_to(vtx);
}
- float v_uv[2] = { uvs[i].x, uvs[i].y };
+ float v_uv[2] = { (float)uvs[i].x, (float)uvs[i].y };
memcpy(&attribute_write_buffer[i * attrib_stride + mesh_surface_offsets[RS::ARRAY_TEX_UV]], v_uv, 8);
- float v_vertex[3] = { vtx.x, vtx.y, vtx.z };
+ float v_vertex[3] = { (float)vtx.x, (float)vtx.y, (float)vtx.z };
memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_VERTEX]], &v_vertex, sizeof(float) * 3);
memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_NORMAL]], &v_normal, 4);
@@ -949,10 +949,10 @@ void AnimatedSprite3D::_draw() {
aabb.expand_to(vtx);
}
- float v_uv[2] = { uvs[i].x, uvs[i].y };
+ float v_uv[2] = { (float)uvs[i].x, (float)uvs[i].y };
memcpy(&attribute_write_buffer[i * attrib_stride + mesh_surface_offsets[RS::ARRAY_TEX_UV]], v_uv, 8);
- float v_vertex[3] = { vtx.x, vtx.y, vtx.z };
+ float v_vertex[3] = { (float)vtx.x, (float)vtx.y, (float)vtx.z };
memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_VERTEX]], &v_vertex, sizeof(float) * 3);
memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_NORMAL]], &v_normal, 4);
memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_TANGENT]], &v_tangent, 4);
@@ -996,7 +996,7 @@ void AnimatedSprite3D::_validate_property(PropertyInfo &property) const {
}
property.hint_string += String(E->get());
- if (animation == E->get()) {
+ if (animation == E) {
current_found = true;
}
}
diff --git a/scene/3d/vehicle_body_3d.cpp b/scene/3d/vehicle_body_3d.cpp
index b0e37b81a5..92c0e09947 100644
--- a/scene/3d/vehicle_body_3d.cpp
+++ b/scene/3d/vehicle_body_3d.cpp
@@ -149,7 +149,7 @@ void VehicleWheel3D::_update(PhysicsDirectBodyState3D *s) {
void VehicleWheel3D::set_radius(real_t p_radius) {
m_wheelRadius = p_radius;
- update_gizmo();
+ update_gizmos();
}
real_t VehicleWheel3D::get_radius() const {
@@ -158,7 +158,7 @@ real_t VehicleWheel3D::get_radius() const {
void VehicleWheel3D::set_suspension_rest_length(real_t p_length) {
m_suspensionRestLength = p_length;
- update_gizmo();
+ update_gizmos();
}
real_t VehicleWheel3D::get_suspension_rest_length() const {
diff --git a/scene/3d/visible_on_screen_notifier_3d.cpp b/scene/3d/visible_on_screen_notifier_3d.cpp
index 682bcec449..6a80aa3f45 100644
--- a/scene/3d/visible_on_screen_notifier_3d.cpp
+++ b/scene/3d/visible_on_screen_notifier_3d.cpp
@@ -63,7 +63,7 @@ void VisibleOnScreenNotifier3D::set_aabb(const AABB &p_aabb) {
RS::get_singleton()->visibility_notifier_set_aabb(get_base(), aabb);
- update_gizmo();
+ update_gizmos();
}
AABB VisibleOnScreenNotifier3D::get_aabb() const {
diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp
index bd47af8100..70a7021f22 100644
--- a/scene/3d/visual_instance_3d.cpp
+++ b/scene/3d/visual_instance_3d.cpp
@@ -238,8 +238,7 @@ bool GeometryInstance3D::_get(const StringName &p_name, Variant &r_ret) const {
void GeometryInstance3D::_get_property_list(List<PropertyInfo> *p_list) const {
List<PropertyInfo> pinfo;
RS::get_singleton()->instance_geometry_get_shader_parameter_list(get_instance(), &pinfo);
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- PropertyInfo pi = E->get();
+ for (PropertyInfo &pi : pinfo) {
bool has_def_value = false;
Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), pi.name);
if (def_value.get_type() != Variant::NIL) {
diff --git a/scene/3d/voxel_gi.cpp b/scene/3d/voxel_gi.cpp
index 3da59ac4c0..5cf7522667 100644
--- a/scene/3d/voxel_gi.cpp
+++ b/scene/3d/voxel_gi.cpp
@@ -265,7 +265,7 @@ Ref<VoxelGIData> VoxelGI::get_probe_data() const {
void VoxelGI::set_subdiv(Subdiv p_subdiv) {
ERR_FAIL_INDEX(p_subdiv, SUBDIV_MAX);
subdiv = p_subdiv;
- update_gizmo();
+ update_gizmos();
}
VoxelGI::Subdiv VoxelGI::get_subdiv() const {
@@ -274,7 +274,7 @@ VoxelGI::Subdiv VoxelGI::get_subdiv() const {
void VoxelGI::set_extents(const Vector3 &p_extents) {
extents = p_extents;
- update_gizmo();
+ update_gizmos();
}
Vector3 VoxelGI::get_extents() const {
@@ -384,14 +384,14 @@ void VoxelGI::bake(Node *p_from_node, bool p_create_visual_debug) {
int pmc = 0;
- for (List<PlotMesh>::Element *E = mesh_list.front(); E; E = E->next()) {
+ for (PlotMesh &E : mesh_list) {
if (bake_step_function) {
bake_step_function(pmc, RTR("Plotting Meshes") + " " + itos(pmc) + "/" + itos(mesh_list.size()));
}
pmc++;
- baker.plot_mesh(E->get().local_xform, E->get().mesh, E->get().instance_materials, E->get().override_material);
+ baker.plot_mesh(E.local_xform, E.mesh, E.instance_materials, E.override_material);
}
if (bake_step_function) {
bake_step_function(pmc++, RTR("Finishing Plot"));
diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp
index 12f055c01d..f1b9708f91 100644
--- a/scene/3d/voxelizer.cpp
+++ b/scene/3d/voxelizer.cpp
@@ -36,17 +36,17 @@
#include <stdlib.h>
static _FORCE_INLINE_ void get_uv_and_normal(const Vector3 &p_pos, const Vector3 *p_vtx, const Vector2 *p_uv, const Vector3 *p_normal, Vector2 &r_uv, Vector3 &r_normal) {
- if (p_pos.distance_squared_to(p_vtx[0]) < CMP_EPSILON2) {
+ if (p_pos.is_equal_approx(p_vtx[0])) {
r_uv = p_uv[0];
r_normal = p_normal[0];
return;
}
- if (p_pos.distance_squared_to(p_vtx[1]) < CMP_EPSILON2) {
+ if (p_pos.is_equal_approx(p_vtx[1])) {
r_uv = p_uv[1];
r_normal = p_normal[1];
return;
}
- if (p_pos.distance_squared_to(p_vtx[2]) < CMP_EPSILON2) {
+ if (p_pos.is_equal_approx(p_vtx[2])) {
r_uv = p_uv[2];
r_normal = p_normal[2];
return;
diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp
index a91e712b0b..b04c7e2858 100644
--- a/scene/3d/xr_nodes.cpp
+++ b/scene/3d/xr_nodes.cpp
@@ -207,10 +207,10 @@ void XRController3D::_notification(int p_what) {
bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)i);
if (!was_pressed && is_pressed) {
- emit_signal("button_pressed", i);
+ emit_signal(SNAME("button_pressed"), i);
button_states += mask;
} else if (was_pressed && !is_pressed) {
- emit_signal("button_released", i);
+ emit_signal(SNAME("button_released"), i);
button_states -= mask;
};
@@ -225,7 +225,7 @@ void XRController3D::_notification(int p_what) {
Ref<Mesh> trackerMesh = tracker->get_mesh();
if (mesh != trackerMesh) {
mesh = trackerMesh;
- emit_signal("mesh_updated", mesh);
+ emit_signal(SNAME("mesh_updated"), mesh);
}
};
}; break;
@@ -422,7 +422,7 @@ void XRAnchor3D::_notification(int p_what) {
Ref<Mesh> trackerMesh = tracker->get_mesh();
if (mesh != trackerMesh) {
mesh = trackerMesh;
- emit_signal("mesh_updated", mesh);
+ emit_signal(SNAME("mesh_updated"), mesh);
}
};
}; break;
diff --git a/scene/animation/animation_blend_space_1d.cpp b/scene/animation/animation_blend_space_1d.cpp
index 3818c7edd1..6e5d964b76 100644
--- a/scene/animation/animation_blend_space_1d.cpp
+++ b/scene/animation/animation_blend_space_1d.cpp
@@ -54,7 +54,7 @@ void AnimationNodeBlendSpace1D::_validate_property(PropertyInfo &property) const
}
void AnimationNodeBlendSpace1D::_tree_changed() {
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeBlendSpace1D::_bind_methods() {
@@ -120,7 +120,7 @@ void AnimationNodeBlendSpace1D::add_blend_point(const Ref<AnimationRootNode> &p_
blend_points[p_at_index].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace1D::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED);
blend_points_used++;
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeBlendSpace1D::set_blend_point_position(int p_point, float p_position) {
@@ -140,7 +140,7 @@ void AnimationNodeBlendSpace1D::set_blend_point_node(int p_point, const Ref<Anim
blend_points[p_point].node = p_node;
blend_points[p_point].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace1D::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED);
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
float AnimationNodeBlendSpace1D::get_blend_point_position(int p_point) const {
@@ -164,7 +164,7 @@ void AnimationNodeBlendSpace1D::remove_blend_point(int p_point) {
}
blend_points_used--;
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
int AnimationNodeBlendSpace1D::get_blend_point_count() const {
diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp
index 935ec457aa..d88a9badf4 100644
--- a/scene/animation/animation_blend_space_2d.cpp
+++ b/scene/animation/animation_blend_space_2d.cpp
@@ -84,7 +84,7 @@ void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_
_queue_auto_triangles();
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeBlendSpace2D::set_blend_point_position(int p_point, const Vector2 &p_position) {
@@ -103,7 +103,7 @@ void AnimationNodeBlendSpace2D::set_blend_point_node(int p_point, const Ref<Anim
blend_points[p_point].node = p_node;
blend_points[p_point].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED);
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
Vector2 AnimationNodeBlendSpace2D::get_blend_point_position(int p_point) const {
@@ -143,7 +143,7 @@ void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) {
blend_points[i] = blend_points[i + 1];
}
blend_points_used--;
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
int AnimationNodeBlendSpace2D::get_blend_point_count() const {
@@ -321,7 +321,7 @@ void AnimationNodeBlendSpace2D::_queue_auto_triangles() {
}
trianges_dirty = true;
- call_deferred("_update_triangles");
+ call_deferred(SNAME("_update_triangles"));
}
void AnimationNodeBlendSpace2D::_update_triangles() {
@@ -332,7 +332,7 @@ void AnimationNodeBlendSpace2D::_update_triangles() {
trianges_dirty = false;
triangles.clear();
if (blend_points_used < 3) {
- emit_signal("triangles_updated");
+ emit_signal(SNAME("triangles_updated"));
return;
}
@@ -347,7 +347,7 @@ void AnimationNodeBlendSpace2D::_update_triangles() {
for (int i = 0; i < triangles.size(); i++) {
add_triangle(triangles[i].points[0], triangles[i].points[1], triangles[i].points[2]);
}
- emit_signal("triangles_updated");
+ emit_signal(SNAME("triangles_updated"));
}
Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) {
@@ -387,19 +387,19 @@ Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) {
}
void AnimationNodeBlendSpace2D::_blend_triangle(const Vector2 &p_pos, const Vector2 *p_points, float *r_weights) {
- if (p_pos.distance_squared_to(p_points[0]) < CMP_EPSILON2) {
+ if (p_pos.is_equal_approx(p_points[0])) {
r_weights[0] = 1;
r_weights[1] = 0;
r_weights[2] = 0;
return;
}
- if (p_pos.distance_squared_to(p_points[1]) < CMP_EPSILON2) {
+ if (p_pos.is_equal_approx(p_points[1])) {
r_weights[0] = 0;
r_weights[1] = 1;
r_weights[2] = 0;
return;
}
- if (p_pos.distance_squared_to(p_points[2]) < CMP_EPSILON2) {
+ if (p_pos.is_equal_approx(p_points[2])) {
r_weights[0] = 0;
r_weights[1] = 0;
r_weights[2] = 1;
@@ -532,10 +532,10 @@ float AnimationNodeBlendSpace2D::process(float p_time, bool p_seek) {
float from = 0.0;
if (blend_mode == BLEND_MODE_DISCRETE_CARRY && closest != -1) {
//see how much animation remains
- from = blend_node(blend_points[closest].name, blend_points[closest].node, p_time, true, 0.0, FILTER_IGNORE, false) - length_internal;
+ from = length_internal - blend_node(blend_points[closest].name, blend_points[closest].node, p_time, false, 0.0, FILTER_IGNORE, false);
}
- mind = blend_node(blend_points[new_closest].name, blend_points[new_closest].node, from, true, 1.0, FILTER_IGNORE, false) + from;
+ mind = blend_node(blend_points[new_closest].name, blend_points[new_closest].node, from, true, 1.0, FILTER_IGNORE, false);
length_internal = from + mind;
closest = new_closest;
@@ -586,7 +586,7 @@ Ref<AnimationNode> AnimationNodeBlendSpace2D::get_child_by_name(const StringName
}
void AnimationNodeBlendSpace2D::_tree_changed() {
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeBlendSpace2D::set_blend_mode(BlendMode p_blend_mode) {
diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp
index 6a988042b5..4bddae3b14 100644
--- a/scene/animation/animation_blend_tree.cpp
+++ b/scene/animation/animation_blend_tree.cpp
@@ -816,7 +816,7 @@ void AnimationNodeBlendTree::add_node(const StringName &p_name, Ref<AnimationNod
nodes[p_name] = n;
emit_changed();
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
p_node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendTree::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED);
p_node->connect("changed", callable_mp(this, &AnimationNodeBlendTree::_node_changed), varray(p_name), CONNECT_REFERENCE_COUNTED);
@@ -896,7 +896,7 @@ void AnimationNodeBlendTree::remove_node(const StringName &p_name) {
}
emit_changed();
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeBlendTree::rename_node(const StringName &p_name, const StringName &p_new_name) {
@@ -921,7 +921,7 @@ void AnimationNodeBlendTree::rename_node(const StringName &p_name, const StringN
//connection must be done with new name
nodes[p_new_name].node->connect("changed", callable_mp(this, &AnimationNodeBlendTree::_node_changed), varray(p_new_name), CONNECT_REFERENCE_COUNTED);
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeBlendTree::connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) {
@@ -1089,10 +1089,10 @@ bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) cons
conns.resize(nc.size() * 3);
int idx = 0;
- for (List<NodeConnection>::Element *E = nc.front(); E; E = E->next()) {
- conns[idx * 3 + 0] = E->get().input_node;
- conns[idx * 3 + 1] = E->get().input_index;
- conns[idx * 3 + 2] = E->get().output_node;
+ for (const NodeConnection &E : nc) {
+ conns[idx * 3 + 0] = E.input_node;
+ conns[idx * 3 + 1] = E.input_index;
+ conns[idx * 3 + 2] = E.output_node;
idx++;
}
@@ -1110,8 +1110,8 @@ void AnimationNodeBlendTree::_get_property_list(List<PropertyInfo> *p_list) cons
}
names.sort_custom<StringName::AlphCompare>();
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
- String name = E->get();
+ for (const StringName &E : names) {
+ String name = E;
if (name != "output") {
p_list->push_back(PropertyInfo(Variant::OBJECT, "nodes/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR));
}
@@ -1125,11 +1125,11 @@ void AnimationNodeBlendTree::reset_state() {
graph_offset = Vector2();
nodes.clear();
emit_changed();
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeBlendTree::_tree_changed() {
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeBlendTree::_node_changed(const StringName &p_node) {
diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp
index b8980fd56b..56743007e4 100644
--- a/scene/animation/animation_cache.cpp
+++ b/scene/animation/animation_cache.cpp
@@ -252,8 +252,8 @@ void AnimationCache::set_all(float p_time, float p_delta) {
List<int> indices;
animation->value_track_get_key_indices(i, p_time, p_delta, &indices);
- for (List<int>::Element *E = indices.front(); E; E = E->next()) {
- Variant v = animation->track_get_key_value(i, E->get());
+ for (int &E : indices) {
+ Variant v = animation->track_get_key_value(i, E);
set_track_value(i, v);
}
}
@@ -263,9 +263,9 @@ void AnimationCache::set_all(float p_time, float p_delta) {
List<int> indices;
animation->method_track_get_key_indices(i, p_time, p_delta, &indices);
- for (List<int>::Element *E = indices.front(); E; E = E->next()) {
- Vector<Variant> args = animation->method_track_get_params(i, E->get());
- StringName name = animation->method_track_get_name(i, E->get());
+ for (int &E : indices) {
+ Vector<Variant> args = animation->method_track_get_params(i, E);
+ StringName name = animation->method_track_get_name(i, E);
Callable::CallError err;
if (!args.size()) {
diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp
index f494f5c163..bf53b554bf 100644
--- a/scene/animation/animation_node_state_machine.cpp
+++ b/scene/animation/animation_node_state_machine.cpp
@@ -57,7 +57,7 @@ void AnimationNodeStateMachineTransition::set_advance_condition(const StringName
} else {
advance_condition_name = StringName();
}
- emit_signal("advance_condition_changed");
+ emit_signal(SNAME("advance_condition_changed"));
}
StringName AnimationNodeStateMachineTransition::get_advance_condition() const {
@@ -512,8 +512,8 @@ void AnimationNodeStateMachine::get_parameter_list(List<PropertyInfo> *r_list) c
}
advance_conditions.sort_custom<StringName::AlphCompare>();
- for (List<StringName>::Element *E = advance_conditions.front(); E; E = E->next()) {
- r_list->push_back(PropertyInfo(Variant::BOOL, E->get()));
+ for (const StringName &E : advance_conditions) {
+ r_list->push_back(PropertyInfo(Variant::BOOL, E));
}
}
@@ -539,7 +539,7 @@ void AnimationNodeStateMachine::add_node(const StringName &p_name, Ref<Animation
states[p_name] = state;
emit_changed();
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
p_node->connect("tree_changed", callable_mp(this, &AnimationNodeStateMachine::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED);
}
@@ -559,7 +559,7 @@ void AnimationNodeStateMachine::replace_node(const StringName &p_name, Ref<Anima
states[p_name].node = p_node;
emit_changed();
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
p_node->connect("tree_changed", callable_mp(this, &AnimationNodeStateMachine::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED);
}
@@ -636,7 +636,7 @@ void AnimationNodeStateMachine::remove_node(const StringName &p_name) {
}*/
emit_changed();
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeStateMachine::rename_node(const StringName &p_name, const StringName &p_new_name) {
@@ -669,7 +669,7 @@ void AnimationNodeStateMachine::rename_node(const StringName &p_name, const Stri
}*/
//path.clear(); //clear path
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeStateMachine::get_node_list(List<StringName> *r_nodes) const {
@@ -679,8 +679,8 @@ void AnimationNodeStateMachine::get_node_list(List<StringName> *r_nodes) const {
}
nodes.sort_custom<StringName::AlphCompare>();
- for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) {
- r_nodes->push_back(E->get());
+ for (const StringName &E : nodes) {
+ r_nodes->push_back(E);
}
}
@@ -902,8 +902,7 @@ void AnimationNodeStateMachine::_get_property_list(List<PropertyInfo> *p_list) c
}
names.sort_custom<StringName::AlphCompare>();
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
- String name = E->get();
+ for (const StringName &name : names) {
p_list->push_back(PropertyInfo(Variant::OBJECT, "states/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "states/" + name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
}
@@ -923,7 +922,7 @@ void AnimationNodeStateMachine::reset_state() {
graph_offset = Vector2();
emit_changed();
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeStateMachine::set_node_position(const StringName &p_name, const Vector2 &p_position) {
@@ -937,7 +936,7 @@ Vector2 AnimationNodeStateMachine::get_node_position(const StringName &p_name) c
}
void AnimationNodeStateMachine::_tree_changed() {
- emit_signal("tree_changed");
+ emit_signal(SNAME("tree_changed"));
}
void AnimationNodeStateMachine::_bind_methods() {
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 6154eef3cf..67b6205a65 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -176,8 +176,8 @@ void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const {
anim_names.sort();
- for (List<PropertyInfo>::Element *E = anim_names.front(); E; E = E->next()) {
- p_list->push_back(E->get());
+ for (const PropertyInfo &E : anim_names) {
+ p_list->push_back(E);
}
p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
@@ -485,8 +485,8 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
List<int> indices;
a->value_track_get_key_indices(i, p_time, p_delta, &indices);
- for (List<int>::Element *F = indices.front(); F; F = F->next()) {
- Variant value = a->track_get_key_value(i, F->get());
+ for (int &F : indices) {
+ Variant value = a->track_get_key_value(i, F);
switch (pa->special) {
case SP_NONE: {
bool valid;
@@ -544,9 +544,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
a->method_track_get_key_indices(i, p_time, p_delta, &indices);
- for (List<int>::Element *E = indices.front(); E; E = E->next()) {
- StringName method = a->method_track_get_name(i, E->get());
- Vector<Variant> params = a->method_track_get_params(i, E->get());
+ for (int &E : indices) {
+ StringName method = a->method_track_get_name(i, E);
+ Vector<Variant> params = a->method_track_get_params(i, E);
int s = params.size();
@@ -557,6 +557,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
}
#endif
+ static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8");
if (can_call) {
if (method_call_mode == ANIMATION_METHOD_CALL_DEFERRED) {
MessageQueue::get_singleton()->push_call(
@@ -566,7 +567,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
s >= 2 ? params[1] : Variant(),
s >= 3 ? params[2] : Variant(),
s >= 4 ? params[3] : Variant(),
- s >= 5 ? params[4] : Variant());
+ s >= 5 ? params[4] : Variant(),
+ s >= 6 ? params[5] : Variant(),
+ s >= 7 ? params[6] : Variant(),
+ s >= 8 ? params[7] : Variant());
} else {
nc->node->call(
method,
@@ -574,7 +578,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
s >= 2 ? params[1] : Variant(),
s >= 3 ? params[2] : Variant(),
s >= 4 ? params[3] : Variant(),
- s >= 5 ? params[4] : Variant());
+ s >= 5 ? params[4] : Variant(),
+ s >= 6 ? params[5] : Variant(),
+ s >= 7 ? params[6] : Variant(),
+ s >= 8 ? params[7] : Variant());
}
}
}
@@ -1069,8 +1076,8 @@ void AnimationPlayer::get_animation_list(List<StringName> *p_animations) const {
anims.sort();
- for (List<String>::Element *E = anims.front(); E; E = E->next()) {
- p_animations->push_back(E->get());
+ for (const String &E : anims) {
+ p_animations->push_back(E);
}
}
@@ -1111,8 +1118,8 @@ void AnimationPlayer::queue(const StringName &p_name) {
Vector<String> AnimationPlayer::get_queue() {
Vector<String> ret;
- for (List<StringName>::Element *E = queued.front(); E; E = E->next()) {
- ret.push_back(E->get());
+ for (const StringName &E : queued) {
+ ret.push_back(E);
}
return ret;
@@ -1325,7 +1332,7 @@ float AnimationPlayer::get_current_animation_length() const {
void AnimationPlayer::_animation_changed() {
clear_caches();
- emit_signal("caches_cleared");
+ emit_signal(SNAME("caches_cleared"));
if (is_playing()) {
playback.seeked = true; //need to restart stuff, like audio
}
@@ -1495,8 +1502,8 @@ void AnimationPlayer::get_argument_options(const StringName &p_function, int p_i
if (p_idx == 0 && (p_function == "play" || p_function == "play_backwards" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue")) {
List<StringName> al;
get_animation_list(&al);
- for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
- r_options->push_back(quote_style + String(E->get()) + quote_style);
+ for (const StringName &E : al) {
+ r_options->push_back(quote_style + String(E) + quote_style);
}
}
Node::get_argument_options(p_function, p_idx, r_options);
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index 1e07f83d09..00b847168d 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -76,10 +76,10 @@ void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) {
Dictionary cn = get_script_instance()->call("_get_child_nodes");
List<Variant> keys;
cn.get_key_list(&keys);
- for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
+ for (const Variant &E : keys) {
ChildNode child;
- child.name = E->get();
- child.node = cn[E->get()];
+ child.name = E;
+ child.node = cn[E];
r_child_nodes->push_back(child);
}
}
@@ -536,8 +536,8 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
List<StringName> sname;
player->get_animation_list(&sname);
- for (List<StringName>::Element *E = sname.front(); E; E = E->next()) {
- Ref<Animation> anim = player->get_animation(E->get());
+ for (const StringName &E : sname) {
+ Ref<Animation> anim = player->get_animation(E);
for (int i = 0; i < anim->get_track_count(); i++) {
NodePath path = anim->track_get_path(i);
Animation::TrackType track_type = anim->track_get_type(i);
@@ -561,7 +561,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
Node *child = parent->get_node_and_resource(path, resource, leftover_path);
if (!child) {
- ERR_PRINT("AnimationTree: '" + String(E->get()) + "', couldn't resolve track: '" + String(path) + "'");
+ ERR_PRINT("AnimationTree: '" + String(E) + "', couldn't resolve track: '" + String(path) + "'");
continue;
}
@@ -590,7 +590,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
Node3D *node_3d = Object::cast_to<Node3D>(child);
if (!node_3d) {
- ERR_PRINT("AnimationTree: '" + String(E->get()) + "', transform track does not point to Node3D: '" + String(path) + "'");
+ ERR_PRINT("AnimationTree: '" + String(E) + "', transform track does not point to Node3D: '" + String(path) + "'");
continue;
}
@@ -816,9 +816,7 @@ void AnimationTree::_process_graph(float p_delta) {
{
bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
- for (List<AnimationNode::AnimationState>::Element *E = state.animation_states.front(); E; E = E->next()) {
- const AnimationNode::AnimationState &as = E->get();
-
+ for (const AnimationNode::AnimationState &as : state.animation_states) {
Ref<Animation> a = as.animation;
float time = as.time;
float delta = as.delta;
@@ -962,8 +960,8 @@ void AnimationTree::_process_graph(float p_delta) {
List<int> indices;
a->value_track_get_key_indices(i, time, delta, &indices);
- for (List<int>::Element *F = indices.front(); F; F = F->next()) {
- Variant value = a->track_get_key_value(i, F->get());
+ for (int &F : indices) {
+ Variant value = a->track_get_key_value(i, F);
t->object->set_indexed(t->subpath, value);
}
}
@@ -979,12 +977,13 @@ void AnimationTree::_process_graph(float p_delta) {
a->method_track_get_key_indices(i, time, delta, &indices);
- for (List<int>::Element *F = indices.front(); F; F = F->next()) {
- StringName method = a->method_track_get_name(i, F->get());
- Vector<Variant> params = a->method_track_get_params(i, F->get());
+ for (int &F : indices) {
+ StringName method = a->method_track_get_name(i, F);
+ Vector<Variant> params = a->method_track_get_params(i, F);
int s = params.size();
+ static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8");
ERR_CONTINUE(s > VARIANT_ARG_MAX);
if (can_call) {
t->object->call_deferred(
@@ -993,7 +992,10 @@ void AnimationTree::_process_graph(float p_delta) {
s >= 2 ? params[1] : Variant(),
s >= 3 ? params[2] : Variant(),
s >= 4 ? params[3] : Variant(),
- s >= 5 ? params[4] : Variant());
+ s >= 5 ? params[4] : Variant(),
+ s >= 6 ? params[5] : Variant(),
+ s >= 7 ? params[6] : Variant(),
+ s >= 8 ? params[7] : Variant());
}
}
@@ -1327,7 +1329,7 @@ void AnimationTree::_tree_changed() {
return;
}
- call_deferred("_update_properties");
+ call_deferred(SNAME("_update_properties"));
properties_dirty = true;
}
@@ -1351,9 +1353,7 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref<A
List<PropertyInfo> plist;
node->get_parameter_list(&plist);
- for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- PropertyInfo pinfo = E->get();
-
+ for (PropertyInfo &pinfo : plist) {
StringName key = pinfo.name;
if (!property_map.has(p_base_path + key)) {
@@ -1369,8 +1369,8 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref<A
List<AnimationNode::ChildNode> children;
node->get_child_nodes(&children);
- for (List<AnimationNode::ChildNode>::Element *E = children.front(); E; E = E->next()) {
- _update_properties_for_node(p_base_path + E->get().name + "/", E->get().node);
+ for (const AnimationNode::ChildNode &E : children) {
+ _update_properties_for_node(p_base_path + E.name + "/", E.node);
}
}
@@ -1424,17 +1424,17 @@ void AnimationTree::_get_property_list(List<PropertyInfo> *p_list) const {
const_cast<AnimationTree *>(this)->_update_properties();
}
- for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
- p_list->push_back(E->get());
+ for (const PropertyInfo &E : properties) {
+ p_list->push_back(E);
}
}
void AnimationTree::rename_parameter(const String &p_base, const String &p_new_base) {
//rename values first
- for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
- if (E->get().name.begins_with(p_base)) {
- String new_name = E->get().name.replace_first(p_base, p_new_base);
- property_map[new_name] = property_map[E->get().name];
+ for (const PropertyInfo &E : properties) {
+ if (E.name.begins_with(p_base)) {
+ String new_name = E.name.replace_first(p_base, p_new_base);
+ property_map[new_name] = property_map[E.name];
}
}
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index 7bf616e602..a57e986877 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -46,8 +46,8 @@ void Tween::start_tweeners() {
ERR_FAIL_MSG("Tween without commands, aborting.");
}
- for (List<Ref<Tweener>>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) {
- E->get()->start();
+ for (Ref<Tweener> &tweener : tweeners.write[current_step]) {
+ tweener->start();
}
}
@@ -253,18 +253,18 @@ bool Tween::step(float p_delta) {
float step_delta = rem_delta;
step_active = false;
- for (List<Ref<Tweener>>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) {
+ for (Ref<Tweener> &tweener : tweeners.write[current_step]) {
// Modified inside Tweener.step().
float temp_delta = rem_delta;
// Turns to true if any Tweener returns true (i.e. is still not finished).
- step_active = E->get()->step(temp_delta) || step_active;
+ step_active = tweener->step(temp_delta) || step_active;
step_delta = MIN(temp_delta, rem_delta);
}
rem_delta = step_delta;
if (!step_active) {
- emit_signal("step_finished", current_step);
+ emit_signal(SNAME("step_finished"), current_step);
current_step++;
if (current_step == tweeners.size()) {
@@ -272,9 +272,9 @@ bool Tween::step(float p_delta) {
if (loops_done == loops) {
running = false;
dead = true;
- emit_signal("finished");
+ emit_signal(SNAME("finished"));
} else {
- emit_signal("loop_finished", loops_done);
+ emit_signal(SNAME("loop_finished"), loops_done);
current_step = 0;
start_tweeners();
}
@@ -690,7 +690,7 @@ bool PropertyTweener::step(float &r_delta) {
} else {
finished = true;
r_delta = elapsed_time - delay - duration;
- emit_signal("finished");
+ emit_signal(SNAME("finished"));
return false;
}
}
@@ -745,7 +745,7 @@ bool IntervalTweener::step(float &r_delta) {
} else {
finished = true;
r_delta = elapsed_time - duration;
- emit_signal("finished");
+ emit_signal(SNAME("finished"));
return false;
}
}
@@ -784,7 +784,7 @@ bool CallbackTweener::step(float &r_delta) {
finished = true;
r_delta = elapsed_time - delay;
- emit_signal("finished");
+ emit_signal(SNAME("finished"));
return false;
}
@@ -854,7 +854,7 @@ bool MethodTweener::step(float &r_delta) {
} else {
finished = true;
r_delta = elapsed_time - delay - duration;
- emit_signal("finished");
+ emit_signal(SNAME("finished"));
return false;
}
}
diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp
index 1478cbf69e..298d75b668 100644
--- a/scene/audio/audio_stream_player.cpp
+++ b/scene/audio/audio_stream_player.cpp
@@ -146,7 +146,7 @@ void AudioStreamPlayer::_notification(int p_what) {
if (!active.is_set() || (setseek.get() < 0 && !stream_playback->is_playing())) {
active.clear();
set_process_internal(false);
- emit_signal("finished");
+ emit_signal(SNAME("finished"));
}
}
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
index 1e121ab6e5..ce2b320c96 100644
--- a/scene/debugger/scene_debugger.cpp
+++ b/scene/debugger/scene_debugger.cpp
@@ -145,12 +145,12 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra
live_editor->_res_set_func(p_args[0], p_args[1], p_args[2]);
} else if (p_msg == "live_node_call") {
- ERR_FAIL_COND_V(p_args.size() < 7, ERR_INVALID_DATA);
- live_editor->_node_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6]);
+ ERR_FAIL_COND_V(p_args.size() < 10, ERR_INVALID_DATA);
+ live_editor->_node_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6], p_args[7], p_args[8], p_args[9]);
} else if (p_msg == "live_res_call") {
- ERR_FAIL_COND_V(p_args.size() < 7, ERR_INVALID_DATA);
- live_editor->_res_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6]);
+ ERR_FAIL_COND_V(p_args.size() < 10, ERR_INVALID_DATA);
+ live_editor->_res_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6], p_args[7], p_args[8], p_args[9]);
} else if (p_msg == "live_create_node") {
ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
@@ -292,9 +292,9 @@ SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) {
// Add base object properties.
List<PropertyInfo> pinfo;
obj->get_property_list(&pinfo, true);
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
- properties.push_back(SceneDebuggerProperty(E->get(), obj->get(E->get().name)));
+ for (const PropertyInfo &E : pinfo) {
+ if (E.usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
+ properties.push_back(SceneDebuggerProperty(E, obj->get(E.name)));
}
}
}
@@ -452,8 +452,7 @@ SceneDebuggerTree::SceneDebuggerTree(Node *p_root) {
}
void SceneDebuggerTree::serialize(Array &p_arr) {
- for (List<RemoteNode>::Element *E = nodes.front(); E; E = E->next()) {
- RemoteNode &n = E->get();
+ for (const RemoteNode &n : nodes) {
p_arr.push_back(n.child_count);
p_arr.push_back(n.name);
p_arr.push_back(n.type_name);
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index c1ae0479f5..75a4464a40 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -125,7 +125,7 @@ void BaseButton::_pressed() {
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed);
}
pressed();
- emit_signal("pressed");
+ emit_signal(SNAME("pressed"));
}
void BaseButton::_toggled(bool p_pressed) {
@@ -133,14 +133,14 @@ void BaseButton::_toggled(bool p_pressed) {
get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, p_pressed);
}
toggled(p_pressed);
- emit_signal("toggled", p_pressed);
+ emit_signal(SNAME("toggled"), p_pressed);
}
void BaseButton::on_action_event(Ref<InputEvent> p_event) {
if (p_event->is_pressed()) {
status.press_attempt = true;
status.pressing_inside = true;
- emit_signal("button_down");
+ emit_signal(SNAME("button_down"));
}
if (status.press_attempt && status.pressing_inside) {
@@ -153,7 +153,7 @@ void BaseButton::on_action_event(Ref<InputEvent> p_event) {
status.pressed = !status.pressed;
_unpress_group();
if (button_group.is_valid()) {
- button_group->emit_signal("pressed", this);
+ button_group->emit_signal(SNAME("pressed"), this);
}
_toggled(status.pressed);
_pressed();
@@ -174,7 +174,7 @@ void BaseButton::on_action_event(Ref<InputEvent> p_event) {
}
status.press_attempt = false;
status.pressing_inside = false;
- emit_signal("button_up");
+ emit_signal(SNAME("button_up"));
}
update();
@@ -218,7 +218,7 @@ void BaseButton::set_pressed(bool p_pressed) {
if (p_pressed) {
_unpress_group();
if (button_group.is_valid()) {
- button_group->emit_signal("pressed", this);
+ button_group->emit_signal(SNAME("pressed"), this);
}
}
_toggled(status.pressed);
@@ -226,6 +226,18 @@ void BaseButton::set_pressed(bool p_pressed) {
update();
}
+void BaseButton::set_pressed_no_signal(bool p_pressed) {
+ if (!toggle_mode) {
+ return;
+ }
+ if (status.pressed == p_pressed) {
+ return;
+ }
+ status.pressed = p_pressed;
+
+ update();
+}
+
bool BaseButton::is_pressing() const {
return status.press_attempt;
}
@@ -399,6 +411,7 @@ void BaseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &BaseButton::_unhandled_key_input);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &BaseButton::set_pressed);
ClassDB::bind_method(D_METHOD("is_pressed"), &BaseButton::is_pressed);
+ ClassDB::bind_method(D_METHOD("set_pressed_no_signal", "pressed"), &BaseButton::set_pressed_no_signal);
ClassDB::bind_method(D_METHOD("is_hovered"), &BaseButton::is_hovered);
ClassDB::bind_method(D_METHOD("set_toggle_mode", "enabled"), &BaseButton::set_toggle_mode);
ClassDB::bind_method(D_METHOD("is_toggle_mode"), &BaseButton::is_toggle_mode);
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 6c7a8f3433..d86b35daf0 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -98,7 +98,8 @@ public:
bool is_pressing() const; ///< return whether button is pressed (toggled in)
bool is_hovered() const;
- void set_pressed(bool p_pressed); ///only works in toggle mode
+ void set_pressed(bool p_pressed); // Only works in toggle mode.
+ void set_pressed_no_signal(bool p_pressed);
void set_toggle_mode(bool p_on);
bool is_toggle_mode() const;
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 7407ad5b8f..a2f1d2b15a 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -43,7 +43,7 @@ void BoxContainer::_resort() {
Size2i new_size = get_size();
- int sep = get_theme_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer");
+ int sep = get_theme_constant(SNAME("separation")); //,vertical?"VBoxContainer":"HBoxContainer");
bool rtl = is_layout_rtl();
bool first = true;
@@ -247,7 +247,7 @@ Size2 BoxContainer::get_minimum_size() const {
/* Calculate MINIMUM SIZE */
Size2i minimum;
- int sep = get_theme_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer");
+ int sep = get_theme_constant(SNAME("separation")); //,vertical?"VBoxContainer":"HBoxContainer");
bool first = true;
@@ -349,6 +349,7 @@ void BoxContainer::_bind_methods() {
MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control *p_control, bool p_expand) {
Label *l = memnew(Label);
+ l->set_theme_type_variation("HeaderSmall");
l->set_text(p_label);
add_child(l);
MarginContainer *mc = memnew(MarginContainer);
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index bcc273114b..4b6c0ef697 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -41,8 +41,8 @@ Size2 Button::get_minimum_size() const {
if (!expand_icon) {
Ref<Texture2D> _icon;
- if (icon.is_null() && has_theme_icon("icon")) {
- _icon = Control::get_theme_icon("icon");
+ if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
+ _icon = Control::get_theme_icon(SNAME("icon"));
} else {
_icon = icon;
}
@@ -53,7 +53,7 @@ Size2 Button::get_minimum_size() const {
if (icon_align != ALIGN_CENTER) {
minsize.width += _icon->get_width();
if (xl_text != "") {
- minsize.width += get_theme_constant("hseparation");
+ minsize.width += get_theme_constant(SNAME("hseparation"));
}
} else {
minsize.width = MAX(minsize.width, _icon->get_width());
@@ -61,12 +61,12 @@ Size2 Button::get_minimum_size() const {
}
}
- Ref<Font> font = get_theme_font("font");
- float font_height = font->get_height(get_theme_font_size("font_size"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ float font_height = font->get_height(get_theme_font_size(SNAME("font_size")));
minsize.height = MAX(font_height, minsize.height);
- return get_theme_stylebox("normal")->get_minimum_size() + minsize;
+ return get_theme_stylebox(SNAME("normal"))->get_minimum_size() + minsize;
}
void Button::_set_internal_margin(Side p_side, float p_value) {
@@ -97,43 +97,43 @@ void Button::_notification(int p_what) {
Color color;
Color color_icon(1, 1, 1, 1);
- Ref<StyleBox> style = get_theme_stylebox("normal");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
bool rtl = is_layout_rtl();
switch (get_draw_mode()) {
case DRAW_NORMAL: {
- if (rtl && has_theme_stylebox("normal_mirrored")) {
- style = get_theme_stylebox("normal_mirrored");
+ if (rtl && has_theme_stylebox(SNAME("normal_mirrored"))) {
+ style = get_theme_stylebox(SNAME("normal_mirrored"));
} else {
- style = get_theme_stylebox("normal");
+ style = get_theme_stylebox(SNAME("normal"));
}
if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
}
- color = get_theme_color("font_color");
- if (has_theme_color("icon_normal_color")) {
- color_icon = get_theme_color("icon_normal_color");
+ color = get_theme_color(SNAME("font_color"));
+ if (has_theme_color(SNAME("icon_normal_color"))) {
+ color_icon = get_theme_color(SNAME("icon_normal_color"));
}
} break;
case DRAW_HOVER_PRESSED: {
- if (has_theme_stylebox("hover_pressed") && has_theme_stylebox_override("hover_pressed")) {
- if (rtl && has_theme_stylebox("hover_pressed_mirrored")) {
- style = get_theme_stylebox("hover_pressed_mirrored");
+ if (has_theme_stylebox(SNAME("hover_pressed")) && has_theme_stylebox_override("hover_pressed")) {
+ if (rtl && has_theme_stylebox(SNAME("hover_pressed_mirrored"))) {
+ style = get_theme_stylebox(SNAME("hover_pressed_mirrored"));
} else {
- style = get_theme_stylebox("hover_pressed");
+ style = get_theme_stylebox(SNAME("hover_pressed"));
}
if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
}
- if (has_theme_color("font_hover_pressed_color")) {
- color = get_theme_color("font_hover_pressed_color");
+ if (has_theme_color(SNAME("font_hover_pressed_color"))) {
+ color = get_theme_color(SNAME("font_hover_pressed_color"));
} else {
- color = get_theme_color("font_color");
+ color = get_theme_color(SNAME("font_color"));
}
- if (has_theme_color("icon_hover_pressed_color")) {
- color_icon = get_theme_color("icon_hover_pressed_color");
+ if (has_theme_color(SNAME("icon_hover_pressed_color"))) {
+ color_icon = get_theme_color(SNAME("icon_hover_pressed_color"));
}
break;
@@ -141,67 +141,67 @@ void Button::_notification(int p_what) {
[[fallthrough]];
}
case DRAW_PRESSED: {
- if (rtl && has_theme_stylebox("pressed_mirrored")) {
- style = get_theme_stylebox("pressed_mirrored");
+ if (rtl && has_theme_stylebox(SNAME("pressed_mirrored"))) {
+ style = get_theme_stylebox(SNAME("pressed_mirrored"));
} else {
- style = get_theme_stylebox("pressed");
+ style = get_theme_stylebox(SNAME("pressed"));
}
if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
}
- if (has_theme_color("font_pressed_color")) {
- color = get_theme_color("font_pressed_color");
+ if (has_theme_color(SNAME("font_pressed_color"))) {
+ color = get_theme_color(SNAME("font_pressed_color"));
} else {
- color = get_theme_color("font_color");
+ color = get_theme_color(SNAME("font_color"));
}
- if (has_theme_color("icon_pressed_color")) {
- color_icon = get_theme_color("icon_pressed_color");
+ if (has_theme_color(SNAME("icon_pressed_color"))) {
+ color_icon = get_theme_color(SNAME("icon_pressed_color"));
}
} break;
case DRAW_HOVER: {
- if (rtl && has_theme_stylebox("hover_mirrored")) {
- style = get_theme_stylebox("hover_mirrored");
+ if (rtl && has_theme_stylebox(SNAME("hover_mirrored"))) {
+ style = get_theme_stylebox(SNAME("hover_mirrored"));
} else {
- style = get_theme_stylebox("hover");
+ style = get_theme_stylebox(SNAME("hover"));
}
if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
}
- color = get_theme_color("font_hover_color");
- if (has_theme_color("icon_hover_color")) {
- color_icon = get_theme_color("icon_hover_color");
+ color = get_theme_color(SNAME("font_hover_color"));
+ if (has_theme_color(SNAME("icon_hover_color"))) {
+ color_icon = get_theme_color(SNAME("icon_hover_color"));
}
} break;
case DRAW_DISABLED: {
- if (rtl && has_theme_stylebox("disabled_mirrored")) {
- style = get_theme_stylebox("disabled_mirrored");
+ if (rtl && has_theme_stylebox(SNAME("disabled_mirrored"))) {
+ style = get_theme_stylebox(SNAME("disabled_mirrored"));
} else {
- style = get_theme_stylebox("disabled");
+ style = get_theme_stylebox(SNAME("disabled"));
}
if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
}
- color = get_theme_color("font_disabled_color");
- if (has_theme_color("icon_disabled_color")) {
- color_icon = get_theme_color("icon_disabled_color");
+ color = get_theme_color(SNAME("font_disabled_color"));
+ if (has_theme_color(SNAME("icon_disabled_color"))) {
+ color_icon = get_theme_color(SNAME("icon_disabled_color"));
}
} break;
}
if (has_focus()) {
- Ref<StyleBox> style2 = get_theme_stylebox("focus");
+ Ref<StyleBox> style2 = get_theme_stylebox(SNAME("focus"));
style2->draw(ci, Rect2(Point2(), size));
}
Ref<Texture2D> _icon;
- if (icon.is_null() && has_theme_icon("icon")) {
- _icon = Control::get_theme_icon("icon");
+ if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
+ _icon = Control::get_theme_icon(SNAME("icon"));
} else {
_icon = icon;
}
@@ -234,21 +234,21 @@ void Button::_notification(int p_what) {
if (icon_align_rtl_checked == ALIGN_LEFT) {
style_offset.x = style->get_margin(SIDE_LEFT);
if (_internal_margin[SIDE_LEFT] > 0) {
- icon_ofs_region = _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation");
+ icon_ofs_region = _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation"));
}
} else if (icon_align_rtl_checked == ALIGN_CENTER) {
style_offset.x = 0.0;
} else if (icon_align_rtl_checked == ALIGN_RIGHT) {
style_offset.x = -style->get_margin(SIDE_RIGHT);
if (_internal_margin[SIDE_RIGHT] > 0) {
- icon_ofs_region = -_internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation");
+ icon_ofs_region = -_internal_margin[SIDE_RIGHT] - get_theme_constant(SNAME("hseparation"));
}
}
style_offset.y = style->get_margin(SIDE_TOP);
if (expand_icon) {
Size2 _size = get_size() - style->get_offset() * 2;
- _size.width -= get_theme_constant("hseparation") + icon_ofs_region;
+ _size.width -= get_theme_constant(SNAME("hseparation")) + icon_ofs_region;
if (!clip_text && icon_align_rtl_checked != ALIGN_CENTER) {
_size.width -= text_buf->get_size().width;
}
@@ -276,7 +276,7 @@ void Button::_notification(int p_what) {
}
}
- Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant("hseparation"), 0) : Point2();
+ Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant(SNAME("hseparation")), 0) : Point2();
if (align_rtl_checked == ALIGN_CENTER && icon_align_rtl_checked == ALIGN_CENTER) {
icon_ofs.x = 0.0;
}
@@ -286,10 +286,10 @@ void Button::_notification(int p_what) {
int text_width = clip_text ? MIN(text_clip, text_buf->get_size().x) : text_buf->get_size().x;
if (_internal_margin[SIDE_LEFT] > 0) {
- text_clip -= _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation");
+ text_clip -= _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation"));
}
if (_internal_margin[SIDE_RIGHT] > 0) {
- text_clip -= _internal_margin[SIDE_RIGHT] + get_theme_constant("hseparation");
+ text_clip -= _internal_margin[SIDE_RIGHT] + get_theme_constant(SNAME("hseparation"));
}
Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - text_buf->get_size() - Point2(_internal_margin[SIDE_RIGHT] - _internal_margin[SIDE_LEFT], 0)) / 2.0;
@@ -300,7 +300,7 @@ void Button::_notification(int p_what) {
icon_ofs.x = 0.0;
}
if (_internal_margin[SIDE_LEFT] > 0) {
- text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation");
+ text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation"));
} else {
text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x;
}
@@ -317,7 +317,7 @@ void Button::_notification(int p_what) {
} break;
case ALIGN_RIGHT: {
if (_internal_margin[SIDE_RIGHT] > 0) {
- text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation");
+ text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant(SNAME("hseparation"));
} else {
text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width;
}
@@ -328,8 +328,8 @@ void Button::_notification(int p_what) {
} break;
}
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
if (outline_size > 0 && font_outline_color.a > 0) {
text_buf->draw_outline(ci, text_ofs, outline_size, font_outline_color);
}
@@ -340,8 +340,8 @@ void Button::_notification(int p_what) {
}
void Button::_shape() {
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
text_buf->clear();
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index c0650a8f3f..d93107df2d 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -33,12 +33,12 @@
#include "servers/rendering_server.h"
Size2 CheckBox::get_icon_size() const {
- Ref<Texture2D> checked = Control::get_theme_icon("checked");
- Ref<Texture2D> checked_disabled = Control::get_theme_icon("checked_disabled");
- Ref<Texture2D> unchecked = Control::get_theme_icon("unchecked");
- Ref<Texture2D> unchecked_disabled = Control::get_theme_icon("unchecked_disabled");
- Ref<Texture2D> radio_checked = Control::get_theme_icon("radio_checked");
- Ref<Texture2D> radio_unchecked = Control::get_theme_icon("radio_unchecked");
+ Ref<Texture2D> checked = Control::get_theme_icon(SNAME("checked"));
+ Ref<Texture2D> checked_disabled = Control::get_theme_icon(SNAME("checked_disabled"));
+ Ref<Texture2D> unchecked = Control::get_theme_icon(SNAME("unchecked"));
+ Ref<Texture2D> unchecked_disabled = Control::get_theme_icon(SNAME("unchecked_disabled"));
+ Ref<Texture2D> radio_checked = Control::get_theme_icon(SNAME("radio_checked"));
+ Ref<Texture2D> radio_unchecked = Control::get_theme_icon(SNAME("radio_unchecked"));
Size2 tex_size = Size2(0, 0);
if (!checked.is_null()) {
@@ -61,9 +61,9 @@ Size2 CheckBox::get_minimum_size() const {
Size2 tex_size = get_icon_size();
minsize.width += tex_size.width;
if (get_text().length() > 0) {
- minsize.width += get_theme_constant("hseparation");
+ minsize.width += get_theme_constant(SNAME("hseparation"));
}
- Ref<StyleBox> sb = get_theme_stylebox("normal");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM));
return minsize;
@@ -83,7 +83,7 @@ void CheckBox::_notification(int p_what) {
Ref<Texture2D> on = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_checked" : "checked", is_disabled() ? "_disabled" : ""));
Ref<Texture2D> off = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_unchecked" : "unchecked", is_disabled() ? "_disabled" : ""));
- Ref<StyleBox> sb = get_theme_stylebox("normal");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
Vector2 ofs;
if (is_layout_rtl()) {
@@ -91,7 +91,7 @@ void CheckBox::_notification(int p_what) {
} else {
ofs.x = sb->get_margin(SIDE_LEFT);
}
- ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant("check_vadjust");
+ ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant(SNAME("check_vadjust"));
if (is_pressed()) {
on->draw(ci, ofs);
diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp
index a8bf449355..162a256d23 100644
--- a/scene/gui/check_button.cpp
+++ b/scene/gui/check_button.cpp
@@ -52,9 +52,9 @@ Size2 CheckButton::get_minimum_size() const {
Size2 tex_size = get_icon_size();
minsize.width += tex_size.width;
if (get_text().length() > 0) {
- minsize.width += get_theme_constant("hseparation");
+ minsize.width += get_theme_constant(SNAME("hseparation"));
}
- Ref<StyleBox> sb = get_theme_stylebox("normal");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM));
return minsize;
@@ -86,7 +86,7 @@ void CheckButton::_notification(int p_what) {
off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off");
}
- Ref<StyleBox> sb = get_theme_stylebox("normal");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
Vector2 ofs;
Size2 tex_size = get_icon_size();
@@ -95,7 +95,7 @@ void CheckButton::_notification(int p_what) {
} else {
ofs.x = get_size().width - (tex_size.width + sb->get_margin(SIDE_RIGHT));
}
- ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant("check_vadjust");
+ ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant(SNAME("check_vadjust"));
if (is_pressed()) {
on->draw(ci, ofs);
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index ba1534ed5c..be5e0bf4e5 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -50,28 +50,28 @@ void CodeEdit::_notification(int p_what) {
set_gutter_width(line_number_gutter, (line_number_digits + 1) * cache.font->get_char_size('0', 0, cache.font_size).width);
set_gutter_width(fold_gutter, get_row_height() / 1.2);
- breakpoint_color = get_theme_color("breakpoint_color");
- breakpoint_icon = get_theme_icon("breakpoint");
+ breakpoint_color = get_theme_color(SNAME("breakpoint_color"));
+ breakpoint_icon = get_theme_icon(SNAME("breakpoint"));
- bookmark_color = get_theme_color("bookmark_color");
- bookmark_icon = get_theme_icon("bookmark");
+ bookmark_color = get_theme_color(SNAME("bookmark_color"));
+ bookmark_icon = get_theme_icon(SNAME("bookmark"));
- executing_line_color = get_theme_color("executing_line_color");
- executing_line_icon = get_theme_icon("executing_line");
+ executing_line_color = get_theme_color(SNAME("executing_line_color"));
+ executing_line_icon = get_theme_icon(SNAME("executing_line"));
- line_number_color = get_theme_color("line_number_color");
+ line_number_color = get_theme_color(SNAME("line_number_color"));
- folding_color = get_theme_color("code_folding_color");
- can_fold_icon = get_theme_icon("can_fold");
- folded_icon = get_theme_icon("folded");
+ folding_color = get_theme_color(SNAME("code_folding_color"));
+ can_fold_icon = get_theme_icon(SNAME("can_fold"));
+ folded_icon = get_theme_icon(SNAME("folded"));
- code_completion_max_width = get_theme_constant("completion_max_width") * cache.font->get_char_size('x').x;
- code_completion_max_lines = get_theme_constant("completion_lines");
- code_completion_scroll_width = get_theme_constant("completion_scroll_width");
- code_completion_scroll_color = get_theme_color("completion_scroll_color");
- code_completion_background_color = get_theme_color("completion_background_color");
- code_completion_selected_color = get_theme_color("completion_selected_color");
- code_completion_existing_color = get_theme_color("completion_existing_color");
+ code_completion_max_width = get_theme_constant(SNAME("completion_max_width")) * cache.font->get_char_size('x').x;
+ code_completion_max_lines = get_theme_constant(SNAME("completion_lines"));
+ code_completion_scroll_width = get_theme_constant(SNAME("completion_scroll_width"));
+ code_completion_scroll_color = get_theme_color(SNAME("completion_scroll_color"));
+ code_completion_background_color = get_theme_color(SNAME("completion_background_color"));
+ code_completion_selected_color = get_theme_color(SNAME("completion_selected_color"));
+ code_completion_existing_color = get_theme_color(SNAME("completion_existing_color"));
} break;
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
@@ -81,11 +81,11 @@ void CodeEdit::_notification(int p_what) {
bool code_completion_below = false;
if (caret_visible && code_completion_active && code_completion_options.size() > 0) {
- Ref<StyleBox> csb = get_theme_stylebox("completion");
+ Ref<StyleBox> csb = get_theme_stylebox(SNAME("completion"));
const int code_completion_options_count = code_completion_options.size();
const int lines = MIN(code_completion_options_count, code_completion_max_lines);
- const int icon_hsep = get_theme_constant("hseparation", "ItemList");
+ const int icon_hsep = get_theme_constant(SNAME("hseparation"), SNAME("ItemList"));
const Size2 icon_area_size(row_height, row_height);
code_completion_rect.size.width = code_completion_longest_line + icon_hsep + icon_area_size.width + 2;
@@ -164,8 +164,8 @@ void CodeEdit::_notification(int p_what) {
if (caret_visible && code_hint != "" && (!code_completion_active || (code_completion_below != code_hint_draw_below))) {
const Ref<Font> font = cache.font;
const int font_height = font->get_height(cache.font_size);
- Ref<StyleBox> sb = get_theme_stylebox("panel", "TooltipPanel");
- Color font_color = get_theme_color("font_color", "TooltipLabel");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel"));
+ Color font_color = get_theme_color(SNAME("font_color"), SNAME("TooltipLabel"));
Vector<String> code_hint_lines = code_hint.split("\n");
int line_count = code_hint_lines.size();
@@ -969,7 +969,7 @@ void CodeEdit::set_line_as_breakpoint(int p_line, bool p_breakpointed) {
} else if (breakpointed_lines.has(p_line)) {
breakpointed_lines.erase(p_line);
}
- emit_signal("breakpoint_toggled", p_line);
+ emit_signal(SNAME("breakpoint_toggled"), p_line);
update();
}
@@ -1551,7 +1551,7 @@ void CodeEdit::request_code_completion(bool p_force) {
}
if (p_force) {
- emit_signal("request_code_completion");
+ emit_signal(SNAME("request_code_completion"));
return;
}
@@ -1559,9 +1559,9 @@ void CodeEdit::request_code_completion(bool p_force) {
int ofs = CLAMP(cursor_get_column(), 0, line.length());
if (ofs > 0 && (is_in_string(cursor_get_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(String::chr(line[ofs - 1])))) {
- emit_signal("request_code_completion");
+ emit_signal(SNAME("request_code_completion"));
} else if (ofs > 1 && line[ofs - 1] == ' ' && code_completion_prefixes.has(String::chr(line[ofs - 2]))) {
- emit_signal("request_code_completion");
+ emit_signal(SNAME("request_code_completion"));
}
}
@@ -2128,7 +2128,7 @@ int CodeEdit::_is_in_delimiter(int p_line, int p_column, DelimiterType p_type) c
int region = (p_line <= 0 || delimiter_cache[p_line - 1].size() < 1) ? -1 : delimiter_cache[p_line - 1].back()->value();
bool in_region = region != -1 && delimiters[region].type == p_type;
for (Map<int, int>::Element *E = delimiter_cache[p_line].front(); E; E = E->next()) {
- /* If column is specified, loop untill the key is larger then the column. */
+ /* If column is specified, loop until the key is larger then the column. */
if (p_column != -1) {
if (E->key() > p_column) {
break;
@@ -2138,7 +2138,7 @@ int CodeEdit::_is_in_delimiter(int p_line, int p_column, DelimiterType p_type) c
continue;
}
- /* If no column, calulate if the entire line is a region */
+ /* If no column, calculate if the entire line is a region */
/* excluding whitespace. */
const String line = get_line(p_line);
if (!in_region) {
@@ -2288,14 +2288,14 @@ void CodeEdit::_filter_code_completion_candidates() {
TypedArray<Dictionary> completion_options_sources;
completion_options_sources.resize(code_completion_option_sources.size());
int i = 0;
- for (List<ScriptCodeCompletionOption>::Element *E = code_completion_option_sources.front(); E; E = E->next()) {
+ for (const ScriptCodeCompletionOption &E : code_completion_option_sources) {
Dictionary option;
- option["kind"] = E->get().kind;
- option["display_text"] = E->get().display;
- option["insert_text"] = E->get().insert_text;
- option["font_color"] = E->get().font_color;
- option["icon"] = E->get().icon;
- option["default_value"] = E->get().default_value;
+ option["kind"] = E.kind;
+ option["display_text"] = E.display;
+ option["insert_text"] = E.insert_text;
+ option["font_color"] = E.font_color;
+ option["icon"] = E.icon;
+ option["default_value"] = E.default_value;
completion_options_sources[i] = option;
i++;
}
@@ -2406,9 +2406,7 @@ void CodeEdit::_filter_code_completion_candidates() {
int max_width = 0;
String string_to_complete_lower = string_to_complete.to_lower();
- for (List<ScriptCodeCompletionOption>::Element *E = code_completion_option_sources.front(); E; E = E->next()) {
- ScriptCodeCompletionOption &option = E->get();
-
+ for (ScriptCodeCompletionOption &option : code_completion_option_sources) {
if (single_quote && option.display.is_quoted()) {
option.display = option.display.unquote().quote("'");
}
@@ -2527,16 +2525,15 @@ void CodeEdit::_lines_edited_from(int p_from_line, int p_to_line) {
int line_count = (p_to_line - p_from_line);
List<int> breakpoints;
breakpointed_lines.get_key_list(&breakpoints);
- for (const List<int>::Element *E = breakpoints.front(); E; E = E->next()) {
- int line = E->get();
+ for (const int line : breakpoints) {
if (line <= from_line) {
continue;
}
breakpointed_lines.erase(line);
- emit_signal("breakpoint_toggled", line);
+ emit_signal(SNAME("breakpoint_toggled"), line);
if (line_count > 0 || line >= p_from_line) {
- emit_signal("breakpoint_toggled", line + line_count);
+ emit_signal(SNAME("breakpoint_toggled"), line + line_count);
breakpointed_lines[line + line_count] = true;
continue;
}
@@ -2562,7 +2559,7 @@ CodeEdit::CodeEdit() {
set_gutter_name(gutter_idx, "main_gutter");
set_gutter_draw(gutter_idx, false);
set_gutter_overwritable(gutter_idx, true);
- set_gutter_type(gutter_idx, GUTTER_TPYE_CUSTOM);
+ set_gutter_type(gutter_idx, GUTTER_TYPE_CUSTOM);
set_gutter_custom_draw(gutter_idx, this, "_main_gutter_draw_callback");
gutter_idx++;
@@ -2570,7 +2567,7 @@ CodeEdit::CodeEdit() {
add_gutter();
set_gutter_name(gutter_idx, "line_numbers");
set_gutter_draw(gutter_idx, false);
- set_gutter_type(gutter_idx, GUTTER_TPYE_CUSTOM);
+ set_gutter_type(gutter_idx, GUTTER_TYPE_CUSTOM);
set_gutter_custom_draw(gutter_idx, this, "_line_number_draw_callback");
gutter_idx++;
@@ -2578,7 +2575,7 @@ CodeEdit::CodeEdit() {
add_gutter();
set_gutter_name(gutter_idx, "fold_gutter");
set_gutter_draw(gutter_idx, false);
- set_gutter_type(gutter_idx, GUTTER_TPYE_CUSTOM);
+ set_gutter_type(gutter_idx, GUTTER_TYPE_CUSTOM);
set_gutter_custom_draw(gutter_idx, this, "_fold_gutter_draw_callback");
gutter_idx++;
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 659d14ae70..261480bcdd 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -45,14 +45,14 @@ List<Color> ColorPicker::preset_cache;
void ColorPicker::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
- btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker"));
- bt_add_preset->set_icon(get_theme_icon("add_preset"));
+ btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker")));
+ bt_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
_update_controls();
} break;
case NOTIFICATION_ENTER_TREE: {
- btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker"));
- bt_add_preset->set_icon(get_theme_icon("add_preset"));
+ btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker")));
+ bt_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
_update_controls();
_update_color();
@@ -75,13 +75,13 @@ void ColorPicker::_notification(int p_what) {
} break;
case NOTIFICATION_PARENTED: {
for (int i = 0; i < 4; i++) {
- set_offset((Side)i, get_offset((Side)i) + get_theme_constant("margin"));
+ set_offset((Side)i, get_offset((Side)i) + get_theme_constant(SNAME("margin")));
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
Popup *p = Object::cast_to<Popup>(get_parent());
if (p) {
- p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant("margin") * 2, get_combined_minimum_size().height + get_theme_constant("margin") * 2));
+ p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant(SNAME("margin")) * 2, get_combined_minimum_size().height + get_theme_constant(SNAME("margin")) * 2));
}
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
@@ -97,43 +97,49 @@ Ref<Shader> ColorPicker::circle_shader;
void ColorPicker::init_shaders() {
wheel_shader.instantiate();
- wheel_shader->set_code(
- "shader_type canvas_item;"
- "void fragment() {"
- " float x = UV.x - 0.5;"
- " float y = UV.y - 0.5;"
- " float a = atan(y, x);"
- " x += 0.001;"
- " y += 0.001;"
- " float b = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);"
- " x -= 0.002;"
- " float b2 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);"
- " y -= 0.002;"
- " float b3 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);"
- " x += 0.002;"
- " float b4 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);"
- " COLOR = vec4(clamp((abs(fract(((a - TAU) / TAU) + vec3(3.0, 2.0, 1.0) / 3.0) * 6.0 - 3.0) - 1.0), 0.0, 1.0), (b + b2 + b3 + b4) / 4.00);"
- "}");
+ wheel_shader->set_code(R"(
+shader_type canvas_item;
+
+void fragment() {
+ float x = UV.x - 0.5;
+ float y = UV.y - 0.5;
+ float a = atan(y, x);
+ x += 0.001;
+ y += 0.001;
+ float b = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);
+ x -= 0.002;
+ float b2 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);
+ y -= 0.002;
+ float b3 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);
+ x += 0.002;
+ float b4 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);
+
+ COLOR = vec4(clamp((abs(fract(((a - TAU) / TAU) + vec3(3.0, 2.0, 1.0) / 3.0) * 6.0 - 3.0) - 1.0), 0.0, 1.0), (b + b2 + b3 + b4) / 4.00);
+}
+)");
circle_shader.instantiate();
- circle_shader->set_code(
- "shader_type canvas_item;"
- "uniform float v = 1.0;"
- "void fragment() {"
- " float x = UV.x - 0.5;"
- " float y = UV.y - 0.5;"
- " float a = atan(y, x);"
- " x += 0.001;"
- " y += 0.001;"
- " float b = float(sqrt(x * x + y * y) < 0.5);"
- " x -= 0.002;"
- " float b2 = float(sqrt(x * x + y * y) < 0.5);"
- " y -= 0.002;"
- " float b3 = float(sqrt(x * x + y * y) < 0.5);"
- " x += 0.002;"
- " float b4 = float(sqrt(x * x + y * y) < 0.5);"
- " COLOR = vec4(mix(vec3(1.0), clamp(abs(fract(vec3((a - TAU) / TAU) + vec3(1.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - vec3(3.0)) - vec3(1.0), 0.0, 1.0), ((float(sqrt(x * x + y * y)) * 2.0)) / 1.0) * vec3(v), (b + b2 + b3 + b4) / 4.00);"
- "}");
+ circle_shader->set_code(R"(
+shader_type canvas_item;
+
+uniform float v = 1.0;
+
+void fragment() {
+ float x = UV.x - 0.5;
+ float y = UV.y - 0.5;
+ float a = atan(y, x);
+ x += 0.001;
+ y += 0.001;
+ float b = float(sqrt(x * x + y * y) < 0.5);
+ x -= 0.002;
+ float b2 = float(sqrt(x * x + y * y) < 0.5);
+ y -= 0.002;
+ float b3 = float(sqrt(x * x + y * y) < 0.5);
+ x += 0.002;
+ float b4 = float(sqrt(x * x + y * y) < 0.5);
+
+ COLOR = vec4(mix(vec3(1.0), clamp(abs(fract(vec3((a - TAU) / TAU) + vec3(1.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - vec3(3.0)) - vec3(1.0), 0.0, 1.0), ((float(sqrt(x * x + y * y)) * 2.0)) / 1.0) * vec3(v), (b + b2 + b3 + b4) / 4.00);
+})");
}
void ColorPicker::finish_shaders() {
@@ -142,7 +148,7 @@ void ColorPicker::finish_shaders() {
}
void ColorPicker::set_focus_on_line_edit() {
- c_text->call_deferred("grab_focus");
+ c_text->call_deferred(SNAME("grab_focus"));
}
void ColorPicker::_update_controls() {
@@ -180,7 +186,7 @@ void ColorPicker::_update_controls() {
}
} else {
Ref<StyleBoxEmpty> style_box_empty(memnew(StyleBoxEmpty));
- Ref<Texture2D> bar_arrow = get_theme_icon("bar_arrow");
+ Ref<Texture2D> bar_arrow = get_theme_icon(SNAME("bar_arrow"));
for (int i = 0; i < 4; i++) {
scroll[i]->add_theme_icon_override("grabber", bar_arrow);
@@ -294,7 +300,7 @@ void ColorPicker::_value_changed(double) {
}
_set_pick_color(color, false);
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
}
void ColorPicker::_html_submitted(const String &p_html) {
@@ -313,7 +319,7 @@ void ColorPicker::_html_submitted(const String &p_html) {
}
set_pick_color(color);
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
}
void ColorPicker::_update_color(bool p_update_sliders) {
@@ -388,7 +394,7 @@ void ColorPicker::_text_type_toggled() {
text_is_constructor = !text_is_constructor;
if (text_is_constructor) {
text_type->set_text("");
- text_type->set_icon(get_theme_icon("Script", "EditorIcons"));
+ text_type->set_icon(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")));
c_text->set_editable(false);
} else {
@@ -537,7 +543,7 @@ void ColorPicker::_sample_input(const Ref<InputEvent> &p_event) {
// Revert to the old color when left-clicking the old color sample.
color = old_color;
_update_color();
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
}
}
}
@@ -554,28 +560,28 @@ 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("preset_bg", "ColorPicker"), rect_old, true);
+ sample->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), rect_old, true);
}
sample->draw_rect(rect_old, old_color);
if (old_color.r > 1 || old_color.g > 1 || old_color.b > 1) {
// Draw an indicator to denote that the old color is "overbright" and can't be displayed accurately in the preview.
- sample->draw_texture(get_theme_icon("overbright_indicator", "ColorPicker"), Point2());
+ sample->draw_texture(get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPicker")), Point2());
}
} else {
rect_new = Rect2(Point2(), Size2(sample->get_size().width, sample->get_size().height * 0.95));
}
if (color.a < 1.0) {
- sample->draw_texture_rect(get_theme_icon("preset_bg", "ColorPicker"), rect_new, true);
+ sample->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), rect_new, true);
}
sample->draw_rect(rect_new, color);
if (color.r > 1 || color.g > 1 || color.b > 1) {
// Draw an indicator to denote that the new color is "overbright" and can't be displayed accurately in the preview.
- sample->draw_texture(get_theme_icon("overbright_indicator", "ColorPicker"), Point2(uv_edit->get_size().width * 0.5, 0));
+ sample->draw_texture(get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPicker")), Point2(uv_edit->get_size().width * 0.5, 0));
}
}
@@ -649,7 +655,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
default: {
}
}
- Ref<Texture2D> cursor = get_theme_icon("picker_cursor", "ColorPicker");
+ Ref<Texture2D> cursor = get_theme_icon(SNAME("picker_cursor"), SNAME("ColorPicker"));
int x;
int y;
if (picker_type == SHAPE_VHS_CIRCLE) {
@@ -679,7 +685,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
} else if (p_which == 1) {
if (picker_type == SHAPE_HSV_RECTANGLE) {
- Ref<Texture2D> hue = get_theme_icon("color_hue", "ColorPicker");
+ Ref<Texture2D> hue = get_theme_icon(SNAME("color_hue"), SNAME("ColorPicker"));
c->draw_texture_rect(hue, Rect2(Point2(), c->get_size()));
int y = c->get_size().y - c->get_size().y * (1.0 - h);
Color col;
@@ -728,7 +734,7 @@ void ColorPicker::_slider_draw(int p_which) {
#endif
if (p_which == 3) {
- scroll[p_which]->draw_texture_rect(get_theme_icon("preset_bg", "ColorPicker"), Rect2(Point2(0, margin), Size2(size.x, margin)), true);
+ scroll[p_which]->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), Rect2(Point2(0, margin), Size2(size.x, margin)), true);
left_color = color;
left_color.a = 0;
@@ -740,7 +746,7 @@ void ColorPicker::_slider_draw(int p_which) {
}
if (hsv_mode_enabled) {
if (p_which == 0) {
- Ref<Texture2D> hue = get_theme_icon("color_hue", "ColorPicker");
+ Ref<Texture2D> hue = get_theme_icon(SNAME("color_hue"), SNAME("ColorPicker"));
scroll[p_which]->draw_set_transform(Point2(), -Math_PI / 2, Size2(1.0, 1.0));
scroll[p_which]->draw_texture_rect(hue, Rect2(Vector2(margin * -2, 0), Vector2(scroll[p_which]->get_size().x, margin)), false, Color(1, 1, 1), true);
return;
@@ -826,10 +832,10 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
set_pick_color(color);
_update_color();
if (!deferred_mode_enabled) {
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
}
} else if (deferred_mode_enabled && !bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_LEFT) {
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
changing_color = false;
spinning = false;
} else {
@@ -873,7 +879,7 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
set_pick_color(color);
_update_color();
if (!deferred_mode_enabled) {
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
}
}
}
@@ -898,9 +904,9 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
set_pick_color(color);
_update_color();
if (!deferred_mode_enabled) {
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
} else if (!bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_LEFT) {
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
}
}
@@ -921,7 +927,7 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
set_pick_color(color);
_update_color();
if (!deferred_mode_enabled) {
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
}
}
}
@@ -941,12 +947,12 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
}
set_pick_color(presets[index]);
_update_color();
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), 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("preset_removed", clicked_preset);
+ emit_signal(SNAME("preset_removed"), clicked_preset);
bt_add_preset->show();
}
}
@@ -972,7 +978,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> bev = p_event;
if (bev.is_valid() && bev->get_button_index() == MOUSE_BUTTON_LEFT && !bev->is_pressed()) {
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
screen->hide();
}
@@ -995,7 +1001,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
void ColorPicker::_add_preset_pressed() {
add_preset(color);
- emit_signal("preset_added", color);
+ emit_signal(SNAME("preset_added"), color);
}
void ColorPicker::_screen_pick_pressed() {
@@ -1012,7 +1018,7 @@ void ColorPicker::_screen_pick_pressed() {
screen->set_default_cursor_shape(CURSOR_POINTING_HAND);
screen->connect("gui_input", callable_mp(this, &ColorPicker::_screen_input));
// It immediately toggles off in the first press otherwise.
- screen->call_deferred("connect", "hidden", Callable(btn_pick, "set_pressed"), varray(false));
+ screen->call_deferred(SNAME("connect"), "hidden", Callable(btn_pick, "set_pressed"), varray(false));
}
screen->raise();
#ifndef _MSC_VER
@@ -1048,7 +1054,7 @@ void ColorPicker::_focus_exit() {
}
void ColorPicker::_html_focus_exit() {
- if (c_text->get_menu()->is_visible()) {
+ if (c_text->is_menu_visible()) {
return;
}
_html_submitted(c_text->get_text());
@@ -1131,7 +1137,7 @@ ColorPicker::ColorPicker() :
uv_edit->set_mouse_filter(MOUSE_FILTER_PASS);
uv_edit->set_h_size_flags(SIZE_EXPAND_FILL);
uv_edit->set_v_size_flags(SIZE_EXPAND_FILL);
- uv_edit->set_custom_minimum_size(Size2(get_theme_constant("sv_width"), get_theme_constant("sv_height")));
+ uv_edit->set_custom_minimum_size(Size2(get_theme_constant(SNAME("sv_width")), get_theme_constant(SNAME("sv_height"))));
uv_edit->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw), make_binds(0, uv_edit));
HBoxContainer *hb_smpl = memnew(HBoxContainer);
@@ -1161,7 +1167,7 @@ ColorPicker::ColorPicker() :
HBoxContainer *hbc = memnew(HBoxContainer);
labels[i] = memnew(Label());
- labels[i]->set_custom_minimum_size(Size2(get_theme_constant("label_width"), 0));
+ labels[i]->set_custom_minimum_size(Size2(get_theme_constant(SNAME("label_width")), 0));
labels[i]->set_v_size_flags(SIZE_SHRINK_CENTER);
hbc->add_child(labels[i]);
@@ -1220,7 +1226,7 @@ ColorPicker::ColorPicker() :
wheel_edit->set_h_size_flags(SIZE_EXPAND_FILL);
wheel_edit->set_v_size_flags(SIZE_EXPAND_FILL);
- wheel_edit->set_custom_minimum_size(Size2(get_theme_constant("sv_width"), get_theme_constant("sv_height")));
+ wheel_edit->set_custom_minimum_size(Size2(get_theme_constant(SNAME("sv_width")), get_theme_constant(SNAME("sv_height"))));
hb_edit->add_child(wheel_edit);
wheel_mat.instantiate();
@@ -1245,7 +1251,7 @@ ColorPicker::ColorPicker() :
wheel_uv->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw), make_binds(0, wheel_uv));
hb_edit->add_child(w_edit);
- w_edit->set_custom_minimum_size(Size2(get_theme_constant("h_width"), 0));
+ w_edit->set_custom_minimum_size(Size2(get_theme_constant(SNAME("h_width")), 0));
w_edit->set_h_size_flags(SIZE_FILL);
w_edit->set_v_size_flags(SIZE_EXPAND_FILL);
w_edit->connect("gui_input", callable_mp(this, &ColorPicker::_w_input));
@@ -1285,11 +1291,11 @@ void ColorPickerButton::_about_to_popup() {
void ColorPickerButton::_color_changed(const Color &p_color) {
color = p_color;
update();
- emit_signal("color_changed", color);
+ emit_signal(SNAME("color_changed"), color);
}
void ColorPickerButton::_modal_closed() {
- emit_signal("popup_closed");
+ emit_signal(SNAME("popup_closed"));
set_pressed(false);
}
@@ -1327,14 +1333,14 @@ void ColorPickerButton::pressed() {
void ColorPickerButton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- const Ref<StyleBox> normal = get_theme_stylebox("normal");
+ const Ref<StyleBox> normal = get_theme_stylebox(SNAME("normal"));
const Rect2 r = Rect2(normal->get_offset(), get_size() - normal->get_minimum_size());
- draw_texture_rect(Control::get_theme_icon("bg", "ColorPickerButton"), r, true);
+ draw_texture_rect(Control::get_theme_icon(SNAME("bg"), SNAME("ColorPickerButton")), r, true);
draw_rect(r, color);
if (color.r > 1 || color.g > 1 || 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("overbright_indicator", "ColorPicker"), normal->get_offset());
+ draw_texture(Control::get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPicker")), normal->get_offset());
}
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
@@ -1399,7 +1405,7 @@ void ColorPickerButton::_update_picker() {
picker->set_pick_color(color);
picker->set_edit_alpha(edit_alpha);
picker->set_display_old_color(true);
- emit_signal("picker_created");
+ emit_signal(SNAME("picker_created"));
}
}
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index dea69aae6b..c97434f69b 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -47,9 +47,9 @@ void Container::add_child_notify(Node *p_child) {
return;
}
- control->connect("size_flags_changed", callable_mp(this, &Container::queue_sort));
- control->connect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed));
- control->connect("visibility_changed", callable_mp(this, &Container::_child_minsize_changed));
+ control->connect(SNAME("size_flags_changed"), callable_mp(this, &Container::queue_sort));
+ control->connect(SNAME("minimum_size_changed"), callable_mp(this, &Container::_child_minsize_changed));
+ control->connect(SNAME("visibility_changed"), callable_mp(this, &Container::_child_minsize_changed));
minimum_size_changed();
queue_sort();
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index d42b505f7b..c19ee849d3 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -339,96 +339,123 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const {
void Control::_get_property_list(List<PropertyInfo> *p_list) const {
Ref<Theme> theme = Theme::get_default();
- /* Using the default theme since the properties below are meant for editor only
- if (data.theme.is_valid()) {
- theme = data.theme;
- } else {
- theme = Theme::get_default();
-
- }*/
{
List<StringName> names;
theme->get_icon_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.icon_override.has(E->get())) {
+ if (data.icon_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage));
}
}
{
List<StringName> names;
theme->get_stylebox_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.style_override.has(E->get())) {
+ if (data.style_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage));
}
}
{
List<StringName> names;
theme->get_font_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.font_override.has(E->get())) {
+ if (data.font_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", usage));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage));
}
}
{
List<StringName> names;
theme->get_font_size_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.font_size_override.has(E->get())) {
+ if (data.font_size_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::INT, "custom_font_sizes/" + E->get(), PROPERTY_HINT_NONE, "", usage));
+ p_list->push_back(PropertyInfo(Variant::INT, "custom_font_sizes/" + E, PROPERTY_HINT_NONE, "", usage));
}
}
{
List<StringName> names;
theme->get_color_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.color_override.has(E->get())) {
+ if (data.color_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", usage));
+ p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E, PROPERTY_HINT_NONE, "", usage));
}
}
{
List<StringName> names;
theme->get_constant_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.constant_override.has(E->get())) {
+ if (data.constant_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", usage));
+ p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E, PROPERTY_HINT_RANGE, "-16384,16384", usage));
}
}
}
+void Control::_validate_property(PropertyInfo &property) const {
+ if (property.name == "theme_type_variation") {
+ List<StringName> names;
+
+ // Only the default theme and the project theme are used for the list of options.
+ // This is an imposed limitation to simplify the logic needed to leverage those options.
+ Theme::get_default()->get_type_variation_list(get_class_name(), &names);
+ if (Theme::get_project_default().is_valid()) {
+ Theme::get_project_default()->get_type_variation_list(get_class_name(), &names);
+ }
+ names.sort_custom<StringName::AlphCompare>();
+
+ Vector<StringName> unique_names;
+ String hint_string;
+ for (const StringName &E : names) {
+ // Skip duplicate values.
+ if (unique_names.has(E)) {
+ continue;
+ }
+
+ hint_string += String(E) + ",";
+ unique_names.append(E);
+ }
+
+ property.hint_string = hint_string;
+ }
+}
+
Control *Control::get_parent_control() const {
return data.parent;
}
+Window *Control::get_parent_window() const {
+ return data.parent_window;
+}
+
void Control::set_layout_direction(Control::LayoutDirection p_direction) {
ERR_FAIL_INDEX((int)p_direction, 4);
data.layout_dir = p_direction;
+ data.is_rtl_dirty = true;
+
propagate_notification(NOTIFICATION_LAYOUT_DIRECTION_CHANGED);
}
@@ -437,29 +464,35 @@ Control::LayoutDirection Control::get_layout_direction() const {
}
bool Control::is_layout_rtl() const {
- if (data.layout_dir == LAYOUT_DIRECTION_INHERITED) {
- Window *parent_window = Object::cast_to<Window>(get_parent());
- Control *parent_control = get_parent_control();
- if (parent_control) {
- return parent_control->is_layout_rtl();
- } else if (parent_window) {
- return parent_window->is_layout_rtl();
- } else {
- if (GLOBAL_GET("internationalization/rendering/force_right_to_left_layout_direction")) {
- return true;
+ if (data.is_rtl_dirty) {
+ const_cast<Control *>(this)->data.is_rtl_dirty = false;
+ if (data.layout_dir == LAYOUT_DIRECTION_INHERITED) {
+ Window *parent_window = get_parent_window();
+ Control *parent_control = get_parent_control();
+ if (parent_control) {
+ const_cast<Control *>(this)->data.is_rtl = parent_control->is_layout_rtl();
+ } else if (parent_window) {
+ const_cast<Control *>(this)->data.is_rtl = parent_window->is_layout_rtl();
+ } else {
+ if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
+ const_cast<Control *>(this)->data.is_rtl = true;
+ } else {
+ String locale = TranslationServer::get_singleton()->get_tool_locale();
+ const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale);
+ }
}
- String locale = TranslationServer::get_singleton()->get_tool_locale();
- return TS->is_locale_right_to_left(locale);
- }
- } else if (data.layout_dir == LAYOUT_DIRECTION_LOCALE) {
- if (GLOBAL_GET("internationalization/rendering/force_right_to_left_layout_direction")) {
- return true;
+ } else if (data.layout_dir == LAYOUT_DIRECTION_LOCALE) {
+ if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
+ const_cast<Control *>(this)->data.is_rtl = true;
+ } else {
+ String locale = TranslationServer::get_singleton()->get_tool_locale();
+ const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale);
+ }
+ } else {
+ const_cast<Control *>(this)->data.is_rtl = (data.layout_dir == LAYOUT_DIRECTION_RTL);
}
- String locale = TranslationServer::get_singleton()->get_tool_locale();
- return TS->is_locale_right_to_left(locale);
- } else {
- return (data.layout_dir == LAYOUT_DIRECTION_RTL);
}
+ return data.is_rtl;
}
void Control::_clear_size_warning() {
@@ -509,6 +542,7 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_POST_ENTER_TREE: {
data.minimum_size_valid = false;
+ data.is_rtl_dirty = true;
_size_changed();
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -522,6 +556,8 @@ void Control::_notification(int p_notification) {
case NOTIFICATION_ENTER_CANVAS: {
data.parent = Object::cast_to<Control>(get_parent());
+ data.parent_window = Object::cast_to<Window>(get_parent());
+ data.is_rtl_dirty = true;
Node *parent = this; //meh
Control *parent_control = nullptr;
@@ -586,6 +622,8 @@ void Control::_notification(int p_notification) {
data.parent = nullptr;
data.parent_canvas_item = nullptr;
+ data.parent_window = nullptr;
+ data.is_rtl_dirty = true;
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
@@ -645,6 +683,7 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
+ data.is_rtl_dirty = true;
_size_changed();
} break;
}
@@ -766,13 +805,13 @@ T Control::get_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner
Window *theme_owner_window = p_theme_owner_window;
while (theme_owner || theme_owner_window) {
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E->get())) {
- return theme_owner->data.theme->get_theme_item(p_data_type, p_name, E->get());
+ for (const StringName &E : p_theme_types) {
+ if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E)) {
+ return theme_owner->data.theme->get_theme_item(p_data_type, p_name, E);
}
- if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E->get())) {
- return theme_owner_window->theme->get_theme_item(p_data_type, p_name, E->get());
+ if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E)) {
+ return theme_owner_window->theme->get_theme_item(p_data_type, p_name, E);
}
}
@@ -795,17 +834,17 @@ T Control::get_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner
// Secondly, check the project-defined Theme resource.
if (Theme::get_project_default().is_valid()) {
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E->get())) {
- return Theme::get_project_default()->get_theme_item(p_data_type, p_name, E->get());
+ for (const StringName &E : p_theme_types) {
+ if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E)) {
+ return Theme::get_project_default()->get_theme_item(p_data_type, p_name, E);
}
}
}
// Lastly, fall back on the items defined in the default Theme, if they exist.
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (Theme::get_default()->has_theme_item(p_data_type, p_name, E->get())) {
- return Theme::get_default()->get_theme_item(p_data_type, p_name, E->get());
+ for (const StringName &E : p_theme_types) {
+ if (Theme::get_default()->has_theme_item(p_data_type, p_name, E)) {
+ return Theme::get_default()->get_theme_item(p_data_type, p_name, E);
}
}
// If they don't exist, use any type to return the default/empty value.
@@ -821,12 +860,12 @@ bool Control::has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_ow
Window *theme_owner_window = p_theme_owner_window;
while (theme_owner || theme_owner_window) {
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E->get())) {
+ for (const StringName &E : p_theme_types) {
+ if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E)) {
return true;
}
- if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E->get())) {
+ if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E)) {
return true;
}
}
@@ -850,16 +889,16 @@ bool Control::has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_ow
// Secondly, check the project-defined Theme resource.
if (Theme::get_project_default().is_valid()) {
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E->get())) {
+ for (const StringName &E : p_theme_types) {
+ if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E)) {
return true;
}
}
}
// Lastly, fall back on the items defined in the default Theme, if they exist.
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (Theme::get_default()->has_theme_item(p_data_type, p_name, E->get())) {
+ for (const StringName &E : p_theme_types) {
+ if (Theme::get_default()->has_theme_item(p_data_type, p_name, E)) {
return true;
}
}
@@ -867,18 +906,19 @@ bool Control::has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_ow
}
void Control::_get_theme_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
- if (data.theme_custom_type != StringName()) {
- p_list->push_back(data.theme_custom_type);
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
+ if (Theme::get_project_default().is_valid() && Theme::get_project_default()->get_type_variation_base(data.theme_type_variation) != StringName()) {
+ Theme::get_project_default()->get_type_dependencies(get_class_name(), data.theme_type_variation, p_list);
+ } else {
+ Theme::get_default()->get_type_dependencies(get_class_name(), data.theme_type_variation, p_list);
}
- Theme::get_type_dependencies(get_class_name(), p_list);
} else {
- Theme::get_type_dependencies(p_theme_type, p_list);
+ Theme::get_default()->get_type_dependencies(p_theme_type, StringName(), p_list);
}
}
Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
const Ref<Texture2D> *tex = data.icon_override.getptr(p_name);
if (tex) {
return *tex;
@@ -891,7 +931,7 @@ Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringNam
}
Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
if (style) {
return *style;
@@ -904,7 +944,7 @@ Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const String
}
Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
const Ref<Font> *font = data.font_override.getptr(p_name);
if (font) {
return *font;
@@ -917,7 +957,7 @@ Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_
}
int Control::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
const int *font_size = data.font_size_override.getptr(p_name);
if (font_size) {
return *font_size;
@@ -930,7 +970,7 @@ int Control::get_theme_font_size(const StringName &p_name, const StringName &p_t
}
Color Control::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
const Color *color = data.color_override.getptr(p_name);
if (color) {
return *color;
@@ -943,7 +983,7 @@ Color Control::get_theme_color(const StringName &p_name, const StringName &p_the
}
int Control::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
const int *constant = data.constant_override.getptr(p_name);
if (constant) {
return *constant;
@@ -986,7 +1026,7 @@ bool Control::has_theme_constant_override(const StringName &p_name) const {
}
bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
if (has_theme_icon_override(p_name)) {
return true;
}
@@ -998,7 +1038,7 @@ bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme
}
bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
if (has_theme_stylebox_override(p_name)) {
return true;
}
@@ -1010,7 +1050,7 @@ bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_t
}
bool Control::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
if (has_theme_font_override(p_name)) {
return true;
}
@@ -1022,7 +1062,7 @@ bool Control::has_theme_font(const StringName &p_name, const StringName &p_theme
}
bool Control::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
if (has_theme_font_size_override(p_name)) {
return true;
}
@@ -1034,7 +1074,7 @@ bool Control::has_theme_font_size(const StringName &p_name, const StringName &p_
}
bool Control::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
if (has_theme_color_override(p_name)) {
return true;
}
@@ -1046,7 +1086,7 @@ bool Control::has_theme_color(const StringName &p_name, const StringName &p_them
}
bool Control::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_custom_type) {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
if (has_theme_constant_override(p_name)) {
return true;
}
@@ -1566,7 +1606,7 @@ void Control::set_rect(const Rect2 &p_rect) {
void Control::_set_size(const Size2 &p_size) {
#ifdef DEBUG_ENABLED
if (data.size_warning && (data.anchor[SIDE_LEFT] != data.anchor[SIDE_RIGHT] || data.anchor[SIDE_TOP] != data.anchor[SIDE_BOTTOM])) {
- WARN_PRINT("Nodes with non-equal opposite anchors will have their size overriden after _ready(). \nIf you want to set size, change the anchors or consider using set_deferred().");
+ WARN_PRINT("Nodes with non-equal opposite anchors will have their size overridden after _ready(). \nIf you want to set size, change the anchors or consider using set_deferred().");
}
#endif
set_size(p_size);
@@ -2031,13 +2071,13 @@ Ref<Theme> Control::get_theme() const {
return data.theme;
}
-void Control::set_theme_custom_type(const StringName &p_theme_type) {
- data.theme_custom_type = p_theme_type;
+void Control::set_theme_type_variation(const StringName &p_theme_type) {
+ data.theme_type_variation = p_theme_type;
_propagate_theme_changed(this, data.theme_owner, data.theme_owner_window);
}
-StringName Control::get_theme_custom_type() const {
- return data.theme_custom_type;
+StringName Control::get_theme_type_variation() const {
+ return data.theme_type_variation;
}
void Control::set_tooltip(const String &p_tooltip) {
@@ -2552,8 +2592,8 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List
}
sn.sort_custom<StringName::AlphCompare>();
- for (List<StringName>::Element *E = sn.front(); E; E = E->next()) {
- r_options->push_back(quote_style + E->get() + quote_style);
+ for (const StringName &E : sn) {
+ r_options->push_back(quote_style + E + quote_style);
}
}
}
@@ -2660,8 +2700,8 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Control::set_theme);
ClassDB::bind_method(D_METHOD("get_theme"), &Control::get_theme);
- ClassDB::bind_method(D_METHOD("set_theme_custom_type", "theme_type"), &Control::set_theme_custom_type);
- ClassDB::bind_method(D_METHOD("get_theme_custom_type"), &Control::get_theme_custom_type);
+ ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Control::set_theme_type_variation);
+ ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Control::get_theme_type_variation);
ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Control::add_theme_icon_override);
ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Control::add_theme_style_override);
@@ -2810,7 +2850,7 @@ void Control::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
ADD_GROUP("Theme", "theme_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
- ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_custom_type"), "set_theme_custom_type", "get_theme_custom_type");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
ADD_GROUP("", "");
BIND_ENUM_CONSTANT(FOCUS_NONE);
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 0642686a9f..3779f9b308 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -179,6 +179,8 @@ private:
GrowDirection v_grow = GROW_DIRECTION_END;
LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED;
+ bool is_rtl_dirty = true;
+ bool is_rtl = false;
real_t rotation = 0.0;
Vector2 scale = Vector2(1, 1);
@@ -202,7 +204,8 @@ private:
Ref<Theme> theme;
Control *theme_owner = nullptr;
Window *theme_owner_window = nullptr;
- StringName theme_custom_type;
+ Window *parent_window = nullptr;
+ StringName theme_type_variation;
String tooltip;
CursorShape default_cursor = CURSOR_ARROW;
@@ -279,8 +282,8 @@ protected:
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_notification);
-
static void _bind_methods();
+ virtual void _validate_property(PropertyInfo &property) const override;
//bind helpers
@@ -342,6 +345,7 @@ public:
Size2 get_custom_minimum_size() const;
Control *get_parent_control() const;
+ Window *get_parent_window() const;
void set_layout_direction(LayoutDirection p_direction);
LayoutDirection get_layout_direction() const;
@@ -402,8 +406,8 @@ public:
void set_theme(const Ref<Theme> &p_theme);
Ref<Theme> get_theme() const;
- void set_theme_custom_type(const StringName &p_theme_type);
- StringName get_theme_custom_type() const;
+ void set_theme_type_variation(const StringName &p_theme_type);
+ StringName get_theme_type_variation() const;
void set_h_size_flags(int p_flags);
int get_h_size_flags() const;
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index dceab00607..f5c764e9cc 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -76,7 +76,7 @@ void AcceptDialog::_notification(int p_what) {
} break;
case NOTIFICATION_THEME_CHANGED: {
- bg->add_theme_style_override("panel", bg->get_theme_stylebox("panel", "AcceptDialog"));
+ bg->add_theme_style_override("panel", bg->get_theme_stylebox(SNAME("panel"), SNAME("AcceptDialog")));
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -106,7 +106,7 @@ void AcceptDialog::_ok_pressed() {
set_visible(false);
}
ok_pressed();
- emit_signal("confirmed");
+ emit_signal(SNAME("confirmed"));
}
void AcceptDialog::_cancel_pressed() {
@@ -116,9 +116,9 @@ void AcceptDialog::_cancel_pressed() {
parent_visible = nullptr;
}
- call_deferred("hide");
+ call_deferred(SNAME("hide"));
- emit_signal("cancelled");
+ emit_signal(SNAME("cancelled"));
cancel_pressed();
@@ -148,11 +148,11 @@ bool AcceptDialog::get_hide_on_ok() const {
}
void AcceptDialog::set_autowrap(bool p_autowrap) {
- label->set_autowrap(p_autowrap);
+ label->set_autowrap_mode(p_autowrap ? Label::AUTOWRAP_WORD : Label::AUTOWRAP_OFF);
}
bool AcceptDialog::has_autowrap() {
- return label->has_autowrap();
+ return label->get_autowrap_mode() != Label::AUTOWRAP_OFF;
}
void AcceptDialog::register_text_enter(Control *p_line_edit) {
@@ -168,7 +168,7 @@ void AcceptDialog::_update_child_rects() {
if (label->get_text().is_empty()) {
label_size.height = 0;
}
- int margin = hbc->get_theme_constant("margin", "Dialogs");
+ int margin = hbc->get_theme_constant(SNAME("margin"), SNAME("Dialogs"));
Size2 size = get_size();
Size2 hminsize = hbc->get_combined_minimum_size();
@@ -200,7 +200,7 @@ void AcceptDialog::_update_child_rects() {
}
Size2 AcceptDialog::_get_contents_minimum_size() const {
- int margin = hbc->get_theme_constant("margin", "Dialogs");
+ int margin = hbc->get_theme_constant(SNAME("margin"), SNAME("Dialogs"));
Size2 minsize = label->get_combined_minimum_size();
for (int i = 0; i < get_child_count(); i++) {
@@ -230,7 +230,7 @@ Size2 AcceptDialog::_get_contents_minimum_size() const {
}
void AcceptDialog::_custom_action(const String &p_action) {
- emit_signal("custom_action", p_action);
+ emit_signal(SNAME("custom_action"), p_action);
custom_action(p_action);
}
@@ -326,8 +326,8 @@ AcceptDialog::AcceptDialog() {
hbc = memnew(HBoxContainer);
- int margin = hbc->get_theme_constant("margin", "Dialogs");
- int button_margin = hbc->get_theme_constant("button_margin", "Dialogs");
+ int margin = hbc->get_theme_constant(SNAME("margin"), SNAME("Dialogs"));
+ int button_margin = hbc->get_theme_constant(SNAME("button_margin"), SNAME("Dialogs"));
label = memnew(Label);
label->set_anchor(SIDE_RIGHT, Control::ANCHOR_END);
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index f8cee6daec..2e4204e171 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -49,9 +49,9 @@ VBoxContainer *FileDialog::get_vbox() {
}
void FileDialog::_theme_changed() {
- Color font_color = vbox->get_theme_color("font_color", "Button");
- Color font_hover_color = vbox->get_theme_color("font_hover_color", "Button");
- Color font_pressed_color = vbox->get_theme_color("font_pressed_color", "Button");
+ Color font_color = vbox->get_theme_color(SNAME("font_color"), SNAME("Button"));
+ Color font_hover_color = vbox->get_theme_color(SNAME("font_hover_color"), SNAME("Button"));
+ Color font_pressed_color = vbox->get_theme_color(SNAME("font_pressed_color"), SNAME("Button"));
dir_up->add_theme_color_override("icon_normal_color", font_color);
dir_up->add_theme_color_override("icon_hover_color", font_hover_color);
@@ -81,16 +81,16 @@ void FileDialog::_notification(int p_what) {
}
}
if (p_what == NOTIFICATION_ENTER_TREE) {
- dir_up->set_icon(vbox->get_theme_icon("parent_folder", "FileDialog"));
+ dir_up->set_icon(vbox->get_theme_icon(SNAME("parent_folder"), SNAME("FileDialog")));
if (vbox->is_layout_rtl()) {
- dir_prev->set_icon(vbox->get_theme_icon("forward_folder", "FileDialog"));
- dir_next->set_icon(vbox->get_theme_icon("back_folder", "FileDialog"));
+ dir_prev->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
+ dir_next->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
} else {
- dir_prev->set_icon(vbox->get_theme_icon("back_folder", "FileDialog"));
- dir_next->set_icon(vbox->get_theme_icon("forward_folder", "FileDialog"));
+ dir_prev->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
+ dir_next->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
}
- refresh->set_icon(vbox->get_theme_icon("reload", "FileDialog"));
- show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden", "FileDialog"));
+ refresh->set_icon(vbox->get_theme_icon(SNAME("reload"), SNAME("FileDialog")));
+ show_hidden->set_icon(vbox->get_theme_icon(SNAME("toggle_hidden"), SNAME("FileDialog")));
_theme_changed();
}
}
@@ -170,7 +170,7 @@ void FileDialog::_file_submitted(const String &p_file) {
void FileDialog::_save_confirm_pressed() {
String f = dir_access->get_current_dir().plus_file(file->get_text());
- emit_signal("file_selected", f);
+ emit_signal(SNAME("file_selected"), f);
hide();
}
@@ -224,7 +224,7 @@ void FileDialog::_action_pressed() {
}
if (files.size()) {
- emit_signal("files_selected", files);
+ emit_signal(SNAME("files_selected"), files);
hide();
}
@@ -234,7 +234,7 @@ void FileDialog::_action_pressed() {
String f = dir_access->get_current_dir().plus_file(file->get_text());
if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && dir_access->file_exists(f)) {
- emit_signal("file_selected", f);
+ emit_signal(SNAME("file_selected"), f);
hide();
} else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) {
String path = dir_access->get_current_dir();
@@ -248,7 +248,7 @@ void FileDialog::_action_pressed() {
}
}
- emit_signal("dir_selected", path);
+ emit_signal(SNAME("dir_selected"), path);
hide();
}
@@ -308,7 +308,7 @@ void FileDialog::_action_pressed() {
confirm_save->set_text(TTRC("File exists, overwrite?"));
confirm_save->popup_centered(Size2(200, 80));
} else {
- emit_signal("file_selected", f);
+ emit_signal(SNAME("file_selected"), f);
hide();
}
}
@@ -437,8 +437,8 @@ void FileDialog::_tree_item_activated() {
if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) {
file->set_text("");
}
- call_deferred("_update_file_list");
- call_deferred("_update_dir");
+ call_deferred(SNAME("_update_file_list"));
+ call_deferred(SNAME("_update_dir"));
_push_history();
} else {
_action_pressed();
@@ -468,10 +468,10 @@ void FileDialog::update_file_list() {
dir_access->list_dir_begin();
TreeItem *root = tree->create_item();
- Ref<Texture2D> folder = vbox->get_theme_icon("folder", "FileDialog");
- Ref<Texture2D> file_icon = vbox->get_theme_icon("file", "FileDialog");
- const Color folder_color = vbox->get_theme_color("folder_icon_modulate", "FileDialog");
- const Color file_color = vbox->get_theme_color("file_icon_modulate", "FileDialog");
+ Ref<Texture2D> folder = vbox->get_theme_icon(SNAME("folder"), SNAME("FileDialog"));
+ Ref<Texture2D> file_icon = vbox->get_theme_icon(SNAME("file"), SNAME("FileDialog"));
+ const Color folder_color = vbox->get_theme_color(SNAME("folder_icon_modulate"), SNAME("FileDialog"));
+ const Color file_color = vbox->get_theme_color(SNAME("file_icon_modulate"), SNAME("FileDialog"));
List<String> files;
List<String> dirs;
@@ -552,9 +552,9 @@ void FileDialog::update_file_list() {
bool match = patterns.is_empty();
String match_str;
- for (List<String>::Element *E = patterns.front(); E; E = E->next()) {
- if (files.front()->get().matchn(E->get())) {
- match_str = E->get();
+ for (const String &E : patterns) {
+ if (files.front()->get().matchn(E)) {
+ match_str = E;
match = true;
break;
}
@@ -573,7 +573,7 @@ void FileDialog::update_file_list() {
ti->set_icon_modulate(0, file_color);
if (mode == FILE_MODE_OPEN_DIR) {
- ti->set_custom_color(0, vbox->get_theme_color("files_disabled", "FileDialog"));
+ ti->set_custom_color(0, vbox->get_theme_color(SNAME("files_disabled"), SNAME("FileDialog")));
ti->set_selectable(0, false);
}
Dictionary d;
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index 7278ca6e94..83ecf1d534 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -101,7 +101,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
grabbed = -1;
grabbing = false;
update();
- emit_signal("ramp_changed");
+ emit_signal(SNAME("ramp_changed"));
accept_event();
}
@@ -121,7 +121,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
grabbed = -1;
grabbing = false;
update();
- emit_signal("ramp_changed");
+ emit_signal(SNAME("ramp_changed"));
accept_event();
}
}
@@ -145,7 +145,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
}
- emit_signal("ramp_changed");
+ emit_signal(SNAME("ramp_changed"));
update();
}
}
@@ -214,13 +214,13 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
}
- emit_signal("ramp_changed");
+ emit_signal(SNAME("ramp_changed"));
}
if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
if (grabbing) {
grabbing = false;
- emit_signal("ramp_changed");
+ emit_signal(SNAME("ramp_changed"));
}
update();
}
@@ -288,7 +288,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
}
- emit_signal("ramp_changed");
+ emit_signal(SNAME("ramp_changed"));
update();
}
@@ -436,7 +436,7 @@ void GradientEdit::_color_changed(const Color &p_color) {
}
points.write[grabbed].color = p_color;
update();
- emit_signal("ramp_changed");
+ emit_signal(SNAME("ramp_changed"));
}
void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) {
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 39aa6749e7..1fac2b9129 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -162,7 +162,7 @@ void GraphEditMinimap::_gui_input(const Ref<InputEvent> &p_ev) {
if (mb->is_pressed()) {
is_pressing = true;
- Ref<Texture2D> resizer = get_theme_icon("resizer");
+ Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
Rect2 resizer_hitbox = Rect2(Point2(), resizer->get_size());
if (resizer_hitbox.has_point(mb->get_position())) {
is_resizing = true;
@@ -217,8 +217,8 @@ Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const S
}
bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
+ for (const Connection &E : connections) {
+ if (E.from == p_from && E.from_port == p_from_port && E.to == p_to && E.to_port == p_to_port) {
return true;
}
}
@@ -227,7 +227,7 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con
}
void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
+ for (const List<Connection>::Element *E = connections.front(); E; E = E->next()) {
if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
connections.erase(E);
top_layer->update();
@@ -257,7 +257,7 @@ Vector2 GraphEdit::get_scroll_ofs() const {
void GraphEdit::_scroll_moved(double) {
if (!awaiting_scroll_offset_update) {
- call_deferred("_update_scroll_offset");
+ call_deferred(SNAME("_update_scroll_offset"));
awaiting_scroll_offset_update = true;
}
top_layer->update();
@@ -265,7 +265,7 @@ void GraphEdit::_scroll_moved(double) {
update();
if (!setting_scroll_ofs) { //in godot, signals on change value are avoided as a convention
- emit_signal("scroll_offset_changed", get_scroll_ofs());
+ emit_signal(SNAME("scroll_offset_changed"), get_scroll_ofs());
}
}
@@ -345,7 +345,7 @@ void GraphEdit::_update_scroll() {
set_block_minimum_size_adjust(false);
if (!awaiting_scroll_offset_update) {
- call_deferred("_update_scroll_offset");
+ call_deferred(SNAME("_update_scroll_offset"));
awaiting_scroll_offset_update = true;
}
@@ -371,7 +371,7 @@ void GraphEdit::_graph_node_raised(Node *p_gn) {
move_child(connections_layer, first_not_comment);
top_layer->raise();
- emit_signal("node_selected", p_gn);
+ emit_signal(SNAME("node_selected"), p_gn);
}
void GraphEdit::_graph_node_moved(Node *p_gn) {
@@ -395,7 +395,7 @@ void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_gn) {
void GraphEdit::add_child_notify(Node *p_child) {
Control::add_child_notify(p_child);
- top_layer->call_deferred("raise"); // Top layer always on top!
+ top_layer->call_deferred(SNAME("raise")); // Top layer always on top!
GraphNode *gn = Object::cast_to<GraphNode>(p_child);
if (gn) {
@@ -421,7 +421,7 @@ void GraphEdit::remove_child_notify(Node *p_child) {
}
if (top_layer != nullptr && is_inside_tree()) {
- top_layer->call_deferred("raise"); // Top layer always on top!
+ top_layer->call_deferred(SNAME("raise")); // Top layer always on top!
}
GraphNode *gn = Object::cast_to<GraphNode>(p_child);
@@ -442,14 +442,14 @@ void GraphEdit::remove_child_notify(Node *p_child) {
void GraphEdit::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- port_grab_distance_horizontal = get_theme_constant("port_grab_distance_horizontal");
- port_grab_distance_vertical = get_theme_constant("port_grab_distance_vertical");
-
- zoom_minus->set_icon(get_theme_icon("minus"));
- zoom_reset->set_icon(get_theme_icon("reset"));
- zoom_plus->set_icon(get_theme_icon("more"));
- snap_button->set_icon(get_theme_icon("snap"));
- minimap_button->set_icon(get_theme_icon("minimap"));
+ port_grab_distance_horizontal = get_theme_constant(SNAME("port_grab_distance_horizontal"));
+ port_grab_distance_vertical = get_theme_constant(SNAME("port_grab_distance_vertical"));
+
+ zoom_minus->set_icon(get_theme_icon(SNAME("minus")));
+ zoom_reset->set_icon(get_theme_icon(SNAME("reset")));
+ zoom_plus->set_icon(get_theme_icon(SNAME("more")));
+ snap_button->set_icon(get_theme_icon(SNAME("snap")));
+ minimap_button->set_icon(get_theme_icon(SNAME("minimap")));
}
if (p_what == NOTIFICATION_READY) {
Size2 hmin = h_scroll->get_combined_minimum_size();
@@ -466,7 +466,7 @@ void GraphEdit::_notification(int p_what) {
v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
}
if (p_what == NOTIFICATION_DRAW) {
- draw_style_box(get_theme_stylebox("bg"), Rect2(Point2(), get_size()));
+ draw_style_box(get_theme_stylebox(SNAME("bg")), Rect2(Point2(), get_size()));
if (is_using_snap()) {
//draw grid
@@ -479,8 +479,8 @@ void GraphEdit::_notification(int p_what) {
Point2i from = (offset / float(snap)).floor();
Point2i len = (size / float(snap)).floor() + Vector2(1, 1);
- Color grid_minor = get_theme_color("grid_minor");
- Color grid_major = get_theme_color("grid_major");
+ Color grid_minor = get_theme_color(SNAME("grid_minor"));
+ Color grid_major = get_theme_color(SNAME("grid_major"));
for (int i = from.x; i < from.x + len.x; i++) {
Color color;
@@ -518,7 +518,7 @@ void GraphEdit::_notification(int p_what) {
}
bool GraphEdit::_filter_input(const Point2 &p_point) {
- Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
+ Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
@@ -548,7 +548,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_LEFT && mb->is_pressed()) {
connecting_valid = false;
- Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
+ Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
click_pos = mb->get_position() / zoom;
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
@@ -561,20 +561,20 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
if (is_in_hot_zone(pos / zoom, click_pos)) {
if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) {
//check disconnect
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().from == gn->get_name() && E->get().from_port == j) {
- Node *to = get_node(String(E->get().to));
+ for (const Connection &E : connections) {
+ if (E.from == gn->get_name() && E.from_port == j) {
+ Node *to = get_node(String(E.to));
if (Object::cast_to<GraphNode>(to)) {
- connecting_from = E->get().to;
- connecting_index = E->get().to_port;
+ connecting_from = E.to;
+ connecting_index = E.to_port;
connecting_out = false;
- connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E->get().to_port);
- connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E->get().to_port);
+ connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E.to_port);
+ connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E.to_port);
connecting_target = false;
connecting_to = pos;
just_disconnected = true;
- emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port);
+ emit_signal(SNAME("disconnection_request"), E.from, E.from_port, E.to, E.to_port);
to = get_node(String(connecting_from)); //maybe it was erased
if (Object::cast_to<GraphNode>(to)) {
connecting = true;
@@ -603,20 +603,20 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
if (is_in_hot_zone(pos / zoom, click_pos)) {
if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) {
//check disconnect
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().to == gn->get_name() && E->get().to_port == j) {
- Node *fr = get_node(String(E->get().from));
+ for (const Connection &E : connections) {
+ if (E.to == gn->get_name() && E.to_port == j) {
+ Node *fr = get_node(String(E.from));
if (Object::cast_to<GraphNode>(fr)) {
- connecting_from = E->get().from;
- connecting_index = E->get().from_port;
+ connecting_from = E.from;
+ connecting_index = E.from_port;
connecting_out = true;
- connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E->get().from_port);
- connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E->get().from_port);
+ connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E.from_port);
+ connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E.from_port);
connecting_target = false;
connecting_to = pos;
just_disconnected = true;
- emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port);
+ emit_signal(SNAME("disconnection_request"), E.from, E.from_port, E.to, E.to_port);
fr = get_node(String(connecting_from)); //maybe it was erased
if (Object::cast_to<GraphNode>(fr)) {
connecting = true;
@@ -652,7 +652,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
connecting_valid = just_disconnected || click_pos.distance_to(connecting_to / zoom) > 20.0 * zoom;
if (connecting_valid) {
- Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
+ Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
Vector2 mpos = mm->get_position() / zoom;
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
@@ -701,7 +701,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
SWAP(from, to);
SWAP(from_slot, to_slot);
}
- emit_signal("connection_request", from, from_slot, to, to_slot);
+ emit_signal(SNAME("connection_request"), from, from_slot, to, to_slot);
} else if (!just_disconnected) {
String from = connecting_from;
@@ -709,9 +709,9 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Vector2 ofs = Vector2(mb->get_position().x, mb->get_position().y);
if (!connecting_out) {
- emit_signal("connection_from_empty", from, from_slot, ofs);
+ emit_signal(SNAME("connection_from_empty"), from, from_slot, ofs);
} else {
- emit_signal("connection_to_empty", from, from_slot, ofs);
+ emit_signal(SNAME("connection_to_empty"), from, from_slot, ofs);
}
}
}
@@ -819,8 +819,8 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const
//cubic bezier code
float diff = p_to.x - p_from.x;
float cp_offset;
- int cp_len = get_theme_constant("bezier_len_pos") * p_bezier_ratio;
- int cp_neg_len = get_theme_constant("bezier_len_neg") * p_bezier_ratio;
+ 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);
@@ -849,7 +849,7 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const
}
void GraphEdit::_connections_layer_draw() {
- Color activity_color = get_theme_color("activity");
+ Color activity_color = get_theme_color(SNAME("activity"));
//draw connections
List<List<Connection>::Element *> to_erase;
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
@@ -934,8 +934,8 @@ void GraphEdit::_top_layer_draw() {
}
if (box_selecting) {
- top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_fill"));
- top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_stroke"), false);
+ top_layer->draw_rect(box_selecting_rect, get_theme_color(SNAME("selection_fill")));
+ top_layer->draw_rect(box_selecting_rect, get_theme_color(SNAME("selection_stroke")), false);
}
}
@@ -948,7 +948,7 @@ void GraphEdit::_minimap_draw() {
// Draw the minimap background.
Rect2 minimap_rect = Rect2(Point2(), minimap->get_size());
- minimap->draw_style_box(minimap->get_theme_stylebox("bg"), minimap_rect);
+ minimap->draw_style_box(minimap->get_theme_stylebox(SNAME("bg")), minimap_rect);
Vector2 graph_offset = minimap->_get_graph_offset();
Vector2 minimap_offset = minimap->minimap_offset;
@@ -964,7 +964,7 @@ void GraphEdit::_minimap_draw() {
Vector2 node_size = minimap->_convert_from_graph_position(gn->get_size() * zoom);
Rect2 node_rect = Rect2(node_position, node_size);
- Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox("node")->duplicate();
+ Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox(SNAME("node"))->duplicate();
// Override default values with colors provided by the GraphNode's stylebox, if possible.
Ref<StyleBoxFlat> sbf = gn->get_theme_stylebox(gn->is_selected() ? "commentfocus" : "comment");
@@ -987,7 +987,7 @@ void GraphEdit::_minimap_draw() {
Vector2 node_size = minimap->_convert_from_graph_position(gn->get_size() * zoom);
Rect2 node_rect = Rect2(node_position, node_size);
- Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox("node")->duplicate();
+ Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox(SNAME("node"))->duplicate();
// Override default values with colors provided by the GraphNode's stylebox, if possible.
Ref<StyleBoxFlat> sbf = gn->get_theme_stylebox(gn->is_selected() ? "selectedframe" : "frame");
@@ -1000,9 +1000,9 @@ void GraphEdit::_minimap_draw() {
}
// Draw node connections.
- Color activity_color = get_theme_color("activity");
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- NodePath fromnp(E->get().from);
+ Color activity_color = get_theme_color(SNAME("activity"));
+ for (const Connection &E : connections) {
+ NodePath fromnp(E.from);
Node *from = get_node(fromnp);
if (!from) {
@@ -1013,7 +1013,7 @@ void GraphEdit::_minimap_draw() {
continue;
}
- NodePath tonp(E->get().to);
+ NodePath tonp(E.to);
Node *to = get_node(tonp);
if (!to) {
continue;
@@ -1023,27 +1023,27 @@ void GraphEdit::_minimap_draw() {
continue;
}
- Vector2 from_slot_position = gfrom->get_position_offset() * zoom + gfrom->get_connection_output_position(E->get().from_port);
+ Vector2 from_slot_position = gfrom->get_position_offset() * zoom + gfrom->get_connection_output_position(E.from_port);
Vector2 from_position = minimap->_convert_from_graph_position(from_slot_position - graph_offset) + minimap_offset;
- Color from_color = gfrom->get_connection_output_color(E->get().from_port);
- Vector2 to_slot_position = gto->get_position_offset() * zoom + gto->get_connection_input_position(E->get().to_port);
+ Color from_color = gfrom->get_connection_output_color(E.from_port);
+ Vector2 to_slot_position = gto->get_position_offset() * zoom + gto->get_connection_input_position(E.to_port);
Vector2 to_position = minimap->_convert_from_graph_position(to_slot_position - graph_offset) + minimap_offset;
- Color to_color = gto->get_connection_input_color(E->get().to_port);
+ Color to_color = gto->get_connection_input_color(E.to_port);
- if (E->get().activity > 0) {
- from_color = from_color.lerp(activity_color, E->get().activity);
- to_color = to_color.lerp(activity_color, E->get().activity);
+ if (E.activity > 0) {
+ 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 the "camera" viewport.
Rect2 camera_rect = minimap->get_camera_rect();
- minimap->draw_style_box(minimap->get_theme_stylebox("camera"), camera_rect);
+ minimap->draw_style_box(minimap->get_theme_stylebox(SNAME("camera")), camera_rect);
// Draw the resizer control.
- Ref<Texture2D> resizer = minimap->get_theme_icon("resizer");
- Color resizer_color = minimap->get_theme_color("resizer_color");
+ Ref<Texture2D> resizer = minimap->get_theme_icon(SNAME("resizer"));
+ Color resizer_color = minimap->get_theme_color(SNAME("resizer_color"));
minimap->draw_texture(resizer, Point2(), resizer_color);
}
@@ -1070,7 +1070,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
if (mm.is_valid() && dragging) {
if (!moving_selection) {
- emit_signal("begin_node_move");
+ emit_signal(SNAME("begin_node_move"));
moving_selection = true;
}
@@ -1113,17 +1113,17 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
if (in_box) {
if (!gn->is_selected() && box_selection_mode_additive) {
- emit_signal("node_selected", gn);
+ emit_signal(SNAME("node_selected"), gn);
} else if (gn->is_selected() && !box_selection_mode_additive) {
- emit_signal("node_deselected", gn);
+ emit_signal(SNAME("node_deselected"), gn);
}
gn->set_selected(box_selection_mode_additive);
} else {
bool select = (previous_selected.find(gn) != nullptr);
if (gn->is_selected() && !select) {
- emit_signal("node_deselected", gn);
+ emit_signal(SNAME("node_deselected"), gn);
} else if (!gn->is_selected() && select) {
- emit_signal("node_selected", gn);
+ emit_signal(SNAME("node_selected"), gn);
}
gn->set_selected(select);
}
@@ -1146,9 +1146,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
bool select = (previous_selected.find(gn) != nullptr);
if (gn->is_selected() && !select) {
- emit_signal("node_deselected", gn);
+ emit_signal(SNAME("node_deselected"), gn);
} else if (!gn->is_selected() && select) {
- emit_signal("node_selected", gn);
+ emit_signal(SNAME("node_selected"), gn);
}
gn->set_selected(select);
}
@@ -1160,7 +1160,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
top_layer->update();
minimap->update();
} else {
- emit_signal("popup_request", b->get_global_position());
+ emit_signal(SNAME("popup_request"), b->get_global_position());
}
}
}
@@ -1175,7 +1175,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
Rect2 r = gn->get_rect();
r.size *= zoom;
if (r.has_point(b->get_position())) {
- emit_signal("node_deselected", gn);
+ emit_signal(SNAME("node_deselected"), gn);
gn->set_selected(false);
}
}
@@ -1192,7 +1192,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (moving_selection) {
- emit_signal("end_node_move");
+ emit_signal(SNAME("end_node_move"));
moving_selection = false;
}
@@ -1238,7 +1238,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
o_gn->set_selected(true);
} else {
if (o_gn->is_selected()) {
- emit_signal("node_deselected", o_gn);
+ emit_signal(SNAME("node_deselected"), o_gn);
}
o_gn->set_selected(false);
}
@@ -1298,7 +1298,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
continue;
}
if (gn2->is_selected()) {
- emit_signal("node_deselected", gn2);
+ emit_signal(SNAME("node_deselected"), gn2);
}
gn2->set_selected(false);
}
@@ -1333,16 +1333,16 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
if (p_ev->is_pressed()) {
if (p_ev->is_action("ui_graph_duplicate")) {
- emit_signal("duplicate_nodes_request");
+ emit_signal(SNAME("duplicate_nodes_request"));
accept_event();
} else if (p_ev->is_action("ui_copy")) {
- emit_signal("copy_nodes_request");
+ emit_signal(SNAME("copy_nodes_request"));
accept_event();
} else if (p_ev->is_action("ui_paste")) {
- emit_signal("paste_nodes_request");
+ emit_signal(SNAME("paste_nodes_request"));
accept_event();
} else if (p_ev->is_action("ui_graph_delete")) {
- emit_signal("delete_nodes_request");
+ emit_signal(SNAME("delete_nodes_request"));
accept_event();
}
}
@@ -1360,15 +1360,15 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) {
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
- if (Math::is_equal_approx(E->get().activity, p_activity)) {
+ for (Connection &E : connections) {
+ if (E.from == p_from && E.from_port == p_from_port && E.to == p_to && E.to_port == p_to_port) {
+ if (Math::is_equal_approx(E.activity, p_activity)) {
//update only if changed
top_layer->update();
minimap->update();
connections_layer->update();
}
- E->get().activity = p_activity;
+ E.activity = p_activity;
return;
}
}
@@ -1500,12 +1500,12 @@ Array GraphEdit::_get_connection_list() const {
List<Connection> conns;
get_connection_list(&conns);
Array arr;
- for (List<Connection>::Element *E = conns.front(); E; E = E->next()) {
+ for (const Connection &E : conns) {
Dictionary d;
- d["from"] = E->get().from;
- d["from_port"] = E->get().from_port;
- d["to"] = E->get().to;
- d["to_port"] = E->get().to_port;
+ d["from"] = E.from;
+ d["from_port"] = E.from_port;
+ d["to"] = E.to;
+ d["to_port"] = E.to_port;
arr.push_back(d);
}
return arr;
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 836bffdf46..e85cefcb7b 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -180,9 +180,9 @@ void GraphNode::_resort() {
/** First pass, determine minimum size AND amount of stretchable elements */
Size2i new_size = get_size();
- Ref<StyleBox> sb = get_theme_stylebox("frame");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame"));
- int sep = get_theme_constant("separation");
+ int sep = get_theme_constant(SNAME("separation"));
bool first = true;
int children_count = 0;
@@ -323,8 +323,8 @@ void GraphNode::_resort() {
bool GraphNode::has_point(const Point2 &p_point) const {
if (comment) {
- Ref<StyleBox> comment = get_theme_stylebox("comment");
- Ref<Texture2D> resizer = get_theme_icon("resizer");
+ Ref<StyleBox> comment = get_theme_stylebox(SNAME("comment"));
+ Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) {
return true;
@@ -355,18 +355,18 @@ void GraphNode::_notification(int p_what) {
//sb=sb->duplicate();
//sb->call("set_modulate",modulate);
- Ref<Texture2D> port = get_theme_icon("port");
- Ref<Texture2D> close = get_theme_icon("close");
- Ref<Texture2D> resizer = get_theme_icon("resizer");
- int close_offset = get_theme_constant("close_offset");
- int close_h_offset = get_theme_constant("close_h_offset");
- Color close_color = get_theme_color("close_color");
- Color resizer_color = get_theme_color("resizer_color");
- int title_offset = get_theme_constant("title_offset");
- int title_h_offset = get_theme_constant("title_h_offset");
- Color title_color = get_theme_color("title_color");
+ Ref<Texture2D> port = get_theme_icon(SNAME("port"));
+ Ref<Texture2D> close = get_theme_icon(SNAME("close"));
+ Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
+ int close_offset = get_theme_constant(SNAME("close_offset"));
+ int close_h_offset = get_theme_constant(SNAME("close_h_offset"));
+ Color close_color = get_theme_color(SNAME("close_color"));
+ Color resizer_color = get_theme_color(SNAME("resizer_color"));
+ int title_offset = get_theme_constant(SNAME("title_offset"));
+ int title_h_offset = get_theme_constant(SNAME("title_h_offset"));
+ Color title_color = get_theme_color(SNAME("title_color"));
Point2i icofs = -port->get_size() * 0.5;
- int edgeofs = get_theme_constant("port_offset");
+ int edgeofs = get_theme_constant(SNAME("port_offset"));
icofs.y += sb->get_margin(SIDE_TOP);
draw_style_box(sb, Rect2(Point2(), get_size()));
@@ -375,10 +375,10 @@ void GraphNode::_notification(int p_what) {
case OVERLAY_DISABLED: {
} break;
case OVERLAY_BREAKPOINT: {
- draw_style_box(get_theme_stylebox("breakpoint"), Rect2(Point2(), get_size()));
+ draw_style_box(get_theme_stylebox(SNAME("breakpoint")), Rect2(Point2(), get_size()));
} break;
case OVERLAY_POSITION: {
- draw_style_box(get_theme_stylebox("position"), Rect2(Point2(), get_size()));
+ draw_style_box(get_theme_stylebox(SNAME("position")), Rect2(Point2(), get_size()));
} break;
}
@@ -446,8 +446,8 @@ void GraphNode::_notification(int p_what) {
}
void GraphNode::_shape() {
- Ref<Font> font = get_theme_font("title_font");
- int font_size = get_theme_font_size("title_font_size");
+ Ref<Font> font = get_theme_font(SNAME("title_font"));
+ int font_size = get_theme_font_size(SNAME("title_font_size"));
title_buf->clear();
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
@@ -481,7 +481,7 @@ void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const C
update();
connpos_dirty = true;
- emit_signal("slot_updated", p_idx);
+ emit_signal(SNAME("slot_updated"), p_idx);
}
void GraphNode::clear_slot(int p_idx) {
@@ -510,7 +510,7 @@ void GraphNode::set_slot_enabled_left(int p_idx, bool p_enable_left) {
update();
connpos_dirty = true;
- emit_signal("slot_updated", p_idx);
+ emit_signal(SNAME("slot_updated"), p_idx);
}
void GraphNode::set_slot_type_left(int p_idx, int p_type_left) {
@@ -520,7 +520,7 @@ void GraphNode::set_slot_type_left(int p_idx, int p_type_left) {
update();
connpos_dirty = true;
- emit_signal("slot_updated", p_idx);
+ emit_signal(SNAME("slot_updated"), p_idx);
}
int GraphNode::get_slot_type_left(int p_idx) const {
@@ -537,7 +537,7 @@ void GraphNode::set_slot_color_left(int p_idx, const Color &p_color_left) {
update();
connpos_dirty = true;
- emit_signal("slot_updated", p_idx);
+ emit_signal(SNAME("slot_updated"), p_idx);
}
Color GraphNode::get_slot_color_left(int p_idx) const {
@@ -561,7 +561,7 @@ void GraphNode::set_slot_enabled_right(int p_idx, bool p_enable_right) {
update();
connpos_dirty = true;
- emit_signal("slot_updated", p_idx);
+ emit_signal(SNAME("slot_updated"), p_idx);
}
void GraphNode::set_slot_type_right(int p_idx, int p_type_right) {
@@ -571,7 +571,7 @@ void GraphNode::set_slot_type_right(int p_idx, int p_type_right) {
update();
connpos_dirty = true;
- emit_signal("slot_updated", p_idx);
+ emit_signal(SNAME("slot_updated"), p_idx);
}
int GraphNode::get_slot_type_right(int p_idx) const {
@@ -588,7 +588,7 @@ void GraphNode::set_slot_color_right(int p_idx, const Color &p_color_right) {
update();
connpos_dirty = true;
- emit_signal("slot_updated", p_idx);
+ emit_signal(SNAME("slot_updated"), p_idx);
}
Color GraphNode::get_slot_color_right(int p_idx) const {
@@ -599,14 +599,14 @@ Color GraphNode::get_slot_color_right(int p_idx) const {
}
Size2 GraphNode::get_minimum_size() const {
- int sep = get_theme_constant("separation");
- Ref<StyleBox> sb = get_theme_stylebox("frame");
+ int sep = get_theme_constant(SNAME("separation"));
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame"));
bool first = true;
Size2 minsize;
minsize.x = title_buf->get_size().x;
if (show_close) {
- Ref<Texture2D> close = get_theme_icon("close");
+ Ref<Texture2D> close = get_theme_icon(SNAME("close"));
minsize.x += sep + close->get_width();
}
@@ -699,7 +699,7 @@ String GraphNode::get_language() const {
void GraphNode::set_position_offset(const Vector2 &p_offset) {
position_offset = p_offset;
- emit_signal("position_offset_changed");
+ emit_signal(SNAME("position_offset_changed"));
update();
}
@@ -720,7 +720,7 @@ void GraphNode::set_drag(bool p_drag) {
if (p_drag) {
drag_from = get_position_offset();
} else {
- emit_signal("dragged", drag_from, get_position_offset()); //useful for undo/redo
+ emit_signal(SNAME("dragged"), drag_from, get_position_offset()); //useful for undo/redo
}
}
@@ -738,10 +738,10 @@ bool GraphNode::is_close_button_visible() const {
}
void GraphNode::_connpos_update() {
- int edgeofs = get_theme_constant("port_offset");
- int sep = get_theme_constant("separation");
+ int edgeofs = get_theme_constant(SNAME("port_offset"));
+ int sep = get_theme_constant(SNAME("separation"));
- Ref<StyleBox> sb = get_theme_stylebox("frame");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame"));
conn_input_cache.clear();
conn_output_cache.clear();
int vofs = 0;
@@ -875,12 +875,12 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
//send focus to parent
get_parent_control()->grab_focus();
- emit_signal("close_request");
+ emit_signal(SNAME("close_request"));
accept_event();
return;
}
- Ref<Texture2D> resizer = get_theme_icon("resizer");
+ Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) {
resizing = true;
@@ -890,7 +890,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
return;
}
- emit_signal("raise_request");
+ emit_signal(SNAME("raise_request"));
}
if (!mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
@@ -904,7 +904,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
Vector2 diff = mpos - resizing_from;
- emit_signal("resize_request", resizing_from_size + diff);
+ emit_signal(SNAME("resize_request"), resizing_from_size + diff);
}
}
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index a54f5eef06..1107e3a4af 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -38,8 +38,8 @@ void GridContainer::_notification(int p_what) {
Set<int> col_expanded; // Columns which have the SIZE_EXPAND flag set.
Set<int> row_expanded; // Rows which have the SIZE_EXPAND flag set.
- int hsep = get_theme_constant("hseparation");
- int vsep = get_theme_constant("vseparation");
+ int hsep = get_theme_constant(SNAME("hseparation"));
+ int vsep = get_theme_constant(SNAME("vseparation"));
int max_col = MIN(get_child_count(), columns);
int max_row = ceil((float)get_child_count() / (float)columns);
@@ -213,8 +213,8 @@ Size2 GridContainer::get_minimum_size() const {
Map<int, int> col_minw;
Map<int, int> row_minh;
- int hsep = get_theme_constant("hseparation");
- int vsep = get_theme_constant("vseparation");
+ int hsep = get_theme_constant(SNAME("hseparation"));
+ int vsep = get_theme_constant(SNAME("vseparation"));
int max_row = 0;
int max_col = 0;
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index b0d54bf8c9..fdf6181f1d 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -42,7 +42,7 @@ void ItemList::_shape(int p_idx) {
} else {
item.text_buf->set_direction((TextServer::Direction)item.text_direction);
}
- item.text_buf->add_string(item.text, get_theme_font("font"), get_theme_font_size("font_size"), item.opentype_features, (item.language != "") ? item.language : TranslationServer::get_singleton()->get_tool_locale());
+ item.text_buf->add_string(item.text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), item.opentype_features, (item.language != "") ? item.language : TranslationServer::get_singleton()->get_tool_locale());
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
item.text_buf->set_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND);
} else {
@@ -548,7 +548,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (defer_select_single >= 0 && mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_LEFT && !mb->is_pressed()) {
select(defer_select_single, true);
- emit_signal("multi_selected", defer_select_single, true);
+ emit_signal(SNAME("multi_selected"), defer_select_single, true);
defer_select_single = -1;
return;
}
@@ -556,7 +556,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && (mb->get_button_index() == MOUSE_BUTTON_LEFT || (allow_rmb_select && mb->get_button_index() == MOUSE_BUTTON_RIGHT)) && mb->is_pressed()) {
search_string = ""; //any mousepress cancels
Vector2 pos = mb->get_position();
- Ref<StyleBox> bg = get_theme_stylebox("bg");
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
pos -= bg->get_offset();
pos.y += scroll_bar->get_value();
@@ -583,7 +583,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (select_mode == SELECT_MULTI && items[i].selected && mb->is_command_pressed()) {
deselect(i);
- emit_signal("multi_selected", i, false);
+ emit_signal(SNAME("multi_selected"), i, false);
} else if (select_mode == SELECT_MULTI && mb->is_shift_pressed() && current >= 0 && current < items.size() && current != i) {
int from = current;
@@ -595,12 +595,12 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
bool selected = !items[j].selected;
select(j, false);
if (selected) {
- emit_signal("multi_selected", j, true);
+ emit_signal(SNAME("multi_selected"), j, true);
}
}
if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, get_local_mouse_position());
+ emit_signal(SNAME("item_rmb_selected"), i, get_local_mouse_position());
}
} else {
if (!mb->is_double_click() && !mb->is_command_pressed() && select_mode == SELECT_MULTI && items[i].selectable && !items[i].disabled && items[i].selected && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
@@ -609,7 +609,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
if (items[i].selected && mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, get_local_mouse_position());
+ emit_signal(SNAME("item_rmb_selected"), i, get_local_mouse_position());
} else {
bool selected = items[i].selected;
@@ -617,16 +617,16 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (!selected || allow_reselect) {
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", i);
+ emit_signal(SNAME("item_selected"), i);
} else {
- emit_signal("multi_selected", i, true);
+ emit_signal(SNAME("multi_selected"), i, true);
}
}
if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, get_local_mouse_position());
+ emit_signal(SNAME("item_rmb_selected"), i, get_local_mouse_position());
} else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_double_click()) {
- emit_signal("item_activated", i);
+ emit_signal(SNAME("item_activated"), i);
}
}
}
@@ -634,13 +634,13 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
return;
}
if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
- emit_signal("rmb_clicked", mb->get_position());
+ emit_signal(SNAME("rmb_clicked"), mb->get_position());
return;
}
// Since closest is null, more likely we clicked on empty space, so send signal to interested controls. Allows, for example, implement items deselecting.
- emit_signal("nothing_selected");
+ emit_signal(SNAME("nothing_selected"));
}
if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP && mb->is_pressed()) {
scroll_bar->set_value(scroll_bar->get_value() - scroll_bar->get_page() * mb->get_factor() / 8);
@@ -661,7 +661,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(i);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
break;
@@ -676,7 +676,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(current - current_columns);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
accept_event();
}
@@ -691,7 +691,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(i);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
break;
}
@@ -705,7 +705,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(current + current_columns);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
accept_event();
}
@@ -717,7 +717,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(current - current_columns * i);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
accept_event();
break;
@@ -731,7 +731,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(current + current_columns * i);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
accept_event();
@@ -745,7 +745,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(current - 1);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
accept_event();
}
@@ -756,7 +756,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(current + 1);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
accept_event();
}
@@ -766,17 +766,17 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (current >= 0 && current < items.size()) {
if (items[current].selectable && !items[current].disabled && !items[current].selected) {
select(current, false);
- emit_signal("multi_selected", current, true);
+ emit_signal(SNAME("multi_selected"), current, true);
} else if (items[current].selected) {
deselect(current);
- emit_signal("multi_selected", current, false);
+ emit_signal(SNAME("multi_selected"), current, false);
}
}
} else if (p_event->is_action("ui_accept")) {
search_string = ""; //any mousepress cancels
if (current >= 0 && current < items.size()) {
- emit_signal("item_activated", current);
+ emit_signal(SNAME("item_activated"), current);
}
} else {
Ref<InputEventKey> k = p_event;
@@ -812,7 +812,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
set_current(i);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
break;
}
@@ -867,7 +867,7 @@ void ItemList::_notification(int p_what) {
}
if (p_what == NOTIFICATION_DRAW) {
- Ref<StyleBox> bg = get_theme_stylebox("bg");
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
int mw = scroll_bar->get_minimum_size().x;
scroll_bar->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -mw);
@@ -884,24 +884,24 @@ void ItemList::_notification(int p_what) {
draw_style_box(bg, Rect2(Point2(), size));
- int hseparation = get_theme_constant("hseparation");
- int vseparation = get_theme_constant("vseparation");
- int icon_margin = get_theme_constant("icon_margin");
- int line_separation = get_theme_constant("line_separation");
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
+ int hseparation = get_theme_constant(SNAME("hseparation"));
+ int vseparation = get_theme_constant(SNAME("vseparation"));
+ int icon_margin = get_theme_constant(SNAME("icon_margin"));
+ int line_separation = get_theme_constant(SNAME("line_separation"));
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
- Ref<StyleBox> sbsel = has_focus() ? get_theme_stylebox("selected_focus") : get_theme_stylebox("selected");
- Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox("cursor") : get_theme_stylebox("cursor_unfocused");
+ Ref<StyleBox> sbsel = has_focus() ? get_theme_stylebox(SNAME("selected_focus")) : get_theme_stylebox(SNAME("selected"));
+ Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox(SNAME("cursor")) : get_theme_stylebox(SNAME("cursor_unfocused"));
bool rtl = is_layout_rtl();
- Color guide_color = get_theme_color("guide_color");
- Color font_color = get_theme_color("font_color");
- Color font_selected_color = get_theme_color("font_selected_color");
+ Color guide_color = get_theme_color(SNAME("guide_color"));
+ Color font_color = get_theme_color(SNAME("font_color"));
+ Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
if (has_focus()) {
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true);
- draw_style_box(get_theme_stylebox("bg_focus"), Rect2(Point2(), size));
+ draw_style_box(get_theme_stylebox(SNAME("bg_focus")), Rect2(Point2(), size));
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false);
}
@@ -1299,7 +1299,7 @@ void ItemList::_scroll_changed(double) {
int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const {
Vector2 pos = p_pos;
- Ref<StyleBox> bg = get_theme_stylebox("bg");
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
pos -= bg->get_offset();
pos.y += scroll_bar->get_value();
@@ -1337,7 +1337,7 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const {
}
Vector2 pos = p_pos;
- Ref<StyleBox> bg = get_theme_stylebox("bg");
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
pos -= bg->get_offset();
pos.y += scroll_bar->get_value();
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 6580d794d1..06faf3fa3e 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -36,20 +36,20 @@
#include "servers/text_server.h"
-void Label::set_autowrap(bool p_autowrap) {
- if (autowrap != p_autowrap) {
- autowrap = p_autowrap;
+void Label::set_autowrap_mode(Label::AutowrapMode p_mode) {
+ if (autowrap_mode != p_mode) {
+ autowrap_mode = p_mode;
lines_dirty = true;
}
update();
- if (clip) {
+ if (clip || overrun_behavior != OVERRUN_NO_TRIMMING) {
minimum_size_changed();
}
}
-bool Label::has_autowrap() const {
- return autowrap;
+Label::AutowrapMode Label::get_autowrap_mode() const {
+ return autowrap_mode;
}
void Label::set_uppercase(bool p_uppercase) {
@@ -64,7 +64,7 @@ bool Label::is_uppercase() const {
}
int Label::get_line_height(int p_line) const {
- Ref<Font> font = get_theme_font("font");
+ Ref<Font> font = get_theme_font(SNAME("font"));
if (p_line >= 0 && p_line < lines_rid.size()) {
return TS->shaped_text_get_size(lines_rid[p_line]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM);
} else if (lines_rid.size() > 0) {
@@ -74,12 +74,12 @@ int Label::get_line_height(int p_line) const {
}
return h;
} else {
- return font->get_height(get_theme_font_size("font_size"));
+ return font->get_height(get_theme_font_size(SNAME("font_size")));
}
}
void Label::_shape() {
- Ref<StyleBox> style = get_theme_stylebox("normal", "Label");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"), SNAME("Label"));
int width = (get_size().width - style->get_minimum_size().width);
if (dirty) {
@@ -89,29 +89,81 @@ void Label::_shape() {
} else {
TS->shaped_text_set_direction(text_rid, (TextServer::Direction)text_direction);
}
- TS->shaped_text_add_string(text_rid, (uppercase) ? xl_text.to_upper() : xl_text, get_theme_font("font")->get_rids(), get_theme_font_size("font_size"), opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
+ TS->shaped_text_add_string(text_rid, (uppercase) ? xl_text.to_upper() : xl_text, get_theme_font(SNAME("font"))->get_rids(), get_theme_font_size(SNAME("font_size")), opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, xl_text));
dirty = false;
lines_dirty = true;
}
+
+ uint8_t overrun_flags = TextServer::OVERRUN_NO_TRIMMING;
if (lines_dirty) {
for (int i = 0; i < lines_rid.size(); i++) {
TS->free(lines_rid[i]);
}
lines_rid.clear();
- Vector<Vector2i> lines = TS->shaped_text_get_line_breaks(text_rid, width, 0, (autowrap) ? (TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND) : TextServer::BREAK_MANDATORY);
+ uint8_t autowrap_flags = TextServer::BREAK_MANDATORY;
+ switch (autowrap_mode) {
+ case AUTOWRAP_WORD_SMART:
+ autowrap_flags = TextServer::BREAK_WORD_BOUND_ADAPTIVE | TextServer::BREAK_MANDATORY;
+ break;
+ case AUTOWRAP_WORD:
+ autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_MANDATORY;
+ break;
+ case AUTOWRAP_ARBITRARY:
+ autowrap_flags = TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_MANDATORY;
+ break;
+ case AUTOWRAP_OFF:
+ break;
+ }
+ Vector<Vector2i> lines = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags);
+
for (int i = 0; i < lines.size(); i++) {
RID line = TS->shaped_text_substr(text_rid, lines[i].x, lines[i].y - lines[i].x);
+
+ switch (overrun_behavior) {
+ case OVERRUN_TRIM_WORD_ELLIPSIS:
+ overrun_flags |= TextServer::OVERRUN_TRIM;
+ overrun_flags |= TextServer::OVERRUN_TRIM_WORD_ONLY;
+ overrun_flags |= TextServer::OVERRUN_ADD_ELLIPSIS;
+ break;
+ case OVERRUN_TRIM_ELLIPSIS:
+ overrun_flags |= TextServer::OVERRUN_TRIM;
+ overrun_flags |= TextServer::OVERRUN_ADD_ELLIPSIS;
+ break;
+ case OVERRUN_TRIM_WORD:
+ overrun_flags |= TextServer::OVERRUN_TRIM;
+ overrun_flags |= TextServer::OVERRUN_TRIM_WORD_ONLY;
+ break;
+ case OVERRUN_TRIM_CHAR:
+ overrun_flags |= TextServer::OVERRUN_TRIM;
+ break;
+ case OVERRUN_NO_TRIMMING:
+ break;
+ }
+
+ if (autowrap_mode == AUTOWRAP_OFF && align != ALIGN_FILL && overrun_behavior != OVERRUN_NO_TRIMMING) {
+ TS->shaped_text_overrun_trim_to_width(line, width, overrun_flags);
+ }
+
lines_rid.push_back(line);
}
+
+ if (autowrap_mode != AUTOWRAP_OFF && overrun_behavior != OVERRUN_NO_TRIMMING) {
+ int visible_lines = get_visible_line_count();
+
+ if (visible_lines < lines_rid.size() && visible_lines > 0) {
+ overrun_flags |= TextServer::OVERRUN_ENFORCE_ELLIPSIS;
+ TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags);
+ }
+ }
}
if (xl_text.length() == 0) {
minsize = Size2(1, get_line_height());
return;
}
- if (!autowrap) {
+ if (autowrap_mode == AUTOWRAP_OFF) {
minsize.width = 0.0f;
for (int i = 0; i < lines_rid.size(); i++) {
if (minsize.width < TS->shaped_text_get_size(lines_rid[i]).x) {
@@ -120,10 +172,21 @@ void Label::_shape() {
}
}
- if (lines_dirty) { // Fill after min_size calculation.
+ if (lines_dirty) {
+ // Fill after min_size calculation.
if (align == ALIGN_FILL) {
for (int i = 0; i < lines_rid.size(); i++) {
- TS->shaped_text_fit_to_width(lines_rid.write[i], width);
+ if (overrun_behavior != OVERRUN_NO_TRIMMING && autowrap_mode == AUTOWRAP_OFF) {
+ float line_unaltered_width = TS->shaped_text_get_width(lines_rid[i]);
+ TS->shaped_text_fit_to_width(lines_rid[i], width);
+ float new_line_width = TS->shaped_text_get_width(lines_rid[i]);
+ // Begin trimming when there is no space between words available anymore.
+ if (new_line_width < line_unaltered_width) {
+ TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags);
+ }
+ } else {
+ TS->shaped_text_fit_to_width(lines_rid[i], width);
+ }
}
}
lines_dirty = false;
@@ -131,15 +194,15 @@ void Label::_shape() {
_update_visible();
- if (!autowrap || !clip) {
+ if (autowrap_mode == AUTOWRAP_OFF || !clip || overrun_behavior == OVERRUN_NO_TRIMMING) {
minimum_size_changed();
}
}
void Label::_update_visible() {
- int line_spacing = get_theme_constant("line_spacing", "Label");
- Ref<StyleBox> style = get_theme_stylebox("normal", "Label");
- Ref<Font> font = get_theme_font("font");
+ int line_spacing = get_theme_constant(SNAME("line_spacing"), SNAME("Label"));
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"), SNAME("Label"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
int lines_visible = lines_rid.size();
if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
@@ -181,15 +244,15 @@ void Label::_notification(int p_what) {
Size2 string_size;
Size2 size = get_size();
- Ref<StyleBox> style = get_theme_stylebox("normal");
- Ref<Font> font = get_theme_font("font");
- Color font_color = get_theme_color("font_color");
- Color font_shadow_color = get_theme_color("font_shadow_color");
- Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
- int line_spacing = get_theme_constant("line_spacing");
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
- int shadow_outline_size = get_theme_constant("shadow_outline_size");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ Color font_color = get_theme_color(SNAME("font_color"));
+ Color font_shadow_color = get_theme_color(SNAME("font_shadow_color"));
+ Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y")));
+ int line_spacing = get_theme_constant(SNAME("line_spacing"));
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
+ int shadow_outline_size = get_theme_constant(SNAME("shadow_outline_size"));
bool rtl = is_layout_rtl();
style->draw(ci, Rect2(Point2(0, 0), get_size()));
@@ -366,17 +429,16 @@ Size2 Label::get_minimum_size() const {
Size2 min_size = minsize;
- Ref<Font> font = get_theme_font("font");
- min_size.height = MAX(min_size.height, font->get_height(get_theme_font_size("font_size")) + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM));
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ min_size.height = MAX(min_size.height, font->get_height(get_theme_font_size(SNAME("font_size"))) + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM));
- Size2 min_style = get_theme_stylebox("normal")->get_minimum_size();
- if (autowrap) {
- return Size2(1, clip ? 1 : min_size.height) + min_style;
+ Size2 min_style = get_theme_stylebox(SNAME("normal"))->get_minimum_size();
+ if (autowrap_mode != AUTOWRAP_OFF) {
+ return Size2(1, (clip || overrun_behavior != OVERRUN_NO_TRIMMING) ? 1 : min_size.height) + min_style;
} else {
- if (clip) {
+ if (clip || overrun_behavior != OVERRUN_NO_TRIMMING) {
min_size.width = 1;
}
-
return min_size + min_style;
}
}
@@ -393,9 +455,9 @@ int Label::get_line_count() const {
}
int Label::get_visible_line_count() const {
- Ref<Font> font = get_theme_font("font");
- Ref<StyleBox> style = get_theme_stylebox("normal");
- int line_spacing = get_theme_constant("line_spacing");
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
+ int line_spacing = get_theme_constant(SNAME("line_spacing"));
int lines_visible = 0;
float total_h = 0.0;
for (int64_t i = lines_skipped; i < lines_rid.size(); i++) {
@@ -536,6 +598,21 @@ bool Label::is_clipping_text() const {
return clip;
}
+void Label::set_text_overrun_behavior(Label::OverrunBehavior p_behavior) {
+ if (overrun_behavior != p_behavior) {
+ overrun_behavior = p_behavior;
+ lines_dirty = true;
+ }
+ update();
+ if (clip || overrun_behavior != OVERRUN_NO_TRIMMING) {
+ minimum_size_changed();
+ }
+}
+
+Label::OverrunBehavior Label::get_text_overrun_behavior() const {
+ return overrun_behavior;
+}
+
String Label::get_text() const {
return text;
}
@@ -663,10 +740,12 @@ void Label::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_opentype_features"), &Label::clear_opentype_features);
ClassDB::bind_method(D_METHOD("set_language", "language"), &Label::set_language);
ClassDB::bind_method(D_METHOD("get_language"), &Label::get_language);
- ClassDB::bind_method(D_METHOD("set_autowrap", "enable"), &Label::set_autowrap);
- ClassDB::bind_method(D_METHOD("has_autowrap"), &Label::has_autowrap);
+ ClassDB::bind_method(D_METHOD("set_autowrap_mode", "autowrap_mode"), &Label::set_autowrap_mode);
+ ClassDB::bind_method(D_METHOD("get_autowrap_mode"), &Label::get_autowrap_mode);
ClassDB::bind_method(D_METHOD("set_clip_text", "enable"), &Label::set_clip_text);
ClassDB::bind_method(D_METHOD("is_clipping_text"), &Label::is_clipping_text);
+ ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &Label::set_text_overrun_behavior);
+ ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &Label::get_text_overrun_behavior);
ClassDB::bind_method(D_METHOD("set_uppercase", "enable"), &Label::set_uppercase);
ClassDB::bind_method(D_METHOD("is_uppercase"), &Label::is_uppercase);
ClassDB::bind_method(D_METHOD("get_line_height", "line"), &Label::get_line_height, DEFVAL(-1));
@@ -696,13 +775,25 @@ void Label::_bind_methods() {
BIND_ENUM_CONSTANT(VALIGN_BOTTOM);
BIND_ENUM_CONSTANT(VALIGN_FILL);
+ BIND_ENUM_CONSTANT(AUTOWRAP_OFF);
+ BIND_ENUM_CONSTANT(AUTOWRAP_ARBITRARY);
+ BIND_ENUM_CONSTANT(AUTOWRAP_WORD);
+ BIND_ENUM_CONSTANT(AUTOWRAP_WORD_SMART);
+
+ BIND_ENUM_CONSTANT(OVERRUN_NO_TRIMMING);
+ BIND_ENUM_CONSTANT(OVERRUN_TRIM_CHAR);
+ BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD);
+ BIND_ENUM_CONSTANT(OVERRUN_TRIM_ELLIPSIS);
+ BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ELLIPSIS);
+
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language");
ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align");
ADD_PROPERTY(PropertyInfo(Variant::INT, "valign", PROPERTY_HINT_ENUM, "Top,Center,Bottom,Fill"), "set_valign", "get_valign");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autowrap"), "set_autowrap", "has_autowrap");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_mode", PROPERTY_HINT_ENUM, "Off,Arbitrary,Word,Word (Smart)"), "set_autowrap_mode", "get_autowrap_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "is_clipping_text");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim nothing,Trim characters,Trim words,Ellipsis,Word ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uppercase"), "set_uppercase", "is_uppercase");
ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1", PROPERTY_USAGE_EDITOR), "set_visible_characters", "get_visible_characters");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
diff --git a/scene/gui/label.h b/scene/gui/label.h
index 032b4112e1..8b48eb9670 100644
--- a/scene/gui/label.h
+++ b/scene/gui/label.h
@@ -51,13 +51,29 @@ public:
VALIGN_FILL
};
+ enum AutowrapMode {
+ AUTOWRAP_OFF,
+ AUTOWRAP_ARBITRARY,
+ AUTOWRAP_WORD,
+ AUTOWRAP_WORD_SMART
+ };
+
+ enum OverrunBehavior {
+ OVERRUN_NO_TRIMMING,
+ OVERRUN_TRIM_CHAR,
+ OVERRUN_TRIM_WORD,
+ OVERRUN_TRIM_ELLIPSIS,
+ OVERRUN_TRIM_WORD_ELLIPSIS,
+ };
+
private:
Align align = ALIGN_LEFT;
VAlign valign = VALIGN_TOP;
String text;
String xl_text;
- bool autowrap = false;
+ AutowrapMode autowrap_mode = AUTOWRAP_OFF;
bool clip = false;
+ OverrunBehavior overrun_behavior = OVERRUN_NO_TRIMMING;
Size2 minsize;
bool uppercase = false;
@@ -118,8 +134,8 @@ public:
void set_structured_text_bidi_override_options(Array p_args);
Array get_structured_text_bidi_override_options() const;
- void set_autowrap(bool p_autowrap);
- bool has_autowrap() const;
+ void set_autowrap_mode(AutowrapMode p_mode);
+ AutowrapMode get_autowrap_mode() const;
void set_uppercase(bool p_uppercase);
bool is_uppercase() const;
@@ -131,6 +147,9 @@ public:
void set_clip_text(bool p_clip);
bool is_clipping_text() const;
+ void set_text_overrun_behavior(OverrunBehavior p_behavior);
+ OverrunBehavior get_text_overrun_behavior() const;
+
void set_percent_visible(float p_percent);
float get_percent_visible() const;
@@ -150,5 +169,7 @@ public:
VARIANT_ENUM_CAST(Label::Align);
VARIANT_ENUM_CAST(Label::VAlign);
+VARIANT_ENUM_CAST(Label::AutowrapMode);
+VARIANT_ENUM_CAST(Label::OverrunBehavior);
#endif
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index f2d0d9bb22..19ffcfca6d 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -227,9 +227,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
return;
}
if (b->is_pressed() && b->get_button_index() == MOUSE_BUTTON_RIGHT && context_menu_enabled) {
+ _ensure_menu();
menu->set_position(get_screen_transform().xform(get_local_mouse_position()));
menu->set_size(Vector2(1, 1));
- _generate_context_menu();
menu->popup();
grab_focus();
accept_event();
@@ -348,10 +348,10 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
if (context_menu_enabled) {
if (k->is_action("ui_menu", true)) {
- Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + get_theme_font("font")->get_height(get_theme_font_size("font_size"))) / 2);
+ _ensure_menu();
+ Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + get_theme_font(SNAME("font"))->get_height(get_theme_font_size(SNAME("font_size")))) / 2);
menu->set_position(get_global_transform().xform(pos));
menu->set_size(Vector2(1, 1));
- _generate_context_menu();
menu->popup();
menu->grab_focus();
}
@@ -359,7 +359,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
// Default is ENTER and KP_ENTER. Cannot use ui_accept as default includes SPACE
if (k->is_action("ui_text_submit", false)) {
- emit_signal("text_submitted", text);
+ emit_signal(SNAME("text_submitted"), text);
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
}
@@ -567,8 +567,8 @@ bool LineEdit::_is_over_clear_button(const Point2 &p_pos) const {
if (!clear_button_enabled || !has_point(p_pos)) {
return false;
}
- Ref<Texture2D> icon = Control::get_theme_icon("clear");
- int x_ofs = get_theme_stylebox("normal")->get_offset().x;
+ Ref<Texture2D> icon = Control::get_theme_icon(SNAME("clear"));
+ int x_ofs = get_theme_stylebox(SNAME("normal"))->get_offset().x;
return p_pos.x > get_size().width - icon->get_width() - x_ofs;
}
@@ -612,7 +612,7 @@ void LineEdit::_notification(int p_what) {
update();
} break;
case NOTIFICATION_DRAW: {
- if ((!has_focus() && !menu->has_focus() && !caret_force_displayed) || !window_has_focus) {
+ if ((!has_focus() && !(menu && menu->has_focus()) && !caret_force_displayed) || !window_has_focus) {
draw_caret = false;
}
@@ -625,17 +625,17 @@ void LineEdit::_notification(int p_what) {
RID ci = get_canvas_item();
- Ref<StyleBox> style = get_theme_stylebox("normal");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
if (!is_editable()) {
- style = get_theme_stylebox("read_only");
+ style = get_theme_stylebox(SNAME("read_only"));
draw_caret = false;
}
- Ref<Font> font = get_theme_font("font");
+ Ref<Font> font = get_theme_font(SNAME("font"));
style->draw(ci, Rect2(Point2(), size));
if (has_focus()) {
- get_theme_stylebox("focus")->draw(ci, Rect2(Point2(), size));
+ get_theme_stylebox(SNAME("focus"))->draw(ci, Rect2(Point2(), size));
}
int x_ofs = 0;
@@ -673,10 +673,10 @@ void LineEdit::_notification(int p_what) {
int y_area = height - style->get_minimum_size().height;
int y_ofs = style->get_offset().y + (y_area - text_height) / 2;
- Color selection_color = get_theme_color("selection_color");
- Color font_color = is_editable() ? get_theme_color("font_color") : get_theme_color("font_uneditable_color");
- Color font_selected_color = get_theme_color("font_selected_color");
- Color caret_color = get_theme_color("caret_color");
+ Color selection_color = get_theme_color(SNAME("selection_color"));
+ Color font_color = is_editable() ? get_theme_color(SNAME("font_color")) : get_theme_color(SNAME("font_uneditable_color"));
+ Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
+ Color caret_color = get_theme_color(SNAME("caret_color"));
// Draw placeholder color.
if (using_placeholder) {
@@ -685,13 +685,13 @@ void LineEdit::_notification(int p_what) {
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
- Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon;
+ Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon;
Color color_icon(1, 1, 1, !is_editable() ? .5 * .9 : .9);
if (display_clear_icon) {
if (clear_button_status.press_attempt && clear_button_status.pressing_inside) {
- color_icon = get_theme_color("clear_button_color_pressed");
+ color_icon = get_theme_color(SNAME("clear_button_color_pressed"));
} else {
- color_icon = get_theme_color("clear_button_color");
+ color_icon = get_theme_color(SNAME("clear_button_color"));
}
}
@@ -738,8 +738,8 @@ void LineEdit::_notification(int p_what) {
// Draw text.
ofs.y += TS->shaped_text_get_ascent(text_rid);
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
if (outline_size > 0 && font_outline_color.a > 0) {
Vector2 oofs = ofs;
for (int i = 0; i < gl_size; i++) {
@@ -784,7 +784,7 @@ void LineEdit::_notification(int p_what) {
if (l_caret == Rect2() && t_caret == Rect2()) {
// No carets, add one at the start.
- int h = get_theme_font("font")->get_height(get_theme_font_size("font_size"));
+ int h = get_theme_font(SNAME("font"))->get_height(get_theme_font_size(SNAME("font_size")));
int y = style->get_offset().y + (y_area - h) / 2;
if (rtl) {
l_dir = TextServer::DIRECTION_RTL;
@@ -1006,7 +1006,7 @@ void LineEdit::shift_selection_check_post(bool p_shift) {
}
void LineEdit::set_caret_at_pixel_pos(int p_x) {
- Ref<StyleBox> style = get_theme_stylebox("normal");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
bool rtl = is_layout_rtl();
int x_ofs = 0;
@@ -1039,7 +1039,7 @@ void LineEdit::set_caret_at_pixel_pos(int p_x) {
bool using_placeholder = text.is_empty() && ime_text.is_empty();
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
- Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon;
+ Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon;
if (align == ALIGN_CENTER) {
if (scroll_offset == 0) {
x_ofs = MAX(style->get_margin(SIDE_LEFT), int(get_size().width - text_width - r_icon->get_width() - style->get_margin(SIDE_RIGHT) * 2) / 2);
@@ -1054,7 +1054,7 @@ void LineEdit::set_caret_at_pixel_pos(int p_x) {
}
Vector2i LineEdit::get_caret_pixel_pos() {
- Ref<StyleBox> style = get_theme_stylebox("normal");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
bool rtl = is_layout_rtl();
int x_ofs = 0;
@@ -1087,7 +1087,7 @@ Vector2i LineEdit::get_caret_pixel_pos() {
bool using_placeholder = text.is_empty() && ime_text.is_empty();
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
- Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon;
+ Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon;
if (align == ALIGN_CENTER) {
if (scroll_offset == 0) {
x_ofs = MAX(style->get_margin(SIDE_LEFT), int(get_size().width - text_width - r_icon->get_width() - style->get_margin(SIDE_RIGHT) * 2) / 2);
@@ -1252,10 +1252,12 @@ void LineEdit::set_text_direction(Control::TextDirection p_text_direction) {
}
_shape();
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
+ if (menu_dir) {
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
+ }
update();
}
}
@@ -1302,7 +1304,9 @@ String LineEdit::get_language() const {
void LineEdit::set_draw_control_chars(bool p_draw_control_chars) {
if (draw_control_chars != p_draw_control_chars) {
draw_control_chars = p_draw_control_chars;
- menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
+ if (menu && menu->get_item_index(MENU_DISPLAY_UCC) >= 0) {
+ menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
+ }
_shape();
update();
}
@@ -1396,7 +1400,7 @@ void LineEdit::set_caret_column(int p_column) {
return;
}
- Ref<StyleBox> style = get_theme_stylebox("normal");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
bool rtl = is_layout_rtl();
int x_ofs = 0;
@@ -1430,7 +1434,7 @@ void LineEdit::set_caret_column(int p_column) {
bool using_placeholder = text.is_empty() && ime_text.is_empty();
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
- Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon;
+ Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon;
if (align == ALIGN_CENTER) {
if (scroll_offset == 0) {
x_ofs = MAX(style->get_margin(SIDE_LEFT), int(get_size().width - text_width - r_icon->get_width() - style->get_margin(SIDE_RIGHT) * 2) / 2);
@@ -1474,7 +1478,7 @@ void LineEdit::insert_text_at_caret(String p_text) {
// Truncate text to append to fit in max_length, if needed.
int available_chars = max_length - text.length();
if (p_text.length() > available_chars) {
- emit_signal("text_change_rejected", p_text.substr(available_chars));
+ emit_signal(SNAME("text_change_rejected"), p_text.substr(available_chars));
p_text = p_text.substr(0, available_chars);
}
}
@@ -1501,15 +1505,15 @@ void LineEdit::clear_internal() {
}
Size2 LineEdit::get_minimum_size() const {
- Ref<StyleBox> style = get_theme_stylebox("normal");
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
Size2 min_size;
// Minimum size of text.
int em_space_size = font->get_char_size('M', 0, font_size).x;
- min_size.width = get_theme_constant("minimum_character_width") * em_space_size;
+ min_size.width = get_theme_constant(SNAME("minimum_character_width")) * em_space_size;
if (expand_to_text_length) {
// Add a space because some fonts are too exact, and because caret needs a bit more when at the end.
@@ -1522,7 +1526,7 @@ Size2 LineEdit::get_minimum_size() const {
bool using_placeholder = text.is_empty() && ime_text.is_empty();
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
- Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon;
+ Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon;
min_size.width += r_icon->get_width();
min_size.height = MAX(min_size.height, r_icon->get_height());
}
@@ -1596,7 +1600,6 @@ void LineEdit::set_editable(bool p_editable) {
}
editable = p_editable;
- _generate_context_menu();
minimum_size_changed();
update();
@@ -1810,7 +1813,12 @@ bool LineEdit::is_context_menu_enabled() {
return context_menu_enabled;
}
+bool LineEdit::is_menu_visible() const {
+ return menu && menu->is_visible();
+}
+
PopupMenu *LineEdit::get_menu() const {
+ const_cast<LineEdit *>(this)->_ensure_menu();
return menu;
}
@@ -1847,8 +1855,6 @@ bool LineEdit::is_clear_button_enabled() const {
void LineEdit::set_shortcut_keys_enabled(bool p_enabled) {
shortcut_keys_enabled = p_enabled;
-
- _generate_context_menu();
}
bool LineEdit::is_shortcut_keys_enabled() const {
@@ -1869,8 +1875,6 @@ void LineEdit::set_selecting_enabled(bool p_enabled) {
if (!selecting_enabled) {
deselect();
}
-
- _generate_context_menu();
}
bool LineEdit::is_selecting_enabled() const {
@@ -1897,7 +1901,7 @@ void LineEdit::_text_changed() {
}
void LineEdit::_emit_text_change() {
- emit_signal("text_changed", text);
+ emit_signal(SNAME("text_changed"), text);
text_changed_dirty = false;
}
@@ -1924,8 +1928,8 @@ void LineEdit::_shape() {
}
TS->shaped_text_set_preserve_control(text_rid, draw_control_chars);
- const Ref<Font> &font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ const Ref<Font> &font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
TS->shaped_text_add_string(text_rid, t, font->get_rids(), font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, t));
@@ -1941,12 +1945,12 @@ void LineEdit::_shape() {
void LineEdit::_fit_to_width() {
if (align == ALIGN_FILL) {
- Ref<StyleBox> style = get_theme_stylebox("normal");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
int t_width = get_size().width - style->get_margin(SIDE_RIGHT) - style->get_margin(SIDE_LEFT);
bool using_placeholder = text.is_empty() && ime_text.is_empty();
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
- Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon;
+ Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon;
t_width -= r_icon->get_width();
}
TS->shaped_text_fit_to_width(text_rid, MAX(t_width, full_width));
@@ -2007,35 +2011,6 @@ int LineEdit::_get_menu_action_accelerator(const String &p_action) {
}
}
-void LineEdit::_generate_context_menu() {
- // Reorganize context menu.
- menu->clear();
- if (editable) {
- menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0);
- }
- menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0);
- if (editable) {
- menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0);
- }
- menu->add_separator();
- if (is_selecting_enabled()) {
- menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0);
- }
- if (editable) {
- menu->add_item(RTR("Clear"), MENU_CLEAR);
- menu->add_separator();
- menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0);
- menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0);
- }
- menu->add_separator();
- menu->add_submenu_item(RTR("Text writing direction"), "DirMenu");
- menu->add_separator();
- menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC);
- if (editable) {
- menu->add_submenu_item(RTR("Insert control character"), "CTLMenu");
- }
-}
-
bool LineEdit::_set(const StringName &p_name, const Variant &p_value) {
String str = p_name;
if (str.begins_with("opentype_features/")) {
@@ -2148,6 +2123,7 @@ void LineEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_secret_character"), &LineEdit::get_secret_character);
ClassDB::bind_method(D_METHOD("menu_option", "option"), &LineEdit::menu_option);
ClassDB::bind_method(D_METHOD("get_menu"), &LineEdit::get_menu);
+ ClassDB::bind_method(D_METHOD("is_menu_visible"), &LineEdit::is_menu_visible);
ClassDB::bind_method(D_METHOD("set_context_menu_enabled", "enable"), &LineEdit::set_context_menu_enabled);
ClassDB::bind_method(D_METHOD("is_context_menu_enabled"), &LineEdit::is_context_menu_enabled);
ClassDB::bind_method(D_METHOD("set_virtual_keyboard_enabled", "enable"), &LineEdit::set_virtual_keyboard_enabled);
@@ -2230,6 +2206,79 @@ void LineEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_mid_grapheme"), "set_caret_mid_grapheme_enabled", "is_caret_mid_grapheme_enabled");
}
+void LineEdit::_ensure_menu() {
+ if (!menu) {
+ menu = memnew(PopupMenu);
+ add_child(menu);
+
+ menu_dir = memnew(PopupMenu);
+ menu_dir->set_name("DirMenu");
+ menu_dir->add_radio_check_item(RTR("Same as layout direction"), MENU_DIR_INHERITED);
+ menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO);
+ menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR);
+ menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL);
+ menu->add_child(menu_dir);
+
+ menu_ctl = memnew(PopupMenu);
+ menu_ctl->set_name("CTLMenu");
+ menu_ctl->add_item(RTR("Left-to-right mark (LRM)"), MENU_INSERT_LRM);
+ menu_ctl->add_item(RTR("Right-to-left mark (RLM)"), MENU_INSERT_RLM);
+ menu_ctl->add_item(RTR("Start of left-to-right embedding (LRE)"), MENU_INSERT_LRE);
+ menu_ctl->add_item(RTR("Start of right-to-left embedding (RLE)"), MENU_INSERT_RLE);
+ menu_ctl->add_item(RTR("Start of left-to-right override (LRO)"), MENU_INSERT_LRO);
+ menu_ctl->add_item(RTR("Start of right-to-left override (RLO)"), MENU_INSERT_RLO);
+ menu_ctl->add_item(RTR("Pop direction formatting (PDF)"), MENU_INSERT_PDF);
+ menu_ctl->add_separator();
+ menu_ctl->add_item(RTR("Arabic letter mark (ALM)"), MENU_INSERT_ALM);
+ menu_ctl->add_item(RTR("Left-to-right isolate (LRI)"), MENU_INSERT_LRI);
+ menu_ctl->add_item(RTR("Right-to-left isolate (RLI)"), MENU_INSERT_RLI);
+ menu_ctl->add_item(RTR("First strong isolate (FSI)"), MENU_INSERT_FSI);
+ menu_ctl->add_item(RTR("Pop direction isolate (PDI)"), MENU_INSERT_PDI);
+ menu_ctl->add_separator();
+ menu_ctl->add_item(RTR("Zero width joiner (ZWJ)"), MENU_INSERT_ZWJ);
+ menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
+ menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ);
+ menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY);
+ menu->add_child(menu_ctl);
+
+ menu->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
+ menu_dir->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
+ menu_ctl->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
+ }
+
+ // Reorganize context menu.
+ menu->clear();
+ if (editable) {
+ menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0);
+ }
+ menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0);
+ if (editable) {
+ menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0);
+ }
+ menu->add_separator();
+ if (is_selecting_enabled()) {
+ menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0);
+ }
+ if (editable) {
+ menu->add_item(RTR("Clear"), MENU_CLEAR);
+ menu->add_separator();
+ menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0);
+ menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0);
+ }
+ menu->add_separator();
+ menu->add_submenu_item(RTR("Text writing direction"), "DirMenu");
+ menu->add_separator();
+ menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC);
+ menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
+ if (editable) {
+ menu->add_submenu_item(RTR("Insert control character"), "CTLMenu");
+ }
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
+}
+
LineEdit::LineEdit() {
text_rid = TS->create_shaped_text();
_create_undo_state();
@@ -2245,44 +2294,7 @@ LineEdit::LineEdit() {
caret_blink_timer->connect("timeout", callable_mp(this, &LineEdit::_toggle_draw_caret));
set_caret_blink_enabled(false);
- menu = memnew(PopupMenu);
- add_child(menu);
-
- menu_dir = memnew(PopupMenu);
- menu_dir->set_name("DirMenu");
- menu_dir->add_radio_check_item(RTR("Same as layout direction"), MENU_DIR_INHERITED);
- menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO);
- menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR);
- menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), true);
- menu->add_child(menu_dir);
-
- menu_ctl = memnew(PopupMenu);
- menu_ctl->set_name("CTLMenu");
- menu_ctl->add_item(RTR("Left-to-right mark (LRM)"), MENU_INSERT_LRM);
- menu_ctl->add_item(RTR("Right-to-left mark (RLM)"), MENU_INSERT_RLM);
- menu_ctl->add_item(RTR("Start of left-to-right embedding (LRE)"), MENU_INSERT_LRE);
- menu_ctl->add_item(RTR("Start of right-to-left embedding (RLE)"), MENU_INSERT_RLE);
- menu_ctl->add_item(RTR("Start of left-to-right override (LRO)"), MENU_INSERT_LRO);
- menu_ctl->add_item(RTR("Start of right-to-left override (RLO)"), MENU_INSERT_RLO);
- menu_ctl->add_item(RTR("Pop direction formatting (PDF)"), MENU_INSERT_PDF);
- menu_ctl->add_separator();
- menu_ctl->add_item(RTR("Arabic letter mark (ALM)"), MENU_INSERT_ALM);
- menu_ctl->add_item(RTR("Left-to-right isolate (LRI)"), MENU_INSERT_LRI);
- menu_ctl->add_item(RTR("Right-to-left isolate (RLI)"), MENU_INSERT_RLI);
- menu_ctl->add_item(RTR("First strong isolate (FSI)"), MENU_INSERT_FSI);
- menu_ctl->add_item(RTR("Pop direction isolate (PDI)"), MENU_INSERT_PDI);
- menu_ctl->add_separator();
- menu_ctl->add_item(RTR("Zero width joiner (ZWJ)"), MENU_INSERT_ZWJ);
- menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
- menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ);
- menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY);
- menu->add_child(menu_ctl);
-
set_editable(true); // Initialise to opposite first, so we get past the early-out in set_editable.
- menu->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
- menu_dir->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
- menu_ctl->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
}
LineEdit::~LineEdit() {
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index 12fec2f98b..c5c92d60aa 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -165,7 +165,6 @@ private:
void _create_undo_state();
int _get_menu_action_accelerator(const String &p_action);
- void _generate_context_menu();
void _shape();
void _fit_to_width();
@@ -198,6 +197,8 @@ private:
void _backspace(bool p_word = false, bool p_all_to_left = false);
void _delete(bool p_word = false, bool p_all_to_right = false);
+ void _ensure_menu();
+
protected:
void _notification(int p_what);
static void _bind_methods();
@@ -222,6 +223,7 @@ public:
void set_context_menu_enabled(bool p_enable);
bool is_context_menu_enabled();
PopupMenu *get_menu() const;
+ bool is_menu_visible() const;
void select(int p_from = 0, int p_to = -1);
void select_all();
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index ee0618a991..419d49bccf 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -32,8 +32,8 @@
#include "core/string/translation.h"
void LinkButton::_shape() {
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
text_buf->clear();
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
@@ -158,41 +158,41 @@ void LinkButton::_notification(int p_what) {
switch (get_draw_mode()) {
case DRAW_NORMAL: {
- color = get_theme_color("font_color");
+ color = get_theme_color(SNAME("font_color"));
do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
} break;
case DRAW_HOVER_PRESSED:
case DRAW_PRESSED: {
- if (has_theme_color("font_pressed_color")) {
- color = get_theme_color("font_pressed_color");
+ if (has_theme_color(SNAME("font_pressed_color"))) {
+ color = get_theme_color(SNAME("font_pressed_color"));
} else {
- color = get_theme_color("font_color");
+ color = get_theme_color(SNAME("font_color"));
}
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
} break;
case DRAW_HOVER: {
- color = get_theme_color("font_hover_color");
+ color = get_theme_color(SNAME("font_hover_color"));
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
} break;
case DRAW_DISABLED: {
- color = get_theme_color("font_disabled_color");
+ color = get_theme_color(SNAME("font_disabled_color"));
do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
} break;
}
if (has_focus()) {
- Ref<StyleBox> style = get_theme_stylebox("focus");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("focus"));
style->draw(ci, Rect2(Point2(), size));
}
int width = text_buf->get_line_width();
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
if (is_layout_rtl()) {
if (outline_size > 0 && font_outline_color.a > 0) {
text_buf->draw_outline(get_canvas_item(), Vector2(size.width - width, 0), outline_size, font_outline_color);
@@ -206,7 +206,7 @@ void LinkButton::_notification(int p_what) {
}
if (do_underline) {
- int underline_spacing = get_theme_constant("underline_spacing") + text_buf->get_line_underline_position();
+ int underline_spacing = get_theme_constant(SNAME("underline_spacing")) + text_buf->get_line_underline_position();
int y = text_buf->get_line_ascent() + underline_spacing;
if (is_layout_rtl()) {
diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp
index 0e9610d0a3..50b4d192a9 100644
--- a/scene/gui/margin_container.cpp
+++ b/scene/gui/margin_container.cpp
@@ -31,10 +31,10 @@
#include "margin_container.h"
Size2 MarginContainer::get_minimum_size() const {
- int margin_left = get_theme_constant("margin_left");
- int margin_top = get_theme_constant("margin_top");
- int margin_right = get_theme_constant("margin_right");
- int margin_bottom = get_theme_constant("margin_bottom");
+ int margin_left = get_theme_constant(SNAME("margin_left"));
+ int margin_top = get_theme_constant(SNAME("margin_top"));
+ int margin_right = get_theme_constant(SNAME("margin_right"));
+ int margin_bottom = get_theme_constant(SNAME("margin_bottom"));
Size2 max;
@@ -68,10 +68,10 @@ Size2 MarginContainer::get_minimum_size() const {
void MarginContainer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
- int margin_left = get_theme_constant("margin_left");
- int margin_top = get_theme_constant("margin_top");
- int margin_right = get_theme_constant("margin_right");
- int margin_bottom = get_theme_constant("margin_bottom");
+ int margin_left = get_theme_constant(SNAME("margin_left"));
+ int margin_top = get_theme_constant(SNAME("margin_top"));
+ int margin_right = get_theme_constant(SNAME("margin_right"));
+ int margin_bottom = get_theme_constant(SNAME("margin_bottom"));
Size2 s = get_size();
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index 1e9baa77fc..cf1f41d0fc 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -55,6 +55,36 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
}
}
+void MenuButton::_popup_visibility_changed(bool p_visible) {
+ set_pressed(p_visible);
+
+ if (!p_visible) {
+ set_process_internal(false);
+ return;
+ }
+
+ if (switch_on_hover) {
+ Window *window = Object::cast_to<Window>(get_viewport());
+ if (window) {
+ mouse_pos_adjusted = window->get_position();
+
+ if (window->is_embedded()) {
+ Window *window_parent = Object::cast_to<Window>(window->get_parent()->get_viewport());
+ while (window_parent) {
+ if (!window_parent->is_embedded()) {
+ mouse_pos_adjusted += window_parent->get_position();
+ break;
+ }
+
+ window_parent = Object::cast_to<Window>(window_parent->get_parent()->get_viewport());
+ }
+ }
+
+ set_process_internal(true);
+ }
+ }
+}
+
void MenuButton::pressed() {
Size2 size = get_size();
@@ -94,10 +124,22 @@ bool MenuButton::is_switch_on_hover() {
}
void MenuButton::_notification(int p_what) {
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- if (!is_visible_in_tree()) {
- popup->hide();
- }
+ switch (p_what) {
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (!is_visible_in_tree()) {
+ popup->hide();
+ }
+ } break;
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ Vector2i mouse_pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted;
+ MenuButton *menu_btn_other = Object::cast_to<MenuButton>(get_viewport()->gui_find_control(mouse_pos));
+
+ if (menu_btn_other && menu_btn_other != this && menu_btn_other->is_switch_on_hover() && !menu_btn_other->is_disabled() &&
+ (get_parent()->is_ancestor_of(menu_btn_other) || menu_btn_other->get_parent()->is_ancestor_of(popup))) {
+ popup->hide();
+ menu_btn_other->pressed();
+ }
+ } break;
}
}
@@ -130,8 +172,8 @@ MenuButton::MenuButton() {
popup = memnew(PopupMenu);
popup->hide();
add_child(popup);
- popup->connect("about_to_popup", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); // For when switching from another MenuButton.
- popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false));
+ popup->connect("about_to_popup", callable_mp(this, &MenuButton::_popup_visibility_changed), varray(true));
+ popup->connect("popup_hide", callable_mp(this, &MenuButton::_popup_visibility_changed), varray(false));
}
MenuButton::~MenuButton() {
diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h
index fd9ae6021e..cc2ca117c4 100644
--- a/scene/gui/menu_button.h
+++ b/scene/gui/menu_button.h
@@ -42,11 +42,15 @@ class MenuButton : public Button {
bool disable_shortcuts = false;
PopupMenu *popup;
+ Vector2i mouse_pos_adjusted;
+
Array _get_items() const;
void _set_items(const Array &p_items);
void _gui_input(Ref<InputEvent> p_event) override;
+ void _popup_visibility_changed(bool p_visible);
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index e52b6917be..cd55f258b3 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -35,12 +35,12 @@
Size2 OptionButton::get_minimum_size() const {
Size2 minsize = Button::get_minimum_size();
- if (has_theme_icon("arrow")) {
- const Size2 padding = get_theme_stylebox("normal")->get_minimum_size();
- const Size2 arrow_size = Control::get_theme_icon("arrow")->get_size();
+ if (has_theme_icon(SNAME("arrow"))) {
+ const Size2 padding = get_theme_stylebox(SNAME("normal"))->get_minimum_size();
+ const Size2 arrow_size = Control::get_theme_icon(SNAME("arrow"))->get_size();
Size2 content_size = minsize - padding;
- content_size.width += arrow_size.width + get_theme_constant("hseparation");
+ content_size.width += arrow_size.width + get_theme_constant(SNAME("hseparation"));
content_size.height = MAX(content_size.height, arrow_size.height);
minsize = content_size + padding;
@@ -52,26 +52,26 @@ Size2 OptionButton::get_minimum_size() const {
void OptionButton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (!has_theme_icon("arrow")) {
+ if (!has_theme_icon(SNAME("arrow"))) {
return;
}
RID ci = get_canvas_item();
- Ref<Texture2D> arrow = Control::get_theme_icon("arrow");
+ Ref<Texture2D> arrow = Control::get_theme_icon(SNAME("arrow"));
Color clr = Color(1, 1, 1);
- if (get_theme_constant("modulate_arrow")) {
+ if (get_theme_constant(SNAME("modulate_arrow"))) {
switch (get_draw_mode()) {
case DRAW_PRESSED:
- clr = get_theme_color("font_pressed_color");
+ clr = get_theme_color(SNAME("font_pressed_color"));
break;
case DRAW_HOVER:
- clr = get_theme_color("font_hover_color");
+ clr = get_theme_color(SNAME("font_hover_color"));
break;
case DRAW_DISABLED:
- clr = get_theme_color("font_disabled_color");
+ clr = get_theme_color(SNAME("font_disabled_color"));
break;
default:
- clr = get_theme_color("font_color");
+ clr = get_theme_color(SNAME("font_color"));
}
}
@@ -79,22 +79,22 @@ void OptionButton::_notification(int p_what) {
Point2 ofs;
if (is_layout_rtl()) {
- ofs = Point2(get_theme_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
+ ofs = Point2(get_theme_constant(SNAME("arrow_margin")), int(Math::abs((size.height - arrow->get_height()) / 2)));
} else {
- ofs = Point2(size.width - arrow->get_width() - get_theme_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
+ ofs = Point2(size.width - arrow->get_width() - get_theme_constant(SNAME("arrow_margin")), int(Math::abs((size.height - arrow->get_height()) / 2)));
}
arrow->draw(ci, ofs, clr);
} break;
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
- if (has_theme_icon("arrow")) {
+ if (has_theme_icon(SNAME("arrow"))) {
if (is_layout_rtl()) {
- _set_internal_margin(SIDE_LEFT, Control::get_theme_icon("arrow")->get_width());
+ _set_internal_margin(SIDE_LEFT, Control::get_theme_icon(SNAME("arrow"))->get_width());
_set_internal_margin(SIDE_RIGHT, 0.f);
} else {
_set_internal_margin(SIDE_LEFT, 0.f);
- _set_internal_margin(SIDE_RIGHT, Control::get_theme_icon("arrow")->get_width());
+ _set_internal_margin(SIDE_RIGHT, Control::get_theme_icon(SNAME("arrow"))->get_width());
}
}
} break;
@@ -107,7 +107,7 @@ void OptionButton::_notification(int p_what) {
}
void OptionButton::_focused(int p_which) {
- emit_signal("item_focused", p_which);
+ emit_signal(SNAME("item_focused"), p_which);
}
void OptionButton::_selected(int p_which) {
@@ -220,7 +220,7 @@ void OptionButton::_select(int p_which, bool p_emit) {
set_icon(popup->get_item_icon(current));
if (is_inside_tree() && p_emit) {
- emit_signal("item_selected", current);
+ emit_signal(SNAME("item_selected"), current);
}
}
@@ -339,12 +339,12 @@ OptionButton::OptionButton() {
set_toggle_mode(true);
set_text_align(ALIGN_LEFT);
if (is_layout_rtl()) {
- if (has_theme_icon("arrow")) {
- _set_internal_margin(SIDE_LEFT, Control::get_theme_icon("arrow")->get_width());
+ if (has_theme_icon(SNAME("arrow"))) {
+ _set_internal_margin(SIDE_LEFT, Control::get_theme_icon(SNAME("arrow"))->get_width());
}
} else {
- if (has_theme_icon("arrow")) {
- _set_internal_margin(SIDE_RIGHT, Control::get_theme_icon("arrow")->get_width());
+ if (has_theme_icon(SNAME("arrow"))) {
+ _set_internal_margin(SIDE_RIGHT, Control::get_theme_icon(SNAME("arrow"))->get_width());
}
}
set_action_mode(ACTION_MODE_BUTTON_PRESS);
diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp
index 995e985c3a..e8e7e3d997 100644
--- a/scene/gui/panel.cpp
+++ b/scene/gui/panel.cpp
@@ -35,7 +35,7 @@
void Panel::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item();
- Ref<StyleBox> style = mode == MODE_BACKGROUND ? get_theme_stylebox("panel") : get_theme_stylebox("panel_fg");
+ Ref<StyleBox> style = mode == MODE_BACKGROUND ? get_theme_stylebox(SNAME("panel")) : get_theme_stylebox(SNAME("panel_fg"));
style->draw(ci, Rect2(Point2(), get_size()));
}
}
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 11d822c5e1..d910e1e882 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -33,10 +33,10 @@
Size2 PanelContainer::get_minimum_size() const {
Ref<StyleBox> style;
- if (has_theme_stylebox("panel")) {
- style = get_theme_stylebox("panel");
+ if (has_theme_stylebox(SNAME("panel"))) {
+ style = get_theme_stylebox(SNAME("panel"));
} else {
- style = get_theme_stylebox("panel", "PanelContainer");
+ style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
}
Size2 ms;
@@ -65,10 +65,10 @@ void PanelContainer::_notification(int p_what) {
RID ci = get_canvas_item();
Ref<StyleBox> style;
- if (has_theme_stylebox("panel")) {
- style = get_theme_stylebox("panel");
+ if (has_theme_stylebox(SNAME("panel"))) {
+ style = get_theme_stylebox(SNAME("panel"));
} else {
- style = get_theme_stylebox("panel", "PanelContainer");
+ style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
}
style->draw(ci, Rect2(Point2(), get_size()));
@@ -77,10 +77,10 @@ void PanelContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_SORT_CHILDREN) {
Ref<StyleBox> style;
- if (has_theme_stylebox("panel")) {
- style = get_theme_stylebox("panel");
+ if (has_theme_stylebox(SNAME("panel"))) {
+ style = get_theme_stylebox(SNAME("panel"));
} else {
- style = get_theme_stylebox("panel", "PanelContainer");
+ style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
}
Size2 size = get_size();
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 36bcca61a7..f7e7e1cd60 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -71,7 +71,8 @@ void Popup::_notification(int p_what) {
_initialize_visible_parents();
} else {
_deinitialize_visible_parents();
- emit_signal("popup_hide");
+ emit_signal(SNAME("popup_hide"));
+ popped_up = false;
}
} break;
@@ -103,9 +104,9 @@ void Popup::_close_pressed() {
_deinitialize_visible_parents();
- call_deferred("hide");
+ call_deferred(SNAME("hide"));
- emit_signal("cancelled");
+ emit_signal(SNAME("cancelled"));
}
void Popup::set_as_minsize() {
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 2100707d2d..7790a0970c 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -46,15 +46,15 @@ String PopupMenu::_get_accel_text(const Item &p_item) const {
}
Size2 PopupMenu::_get_contents_minimum_size() const {
- int vseparation = get_theme_constant("vseparation");
- int hseparation = get_theme_constant("hseparation");
+ int vseparation = get_theme_constant(SNAME("vseparation"));
+ int hseparation = get_theme_constant(SNAME("hseparation"));
- Size2 minsize = get_theme_stylebox("panel")->get_minimum_size(); // Accounts for margin in the margin container
+ Size2 minsize = get_theme_stylebox(SNAME("panel"))->get_minimum_size(); // Accounts for margin in the margin container
minsize.x += scroll_container->get_v_scrollbar()->get_size().width * 2; // Adds a buffer so that the scrollbar does not render over the top of content
float max_w = 0.0;
float icon_w = 0.0;
- int check_w = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation;
+ int check_w = MAX(get_theme_icon(SNAME("checked"))->get_width(), get_theme_icon(SNAME("radio_checked"))->get_width()) + hseparation;
int accel_max_w = 0;
bool has_check = false;
@@ -81,7 +81,7 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
}
if (items[i].submenu != "") {
- size.width += get_theme_icon("submenu")->get_width();
+ size.width += get_theme_icon(SNAME("submenu"))->get_width();
}
max_w = MAX(max_w, size.width);
@@ -89,7 +89,7 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
minsize.height += size.height;
}
- int item_side_padding = get_theme_constant("item_start_padding") + get_theme_constant("item_end_padding");
+ int item_side_padding = get_theme_constant(SNAME("item_start_padding")) + get_theme_constant(SNAME("item_end_padding"));
minsize.width += max_w + icon_w + accel_max_w + item_side_padding;
if (has_check) {
@@ -112,24 +112,24 @@ int PopupMenu::_get_item_height(int p_item) const {
int icon_height = items[p_item].get_icon_size().height;
if (items[p_item].checkable_type) {
- icon_height = MAX(icon_height, MAX(get_theme_icon("checked")->get_height(), get_theme_icon("radio_checked")->get_height()));
+ icon_height = MAX(icon_height, MAX(get_theme_icon(SNAME("checked"))->get_height(), get_theme_icon(SNAME("radio_checked"))->get_height()));
}
int text_height = items[p_item].text_buf->get_size().height;
if (text_height == 0 && !items[p_item].separator) {
- text_height = get_theme_font("font")->get_height(get_theme_font_size("font_size"));
+ text_height = get_theme_font(SNAME("font"))->get_height(get_theme_font_size(SNAME("font_size")));
}
int separator_height = 0;
if (items[p_item].separator) {
- separator_height = MAX(get_theme_stylebox("separator")->get_minimum_size().height, MAX(get_theme_stylebox("labeled_separator_left")->get_minimum_size().height, get_theme_stylebox("labeled_separator_right")->get_minimum_size().height));
+ separator_height = MAX(get_theme_stylebox(SNAME("separator"))->get_minimum_size().height, MAX(get_theme_stylebox(SNAME("labeled_separator_left"))->get_minimum_size().height, get_theme_stylebox(SNAME("labeled_separator_right"))->get_minimum_size().height));
}
return MAX(separator_height, MAX(text_height, icon_height));
}
int PopupMenu::_get_items_total_height() const {
- int vsep = get_theme_constant("vseparation");
+ int vsep = get_theme_constant(SNAME("vseparation"));
// Get total height of all items by taking max of icon height and font height
int items_total_height = 0;
@@ -163,9 +163,9 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
return -1;
}
- Ref<StyleBox> style = get_theme_stylebox("panel"); // Accounts for margin in the margin container
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("panel")); // Accounts for margin in the margin container
- int vseparation = get_theme_constant("vseparation");
+ int vseparation = get_theme_constant(SNAME("vseparation"));
Point2 ofs = style->get_offset() + Point2(0, vseparation / 2);
@@ -195,8 +195,8 @@ void PopupMenu::_activate_submenu(int p_over) {
return; //already visible!
}
- Ref<StyleBox> style = get_theme_stylebox("panel");
- int vsep = get_theme_constant("vseparation");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("panel"));
+ int vsep = get_theme_constant(SNAME("vseparation"));
Point2 this_pos = get_position();
Rect2 this_rect(this_pos, get_size());
@@ -264,7 +264,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
for (int i = search_from; i < items.size(); i++) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal("id_focused", i);
+ emit_signal(SNAME("id_focused"), i);
_scroll_to_item(i);
control->update();
set_input_as_handled();
@@ -278,7 +278,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
for (int i = 0; i < search_from; i++) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal("id_focused", i);
+ emit_signal(SNAME("id_focused"), i);
_scroll_to_item(i);
control->update();
set_input_as_handled();
@@ -296,7 +296,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
for (int i = search_from; i >= 0; i--) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal("id_focused", i);
+ emit_signal(SNAME("id_focused"), i);
_scroll_to_item(i);
control->update();
set_input_as_handled();
@@ -310,7 +310,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
for (int i = items.size() - 1; i >= search_from; i--) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal("id_focused", i);
+ emit_signal(SNAME("id_focused"), i);
_scroll_to_item(i);
control->update();
set_input_as_handled();
@@ -397,17 +397,17 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
- if (!item_clickable_area.has_point(m->get_position())) {
- return;
- }
-
- for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
- if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) {
+ for (const Rect2 &E : autohide_areas) {
+ if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E.has_point(m->get_position())) {
_close_pressed();
return;
}
}
+ if (!item_clickable_area.has_point(m->get_position())) {
+ return;
+ }
+
int over = _get_mouse_over(m->get_position());
int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].id >= 0 ? items[over].id : over);
@@ -459,7 +459,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
if (items[i].text.findn(search_string) == 0) {
mouse_over = i;
- emit_signal("id_focused", i);
+ emit_signal(SNAME("id_focused"), i);
_scroll_to_item(i);
control->update();
set_input_as_handled();
@@ -474,37 +474,37 @@ void PopupMenu::_draw_items() {
RID ci = control->get_canvas_item();
Size2 margin_size;
- margin_size.width = margin_container->get_theme_constant("margin_right") + margin_container->get_theme_constant("margin_left");
- margin_size.height = margin_container->get_theme_constant("margin_top") + margin_container->get_theme_constant("margin_bottom");
+ margin_size.width = margin_container->get_theme_constant(SNAME("margin_right")) + margin_container->get_theme_constant(SNAME("margin_left"));
+ margin_size.height = margin_container->get_theme_constant(SNAME("margin_top")) + margin_container->get_theme_constant(SNAME("margin_bottom"));
// Space between the item content and the sides of popup menu.
- int item_start_padding = get_theme_constant("item_start_padding");
- int item_end_padding = get_theme_constant("item_end_padding");
+ int item_start_padding = get_theme_constant(SNAME("item_start_padding"));
+ int item_end_padding = get_theme_constant(SNAME("item_end_padding"));
bool rtl = control->is_layout_rtl();
- Ref<StyleBox> style = get_theme_stylebox("panel");
- Ref<StyleBox> hover = get_theme_stylebox("hover");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("panel"));
+ Ref<StyleBox> hover = get_theme_stylebox(SNAME("hover"));
// In Item::checkable_type enum order (less the non-checkable member)
- Ref<Texture2D> check[] = { get_theme_icon("checked"), get_theme_icon("radio_checked") };
- Ref<Texture2D> uncheck[] = { get_theme_icon("unchecked"), get_theme_icon("radio_unchecked") };
+ Ref<Texture2D> check[] = { get_theme_icon(SNAME("checked")), get_theme_icon(SNAME("radio_checked")) };
+ Ref<Texture2D> uncheck[] = { get_theme_icon(SNAME("unchecked")), get_theme_icon(SNAME("radio_unchecked")) };
Ref<Texture2D> submenu;
if (rtl) {
- submenu = get_theme_icon("submenu_mirrored");
+ submenu = get_theme_icon(SNAME("submenu_mirrored"));
} else {
- submenu = get_theme_icon("submenu");
+ submenu = get_theme_icon(SNAME("submenu"));
}
- Ref<StyleBox> separator = get_theme_stylebox("separator");
- Ref<StyleBox> labeled_separator_left = get_theme_stylebox("labeled_separator_left");
- Ref<StyleBox> labeled_separator_right = get_theme_stylebox("labeled_separator_right");
+ Ref<StyleBox> separator = get_theme_stylebox(SNAME("separator"));
+ Ref<StyleBox> labeled_separator_left = get_theme_stylebox(SNAME("labeled_separator_left"));
+ Ref<StyleBox> labeled_separator_right = get_theme_stylebox(SNAME("labeled_separator_right"));
- int vseparation = get_theme_constant("vseparation");
- int hseparation = get_theme_constant("hseparation");
- Color font_color = get_theme_color("font_color");
- Color font_disabled_color = get_theme_color("font_disabled_color");
- Color font_accelerator_color = get_theme_color("font_accelerator_color");
- Color font_hover_color = get_theme_color("font_hover_color");
- Color font_separator_color = get_theme_color("font_separator_color");
+ int vseparation = get_theme_constant(SNAME("vseparation"));
+ int hseparation = get_theme_constant(SNAME("hseparation"));
+ Color font_color = get_theme_color(SNAME("font_color"));
+ Color font_disabled_color = get_theme_color(SNAME("font_disabled_color"));
+ Color font_accelerator_color = get_theme_color(SNAME("font_accelerator_color"));
+ Color font_hover_color = get_theme_color(SNAME("font_hover_color"));
+ Color font_separator_color = get_theme_color(SNAME("font_separator_color"));
float scroll_width = scroll_container->get_v_scrollbar()->is_visible_in_tree() ? scroll_container->get_v_scrollbar()->get_size().width : 0;
float display_width = control->get_size().width - scroll_width;
@@ -525,7 +525,7 @@ void PopupMenu::_draw_items() {
float check_ofs = 0.0;
if (has_check) {
- check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation;
+ check_ofs = MAX(get_theme_icon(SNAME("checked"))->get_width(), get_theme_icon(SNAME("radio_checked"))->get_width()) + hseparation;
}
Point2 ofs = Point2();
@@ -606,8 +606,8 @@ void PopupMenu::_draw_items() {
}
// Text
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
if (items[i].separator) {
if (text != String()) {
int center = (display_width - items[i].text_buf->get_size().width) / 2;
@@ -657,7 +657,7 @@ void PopupMenu::_draw_items() {
}
void PopupMenu::_draw_background() {
- Ref<StyleBox> style = get_theme_stylebox("panel");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("panel"));
RID ci2 = margin_container->get_canvas_item();
style->draw(ci2, Rect2(Point2(), margin_container->get_size()));
}
@@ -691,8 +691,8 @@ void PopupMenu::_shape_item(int p_item) {
if (items.write[p_item].dirty) {
items.write[p_item].text_buf->clear();
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
if (items[p_item].text_direction == Control::TEXT_DIRECTION_INHERITED) {
items.write[p_item].text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
@@ -747,12 +747,12 @@ void PopupMenu::_notification(int p_what) {
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
//only used when using operating system windows
- if (get_window_id() != DisplayServer::INVALID_WINDOW_ID && autohide_areas.size()) {
+ if (!is_embedded() && autohide_areas.size()) {
Point2 mouse_pos = DisplayServer::get_singleton()->mouse_get_position();
mouse_pos -= get_position();
- for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
- if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E->get().has_point(mouse_pos)) {
+ for (const Rect2 &E : autohide_areas) {
+ if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E.has_point(mouse_pos)) {
_close_pressed();
return;
}
@@ -786,12 +786,12 @@ void PopupMenu::_notification(int p_what) {
set_process_internal(false);
} else {
- if (get_window_id() != DisplayServer::INVALID_WINDOW_ID) {
+ if (!is_embedded()) {
set_process_internal(true);
}
// Set margin on the margin container
- Ref<StyleBox> panel_style = get_theme_stylebox("panel");
+ Ref<StyleBox> panel_style = get_theme_stylebox(SNAME("panel"));
margin_container->add_theme_constant_override("margin_top", panel_style->get_margin(Side::SIDE_TOP));
margin_container->add_theme_constant_override("margin_bottom", panel_style->get_margin(Side::SIDE_BOTTOM));
margin_container->add_theme_constant_override("margin_left", panel_style->get_margin(Side::SIDE_LEFT));
@@ -1376,8 +1376,8 @@ void PopupMenu::activate_item(int p_item) {
need_hide = false;
}
- emit_signal("id_pressed", id);
- emit_signal("index_pressed", p_item);
+ emit_signal(SNAME("id_pressed"), id);
+ emit_signal(SNAME("index_pressed"), p_item);
if (need_hide) {
hide();
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index 74718395d3..aedc5d0155 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -140,7 +140,6 @@ class PopupMenu : public Popup {
void _close_pressed();
protected:
- friend class MenuButton;
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp
index 6e8dfd5994..2cfaaa2fde 100644
--- a/scene/gui/progress_bar.cpp
+++ b/scene/gui/progress_bar.cpp
@@ -32,10 +32,10 @@
#include "scene/resources/text_line.h"
Size2 ProgressBar::get_minimum_size() const {
- Ref<StyleBox> bg = get_theme_stylebox("bg");
- Ref<StyleBox> fg = get_theme_stylebox("fg");
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
+ Ref<StyleBox> fg = get_theme_stylebox(SNAME("fg"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
Size2 minimum_size = bg->get_minimum_size();
minimum_size.height = MAX(minimum_size.height, fg->get_minimum_size().height);
@@ -53,11 +53,11 @@ Size2 ProgressBar::get_minimum_size() const {
void ProgressBar::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
- Ref<StyleBox> bg = get_theme_stylebox("bg");
- Ref<StyleBox> fg = get_theme_stylebox("fg");
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
- Color font_color = get_theme_color("font_color");
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
+ Ref<StyleBox> fg = get_theme_stylebox(SNAME("fg"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
+ Color font_color = get_theme_color(SNAME("font_color"));
draw_style_box(bg, Rect2(Point2(), get_size()));
float r = get_as_ratio();
@@ -75,8 +75,8 @@ void ProgressBar::_notification(int p_what) {
String txt = TS->format_number(itos(int(get_as_ratio() * 100))) + TS->percent_sign();
TextLine tl = TextLine(txt, font, font_size);
Vector2 text_pos = (Point2(get_size().width - tl.get_size().x, get_size().height - tl.get_size().y) / 2).round();
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
if (outline_size > 0 && font_outline_color.a > 0) {
tl.draw_outline(get_canvas_item(), text_pos, outline_size, font_outline_color);
}
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index 4ea1e1eb9f..92d4261d8d 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -42,7 +42,7 @@ TypedArray<String> Range::get_configuration_warnings() const {
void Range::_value_changed_notify() {
_value_changed(shared->val);
- emit_signal("value_changed", shared->val);
+ emit_signal(SNAME("value_changed"), shared->val);
update();
}
@@ -57,7 +57,7 @@ void Range::Shared::emit_value_changed() {
}
void Range::_changed_notify(const char *p_what) {
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
update();
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index f32ad2144a..3925e0c38e 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -136,7 +136,7 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) co
}
Rect2 RichTextLabel::_get_text_rect() {
- Ref<StyleBox> style = get_theme_stylebox("normal");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
return Rect2(style->get_offset(), get_size() - style->get_minimum_size());
}
@@ -229,8 +229,8 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
switch (it->type) {
case ITEM_TABLE: {
ItemTable *table = static_cast<ItemTable *>(it);
- int hseparation = get_theme_constant("table_hseparation");
- int vseparation = get_theme_constant("table_vseparation");
+ int hseparation = get_theme_constant(SNAME("table_hseparation"));
+ int vseparation = get_theme_constant(SNAME("table_vseparation"));
int col_count = table->columns.size();
for (int i = 0; i < col_count; i++) {
@@ -238,9 +238,9 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
}
int idx = 0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
for (int i = 0; i < frame->lines.size(); i++) {
_resize_line(frame, i, p_base_font, p_base_font_size, 1);
}
@@ -316,9 +316,9 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
Vector2 offset;
float row_height = 0.0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int column = idx % col_count;
@@ -458,8 +458,8 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
} break;
case ITEM_TABLE: {
ItemTable *table = static_cast<ItemTable *>(it);
- int hseparation = get_theme_constant("table_hseparation");
- int vseparation = get_theme_constant("table_vseparation");
+ int hseparation = get_theme_constant(SNAME("table_hseparation"));
+ int vseparation = get_theme_constant(SNAME("table_vseparation"));
int col_count = table->columns.size();
int t_char_count = 0;
// Set minimums to zero.
@@ -472,9 +472,9 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
const int available_width = p_width - hseparation * (col_count - 1);
int idx = 0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int column = idx % col_count;
for (int i = 0; i < frame->lines.size(); i++) {
@@ -556,7 +556,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
Vector2 offset;
float row_height = 0.0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ for (const List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
ItemFrame *frame = static_cast<ItemFrame *>(E->get());
@@ -672,11 +672,11 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
if (prefix != "") {
Ref<Font> font = _find_font(l.from);
if (font.is_null()) {
- font = get_theme_font("normal_font");
+ font = get_theme_font(SNAME("normal_font"));
}
int font_size = _find_font_size(l.from);
if (font_size == -1) {
- font_size = get_theme_font_size("normal_font_size");
+ font_size = get_theme_font_size(SNAME("normal_font_size"));
}
if (rtl) {
float offx = 0.0f;
@@ -775,16 +775,16 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
} break;
case ITEM_TABLE: {
ItemTable *table = static_cast<ItemTable *>(it);
- Color odd_row_bg = get_theme_color("table_odd_row_bg");
- Color even_row_bg = get_theme_color("table_even_row_bg");
- Color border = get_theme_color("table_border");
- int hseparation = get_theme_constant("table_hseparation");
+ Color odd_row_bg = get_theme_color(SNAME("table_odd_row_bg"));
+ Color even_row_bg = get_theme_color(SNAME("table_even_row_bg"));
+ Color border = get_theme_color(SNAME("table_border"));
+ int hseparation = get_theme_constant(SNAME("table_hseparation"));
int col_count = table->columns.size();
int row_count = table->rows.size();
int idx = 0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int col = idx % col_count;
int row = idx / col_count;
@@ -916,7 +916,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
}
}
- Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
+ Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y")));
// Draw glyph outlines.
for (int j = 0; j < glyphs[i].repeat; j++) {
@@ -940,8 +940,8 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
_draw_fbg_boxes(ci, rid, fbg_line_off, it_from, it_to, chr_range.x, chr_range.y, 0);
// Draw main text.
- Color selection_fg = get_theme_color("font_selected_color");
- Color selection_bg = get_theme_color("selection_color");
+ Color selection_fg = get_theme_color(SNAME("font_selected_color"));
+ Color selection_bg = get_theme_color(SNAME("selection_color"));
int sel_start = -1;
int sel_end = -1;
@@ -1192,8 +1192,8 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
if (rect.has_point(p_click - p_ofs - off)) {
switch (it->type) {
case ITEM_TABLE: {
- int hseparation = get_theme_constant("table_hseparation");
- int vseparation = get_theme_constant("table_vseparation");
+ int hseparation = get_theme_constant(SNAME("table_hseparation"));
+ int vseparation = get_theme_constant(SNAME("table_vseparation"));
ItemTable *table = static_cast<ItemTable *>(it);
@@ -1203,8 +1203,8 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
int col_count = table->columns.size();
int row_count = table->rows.size();
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int col = idx % col_count;
int row = idx / col_count;
@@ -1362,7 +1362,7 @@ void RichTextLabel::_notification(int p_what) {
case NOTIFICATION_MOUSE_EXIT: {
if (meta_hovering) {
meta_hovering = nullptr;
- emit_signal("meta_hover_ended", current_meta);
+ emit_signal(SNAME("meta_hover_ended"), current_meta);
current_meta = false;
update();
}
@@ -1395,11 +1395,11 @@ void RichTextLabel::_notification(int p_what) {
Size2 size = get_size();
Rect2 text_rect = _get_text_rect();
- draw_style_box(get_theme_stylebox("normal"), Rect2(Point2(), size));
+ draw_style_box(get_theme_stylebox(SNAME("normal")), Rect2(Point2(), size));
if (has_focus()) {
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
- draw_style_box(get_theme_stylebox("focus"), Rect2(Point2(), size));
+ draw_style_box(get_theme_stylebox(SNAME("focus")), Rect2(Point2(), size));
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
}
@@ -1419,13 +1419,13 @@ void RichTextLabel::_notification(int p_what) {
if (from_line >= main->lines.size()) {
break; //nothing to draw
}
- Ref<Font> base_font = get_theme_font("normal_font");
- Color base_color = get_theme_color("default_color");
- Color outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
- Color font_shadow_color = get_theme_color("font_shadow_color");
- bool use_outline = get_theme_constant("shadow_as_outline");
- Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
+ Ref<Font> base_font = get_theme_font(SNAME("normal_font"));
+ Color base_color = get_theme_color(SNAME("default_color"));
+ Color outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
+ Color font_shadow_color = get_theme_color(SNAME("font_shadow_color"));
+ bool use_outline = get_theme_constant(SNAME("shadow_as_outline"));
+ Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y")));
visible_paragraph_count = 0;
visible_line_count = 0;
@@ -1568,7 +1568,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
Variant meta;
if (!outside && _find_meta(c_item, &meta)) {
//meta clicked
- emit_signal("meta_clicked", meta);
+ emit_signal(SNAME("meta_clicked"), meta);
}
}
}
@@ -1611,11 +1611,11 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
handled = true;
}
if (k->is_action("ui_up") && vscroll->is_visible_in_tree()) {
- vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size")));
+ vscroll->set_value(vscroll->get_value() - get_theme_font(SNAME("normal_font"))->get_height(get_theme_font_size(SNAME("normal_font_size"))));
handled = true;
}
if (k->is_action("ui_down") && vscroll->is_visible_in_tree()) {
- vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size")));
+ vscroll->set_value(vscroll->get_value() + get_theme_font(SNAME("normal_font"))->get_height(get_theme_font_size(SNAME("normal_font_size"))));
handled = true;
}
if (k->is_action("ui_home") && vscroll->is_visible_in_tree()) {
@@ -1693,15 +1693,15 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
if (c_item && !outside && _find_meta(c_item, &meta, &item_meta)) {
if (meta_hovering != item_meta) {
if (meta_hovering) {
- emit_signal("meta_hover_ended", current_meta);
+ emit_signal(SNAME("meta_hover_ended"), current_meta);
}
meta_hovering = item_meta;
current_meta = meta;
- emit_signal("meta_hover_started", meta);
+ emit_signal(SNAME("meta_hover_started"), meta);
}
} else if (meta_hovering) {
meta_hovering = nullptr;
- emit_signal("meta_hover_ended", current_meta);
+ emit_signal(SNAME("meta_hover_ended"), current_meta);
current_meta = false;
}
}
@@ -2080,8 +2080,8 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
return true;
}
- for (List<Item *>::Element *E = from->subitems.front(); E; E = E->next()) {
- bool layout = _find_layout_subitem(E->get(), to);
+ for (Item *E : from->subitems) {
+ bool layout = _find_layout_subitem(E, to);
if (layout) {
return true;
@@ -2105,8 +2105,8 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
}
Rect2 text_rect = _get_text_rect();
- Ref<Font> base_font = get_theme_font("normal_font");
- int base_font_size = get_theme_font_size("normal_font_size");
+ Ref<Font> base_font = get_theme_font(SNAME("normal_font"));
+ int base_font_size = get_theme_font_size(SNAME("normal_font_size"));
for (int i = p_frame->first_resized_line; i < p_frame->lines.size(); i++) {
_resize_line(p_frame, i, base_font, base_font_size, text_rect.get_size().width - scroll_w);
@@ -2140,8 +2140,8 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
}
Rect2 text_rect = _get_text_rect();
- Ref<Font> base_font = get_theme_font("normal_font");
- int base_font_size = get_theme_font_size("normal_font_size");
+ Ref<Font> base_font = get_theme_font(SNAME("normal_font"));
+ int base_font_size = get_theme_font_size(SNAME("normal_font_size"));
int total_chars = (p_frame->first_invalid_line == 0) ? 0 : (p_frame->lines[p_frame->first_invalid_line].char_offset + p_frame->lines[p_frame->first_invalid_line].char_count);
for (int i = p_frame->first_invalid_line; i < p_frame->lines.size(); i++) {
@@ -2406,35 +2406,35 @@ void RichTextLabel::push_font(const Ref<Font> &p_font) {
}
void RichTextLabel::push_normal() {
- Ref<Font> normal_font = get_theme_font("normal_font");
+ Ref<Font> normal_font = get_theme_font(SNAME("normal_font"));
ERR_FAIL_COND(normal_font.is_null());
push_font(normal_font);
}
void RichTextLabel::push_bold() {
- Ref<Font> bold_font = get_theme_font("bold_font");
+ Ref<Font> bold_font = get_theme_font(SNAME("bold_font"));
ERR_FAIL_COND(bold_font.is_null());
push_font(bold_font);
}
void RichTextLabel::push_bold_italics() {
- Ref<Font> bold_italics_font = get_theme_font("bold_italics_font");
+ Ref<Font> bold_italics_font = get_theme_font(SNAME("bold_italics_font"));
ERR_FAIL_COND(bold_italics_font.is_null());
push_font(bold_italics_font);
}
void RichTextLabel::push_italics() {
- Ref<Font> italics_font = get_theme_font("italics_font");
+ Ref<Font> italics_font = get_theme_font(SNAME("italics_font"));
ERR_FAIL_COND(italics_font.is_null());
push_font(italics_font);
}
void RichTextLabel::push_mono() {
- Ref<Font> mono_font = get_theme_font("mono_font");
+ Ref<Font> mono_font = get_theme_font(SNAME("mono_font"));
ERR_FAIL_COND(mono_font.is_null());
push_font(mono_font);
@@ -2774,13 +2774,13 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
int pos = 0;
List<String> tag_stack;
- Ref<Font> normal_font = get_theme_font("normal_font");
- Ref<Font> bold_font = get_theme_font("bold_font");
- Ref<Font> italics_font = get_theme_font("italics_font");
- Ref<Font> bold_italics_font = get_theme_font("bold_italics_font");
- Ref<Font> mono_font = get_theme_font("mono_font");
+ Ref<Font> normal_font = get_theme_font(SNAME("normal_font"));
+ Ref<Font> bold_font = get_theme_font(SNAME("bold_font"));
+ Ref<Font> italics_font = get_theme_font(SNAME("italics_font"));
+ Ref<Font> bold_italics_font = get_theme_font(SNAME("bold_italics_font"));
+ Ref<Font> mono_font = get_theme_font(SNAME("mono_font"));
- Color base_color = get_theme_color("default_color");
+ Color base_color = get_theme_color(SNAME("default_color"));
int indent_level = 0;
@@ -3140,11 +3140,11 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front("url");
} else if (tag.begins_with("dropcap")) {
Vector<String> subtag = tag.substr(5, tag.length()).split(" ");
- Ref<Font> f = get_theme_font("normal_font");
- int fs = get_theme_font_size("normal_font_size") * 3;
- Color color = get_theme_color("default_color");
- Color outline_color = get_theme_color("outline_color");
- int outline_size = get_theme_constant("outline_size");
+ Ref<Font> f = get_theme_font(SNAME("normal_font"));
+ int fs = get_theme_font_size(SNAME("normal_font_size")) * 3;
+ Color color = get_theme_color(SNAME("default_color"));
+ Color outline_color = get_theme_color(SNAME("outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
Rect2 dropcap_margins = Rect2();
for (int i = 0; i < subtag.size(); i++) {
@@ -3448,8 +3448,8 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
Vector<ItemFX *> fx_items;
- for (List<Item *>::Element *E = main->subitems.front(); E; E = E->next()) {
- Item *subitem = static_cast<Item *>(E->get());
+ for (Item *E : main->subitems) {
+ Item *subitem = static_cast<Item *>(E);
_fetch_item_fx_stack(subitem, fx_items);
if (fx_items.size()) {
@@ -3719,9 +3719,9 @@ String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p
ItemTable *table = static_cast<ItemTable *>(it);
int idx = 0;
int col_count = table->columns.size();
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int column = idx % col_count;
for (int i = 0; i < frame->lines.size(); i++) {
@@ -4168,7 +4168,7 @@ void RichTextLabel::set_fixed_size_to_width(int p_width) {
}
Size2 RichTextLabel::get_minimum_size() const {
- Ref<StyleBox> style = get_theme_stylebox("normal");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
Size2 size = style->get_minimum_size();
if (fixed_width != -1) {
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index 62276e3af0..ce04a0204b 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -46,7 +46,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseMotion> m = p_event;
if (!m.is_valid() || drag.active) {
- emit_signal("scrolling");
+ emit_signal(SNAME("scrolling"));
}
Ref<InputEventMouseButton> b = p_event;
@@ -70,8 +70,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
if (b->is_pressed()) {
double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x;
- Ref<Texture2D> decr = get_theme_icon("decrement");
- Ref<Texture2D> incr = get_theme_icon("increment");
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
@@ -140,7 +140,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
if (drag.active) {
double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x;
- Ref<Texture2D> decr = get_theme_icon("decrement");
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
ofs -= decr_size;
@@ -150,8 +150,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
set_as_ratio(drag.value_at_click + diff);
} else {
double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x;
- Ref<Texture2D> decr = get_theme_icon("decrement");
- Ref<Texture2D> incr = get_theme_icon("increment");
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
@@ -215,17 +215,17 @@ void ScrollBar::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item();
- Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon("decrement_highlight") : get_theme_icon("decrement");
- Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_theme_icon("increment_highlight") : get_theme_icon("increment");
- Ref<StyleBox> bg = has_focus() ? get_theme_stylebox("scroll_focus") : get_theme_stylebox("scroll");
+ Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon(SNAME("decrement_highlight")) : get_theme_icon(SNAME("decrement"));
+ Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_theme_icon(SNAME("increment_highlight")) : get_theme_icon(SNAME("increment"));
+ Ref<StyleBox> bg = has_focus() ? get_theme_stylebox(SNAME("scroll_focus")) : get_theme_stylebox(SNAME("scroll"));
Ref<StyleBox> grabber;
if (drag.active) {
- grabber = get_theme_stylebox("grabber_pressed");
+ grabber = get_theme_stylebox(SNAME("grabber_pressed"));
} else if (highlight == HIGHLIGHT_RANGE) {
- grabber = get_theme_stylebox("grabber_highlight");
+ grabber = get_theme_stylebox(SNAME("grabber_highlight"));
} else {
- grabber = get_theme_stylebox("grabber");
+ grabber = get_theme_stylebox(SNAME("grabber"));
}
Point2 ofs;
@@ -389,7 +389,7 @@ void ScrollBar::_notification(int p_what) {
}
double ScrollBar::get_grabber_min_size() const {
- Ref<StyleBox> grabber = get_theme_stylebox("grabber");
+ Ref<StyleBox> grabber = get_theme_stylebox(SNAME("grabber"));
Size2 gminsize = grabber->get_minimum_size() + grabber->get_center_size();
return (orientation == VERTICAL) ? gminsize.height : gminsize.width;
}
@@ -415,17 +415,17 @@ double ScrollBar::get_area_size() const {
switch (orientation) {
case VERTICAL: {
double area = get_size().height;
- area -= get_theme_stylebox("scroll")->get_minimum_size().height;
- area -= get_theme_icon("increment")->get_height();
- area -= get_theme_icon("decrement")->get_height();
+ area -= get_theme_stylebox(SNAME("scroll"))->get_minimum_size().height;
+ area -= get_theme_icon(SNAME("increment"))->get_height();
+ area -= get_theme_icon(SNAME("decrement"))->get_height();
area -= get_grabber_min_size();
return area;
} break;
case HORIZONTAL: {
double area = get_size().width;
- area -= get_theme_stylebox("scroll")->get_minimum_size().width;
- area -= get_theme_icon("increment")->get_width();
- area -= get_theme_icon("decrement")->get_width();
+ area -= get_theme_stylebox(SNAME("scroll"))->get_minimum_size().width;
+ area -= get_theme_icon(SNAME("increment"))->get_width();
+ area -= get_theme_icon(SNAME("decrement"))->get_width();
area -= get_grabber_min_size();
return area;
} break;
@@ -439,13 +439,13 @@ double ScrollBar::get_area_offset() const {
double ofs = 0.0;
if (orientation == VERTICAL) {
- ofs += get_theme_stylebox("hscroll")->get_margin(SIDE_TOP);
- ofs += get_theme_icon("decrement")->get_height();
+ ofs += get_theme_stylebox(SNAME("hscroll"))->get_margin(SIDE_TOP);
+ ofs += get_theme_icon(SNAME("decrement"))->get_height();
}
if (orientation == HORIZONTAL) {
- ofs += get_theme_stylebox("hscroll")->get_margin(SIDE_LEFT);
- ofs += get_theme_icon("decrement")->get_width();
+ ofs += get_theme_stylebox(SNAME("hscroll"))->get_margin(SIDE_LEFT);
+ ofs += get_theme_icon(SNAME("decrement"))->get_width();
}
return ofs;
@@ -456,9 +456,9 @@ double ScrollBar::get_grabber_offset() const {
}
Size2 ScrollBar::get_minimum_size() const {
- Ref<Texture2D> incr = get_theme_icon("increment");
- Ref<Texture2D> decr = get_theme_icon("decrement");
- Ref<StyleBox> bg = get_theme_stylebox("scroll");
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("scroll"));
Size2 minsize;
if (orientation == VERTICAL) {
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 177f146b6a..eb5fc924da 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -33,7 +33,7 @@
#include "scene/main/window.h"
Size2 ScrollContainer::get_minimum_size() const {
- Ref<StyleBox> sb = get_theme_stylebox("bg");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg"));
Size2 min_size;
for (int i = 0; i < get_child_count(); i++) {
@@ -77,7 +77,7 @@ void ScrollContainer::_cancel_drag() {
drag_from = Vector2();
if (beyond_deadzone) {
- emit_signal("scroll_ended");
+ emit_signal(SNAME("scroll_ended"));
propagate_notification(NOTIFICATION_SCROLL_END);
beyond_deadzone = false;
}
@@ -173,7 +173,7 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (beyond_deadzone || (scroll_h && Math::abs(drag_accum.x) > deadzone) || (scroll_v && Math::abs(drag_accum.y) > deadzone)) {
if (!beyond_deadzone) {
propagate_notification(NOTIFICATION_SCROLL_BEGIN);
- emit_signal("scroll_started");
+ emit_signal(SNAME("scroll_started"));
beyond_deadzone = true;
// resetting drag_accum here ensures smooth scrolling after reaching deadzone
@@ -260,7 +260,7 @@ void ScrollContainer::_update_dimensions() {
Size2 size = get_size();
Point2 ofs;
- Ref<StyleBox> sb = get_theme_stylebox("bg");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg"));
size -= sb->get_minimum_size();
ofs += sb->get_offset();
bool rtl = is_layout_rtl();
@@ -319,7 +319,7 @@ void ScrollContainer::_update_dimensions() {
void ScrollContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) {
_updating_scrollbars = true;
- call_deferred("_update_scrollbar_position");
+ call_deferred(SNAME("_update_scrollbar_position"));
};
if (p_what == NOTIFICATION_READY) {
@@ -332,7 +332,7 @@ void ScrollContainer::_notification(int p_what) {
};
if (p_what == NOTIFICATION_DRAW) {
- Ref<StyleBox> sb = get_theme_stylebox("bg");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg"));
draw_style_box(sb, Rect2(Vector2(), get_size()));
update_scrollbars();
@@ -409,7 +409,7 @@ void ScrollContainer::_notification(int p_what) {
void ScrollContainer::update_scrollbars() {
Size2 size = get_size();
- Ref<StyleBox> sb = get_theme_stylebox("bg");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg"));
size -= sb->get_minimum_size();
Size2 hmin;
diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp
index 3cb8ccf135..1f3cb7aa24 100644
--- a/scene/gui/separator.cpp
+++ b/scene/gui/separator.cpp
@@ -33,9 +33,9 @@
Size2 Separator::get_minimum_size() const {
Size2 ms(3, 3);
if (orientation == VERTICAL) {
- ms.x = get_theme_constant("separation");
+ ms.x = get_theme_constant(SNAME("separation"));
} else { // HORIZONTAL
- ms.y = get_theme_constant("separation");
+ ms.y = get_theme_constant(SNAME("separation"));
}
return ms;
}
@@ -44,7 +44,7 @@ void Separator::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
Size2i size = get_size();
- Ref<StyleBox> style = get_theme_stylebox("separator");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("separator"));
Size2i ssize = style->get_minimum_size() + style->get_center_size();
if (orientation == VERTICAL) {
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index 5947f3b99e..61b5325175 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -32,10 +32,10 @@
#include "core/os/keyboard.h"
Size2 Slider::get_minimum_size() const {
- Ref<StyleBox> style = get_theme_stylebox("slider");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("slider"));
Size2i ss = style->get_minimum_size() + style->get_center_size();
- Ref<Texture2D> grabber = get_theme_icon("grabber");
+ Ref<Texture2D> grabber = get_theme_icon(SNAME("grabber"));
Size2i rs = grabber->get_size();
if (orientation == HORIZONTAL) {
@@ -89,7 +89,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
if (mm.is_valid()) {
if (grab.active) {
Size2i size = get_size();
- Ref<Texture2D> grabber = get_theme_icon("grabber");
+ Ref<Texture2D> grabber = get_theme_icon(SNAME("grabber"));
float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos;
if (orientation == VERTICAL) {
motion = -motion;
@@ -161,11 +161,11 @@ void Slider::_notification(int p_what) {
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Size2i size = get_size();
- Ref<StyleBox> style = get_theme_stylebox("slider");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("slider"));
bool highlighted = mouse_inside || has_focus();
Ref<StyleBox> grabber_area = get_theme_stylebox(highlighted ? "grabber_area_highlight" : "grabber_area");
Ref<Texture2D> grabber = get_theme_icon(editable ? (highlighted ? "grabber_highlight" : "grabber") : "grabber_disabled");
- Ref<Texture2D> tick = get_theme_icon("tick");
+ Ref<Texture2D> tick = get_theme_icon(SNAME("tick"));
double ratio = Math::is_nan(get_as_ratio()) ? 0 : get_as_ratio();
if (orientation == VERTICAL) {
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 941dd30057..3f0368a4e2 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -170,7 +170,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
void SpinBox::_line_edit_focus_exit() {
// discontinue because the focus_exit was caused by right-click context menu
- if (line_edit->get_menu()->is_visible()) {
+ if (line_edit->is_menu_visible()) {
return;
}
@@ -188,7 +188,7 @@ inline void SpinBox::_adjust_width_for_icon(const Ref<Texture2D> &icon) {
void SpinBox::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
- Ref<Texture2D> updown = get_theme_icon("updown");
+ Ref<Texture2D> updown = get_theme_icon(SNAME("updown"));
_adjust_width_for_icon(updown);
@@ -204,15 +204,15 @@ void SpinBox::_notification(int p_what) {
} else if (p_what == NOTIFICATION_FOCUS_EXIT) {
//_value_changed(0);
} else if (p_what == NOTIFICATION_ENTER_TREE) {
- _adjust_width_for_icon(get_theme_icon("updown"));
+ _adjust_width_for_icon(get_theme_icon(SNAME("updown")));
_value_changed(0);
} else if (p_what == NOTIFICATION_EXIT_TREE) {
_release_mouse();
} else if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
_value_changed(0);
} else if (p_what == NOTIFICATION_THEME_CHANGED) {
- call_deferred("minimum_size_changed");
- get_line_edit()->call_deferred("minimum_size_changed");
+ call_deferred(SNAME("minimum_size_changed"));
+ get_line_edit()->call_deferred(SNAME("minimum_size_changed"));
} else if (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) {
update();
}
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 9796b32c6b..3114e5b7c0 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -76,8 +76,8 @@ void SplitContainer::_resort() {
bool second_expanded = (vertical ? second->get_v_size_flags() : second->get_h_size_flags()) & SIZE_EXPAND;
// Determine the separation between items
- Ref<Texture2D> g = get_theme_icon("grabber");
- int sep = get_theme_constant("separation");
+ Ref<Texture2D> g = get_theme_icon(SNAME("grabber"));
+ int sep = get_theme_constant(SNAME("separation"));
sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0;
// Compute the minimum size
@@ -131,8 +131,8 @@ Size2 SplitContainer::get_minimum_size() const {
/* Calculate MINIMUM SIZE */
Size2i minimum;
- Ref<Texture2D> g = get_theme_icon("grabber");
- int sep = get_theme_constant("separation");
+ Ref<Texture2D> g = get_theme_icon(SNAME("grabber"));
+ int sep = get_theme_constant(SNAME("separation"));
sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0;
for (int i = 0; i < 2; i++) {
@@ -173,7 +173,7 @@ void SplitContainer::_notification(int p_what) {
} break;
case NOTIFICATION_MOUSE_EXIT: {
mouse_inside = false;
- if (get_theme_constant("autohide")) {
+ if (get_theme_constant(SNAME("autohide"))) {
update();
}
} break;
@@ -182,7 +182,7 @@ void SplitContainer::_notification(int p_what) {
return;
}
- if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide"))) {
+ if (collapsed || (!dragging && !mouse_inside && get_theme_constant(SNAME("autohide")))) {
return;
}
@@ -190,8 +190,8 @@ void SplitContainer::_notification(int p_what) {
return;
}
- int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant("separation") : 0;
- Ref<Texture2D> tex = get_theme_icon("grabber");
+ int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant(SNAME("separation")) : 0;
+ Ref<Texture2D> tex = get_theme_icon(SNAME("grabber"));
Size2 size = get_size();
if (vertical) {
@@ -218,7 +218,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid()) {
if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
if (mb->is_pressed()) {
- int sep = get_theme_constant("separation");
+ int sep = get_theme_constant(SNAME("separation"));
if (vertical) {
if (mb->get_position().y > middle_sep && mb->get_position().y < middle_sep + sep) {
@@ -244,14 +244,14 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (mm.is_valid()) {
bool mouse_inside_state = false;
if (vertical) {
- mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant("separation");
+ mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant(SNAME("separation"));
} else {
- mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant("separation");
+ mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant(SNAME("separation"));
}
if (mouse_inside != mouse_inside_state) {
mouse_inside = mouse_inside_state;
- if (get_theme_constant("autohide")) {
+ if (get_theme_constant(SNAME("autohide"))) {
update();
}
}
@@ -267,7 +267,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
should_clamp_split_offset = true;
queue_sort();
- emit_signal("dragged", get_split_offset());
+ emit_signal(SNAME("dragged"), get_split_offset());
}
}
@@ -277,7 +277,7 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const
}
if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) {
- int sep = get_theme_constant("separation");
+ int sep = get_theme_constant(SNAME("separation"));
if (vertical) {
if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) {
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 133966013b..8f84585f9b 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -43,9 +43,9 @@ int TabContainer::_get_top_margin() const {
}
// Respect the minimum tab height.
- Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
- Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
- Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
+ Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
+ Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
int tab_height = MAX(MAX(tab_unselected->get_minimum_size().height, tab_selected->get_minimum_size().height), tab_disabled->get_minimum_size().height);
@@ -88,11 +88,11 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
// Handle menu button.
- Ref<Texture2D> menu = get_theme_icon("menu");
+ Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
if (is_layout_rtl()) {
if (popup && pos.x < menu->get_width()) {
- emit_signal("pre_popup_pressed");
+ emit_signal(SNAME("pre_popup_pressed"));
Vector2 popup_pos = get_screen_position();
popup_pos.y += menu->get_height();
@@ -103,7 +103,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
} else {
if (popup && pos.x > size.width - menu->get_width()) {
- emit_signal("pre_popup_pressed");
+ emit_signal(SNAME("pre_popup_pressed"));
Vector2 popup_pos = get_screen_position();
popup_pos.x += size.width - popup->get_size().width;
@@ -129,8 +129,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
popup_ofs = menu->get_width();
}
- Ref<Texture2D> increment = get_theme_icon("increment");
- Ref<Texture2D> decrement = get_theme_icon("decrement");
+ Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
if (is_layout_rtl()) {
if (pos.x < popup_ofs + decrement->get_width()) {
if (last_tab_cache < tabs.size() - 1) {
@@ -203,7 +203,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
return;
}
- Ref<Texture2D> menu = get_theme_icon("menu");
+ Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
if (popup) {
if (is_layout_rtl()) {
if (pos.x <= menu->get_width()) {
@@ -248,8 +248,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
popup_ofs = menu->get_width();
}
- Ref<Texture2D> increment = get_theme_icon("increment");
- Ref<Texture2D> decrement = get_theme_icon("decrement");
+ Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
if (is_layout_rtl()) {
if (pos.x <= popup_ofs + decrement->get_width()) {
@@ -289,10 +289,10 @@ void TabContainer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_RESIZED: {
Vector<Control *> tabs = _get_tabs();
- int side_margin = get_theme_constant("side_margin");
- Ref<Texture2D> menu = get_theme_icon("menu");
- Ref<Texture2D> increment = get_theme_icon("increment");
- Ref<Texture2D> decrement = get_theme_icon("decrement");
+ int side_margin = get_theme_constant(SNAME("side_margin"));
+ Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
+ Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
int header_width = get_size().width - side_margin * 2;
// Find the width of the header area.
@@ -332,26 +332,26 @@ void TabContainer::_notification(int p_what) {
bool rtl = is_layout_rtl();
// Draw only the tab area if the header is hidden.
- Ref<StyleBox> panel = get_theme_stylebox("panel");
+ Ref<StyleBox> panel = get_theme_stylebox(SNAME("panel"));
if (!tabs_visible) {
panel->draw(canvas, Rect2(0, 0, size.width, size.height));
return;
}
Vector<Control *> tabs = _get_tabs();
- Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
- Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
- Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
- Ref<Texture2D> increment = get_theme_icon("increment");
- Ref<Texture2D> increment_hl = get_theme_icon("increment_highlight");
- Ref<Texture2D> decrement = get_theme_icon("decrement");
- Ref<Texture2D> decrement_hl = get_theme_icon("decrement_highlight");
- Ref<Texture2D> menu = get_theme_icon("menu");
- Ref<Texture2D> menu_hl = get_theme_icon("menu_highlight");
- Color font_selected_color = get_theme_color("font_selected_color");
- Color font_unselected_color = get_theme_color("font_unselected_color");
- Color font_disabled_color = get_theme_color("font_disabled_color");
- int side_margin = get_theme_constant("side_margin");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
+ Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
+ Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
+ Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> increment_hl = get_theme_icon(SNAME("increment_highlight"));
+ Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
+ Ref<Texture2D> decrement_hl = get_theme_icon(SNAME("decrement_highlight"));
+ Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
+ Ref<Texture2D> menu_hl = get_theme_icon(SNAME("menu_highlight"));
+ Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
+ Color font_unselected_color = get_theme_color(SNAME("font_unselected_color"));
+ Color font_disabled_color = get_theme_color(SNAME("font_disabled_color"));
+ int side_margin = get_theme_constant(SNAME("side_margin"));
// Find out start and width of the header area.
int header_x = side_margin;
@@ -529,7 +529,7 @@ void TabContainer::_notification(int p_what) {
text_buf.write[i]->clear();
}
_theme_changing = true;
- call_deferred("_on_theme_changed"); // Wait until all changed theme.
+ call_deferred(SNAME("_on_theme_changed")); // Wait until all changed theme.
} break;
}
}
@@ -537,10 +537,10 @@ void TabContainer::_notification(int p_what) {
void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x) {
Vector<Control *> tabs = _get_tabs();
RID canvas = get_canvas_item();
- Ref<Font> font = get_theme_font("font");
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
- int icon_text_distance = get_theme_constant("icon_separation");
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
+ int icon_text_distance = get_theme_constant(SNAME("icon_separation"));
int tab_width = _get_tab_width(p_index);
int header_height = _get_top_margin();
@@ -580,8 +580,8 @@ void TabContainer::_refresh_texts() {
text_buf.clear();
Vector<Control *> tabs = _get_tabs();
bool rtl = is_layout_rtl();
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
for (int i = 0; i < tabs.size(); i++) {
Control *control = Object::cast_to<Control>(tabs[i]);
String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
@@ -609,7 +609,7 @@ void TabContainer::_on_theme_changed() {
}
void TabContainer::_repaint() {
- Ref<StyleBox> sb = get_theme_stylebox("panel");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"));
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
@@ -646,8 +646,8 @@ int TabContainer::_get_tab_width(int p_index) const {
}
// Get the width of the text displayed on the tab.
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
int width = font->get_string_size(text, font_size).width;
@@ -657,15 +657,15 @@ int TabContainer::_get_tab_width(int p_index) const {
if (icon.is_valid()) {
width += icon->get_width();
if (text != "") {
- width += get_theme_constant("icon_separation");
+ width += get_theme_constant(SNAME("icon_separation"));
}
}
}
// Respect a minimum size.
- Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
- Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
- Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
+ Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
+ Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
if (get_tab_disabled(p_index)) {
width += tab_disabled->get_minimum_size().width;
} else if (p_index == current) {
@@ -715,7 +715,7 @@ void TabContainer::add_child_notify(Node *p_child) {
c->hide();
} else {
c->show();
- //call_deferred("set_current_tab",0);
+ //call_deferred(SNAME("set_current_tab"),0);
first = true;
current = 0;
previous = 0;
@@ -724,7 +724,7 @@ void TabContainer::add_child_notify(Node *p_child) {
if (tabs_visible) {
c->set_offset(SIDE_TOP, _get_top_margin());
}
- Ref<StyleBox> sb = get_theme_stylebox("panel");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"));
c->set_offset(Side(SIDE_TOP), c->get_offset(Side(SIDE_TOP)) + sb->get_margin(Side(SIDE_TOP)));
c->set_offset(Side(SIDE_LEFT), c->get_offset(Side(SIDE_LEFT)) + sb->get_margin(Side(SIDE_LEFT)));
c->set_offset(Side(SIDE_RIGHT), c->get_offset(Side(SIDE_RIGHT)) - sb->get_margin(Side(SIDE_RIGHT)));
@@ -732,13 +732,13 @@ void TabContainer::add_child_notify(Node *p_child) {
update();
p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
if (first && is_inside_tree()) {
- emit_signal("tab_changed", current);
+ emit_signal(SNAME("tab_changed"), current);
}
}
void TabContainer::move_child_notify(Node *p_child) {
Container::move_child_notify(p_child);
- call_deferred("_update_current_tab");
+ call_deferred(SNAME("_update_current_tab"));
_refresh_texts();
update();
}
@@ -756,11 +756,11 @@ void TabContainer::set_current_tab(int p_current) {
_repaint();
if (pending_previous == current) {
- emit_signal("tab_selected", current);
+ emit_signal(SNAME("tab_selected"), current);
} else {
previous = pending_previous;
- emit_signal("tab_selected", current);
- emit_signal("tab_changed", current);
+ emit_signal(SNAME("tab_selected"), current);
+ emit_signal(SNAME("tab_changed"), current);
}
update();
@@ -799,7 +799,7 @@ void TabContainer::remove_child_notify(Node *p_child) {
return;
}
- call_deferred("_update_current_tab");
+ call_deferred(SNAME("_update_current_tab"));
p_child->disconnect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
@@ -913,7 +913,7 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
}
move_child(moving_tabc, hover_now);
set_current_tab(hover_now);
- emit_signal("tab_changed", hover_now);
+ emit_signal(SNAME("tab_changed"), hover_now);
}
}
}
@@ -944,12 +944,12 @@ int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
Popup *popup = get_popup();
if (popup) {
- Ref<Texture2D> menu = get_theme_icon("menu");
+ Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
button_ofs += menu->get_width();
}
if (buttons_visible_cache) {
- Ref<Texture2D> increment = get_theme_icon("increment");
- Ref<Texture2D> decrement = get_theme_icon("decrement");
+ Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
button_ofs += increment->get_width() + decrement->get_width();
}
if (px > size.width - button_ofs) {
@@ -1136,17 +1136,17 @@ Size2 TabContainer::get_minimum_size() const {
ms.y = MAX(ms.y, cms.y);
}
- Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
- Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
- Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
- Ref<Font> font = get_theme_font("font");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
+ Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
+ Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
if (tabs_visible) {
ms.y += MAX(MAX(tab_unselected->get_minimum_size().y, tab_selected->get_minimum_size().y), tab_disabled->get_minimum_size().y);
ms.y += _get_top_margin();
}
- Ref<StyleBox> sb = get_theme_stylebox("panel");
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"));
ms += sb->get_minimum_size();
return ms;
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 6f1cff9ec8..9e8fe27ffb 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -38,9 +38,9 @@
#include "scene/gui/texture_rect.h"
Size2 Tabs::get_minimum_size() const {
- Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
- Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
- Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
+ Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
+ Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
int y_margin = MAX(MAX(tab_unselected->get_minimum_size().height, tab_selected->get_minimum_size().height), tab_disabled->get_minimum_size().height);
@@ -51,7 +51,7 @@ Size2 Tabs::get_minimum_size() const {
if (tex.is_valid()) {
ms.height = MAX(ms.height, tex->get_size().height);
if (tabs[i].text != "") {
- ms.width += get_theme_constant("hseparation");
+ ms.width += get_theme_constant(SNAME("hseparation"));
}
}
@@ -69,15 +69,15 @@ Size2 Tabs::get_minimum_size() const {
if (tabs[i].right_button.is_valid()) {
Ref<Texture2D> rb = tabs[i].right_button;
Size2 bms = rb->get_size();
- bms.width += get_theme_constant("hseparation");
+ bms.width += get_theme_constant(SNAME("hseparation"));
ms.width += bms.width;
ms.height = MAX(bms.height + tab_unselected->get_minimum_size().height, ms.height);
}
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
- Ref<Texture2D> cb = get_theme_icon("close");
+ Ref<Texture2D> cb = get_theme_icon(SNAME("close"));
Size2 bms = cb->get_size();
- bms.width += get_theme_constant("hseparation");
+ bms.width += get_theme_constant(SNAME("hseparation"));
ms.width += bms.width;
ms.height = MAX(bms.height + tab_unselected->get_minimum_size().height, ms.height);
}
@@ -100,8 +100,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
highlight_arrow = -1;
if (buttons_visible) {
- Ref<Texture2D> incr = get_theme_icon("increment");
- Ref<Texture2D> decr = get_theme_icon("decrement");
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
if (is_layout_rtl()) {
if (pos.x < decr->get_width()) {
@@ -148,7 +148,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
if (rb_hover != -1) {
//pressed
- emit_signal("right_button_pressed", rb_hover);
+ emit_signal(SNAME("right_button_pressed"), rb_hover);
}
rb_pressing = false;
@@ -158,7 +158,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
if (cb_hover != -1) {
//pressed
- emit_signal("tab_closed", cb_hover);
+ emit_signal(SNAME("tab_closed"), cb_hover);
}
cb_pressing = false;
@@ -170,8 +170,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
Point2 pos(mb->get_position().x, mb->get_position().y);
if (buttons_visible) {
- Ref<Texture2D> incr = get_theme_icon("increment");
- Ref<Texture2D> decr = get_theme_icon("decrement");
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
if (is_layout_rtl()) {
if (pos.x < decr->get_width()) {
@@ -229,15 +229,15 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
if (found != -1) {
set_current_tab(found);
- emit_signal("tab_clicked", found);
+ emit_signal(SNAME("tab_clicked"), found);
}
}
}
}
void Tabs::_shape(int p_tab) {
- Ref<Font> font = get_theme_font("font");
- int font_size = get_theme_font_size("font_size");
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
tabs.write[p_tab].xl_text = tr(tabs[p_tab].text);
tabs.write[p_tab].text_buf->clear();
@@ -274,15 +274,15 @@ void Tabs::_notification(int p_what) {
_update_cache();
RID ci = get_canvas_item();
- Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
- Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
- Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
- Color font_selected_color = get_theme_color("font_selected_color");
- Color font_unselected_color = get_theme_color("font_unselected_color");
- Color font_disabled_color = get_theme_color("font_disabled_color");
- Ref<Texture2D> close = get_theme_icon("close");
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
+ Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
+ Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
+ Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
+ Color font_unselected_color = get_theme_color(SNAME("font_unselected_color"));
+ Color font_disabled_color = get_theme_color(SNAME("font_disabled_color"));
+ Ref<Texture2D> close = get_theme_icon(SNAME("close"));
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
Vector2 size = get_size();
bool rtl = is_layout_rtl();
@@ -306,10 +306,10 @@ void Tabs::_notification(int p_what) {
w = 0;
}
- Ref<Texture2D> incr = get_theme_icon("increment");
- Ref<Texture2D> decr = get_theme_icon("decrement");
- Ref<Texture2D> incr_hl = get_theme_icon("increment_highlight");
- Ref<Texture2D> decr_hl = get_theme_icon("decrement_highlight");
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
+ Ref<Texture2D> incr_hl = get_theme_icon(SNAME("increment_highlight"));
+ Ref<Texture2D> decr_hl = get_theme_icon(SNAME("decrement_highlight"));
int limit = get_size().width;
int limit_minus_buttons = get_size().width - incr->get_width() - decr->get_width();
@@ -363,7 +363,7 @@ void Tabs::_notification(int p_what) {
icon->draw(ci, Point2i(w, sb->get_margin(SIDE_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
}
if (tabs[i].text != "") {
- w += icon->get_width() + get_theme_constant("hseparation");
+ w += icon->get_width() + get_theme_constant(SNAME("hseparation"));
}
}
@@ -384,10 +384,10 @@ void Tabs::_notification(int p_what) {
w += tabs[i].size_text;
if (tabs[i].right_button.is_valid()) {
- Ref<StyleBox> style = get_theme_stylebox("button");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("button"));
Ref<Texture2D> rb = tabs[i].right_button;
- w += get_theme_constant("hseparation");
+ w += get_theme_constant(SNAME("hseparation"));
Rect2 rb_rect;
rb_rect.size = style->get_minimum_size() + rb->get_size();
@@ -400,7 +400,7 @@ void Tabs::_notification(int p_what) {
if (rb_hover == i) {
if (rb_pressing) {
- get_theme_stylebox("button_pressed")->draw(ci, rb_rect);
+ get_theme_stylebox(SNAME("button_pressed"))->draw(ci, rb_rect);
} else {
style->draw(ci, rb_rect);
}
@@ -416,10 +416,10 @@ void Tabs::_notification(int p_what) {
}
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
- Ref<StyleBox> style = get_theme_stylebox("button");
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("button"));
Ref<Texture2D> cb = close;
- w += get_theme_constant("hseparation");
+ w += get_theme_constant(SNAME("hseparation"));
Rect2 cb_rect;
cb_rect.size = style->get_minimum_size() + cb->get_size();
@@ -432,7 +432,7 @@ void Tabs::_notification(int p_what) {
if (!tabs[i].disabled && cb_hover == i) {
if (cb_pressing) {
- get_theme_stylebox("button_pressed")->draw(ci, cb_rect);
+ get_theme_stylebox(SNAME("button_pressed"))->draw(ci, cb_rect);
} else {
style->draw(ci, cb_rect);
}
@@ -503,7 +503,7 @@ void Tabs::set_current_tab(int p_current) {
_update_cache();
update();
- emit_signal("tab_changed", p_current);
+ emit_signal(SNAME("tab_changed"), p_current);
}
int Tabs::get_current_tab() const {
@@ -659,7 +659,7 @@ void Tabs::_update_hover() {
}
if (hover != hover_now) {
hover = hover_now;
- emit_signal("tab_hovered", hover);
+ emit_signal(SNAME("tab_hovered"), hover);
}
if (hover_buttons == -1) { // no hover
@@ -669,11 +669,11 @@ void Tabs::_update_hover() {
}
void Tabs::_update_cache() {
- Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
- Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
- Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
- Ref<Texture2D> incr = get_theme_icon("increment");
- Ref<Texture2D> decr = get_theme_icon("decrement");
+ Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
+ Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
+ Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
int limit_minus_buttons = get_size().width - incr->get_width() - decr->get_width();
int w = 0;
@@ -712,12 +712,12 @@ void Tabs::_update_cache() {
slen = m_width - (sb->get_margin(SIDE_LEFT) + sb->get_margin(SIDE_RIGHT));
if (tabs[i].icon.is_valid()) {
slen -= tabs[i].icon->get_width();
- slen -= get_theme_constant("hseparation");
+ slen -= get_theme_constant(SNAME("hseparation"));
}
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
- Ref<Texture2D> cb = get_theme_icon("close");
+ Ref<Texture2D> cb = get_theme_icon(SNAME("close"));
slen -= cb->get_width();
- slen -= get_theme_constant("hseparation");
+ slen -= get_theme_constant(SNAME("hseparation"));
}
slen = MAX(slen, 1);
lsize = m_width;
@@ -745,7 +745,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) {
t.xl_text = tr(p_str);
t.text_buf.instantiate();
t.text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
- t.text_buf->add_string(t.xl_text, get_theme_font("font"), get_theme_font_size("font_size"), Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
+ t.text_buf->add_string(t.xl_text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
t.icon = p_icon;
t.disabled = false;
t.ofs_cache = 0;
@@ -753,7 +753,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) {
tabs.push_back(t);
_update_cache();
- call_deferred("_update_hover");
+ call_deferred(SNAME("_update_hover"));
update();
minimum_size_changed();
}
@@ -762,7 +762,7 @@ void Tabs::clear_tabs() {
tabs.clear();
current = 0;
previous = 0;
- call_deferred("_update_hover");
+ call_deferred(SNAME("_update_hover"));
update();
}
@@ -773,7 +773,7 @@ void Tabs::remove_tab(int p_idx) {
current--;
}
_update_cache();
- call_deferred("_update_hover");
+ call_deferred(SNAME("_update_hover"));
update();
minimum_size_changed();
@@ -870,7 +870,7 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
hover_now = get_tab_count() - 1;
}
move_tab(tab_from_id, hover_now);
- emit_signal("reposition_active_tab_request", hover_now);
+ emit_signal(SNAME("reposition_active_tab_request"), hover_now);
set_current_tab(hover_now);
} else if (get_tabs_rearrange_group() != -1) {
// drag and drop between Tabs
@@ -887,7 +887,7 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
tabs.insert(hover_now, moving_tab);
from_tabs->remove_tab(tab_from_id);
set_current_tab(hover_now);
- emit_signal("tab_changed", hover_now);
+ emit_signal(SNAME("tab_changed"), hover_now);
_update_cache();
}
}
@@ -949,9 +949,9 @@ void Tabs::move_tab(int from, int to) {
int Tabs::get_tab_width(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, tabs.size(), 0);
- Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
- Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
- Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
+ Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
+ Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
int x = 0;
@@ -959,7 +959,7 @@ int Tabs::get_tab_width(int p_idx) const {
if (tex.is_valid()) {
x += tex->get_width();
if (tabs[p_idx].text != "") {
- x += get_theme_constant("hseparation");
+ x += get_theme_constant(SNAME("hseparation"));
}
}
@@ -976,13 +976,13 @@ int Tabs::get_tab_width(int p_idx) const {
if (tabs[p_idx].right_button.is_valid()) {
Ref<Texture2D> rb = tabs[p_idx].right_button;
x += rb->get_width();
- x += get_theme_constant("hseparation");
+ x += get_theme_constant(SNAME("hseparation"));
}
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx == current)) {
- Ref<Texture2D> cb = get_theme_icon("close");
+ Ref<Texture2D> cb = get_theme_icon(SNAME("close"));
x += cb->get_width();
- x += get_theme_constant("hseparation");
+ x += get_theme_constant(SNAME("hseparation"));
}
return x;
@@ -993,8 +993,8 @@ void Tabs::_ensure_no_over_offset() {
return;
}
- Ref<Texture2D> incr = get_theme_icon("increment");
- Ref<Texture2D> decr = get_theme_icon("decrement");
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
int limit = get_size().width;
int limit_minus_buttons = get_size().width - incr->get_width() - decr->get_width();
@@ -1034,8 +1034,8 @@ void Tabs::ensure_tab_visible(int p_idx) {
}
int prev_offset = offset;
- Ref<Texture2D> incr = get_theme_icon("increment");
- Ref<Texture2D> decr = get_theme_icon("decrement");
+ Ref<Texture2D> incr = get_theme_icon(SNAME("increment"));
+ Ref<Texture2D> decr = get_theme_icon(SNAME("decrement"));
int limit = get_size().width;
int limit_minus_buttons = get_size().width - incr->get_width() - decr->get_width();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 6f96b530a6..be3edccc99 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -542,8 +542,8 @@ void TextEdit::_notification(int p_what) {
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
- call_deferred("_update_scrollbars");
- call_deferred("_update_wrap_at");
+ call_deferred(SNAME("_update_scrollbars"));
+ call_deferred(SNAME("_update_wrap_at"));
}
} break;
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
@@ -599,7 +599,7 @@ void TextEdit::_notification(int p_what) {
Size2 size = get_size();
bool rtl = is_layout_rtl();
- if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
+ if ((!has_focus() && !(menu && menu->has_focus())) || !window_has_focus) {
draw_caret = false;
}
@@ -1119,7 +1119,7 @@ void TextEdit::_notification(int p_what) {
}
tl->draw(ci, Point2(gutter_offset + ofs_x, yofs), get_line_gutter_item_color(line, g));
} break;
- case GUTTER_TPYE_ICON: {
+ case GUTTER_TYPE_ICON: {
const Ref<Texture2D> icon = get_line_gutter_icon(line, g);
if (icon.is_null()) {
break;
@@ -1147,7 +1147,7 @@ void TextEdit::_notification(int p_what) {
icon->draw_rect(ci, gutter_rect, false, get_line_gutter_item_color(line, g));
} break;
- case GUTTER_TPYE_CUSTOM: {
+ case GUTTER_TYPE_CUSTOM: {
if (gutter.custom_draw_obj.is_valid()) {
Object *cdo = ObjectDB::get_instance(gutter.custom_draw_obj);
if (cdo) {
@@ -2361,7 +2361,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (mpos.x > left_margin && mpos.x <= (left_margin + gutters[i].width) - 3) {
- emit_signal("gutter_clicked", row, i);
+ emit_signal(SNAME("gutter_clicked"), row, i);
return;
}
@@ -2470,9 +2470,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+ _ensure_menu();
menu->set_position(get_screen_transform().xform(mpos));
menu->set_size(Vector2(1, 1));
- _generate_context_menu();
menu->popup();
grab_focus();
}
@@ -2482,7 +2482,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int row, col;
_get_mouse_pos(Point2i(mpos.x, mpos.y), row, col);
- emit_signal("symbol_lookup", highlighted_word, row, col);
+ emit_signal(SNAME("symbol_lookup"), highlighted_word, row, col);
return;
}
@@ -2524,7 +2524,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (!dragging_minimap && !dragging_selection && mm->is_command_pressed() && mm->get_button_mask() == 0) {
String new_word = get_word_at_pos(mpos);
if (new_word != highlighted_word) {
- emit_signal("symbol_validate", new_word);
+ emit_signal(SNAME("symbol_validate"), new_word);
}
} else {
if (highlighted_word != String()) {
@@ -2575,7 +2575,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (select_identifiers_enabled) {
if (k->is_pressed() && !dragging_minimap && !dragging_selection) {
Point2 mp = _get_local_mouse_pos();
- emit_signal("symbol_validate", get_word_at_pos(mp));
+ emit_signal(SNAME("symbol_validate"), get_word_at_pos(mp));
} else {
set_highlighted_word(String());
}
@@ -2709,9 +2709,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// MISC.
if (k->is_action("ui_menu", true)) {
if (context_menu_enabled) {
+ _ensure_menu();
menu->set_position(get_screen_transform().xform(_get_cursor_pixel_pos()));
menu->set_size(Vector2(1, 1));
- _generate_context_menu();
menu->popup();
menu->grab_focus();
}
@@ -2990,7 +2990,7 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
}
text_changed_dirty = true;
}
- emit_signal("lines_edited_from", p_line, r_end_line);
+ emit_signal(SNAME("lines_edited_from"), p_line, r_end_line);
}
String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const {
@@ -3041,7 +3041,7 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
}
text_changed_dirty = true;
}
- emit_signal("lines_edited_from", p_to_line, p_from_line);
+ emit_signal(SNAME("lines_edited_from"), p_to_line, p_from_line);
}
void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r_end_line, int *r_end_char) {
@@ -3212,35 +3212,6 @@ int TextEdit::_get_menu_action_accelerator(const String &p_action) {
}
}
-void TextEdit::_generate_context_menu() {
- // Reorganize context menu.
- menu->clear();
- if (!readonly) {
- menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0);
- }
- menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0);
- if (!readonly) {
- menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0);
- }
- menu->add_separator();
- if (is_selecting_enabled()) {
- menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0);
- }
- if (!readonly) {
- menu->add_item(RTR("Clear"), MENU_CLEAR);
- menu->add_separator();
- menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0);
- menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0);
- }
- menu->add_separator();
- menu->add_submenu_item(RTR("Text writing direction"), "DirMenu");
- menu->add_separator();
- menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC);
- if (!readonly) {
- menu->add_submenu_item(RTR("Insert control character"), "CTLMenu");
- }
-}
-
int TextEdit::get_visible_rows() const {
return _get_control_height() / get_row_height();
}
@@ -3858,10 +3829,12 @@ void TextEdit::set_text_direction(Control::TextDirection p_text_direction) {
text.set_direction_and_language(dir, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
text.invalidate_all();
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
+ if (menu_dir) {
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
+ }
update();
}
}
@@ -3917,7 +3890,9 @@ String TextEdit::get_language() const {
void TextEdit::set_draw_control_chars(bool p_draw_control_chars) {
if (draw_control_chars != p_draw_control_chars) {
draw_control_chars = p_draw_control_chars;
- menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
+ if (menu && menu->get_item_index(MENU_DISPLAY_UCC) >= 0) {
+ menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
+ }
text.set_draw_control_chars(draw_control_chars);
text.invalidate_all();
update();
@@ -3988,7 +3963,6 @@ void TextEdit::set_readonly(bool p_readonly) {
}
readonly = p_readonly;
- _generate_context_menu();
update();
}
@@ -4027,35 +4001,35 @@ void TextEdit::_toggle_draw_caret() {
}
void TextEdit::_update_caches() {
- cache.style_normal = get_theme_stylebox("normal");
- cache.style_focus = get_theme_stylebox("focus");
- cache.style_readonly = get_theme_stylebox("read_only");
- cache.font = get_theme_font("font");
- cache.font_size = get_theme_font_size("font_size");
- cache.outline_color = get_theme_color("font_outline_color");
- cache.outline_size = get_theme_constant("outline_size");
- cache.caret_color = get_theme_color("caret_color");
- cache.caret_background_color = get_theme_color("caret_background_color");
- cache.font_color = get_theme_color("font_color");
- cache.font_selected_color = get_theme_color("font_selected_color");
- cache.font_readonly_color = get_theme_color("font_readonly_color");
- cache.selection_color = get_theme_color("selection_color");
- cache.current_line_color = get_theme_color("current_line_color");
- cache.line_length_guideline_color = get_theme_color("line_length_guideline_color");
- cache.code_folding_color = get_theme_color("code_folding_color", "CodeEdit");
- cache.brace_mismatch_color = get_theme_color("brace_mismatch_color");
- cache.word_highlighted_color = get_theme_color("word_highlighted_color");
- cache.search_result_color = get_theme_color("search_result_color");
- cache.search_result_border_color = get_theme_color("search_result_border_color");
- cache.background_color = get_theme_color("background_color");
+ cache.style_normal = get_theme_stylebox(SNAME("normal"));
+ cache.style_focus = get_theme_stylebox(SNAME("focus"));
+ cache.style_readonly = get_theme_stylebox(SNAME("read_only"));
+ cache.font = get_theme_font(SNAME("font"));
+ cache.font_size = get_theme_font_size(SNAME("font_size"));
+ cache.outline_color = get_theme_color(SNAME("font_outline_color"));
+ cache.outline_size = get_theme_constant(SNAME("outline_size"));
+ cache.caret_color = get_theme_color(SNAME("caret_color"));
+ cache.caret_background_color = get_theme_color(SNAME("caret_background_color"));
+ cache.font_color = get_theme_color(SNAME("font_color"));
+ cache.font_selected_color = get_theme_color(SNAME("font_selected_color"));
+ cache.font_readonly_color = get_theme_color(SNAME("font_readonly_color"));
+ cache.selection_color = get_theme_color(SNAME("selection_color"));
+ cache.current_line_color = get_theme_color(SNAME("current_line_color"));
+ cache.line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color"));
+ cache.code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit"));
+ cache.brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color"));
+ cache.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color"));
+ cache.search_result_color = get_theme_color(SNAME("search_result_color"));
+ cache.search_result_border_color = get_theme_color(SNAME("search_result_border_color"));
+ cache.background_color = get_theme_color(SNAME("background_color"));
#ifdef TOOLS_ENABLED
- cache.line_spacing = get_theme_constant("line_spacing") * EDSCALE;
+ cache.line_spacing = get_theme_constant(SNAME("line_spacing")) * EDSCALE;
#else
- cache.line_spacing = get_theme_constant("line_spacing");
+ cache.line_spacing = get_theme_constant(SNAME("line_spacing"));
#endif
- cache.tab_icon = get_theme_icon("tab");
- cache.space_icon = get_theme_icon("space");
- cache.folded_eol_icon = get_theme_icon("folded_eol_icon", "CodeEdit");
+ cache.tab_icon = get_theme_icon(SNAME("tab"));
+ cache.space_icon = get_theme_icon(SNAME("space"));
+ cache.folded_eol_icon = get_theme_icon(SNAME("folded_eol_icon"), SNAME("CodeEdit"));
TextServer::Direction dir;
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
@@ -4112,7 +4086,7 @@ void TextEdit::add_gutter(int p_at) {
for (int i = 0; i < text.size() + 1; i++) {
text.add_gutter(p_at);
}
- emit_signal("gutter_added");
+ emit_signal(SNAME("gutter_added"));
update();
}
@@ -4124,7 +4098,7 @@ void TextEdit::remove_gutter(int p_gutter) {
for (int i = 0; i < text.size() + 1; i++) {
text.remove_gutter(p_gutter);
}
- emit_signal("gutter_removed");
+ emit_signal(SNAME("gutter_removed"));
update();
}
@@ -4748,12 +4722,12 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
}
void TextEdit::_cursor_changed_emit() {
- emit_signal("cursor_changed");
+ emit_signal(SNAME("cursor_changed"));
cursor_changed_dirty = false;
}
void TextEdit::_text_changed_emit() {
- emit_signal("text_changed");
+ emit_signal(SNAME("text_changed"));
text_changed_dirty = false;
}
@@ -5564,8 +5538,6 @@ bool TextEdit::is_context_menu_enabled() {
void TextEdit::set_shortcut_keys_enabled(bool p_enabled) {
shortcut_keys_enabled = p_enabled;
-
- _generate_context_menu();
}
void TextEdit::set_virtual_keyboard_enabled(bool p_enable) {
@@ -5578,8 +5550,6 @@ void TextEdit::set_selecting_enabled(bool p_enabled) {
if (!selecting_enabled) {
deselect();
}
-
- _generate_context_menu();
}
bool TextEdit::is_selecting_enabled() const {
@@ -5594,7 +5564,12 @@ bool TextEdit::is_virtual_keyboard_enabled() const {
return virtual_keyboard_enabled;
}
+bool TextEdit::is_menu_visible() const {
+ return menu && menu->is_visible();
+}
+
PopupMenu *TextEdit::get_menu() const {
+ const_cast<TextEdit *>(this)->_ensure_menu();
return menu;
}
@@ -5782,8 +5757,8 @@ void TextEdit::_bind_methods() {
/* Gutters. */
BIND_ENUM_CONSTANT(GUTTER_TYPE_STRING);
- BIND_ENUM_CONSTANT(GUTTER_TPYE_ICON);
- BIND_ENUM_CONSTANT(GUTTER_TPYE_CUSTOM);
+ BIND_ENUM_CONSTANT(GUTTER_TYPE_ICON);
+ BIND_ENUM_CONSTANT(GUTTER_TYPE_CUSTOM);
ClassDB::bind_method(D_METHOD("add_gutter", "at"), &TextEdit::add_gutter, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("remove_gutter", "gutter"), &TextEdit::remove_gutter);
@@ -5833,6 +5808,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("menu_option", "option"), &TextEdit::menu_option);
ClassDB::bind_method(D_METHOD("get_menu"), &TextEdit::get_menu);
+ ClassDB::bind_method(D_METHOD("is_menu_visible"), &TextEdit::is_menu_visible);
ClassDB::bind_method(D_METHOD("draw_minimap", "draw"), &TextEdit::set_draw_minimap);
ClassDB::bind_method(D_METHOD("is_drawing_minimap"), &TextEdit::is_drawing_minimap);
@@ -5921,6 +5897,79 @@ void TextEdit::_bind_methods() {
ProjectSettings::get_singleton()->set_custom_property_info("gui/common/text_edit_undo_stack_max_size", PropertyInfo(Variant::INT, "gui/common/text_edit_undo_stack_max_size", PROPERTY_HINT_RANGE, "0,10000,1,or_greater")); // No negative numbers.
}
+void TextEdit::_ensure_menu() {
+ if (!menu) {
+ menu = memnew(PopupMenu);
+ add_child(menu);
+
+ menu_dir = memnew(PopupMenu);
+ menu_dir->set_name("DirMenu");
+ menu_dir->add_radio_check_item(RTR("Same as layout direction"), MENU_DIR_INHERITED);
+ menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO);
+ menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR);
+ menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL);
+ menu->add_child(menu_dir);
+
+ menu_ctl = memnew(PopupMenu);
+ menu_ctl->set_name("CTLMenu");
+ menu_ctl->add_item(RTR("Left-to-right mark (LRM)"), MENU_INSERT_LRM);
+ menu_ctl->add_item(RTR("Right-to-left mark (RLM)"), MENU_INSERT_RLM);
+ menu_ctl->add_item(RTR("Start of left-to-right embedding (LRE)"), MENU_INSERT_LRE);
+ menu_ctl->add_item(RTR("Start of right-to-left embedding (RLE)"), MENU_INSERT_RLE);
+ menu_ctl->add_item(RTR("Start of left-to-right override (LRO)"), MENU_INSERT_LRO);
+ menu_ctl->add_item(RTR("Start of right-to-left override (RLO)"), MENU_INSERT_RLO);
+ menu_ctl->add_item(RTR("Pop direction formatting (PDF)"), MENU_INSERT_PDF);
+ menu_ctl->add_separator();
+ menu_ctl->add_item(RTR("Arabic letter mark (ALM)"), MENU_INSERT_ALM);
+ menu_ctl->add_item(RTR("Left-to-right isolate (LRI)"), MENU_INSERT_LRI);
+ menu_ctl->add_item(RTR("Right-to-left isolate (RLI)"), MENU_INSERT_RLI);
+ menu_ctl->add_item(RTR("First strong isolate (FSI)"), MENU_INSERT_FSI);
+ menu_ctl->add_item(RTR("Pop direction isolate (PDI)"), MENU_INSERT_PDI);
+ menu_ctl->add_separator();
+ menu_ctl->add_item(RTR("Zero width joiner (ZWJ)"), MENU_INSERT_ZWJ);
+ menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
+ menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ);
+ menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY);
+ menu->add_child(menu_ctl);
+
+ menu->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
+ menu_dir->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
+ menu_ctl->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
+ }
+
+ // Reorganize context menu.
+ menu->clear();
+ if (!readonly) {
+ menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0);
+ }
+ menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0);
+ if (!readonly) {
+ menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0);
+ }
+ menu->add_separator();
+ if (is_selecting_enabled()) {
+ menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0);
+ }
+ if (!readonly) {
+ menu->add_item(RTR("Clear"), MENU_CLEAR);
+ menu->add_separator();
+ menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0);
+ menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0);
+ }
+ menu->add_separator();
+ menu->add_submenu_item(RTR("Text writing direction"), "DirMenu");
+ menu->add_separator();
+ menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC);
+ menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
+ if (!readonly) {
+ menu->add_submenu_item(RTR("Insert control character"), "CTLMenu");
+ }
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
+ menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
+}
+
TextEdit::TextEdit() {
clear();
set_focus_mode(FOCUS_ALL);
@@ -5960,44 +6009,7 @@ TextEdit::TextEdit() {
undo_stack_max_size = GLOBAL_GET("gui/common/text_edit_undo_stack_max_size");
- menu = memnew(PopupMenu);
- add_child(menu);
-
- menu_dir = memnew(PopupMenu);
- menu_dir->set_name("DirMenu");
- menu_dir->add_radio_check_item(RTR("Same as layout direction"), MENU_DIR_INHERITED);
- menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO);
- menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR);
- menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), true);
- menu->add_child(menu_dir);
-
- menu_ctl = memnew(PopupMenu);
- menu_ctl->set_name("CTLMenu");
- menu_ctl->add_item(RTR("Left-to-right mark (LRM)"), MENU_INSERT_LRM);
- menu_ctl->add_item(RTR("Right-to-left mark (RLM)"), MENU_INSERT_RLM);
- menu_ctl->add_item(RTR("Start of left-to-right embedding (LRE)"), MENU_INSERT_LRE);
- menu_ctl->add_item(RTR("Start of right-to-left embedding (RLE)"), MENU_INSERT_RLE);
- menu_ctl->add_item(RTR("Start of left-to-right override (LRO)"), MENU_INSERT_LRO);
- menu_ctl->add_item(RTR("Start of right-to-left override (RLO)"), MENU_INSERT_RLO);
- menu_ctl->add_item(RTR("Pop direction formatting (PDF)"), MENU_INSERT_PDF);
- menu_ctl->add_separator();
- menu_ctl->add_item(RTR("Arabic letter mark (ALM)"), MENU_INSERT_ALM);
- menu_ctl->add_item(RTR("Left-to-right isolate (LRI)"), MENU_INSERT_LRI);
- menu_ctl->add_item(RTR("Right-to-left isolate (RLI)"), MENU_INSERT_RLI);
- menu_ctl->add_item(RTR("First strong isolate (FSI)"), MENU_INSERT_FSI);
- menu_ctl->add_item(RTR("Pop direction isolate (PDI)"), MENU_INSERT_PDI);
- menu_ctl->add_separator();
- menu_ctl->add_item(RTR("Zero width joiner (ZWJ)"), MENU_INSERT_ZWJ);
- menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
- menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ);
- menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY);
- menu->add_child(menu_ctl);
-
set_readonly(false);
- menu->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
- menu_dir->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
- menu_ctl->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
}
TextEdit::~TextEdit() {
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index dcd5c6d0f8..62d576b48a 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -44,8 +44,8 @@ class TextEdit : public Control {
public:
enum GutterType {
GUTTER_TYPE_STRING,
- GUTTER_TPYE_ICON,
- GUTTER_TPYE_CUSTOM
+ GUTTER_TYPE_ICON,
+ GUTTER_TYPE_CUSTOM
};
enum SelectionMode {
@@ -336,8 +336,6 @@ private:
bool shortcut_keys_enabled = true;
bool virtual_keyboard_enabled = true;
- void _generate_context_menu();
-
int get_visible_rows() const;
int get_total_visible_rows() const;
@@ -410,9 +408,11 @@ private:
Dictionary _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
- PopupMenu *menu;
- PopupMenu *menu_dir;
- PopupMenu *menu_ctl;
+ PopupMenu *menu = nullptr;
+ PopupMenu *menu_dir = nullptr;
+ PopupMenu *menu_ctl = nullptr;
+
+ void _ensure_menu();
void _clear();
@@ -781,6 +781,7 @@ public:
void set_virtual_keyboard_enabled(bool p_enable);
bool is_virtual_keyboard_enabled() const;
+ bool is_menu_visible() const;
PopupMenu *get_menu() const;
String get_text_for_lookup_completion();
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 98de71d81c..09db3205d9 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -99,39 +99,44 @@ void TreeItem::_change_tree(Tree *p_tree) {
c = c->next;
}
- if (tree && tree->root == this) {
- tree->root = nullptr;
- }
+ if (tree) {
+ if (tree->root == this) {
+ tree->root = nullptr;
+ }
- if (tree && tree->popup_edited_item == this) {
- tree->popup_edited_item = nullptr;
- tree->pressing_for_editor = false;
- }
+ if (tree->popup_edited_item == this) {
+ tree->popup_edited_item = nullptr;
+ tree->pressing_for_editor = false;
+ }
- if (tree && tree->cache.hover_item == this) {
- tree->cache.hover_item = nullptr;
- }
+ if (tree->cache.hover_item == this) {
+ tree->cache.hover_item = nullptr;
+ }
- if (tree && tree->selected_item == this) {
- tree->selected_item = nullptr;
- }
+ if (tree->selected_item == this) {
+ tree->selected_item = nullptr;
+ }
- if (tree && tree->drop_mode_over == this) {
- tree->drop_mode_over = nullptr;
- }
+ if (tree->drop_mode_over == this) {
+ tree->drop_mode_over = nullptr;
+ }
- if (tree && tree->single_select_defer == this) {
- tree->single_select_defer = nullptr;
- }
+ if (tree->single_select_defer == this) {
+ tree->single_select_defer = nullptr;
+ }
+
+ if (tree->edited_item == this) {
+ tree->edited_item = nullptr;
+ tree->pressing_for_editor = false;
+ }
- if (tree && tree->edited_item == this) {
- tree->edited_item = nullptr;
- tree->pressing_for_editor = false;
+ tree->update();
}
tree = p_tree;
if (tree) {
+ tree->update();
cells.resize(tree->columns.size());
}
}
@@ -411,7 +416,7 @@ void TreeItem::set_collapsed(bool p_collapsed) {
if (tree->select_mode == Tree::SELECT_MULTI) {
tree->selected_item = this;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
} else {
select(tree->selected_col);
}
@@ -421,7 +426,7 @@ void TreeItem::set_collapsed(bool p_collapsed) {
}
_changed_notify();
- tree->emit_signal("item_collapsed", this);
+ tree->emit_signal(SNAME("item_collapsed"), this);
}
bool TreeItem::is_collapsed() {
@@ -451,6 +456,7 @@ TreeItem *TreeItem::create_child(int p_idx) {
TreeItem *ti = memnew(TreeItem(tree));
if (tree) {
ti->cells.resize(tree->columns.size());
+ tree->update();
}
TreeItem *l_prev = nullptr;
@@ -654,11 +660,7 @@ void TreeItem::move_before(TreeItem *p_item) {
next = p_item;
p_item->prev = this;
- if (old_tree && old_tree != tree) {
- old_tree->update();
- }
-
- if (tree) {
+ if (tree && old_tree == tree) {
tree->update();
}
}
@@ -696,11 +698,7 @@ void TreeItem::move_after(TreeItem *p_item) {
parent->children_cache.append(this);
}
- if (old_tree && old_tree != tree) {
- old_tree->update();
- }
-
- if (tree) {
+ if (tree && old_tree == tree) {
tree->update();
}
}
@@ -1217,62 +1215,62 @@ TreeItem::~TreeItem() {
/**********************************************/
void Tree::update_cache() {
- cache.font = get_theme_font("font");
- cache.font_size = get_theme_font_size("font_size");
- cache.tb_font = get_theme_font("title_button_font");
- cache.tb_font_size = get_theme_font_size("title_button_font_size");
- cache.bg = get_theme_stylebox("bg");
- cache.selected = get_theme_stylebox("selected");
- cache.selected_focus = get_theme_stylebox("selected_focus");
- cache.cursor = get_theme_stylebox("cursor");
- cache.cursor_unfocus = get_theme_stylebox("cursor_unfocused");
- cache.button_pressed = get_theme_stylebox("button_pressed");
-
- cache.checked = get_theme_icon("checked");
- cache.unchecked = get_theme_icon("unchecked");
+ cache.font = get_theme_font(SNAME("font"));
+ cache.font_size = get_theme_font_size(SNAME("font_size"));
+ cache.tb_font = get_theme_font(SNAME("title_button_font"));
+ cache.tb_font_size = get_theme_font_size(SNAME("title_button_font_size"));
+ cache.bg = get_theme_stylebox(SNAME("bg"));
+ cache.selected = get_theme_stylebox(SNAME("selected"));
+ cache.selected_focus = get_theme_stylebox(SNAME("selected_focus"));
+ cache.cursor = get_theme_stylebox(SNAME("cursor"));
+ cache.cursor_unfocus = get_theme_stylebox(SNAME("cursor_unfocused"));
+ cache.button_pressed = get_theme_stylebox(SNAME("button_pressed"));
+
+ cache.checked = get_theme_icon(SNAME("checked"));
+ cache.unchecked = get_theme_icon(SNAME("unchecked"));
if (is_layout_rtl()) {
- cache.arrow_collapsed = get_theme_icon("arrow_collapsed_mirrored");
+ cache.arrow_collapsed = get_theme_icon(SNAME("arrow_collapsed_mirrored"));
} else {
- cache.arrow_collapsed = get_theme_icon("arrow_collapsed");
- }
- cache.arrow = get_theme_icon("arrow");
- cache.select_arrow = get_theme_icon("select_arrow");
- cache.updown = get_theme_icon("updown");
-
- cache.custom_button = get_theme_stylebox("custom_button");
- cache.custom_button_hover = get_theme_stylebox("custom_button_hover");
- cache.custom_button_pressed = get_theme_stylebox("custom_button_pressed");
- cache.custom_button_font_highlight = get_theme_color("custom_button_font_highlight");
-
- cache.font_color = get_theme_color("font_color");
- cache.font_selected_color = get_theme_color("font_selected_color");
- cache.drop_position_color = get_theme_color("drop_position_color");
- cache.hseparation = get_theme_constant("hseparation");
- cache.vseparation = get_theme_constant("vseparation");
- cache.item_margin = get_theme_constant("item_margin");
- cache.button_margin = get_theme_constant("button_margin");
-
- cache.font_outline_color = get_theme_color("font_outline_color");
- cache.font_outline_size = get_theme_constant("outline_size");
-
- cache.draw_guides = get_theme_constant("draw_guides");
- cache.guide_color = get_theme_color("guide_color");
- cache.draw_relationship_lines = get_theme_constant("draw_relationship_lines");
- cache.relationship_line_width = get_theme_constant("relationship_line_width");
- cache.parent_hl_line_width = get_theme_constant("parent_hl_line_width");
- cache.children_hl_line_width = get_theme_constant("children_hl_line_width");
- cache.parent_hl_line_margin = get_theme_constant("parent_hl_line_margin");
- cache.relationship_line_color = get_theme_color("relationship_line_color");
- cache.parent_hl_line_color = get_theme_color("parent_hl_line_color");
- cache.children_hl_line_color = get_theme_color("children_hl_line_color");
-
- cache.scroll_border = get_theme_constant("scroll_border");
- cache.scroll_speed = get_theme_constant("scroll_speed");
-
- cache.title_button = get_theme_stylebox("title_button_normal");
- cache.title_button_pressed = get_theme_stylebox("title_button_pressed");
- cache.title_button_hover = get_theme_stylebox("title_button_hover");
- cache.title_button_color = get_theme_color("title_button_color");
+ cache.arrow_collapsed = get_theme_icon(SNAME("arrow_collapsed"));
+ }
+ cache.arrow = get_theme_icon(SNAME("arrow"));
+ cache.select_arrow = get_theme_icon(SNAME("select_arrow"));
+ cache.updown = get_theme_icon(SNAME("updown"));
+
+ cache.custom_button = get_theme_stylebox(SNAME("custom_button"));
+ cache.custom_button_hover = get_theme_stylebox(SNAME("custom_button_hover"));
+ cache.custom_button_pressed = get_theme_stylebox(SNAME("custom_button_pressed"));
+ cache.custom_button_font_highlight = get_theme_color(SNAME("custom_button_font_highlight"));
+
+ cache.font_color = get_theme_color(SNAME("font_color"));
+ cache.font_selected_color = get_theme_color(SNAME("font_selected_color"));
+ cache.drop_position_color = get_theme_color(SNAME("drop_position_color"));
+ cache.hseparation = get_theme_constant(SNAME("hseparation"));
+ cache.vseparation = get_theme_constant(SNAME("vseparation"));
+ cache.item_margin = get_theme_constant(SNAME("item_margin"));
+ cache.button_margin = get_theme_constant(SNAME("button_margin"));
+
+ cache.font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ cache.font_outline_size = get_theme_constant(SNAME("outline_size"));
+
+ cache.draw_guides = get_theme_constant(SNAME("draw_guides"));
+ cache.guide_color = get_theme_color(SNAME("guide_color"));
+ cache.draw_relationship_lines = get_theme_constant(SNAME("draw_relationship_lines"));
+ cache.relationship_line_width = get_theme_constant(SNAME("relationship_line_width"));
+ cache.parent_hl_line_width = get_theme_constant(SNAME("parent_hl_line_width"));
+ cache.children_hl_line_width = get_theme_constant(SNAME("children_hl_line_width"));
+ cache.parent_hl_line_margin = get_theme_constant(SNAME("parent_hl_line_margin"));
+ cache.relationship_line_color = get_theme_color(SNAME("relationship_line_color"));
+ cache.parent_hl_line_color = get_theme_color(SNAME("parent_hl_line_color"));
+ cache.children_hl_line_color = get_theme_color(SNAME("children_hl_line_color"));
+
+ cache.scroll_border = get_theme_constant(SNAME("scroll_border"));
+ cache.scroll_speed = get_theme_constant(SNAME("scroll_speed"));
+
+ cache.title_button = get_theme_stylebox(SNAME("title_button_normal"));
+ cache.title_button_pressed = get_theme_stylebox(SNAME("title_button_pressed"));
+ cache.title_button_hover = get_theme_stylebox(SNAME("title_button_hover"));
+ cache.title_button_color = get_theme_color(SNAME("title_button_color"));
v_scroll->set_custom_step(cache.font->get_height(cache.font_size));
}
@@ -2077,7 +2075,7 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
selected_item = p_selected;
selected_col = 0;
if (!emitted_row) {
- emit_signal("item_selected");
+ emit_signal(SNAME("item_selected"));
emitted_row = true;
}
/*
@@ -2097,28 +2095,28 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
selected_item = p_selected;
selected_col = i;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
if (select_mode == SELECT_MULTI) {
- emit_signal("multi_selected", p_current, i, true);
+ emit_signal(SNAME("multi_selected"), p_current, i, true);
} else if (select_mode == SELECT_SINGLE) {
- emit_signal("item_selected");
+ emit_signal(SNAME("item_selected"));
}
} else if (select_mode == SELECT_MULTI && (selected_item != p_selected || selected_col != i)) {
selected_item = p_selected;
selected_col = i;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
}
} else {
if (r_in_range && *r_in_range && !p_force_deselect) {
if (!c.selected && c.selectable) {
c.selected = true;
- emit_signal("multi_selected", p_current, i, true);
+ emit_signal(SNAME("multi_selected"), p_current, i, true);
}
} else if (!r_in_range || p_force_deselect) {
if (select_mode == SELECT_MULTI && c.selected) {
- emit_signal("multi_selected", p_current, i, false);
+ emit_signal(SNAME("multi_selected"), p_current, i, false);
}
c.selected = false;
}
@@ -2186,7 +2184,7 @@ void Tree::_range_click_timeout() {
}
if (propagate_mouse_activated) {
- emit_signal("item_activated");
+ emit_signal(SNAME("item_activated"));
propagate_mouse_activated = false;
}
@@ -2299,7 +2297,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
cache.click_column = col;
cache.click_pos = get_global_mouse_position() - get_global_position();
update();
- //emit_signal("button_pressed");
+ //emit_signal(SNAME("button_pressed"));
return -1;
}
@@ -2320,15 +2318,15 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
if (select_mode == SELECT_MULTI && p_mod->is_command_pressed() && c.selectable) {
if (!c.selected || p_button == MOUSE_BUTTON_RIGHT) {
p_item->select(col);
- emit_signal("multi_selected", p_item, col, true);
+ emit_signal(SNAME("multi_selected"), p_item, col, true);
if (p_button == MOUSE_BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", get_local_mouse_position());
+ emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position());
}
//p_item->selected_signal.call(col);
} else {
p_item->deselect(col);
- emit_signal("multi_selected", p_item, col, false);
+ emit_signal(SNAME("multi_selected"), p_item, col, false);
//p_item->deselected_signal.call(col);
}
@@ -2339,7 +2337,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
select_single_item(p_item, root, col, selected_item, &inrange);
if (p_button == MOUSE_BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", get_local_mouse_position());
+ emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position());
}
} else {
int icount = _count_selected_items(root);
@@ -2353,14 +2351,14 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
}
if (p_button == MOUSE_BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", get_local_mouse_position());
+ emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position());
}
}
}
/*
if (!c.selected && select_mode==SELECT_MULTI) {
- emit_signal("multi_selected",p_item,col,true);
+ emit_signal(SNAME("multi_selected"),p_item,col,true);
}
*/
update();
@@ -2474,7 +2472,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h));
if (on_arrow || !p_item->cells[col].custom_button) {
- emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2))));
+ emit_signal(SNAME("custom_popup_edited"), ((bool)(x >= (col_width - item_h / 2))));
}
if (!p_item->cells[col].custom_button || !on_arrow) {
@@ -2526,7 +2524,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
}
}
if (p_item == root && p_button == MOUSE_BUTTON_RIGHT) {
- emit_signal("empty_rmb", get_local_mouse_position());
+ emit_signal(SNAME("empty_rmb"), get_local_mouse_position());
}
}
@@ -2632,7 +2630,7 @@ void Tree::_go_left() {
} else {
if (select_mode == SELECT_MULTI) {
selected_col--;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
} else {
selected_item->select(selected_col - 1);
}
@@ -2653,7 +2651,7 @@ void Tree::_go_right() {
} else {
if (select_mode == SELECT_MULTI) {
selected_col++;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
} else {
selected_item->select(selected_col + 1);
}
@@ -2686,7 +2684,7 @@ void Tree::_go_up() {
return;
}
selected_item = prev;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
update();
} else {
int col = selected_col < 0 ? 0 : selected_col;
@@ -2729,7 +2727,7 @@ void Tree::_go_down() {
}
selected_item = next;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
update();
} else {
int col = selected_col < 0 ? 0 : selected_col;
@@ -2830,7 +2828,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (select_mode == SELECT_MULTI) {
selected_item = next;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
update();
} else {
while (next && !next->cells[selected_col].selectable) {
@@ -2868,7 +2866,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (select_mode == SELECT_MULTI) {
selected_item = prev;
- emit_signal("cell_selected");
+ emit_signal(SNAME("cell_selected"));
update();
} else {
while (prev && !prev->cells[selected_col].selectable) {
@@ -2884,7 +2882,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (selected_item) {
//bring up editor if possible
if (!edit_selected()) {
- emit_signal("item_activated");
+ emit_signal(SNAME("item_activated"));
incr_search.clear();
}
}
@@ -2896,10 +2894,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
if (selected_item->is_selected(selected_col)) {
selected_item->deselect(selected_col);
- emit_signal("multi_selected", selected_item, selected_col, false);
+ emit_signal(SNAME("multi_selected"), selected_item, selected_col, false);
} else if (selected_item->is_selectable(selected_col)) {
selected_item->select(selected_col);
- emit_signal("multi_selected", selected_item, selected_col, true);
+ emit_signal(SNAME("multi_selected"), selected_item, selected_col, true);
}
}
accept_event();
@@ -3083,7 +3081,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
for (int i = 0; i < columns.size(); i++) {
len += get_column_width(i);
if (pos.x < len) {
- emit_signal("column_title_pressed", i);
+ emit_signal(SNAME("column_title_pressed"), i);
break;
}
}
@@ -3110,10 +3108,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
if (rect.has_point(mpos)) {
if (!edit_selected()) {
- emit_signal("item_double_clicked");
+ emit_signal(SNAME("item_double_clicked"));
}
} else {
- emit_signal("item_double_clicked");
+ emit_signal(SNAME("item_double_clicked"));
}
}
pressing_for_editor = false;
@@ -3122,7 +3120,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr) {
// make sure in case of wrong reference after reconstructing whole TreeItems
cache.click_item = get_item_at_position(cache.click_pos);
- emit_signal("button_pressed", cache.click_item, cache.click_column, cache.click_id);
+ emit_signal(SNAME("button_pressed"), cache.click_item, cache.click_column, cache.click_id);
}
cache.click_type = Cache::CLICK_NONE;
cache.click_index = -1;
@@ -3182,7 +3180,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
if (!root || (!root->get_first_child() && hide_root)) {
if (b->get_button_index() == MOUSE_BUTTON_RIGHT && allow_rmb_select) {
- emit_signal("empty_tree_rmb_selected", get_local_mouse_position());
+ emit_signal(SNAME("empty_tree_rmb_selected"), get_local_mouse_position());
}
break;
}
@@ -3233,13 +3231,13 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (b->get_button_index() == MOUSE_BUTTON_LEFT) {
if (get_item_at_position(b->get_position()) == nullptr && !b->is_shift_pressed() && !b->is_ctrl_pressed() && !b->is_command_pressed()) {
- emit_signal("nothing_selected");
+ emit_signal(SNAME("nothing_selected"));
}
}
}
if (propagate_mouse_activated) {
- emit_signal("item_activated");
+ emit_signal(SNAME("item_activated"));
propagate_mouse_activated = false;
}
@@ -3308,7 +3306,7 @@ bool Tree::edit_selected() {
edited_item = s;
edited_col = col;
custom_popup_rect = Rect2i(get_global_position() + rect.position, rect.size);
- emit_signal("custom_popup_edited", false);
+ emit_signal(SNAME("custom_popup_edited"), false);
item_edited(col, s);
return true;
@@ -3544,8 +3542,8 @@ void Tree::_notification(int p_what) {
RID ci = get_canvas_item();
Ref<StyleBox> bg = cache.bg;
- Color font_outline_color = get_theme_color("font_outline_color");
- int outline_size = get_theme_constant("outline_size");
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
Point2 draw_ofs;
draw_ofs += bg->get_offset();
@@ -3595,7 +3593,7 @@ void Tree::_notification(int p_what) {
// Otherwise, section heading backgrounds can appear to be in front of the focus outline when scrolling.
if (has_focus()) {
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
- const Ref<StyleBox> bg_focus = get_theme_stylebox("bg_focus");
+ const Ref<StyleBox> bg_focus = get_theme_stylebox(SNAME("bg_focus"));
bg_focus->draw(ci, Rect2(Point2(), get_size()));
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
}
@@ -3696,9 +3694,9 @@ void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) {
edited_item->cells.write[p_column].dirty = true;
}
if (p_lmb) {
- emit_signal("item_edited");
+ emit_signal(SNAME("item_edited"));
} else {
- emit_signal("item_rmb_edited");
+ emit_signal(SNAME("item_rmb_edited"));
}
}
@@ -3716,7 +3714,7 @@ void Tree::item_selected(int p_column, TreeItem *p_item) {
}
p_item->cells.write[p_column].selected = true;
- //emit_signal("multi_selected",p_item,p_column,true); - NO this is for TreeItem::select
+ //emit_signal(SNAME("multi_selected"),p_item,p_column,true); - NO this is for TreeItem::select
selected_col = p_column;
if (!selected_item) {
@@ -4077,7 +4075,7 @@ void Tree::ensure_cursor_is_visible() {
if (cell_h > screen_h) { // Screen size is too small, maybe it was not resized yet.
v_scroll->set_value(y_offset);
} else if (y_offset + cell_h > v_scroll->get_value() + screen_h) {
- v_scroll->call_deferred("set_value", y_offset - screen_h + cell_h);
+ v_scroll->call_deferred(SNAME("set_value"), y_offset - screen_h + cell_h);
} else if (y_offset < v_scroll->get_value()) {
v_scroll->set_value(y_offset);
}
@@ -4095,7 +4093,7 @@ void Tree::ensure_cursor_is_visible() {
if (cell_w > screen_w) {
h_scroll->set_value(x_offset);
} else if (x_offset + cell_w > h_scroll->get_value() + screen_w) {
- h_scroll->call_deferred("set_value", x_offset - screen_w + cell_w);
+ h_scroll->call_deferred(SNAME("set_value"), x_offset - screen_w + cell_w);
} else if (x_offset < h_scroll->get_value()) {
h_scroll->set_value(x_offset);
}
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index f81a3ef630..0a76351885 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -128,24 +128,21 @@ void CanvasItemMaterial::_update_shader() {
if (particles_animation) {
code += "uniform int particles_anim_h_frames;\n";
code += "uniform int particles_anim_v_frames;\n";
- code += "uniform bool particles_anim_loop;\n";
+ code += "uniform bool particles_anim_loop;\n\n";
code += "void vertex() {\n";
-
- code += "\tfloat h_frames = float(particles_anim_h_frames);\n";
- code += "\tfloat v_frames = float(particles_anim_v_frames);\n";
-
- code += "\tVERTEX.xy /= vec2(h_frames, v_frames);\n";
-
- code += "\tfloat particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n";
- code += "\tfloat particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n";
- code += "\tif (!particles_anim_loop) {\n";
- code += "\t\tparticle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n";
- code += "\t} else {\n";
- code += "\t\tparticle_frame = mod(particle_frame, particle_total_frames);\n";
- code += "\t}";
- code += "\tUV /= vec2(h_frames, v_frames);\n";
- code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n";
+ code += " float h_frames = float(particles_anim_h_frames);\n";
+ code += " float v_frames = float(particles_anim_v_frames);\n";
+ code += " VERTEX.xy /= vec2(h_frames, v_frames);\n";
+ code += " float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n";
+ code += " float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n";
+ code += " if (!particles_anim_loop) {\n";
+ code += " particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n";
+ code += " } else {\n";
+ code += " particle_frame = mod(particle_frame, particle_total_frames);\n";
+ code += " }";
+ code += " UV /= vec2(h_frames, v_frames);\n";
+ code += " UV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n";
code += "}\n";
}
@@ -526,7 +523,7 @@ void CanvasItem::_enter_canvas() {
get_viewport()->gui_reset_canvas_sort_index();
}
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_top_level_raise_self");
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, SNAME("_top_level_raise_self"));
} else {
CanvasItem *parent = get_parent_item();
@@ -545,7 +542,7 @@ void CanvasItem::_exit_canvas() {
notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, RID());
canvas_layer = nullptr;
- group = "";
+ group = StringName();
}
void CanvasItem::_notification(int p_what) {
@@ -591,7 +588,7 @@ void CanvasItem::_notification(int p_what) {
break;
}
- if (group != "") {
+ if (group != StringName()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_top_level_raise_self");
} else {
CanvasItem *p = get_parent_item();
@@ -651,7 +648,7 @@ void CanvasItem::update() {
pending_update = true;
- MessageQueue::get_singleton()->push_call(this, "_update_callback");
+ MessageQueue::get_singleton()->push_call(this, SNAME("_update_callback"));
}
void CanvasItem::set_modulate(const Color &p_modulate) {
@@ -959,8 +956,7 @@ void CanvasItem::_notify_transform(CanvasItem *p_node) {
}
}
- for (List<CanvasItem *>::Element *E = p_node->children_items.front(); E; E = E->next()) {
- CanvasItem *ci = E->get();
+ for (CanvasItem *ci : p_node->children_items) {
if (ci->top_level) {
continue;
}
@@ -1337,9 +1333,9 @@ void CanvasItem::_update_texture_filter_changed(bool p_propagate) {
update();
if (p_propagate) {
- for (List<CanvasItem *>::Element *E = children_items.front(); E; E = E->next()) {
- if (!E->get()->top_level && E->get()->texture_filter == TEXTURE_FILTER_PARENT_NODE) {
- E->get()->_update_texture_filter_changed(true);
+ for (CanvasItem *E : children_items) {
+ if (!E->top_level && E->texture_filter == TEXTURE_FILTER_PARENT_NODE) {
+ E->_update_texture_filter_changed(true);
}
}
}
@@ -1377,9 +1373,9 @@ void CanvasItem::_update_texture_repeat_changed(bool p_propagate) {
RS::get_singleton()->canvas_item_set_default_texture_repeat(get_canvas_item(), texture_repeat_cache);
update();
if (p_propagate) {
- for (List<CanvasItem *>::Element *E = children_items.front(); E; E = E->next()) {
- if (!E->get()->top_level && E->get()->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) {
- E->get()->_update_texture_repeat_changed(true);
+ for (CanvasItem *E : children_items) {
+ if (!E->top_level && E->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) {
+ E->_update_texture_repeat_changed(true);
}
}
}
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index afdd18d76b..f264764870 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -187,7 +187,7 @@ private:
mutable SelfList<Node> xform_change;
RID canvas_item;
- String group;
+ StringName group;
CanvasLayer *canvas_layer = nullptr;
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 775dfa4c46..2c6cefa771 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -151,7 +151,7 @@ Error HTTPRequest::request_raw(const String &p_url, const Vector<String> &p_cust
client->set_blocking_mode(false);
err = _request();
if (err != OK) {
- call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
return ERR_CANT_CONNECT;
}
@@ -167,7 +167,7 @@ void HTTPRequest::_thread_func(void *p_userdata) {
Error err = hr->_request();
if (err != OK) {
- hr->call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
+ hr->call_deferred(SNAME("_request_done"), RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
} else {
while (!hr->thread_request_quit.is_set()) {
bool exit = hr->_update_connection();
@@ -209,7 +209,7 @@ void HTTPRequest::cancel_request() {
bool HTTPRequest::_handle_response(bool *ret_value) {
if (!client->has_response()) {
- call_deferred("_request_done", RESULT_NO_RESPONSE, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_NO_RESPONSE, 0, PackedStringArray(), PackedByteArray());
*ret_value = true;
return true;
}
@@ -220,24 +220,24 @@ bool HTTPRequest::_handle_response(bool *ret_value) {
client->get_response_headers(&rheaders);
response_headers.resize(0);
downloaded.set(0);
- for (List<String>::Element *E = rheaders.front(); E; E = E->next()) {
- response_headers.push_back(E->get());
+ for (const String &E : rheaders) {
+ response_headers.push_back(E);
}
if (response_code == 301 || response_code == 302) {
// Handle redirect
if (max_redirects >= 0 && redirections >= max_redirects) {
- call_deferred("_request_done", RESULT_REDIRECT_LIMIT_REACHED, response_code, response_headers, PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_REDIRECT_LIMIT_REACHED, response_code, response_headers, PackedByteArray());
*ret_value = true;
return true;
}
String new_request;
- for (List<String>::Element *E = rheaders.front(); E; E = E->next()) {
- if (E->get().findn("Location: ") != -1) {
- new_request = E->get().substr(9, E->get().length()).strip_edges();
+ for (const String &E : rheaders) {
+ if (E.findn("Location: ") != -1) {
+ new_request = E.substr(9, E.length()).strip_edges();
}
}
@@ -273,7 +273,7 @@ bool HTTPRequest::_handle_response(bool *ret_value) {
bool HTTPRequest::_update_connection() {
switch (client->get_status()) {
case HTTPClient::STATUS_DISCONNECTED: {
- call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
return true; // End it, since it's doing something
} break;
case HTTPClient::STATUS_RESOLVING: {
@@ -282,7 +282,7 @@ bool HTTPRequest::_update_connection() {
return false;
} break;
case HTTPClient::STATUS_CANT_RESOLVE: {
- call_deferred("_request_done", RESULT_CANT_RESOLVE, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_CANT_RESOLVE, 0, PackedStringArray(), PackedByteArray());
return true;
} break;
@@ -292,7 +292,7 @@ bool HTTPRequest::_update_connection() {
return false;
} break; // Connecting to IP
case HTTPClient::STATUS_CANT_CONNECT: {
- call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
return true;
} break;
@@ -307,16 +307,16 @@ bool HTTPRequest::_update_connection() {
return ret_value;
}
- call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, PackedByteArray());
return true;
}
if (body_len < 0) {
// Chunked transfer is done
- call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body);
+ call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, body);
return true;
}
- call_deferred("_request_done", RESULT_CHUNKED_BODY_SIZE_MISMATCH, response_code, response_headers, PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_CHUNKED_BODY_SIZE_MISMATCH, response_code, response_headers, PackedByteArray());
return true;
// Request might have been done
} else {
@@ -325,7 +325,7 @@ bool HTTPRequest::_update_connection() {
int size = request_data.size();
Error err = client->request(method, request_string, headers, size > 0 ? request_data.ptr() : nullptr, size);
if (err != OK) {
- call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray());
return true;
}
@@ -348,7 +348,7 @@ bool HTTPRequest::_update_connection() {
}
if (!client->is_response_chunked() && client->get_response_body_length() == 0) {
- call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, PackedByteArray());
return true;
}
@@ -357,14 +357,14 @@ bool HTTPRequest::_update_connection() {
body_len = client->get_response_body_length();
if (body_size_limit >= 0 && body_len > body_size_limit) {
- call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray());
return true;
}
if (download_to_file != String()) {
file = FileAccess::open(download_to_file, FileAccess::WRITE);
if (!file) {
- call_deferred("_request_done", RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, PackedByteArray());
return true;
}
}
@@ -383,7 +383,7 @@ bool HTTPRequest::_update_connection() {
const uint8_t *r = chunk.ptr();
file->store_buffer(r, chunk.size());
if (file->get_error() != OK) {
- call_deferred("_request_done", RESULT_DOWNLOAD_FILE_WRITE_ERROR, response_code, response_headers, PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_DOWNLOAD_FILE_WRITE_ERROR, response_code, response_headers, PackedByteArray());
return true;
}
} else {
@@ -392,18 +392,18 @@ bool HTTPRequest::_update_connection() {
}
if (body_size_limit >= 0 && downloaded.get() > body_size_limit) {
- call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray());
return true;
}
if (body_len >= 0) {
if (downloaded.get() == body_len) {
- call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body);
+ call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, body);
return true;
}
} else if (client->get_status() == HTTPClient::STATUS_DISCONNECTED) {
// We read till EOF, with no errors. Request is done.
- call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body);
+ call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, body);
return true;
}
@@ -411,11 +411,11 @@ bool HTTPRequest::_update_connection() {
} break; // Request resulted in body: break which must be read
case HTTPClient::STATUS_CONNECTION_ERROR: {
- call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray());
return true;
} break;
case HTTPClient::STATUS_SSL_HANDSHAKE_ERROR: {
- call_deferred("_request_done", RESULT_SSL_HANDSHAKE_ERROR, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_SSL_HANDSHAKE_ERROR, 0, PackedStringArray(), PackedByteArray());
return true;
} break;
}
@@ -463,7 +463,7 @@ void HTTPRequest::_request_done(int p_status, int p_code, const PackedStringArra
data = &p_data;
}
- emit_signal("request_completed", p_status, p_code, p_headers, *data);
+ emit_signal(SNAME("request_completed"), p_status, p_code, p_headers, *data);
}
void HTTPRequest::_notification(int p_what) {
@@ -563,7 +563,7 @@ int HTTPRequest::get_timeout() {
void HTTPRequest::_timeout() {
cancel_request();
- call_deferred("_request_done", RESULT_TIMEOUT, 0, PackedStringArray(), PackedByteArray());
+ call_deferred(SNAME("_request_done"), RESULT_TIMEOUT, 0, PackedStringArray(), PackedByteArray());
}
void HTTPRequest::_bind_methods() {
diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp
index 89dac5f5a8..b5ba1899ec 100644
--- a/scene/main/instance_placeholder.cpp
+++ b/scene/main/instance_placeholder.cpp
@@ -42,9 +42,9 @@ bool InstancePlaceholder::_set(const StringName &p_name, const Variant &p_value)
}
bool InstancePlaceholder::_get(const StringName &p_name, Variant &r_ret) const {
- for (const List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) {
- if (E->get().name == p_name) {
- r_ret = E->get().value;
+ for (const PropSet &E : stored_values) {
+ if (E.name == p_name) {
+ r_ret = E.value;
return true;
}
}
@@ -52,10 +52,10 @@ bool InstancePlaceholder::_get(const StringName &p_name, Variant &r_ret) const {
}
void InstancePlaceholder::_get_property_list(List<PropertyInfo> *p_list) const {
- for (const List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) {
+ for (const PropSet &E : stored_values) {
PropertyInfo pi;
- pi.name = E->get().name;
- pi.type = E->get().value.get_type();
+ pi.name = E.name;
+ pi.type = E.value.get_type();
pi.usage = PROPERTY_USAGE_STORAGE;
p_list->push_back(pi);
@@ -95,8 +95,8 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene
scene->set_name(get_name());
int pos = get_index();
- for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) {
- scene->set(E->get().name, E->get().value);
+ for (const PropSet &E : stored_values) {
+ scene->set(E.name, E.value);
}
if (p_replace) {
@@ -114,10 +114,10 @@ Dictionary InstancePlaceholder::get_stored_values(bool p_with_order) {
Dictionary ret;
PackedStringArray order;
- for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) {
- ret[E->get().name] = E->get().value;
+ for (const PropSet &E : stored_values) {
+ ret[E.name] = E.value;
if (p_with_order) {
- order.push_back(E->get().name);
+ order.push_back(E.name);
}
};
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index ef6d2e72f6..f1e5574351 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -442,7 +442,7 @@ void Node::set_process_mode(ProcessMode p_mode) {
// This is required for the editor to update the visibility of disabled nodes
// It's very expensive during runtime to change, so editor-only
if (Engine::get_singleton()->is_editor_hint()) {
- get_tree()->emit_signal("tree_process_mode_changed");
+ get_tree()->emit_signal(SNAME("tree_process_mode_changed"));
}
#endif
}
@@ -507,7 +507,7 @@ bool Node::is_network_master() const {
/***** RPC CONFIG ********/
-uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, NetworkedMultiplayerPeer::TransferMode p_transfer_mode, int p_channel) {
+uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, MultiplayerPeer::TransferMode p_transfer_mode, int p_channel) {
for (int i = 0; i < data.rpc_methods.size(); i++) {
if (data.rpc_methods[i].name == p_method) {
MultiplayerAPI::RPCConfig &nd = data.rpc_methods.write[i];
@@ -868,7 +868,7 @@ void Node::set_name(const String &p_name) {
propagate_notification(NOTIFICATION_PATH_CHANGED);
if (is_inside_tree()) {
- emit_signal("renamed");
+ emit_signal(SNAME("renamed"));
get_tree()->node_renamed(this);
get_tree()->tree_changed();
}
@@ -1597,8 +1597,8 @@ Array Node::_get_groups() const {
Array groups;
List<GroupInfo> gi;
get_groups(&gi);
- for (List<GroupInfo>::Element *E = gi.front(); E; E = E->next()) {
- groups.push_back(E->get().name);
+ for (const GroupInfo &E : gi) {
+ groups.push_back(E.name);
}
return groups;
@@ -1822,6 +1822,18 @@ Node *Node::get_deepest_editable_node(Node *p_start_node) const {
return node;
}
+String Node::to_string() {
+ if (get_script_instance()) {
+ bool valid;
+ String ret = get_script_instance()->to_string(&valid);
+ if (valid) {
+ return ret;
+ }
+ }
+
+ return (get_name() ? String(get_name()) + ":" : "") + Object::to_string();
+}
+
void Node::set_scene_instance_state(const Ref<SceneState> &p_state) {
data.instance_state = p_state;
}
@@ -1935,18 +1947,18 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
List<PropertyInfo> plist;
N->get()->get_property_list(&plist);
- for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
+ for (const PropertyInfo &E : plist) {
+ if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
- String name = E->get().name;
+ String name = E.name;
if (name == script_property_name) {
continue;
}
Variant value = N->get()->get(name).duplicate(true);
- if (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE) {
+ if (E.usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE) {
Resource *res = Object::cast_to<Resource>(value);
if (res) { // Duplicate only if it's a resource
current_node->set(name, res->duplicate());
@@ -1971,14 +1983,14 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
if (p_flags & DUPLICATE_GROUPS) {
List<GroupInfo> gi;
get_groups(&gi);
- for (List<GroupInfo>::Element *E = gi.front(); E; E = E->next()) {
+ for (const GroupInfo &E : gi) {
#ifdef TOOLS_ENABLED
- if ((p_flags & DUPLICATE_FROM_EDITOR) && !E->get().persistent) {
+ if ((p_flags & DUPLICATE_FROM_EDITOR) && !E.persistent) {
continue;
}
#endif
- node->add_to_group(E->get().name, E->get().persistent);
+ node->add_to_group(E.name, E.persistent);
}
}
@@ -2002,21 +2014,21 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
}
}
- for (List<const Node *>::Element *E = hidden_roots.front(); E; E = E->next()) {
- Node *parent = node->get_node(get_path_to(E->get()->data.parent));
+ for (const Node *&E : hidden_roots) {
+ Node *parent = node->get_node(get_path_to(E->data.parent));
if (!parent) {
memdelete(node);
return nullptr;
}
- Node *dup = E->get()->_duplicate(p_flags, r_duplimap);
+ Node *dup = E->_duplicate(p_flags, r_duplimap);
if (!dup) {
memdelete(node);
return nullptr;
}
parent->add_child(dup);
- int pos = E->get()->get_index();
+ int pos = E->get_index();
if (pos < parent->get_child_count() - 1) {
parent->move_child(dup, pos);
@@ -2061,17 +2073,17 @@ void Node::remap_node_resources(Node *p_node, const Map<RES, RES> &p_resource_re
List<PropertyInfo> props;
p_node->get_property_list(&props);
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
+ for (const PropertyInfo &E : props) {
+ if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
- Variant v = p_node->get(E->get().name);
+ Variant v = p_node->get(E.name);
if (v.is_ref()) {
RES res = v;
if (res.is_valid()) {
if (p_resource_remap.has(res)) {
- p_node->set(E->get().name, p_resource_remap[res]);
+ p_node->set(E.name, p_resource_remap[res]);
remap_nested_resources(res, p_resource_remap);
}
}
@@ -2087,17 +2099,17 @@ void Node::remap_nested_resources(RES p_resource, const Map<RES, RES> &p_resourc
List<PropertyInfo> props;
p_resource->get_property_list(&props);
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
+ for (const PropertyInfo &E : props) {
+ if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
- Variant v = p_resource->get(E->get().name);
+ Variant v = p_resource->get(E.name);
if (v.is_ref()) {
RES res = v;
if (res.is_valid()) {
if (p_resource_remap.has(res)) {
- p_resource->set(E->get().name, p_resource_remap[res]);
+ p_resource->set(E.name, p_resource_remap[res]);
remap_nested_resources(res, p_resource_remap);
}
}
@@ -2123,13 +2135,13 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const {
List<Connection> conns;
n->get_all_signal_connections(&conns);
- for (List<Connection>::Element *E = conns.front(); E; E = E->next()) {
- if (E->get().flags & CONNECT_PERSIST) {
+ for (const Connection &E : conns) {
+ if (E.flags & CONNECT_PERSIST) {
//user connected
NodePath p = p_original->get_path_to(n);
Node *copy = p_copy->get_node(p);
- Node *target = Object::cast_to<Node>(E->get().callable.get_object());
+ Node *target = Object::cast_to<Node>(E.callable.get_object());
if (!target) {
continue;
}
@@ -2146,9 +2158,9 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const {
}
if (copy && copytarget) {
- const Callable copy_callable = Callable(copytarget, E->get().callable.get_method());
- if (!copy->is_connected(E->get().signal.get_name(), copy_callable)) {
- copy->connect(E->get().signal.get_name(), copy_callable, E->get().binds, E->get().flags);
+ const Callable copy_callable = Callable(copytarget, E.callable.get_method());
+ if (!copy->is_connected(E.signal.get_name(), copy_callable)) {
+ copy->connect(E.signal.get_name(), copy_callable, E.binds, E.flags);
}
}
}
@@ -2182,8 +2194,8 @@ void Node::replace_by(Node *p_node, bool p_keep_groups) {
List<GroupInfo> groups;
get_groups(&groups);
- for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) {
- p_node->add_to_group(E->get().name, E->get().persistent);
+ for (const GroupInfo &E : groups) {
+ p_node->add_to_group(E.name, E.persistent);
}
}
@@ -2229,9 +2241,7 @@ void Node::_replace_connections_target(Node *p_new_target) {
List<Connection> cl;
get_signals_connected_to_this(&cl);
- for (List<Connection>::Element *E = cl.front(); E; E = E->next()) {
- Connection &c = E->get();
-
+ for (const Connection &c : cl) {
if (c.flags & CONNECT_PERSIST) {
c.signal.get_object()->disconnect(c.signal.get_name(), Callable(this, c.callable.get_method()));
bool valid = p_new_target->has_method(c.callable.get_method()) || Ref<Script>(p_new_target->get_script()).is_null() || Ref<Script>(p_new_target->get_script())->has_method(c.callable.get_method());
@@ -2623,7 +2633,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_multiplayer"), &Node::get_multiplayer);
ClassDB::bind_method(D_METHOD("get_custom_multiplayer"), &Node::get_custom_multiplayer);
ClassDB::bind_method(D_METHOD("set_custom_multiplayer", "api"), &Node::set_custom_multiplayer);
- ClassDB::bind_method(D_METHOD("rpc_config", "method", "rpc_mode", "transfer_mode", "channel"), &Node::rpc_config, DEFVAL(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("rpc_config", "method", "rpc_mode", "transfer_mode", "channel"), &Node::rpc_config, DEFVAL(MultiplayerPeer::TRANSFER_MODE_RELIABLE), DEFVAL(0));
ClassDB::bind_method(D_METHOD("set_editor_description", "editor_description"), &Node::set_editor_description);
ClassDB::bind_method(D_METHOD("get_editor_description"), &Node::get_editor_description);
diff --git a/scene/main/node.h b/scene/main/node.h
index fc5af43829..20315d7a86 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -329,6 +329,8 @@ public:
bool is_editable_instance(const Node *p_node) const;
Node *get_deepest_editable_node(Node *p_start_node) const;
+ virtual String to_string() override;
+
/* NOTIFICATIONS */
void propagate_notification(int p_notification);
@@ -430,7 +432,7 @@ public:
int get_network_master() const;
bool is_network_master() const;
- uint16_t rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, NetworkedMultiplayerPeer::TransferMode p_transfer_mode, int p_channel = 0); // config a local method for RPC
+ uint16_t rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, MultiplayerPeer::TransferMode p_transfer_mode, int p_channel = 0); // config a local method for RPC
Vector<MultiplayerAPI::RPCConfig> get_node_rpc_methods() const;
void rpc(const StringName &p_method, VARIANT_ARG_LIST); // RPC, honors RPCMode, TransferMode, channel
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 4b52c4e99f..dcbbebbc55 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -66,11 +66,11 @@ void SceneTreeTimer::_bind_methods() {
ADD_SIGNAL(MethodInfo("timeout"));
}
-void SceneTreeTimer::set_time_left(float p_time) {
+void SceneTreeTimer::set_time_left(double p_time) {
time_left = p_time;
}
-float SceneTreeTimer::get_time_left() const {
+double SceneTreeTimer::get_time_left() const {
return time_left;
}
@@ -82,12 +82,19 @@ bool SceneTreeTimer::is_process_always() {
return process_always;
}
+void SceneTreeTimer::set_ignore_time_scale(bool p_ignore) {
+ ignore_time_scale = p_ignore;
+}
+
+bool SceneTreeTimer::is_ignore_time_scale() {
+ return ignore_time_scale;
+}
+
void SceneTreeTimer::release_connections() {
List<Connection> connections;
get_all_signal_connections(&connections);
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- Connection const &connection = E->get();
+ for (const Connection &connection : connections) {
disconnect(connection.signal.get_name(), connection.callable);
}
}
@@ -169,8 +176,8 @@ void SceneTree::_flush_ugc() {
v[i] = E->get()[i];
}
- static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5");
- call_group_flags(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4]);
+ static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8");
+ call_group_flags(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);
unique_group_calls.erase(E);
}
@@ -396,7 +403,7 @@ void SceneTree::initialize() {
MainLoop::initialize();
}
-bool SceneTree::physics_process(float p_time) {
+bool SceneTree::physics_process(double p_time) {
root_lock++;
current_frame++;
@@ -406,11 +413,11 @@ bool SceneTree::physics_process(float p_time) {
MainLoop::physics_process(p_time);
physics_process_time = p_time;
- emit_signal("physics_frame");
+ emit_signal(SNAME("physics_frame"));
- _notify_group_pause("physics_process_internal", Node::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
- call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_process_picking");
- _notify_group_pause("physics_process", Node::NOTIFICATION_PHYSICS_PROCESS);
+ _notify_group_pause(SNAME("physics_process_internal"), Node::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
+ call_group_flags(GROUP_CALL_REALTIME, SNAME("_picking_viewports"), SNAME("_process_picking"));
+ _notify_group_pause(SNAME("physics_process"), Node::NOTIFICATION_PHYSICS_PROCESS);
_flush_ugc();
MessageQueue::get_singleton()->flush(); //small little hack
@@ -425,7 +432,7 @@ bool SceneTree::physics_process(float p_time) {
return _quit;
}
-bool SceneTree::process(float p_time) {
+bool SceneTree::process(double p_time) {
root_lock++;
MainLoop::process(p_time);
@@ -436,14 +443,14 @@ bool SceneTree::process(float p_time) {
multiplayer->poll();
}
- emit_signal("process_frame");
+ emit_signal(SNAME("process_frame"));
MessageQueue::get_singleton()->flush(); //small little hack
flush_transform_notifications();
- _notify_group_pause("process_internal", Node::NOTIFICATION_INTERNAL_PROCESS);
- _notify_group_pause("process", Node::NOTIFICATION_PROCESS);
+ _notify_group_pause(SNAME("process_internal"), Node::NOTIFICATION_INTERNAL_PROCESS);
+ _notify_group_pause(SNAME("process"), Node::NOTIFICATION_PROCESS);
_flush_ugc();
MessageQueue::get_singleton()->flush(); //small little hack
@@ -466,12 +473,17 @@ bool SceneTree::process(float p_time) {
E = N;
continue;
}
- float time_left = E->get()->get_time_left();
- time_left -= p_time;
+
+ double time_left = E->get()->get_time_left();
+ if (E->get()->is_ignore_time_scale()) {
+ time_left -= Engine::get_singleton()->get_process_step();
+ } else {
+ time_left -= p_time;
+ }
E->get()->set_time_left(time_left);
if (time_left < 0) {
- E->get()->emit_signal("timeout");
+ E->get()->emit_signal(SNAME("timeout"));
timers.erase(E);
}
if (E == L) {
@@ -490,7 +502,7 @@ bool SceneTree::process(float p_time) {
if (Engine::get_singleton()->is_editor_hint()) {
//simple hack to reload fallback environment if it changed from editor
- String env_path = ProjectSettings::get_singleton()->get("rendering/environment/defaults/default_environment");
+ String env_path = ProjectSettings::get_singleton()->get(SNAME("rendering/environment/defaults/default_environment"));
env_path = env_path.strip_edges(); //user may have added a space or two
String cpath;
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
@@ -559,8 +571,8 @@ void SceneTree::finalize() {
}
// cleanup timers
- for (List<Ref<SceneTreeTimer>>::Element *E = timers.front(); E; E = E->next()) {
- E->get()->release_connections();
+ for (Ref<SceneTreeTimer> &timer : timers) {
+ timer->release_connections();
}
timers.clear();
}
@@ -927,8 +939,8 @@ Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Cal
v[i] = *p_args[i + 3];
}
- static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5");
- call_group_flags(flags, group, method, v[0], v[1], v[2], v[3], v[4]);
+ static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8");
+ call_group_flags(flags, group, method, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);
return Variant();
}
@@ -947,8 +959,8 @@ Variant SceneTree::_call_group(const Variant **p_args, int p_argcount, Callable:
v[i] = *p_args[i + 2];
}
- static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5");
- call_group_flags(0, group, method, v[0], v[1], v[2], v[3], v[4]);
+ static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8");
+ call_group_flags(0, group, method, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);
return Variant();
}
@@ -1097,7 +1109,7 @@ Error SceneTree::change_scene_to(const Ref<PackedScene> &p_scene) {
ERR_FAIL_COND_V(!new_scene, ERR_CANT_CREATE);
}
- call_deferred("_change_scene", new_scene);
+ call_deferred(SNAME("_change_scene"), new_scene);
return OK;
}
@@ -1112,7 +1124,7 @@ void SceneTree::add_current_scene(Node *p_current) {
root->add_child(p_current);
}
-Ref<SceneTreeTimer> SceneTree::create_timer(float p_delay_sec, bool p_process_always) {
+Ref<SceneTreeTimer> SceneTree::create_timer(double p_delay_sec, bool p_process_always) {
Ref<SceneTreeTimer> stt;
stt.instantiate();
stt->set_process_always(p_process_always);
@@ -1134,34 +1146,14 @@ Array SceneTree::get_processed_tweens() {
ret.resize(tweens.size());
int i = 0;
- for (List<Ref<Tween>>::Element *E = tweens.front(); E; E = E->next()) {
- ret[i] = E->get();
+ for (const Ref<Tween> &tween : tweens) {
+ ret[i] = tween;
i++;
}
return ret;
}
-void SceneTree::_network_peer_connected(int p_id) {
- emit_signal("network_peer_connected", p_id);
-}
-
-void SceneTree::_network_peer_disconnected(int p_id) {
- emit_signal("network_peer_disconnected", p_id);
-}
-
-void SceneTree::_connected_to_server() {
- emit_signal("connected_to_server");
-}
-
-void SceneTree::_connection_failed() {
- emit_signal("connection_failed");
-}
-
-void SceneTree::_server_disconnected() {
- emit_signal("server_disconnected");
-}
-
Ref<MultiplayerAPI> SceneTree::get_multiplayer() const {
return multiplayer;
}
@@ -1177,58 +1169,8 @@ bool SceneTree::is_multiplayer_poll_enabled() const {
void SceneTree::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
ERR_FAIL_COND(!p_multiplayer.is_valid());
- if (multiplayer.is_valid()) {
- multiplayer->disconnect("network_peer_connected", callable_mp(this, &SceneTree::_network_peer_connected));
- multiplayer->disconnect("network_peer_disconnected", callable_mp(this, &SceneTree::_network_peer_disconnected));
- multiplayer->disconnect("connected_to_server", callable_mp(this, &SceneTree::_connected_to_server));
- multiplayer->disconnect("connection_failed", callable_mp(this, &SceneTree::_connection_failed));
- multiplayer->disconnect("server_disconnected", callable_mp(this, &SceneTree::_server_disconnected));
- }
-
multiplayer = p_multiplayer;
multiplayer->set_root_node(root);
-
- multiplayer->connect("network_peer_connected", callable_mp(this, &SceneTree::_network_peer_connected));
- multiplayer->connect("network_peer_disconnected", callable_mp(this, &SceneTree::_network_peer_disconnected));
- multiplayer->connect("connected_to_server", callable_mp(this, &SceneTree::_connected_to_server));
- multiplayer->connect("connection_failed", callable_mp(this, &SceneTree::_connection_failed));
- multiplayer->connect("server_disconnected", callable_mp(this, &SceneTree::_server_disconnected));
-}
-
-void SceneTree::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_network_peer) {
- multiplayer->set_network_peer(p_network_peer);
-}
-
-Ref<NetworkedMultiplayerPeer> SceneTree::get_network_peer() const {
- return multiplayer->get_network_peer();
-}
-
-bool SceneTree::is_network_server() const {
- return multiplayer->is_network_server();
-}
-
-bool SceneTree::has_network_peer() const {
- return multiplayer->has_network_peer();
-}
-
-int SceneTree::get_network_unique_id() const {
- return multiplayer->get_network_unique_id();
-}
-
-Vector<int> SceneTree::get_network_connected_peers() const {
- return multiplayer->get_network_connected_peers();
-}
-
-int SceneTree::get_rpc_sender_id() const {
- return multiplayer->get_rpc_sender_id();
-}
-
-void SceneTree::set_refuse_new_network_connections(bool p_refuse) {
- multiplayer->set_refuse_new_network_connections(p_refuse);
-}
-
-bool SceneTree::is_refusing_new_network_connections() const {
- return multiplayer->is_refusing_new_network_connections();
}
void SceneTree::_bind_methods() {
@@ -1297,24 +1239,12 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_multiplayer"), &SceneTree::get_multiplayer);
ClassDB::bind_method(D_METHOD("set_multiplayer_poll_enabled", "enabled"), &SceneTree::set_multiplayer_poll_enabled);
ClassDB::bind_method(D_METHOD("is_multiplayer_poll_enabled"), &SceneTree::is_multiplayer_poll_enabled);
- ClassDB::bind_method(D_METHOD("set_network_peer", "peer"), &SceneTree::set_network_peer);
- ClassDB::bind_method(D_METHOD("get_network_peer"), &SceneTree::get_network_peer);
- ClassDB::bind_method(D_METHOD("is_network_server"), &SceneTree::is_network_server);
- ClassDB::bind_method(D_METHOD("has_network_peer"), &SceneTree::has_network_peer);
- ClassDB::bind_method(D_METHOD("get_network_connected_peers"), &SceneTree::get_network_connected_peers);
- ClassDB::bind_method(D_METHOD("get_network_unique_id"), &SceneTree::get_network_unique_id);
- ClassDB::bind_method(D_METHOD("get_rpc_sender_id"), &SceneTree::get_rpc_sender_id);
- ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections", "refuse"), &SceneTree::set_refuse_new_network_connections);
- ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"), &SceneTree::is_refusing_new_network_connections);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_collisions_hint"), "set_debug_collisions_hint", "is_debugging_collisions_hint");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_navigation_hint"), "set_debug_navigation_hint", "is_debugging_navigation_hint");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_pause", "is_paused");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections");
- ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_edited_scene_root", "get_edited_scene_root");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "current_scene", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_current_scene", "get_current_scene");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", PROPERTY_USAGE_NONE), "set_network_peer", "get_network_peer");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "root", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "", "get_root");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", PROPERTY_USAGE_NONE), "set_multiplayer", "get_multiplayer");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "multiplayer_poll"), "set_multiplayer_poll_enabled", "is_multiplayer_poll_enabled");
@@ -1330,11 +1260,6 @@ void SceneTree::_bind_methods() {
ADD_SIGNAL(MethodInfo("physics_frame"));
ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "screen")));
- ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id")));
- ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id")));
- ADD_SIGNAL(MethodInfo("connected_to_server"));
- ADD_SIGNAL(MethodInfo("connection_failed"));
- ADD_SIGNAL(MethodInfo("server_disconnected"));
BIND_ENUM_CONSTANT(GROUP_CALL_DEFAULT);
BIND_ENUM_CONSTANT(GROUP_CALL_REVERSE);
@@ -1477,11 +1402,11 @@ SceneTree::SceneTree() {
List<String> exts;
ResourceLoader::get_recognized_extensions_for_type("Environment", &exts);
String ext_hint;
- for (List<String>::Element *E = exts.front(); E; E = E->next()) {
+ for (const String &E : exts) {
if (ext_hint != String()) {
ext_hint += ",";
}
- ext_hint += "*." + E->get();
+ ext_hint += "*." + E;
}
// Get path.
String env_path = GLOBAL_DEF("rendering/environment/defaults/default_environment", "");
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index 0e9ffb0f5f..cfb95bd6b5 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -52,19 +52,23 @@ class Tween;
class SceneTreeTimer : public RefCounted {
GDCLASS(SceneTreeTimer, RefCounted);
- float time_left = 0.0;
+ double time_left = 0.0;
bool process_always = true;
+ bool ignore_time_scale = false;
protected:
static void _bind_methods();
public:
- void set_time_left(float p_time);
- float get_time_left() const;
+ void set_time_left(double p_time);
+ double get_time_left() const;
void set_process_always(bool p_process_always);
bool is_process_always();
+ void set_ignore_time_scale(bool p_ignore);
+ bool is_ignore_time_scale();
+
void release_connections();
SceneTreeTimer();
@@ -87,8 +91,8 @@ private:
Window *root = nullptr;
uint64_t tree_version = 1;
- float physics_process_time = 1.0;
- float process_time = 1.0;
+ double physics_process_time = 1.0;
+ double process_time = 1.0;
bool accept_quit = true;
bool quit_on_go_back = true;
@@ -159,13 +163,6 @@ private:
Ref<MultiplayerAPI> multiplayer;
bool multiplayer_poll = true;
- void _network_peer_connected(int p_id);
- void _network_peer_disconnected(int p_id);
-
- void _connected_to_server();
- void _connection_failed();
- void _server_disconnected();
-
static SceneTree *singleton;
friend class Node;
@@ -240,8 +237,8 @@ public:
virtual void initialize() override;
- virtual bool physics_process(float p_time) override;
- virtual bool process(float p_time) override;
+ virtual bool physics_process(double p_time) override;
+ virtual bool process(double p_time) override;
virtual void finalize() override;
@@ -250,8 +247,8 @@ public:
void quit(int p_exit_code = EXIT_SUCCESS);
- _FORCE_INLINE_ float get_physics_process_time() const { return physics_process_time; }
- _FORCE_INLINE_ float get_process_time() const { return process_time; }
+ _FORCE_INLINE_ double get_physics_process_time() const { return physics_process_time; }
+ _FORCE_INLINE_ double get_process_time() const { return process_time; }
#ifdef TOOLS_ENABLED
bool is_node_being_edited(const Node *p_node) const;
@@ -320,7 +317,7 @@ public:
Error change_scene_to(const Ref<PackedScene> &p_scene);
Error reload_current_scene();
- Ref<SceneTreeTimer> create_timer(float p_delay_sec, bool p_process_always = true);
+ Ref<SceneTreeTimer> create_timer(double p_delay_sec, bool p_process_always = true);
Ref<Tween> create_tween();
Array get_processed_tweens();
@@ -337,16 +334,6 @@ public:
void set_multiplayer_poll_enabled(bool p_enabled);
bool is_multiplayer_poll_enabled() const;
void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer);
- void set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_network_peer);
- Ref<NetworkedMultiplayerPeer> get_network_peer() const;
- bool is_network_server() const;
- bool has_network_peer() const;
- int get_network_unique_id() const;
- Vector<int> get_network_connected_peers() const;
- int get_rpc_sender_id() const;
-
- void set_refuse_new_network_connections(bool p_refuse);
- bool is_refusing_new_network_connections() const;
static void add_idle_callback(IdleCallback p_callback);
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index f52237251c..b5a2a30b3b 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -58,7 +58,7 @@ void Timer::_notification(int p_what) {
stop();
}
- emit_signal("timeout");
+ emit_signal(SNAME("timeout"));
}
} break;
@@ -74,19 +74,19 @@ void Timer::_notification(int p_what) {
} else {
stop();
}
- emit_signal("timeout");
+ emit_signal(SNAME("timeout"));
}
} break;
}
}
-void Timer::set_wait_time(float p_time) {
+void Timer::set_wait_time(double p_time) {
ERR_FAIL_COND_MSG(p_time <= 0, "Time should be greater than zero.");
wait_time = p_time;
}
-float Timer::get_wait_time() const {
+double Timer::get_wait_time() const {
return wait_time;
}
@@ -106,7 +106,7 @@ bool Timer::has_autostart() const {
return autostart;
}
-void Timer::start(float p_time) {
+void Timer::start(double p_time) {
ERR_FAIL_COND_MSG(!is_inside_tree(), "Timer was not added to the SceneTree. Either add it or set autostart to true.");
if (p_time > 0) {
@@ -139,7 +139,7 @@ bool Timer::is_stopped() const {
return get_time_left() <= 0;
}
-float Timer::get_time_left() const {
+double Timer::get_time_left() const {
return time_left > 0 ? time_left : 0;
}
diff --git a/scene/main/timer.h b/scene/main/timer.h
index 3d9e21d7fc..2b9faddcb9 100644
--- a/scene/main/timer.h
+++ b/scene/main/timer.h
@@ -36,7 +36,7 @@
class Timer : public Node {
GDCLASS(Timer, Node);
- float wait_time = 1.0;
+ double wait_time = 1.0;
bool one_shot = false;
bool autostart = false;
bool processing = false;
@@ -54,8 +54,8 @@ public:
TIMER_PROCESS_IDLE,
};
- void set_wait_time(float p_time);
- float get_wait_time() const;
+ void set_wait_time(double p_time);
+ double get_wait_time() const;
void set_one_shot(bool p_one_shot);
bool is_one_shot() const;
@@ -63,7 +63,7 @@ public:
void set_autostart(bool p_start);
bool has_autostart() const;
- void start(float p_time = -1);
+ void start(double p_time = -1);
void stop();
void set_paused(bool p_paused);
@@ -71,7 +71,7 @@ public:
bool is_stopped() const;
- float get_time_left() const;
+ double get_time_left() const;
void set_timer_process_callback(TimerProcessCallback p_callback);
TimerProcessCallback get_timer_process_callback() const;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 9a2e0c5230..27e42db1bd 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -37,6 +37,7 @@
#include "core/os/os.h"
#include "core/string/translation.h"
+#include "scene/2d/camera_2d.h"
#include "scene/2d/collision_object_2d.h"
#include "scene/3d/camera_3d.h"
#include "scene/3d/collision_object_3d.h"
@@ -195,7 +196,7 @@ void Viewport::_collision_object_input_event(CollisionObject3D *p_object, Camera
return; //discarded
}
}
- p_object->_input_event(camera, p_input_event, p_pos, p_normal, p_shape);
+ p_object->_input_event(camera_3d, p_input_event, p_pos, p_normal, p_shape);
physics_last_object_transform = object_transform;
physics_last_camera_transform = camera_transform;
physics_last_id = id;
@@ -248,16 +249,16 @@ void Viewport::_sub_window_update(Window *p_window) {
Rect2i r = Rect2i(p_window->get_position(), sw.window->get_size());
if (!p_window->get_flag(Window::FLAG_BORDERLESS)) {
- Ref<StyleBox> panel = p_window->get_theme_stylebox("panel_window");
+ Ref<StyleBox> panel = p_window->get_theme_stylebox(SNAME("panel_window"));
panel->draw(sw.canvas_item, r);
// Draw the title bar text.
- Ref<Font> title_font = p_window->get_theme_font("title_font");
- int font_size = p_window->get_theme_font_size("title_font_size");
- Color title_color = p_window->get_theme_color("title_color");
- int title_height = p_window->get_theme_constant("title_height");
- int close_h_ofs = p_window->get_theme_constant("close_h_ofs");
- int close_v_ofs = p_window->get_theme_constant("close_v_ofs");
+ Ref<Font> title_font = p_window->get_theme_font(SNAME("title_font"));
+ int font_size = p_window->get_theme_font_size(SNAME("title_font_size"));
+ Color title_color = p_window->get_theme_color(SNAME("title_color"));
+ int title_height = p_window->get_theme_constant(SNAME("title_height"));
+ int close_h_ofs = p_window->get_theme_constant(SNAME("close_h_ofs"));
+ int close_v_ofs = p_window->get_theme_constant(SNAME("close_v_ofs"));
TextLine title_text = TextLine(p_window->get_title(), title_font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
title_text.set_width(r.size.width - panel->get_minimum_size().x - close_h_ofs);
@@ -265,8 +266,8 @@ void Viewport::_sub_window_update(Window *p_window) {
int x = (r.size.width - title_text.get_size().x) / 2;
int y = (-title_height - title_text.get_size().y) / 2;
- Color font_outline_color = p_window->get_theme_color("title_outline_modulate");
- int outline_size = p_window->get_theme_constant("title_outline_size");
+ Color font_outline_color = p_window->get_theme_color(SNAME("title_outline_modulate"));
+ int outline_size = p_window->get_theme_constant(SNAME("title_outline_size"));
if (outline_size > 0 && font_outline_color.a > 0) {
title_text.draw_outline(sw.canvas_item, r.position + Point2(x, y), outline_size, font_outline_color);
}
@@ -444,6 +445,7 @@ void Viewport::_notification(int p_what) {
RenderingServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh);
RenderingServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world_3d()->get_scenario());
//RenderingServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, RS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true);
+ set_physics_process_internal(true);
}
} break;
@@ -462,7 +464,7 @@ void Viewport::_notification(int p_what) {
}
}
- if (cameras.size() && !camera) {
+ if (cameras.size() && !camera_3d) {
//there are cameras but no current camera, pick first in tree and make it current
Camera3D *first = nullptr;
for (Set<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) {
@@ -477,10 +479,6 @@ void Viewport::_notification(int p_what) {
}
#endif
- // Enable processing for tooltips, collision debugging, physics object picking, etc.
- set_process_internal(true);
- set_physics_process_internal(true);
-
} break;
case NOTIFICATION_EXIT_TREE: {
_gui_cancel_tooltip();
@@ -500,19 +498,10 @@ void Viewport::_notification(int p_what) {
}
remove_from_group("_viewports");
+ set_physics_process_internal(false);
RS::get_singleton()->viewport_set_active(viewport, false);
RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, RID());
-
- } break;
- case NOTIFICATION_INTERNAL_PROCESS: {
- if (gui.tooltip_timer >= 0) {
- gui.tooltip_timer -= get_process_delta_time();
- if (gui.tooltip_timer < 0) {
- _gui_show_tooltip();
- }
- }
-
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
@@ -584,8 +573,7 @@ void Viewport::_process_picking() {
// if no mouse event exists, create a motion one. This is necessary because objects or camera may have moved.
// while this extra event is sent, it is checked if both camera and last object and last ID did not move. If nothing changed, the event is discarded to avoid flooding with unnecessary motion events every frame
bool has_mouse_event = false;
- for (List<Ref<InputEvent>>::Element *E = physics_picking_events.front(); E; E = E->next()) {
- Ref<InputEventMouse> m = E->get();
+ for (const Ref<InputEvent> &m : physics_picking_events) {
if (m.is_valid()) {
has_mouse_event = true;
break;
@@ -706,7 +694,6 @@ void Viewport::_process_picking() {
bool send_event = true;
if (is_mouse) {
Map<ObjectID, uint64_t>::Element *F = physics_2d_mouseover.find(res[i].collider_id);
-
if (!F) {
physics_2d_mouseover.insert(res[i].collider_id, frame);
co->_mouse_enter();
@@ -717,6 +704,13 @@ void Viewport::_process_picking() {
send_event = false;
}
}
+ Map<Pair<ObjectID, int>, uint64_t, PairSort<ObjectID, int>>::Element *SF = physics_2d_shape_mouseover.find(Pair(res[i].collider_id, res[i].shape));
+ if (!SF) {
+ physics_2d_shape_mouseover.insert(Pair(res[i].collider_id, res[i].shape), frame);
+ co->_mouse_shape_enter(res[i].shape);
+ } else {
+ SF->get() = frame;
+ }
}
if (send_event) {
@@ -728,25 +722,7 @@ void Viewport::_process_picking() {
}
if (is_mouse) {
- List<Map<ObjectID, uint64_t>::Element *> to_erase;
-
- for (Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.front(); E; E = E->next()) {
- if (E->get() != frame) {
- Object *o = ObjectDB::get_instance(E->key());
- if (o) {
- CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
- if (co) {
- co->_mouse_exit();
- }
- }
- to_erase.push_back(E);
- }
- }
-
- while (to_erase.size()) {
- physics_2d_mouseover.erase(to_erase.front()->get());
- to_erase.pop_front();
- }
+ _cleanup_mouseover_colliders(false, false, frame);
}
}
@@ -755,8 +731,8 @@ void Viewport::_process_picking() {
if (physics_object_capture.is_valid()) {
CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_capture));
- if (co && camera) {
- _collision_object_input_event(co, camera, ev, Vector3(), Vector3(), 0);
+ if (co && camera_3d) {
+ _collision_object_input_event(co, camera_3d, ev, Vector3(), Vector3(), 0);
captured = true;
if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
physics_object_capture = ObjectID();
@@ -773,16 +749,16 @@ void Viewport::_process_picking() {
if (last_id.is_valid()) {
if (ObjectDB::get_instance(last_id) && last_object) {
//good, exists
- _collision_object_input_event(last_object, camera, ev, result.position, result.normal, result.shape);
+ _collision_object_input_event(last_object, camera_3d, ev, result.position, result.normal, result.shape);
if (last_object->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
physics_object_capture = last_id;
}
}
}
} else {
- if (camera) {
- Vector3 from = camera->project_ray_origin(pos);
- Vector3 dir = camera->project_ray_normal(pos);
+ if (camera_3d) {
+ Vector3 from = camera_3d->project_ray_origin(pos);
+ Vector3 dir = camera_3d->project_ray_normal(pos);
PhysicsDirectSpaceState3D *space = PhysicsServer3D::get_singleton()->space_get_direct_state(find_world_3d()->get_space());
if (space) {
@@ -790,8 +766,8 @@ void Viewport::_process_picking() {
ObjectID new_collider;
if (col) {
CollisionObject3D *co = Object::cast_to<CollisionObject3D>(result.collider);
- if (co && co->can_process()) {
- _collision_object_input_event(co, camera, ev, result.position, result.normal, result.shape);
+ if (co) {
+ _collision_object_input_event(co, camera_3d, ev, result.position, result.normal, result.shape);
last_object = co;
last_id = result.collider_id;
new_collider = last_id;
@@ -859,7 +835,7 @@ void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override,
update_canvas_items();
- emit_signal("size_changed");
+ emit_signal(SNAME("size_changed"));
}
Size2i Viewport::_get_size() const {
@@ -1045,64 +1021,68 @@ void Viewport::_listener_make_next_current(Listener3D *p_exclude) {
}
} else {
// Attempt to reset listener to the camera position
- if (camera != nullptr) {
+ if (camera_3d != nullptr) {
_update_listener();
- _camera_transform_changed_notify();
+ _camera_3d_transform_changed_notify();
}
}
}
#endif
-void Viewport::_camera_transform_changed_notify() {
+void Viewport::_camera_3d_transform_changed_notify() {
#ifndef _3D_DISABLED
#endif
}
-void Viewport::_camera_set(Camera3D *p_camera) {
+void Viewport::_camera_3d_set(Camera3D *p_camera) {
#ifndef _3D_DISABLED
- if (camera == p_camera) {
+ if (camera_3d == p_camera) {
return;
}
- if (camera) {
- camera->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
+ if (camera_3d) {
+ camera_3d->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
}
- camera = p_camera;
+ camera_3d = p_camera;
if (!camera_override) {
- if (camera) {
- RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera());
+ if (camera_3d) {
+ RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera_3d->get_camera());
} else {
RenderingServer::get_singleton()->viewport_attach_camera(viewport, RID());
}
}
- if (camera) {
- camera->notification(Camera3D::NOTIFICATION_BECAME_CURRENT);
+ if (camera_3d) {
+ camera_3d->notification(Camera3D::NOTIFICATION_BECAME_CURRENT);
}
_update_listener();
- _camera_transform_changed_notify();
+ _camera_3d_transform_changed_notify();
#endif
}
-bool Viewport::_camera_add(Camera3D *p_camera) {
+void Viewport::_camera_2d_set(Camera2D *p_camera_2d) {
+ camera_2d = p_camera_2d;
+}
+
+bool Viewport::_camera_3d_add(Camera3D *p_camera) {
cameras.insert(p_camera);
return cameras.size() == 1;
}
-void Viewport::_camera_remove(Camera3D *p_camera) {
+void Viewport::_camera_3d_remove(Camera3D *p_camera) {
cameras.erase(p_camera);
- if (camera == p_camera) {
- camera->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
- camera = nullptr;
+ if (camera_3d == p_camera) {
+ camera_3d->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
+ camera_3d = nullptr;
}
}
#ifndef _3D_DISABLED
-void Viewport::_camera_make_next_current(Camera3D *p_exclude) {
+void Viewport::_camera_3d_make_next_current(Camera3D *p_exclude) {
for (Set<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) {
if (p_exclude == E->get()) {
continue;
@@ -1110,7 +1090,7 @@ void Viewport::_camera_make_next_current(Camera3D *p_exclude) {
if (!E->get()->is_inside_tree()) {
continue;
}
- if (camera != nullptr) {
+ if (camera_3d != nullptr) {
return;
}
@@ -1299,8 +1279,12 @@ Listener3D *Viewport::get_listener() const {
return listener;
}
-Camera3D *Viewport::get_camera() const {
- return camera;
+Camera3D *Viewport::get_camera_3d() const {
+ return camera_3d;
+}
+
+Camera2D *Viewport::get_camera_2d() const {
+ return camera_2d;
}
void Viewport::enable_camera_override(bool p_enable) {
@@ -1318,8 +1302,8 @@ void Viewport::enable_camera_override(bool p_enable) {
if (p_enable) {
RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera_override.rid);
- } else if (camera) {
- RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera());
+ } else if (camera_3d) {
+ RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera_3d->get_camera());
} else {
RenderingServer::get_singleton()->viewport_attach_camera(viewport, RID());
}
@@ -1493,7 +1477,10 @@ void Viewport::_gui_sort_roots() {
void Viewport::_gui_cancel_tooltip() {
gui.tooltip_control = nullptr;
- gui.tooltip_timer = -1;
+ if (gui.tooltip_timer.is_valid()) {
+ gui.tooltip_timer->release_connections();
+ gui.tooltip_timer = Ref<SceneTreeTimer>();
+ }
if (gui.tooltip_popup) {
gui.tooltip_popup->queue_delete();
gui.tooltip_popup = nullptr;
@@ -1562,6 +1549,9 @@ void Viewport::_gui_show_tooltip() {
return;
}
+ // Popup window which houses the tooltip content.
+ TooltipPanel *panel = memnew(TooltipPanel);
+
// Controls can implement `make_custom_tooltip` to provide their own tooltip.
// This should be a Control node which will be added as child to a TooltipPanel.
Control *base_tooltip = tooltip_owner->make_custom_tooltip(tooltip_text);
@@ -1571,11 +1561,11 @@ void Viewport::_gui_show_tooltip() {
gui.tooltip_label = memnew(TooltipLabel);
gui.tooltip_label->set_text(tooltip_text);
base_tooltip = gui.tooltip_label;
+ panel->connect("mouse_entered", callable_mp(this, &Viewport::_gui_cancel_tooltip));
}
base_tooltip->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
- TooltipPanel *panel = memnew(TooltipPanel);
panel->set_transient(false);
panel->set_flag(Window::FLAG_NO_FOCUS, true);
panel->set_wrap_controls(true);
@@ -1710,7 +1700,7 @@ void Viewport::_gui_call_notification(Control *p_control, int p_what) {
//_unblock();
}
-Control *Viewport::_gui_find_control(const Point2 &p_global) {
+Control *Viewport::gui_find_control(const Point2 &p_global) {
//aca va subwindows
_gui_sort_roots();
@@ -1850,7 +1840,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
parent_xform=data.parent_canvas_item->get_global_transform();
*/
- gui.mouse_focus = _gui_find_control(pos);
+ gui.mouse_focus = gui_find_control(pos);
gui.last_mouse_focus = gui.mouse_focus;
if (!gui.mouse_focus) {
@@ -1991,7 +1981,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (gui.mouse_focus) {
over = gui.mouse_focus;
} else {
- over = _gui_find_control(mpos);
+ over = gui_find_control(mpos);
}
if (gui.mouse_focus_mask == 0 && over != gui.mouse_over) {
@@ -2074,7 +2064,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (gui.mouse_focus) {
over = gui.mouse_focus;
} else {
- over = _gui_find_control(mpos);
+ over = gui_find_control(mpos);
}
if (over != gui.mouse_over) {
@@ -2139,9 +2129,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
if (can_tooltip && !is_tooltip_shown) {
+ if (gui.tooltip_timer.is_valid()) {
+ gui.tooltip_timer->release_connections();
+ gui.tooltip_timer = Ref<SceneTreeTimer>();
+ }
gui.tooltip_control = over;
gui.tooltip_pos = over->get_screen_transform().xform(pos);
- gui.tooltip_timer = gui.tooltip_delay;
+ gui.tooltip_timer = get_tree()->create_timer(gui.tooltip_delay);
+ gui.tooltip_timer->set_ignore_time_scale(true);
+ gui.tooltip_timer->connect("timeout", callable_mp(this, &Viewport::_gui_show_tooltip));
}
}
@@ -2223,7 +2219,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Window *sw = embedder->gui.sub_windows[i].window;
Rect2 swrect = Rect2i(sw->get_position(), sw->get_size());
if (!sw->get_flag(Window::FLAG_BORDERLESS)) {
- int title_height = sw->get_theme_constant("title_height");
+ int title_height = sw->get_theme_constant(SNAME("title_height"));
swrect.position.y -= title_height;
swrect.size.y += title_height;
}
@@ -2261,7 +2257,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Transform2D ai = (viewport_under->get_final_transform().affine_inverse() * viewport_under->_get_input_pre_xform());
viewport_pos = ai.xform(viewport_pos);
//find control under at pos
- gui.drag_mouse_over = viewport_under->_gui_find_control(viewport_pos);
+ gui.drag_mouse_over = viewport_under->gui_find_control(viewport_pos);
if (gui.drag_mouse_over) {
Transform2D localizer = gui.drag_mouse_over->get_global_transform_with_canvas().affine_inverse();
gui.drag_mouse_over_pos = localizer.xform(viewport_pos);
@@ -2289,7 +2285,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (touch_event.is_valid()) {
Size2 pos = touch_event->get_position();
if (touch_event->is_pressed()) {
- Control *over = _gui_find_control(pos);
+ Control *over = gui_find_control(pos);
if (over) {
if (over->can_process()) {
touch_event = touch_event->xformed_by(Transform2D()); //make a copy
@@ -2324,7 +2320,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Size2 pos = gesture_event->get_position();
- Control *over = _gui_find_control(pos);
+ Control *over = gui_find_control(pos);
if (over) {
if (over->can_process()) {
gesture_event = gesture_event->xformed_by(Transform2D()); //make a copy
@@ -2345,7 +2341,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (drag_event.is_valid()) {
Control *over = gui.mouse_focus;
if (!over) {
- over = _gui_find_control(drag_event->get_position());
+ over = gui_find_control(drag_event->get_position());
}
if (over) {
if (over->can_process()) {
@@ -2572,7 +2568,7 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
}
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus_for_window", (Node *)get_base_window());
gui.key_focus = p_control;
- emit_signal("gui_focus_changed", p_control);
+ emit_signal(SNAME("gui_focus_changed"), p_control);
p_control->notification(Control::NOTIFICATION_FOCUS_ENTER);
p_control->update();
}
@@ -2607,20 +2603,41 @@ void Viewport::_drop_mouse_focus() {
void Viewport::_drop_physics_mouseover(bool p_paused_only) {
physics_has_last_mousepos = false;
+ _cleanup_mouseover_colliders(true, p_paused_only);
+
+#ifndef _3D_DISABLED
+ if (physics_object_over.is_valid()) {
+ CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over));
+ if (co) {
+ if (!(p_paused_only && co->can_process())) {
+ co->_mouse_exit();
+ physics_object_over = ObjectID();
+ physics_object_capture = ObjectID();
+ }
+ }
+ }
+#endif
+}
+
+void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference) {
List<Map<ObjectID, uint64_t>::Element *> to_erase;
for (Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.front(); E; E = E->next()) {
+ if (!p_clean_all_frames && E->get() == p_frame_reference) {
+ continue;
+ }
+
Object *o = ObjectDB::get_instance(E->key());
if (o) {
CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
if (co) {
- if (p_paused_only && co->can_process()) {
+ if (p_clean_all_frames && p_paused_only && co->can_process()) {
continue;
}
co->_mouse_exit();
- to_erase.push_back(E);
}
}
+ to_erase.push_back(E);
}
while (to_erase.size()) {
@@ -2628,18 +2645,31 @@ void Viewport::_drop_physics_mouseover(bool p_paused_only) {
to_erase.pop_front();
}
-#ifndef _3D_DISABLED
- if (physics_object_over.is_valid()) {
- CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over));
- if (co) {
- if (!(p_paused_only && co->can_process())) {
- co->_mouse_exit();
- physics_object_over = ObjectID();
- physics_object_capture = ObjectID();
+ // Per-shape
+ List<Map<Pair<ObjectID, int>, uint64_t, PairSort<ObjectID, int>>::Element *> shapes_to_erase;
+
+ for (Map<Pair<ObjectID, int>, uint64_t, PairSort<ObjectID, int>>::Element *E = physics_2d_shape_mouseover.front(); E; E = E->next()) {
+ if (!p_clean_all_frames && E->get() == p_frame_reference) {
+ continue;
+ }
+
+ Object *o = ObjectDB::get_instance(E->key().first);
+ if (o) {
+ CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
+ if (co) {
+ if (p_clean_all_frames && p_paused_only && co->can_process()) {
+ continue;
+ }
+ co->_mouse_shape_exit(E->key().second);
}
}
+ shapes_to_erase.push_back(E);
+ }
+
+ while (shapes_to_erase.size()) {
+ physics_2d_shape_mouseover.erase(shapes_to_erase.front()->get());
+ shapes_to_erase.pop_front();
}
-#endif
}
Control *Viewport::_gui_get_focus_owner() {
@@ -2648,7 +2678,7 @@ Control *Viewport::_gui_get_focus_owner() {
void Viewport::_gui_grab_click_focus(Control *p_control) {
gui.mouse_click_grabber = p_control;
- call_deferred("_post_gui_grab_click_focus");
+ call_deferred(SNAME("_post_gui_grab_click_focus"));
}
void Viewport::_post_gui_grab_click_focus() {
@@ -2721,7 +2751,7 @@ Viewport::SubWindowResize Viewport::_sub_window_get_resize_margin(Window *p_subw
Rect2i r = Rect2i(p_subwindow->get_position(), p_subwindow->get_size());
- int title_height = p_subwindow->get_theme_constant("title_height");
+ int title_height = p_subwindow->get_theme_constant(SNAME("title_height"));
r.position.y -= title_height;
r.size.y += title_height;
@@ -2733,7 +2763,7 @@ Viewport::SubWindowResize Viewport::_sub_window_get_resize_margin(Window *p_subw
int dist_x = p_point.x < r.position.x ? (p_point.x - r.position.x) : (p_point.x > (r.position.x + r.size.x) ? (p_point.x - (r.position.x + r.size.x)) : 0);
int dist_y = p_point.y < r.position.y ? (p_point.y - r.position.y) : (p_point.y > (r.position.y + r.size.y) ? (p_point.y - (r.position.y + r.size.y)) : 0);
- int limit = p_subwindow->get_theme_constant("resize_margin");
+ int limit = p_subwindow->get_theme_constant(SNAME("resize_margin"));
if (ABS(dist_x) > limit) {
return SUB_WINDOW_RESIZE_DISABLED;
@@ -2815,7 +2845,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
new_rect.position.x = 0;
}
- int title_height = gui.subwindow_focused->get_flag(Window::FLAG_BORDERLESS) ? 0 : gui.subwindow_focused->get_theme_constant("title_height");
+ int title_height = gui.subwindow_focused->get_flag(Window::FLAG_BORDERLESS) ? 0 : gui.subwindow_focused->get_theme_constant(SNAME("title_height"));
if (new_rect.position.y < title_height) {
new_rect.position.y = title_height;
@@ -2919,7 +2949,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
if (!sw.window->get_flag(Window::FLAG_BORDERLESS)) {
//check top bar
- int title_height = sw.window->get_theme_constant("title_height");
+ int title_height = sw.window->get_theme_constant(SNAME("title_height"));
Rect2i title_bar = r;
title_bar.position.y -= title_height;
title_bar.size.y = title_height;
@@ -2927,9 +2957,9 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
if (title_bar.has_point(mb->get_position())) {
click_on_window = true;
- int close_h_ofs = sw.window->get_theme_constant("close_h_ofs");
- int close_v_ofs = sw.window->get_theme_constant("close_v_ofs");
- Ref<Texture2D> close_icon = sw.window->get_theme_icon("close");
+ int close_h_ofs = sw.window->get_theme_constant(SNAME("close_h_ofs"));
+ int close_v_ofs = sw.window->get_theme_constant(SNAME("close_v_ofs"));
+ Ref<Texture2D> close_icon = sw.window->get_theme_icon(SNAME("close"));
Rect2 close_rect;
close_rect.position = Vector2(r.position.x + r.size.x - close_v_ofs, r.position.y - close_h_ofs);
@@ -3147,8 +3177,13 @@ bool Viewport::is_using_own_world_3d() const {
void Viewport::set_physics_object_picking(bool p_enable) {
physics_object_picking = p_enable;
- if (!physics_object_picking) {
+ if (physics_object_picking) {
+ add_to_group("_picking_viewports");
+ } else {
physics_picking_events.clear();
+ if (is_in_group("_picking_viewports")) {
+ remove_from_group("_picking_viewports");
+ }
}
}
@@ -3517,7 +3552,8 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_use_own_world_3d", "enable"), &Viewport::set_use_own_world_3d);
ClassDB::bind_method(D_METHOD("is_using_own_world_3d"), &Viewport::is_using_own_world_3d);
- ClassDB::bind_method(D_METHOD("get_camera"), &Viewport::get_camera);
+ ClassDB::bind_method(D_METHOD("get_camera_3d"), &Viewport::get_camera_3d);
+ ClassDB::bind_method(D_METHOD("get_camera_2d"), &Viewport::get_camera_2d);
ClassDB::bind_method(D_METHOD("set_as_audio_listener", "enable"), &Viewport::set_as_audio_listener);
ClassDB::bind_method(D_METHOD("is_audio_listener"), &Viewport::is_audio_listener);
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 0f3bb8707d..b5c49a8a97 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -32,6 +32,7 @@
#define VIEWPORT_H
#include "core/math/transform_2d.h"
+#include "core/templates/pair.h"
#include "scene/main/node.h"
#include "scene/resources/texture.h"
#include "scene/resources/world_2d.h"
@@ -49,6 +50,7 @@ class Label;
class Timer;
class Viewport;
class CollisionObject3D;
+class SceneTreeTimer;
class ViewportTexture : public Texture2D {
GDCLASS(ViewportTexture, Texture2D);
@@ -213,7 +215,8 @@ private:
}
} camera_override;
- Camera3D *camera = nullptr;
+ Camera3D *camera_3d = nullptr;
+ Camera2D *camera_2d = nullptr;
Set<Camera3D *> cameras;
Set<CanvasLayer *> canvas_layers;
@@ -261,7 +264,7 @@ private:
Transform3D physics_last_camera_transform;
ObjectID physics_last_id;
bool physics_has_last_mousepos = false;
- Vector2 physics_last_mousepos = Vector2(Math_INF, Math_INF);
+ Vector2 physics_last_mousepos = Vector2(INFINITY, INFINITY);
struct {
bool alt = false;
bool control = false;
@@ -276,7 +279,12 @@ private:
bool handle_input_locally = true;
bool local_input_handled = false;
+ // Collider to frame
Map<ObjectID, uint64_t> physics_2d_mouseover;
+ // Collider & shape to frame
+ Map<Pair<ObjectID, int>, uint64_t, PairSort<ObjectID, int>> physics_2d_shape_mouseover;
+ // Cleans up colliders corresponding to old frames or all of them.
+ void _cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference = 0);
Ref<World2D> world_2d;
Ref<World3D> world_3d;
@@ -366,7 +374,7 @@ private:
bool drag_attempted = false;
Variant drag_data;
ObjectID drag_preview_id;
- float tooltip_timer = -1.0;
+ Ref<SceneTreeTimer> tooltip_timer;
float tooltip_delay = 0.0;
Transform2D focus_inv_xform;
bool roots_order_dirty = false;
@@ -397,7 +405,6 @@ private:
void _gui_call_notification(Control *p_control, int p_what);
void _gui_sort_roots();
- Control *_gui_find_control(const Point2 &p_global);
Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform);
void _gui_input_event(Ref<InputEvent> p_event);
@@ -444,11 +451,14 @@ private:
void _listener_make_next_current(Listener3D *p_exclude);
friend class Camera3D;
- void _camera_transform_changed_notify();
- void _camera_set(Camera3D *p_camera);
- bool _camera_add(Camera3D *p_camera); //true if first
- void _camera_remove(Camera3D *p_camera);
- void _camera_make_next_current(Camera3D *p_exclude);
+ void _camera_3d_transform_changed_notify();
+ void _camera_3d_set(Camera3D *p_camera);
+ bool _camera_3d_add(Camera3D *p_camera); //true if first
+ void _camera_3d_remove(Camera3D *p_camera);
+ void _camera_3d_make_next_current(Camera3D *p_exclude);
+
+ friend class Camera2D;
+ void _camera_2d_set(Camera2D *p_camera_2d);
friend class CanvasLayer;
void _canvas_layer_add(CanvasLayer *p_canvas_layer);
@@ -491,7 +501,8 @@ public:
uint64_t get_processed_events_count() const { return event_count; }
Listener3D *get_listener() const;
- Camera3D *get_camera() const;
+ Camera3D *get_camera_3d() const;
+ Camera2D *get_camera_2d() const;
void enable_camera_override(bool p_enable);
bool is_camera_override_enabled() const;
@@ -618,6 +629,8 @@ public:
bool gui_is_dragging() const;
+ Control *gui_find_control(const Point2 &p_global);
+
void set_sdf_oversize(SDFOversize p_sdf_oversize);
SDFOversize get_sdf_oversize() const;
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 9299f8d6be..ab1846660b 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -115,7 +115,7 @@ Size2i Window::get_max_size() const {
void Window::set_min_size(const Size2i &p_min_size) {
min_size = p_min_size;
- if (window_id != DisplayServer::INVALID_WINDOW_ID) {
+ if (!wrap_controls && window_id != DisplayServer::INVALID_WINDOW_ID) {
DisplayServer::get_singleton()->window_set_min_size(min_size, window_id);
}
_update_window_size();
@@ -313,39 +313,39 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
switch (p_event) {
case DisplayServer::WINDOW_EVENT_MOUSE_ENTER: {
_propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER);
- emit_signal("mouse_entered");
+ emit_signal(SNAME("mouse_entered"));
DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CURSOR_ARROW); //restore cursor shape
} break;
case DisplayServer::WINDOW_EVENT_MOUSE_EXIT: {
_propagate_window_notification(this, NOTIFICATION_WM_MOUSE_EXIT);
- emit_signal("mouse_exited");
+ emit_signal(SNAME("mouse_exited"));
} break;
case DisplayServer::WINDOW_EVENT_FOCUS_IN: {
focused = true;
_propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_IN);
- emit_signal("focus_entered");
+ emit_signal(SNAME("focus_entered"));
} break;
case DisplayServer::WINDOW_EVENT_FOCUS_OUT: {
focused = false;
_propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_OUT);
- emit_signal("focus_exited");
+ emit_signal(SNAME("focus_exited"));
} break;
case DisplayServer::WINDOW_EVENT_CLOSE_REQUEST: {
if (exclusive_child != nullptr) {
break; //has an exclusive child, can't get events until child is closed
}
_propagate_window_notification(this, NOTIFICATION_WM_CLOSE_REQUEST);
- emit_signal("close_requested");
+ emit_signal(SNAME("close_requested"));
} break;
case DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST: {
_propagate_window_notification(this, NOTIFICATION_WM_GO_BACK_REQUEST);
- emit_signal("go_back_requested");
+ emit_signal(SNAME("go_back_requested"));
} break;
case DisplayServer::WINDOW_EVENT_DPI_CHANGE: {
_update_viewport_size();
_propagate_window_notification(this, NOTIFICATION_WM_DPI_CHANGE);
- emit_signal("dpi_changed");
+ emit_signal(SNAME("dpi_changed"));
} break;
}
}
@@ -542,6 +542,7 @@ void Window::_update_window_size() {
embedder->_sub_window_update(this);
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
DisplayServer::get_singleton()->window_set_size(size, window_id);
+ DisplayServer::get_singleton()->window_set_min_size(size_limit, window_id);
}
//update the viewport
@@ -881,7 +882,7 @@ void Window::child_controls_changed() {
}
updating_child_controls = true;
- call_deferred("_update_child_controls");
+ call_deferred(SNAME("_update_child_controls"));
}
bool Window::_can_consume_input_events() const {
@@ -924,7 +925,7 @@ void Window::_window_input_text(const String &p_text) {
}
void Window::_window_drop_files(const Vector<String> &p_files) {
- emit_signal("files_dropped", p_files, current_screen);
+ emit_signal(SNAME("files_dropped"), p_files, current_screen);
}
Viewport *Window::get_parent_viewport() const {
@@ -1042,7 +1043,7 @@ void Window::popup_centered_ratio(float p_ratio) {
}
void Window::popup(const Rect2i &p_screen_rect) {
- emit_signal("about_to_popup");
+ emit_signal(SNAME("about_to_popup"));
// Update window size to calculate the actual window size based on contents minimum size and minimum size.
_update_window_size();
@@ -1170,23 +1171,24 @@ Ref<Theme> Window::get_theme() const {
return theme;
}
-void Window::set_theme_custom_type(const StringName &p_theme_type) {
- theme_custom_type = p_theme_type;
+void Window::set_theme_type_variation(const StringName &p_theme_type) {
+ theme_type_variation = p_theme_type;
Control::_propagate_theme_changed(this, theme_owner, theme_owner_window);
}
-StringName Window::get_theme_custom_type() const {
- return theme_custom_type;
+StringName Window::get_theme_type_variation() const {
+ return theme_type_variation;
}
void Window::_get_theme_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) const {
- if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_custom_type) {
- if (theme_custom_type != StringName()) {
- p_list->push_back(theme_custom_type);
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ if (Theme::get_project_default().is_valid() && Theme::get_project_default()->get_type_variation_base(theme_type_variation) != StringName()) {
+ Theme::get_project_default()->get_type_dependencies(get_class_name(), theme_type_variation, p_list);
+ } else {
+ Theme::get_default()->get_type_dependencies(get_class_name(), theme_type_variation, p_list);
}
- Theme::get_type_dependencies(get_class_name(), p_list);
} else {
- Theme::get_type_dependencies(p_theme_type, p_list);
+ Theme::get_default()->get_type_dependencies(p_theme_type, StringName(), p_list);
}
}
@@ -1323,14 +1325,14 @@ bool Window::is_layout_rtl() const {
if (parent) {
return parent->is_layout_rtl();
} else {
- if (GLOBAL_GET("internationalization/rendering/force_right_to_left_layout_direction")) {
+ if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
return true;
}
String locale = TranslationServer::get_singleton()->get_tool_locale();
return TS->is_locale_right_to_left(locale);
}
} else if (layout_dir == LAYOUT_DIRECTION_LOCALE) {
- if (GLOBAL_GET("internationalization/rendering/force_right_to_left_layout_direction")) {
+ if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
return true;
}
String locale = TranslationServer::get_singleton()->get_tool_locale();
@@ -1340,6 +1342,34 @@ bool Window::is_layout_rtl() const {
}
}
+void Window::_validate_property(PropertyInfo &property) const {
+ if (property.name == "theme_type_variation") {
+ List<StringName> names;
+
+ // Only the default theme and the project theme are used for the list of options.
+ // This is an imposed limitation to simplify the logic needed to leverage those options.
+ Theme::get_default()->get_type_variation_list(get_class_name(), &names);
+ if (Theme::get_project_default().is_valid()) {
+ Theme::get_project_default()->get_type_variation_list(get_class_name(), &names);
+ }
+ names.sort_custom<StringName::AlphCompare>();
+
+ Vector<StringName> unique_names;
+ String hint_string;
+ for (const StringName &E : names) {
+ // Skip duplicate values.
+ if (unique_names.has(E)) {
+ continue;
+ }
+
+ hint_string += String(E) + ",";
+ unique_names.append(E);
+ }
+
+ property.hint_string = hint_string;
+ }
+}
+
void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &Window::get_title);
@@ -1417,8 +1447,8 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Window::set_theme);
ClassDB::bind_method(D_METHOD("get_theme"), &Window::get_theme);
- ClassDB::bind_method(D_METHOD("set_theme_custom_type", "theme_type"), &Window::set_theme_custom_type);
- ClassDB::bind_method(D_METHOD("get_theme_custom_type"), &Window::get_theme_custom_type);
+ ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Window::set_theme_type_variation);
+ ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Window::get_theme_type_variation);
ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "theme_type"), &Window::get_theme_icon, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "theme_type"), &Window::get_theme_stylebox, DEFVAL(""));
@@ -1468,7 +1498,7 @@ void Window::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,Keep Width,Keep Height,Expand"), "set_content_scale_aspect", "get_content_scale_aspect");
ADD_GROUP("Theme", "theme_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
- ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_custom_type"), "set_theme_custom_type", "get_theme_custom_type");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
ADD_SIGNAL(MethodInfo("window_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files")));
diff --git a/scene/main/window.h b/scene/main/window.h
index 494c386606..e92b5e22ed 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -130,7 +130,7 @@ private:
Ref<Theme> theme;
Control *theme_owner = nullptr;
Window *theme_owner_window = nullptr;
- StringName theme_custom_type;
+ StringName theme_type_variation;
Viewport *embedder = nullptr;
@@ -151,6 +151,7 @@ protected:
virtual Size2 _get_contents_minimum_size() const;
static void _bind_methods();
void _notification(int p_what);
+ virtual void _validate_property(PropertyInfo &property) const override;
virtual void add_child_notify(Node *p_child) override;
virtual void remove_child_notify(Node *p_child) override;
@@ -242,8 +243,8 @@ public:
void set_theme(const Ref<Theme> &p_theme);
Ref<Theme> get_theme() const;
- void set_theme_custom_type(const StringName &p_theme_type);
- StringName get_theme_custom_type() const;
+ void set_theme_type_variation(const StringName &p_theme_type);
+ StringName get_theme_type_variation() const;
_FORCE_INLINE_ void _get_theme_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) const;
Size2 get_contents_minimum_size() const;
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index a768754f11..8ede8e9a0b 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -292,108 +292,108 @@ void register_scene_types() {
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_class<Object>();
+ GDREGISTER_CLASS(Object);
- ClassDB::register_class<Node>();
- ClassDB::register_virtual_class<InstancePlaceholder>();
+ GDREGISTER_CLASS(Node);
+ GDREGISTER_VIRTUAL_CLASS(InstancePlaceholder);
- ClassDB::register_virtual_class<Viewport>();
- ClassDB::register_class<SubViewport>();
- ClassDB::register_class<ViewportTexture>();
- ClassDB::register_class<HTTPRequest>();
- ClassDB::register_class<Timer>();
- ClassDB::register_class<CanvasLayer>();
- ClassDB::register_class<CanvasModulate>();
- ClassDB::register_class<ResourcePreloader>();
- ClassDB::register_class<Window>();
+ GDREGISTER_VIRTUAL_CLASS(Viewport);
+ GDREGISTER_CLASS(SubViewport);
+ GDREGISTER_CLASS(ViewportTexture);
+ GDREGISTER_CLASS(HTTPRequest);
+ GDREGISTER_CLASS(Timer);
+ GDREGISTER_CLASS(CanvasLayer);
+ GDREGISTER_CLASS(CanvasModulate);
+ GDREGISTER_CLASS(ResourcePreloader);
+ GDREGISTER_CLASS(Window);
/* REGISTER GUI */
- ClassDB::register_class<ButtonGroup>();
- ClassDB::register_virtual_class<BaseButton>();
+ GDREGISTER_CLASS(ButtonGroup);
+ GDREGISTER_VIRTUAL_CLASS(BaseButton);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_class<Shortcut>();
- ClassDB::register_class<Control>();
- ClassDB::register_class<Button>();
- ClassDB::register_class<Label>();
- ClassDB::register_virtual_class<ScrollBar>();
- ClassDB::register_class<HScrollBar>();
- ClassDB::register_class<VScrollBar>();
- ClassDB::register_class<ProgressBar>();
- ClassDB::register_virtual_class<Slider>();
- ClassDB::register_class<HSlider>();
- ClassDB::register_class<VSlider>();
- ClassDB::register_class<Popup>();
- ClassDB::register_class<PopupPanel>();
- ClassDB::register_class<MenuButton>();
- ClassDB::register_class<CheckBox>();
- ClassDB::register_class<CheckButton>();
- ClassDB::register_class<LinkButton>();
- ClassDB::register_class<Panel>();
- ClassDB::register_virtual_class<Range>();
+ GDREGISTER_CLASS(Shortcut);
+ GDREGISTER_CLASS(Control);
+ GDREGISTER_CLASS(Button);
+ GDREGISTER_CLASS(Label);
+ GDREGISTER_VIRTUAL_CLASS(ScrollBar);
+ GDREGISTER_CLASS(HScrollBar);
+ GDREGISTER_CLASS(VScrollBar);
+ GDREGISTER_CLASS(ProgressBar);
+ GDREGISTER_VIRTUAL_CLASS(Slider);
+ GDREGISTER_CLASS(HSlider);
+ GDREGISTER_CLASS(VSlider);
+ GDREGISTER_CLASS(Popup);
+ GDREGISTER_CLASS(PopupPanel);
+ GDREGISTER_CLASS(MenuButton);
+ GDREGISTER_CLASS(CheckBox);
+ GDREGISTER_CLASS(CheckButton);
+ GDREGISTER_CLASS(LinkButton);
+ GDREGISTER_CLASS(Panel);
+ GDREGISTER_VIRTUAL_CLASS(Range);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_class<TextureRect>();
- ClassDB::register_class<ColorRect>();
- ClassDB::register_class<NinePatchRect>();
- ClassDB::register_class<ReferenceRect>();
- ClassDB::register_class<AspectRatioContainer>();
- ClassDB::register_class<TabContainer>();
- ClassDB::register_class<Tabs>();
- ClassDB::register_virtual_class<Separator>();
- ClassDB::register_class<HSeparator>();
- ClassDB::register_class<VSeparator>();
- ClassDB::register_class<TextureButton>();
- ClassDB::register_class<Container>();
- ClassDB::register_virtual_class<BoxContainer>();
- ClassDB::register_class<HBoxContainer>();
- ClassDB::register_class<VBoxContainer>();
- ClassDB::register_class<GridContainer>();
- ClassDB::register_class<CenterContainer>();
- ClassDB::register_class<ScrollContainer>();
- ClassDB::register_class<PanelContainer>();
+ GDREGISTER_CLASS(TextureRect);
+ GDREGISTER_CLASS(ColorRect);
+ GDREGISTER_CLASS(NinePatchRect);
+ GDREGISTER_CLASS(ReferenceRect);
+ GDREGISTER_CLASS(AspectRatioContainer);
+ GDREGISTER_CLASS(TabContainer);
+ GDREGISTER_CLASS(Tabs);
+ GDREGISTER_VIRTUAL_CLASS(Separator);
+ GDREGISTER_CLASS(HSeparator);
+ GDREGISTER_CLASS(VSeparator);
+ GDREGISTER_CLASS(TextureButton);
+ GDREGISTER_CLASS(Container);
+ GDREGISTER_VIRTUAL_CLASS(BoxContainer);
+ GDREGISTER_CLASS(HBoxContainer);
+ GDREGISTER_CLASS(VBoxContainer);
+ GDREGISTER_CLASS(GridContainer);
+ GDREGISTER_CLASS(CenterContainer);
+ GDREGISTER_CLASS(ScrollContainer);
+ GDREGISTER_CLASS(PanelContainer);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_class<TextureProgressBar>();
- ClassDB::register_class<ItemList>();
+ GDREGISTER_CLASS(TextureProgressBar);
+ GDREGISTER_CLASS(ItemList);
- ClassDB::register_class<LineEdit>();
- ClassDB::register_class<VideoPlayer>();
+ GDREGISTER_CLASS(LineEdit);
+ GDREGISTER_CLASS(VideoPlayer);
#ifndef ADVANCED_GUI_DISABLED
- ClassDB::register_class<FileDialog>();
-
- ClassDB::register_class<PopupMenu>();
- ClassDB::register_class<Tree>();
-
- ClassDB::register_class<TextEdit>();
- ClassDB::register_class<CodeEdit>();
- ClassDB::register_class<SyntaxHighlighter>();
- ClassDB::register_class<CodeHighlighter>();
-
- ClassDB::register_virtual_class<TreeItem>();
- ClassDB::register_class<OptionButton>();
- ClassDB::register_class<SpinBox>();
- ClassDB::register_class<ColorPicker>();
- ClassDB::register_class<ColorPickerButton>();
- ClassDB::register_class<RichTextLabel>();
- ClassDB::register_class<RichTextEffect>();
- ClassDB::register_class<CharFXTransform>();
-
- ClassDB::register_class<AcceptDialog>();
- ClassDB::register_class<ConfirmationDialog>();
-
- ClassDB::register_class<MarginContainer>();
- ClassDB::register_class<SubViewportContainer>();
- ClassDB::register_virtual_class<SplitContainer>();
- ClassDB::register_class<HSplitContainer>();
- ClassDB::register_class<VSplitContainer>();
- ClassDB::register_class<GraphNode>();
- ClassDB::register_class<GraphEdit>();
+ GDREGISTER_CLASS(FileDialog);
+
+ GDREGISTER_CLASS(PopupMenu);
+ GDREGISTER_CLASS(Tree);
+
+ GDREGISTER_CLASS(TextEdit);
+ GDREGISTER_CLASS(CodeEdit);
+ GDREGISTER_CLASS(SyntaxHighlighter);
+ GDREGISTER_CLASS(CodeHighlighter);
+
+ GDREGISTER_VIRTUAL_CLASS(TreeItem);
+ GDREGISTER_CLASS(OptionButton);
+ GDREGISTER_CLASS(SpinBox);
+ GDREGISTER_CLASS(ColorPicker);
+ GDREGISTER_CLASS(ColorPickerButton);
+ GDREGISTER_CLASS(RichTextLabel);
+ GDREGISTER_CLASS(RichTextEffect);
+ GDREGISTER_CLASS(CharFXTransform);
+
+ GDREGISTER_CLASS(AcceptDialog);
+ GDREGISTER_CLASS(ConfirmationDialog);
+
+ GDREGISTER_CLASS(MarginContainer);
+ GDREGISTER_CLASS(SubViewportContainer);
+ GDREGISTER_VIRTUAL_CLASS(SplitContainer);
+ GDREGISTER_CLASS(HSplitContainer);
+ GDREGISTER_CLASS(VSplitContainer);
+ GDREGISTER_CLASS(GraphNode);
+ GDREGISTER_CLASS(GraphEdit);
OS::get_singleton()->yield(); //may take time to init
@@ -406,450 +406,451 @@ void register_scene_types() {
/* REGISTER ANIMATION */
- ClassDB::register_class<AnimationPlayer>();
- ClassDB::register_class<Tween>();
- ClassDB::register_virtual_class<Tweener>();
- ClassDB::register_class<PropertyTweener>();
- ClassDB::register_class<IntervalTweener>();
- ClassDB::register_class<CallbackTweener>();
- ClassDB::register_class<MethodTweener>();
-
- ClassDB::register_class<AnimationTree>();
- ClassDB::register_class<AnimationNode>();
- ClassDB::register_class<AnimationRootNode>();
- ClassDB::register_class<AnimationNodeBlendTree>();
- ClassDB::register_class<AnimationNodeBlendSpace1D>();
- ClassDB::register_class<AnimationNodeBlendSpace2D>();
- ClassDB::register_class<AnimationNodeStateMachine>();
- ClassDB::register_class<AnimationNodeStateMachinePlayback>();
-
- ClassDB::register_class<AnimationNodeStateMachineTransition>();
- ClassDB::register_class<AnimationNodeOutput>();
- ClassDB::register_class<AnimationNodeOneShot>();
- ClassDB::register_class<AnimationNodeAnimation>();
- ClassDB::register_class<AnimationNodeAdd2>();
- ClassDB::register_class<AnimationNodeAdd3>();
- ClassDB::register_class<AnimationNodeBlend2>();
- ClassDB::register_class<AnimationNodeBlend3>();
- ClassDB::register_class<AnimationNodeTimeScale>();
- ClassDB::register_class<AnimationNodeTimeSeek>();
- ClassDB::register_class<AnimationNodeTransition>();
-
- ClassDB::register_class<ShaderGlobalsOverride>(); //can be used in any shader
+ GDREGISTER_CLASS(AnimationPlayer);
+ GDREGISTER_CLASS(Tween);
+ GDREGISTER_VIRTUAL_CLASS(Tweener);
+ GDREGISTER_CLASS(PropertyTweener);
+ GDREGISTER_CLASS(IntervalTweener);
+ GDREGISTER_CLASS(CallbackTweener);
+ GDREGISTER_CLASS(MethodTweener);
+
+ GDREGISTER_CLASS(AnimationTree);
+ GDREGISTER_CLASS(AnimationNode);
+ GDREGISTER_CLASS(AnimationRootNode);
+ GDREGISTER_CLASS(AnimationNodeBlendTree);
+ GDREGISTER_CLASS(AnimationNodeBlendSpace1D);
+ GDREGISTER_CLASS(AnimationNodeBlendSpace2D);
+ GDREGISTER_CLASS(AnimationNodeStateMachine);
+ GDREGISTER_CLASS(AnimationNodeStateMachinePlayback);
+
+ GDREGISTER_CLASS(AnimationNodeStateMachineTransition);
+ GDREGISTER_CLASS(AnimationNodeOutput);
+ GDREGISTER_CLASS(AnimationNodeOneShot);
+ GDREGISTER_CLASS(AnimationNodeAnimation);
+ GDREGISTER_CLASS(AnimationNodeAdd2);
+ GDREGISTER_CLASS(AnimationNodeAdd3);
+ GDREGISTER_CLASS(AnimationNodeBlend2);
+ GDREGISTER_CLASS(AnimationNodeBlend3);
+ GDREGISTER_CLASS(AnimationNodeTimeScale);
+ GDREGISTER_CLASS(AnimationNodeTimeSeek);
+ GDREGISTER_CLASS(AnimationNodeTransition);
+
+ GDREGISTER_CLASS(ShaderGlobalsOverride); //can be used in any shader
OS::get_singleton()->yield(); //may take time to init
/* REGISTER 3D */
#ifndef _3D_DISABLED
- ClassDB::register_class<Node3D>();
- ClassDB::register_virtual_class<Node3DGizmo>();
- ClassDB::register_class<Skin>();
- ClassDB::register_virtual_class<SkinReference>();
- ClassDB::register_class<Skeleton3D>();
- ClassDB::register_virtual_class<VisualInstance3D>();
- ClassDB::register_virtual_class<GeometryInstance3D>();
- ClassDB::register_class<Camera3D>();
- ClassDB::register_class<ClippedCamera3D>();
- ClassDB::register_class<Listener3D>();
- ClassDB::register_class<XRCamera3D>();
- ClassDB::register_class<XRController3D>();
- ClassDB::register_class<XRAnchor3D>();
- ClassDB::register_class<XROrigin3D>();
- ClassDB::register_class<MeshInstance3D>();
- ClassDB::register_class<OccluderInstance3D>();
- ClassDB::register_class<Occluder3D>();
- ClassDB::register_virtual_class<SpriteBase3D>();
- ClassDB::register_class<Sprite3D>();
- ClassDB::register_class<AnimatedSprite3D>();
- ClassDB::register_virtual_class<Light3D>();
- ClassDB::register_class<DirectionalLight3D>();
- ClassDB::register_class<OmniLight3D>();
- ClassDB::register_class<SpotLight3D>();
- ClassDB::register_class<ReflectionProbe>();
- ClassDB::register_class<Decal>();
- ClassDB::register_class<VoxelGI>();
- ClassDB::register_class<VoxelGIData>();
- ClassDB::register_class<LightmapGI>();
- ClassDB::register_class<LightmapGIData>();
- ClassDB::register_class<LightmapProbe>();
- ClassDB::register_virtual_class<Lightmapper>();
- ClassDB::register_class<GPUParticles3D>();
- ClassDB::register_virtual_class<GPUParticlesCollision3D>();
- ClassDB::register_class<GPUParticlesCollisionBox>();
- ClassDB::register_class<GPUParticlesCollisionSphere>();
- ClassDB::register_class<GPUParticlesCollisionSDF>();
- ClassDB::register_class<GPUParticlesCollisionHeightField>();
- ClassDB::register_virtual_class<GPUParticlesAttractor3D>();
- ClassDB::register_class<GPUParticlesAttractorBox>();
- ClassDB::register_class<GPUParticlesAttractorSphere>();
- ClassDB::register_class<GPUParticlesAttractorVectorField>();
- ClassDB::register_class<CPUParticles3D>();
- ClassDB::register_class<Position3D>();
-
- ClassDB::register_class<RootMotionView>();
+ GDREGISTER_CLASS(Node3D);
+ GDREGISTER_VIRTUAL_CLASS(Node3DGizmo);
+ GDREGISTER_CLASS(Skin);
+ GDREGISTER_VIRTUAL_CLASS(SkinReference);
+ GDREGISTER_CLASS(Skeleton3D);
+ GDREGISTER_VIRTUAL_CLASS(VisualInstance3D);
+ GDREGISTER_VIRTUAL_CLASS(GeometryInstance3D);
+ GDREGISTER_CLASS(Camera3D);
+ GDREGISTER_CLASS(ClippedCamera3D);
+ GDREGISTER_CLASS(Listener3D);
+ GDREGISTER_CLASS(XRCamera3D);
+ GDREGISTER_CLASS(XRController3D);
+ GDREGISTER_CLASS(XRAnchor3D);
+ GDREGISTER_CLASS(XROrigin3D);
+ GDREGISTER_CLASS(MeshInstance3D);
+ GDREGISTER_CLASS(OccluderInstance3D);
+ GDREGISTER_CLASS(Occluder3D);
+ GDREGISTER_VIRTUAL_CLASS(SpriteBase3D);
+ GDREGISTER_CLASS(Sprite3D);
+ GDREGISTER_CLASS(AnimatedSprite3D);
+ GDREGISTER_VIRTUAL_CLASS(Light3D);
+ GDREGISTER_CLASS(DirectionalLight3D);
+ GDREGISTER_CLASS(OmniLight3D);
+ GDREGISTER_CLASS(SpotLight3D);
+ GDREGISTER_CLASS(ReflectionProbe);
+ GDREGISTER_CLASS(Decal);
+ GDREGISTER_CLASS(VoxelGI);
+ GDREGISTER_CLASS(VoxelGIData);
+ GDREGISTER_CLASS(LightmapGI);
+ GDREGISTER_CLASS(LightmapGIData);
+ GDREGISTER_CLASS(LightmapProbe);
+ GDREGISTER_VIRTUAL_CLASS(Lightmapper);
+ GDREGISTER_CLASS(GPUParticles3D);
+ GDREGISTER_VIRTUAL_CLASS(GPUParticlesCollision3D);
+ GDREGISTER_CLASS(GPUParticlesCollisionBox);
+ GDREGISTER_CLASS(GPUParticlesCollisionSphere);
+ GDREGISTER_CLASS(GPUParticlesCollisionSDF);
+ GDREGISTER_CLASS(GPUParticlesCollisionHeightField);
+ GDREGISTER_VIRTUAL_CLASS(GPUParticlesAttractor3D);
+ GDREGISTER_CLASS(GPUParticlesAttractorBox);
+ GDREGISTER_CLASS(GPUParticlesAttractorSphere);
+ GDREGISTER_CLASS(GPUParticlesAttractorVectorField);
+ GDREGISTER_CLASS(CPUParticles3D);
+ GDREGISTER_CLASS(Position3D);
+
+ GDREGISTER_CLASS(RootMotionView);
ClassDB::set_class_enabled("RootMotionView", false); //disabled by default, enabled by editor
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_virtual_class<CollisionObject3D>();
- ClassDB::register_virtual_class<PhysicsBody3D>();
- ClassDB::register_class<StaticBody3D>();
- ClassDB::register_class<RigidBody3D>();
- ClassDB::register_class<KinematicCollision3D>();
- ClassDB::register_class<CharacterBody3D>();
- ClassDB::register_class<SpringArm3D>();
-
- ClassDB::register_class<PhysicalBone3D>();
- ClassDB::register_class<SoftBody3D>();
-
- ClassDB::register_class<SkeletonIK3D>();
- ClassDB::register_class<BoneAttachment3D>();
-
- ClassDB::register_class<VehicleBody3D>();
- ClassDB::register_class<VehicleWheel3D>();
- ClassDB::register_class<Area3D>();
- ClassDB::register_class<ProximityGroup3D>();
- ClassDB::register_class<CollisionShape3D>();
- ClassDB::register_class<CollisionPolygon3D>();
- ClassDB::register_class<RayCast3D>();
- ClassDB::register_class<MultiMeshInstance3D>();
-
- ClassDB::register_class<Curve3D>();
- ClassDB::register_class<Path3D>();
- ClassDB::register_class<PathFollow3D>();
- ClassDB::register_class<VisibleOnScreenNotifier3D>();
- ClassDB::register_class<VisibleOnScreenEnabler3D>();
- ClassDB::register_class<WorldEnvironment>();
- ClassDB::register_class<RemoteTransform3D>();
-
- ClassDB::register_virtual_class<Joint3D>();
- ClassDB::register_class<PinJoint3D>();
- ClassDB::register_class<HingeJoint3D>();
- ClassDB::register_class<SliderJoint3D>();
- ClassDB::register_class<ConeTwistJoint3D>();
- ClassDB::register_class<Generic6DOFJoint3D>();
-
- ClassDB::register_class<NavigationRegion3D>();
- ClassDB::register_class<NavigationAgent3D>();
- ClassDB::register_class<NavigationObstacle3D>();
+ GDREGISTER_VIRTUAL_CLASS(CollisionObject3D);
+ GDREGISTER_VIRTUAL_CLASS(PhysicsBody3D);
+ GDREGISTER_CLASS(StaticBody3D);
+ GDREGISTER_CLASS(RigidBody3D);
+ GDREGISTER_CLASS(KinematicCollision3D);
+ GDREGISTER_CLASS(CharacterBody3D);
+ GDREGISTER_CLASS(SpringArm3D);
+
+ GDREGISTER_CLASS(PhysicalBone3D);
+ GDREGISTER_CLASS(SoftBody3D);
+
+ GDREGISTER_CLASS(SkeletonIK3D);
+ GDREGISTER_CLASS(BoneAttachment3D);
+
+ GDREGISTER_CLASS(VehicleBody3D);
+ GDREGISTER_CLASS(VehicleWheel3D);
+ GDREGISTER_CLASS(Area3D);
+ GDREGISTER_CLASS(ProximityGroup3D);
+ GDREGISTER_CLASS(CollisionShape3D);
+ GDREGISTER_CLASS(CollisionPolygon3D);
+ GDREGISTER_CLASS(RayCast3D);
+ GDREGISTER_CLASS(MultiMeshInstance3D);
+
+ GDREGISTER_CLASS(Curve3D);
+ GDREGISTER_CLASS(Path3D);
+ GDREGISTER_CLASS(PathFollow3D);
+ GDREGISTER_CLASS(VisibleOnScreenNotifier3D);
+ GDREGISTER_CLASS(VisibleOnScreenEnabler3D);
+ GDREGISTER_CLASS(WorldEnvironment);
+ GDREGISTER_CLASS(RemoteTransform3D);
+
+ GDREGISTER_VIRTUAL_CLASS(Joint3D);
+ GDREGISTER_CLASS(PinJoint3D);
+ GDREGISTER_CLASS(HingeJoint3D);
+ GDREGISTER_CLASS(SliderJoint3D);
+ GDREGISTER_CLASS(ConeTwistJoint3D);
+ GDREGISTER_CLASS(Generic6DOFJoint3D);
+
+ GDREGISTER_CLASS(NavigationRegion3D);
+ GDREGISTER_CLASS(NavigationAgent3D);
+ GDREGISTER_CLASS(NavigationObstacle3D);
OS::get_singleton()->yield(); //may take time to init
#endif
/* REGISTER SHADER */
- ClassDB::register_class<Shader>();
- ClassDB::register_class<VisualShader>();
- ClassDB::register_virtual_class<VisualShaderNode>();
- ClassDB::register_class<VisualShaderNodeCustom>();
- ClassDB::register_class<VisualShaderNodeInput>();
- ClassDB::register_virtual_class<VisualShaderNodeOutput>();
- ClassDB::register_virtual_class<VisualShaderNodeResizableBase>();
- ClassDB::register_virtual_class<VisualShaderNodeGroupBase>();
- ClassDB::register_virtual_class<VisualShaderNodeConstant>();
- ClassDB::register_class<VisualShaderNodeComment>();
- ClassDB::register_class<VisualShaderNodeFloatConstant>();
- ClassDB::register_class<VisualShaderNodeIntConstant>();
- ClassDB::register_class<VisualShaderNodeBooleanConstant>();
- ClassDB::register_class<VisualShaderNodeColorConstant>();
- ClassDB::register_class<VisualShaderNodeVec3Constant>();
- ClassDB::register_class<VisualShaderNodeTransformConstant>();
- ClassDB::register_class<VisualShaderNodeFloatOp>();
- ClassDB::register_class<VisualShaderNodeIntOp>();
- ClassDB::register_class<VisualShaderNodeVectorOp>();
- ClassDB::register_class<VisualShaderNodeColorOp>();
- ClassDB::register_class<VisualShaderNodeTransformMult>();
- ClassDB::register_class<VisualShaderNodeTransformVecMult>();
- ClassDB::register_class<VisualShaderNodeFloatFunc>();
- ClassDB::register_class<VisualShaderNodeIntFunc>();
- ClassDB::register_class<VisualShaderNodeVectorFunc>();
- ClassDB::register_class<VisualShaderNodeColorFunc>();
- ClassDB::register_class<VisualShaderNodeTransformFunc>();
- ClassDB::register_class<VisualShaderNodeUVFunc>();
- ClassDB::register_class<VisualShaderNodeDotProduct>();
- ClassDB::register_class<VisualShaderNodeVectorLen>();
- ClassDB::register_class<VisualShaderNodeDeterminant>();
- ClassDB::register_class<VisualShaderNodeScalarDerivativeFunc>();
- ClassDB::register_class<VisualShaderNodeVectorDerivativeFunc>();
- ClassDB::register_class<VisualShaderNodeClamp>();
- ClassDB::register_class<VisualShaderNodeFaceForward>();
- ClassDB::register_class<VisualShaderNodeOuterProduct>();
- ClassDB::register_class<VisualShaderNodeSmoothStep>();
- ClassDB::register_class<VisualShaderNodeStep>();
- ClassDB::register_class<VisualShaderNodeVectorDistance>();
- ClassDB::register_class<VisualShaderNodeVectorRefract>();
- ClassDB::register_class<VisualShaderNodeMix>();
- ClassDB::register_class<VisualShaderNodeVectorCompose>();
- ClassDB::register_class<VisualShaderNodeTransformCompose>();
- ClassDB::register_class<VisualShaderNodeVectorDecompose>();
- ClassDB::register_class<VisualShaderNodeTransformDecompose>();
- ClassDB::register_class<VisualShaderNodeTexture>();
- ClassDB::register_class<VisualShaderNodeCurveTexture>();
- ClassDB::register_virtual_class<VisualShaderNodeSample3D>();
- ClassDB::register_class<VisualShaderNodeTexture2DArray>();
- ClassDB::register_class<VisualShaderNodeTexture3D>();
- ClassDB::register_class<VisualShaderNodeCubemap>();
- ClassDB::register_virtual_class<VisualShaderNodeUniform>();
- ClassDB::register_class<VisualShaderNodeUniformRef>();
- ClassDB::register_class<VisualShaderNodeFloatUniform>();
- ClassDB::register_class<VisualShaderNodeIntUniform>();
- ClassDB::register_class<VisualShaderNodeBooleanUniform>();
- ClassDB::register_class<VisualShaderNodeColorUniform>();
- ClassDB::register_class<VisualShaderNodeVec3Uniform>();
- ClassDB::register_class<VisualShaderNodeTransformUniform>();
- ClassDB::register_class<VisualShaderNodeTextureUniform>();
- ClassDB::register_class<VisualShaderNodeTextureUniformTriplanar>();
- ClassDB::register_class<VisualShaderNodeTexture2DArrayUniform>();
- ClassDB::register_class<VisualShaderNodeTexture3DUniform>();
- ClassDB::register_class<VisualShaderNodeCubemapUniform>();
- ClassDB::register_class<VisualShaderNodeIf>();
- ClassDB::register_class<VisualShaderNodeSwitch>();
- ClassDB::register_class<VisualShaderNodeFresnel>();
- ClassDB::register_class<VisualShaderNodeExpression>();
- ClassDB::register_class<VisualShaderNodeGlobalExpression>();
- ClassDB::register_class<VisualShaderNodeIs>();
- ClassDB::register_class<VisualShaderNodeCompare>();
- ClassDB::register_class<VisualShaderNodeMultiplyAdd>();
- ClassDB::register_class<VisualShaderNodeBillboard>();
-
- ClassDB::register_class<VisualShaderNodeSDFToScreenUV>();
- ClassDB::register_class<VisualShaderNodeScreenUVToSDF>();
- ClassDB::register_class<VisualShaderNodeTextureSDF>();
- ClassDB::register_class<VisualShaderNodeTextureSDFNormal>();
- ClassDB::register_class<VisualShaderNodeSDFRaymarch>();
-
- ClassDB::register_class<VisualShaderNodeParticleOutput>();
- ClassDB::register_virtual_class<VisualShaderNodeParticleEmitter>();
- ClassDB::register_class<VisualShaderNodeParticleSphereEmitter>();
- ClassDB::register_class<VisualShaderNodeParticleBoxEmitter>();
- ClassDB::register_class<VisualShaderNodeParticleRingEmitter>();
- ClassDB::register_class<VisualShaderNodeParticleMultiplyByAxisAngle>();
- ClassDB::register_class<VisualShaderNodeParticleConeVelocity>();
- ClassDB::register_class<VisualShaderNodeParticleRandomness>();
- ClassDB::register_class<VisualShaderNodeParticleAccelerator>();
- ClassDB::register_class<VisualShaderNodeParticleEmit>();
-
- ClassDB::register_class<ShaderMaterial>();
- ClassDB::register_virtual_class<CanvasItem>();
- ClassDB::register_class<CanvasTexture>();
- ClassDB::register_class<CanvasItemMaterial>();
+ GDREGISTER_CLASS(Shader);
+ GDREGISTER_CLASS(VisualShader);
+ GDREGISTER_VIRTUAL_CLASS(VisualShaderNode);
+ GDREGISTER_CLASS(VisualShaderNodeCustom);
+ GDREGISTER_CLASS(VisualShaderNodeInput);
+ GDREGISTER_VIRTUAL_CLASS(VisualShaderNodeOutput);
+ GDREGISTER_VIRTUAL_CLASS(VisualShaderNodeResizableBase);
+ GDREGISTER_VIRTUAL_CLASS(VisualShaderNodeGroupBase);
+ GDREGISTER_VIRTUAL_CLASS(VisualShaderNodeConstant);
+ GDREGISTER_CLASS(VisualShaderNodeComment);
+ GDREGISTER_CLASS(VisualShaderNodeFloatConstant);
+ GDREGISTER_CLASS(VisualShaderNodeIntConstant);
+ GDREGISTER_CLASS(VisualShaderNodeBooleanConstant);
+ GDREGISTER_CLASS(VisualShaderNodeColorConstant);
+ GDREGISTER_CLASS(VisualShaderNodeVec3Constant);
+ GDREGISTER_CLASS(VisualShaderNodeTransformConstant);
+ GDREGISTER_CLASS(VisualShaderNodeFloatOp);
+ GDREGISTER_CLASS(VisualShaderNodeIntOp);
+ GDREGISTER_CLASS(VisualShaderNodeVectorOp);
+ GDREGISTER_CLASS(VisualShaderNodeColorOp);
+ GDREGISTER_CLASS(VisualShaderNodeTransformMult);
+ GDREGISTER_CLASS(VisualShaderNodeTransformVecMult);
+ GDREGISTER_CLASS(VisualShaderNodeFloatFunc);
+ GDREGISTER_CLASS(VisualShaderNodeIntFunc);
+ GDREGISTER_CLASS(VisualShaderNodeVectorFunc);
+ GDREGISTER_CLASS(VisualShaderNodeColorFunc);
+ GDREGISTER_CLASS(VisualShaderNodeTransformFunc);
+ GDREGISTER_CLASS(VisualShaderNodeUVFunc);
+ GDREGISTER_CLASS(VisualShaderNodeDotProduct);
+ GDREGISTER_CLASS(VisualShaderNodeVectorLen);
+ GDREGISTER_CLASS(VisualShaderNodeDeterminant);
+ GDREGISTER_CLASS(VisualShaderNodeScalarDerivativeFunc);
+ GDREGISTER_CLASS(VisualShaderNodeVectorDerivativeFunc);
+ GDREGISTER_CLASS(VisualShaderNodeClamp);
+ GDREGISTER_CLASS(VisualShaderNodeFaceForward);
+ GDREGISTER_CLASS(VisualShaderNodeOuterProduct);
+ GDREGISTER_CLASS(VisualShaderNodeSmoothStep);
+ GDREGISTER_CLASS(VisualShaderNodeStep);
+ GDREGISTER_CLASS(VisualShaderNodeVectorDistance);
+ GDREGISTER_CLASS(VisualShaderNodeVectorRefract);
+ GDREGISTER_CLASS(VisualShaderNodeMix);
+ GDREGISTER_CLASS(VisualShaderNodeVectorCompose);
+ GDREGISTER_CLASS(VisualShaderNodeTransformCompose);
+ GDREGISTER_CLASS(VisualShaderNodeVectorDecompose);
+ GDREGISTER_CLASS(VisualShaderNodeTransformDecompose);
+ GDREGISTER_CLASS(VisualShaderNodeTexture);
+ GDREGISTER_CLASS(VisualShaderNodeCurveTexture);
+ GDREGISTER_CLASS(VisualShaderNodeCurveXYZTexture);
+ GDREGISTER_VIRTUAL_CLASS(VisualShaderNodeSample3D);
+ GDREGISTER_CLASS(VisualShaderNodeTexture2DArray);
+ GDREGISTER_CLASS(VisualShaderNodeTexture3D);
+ GDREGISTER_CLASS(VisualShaderNodeCubemap);
+ GDREGISTER_VIRTUAL_CLASS(VisualShaderNodeUniform);
+ GDREGISTER_CLASS(VisualShaderNodeUniformRef);
+ GDREGISTER_CLASS(VisualShaderNodeFloatUniform);
+ GDREGISTER_CLASS(VisualShaderNodeIntUniform);
+ GDREGISTER_CLASS(VisualShaderNodeBooleanUniform);
+ GDREGISTER_CLASS(VisualShaderNodeColorUniform);
+ GDREGISTER_CLASS(VisualShaderNodeVec3Uniform);
+ GDREGISTER_CLASS(VisualShaderNodeTransformUniform);
+ GDREGISTER_CLASS(VisualShaderNodeTextureUniform);
+ GDREGISTER_CLASS(VisualShaderNodeTextureUniformTriplanar);
+ GDREGISTER_CLASS(VisualShaderNodeTexture2DArrayUniform);
+ GDREGISTER_CLASS(VisualShaderNodeTexture3DUniform);
+ GDREGISTER_CLASS(VisualShaderNodeCubemapUniform);
+ GDREGISTER_CLASS(VisualShaderNodeIf);
+ GDREGISTER_CLASS(VisualShaderNodeSwitch);
+ GDREGISTER_CLASS(VisualShaderNodeFresnel);
+ GDREGISTER_CLASS(VisualShaderNodeExpression);
+ GDREGISTER_CLASS(VisualShaderNodeGlobalExpression);
+ GDREGISTER_CLASS(VisualShaderNodeIs);
+ GDREGISTER_CLASS(VisualShaderNodeCompare);
+ GDREGISTER_CLASS(VisualShaderNodeMultiplyAdd);
+ GDREGISTER_CLASS(VisualShaderNodeBillboard);
+
+ GDREGISTER_CLASS(VisualShaderNodeSDFToScreenUV);
+ GDREGISTER_CLASS(VisualShaderNodeScreenUVToSDF);
+ GDREGISTER_CLASS(VisualShaderNodeTextureSDF);
+ GDREGISTER_CLASS(VisualShaderNodeTextureSDFNormal);
+ GDREGISTER_CLASS(VisualShaderNodeSDFRaymarch);
+
+ GDREGISTER_CLASS(VisualShaderNodeParticleOutput);
+ GDREGISTER_VIRTUAL_CLASS(VisualShaderNodeParticleEmitter);
+ GDREGISTER_CLASS(VisualShaderNodeParticleSphereEmitter);
+ GDREGISTER_CLASS(VisualShaderNodeParticleBoxEmitter);
+ GDREGISTER_CLASS(VisualShaderNodeParticleRingEmitter);
+ GDREGISTER_CLASS(VisualShaderNodeParticleMultiplyByAxisAngle);
+ GDREGISTER_CLASS(VisualShaderNodeParticleConeVelocity);
+ GDREGISTER_CLASS(VisualShaderNodeParticleRandomness);
+ GDREGISTER_CLASS(VisualShaderNodeParticleAccelerator);
+ GDREGISTER_CLASS(VisualShaderNodeParticleEmit);
+
+ GDREGISTER_CLASS(ShaderMaterial);
+ GDREGISTER_VIRTUAL_CLASS(CanvasItem);
+ GDREGISTER_CLASS(CanvasTexture);
+ GDREGISTER_CLASS(CanvasItemMaterial);
SceneTree::add_idle_callback(CanvasItemMaterial::flush_changes);
CanvasItemMaterial::init_shaders();
/* REGISTER 2D */
- ClassDB::register_class<Node2D>();
- ClassDB::register_class<CanvasGroup>();
- ClassDB::register_class<CPUParticles2D>();
- ClassDB::register_class<GPUParticles2D>();
- ClassDB::register_class<Sprite2D>();
- ClassDB::register_class<SpriteFrames>();
- ClassDB::register_class<AnimatedSprite2D>();
- ClassDB::register_class<Position2D>();
- ClassDB::register_class<Line2D>();
- ClassDB::register_class<MeshInstance2D>();
- ClassDB::register_class<MultiMeshInstance2D>();
- ClassDB::register_virtual_class<CollisionObject2D>();
- ClassDB::register_virtual_class<PhysicsBody2D>();
- ClassDB::register_class<StaticBody2D>();
- ClassDB::register_class<RigidBody2D>();
- ClassDB::register_class<CharacterBody2D>();
- ClassDB::register_class<KinematicCollision2D>();
- ClassDB::register_class<Area2D>();
- ClassDB::register_class<CollisionShape2D>();
- ClassDB::register_class<CollisionPolygon2D>();
- ClassDB::register_class<RayCast2D>();
- ClassDB::register_class<VisibleOnScreenNotifier2D>();
- ClassDB::register_class<VisibleOnScreenEnabler2D>();
- ClassDB::register_class<Polygon2D>();
- ClassDB::register_class<Skeleton2D>();
- ClassDB::register_class<Bone2D>();
- ClassDB::register_virtual_class<Light2D>();
- ClassDB::register_class<PointLight2D>();
- ClassDB::register_class<DirectionalLight2D>();
- ClassDB::register_class<LightOccluder2D>();
- ClassDB::register_class<OccluderPolygon2D>();
- ClassDB::register_class<BackBufferCopy>();
+ GDREGISTER_CLASS(Node2D);
+ GDREGISTER_CLASS(CanvasGroup);
+ GDREGISTER_CLASS(CPUParticles2D);
+ GDREGISTER_CLASS(GPUParticles2D);
+ GDREGISTER_CLASS(Sprite2D);
+ GDREGISTER_CLASS(SpriteFrames);
+ GDREGISTER_CLASS(AnimatedSprite2D);
+ GDREGISTER_CLASS(Position2D);
+ GDREGISTER_CLASS(Line2D);
+ GDREGISTER_CLASS(MeshInstance2D);
+ GDREGISTER_CLASS(MultiMeshInstance2D);
+ GDREGISTER_VIRTUAL_CLASS(CollisionObject2D);
+ GDREGISTER_VIRTUAL_CLASS(PhysicsBody2D);
+ GDREGISTER_CLASS(StaticBody2D);
+ GDREGISTER_CLASS(RigidBody2D);
+ GDREGISTER_CLASS(CharacterBody2D);
+ GDREGISTER_CLASS(KinematicCollision2D);
+ GDREGISTER_CLASS(Area2D);
+ GDREGISTER_CLASS(CollisionShape2D);
+ GDREGISTER_CLASS(CollisionPolygon2D);
+ GDREGISTER_CLASS(RayCast2D);
+ GDREGISTER_CLASS(VisibleOnScreenNotifier2D);
+ GDREGISTER_CLASS(VisibleOnScreenEnabler2D);
+ GDREGISTER_CLASS(Polygon2D);
+ GDREGISTER_CLASS(Skeleton2D);
+ GDREGISTER_CLASS(Bone2D);
+ GDREGISTER_VIRTUAL_CLASS(Light2D);
+ GDREGISTER_CLASS(PointLight2D);
+ GDREGISTER_CLASS(DirectionalLight2D);
+ GDREGISTER_CLASS(LightOccluder2D);
+ GDREGISTER_CLASS(OccluderPolygon2D);
+ GDREGISTER_CLASS(BackBufferCopy);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_class<Camera2D>();
- ClassDB::register_virtual_class<Joint2D>();
- ClassDB::register_class<PinJoint2D>();
- ClassDB::register_class<GrooveJoint2D>();
- ClassDB::register_class<DampedSpringJoint2D>();
- ClassDB::register_class<TileSet>();
- ClassDB::register_virtual_class<TileSetSource>();
- ClassDB::register_class<TileSetAtlasSource>();
- ClassDB::register_class<TileSetScenesCollectionSource>();
- ClassDB::register_class<TileData>();
- ClassDB::register_class<TileMap>();
- ClassDB::register_class<ParallaxBackground>();
- ClassDB::register_class<ParallaxLayer>();
- ClassDB::register_class<TouchScreenButton>();
- ClassDB::register_class<RemoteTransform2D>();
-
- ClassDB::register_class<SkeletonModificationStack2D>();
- ClassDB::register_class<SkeletonModification2D>();
- ClassDB::register_class<SkeletonModification2DLookAt>();
- ClassDB::register_class<SkeletonModification2DCCDIK>();
- ClassDB::register_class<SkeletonModification2DFABRIK>();
- ClassDB::register_class<SkeletonModification2DJiggle>();
- ClassDB::register_class<SkeletonModification2DTwoBoneIK>();
- ClassDB::register_class<SkeletonModification2DStackHolder>();
-
- ClassDB::register_class<PhysicalBone2D>();
- ClassDB::register_class<SkeletonModification2DPhysicalBones>();
+ GDREGISTER_CLASS(Camera2D);
+ GDREGISTER_VIRTUAL_CLASS(Joint2D);
+ GDREGISTER_CLASS(PinJoint2D);
+ GDREGISTER_CLASS(GrooveJoint2D);
+ GDREGISTER_CLASS(DampedSpringJoint2D);
+ GDREGISTER_CLASS(TileSet);
+ GDREGISTER_VIRTUAL_CLASS(TileSetSource);
+ GDREGISTER_CLASS(TileSetAtlasSource);
+ GDREGISTER_CLASS(TileSetScenesCollectionSource);
+ GDREGISTER_CLASS(TileData);
+ GDREGISTER_CLASS(TileMap);
+ GDREGISTER_CLASS(ParallaxBackground);
+ GDREGISTER_CLASS(ParallaxLayer);
+ GDREGISTER_CLASS(TouchScreenButton);
+ GDREGISTER_CLASS(RemoteTransform2D);
+
+ GDREGISTER_CLASS(SkeletonModificationStack2D);
+ GDREGISTER_CLASS(SkeletonModification2D);
+ GDREGISTER_CLASS(SkeletonModification2DLookAt);
+ GDREGISTER_CLASS(SkeletonModification2DCCDIK);
+ GDREGISTER_CLASS(SkeletonModification2DFABRIK);
+ GDREGISTER_CLASS(SkeletonModification2DJiggle);
+ GDREGISTER_CLASS(SkeletonModification2DTwoBoneIK);
+ GDREGISTER_CLASS(SkeletonModification2DStackHolder);
+
+ GDREGISTER_CLASS(PhysicalBone2D);
+ GDREGISTER_CLASS(SkeletonModification2DPhysicalBones);
OS::get_singleton()->yield(); //may take time to init
/* REGISTER RESOURCES */
- ClassDB::register_virtual_class<Shader>();
- ClassDB::register_class<ParticlesMaterial>();
+ GDREGISTER_VIRTUAL_CLASS(Shader);
+ GDREGISTER_CLASS(ParticlesMaterial);
SceneTree::add_idle_callback(ParticlesMaterial::flush_changes);
ParticlesMaterial::init_shaders();
- ClassDB::register_class<ProceduralSkyMaterial>();
- ClassDB::register_class<PanoramaSkyMaterial>();
- ClassDB::register_class<PhysicalSkyMaterial>();
+ GDREGISTER_CLASS(ProceduralSkyMaterial);
+ GDREGISTER_CLASS(PanoramaSkyMaterial);
+ GDREGISTER_CLASS(PhysicalSkyMaterial);
- ClassDB::register_virtual_class<Mesh>();
- ClassDB::register_class<ArrayMesh>();
- ClassDB::register_class<ImmediateMesh>();
- ClassDB::register_class<MultiMesh>();
- ClassDB::register_class<SurfaceTool>();
- ClassDB::register_class<MeshDataTool>();
+ GDREGISTER_VIRTUAL_CLASS(Mesh);
+ GDREGISTER_CLASS(ArrayMesh);
+ GDREGISTER_CLASS(ImmediateMesh);
+ GDREGISTER_CLASS(MultiMesh);
+ GDREGISTER_CLASS(SurfaceTool);
+ GDREGISTER_CLASS(MeshDataTool);
#ifndef _3D_DISABLED
- ClassDB::register_virtual_class<PrimitiveMesh>();
- ClassDB::register_class<BoxMesh>();
- ClassDB::register_class<CapsuleMesh>();
- ClassDB::register_class<CylinderMesh>();
- ClassDB::register_class<PlaneMesh>();
- ClassDB::register_class<PrismMesh>();
- ClassDB::register_class<QuadMesh>();
- ClassDB::register_class<SphereMesh>();
- ClassDB::register_class<TubeTrailMesh>();
- ClassDB::register_class<RibbonTrailMesh>();
- ClassDB::register_class<PointMesh>();
- ClassDB::register_virtual_class<Material>();
- ClassDB::register_virtual_class<BaseMaterial3D>();
- ClassDB::register_class<StandardMaterial3D>();
- ClassDB::register_class<ORMMaterial3D>();
+ GDREGISTER_VIRTUAL_CLASS(PrimitiveMesh);
+ GDREGISTER_CLASS(BoxMesh);
+ GDREGISTER_CLASS(CapsuleMesh);
+ GDREGISTER_CLASS(CylinderMesh);
+ GDREGISTER_CLASS(PlaneMesh);
+ GDREGISTER_CLASS(PrismMesh);
+ GDREGISTER_CLASS(QuadMesh);
+ GDREGISTER_CLASS(SphereMesh);
+ GDREGISTER_CLASS(TubeTrailMesh);
+ GDREGISTER_CLASS(RibbonTrailMesh);
+ GDREGISTER_CLASS(PointMesh);
+ GDREGISTER_VIRTUAL_CLASS(Material);
+ GDREGISTER_VIRTUAL_CLASS(BaseMaterial3D);
+ GDREGISTER_CLASS(StandardMaterial3D);
+ GDREGISTER_CLASS(ORMMaterial3D);
SceneTree::add_idle_callback(BaseMaterial3D::flush_changes);
BaseMaterial3D::init_shaders();
- ClassDB::register_class<MeshLibrary>();
+ GDREGISTER_CLASS(MeshLibrary);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_virtual_class<Shape3D>();
- ClassDB::register_class<RayShape3D>();
- ClassDB::register_class<SphereShape3D>();
- ClassDB::register_class<BoxShape3D>();
- ClassDB::register_class<CapsuleShape3D>();
- ClassDB::register_class<CylinderShape3D>();
- ClassDB::register_class<HeightMapShape3D>();
- ClassDB::register_class<WorldMarginShape3D>();
- ClassDB::register_class<ConvexPolygonShape3D>();
- ClassDB::register_class<ConcavePolygonShape3D>();
+ GDREGISTER_VIRTUAL_CLASS(Shape3D);
+ GDREGISTER_CLASS(RayShape3D);
+ GDREGISTER_CLASS(SphereShape3D);
+ GDREGISTER_CLASS(BoxShape3D);
+ GDREGISTER_CLASS(CapsuleShape3D);
+ GDREGISTER_CLASS(CylinderShape3D);
+ GDREGISTER_CLASS(HeightMapShape3D);
+ GDREGISTER_CLASS(WorldMarginShape3D);
+ GDREGISTER_CLASS(ConvexPolygonShape3D);
+ GDREGISTER_CLASS(ConcavePolygonShape3D);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_class<VelocityTracker3D>();
+ GDREGISTER_CLASS(VelocityTracker3D);
#endif
- ClassDB::register_class<PhysicsMaterial>();
- ClassDB::register_class<World3D>();
- ClassDB::register_class<Environment>();
- ClassDB::register_class<CameraEffects>();
- ClassDB::register_class<World2D>();
- ClassDB::register_virtual_class<Texture>();
- ClassDB::register_virtual_class<Texture2D>();
- ClassDB::register_class<Sky>();
- ClassDB::register_class<StreamTexture2D>();
- ClassDB::register_class<ImageTexture>();
- ClassDB::register_class<AtlasTexture>();
- ClassDB::register_class<MeshTexture>();
- ClassDB::register_class<CurveTexture>();
- ClassDB::register_class<Curve3Texture>();
- ClassDB::register_class<GradientTexture>();
- ClassDB::register_class<ProxyTexture>();
- ClassDB::register_class<AnimatedTexture>();
- ClassDB::register_class<CameraTexture>();
- ClassDB::register_virtual_class<TextureLayered>();
- ClassDB::register_virtual_class<ImageTextureLayered>();
- ClassDB::register_virtual_class<Texture3D>();
- ClassDB::register_class<ImageTexture3D>();
- ClassDB::register_class<StreamTexture3D>();
- ClassDB::register_class<Cubemap>();
- ClassDB::register_class<CubemapArray>();
- ClassDB::register_class<Texture2DArray>();
- ClassDB::register_virtual_class<StreamTextureLayered>();
- ClassDB::register_class<StreamCubemap>();
- ClassDB::register_class<StreamCubemapArray>();
- ClassDB::register_class<StreamTexture2DArray>();
-
- ClassDB::register_class<Animation>();
- ClassDB::register_class<FontData>();
- ClassDB::register_class<Font>();
- ClassDB::register_class<Curve>();
-
- ClassDB::register_class<TextFile>();
- ClassDB::register_class<TextLine>();
- ClassDB::register_class<TextParagraph>();
-
- ClassDB::register_virtual_class<StyleBox>();
- ClassDB::register_class<StyleBoxEmpty>();
- ClassDB::register_class<StyleBoxTexture>();
- ClassDB::register_class<StyleBoxFlat>();
- ClassDB::register_class<StyleBoxLine>();
- ClassDB::register_class<Theme>();
-
- ClassDB::register_class<PolygonPathFinder>();
- ClassDB::register_class<BitMap>();
- ClassDB::register_class<Gradient>();
+ GDREGISTER_CLASS(PhysicsMaterial);
+ GDREGISTER_CLASS(World3D);
+ GDREGISTER_CLASS(Environment);
+ GDREGISTER_CLASS(CameraEffects);
+ GDREGISTER_CLASS(World2D);
+ GDREGISTER_VIRTUAL_CLASS(Texture);
+ GDREGISTER_VIRTUAL_CLASS(Texture2D);
+ GDREGISTER_CLASS(Sky);
+ GDREGISTER_CLASS(StreamTexture2D);
+ GDREGISTER_CLASS(ImageTexture);
+ GDREGISTER_CLASS(AtlasTexture);
+ GDREGISTER_CLASS(MeshTexture);
+ GDREGISTER_CLASS(CurveTexture);
+ GDREGISTER_CLASS(CurveXYZTexture);
+ GDREGISTER_CLASS(GradientTexture);
+ GDREGISTER_CLASS(ProxyTexture);
+ GDREGISTER_CLASS(AnimatedTexture);
+ GDREGISTER_CLASS(CameraTexture);
+ GDREGISTER_VIRTUAL_CLASS(TextureLayered);
+ GDREGISTER_VIRTUAL_CLASS(ImageTextureLayered);
+ GDREGISTER_VIRTUAL_CLASS(Texture3D);
+ GDREGISTER_CLASS(ImageTexture3D);
+ GDREGISTER_CLASS(StreamTexture3D);
+ GDREGISTER_CLASS(Cubemap);
+ GDREGISTER_CLASS(CubemapArray);
+ GDREGISTER_CLASS(Texture2DArray);
+ GDREGISTER_VIRTUAL_CLASS(StreamTextureLayered);
+ GDREGISTER_CLASS(StreamCubemap);
+ GDREGISTER_CLASS(StreamCubemapArray);
+ GDREGISTER_CLASS(StreamTexture2DArray);
+
+ GDREGISTER_CLASS(Animation);
+ GDREGISTER_CLASS(FontData);
+ GDREGISTER_CLASS(Font);
+ GDREGISTER_CLASS(Curve);
+
+ GDREGISTER_CLASS(TextFile);
+ GDREGISTER_CLASS(TextLine);
+ GDREGISTER_CLASS(TextParagraph);
+
+ GDREGISTER_VIRTUAL_CLASS(StyleBox);
+ GDREGISTER_CLASS(StyleBoxEmpty);
+ GDREGISTER_CLASS(StyleBoxTexture);
+ GDREGISTER_CLASS(StyleBoxFlat);
+ GDREGISTER_CLASS(StyleBoxLine);
+ GDREGISTER_CLASS(Theme);
+
+ GDREGISTER_CLASS(PolygonPathFinder);
+ GDREGISTER_CLASS(BitMap);
+ GDREGISTER_CLASS(Gradient);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_class<AudioStreamPlayer>();
- ClassDB::register_class<AudioStreamPlayer2D>();
+ GDREGISTER_CLASS(AudioStreamPlayer);
+ GDREGISTER_CLASS(AudioStreamPlayer2D);
#ifndef _3D_DISABLED
- ClassDB::register_class<AudioStreamPlayer3D>();
+ GDREGISTER_CLASS(AudioStreamPlayer3D);
#endif
- ClassDB::register_virtual_class<VideoStream>();
- ClassDB::register_class<AudioStreamSample>();
+ GDREGISTER_VIRTUAL_CLASS(VideoStream);
+ GDREGISTER_CLASS(AudioStreamSample);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_virtual_class<Shape2D>();
- ClassDB::register_class<LineShape2D>();
- ClassDB::register_class<SegmentShape2D>();
- ClassDB::register_class<RayShape2D>();
- ClassDB::register_class<CircleShape2D>();
- ClassDB::register_class<RectangleShape2D>();
- ClassDB::register_class<CapsuleShape2D>();
- ClassDB::register_class<ConvexPolygonShape2D>();
- ClassDB::register_class<ConcavePolygonShape2D>();
- ClassDB::register_class<Curve2D>();
- ClassDB::register_class<Path2D>();
- ClassDB::register_class<PathFollow2D>();
-
- ClassDB::register_class<NavigationMesh>();
- ClassDB::register_class<NavigationPolygon>();
- ClassDB::register_class<NavigationRegion2D>();
- ClassDB::register_class<NavigationAgent2D>();
- ClassDB::register_class<NavigationObstacle2D>();
+ GDREGISTER_VIRTUAL_CLASS(Shape2D);
+ GDREGISTER_CLASS(LineShape2D);
+ GDREGISTER_CLASS(SegmentShape2D);
+ GDREGISTER_CLASS(RayShape2D);
+ GDREGISTER_CLASS(CircleShape2D);
+ GDREGISTER_CLASS(RectangleShape2D);
+ GDREGISTER_CLASS(CapsuleShape2D);
+ GDREGISTER_CLASS(ConvexPolygonShape2D);
+ GDREGISTER_CLASS(ConcavePolygonShape2D);
+ GDREGISTER_CLASS(Curve2D);
+ GDREGISTER_CLASS(Path2D);
+ GDREGISTER_CLASS(PathFollow2D);
+
+ GDREGISTER_CLASS(NavigationMesh);
+ GDREGISTER_CLASS(NavigationPolygon);
+ GDREGISTER_CLASS(NavigationRegion2D);
+ GDREGISTER_CLASS(NavigationAgent2D);
+ GDREGISTER_CLASS(NavigationObstacle2D);
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_virtual_class<SceneState>();
- ClassDB::register_class<PackedScene>();
+ GDREGISTER_VIRTUAL_CLASS(SceneState);
+ GDREGISTER_CLASS(PackedScene);
- ClassDB::register_class<SceneTree>();
- ClassDB::register_virtual_class<SceneTreeTimer>(); //sorry, you can't create it
+ GDREGISTER_CLASS(SceneTree);
+ GDREGISTER_VIRTUAL_CLASS(SceneTreeTimer); //sorry, you can't create it
#ifndef DISABLE_DEPRECATED
// Dropped in 4.0, near approximation.
@@ -1083,6 +1084,10 @@ void unregister_scene_types() {
BaseMaterial3D::finish_shaders();
#endif // _3D_DISABLED
+ PhysicalSkyMaterial::cleanup_shader();
+ PanoramaSkyMaterial::cleanup_shader();
+ ProceduralSkyMaterial::cleanup_shader();
+
ParticlesMaterial::finish_shaders();
CanvasItemMaterial::finish_shaders();
ColorPicker::finish_shaders();
diff --git a/scene/resources/animation.h b/scene/resources/animation.h
index 1484007333..920ee2e5ab 100644
--- a/scene/resources/animation.h
+++ b/scene/resources/animation.h
@@ -228,8 +228,8 @@ private:
value_track_get_key_indices(p_track, p_time, p_delta, &idxs);
Vector<int> idxr;
- for (List<int>::Element *E = idxs.front(); E; E = E->next()) {
- idxr.push_back(E->get());
+ for (int &E : idxs) {
+ idxr.push_back(E);
}
return idxr;
}
@@ -238,8 +238,8 @@ private:
method_track_get_key_indices(p_track, p_time, p_delta, &idxs);
Vector<int> idxr;
- for (List<int>::Element *E = idxs.front(); E; E = E->next()) {
- idxr.push_back(E->get());
+ for (int &E : idxs) {
+ idxr.push_back(E);
}
return idxr;
}
diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp
index 846da39221..c13db83d6d 100644
--- a/scene/resources/curve.cpp
+++ b/scene/resources/curve.cpp
@@ -286,7 +286,7 @@ void Curve::set_min_value(float p_min) {
}
// Note: min and max are indicative values,
// it's still possible that existing points are out of range at this point.
- emit_signal(SIGNAL_RANGE_CHANGED);
+ emit_signal(SNAME(SIGNAL_RANGE_CHANGED));
}
void Curve::set_max_value(float p_max) {
@@ -296,7 +296,7 @@ void Curve::set_max_value(float p_max) {
_minmax_set_once |= 0b01; // second bit is "max set"
_max_value = p_max;
}
- emit_signal(SIGNAL_RANGE_CHANGED);
+ emit_signal(SNAME(SIGNAL_RANGE_CHANGED));
}
real_t Curve::interpolate(real_t offset) const {
@@ -729,8 +729,8 @@ void Curve2D::_bake() const {
Vector2 *w = baked_point_cache.ptrw();
int idx = 0;
- for (List<Vector2>::Element *E = pointlist.front(); E; E = E->next()) {
- w[idx] = E->get();
+ for (const Vector2 &E : pointlist) {
+ w[idx] = E;
idx++;
}
}
@@ -1239,9 +1239,9 @@ void Curve3D::_bake() const {
Vector3 prev_up = Vector3(0, 1, 0);
Vector3 prev_forward = Vector3(0, 0, 1);
- for (List<Plane>::Element *E = pointlist.front(); E; E = E->next()) {
- w[idx] = E->get().normal;
- wt[idx] = E->get().d;
+ for (const Plane &E : pointlist) {
+ w[idx] = E.normal;
+ wt[idx] = E.d;
if (!up_vector_enabled) {
idx++;
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 5464a46df4..1bbb84f43d 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -390,6 +390,15 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_constant("shadow_outline_size", "Label", 1 * scale);
theme->set_constant("line_spacing", "Label", 3 * scale);
+ theme->set_type_variation("HeaderSmall", "Label");
+ theme->set_font_size("font_size", "HeaderSmall", default_font_size + 4);
+
+ theme->set_type_variation("HeaderMedium", "Label");
+ theme->set_font_size("font_size", "HeaderMedium", default_font_size + 8);
+
+ theme->set_type_variation("HeaderLarge", "Label");
+ theme->set_font_size("font_size", "HeaderLarge", default_font_size + 12);
+
// LineEdit
theme->set_stylebox("normal", "LineEdit", make_stylebox(line_edit_png, 5, 5, 5, 5));
@@ -984,7 +993,7 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) {
Ref<StyleBox> default_style;
Ref<Texture2D> default_icon;
Ref<Font> default_font;
- int default_font_size = 16;
+
if (p_font.is_valid()) {
// Use the custom font defined in the Project Settings.
default_font = p_font;
diff --git a/scene/resources/default_theme/default_theme.h b/scene/resources/default_theme/default_theme.h
index a7b2bec5a4..4cd781e814 100644
--- a/scene/resources/default_theme/default_theme.h
+++ b/scene/resources/default_theme/default_theme.h
@@ -33,6 +33,8 @@
#include "scene/resources/theme.h"
+const int default_font_size = 16;
+
void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const Ref<Font> &large_font, Ref<Texture2D> &default_icon, Ref<StyleBox> &default_style, float p_scale);
void make_default_theme(bool p_hidpi, Ref<Font> p_font);
void clear_default_theme();
diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp
index ebe65605f8..05d1a7bf94 100644
--- a/scene/resources/immediate_mesh.cpp
+++ b/scene/resources/immediate_mesh.cpp
@@ -146,7 +146,7 @@ void ImmediateMesh::surface_add_vertex_2d(const Vector2 &p_vertex) {
}
void ImmediateMesh::surface_end() {
ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
- ERR_FAIL_COND_MSG(!vertices.size(), "No vertices were added, surface cant be created.");
+ ERR_FAIL_COND_MSG(!vertices.size(), "No vertices were added, surface can't be created.");
uint32_t format = ARRAY_FORMAT_VERTEX;
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index a264c2d1eb..08f7274ff6 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -278,8 +278,8 @@ void ShaderMaterial::get_argument_options(const StringName &p_function, int p_id
if (shader.is_valid()) {
List<PropertyInfo> pl;
shader->get_param_list(&pl);
- for (List<PropertyInfo>::Element *E = pl.front(); E; E = E->next()) {
- r_options->push_back(quote_style + E->get().name.replace_first("shader_param/", "") + quote_style);
+ for (const PropertyInfo &E : pl) {
+ r_options->push_back(quote_style + E.name.replace_first("shader_param/", "") + quote_style);
}
}
}
@@ -757,148 +757,148 @@ void BaseMaterial3D::_update_shader() {
code += "void vertex() {\n";
if (flags[FLAG_SRGB_VERTEX_COLOR]) {
- code += "\tif (!OUTPUT_IS_SRGB) {\n";
- code += "\t\tCOLOR.rgb = mix(pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb * (1.0 / 12.92), lessThan(COLOR.rgb, vec3(0.04045)));\n";
- code += "\t}\n";
+ code += " if (!OUTPUT_IS_SRGB) {\n";
+ code += " COLOR.rgb = mix(pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb * (1.0 / 12.92), lessThan(COLOR.rgb, vec3(0.04045)));\n";
+ code += " }\n";
}
if (flags[FLAG_USE_POINT_SIZE]) {
- code += "\tPOINT_SIZE=point_size;\n";
+ code += " POINT_SIZE=point_size;\n";
}
if (shading_mode == SHADING_MODE_PER_VERTEX) {
- code += "\tROUGHNESS=roughness;\n";
+ code += " ROUGHNESS=roughness;\n";
}
if (!flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tUV=UV*uv1_scale.xy+uv1_offset.xy;\n";
+ code += " UV=UV*uv1_scale.xy+uv1_offset.xy;\n";
}
switch (billboard_mode) {
case BILLBOARD_DISABLED: {
} break;
case BILLBOARD_ENABLED: {
- code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],CAMERA_MATRIX[1],CAMERA_MATRIX[2],WORLD_MATRIX[3]);\n";
+ code += " MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],CAMERA_MATRIX[1],CAMERA_MATRIX[2],WORLD_MATRIX[3]);\n";
if (flags[FLAG_BILLBOARD_KEEP_SCALE]) {
- code += "\tMODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n";
}
} break;
case BILLBOARD_FIXED_Y: {
- code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],WORLD_MATRIX[1],vec4(normalize(cross(CAMERA_MATRIX[0].xyz,WORLD_MATRIX[1].xyz)), 0.0),WORLD_MATRIX[3]);\n";
+ code += " MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],WORLD_MATRIX[1],vec4(normalize(cross(CAMERA_MATRIX[0].xyz,WORLD_MATRIX[1].xyz)), 0.0),WORLD_MATRIX[3]);\n";
if (flags[FLAG_BILLBOARD_KEEP_SCALE]) {
- code += "\tMODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, 1.0, 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, 1.0, 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
} else {
- code += "\tMODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(1.0, 0.0, 0.0, 0.0),vec4(0.0, 1.0/length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0 ,1.0));\n";
+ code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(1.0, 0.0, 0.0, 0.0),vec4(0.0, 1.0/length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0 ,1.0));\n";
}
} break;
case BILLBOARD_PARTICLES: {
//make billboard
- code += "\tmat4 mat_world = mat4(normalize(CAMERA_MATRIX[0])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[1])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[2])*length(WORLD_MATRIX[2]),WORLD_MATRIX[3]);\n";
+ code += " mat4 mat_world = mat4(normalize(CAMERA_MATRIX[0])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[1])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[2])*length(WORLD_MATRIX[2]),WORLD_MATRIX[3]);\n";
//rotate by rotation
- code += "\tmat_world = mat_world * mat4( vec4(cos(INSTANCE_CUSTOM.x),-sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0),vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code += " mat_world = mat_world * mat4( vec4(cos(INSTANCE_CUSTOM.x),-sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0),vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n";
//set modelview
- code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat_world;\n";
+ code += " MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat_world;\n";
//handle animation
- code += "\tfloat h_frames = float(particles_anim_h_frames);\n";
- code += "\tfloat v_frames = float(particles_anim_v_frames);\n";
- code += "\tfloat particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n";
- code += "\tfloat particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n";
- code += "\tif (!particles_anim_loop) {\n";
- code += "\t\tparticle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n";
- code += "\t} else {\n";
- code += "\t\tparticle_frame = mod(particle_frame, particle_total_frames);\n";
- code += "\t}";
- code += "\tUV /= vec2(h_frames, v_frames);\n";
- code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n";
+ code += " float h_frames = float(particles_anim_h_frames);\n";
+ code += " float v_frames = float(particles_anim_v_frames);\n";
+ code += " float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n";
+ code += " float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n";
+ code += " if (!particles_anim_loop) {\n";
+ code += " particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n";
+ code += " } else {\n";
+ code += " particle_frame = mod(particle_frame, particle_total_frames);\n";
+ code += " }";
+ code += " UV /= vec2(h_frames, v_frames);\n";
+ code += " UV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n";
} break;
case BILLBOARD_MAX:
break; // Internal value, skip.
}
if (flags[FLAG_FIXED_SIZE]) {
- code += "\tif (PROJECTION_MATRIX[3][3] != 0.0) {\n";
+ code += " if (PROJECTION_MATRIX[3][3] != 0.0) {\n";
//orthogonal matrix, try to do about the same
//with viewport size
- code += "\t\tfloat h = abs(1.0 / (2.0 * PROJECTION_MATRIX[1][1]));\n";
- code += "\t\tfloat sc = (h * 2.0); //consistent with Y-fov\n";
- code += "\t\tMODELVIEW_MATRIX[0]*=sc;\n";
- code += "\t\tMODELVIEW_MATRIX[1]*=sc;\n";
- code += "\t\tMODELVIEW_MATRIX[2]*=sc;\n";
- code += "\t} else {\n";
+ code += " float h = abs(1.0 / (2.0 * PROJECTION_MATRIX[1][1]));\n";
+ code += " float sc = (h * 2.0); //consistent with Y-fov\n";
+ code += " MODELVIEW_MATRIX[0]*=sc;\n";
+ code += " MODELVIEW_MATRIX[1]*=sc;\n";
+ code += " MODELVIEW_MATRIX[2]*=sc;\n";
+ code += " } else {\n";
//just scale by depth
- code += "\t\tfloat sc = -(MODELVIEW_MATRIX)[3].z;\n";
- code += "\t\tMODELVIEW_MATRIX[0]*=sc;\n";
- code += "\t\tMODELVIEW_MATRIX[1]*=sc;\n";
- code += "\t\tMODELVIEW_MATRIX[2]*=sc;\n";
- code += "\t}\n";
+ code += " float sc = -(MODELVIEW_MATRIX)[3].z;\n";
+ code += " MODELVIEW_MATRIX[0]*=sc;\n";
+ code += " MODELVIEW_MATRIX[1]*=sc;\n";
+ code += " MODELVIEW_MATRIX[2]*=sc;\n";
+ code += " }\n";
}
if (detail_uv == DETAIL_UV_2 && !flags[FLAG_UV2_USE_TRIPLANAR]) {
- code += "\tUV2=UV2*uv2_scale.xy+uv2_offset.xy;\n";
+ code += " UV2=UV2*uv2_scale.xy+uv2_offset.xy;\n";
}
if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) {
//generate tangent and binormal in world space
- code += "\tTANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);\n";
- code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.y);\n";
- code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);\n";
- code += "\tTANGENT = normalize(TANGENT);\n";
+ code += " TANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);\n";
+ code += " TANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.y);\n";
+ code += " TANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);\n";
+ code += " TANGENT = normalize(TANGENT);\n";
- code += "\tBINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);\n";
- code += "\tBINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);\n";
- code += "\tBINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);\n";
- code += "\tBINORMAL = normalize(BINORMAL);\n";
+ code += " BINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);\n";
+ code += " BINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);\n";
+ code += " BINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);\n";
+ code += " BINORMAL = normalize(BINORMAL);\n";
}
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
if (flags[FLAG_UV1_USE_WORLD_TRIPLANAR]) {
- code += "\tuv1_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL),vec3(uv1_blend_sharpness));\n";
- code += "\tuv1_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv1_scale + uv1_offset;\n";
+ code += " uv1_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL),vec3(uv1_blend_sharpness));\n";
+ code += " uv1_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv1_scale + uv1_offset;\n";
} else {
- code += "\tuv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n";
- code += "\tuv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;\n";
+ code += " uv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n";
+ code += " uv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;\n";
}
- code += "\tuv1_power_normal/=dot(uv1_power_normal,vec3(1.0));\n";
- code += "\tuv1_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n";
+ code += " uv1_power_normal/=dot(uv1_power_normal,vec3(1.0));\n";
+ code += " uv1_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n";
}
if (flags[FLAG_UV2_USE_TRIPLANAR]) {
if (flags[FLAG_UV2_USE_WORLD_TRIPLANAR]) {
- code += "\tuv2_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL), vec3(uv2_blend_sharpness));\n";
- code += "\tuv2_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv2_scale + uv2_offset;\n";
+ code += " uv2_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL), vec3(uv2_blend_sharpness));\n";
+ code += " uv2_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv2_scale + uv2_offset;\n";
} else {
- code += "\tuv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n";
- code += "\tuv2_triplanar_pos = VERTEX * uv2_scale + uv2_offset;\n";
+ code += " uv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n";
+ code += " uv2_triplanar_pos = VERTEX * uv2_scale + uv2_offset;\n";
}
- code += "\tuv2_power_normal/=dot(uv2_power_normal,vec3(1.0));\n";
- code += "\tuv2_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n";
+ code += " uv2_power_normal/=dot(uv2_power_normal,vec3(1.0));\n";
+ code += " uv2_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n";
}
if (grow_enabled) {
- code += "\tVERTEX+=NORMAL*grow;\n";
+ code += " VERTEX+=NORMAL*grow;\n";
}
code += "}\n";
code += "\n\n";
if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) {
code += "vec4 triplanar_texture(sampler2D p_sampler,vec3 p_weights,vec3 p_triplanar_pos) {\n";
- code += "\tvec4 samp=vec4(0.0);\n";
- code += "\tsamp+= texture(p_sampler,p_triplanar_pos.xy) * p_weights.z;\n";
- code += "\tsamp+= texture(p_sampler,p_triplanar_pos.xz) * p_weights.y;\n";
- code += "\tsamp+= texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)) * p_weights.x;\n";
- code += "\treturn samp;\n";
+ code += " vec4 samp=vec4(0.0);\n";
+ code += " samp+= texture(p_sampler,p_triplanar_pos.xy) * p_weights.z;\n";
+ code += " samp+= texture(p_sampler,p_triplanar_pos.xz) * p_weights.y;\n";
+ code += " samp+= texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)) * p_weights.x;\n";
+ code += " return samp;\n";
code += "}\n";
}
code += "\n\n";
code += "void fragment() {\n";
if (!flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec2 base_uv = UV;\n";
+ code += " vec2 base_uv = UV;\n";
}
if ((features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) || (features[FEATURE_AMBIENT_OCCLUSION] && flags[FLAG_AO_ON_UV2]) || (features[FEATURE_EMISSION] && flags[FLAG_EMISSION_ON_UV2])) {
- code += "\tvec2 base_uv2 = UV2;\n";
+ code += " vec2 base_uv2 = UV2;\n";
}
if (features[FEATURE_HEIGHT_MAPPING] && flags[FLAG_UV1_USE_TRIPLANAR]) {
@@ -916,317 +916,317 @@ void BaseMaterial3D::_update_shader() {
}
if (!RenderingServer::get_singleton()->is_low_end() && features[FEATURE_HEIGHT_MAPPING] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //heightmap not supported with triplanar
- code += "\t{\n";
- code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*heightmap_flip.x,-BINORMAL*heightmap_flip.y,NORMAL));\n"; // binormal is negative due to mikktspace, flip 'unflips' it ;-)
+ code += " {\n";
+ code += " vec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*heightmap_flip.x,-BINORMAL*heightmap_flip.y,NORMAL));\n"; // binormal is negative due to mikktspace, flip 'unflips' it ;-)
if (deep_parallax) {
- code += "\t\tfloat num_layers = mix(float(heightmap_max_layers),float(heightmap_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n";
- code += "\t\tfloat layer_depth = 1.0 / num_layers;\n";
- code += "\t\tfloat current_layer_depth = 0.0;\n";
- code += "\t\tvec2 P = view_dir.xy * heightmap_scale;\n";
- code += "\t\tvec2 delta = P / num_layers;\n";
- code += "\t\tvec2 ofs = base_uv;\n";
+ code += " float num_layers = mix(float(heightmap_max_layers),float(heightmap_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n";
+ code += " float layer_depth = 1.0 / num_layers;\n";
+ code += " float current_layer_depth = 0.0;\n";
+ code += " vec2 P = view_dir.xy * heightmap_scale;\n";
+ code += " vec2 delta = P / num_layers;\n";
+ code += " vec2 ofs = base_uv;\n";
if (flags[FLAG_INVERT_HEIGHTMAP]) {
- code += "\t\tfloat depth = texture(texture_heightmap, ofs).r;\n";
+ code += " float depth = texture(texture_heightmap, ofs).r;\n";
} else {
- code += "\t\tfloat depth = 1.0 - texture(texture_heightmap, ofs).r;\n";
+ code += " float depth = 1.0 - texture(texture_heightmap, ofs).r;\n";
}
- code += "\t\tfloat current_depth = 0.0;\n";
- code += "\t\twhile(current_depth < depth) {\n";
- code += "\t\t\tofs -= delta;\n";
+ code += " float current_depth = 0.0;\n";
+ code += " while(current_depth < depth) {\n";
+ code += " ofs -= delta;\n";
if (flags[FLAG_INVERT_HEIGHTMAP]) {
- code += "\t\t\tdepth = texture(texture_heightmap, ofs).r;\n";
+ code += " depth = texture(texture_heightmap, ofs).r;\n";
} else {
- code += "\t\t\tdepth = 1.0 - texture(texture_heightmap, ofs).r;\n";
+ code += " depth = 1.0 - texture(texture_heightmap, ofs).r;\n";
}
- code += "\t\t\tcurrent_depth += layer_depth;\n";
- code += "\t\t}\n";
- code += "\t\tvec2 prev_ofs = ofs + delta;\n";
- code += "\t\tfloat after_depth = depth - current_depth;\n";
+ code += " current_depth += layer_depth;\n";
+ code += " }\n";
+ code += " vec2 prev_ofs = ofs + delta;\n";
+ code += " float after_depth = depth - current_depth;\n";
if (flags[FLAG_INVERT_HEIGHTMAP]) {
- code += "\t\tfloat before_depth = texture(texture_heightmap, prev_ofs).r - current_depth + layer_depth;\n";
+ code += " float before_depth = texture(texture_heightmap, prev_ofs).r - current_depth + layer_depth;\n";
} else {
- code += "\t\tfloat before_depth = ( 1.0 - texture(texture_heightmap, prev_ofs).r ) - current_depth + layer_depth;\n";
+ code += " float before_depth = ( 1.0 - texture(texture_heightmap, prev_ofs).r ) - current_depth + layer_depth;\n";
}
- code += "\t\tfloat weight = after_depth / (after_depth - before_depth);\n";
- code += "\t\tofs = mix(ofs,prev_ofs,weight);\n";
+ code += " float weight = after_depth / (after_depth - before_depth);\n";
+ code += " ofs = mix(ofs,prev_ofs,weight);\n";
} else {
if (flags[FLAG_INVERT_HEIGHTMAP]) {
- code += "\t\tfloat depth = texture(texture_heightmap, base_uv).r;\n";
+ code += " float depth = texture(texture_heightmap, base_uv).r;\n";
} else {
- code += "\t\tfloat depth = 1.0 - texture(texture_heightmap, base_uv).r;\n";
+ code += " float depth = 1.0 - texture(texture_heightmap, base_uv).r;\n";
}
- code += "\t\tvec2 ofs = base_uv - view_dir.xy / view_dir.z * (depth * heightmap_scale);\n";
+ code += " vec2 ofs = base_uv - view_dir.xy / view_dir.z * (depth * heightmap_scale);\n";
}
- code += "\t\tbase_uv=ofs;\n";
+ code += " base_uv=ofs;\n";
if (features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) {
- code += "\t\tbase_uv2-=ofs;\n";
+ code += " base_uv2-=ofs;\n";
}
- code += "\t}\n";
+ code += " }\n";
}
if (flags[FLAG_USE_POINT_SIZE]) {
- code += "\tvec4 albedo_tex = texture(texture_albedo,POINT_COORD);\n";
+ code += " vec4 albedo_tex = texture(texture_albedo,POINT_COORD);\n";
} else {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos);\n";
+ code += " vec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos);\n";
} else {
- code += "\tvec4 albedo_tex = texture(texture_albedo,base_uv);\n";
+ code += " vec4 albedo_tex = texture(texture_albedo,base_uv);\n";
}
}
if (flags[FLAG_ALBEDO_TEXTURE_FORCE_SRGB]) {
- code += "\talbedo_tex.rgb = mix(pow((albedo_tex.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)),vec3(2.4)),albedo_tex.rgb.rgb * (1.0 / 12.92),lessThan(albedo_tex.rgb,vec3(0.04045)));\n";
+ code += " albedo_tex.rgb = mix(pow((albedo_tex.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)),vec3(2.4)),albedo_tex.rgb.rgb * (1.0 / 12.92),lessThan(albedo_tex.rgb,vec3(0.04045)));\n";
}
if (flags[FLAG_ALBEDO_FROM_VERTEX_COLOR]) {
- code += "\talbedo_tex *= COLOR;\n";
+ code += " albedo_tex *= COLOR;\n";
}
- code += "\tALBEDO = albedo.rgb * albedo_tex.rgb;\n";
+ code += " ALBEDO = albedo.rgb * albedo_tex.rgb;\n";
if (!orm) {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tfloat metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);\n";
+ code += " float metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);\n";
} else {
- code += "\tfloat metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);\n";
+ code += " float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);\n";
}
- code += "\tMETALLIC = metallic_tex * metallic;\n";
+ code += " METALLIC = metallic_tex * metallic;\n";
switch (roughness_texture_channel) {
case TEXTURE_CHANNEL_RED: {
- code += "\tvec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);\n";
+ code += " vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);\n";
} break;
case TEXTURE_CHANNEL_GREEN: {
- code += "\tvec4 roughness_texture_channel = vec4(0.0,1.0,0.0,0.0);\n";
+ code += " vec4 roughness_texture_channel = vec4(0.0,1.0,0.0,0.0);\n";
} break;
case TEXTURE_CHANNEL_BLUE: {
- code += "\tvec4 roughness_texture_channel = vec4(0.0,0.0,1.0,0.0);\n";
+ code += " vec4 roughness_texture_channel = vec4(0.0,0.0,1.0,0.0);\n";
} break;
case TEXTURE_CHANNEL_ALPHA: {
- code += "\tvec4 roughness_texture_channel = vec4(0.0,0.0,0.0,1.0);\n";
+ code += " vec4 roughness_texture_channel = vec4(0.0,0.0,0.0,1.0);\n";
} break;
case TEXTURE_CHANNEL_GRAYSCALE: {
- code += "\tvec4 roughness_texture_channel = vec4(0.333333,0.333333,0.333333,0.0);\n";
+ code += " vec4 roughness_texture_channel = vec4(0.333333,0.333333,0.333333,0.0);\n";
} break;
case TEXTURE_CHANNEL_MAX:
break; // Internal value, skip.
}
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tfloat roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);\n";
+ code += " float roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);\n";
} else {
- code += "\tfloat roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);\n";
+ code += " float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);\n";
}
- code += "\tROUGHNESS = roughness_tex * roughness;\n";
- code += "\tSPECULAR = specular;\n";
+ code += " ROUGHNESS = roughness_tex * roughness;\n";
+ code += " SPECULAR = specular;\n";
} else {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec4 orm_tex = triplanar_texture(texture_orm,uv1_power_normal,uv1_triplanar_pos);\n";
+ code += " vec4 orm_tex = triplanar_texture(texture_orm,uv1_power_normal,uv1_triplanar_pos);\n";
} else {
- code += "\tvec4 orm_tex = texture(texture_orm,base_uv);\n";
+ code += " vec4 orm_tex = texture(texture_orm,base_uv);\n";
}
- code += "\tROUGHNESS = orm_tex.g;\n";
- code += "\tMETALLIC = orm_tex.b;\n";
+ code += " ROUGHNESS = orm_tex.g;\n";
+ code += " METALLIC = orm_tex.b;\n";
}
if (features[FEATURE_NORMAL_MAPPING]) {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tNORMAL_MAP = triplanar_texture(texture_normal,uv1_power_normal,uv1_triplanar_pos).rgb;\n";
+ code += " NORMAL_MAP = triplanar_texture(texture_normal,uv1_power_normal,uv1_triplanar_pos).rgb;\n";
} else {
- code += "\tNORMAL_MAP = texture(texture_normal,base_uv).rgb;\n";
+ code += " NORMAL_MAP = texture(texture_normal,base_uv).rgb;\n";
}
- code += "\tNORMAL_MAP_DEPTH = normal_scale;\n";
+ code += " NORMAL_MAP_DEPTH = normal_scale;\n";
}
if (features[FEATURE_EMISSION]) {
if (flags[FLAG_EMISSION_ON_UV2]) {
if (flags[FLAG_UV2_USE_TRIPLANAR]) {
- code += "\tvec3 emission_tex = triplanar_texture(texture_emission,uv2_power_normal,uv2_triplanar_pos).rgb;\n";
+ code += " vec3 emission_tex = triplanar_texture(texture_emission,uv2_power_normal,uv2_triplanar_pos).rgb;\n";
} else {
- code += "\tvec3 emission_tex = texture(texture_emission,base_uv2).rgb;\n";
+ code += " vec3 emission_tex = texture(texture_emission,base_uv2).rgb;\n";
}
} else {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec3 emission_tex = triplanar_texture(texture_emission,uv1_power_normal,uv1_triplanar_pos).rgb;\n";
+ code += " vec3 emission_tex = triplanar_texture(texture_emission,uv1_power_normal,uv1_triplanar_pos).rgb;\n";
} else {
- code += "\tvec3 emission_tex = texture(texture_emission,base_uv).rgb;\n";
+ code += " vec3 emission_tex = texture(texture_emission,base_uv).rgb;\n";
}
}
if (emission_op == EMISSION_OP_ADD) {
- code += "\tEMISSION = (emission.rgb+emission_tex)*emission_energy;\n";
+ code += " EMISSION = (emission.rgb+emission_tex)*emission_energy;\n";
} else {
- code += "\tEMISSION = (emission.rgb*emission_tex)*emission_energy;\n";
+ code += " EMISSION = (emission.rgb*emission_tex)*emission_energy;\n";
}
}
if (features[FEATURE_REFRACTION]) {
if (features[FEATURE_NORMAL_MAPPING]) {
- code += "\tvec3 unpacked_normal = NORMAL_MAP;\n";
- code += "\tunpacked_normal.xy = unpacked_normal.xy * 2.0 - 1.0;\n";
- code += "\tunpacked_normal.z = sqrt(max(0.0, 1.0 - dot(unpacked_normal.xy, unpacked_normal.xy)));\n";
- code += "\tvec3 ref_normal = normalize( mix(NORMAL,TANGENT * unpacked_normal.x + BINORMAL * unpacked_normal.y + NORMAL * unpacked_normal.z,NORMAL_MAP_DEPTH) );\n";
+ code += " vec3 unpacked_normal = NORMAL_MAP;\n";
+ code += " unpacked_normal.xy = unpacked_normal.xy * 2.0 - 1.0;\n";
+ code += " unpacked_normal.z = sqrt(max(0.0, 1.0 - dot(unpacked_normal.xy, unpacked_normal.xy)));\n";
+ code += " vec3 ref_normal = normalize( mix(NORMAL,TANGENT * unpacked_normal.x + BINORMAL * unpacked_normal.y + NORMAL * unpacked_normal.z,NORMAL_MAP_DEPTH) );\n";
} else {
- code += "\tvec3 ref_normal = NORMAL;\n";
+ code += " vec3 ref_normal = NORMAL;\n";
}
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(triplanar_texture(texture_refraction,uv1_power_normal,uv1_triplanar_pos),refraction_texture_channel) * refraction;\n";
+ code += " vec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(triplanar_texture(texture_refraction,uv1_power_normal,uv1_triplanar_pos),refraction_texture_channel) * refraction;\n";
} else {
- code += "\tvec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(texture(texture_refraction,base_uv),refraction_texture_channel) * refraction;\n";
+ code += " vec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(texture(texture_refraction,base_uv),refraction_texture_channel) * refraction;\n";
}
- code += "\tfloat ref_amount = 1.0 - albedo.a * albedo_tex.a;\n";
- code += "\tEMISSION += textureLod(SCREEN_TEXTURE,ref_ofs,ROUGHNESS * 8.0).rgb * ref_amount;\n";
- code += "\tALBEDO *= 1.0 - ref_amount;\n";
- code += "\tALPHA = 1.0;\n";
+ code += " float ref_amount = 1.0 - albedo.a * albedo_tex.a;\n";
+ code += " EMISSION += textureLod(SCREEN_TEXTURE,ref_ofs,ROUGHNESS * 8.0).rgb * ref_amount;\n";
+ code += " ALBEDO *= 1.0 - ref_amount;\n";
+ code += " ALPHA = 1.0;\n";
} else if (transparency != TRANSPARENCY_DISABLED || flags[FLAG_USE_SHADOW_TO_OPACITY] || (distance_fade == DISTANCE_FADE_PIXEL_ALPHA) || proximity_fade_enabled) {
- code += "\tALPHA = albedo.a * albedo_tex.a;\n";
+ code += " ALPHA = albedo.a * albedo_tex.a;\n";
}
if (transparency == TRANSPARENCY_ALPHA_HASH) {
- code += "\tALPHA_HASH_SCALE = alpha_hash_scale;\n";
+ code += " ALPHA_HASH_SCALE = alpha_hash_scale;\n";
} else if (transparency == TRANSPARENCY_ALPHA_SCISSOR) {
- code += "\tALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;\n";
+ code += " ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;\n";
}
if (alpha_antialiasing_mode != ALPHA_ANTIALIASING_OFF && (transparency == TRANSPARENCY_ALPHA_HASH || transparency == TRANSPARENCY_ALPHA_SCISSOR)) {
- code += "\tALPHA_ANTIALIASING_EDGE = alpha_antialiasing_edge;\n";
- code += "\tALPHA_TEXTURE_COORDINATE = UV * vec2(albedo_texture_size);\n";
+ code += " ALPHA_ANTIALIASING_EDGE = alpha_antialiasing_edge;\n";
+ code += " ALPHA_TEXTURE_COORDINATE = UV * vec2(albedo_texture_size);\n";
}
if (proximity_fade_enabled) {
- code += "\tfloat depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;\n";
- code += "\tvec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);\n";
- code += "\tworld_pos.xyz/=world_pos.w;\n";
- code += "\tALPHA*=clamp(1.0-smoothstep(world_pos.z+proximity_fade_distance,world_pos.z,VERTEX.z),0.0,1.0);\n";
+ code += " float depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;\n";
+ code += " vec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);\n";
+ code += " world_pos.xyz/=world_pos.w;\n";
+ code += " ALPHA*=clamp(1.0-smoothstep(world_pos.z+proximity_fade_distance,world_pos.z,VERTEX.z),0.0,1.0);\n";
}
if (distance_fade != DISTANCE_FADE_DISABLED) {
if ((distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER)) {
if (!RenderingServer::get_singleton()->is_low_end()) {
- code += "\t{\n";
+ code += " {\n";
if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) {
- code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n";
+ code += " float fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n";
} else {
- code += "\t\tfloat fade_distance=-VERTEX.z;\n";
+ code += " float fade_distance=-VERTEX.z;\n";
}
- code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n";
- code += "\t\tint x = int(FRAGCOORD.x) % 4;\n";
- code += "\t\tint y = int(FRAGCOORD.y) % 4;\n";
- code += "\t\tint index = x + y * 4;\n";
- code += "\t\tfloat limit = 0.0;\n\n";
- code += "\t\tif (x < 8) {\n";
- code += "\t\t\tif (index == 0) limit = 0.0625;\n";
- code += "\t\t\tif (index == 1) limit = 0.5625;\n";
- code += "\t\t\tif (index == 2) limit = 0.1875;\n";
- code += "\t\t\tif (index == 3) limit = 0.6875;\n";
- code += "\t\t\tif (index == 4) limit = 0.8125;\n";
- code += "\t\t\tif (index == 5) limit = 0.3125;\n";
- code += "\t\t\tif (index == 6) limit = 0.9375;\n";
- code += "\t\t\tif (index == 7) limit = 0.4375;\n";
- code += "\t\t\tif (index == 8) limit = 0.25;\n";
- code += "\t\t\tif (index == 9) limit = 0.75;\n";
- code += "\t\t\tif (index == 10) limit = 0.125;\n";
- code += "\t\t\tif (index == 11) limit = 0.625;\n";
- code += "\t\t\tif (index == 12) limit = 1.0;\n";
- code += "\t\t\tif (index == 13) limit = 0.5;\n";
- code += "\t\t\tif (index == 14) limit = 0.875;\n";
- code += "\t\t\tif (index == 15) limit = 0.375;\n";
- code += "\t\t}\n\n";
- code += "\tif (fade < limit)\n";
- code += "\t\tdiscard;\n";
- code += "\t}\n\n";
+ code += " float fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n";
+ code += " int x = int(FRAGCOORD.x) % 4;\n";
+ code += " int y = int(FRAGCOORD.y) % 4;\n";
+ code += " int index = x + y * 4;\n";
+ code += " float limit = 0.0;\n\n";
+ code += " if (x < 8) {\n";
+ code += " if (index == 0) limit = 0.0625;\n";
+ code += " if (index == 1) limit = 0.5625;\n";
+ code += " if (index == 2) limit = 0.1875;\n";
+ code += " if (index == 3) limit = 0.6875;\n";
+ code += " if (index == 4) limit = 0.8125;\n";
+ code += " if (index == 5) limit = 0.3125;\n";
+ code += " if (index == 6) limit = 0.9375;\n";
+ code += " if (index == 7) limit = 0.4375;\n";
+ code += " if (index == 8) limit = 0.25;\n";
+ code += " if (index == 9) limit = 0.75;\n";
+ code += " if (index == 10) limit = 0.125;\n";
+ code += " if (index == 11) limit = 0.625;\n";
+ code += " if (index == 12) limit = 1.0;\n";
+ code += " if (index == 13) limit = 0.5;\n";
+ code += " if (index == 14) limit = 0.875;\n";
+ code += " if (index == 15) limit = 0.375;\n";
+ code += " }\n\n";
+ code += " if (fade < limit)\n";
+ code += " discard;\n";
+ code += " }\n\n";
}
} else {
- code += "\tALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n";
+ code += " ALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n";
}
}
if (features[FEATURE_RIM]) {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec2 rim_tex = triplanar_texture(texture_rim,uv1_power_normal,uv1_triplanar_pos).xy;\n";
+ code += " vec2 rim_tex = triplanar_texture(texture_rim,uv1_power_normal,uv1_triplanar_pos).xy;\n";
} else {
- code += "\tvec2 rim_tex = texture(texture_rim,base_uv).xy;\n";
+ code += " vec2 rim_tex = texture(texture_rim,base_uv).xy;\n";
}
- code += "\tRIM = rim*rim_tex.x;";
- code += "\tRIM_TINT = rim_tint*rim_tex.y;\n";
+ code += " RIM = rim*rim_tex.x;";
+ code += " RIM_TINT = rim_tint*rim_tex.y;\n";
}
if (features[FEATURE_CLEARCOAT]) {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec2 clearcoat_tex = triplanar_texture(texture_clearcoat,uv1_power_normal,uv1_triplanar_pos).xy;\n";
+ code += " vec2 clearcoat_tex = triplanar_texture(texture_clearcoat,uv1_power_normal,uv1_triplanar_pos).xy;\n";
} else {
- code += "\tvec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xy;\n";
+ code += " vec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xy;\n";
}
- code += "\tCLEARCOAT = clearcoat*clearcoat_tex.x;";
- code += "\tCLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y;\n";
+ code += " CLEARCOAT = clearcoat*clearcoat_tex.x;";
+ code += " CLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y;\n";
}
if (features[FEATURE_ANISOTROPY]) {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec3 anisotropy_tex = triplanar_texture(texture_flowmap,uv1_power_normal,uv1_triplanar_pos).rga;\n";
+ code += " vec3 anisotropy_tex = triplanar_texture(texture_flowmap,uv1_power_normal,uv1_triplanar_pos).rga;\n";
} else {
- code += "\tvec3 anisotropy_tex = texture(texture_flowmap,base_uv).rga;\n";
+ code += " vec3 anisotropy_tex = texture(texture_flowmap,base_uv).rga;\n";
}
- code += "\tANISOTROPY = anisotropy_ratio*anisotropy_tex.b;\n";
- code += "\tANISOTROPY_FLOW = anisotropy_tex.rg*2.0-1.0;\n";
+ code += " ANISOTROPY = anisotropy_ratio*anisotropy_tex.b;\n";
+ code += " ANISOTROPY_FLOW = anisotropy_tex.rg*2.0-1.0;\n";
}
if (features[FEATURE_AMBIENT_OCCLUSION]) {
if (!orm) {
if (flags[FLAG_AO_ON_UV2]) {
if (flags[FLAG_UV2_USE_TRIPLANAR]) {
- code += "\tAO = dot(triplanar_texture(texture_ambient_occlusion,uv2_power_normal,uv2_triplanar_pos),ao_texture_channel);\n";
+ code += " AO = dot(triplanar_texture(texture_ambient_occlusion,uv2_power_normal,uv2_triplanar_pos),ao_texture_channel);\n";
} else {
- code += "\tAO = dot(texture(texture_ambient_occlusion,base_uv2),ao_texture_channel);\n";
+ code += " AO = dot(texture(texture_ambient_occlusion,base_uv2),ao_texture_channel);\n";
}
} else {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tAO = dot(triplanar_texture(texture_ambient_occlusion,uv1_power_normal,uv1_triplanar_pos),ao_texture_channel);\n";
+ code += " AO = dot(triplanar_texture(texture_ambient_occlusion,uv1_power_normal,uv1_triplanar_pos),ao_texture_channel);\n";
} else {
- code += "\tAO = dot(texture(texture_ambient_occlusion,base_uv),ao_texture_channel);\n";
+ code += " AO = dot(texture(texture_ambient_occlusion,base_uv),ao_texture_channel);\n";
}
}
} else {
- code += "\tAO = orm_tex.r;\n";
+ code += " AO = orm_tex.r;\n";
}
- code += "\tAO_LIGHT_AFFECT = ao_light_affect;\n";
+ code += " AO_LIGHT_AFFECT = ao_light_affect;\n";
}
if (features[FEATURE_SUBSURFACE_SCATTERING]) {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tfloat sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_triplanar_pos).r;\n";
+ code += " float sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_triplanar_pos).r;\n";
} else {
- code += "\tfloat sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n";
+ code += " float sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n";
}
- code += "\tSSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n";
+ code += " SSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n";
}
if (features[FEATURE_SUBSURFACE_TRANSMITTANCE]) {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec4 trans_color_tex = triplanar_texture(texture_subsurface_transmittance,uv1_power_normal,uv1_triplanar_pos);\n";
+ code += " vec4 trans_color_tex = triplanar_texture(texture_subsurface_transmittance,uv1_power_normal,uv1_triplanar_pos);\n";
} else {
- code += "\tvec4 trans_color_tex = texture(texture_subsurface_transmittance,base_uv);\n";
+ code += " vec4 trans_color_tex = texture(texture_subsurface_transmittance,base_uv);\n";
}
- code += "\tSSS_TRANSMITTANCE_COLOR=transmittance_color*trans_color_tex;\n";
+ code += " SSS_TRANSMITTANCE_COLOR=transmittance_color*trans_color_tex;\n";
- code += "\tSSS_TRANSMITTANCE_DEPTH=transmittance_depth;\n";
- code += "\tSSS_TRANSMITTANCE_BOOST=transmittance_boost;\n";
+ code += " SSS_TRANSMITTANCE_DEPTH=transmittance_depth;\n";
+ code += " SSS_TRANSMITTANCE_BOOST=transmittance_boost;\n";
}
if (features[FEATURE_BACKLIGHT]) {
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec3 backlight_tex = triplanar_texture(texture_backlight,uv1_power_normal,uv1_triplanar_pos).rgb;\n";
+ code += " vec3 backlight_tex = triplanar_texture(texture_backlight,uv1_power_normal,uv1_triplanar_pos).rgb;\n";
} else {
- code += "\tvec3 backlight_tex = texture(texture_backlight,base_uv).rgb;\n";
+ code += " vec3 backlight_tex = texture(texture_backlight,base_uv).rgb;\n";
}
- code += "\tBACKLIGHT = (backlight.rgb+backlight_tex);\n";
+ code += " BACKLIGHT = (backlight.rgb+backlight_tex);\n";
}
if (features[FEATURE_DETAIL]) {
@@ -1234,41 +1234,41 @@ void BaseMaterial3D::_update_shader() {
if (triplanar) {
String tp_uv = detail_uv == DETAIL_UV_1 ? "uv1" : "uv2";
- code += "\tvec4 detail_tex = triplanar_texture(texture_detail_albedo," + tp_uv + "_power_normal," + tp_uv + "_triplanar_pos);\n";
- code += "\tvec4 detail_norm_tex = triplanar_texture(texture_detail_normal," + tp_uv + "_power_normal," + tp_uv + "_triplanar_pos);\n";
+ code += " vec4 detail_tex = triplanar_texture(texture_detail_albedo," + tp_uv + "_power_normal," + tp_uv + "_triplanar_pos);\n";
+ code += " vec4 detail_norm_tex = triplanar_texture(texture_detail_normal," + tp_uv + "_power_normal," + tp_uv + "_triplanar_pos);\n";
} else {
String det_uv = detail_uv == DETAIL_UV_1 ? "base_uv" : "base_uv2";
- code += "\tvec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n";
- code += "\tvec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n";
+ code += " vec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n";
+ code += " vec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n";
}
if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tvec4 detail_mask_tex = triplanar_texture(texture_detail_mask,uv1_power_normal,uv1_triplanar_pos);\n";
+ code += " vec4 detail_mask_tex = triplanar_texture(texture_detail_mask,uv1_power_normal,uv1_triplanar_pos);\n";
} else {
- code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n";
+ code += " vec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n";
}
switch (detail_blend_mode) {
case BLEND_MODE_MIX: {
- code += "\tvec3 detail = mix(ALBEDO.rgb,detail_tex.rgb,detail_tex.a);\n";
+ code += " vec3 detail = mix(ALBEDO.rgb,detail_tex.rgb,detail_tex.a);\n";
} break;
case BLEND_MODE_ADD: {
- code += "\tvec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb+detail_tex.rgb,detail_tex.a);\n";
+ code += " vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb+detail_tex.rgb,detail_tex.a);\n";
} break;
case BLEND_MODE_SUB: {
- code += "\tvec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb-detail_tex.rgb,detail_tex.a);\n";
+ code += " vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb-detail_tex.rgb,detail_tex.a);\n";
} break;
case BLEND_MODE_MUL: {
- code += "\tvec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb*detail_tex.rgb,detail_tex.a);\n";
+ code += " vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb*detail_tex.rgb,detail_tex.a);\n";
} break;
case BLEND_MODE_MAX:
break; // Internal value, skip.
}
- code += "\tvec3 detail_norm = mix(NORMAL_MAP,detail_norm_tex.rgb,detail_tex.a);\n";
- code += "\tNORMAL_MAP = mix(NORMAL_MAP,detail_norm,detail_mask_tex.r);\n";
- code += "\tALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n";
+ code += " vec3 detail_norm = mix(NORMAL_MAP,detail_norm_tex.rgb,detail_tex.a);\n";
+ code += " NORMAL_MAP = mix(NORMAL_MAP,detail_norm,detail_mask_tex.r);\n";
+ code += " ALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n";
}
code += "}\n";
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index f44c0c3ee2..2f92872ad5 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -30,6 +30,7 @@
#include "mesh.h"
+#include "core/math/convex_hull.h"
#include "core/templates/pair.h"
#include "scene/resources/concave_polygon_shape_3d.h"
#include "scene/resources/convex_polygon_shape_3d.h"
@@ -221,9 +222,17 @@ Vector<Face3> Mesh::get_faces() const {
*/
}
-Ref<Shape3D> Mesh::create_convex_shape() const {
- Vector<Vector3> vertices;
+Ref<Shape3D> Mesh::create_convex_shape(bool p_clean, bool p_simplify) const {
+ if (p_simplify) {
+ Vector<Ref<Shape3D>> decomposed = convex_decompose(1);
+ if (decomposed.size() == 1) {
+ return decomposed[0];
+ } else {
+ ERR_PRINT("Convex shape simplification failed, falling back to simpler process.");
+ }
+ }
+ Vector<Vector3> vertices;
for (int i = 0; i < get_surface_count(); i++) {
Array a = surface_get_arrays(i);
ERR_FAIL_COND_V(a.is_empty(), Ref<ConvexPolygonShape3D>());
@@ -232,6 +241,18 @@ Ref<Shape3D> Mesh::create_convex_shape() const {
}
Ref<ConvexPolygonShape3D> shape = memnew(ConvexPolygonShape3D);
+
+ if (p_clean) {
+ Geometry3D::MeshData md;
+ Error err = ConvexHullComputer::convex_hull(vertices, md);
+ if (err == OK) {
+ shape->set_points(md.vertices);
+ return shape;
+ } else {
+ ERR_PRINT("Convex shape cleaning failed, falling back to simpler process.");
+ }
+ }
+
shape->set_points(vertices);
return shape;
}
@@ -543,12 +564,12 @@ void Mesh::clear_cache() const {
debug_lines.clear();
}
-Vector<Ref<Shape3D>> Mesh::convex_decompose() const {
+Vector<Ref<Shape3D>> Mesh::convex_decompose(int p_max_convex_hulls) const {
ERR_FAIL_COND_V(!convex_composition_function, Vector<Ref<Shape3D>>());
const Vector<Face3> faces = get_faces();
- Vector<Vector<Face3>> decomposed = convex_composition_function(faces);
+ Vector<Vector<Face3>> decomposed = convex_composition_function(faces, p_max_convex_hulls);
Vector<Ref<Shape3D>> ret;
@@ -1852,7 +1873,7 @@ void ArrayMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("surface_set_name", "surf_idx", "name"), &ArrayMesh::surface_set_name);
ClassDB::bind_method(D_METHOD("surface_get_name", "surf_idx"), &ArrayMesh::surface_get_name);
ClassDB::bind_method(D_METHOD("create_trimesh_shape"), &ArrayMesh::create_trimesh_shape);
- ClassDB::bind_method(D_METHOD("create_convex_shape"), &ArrayMesh::create_convex_shape);
+ ClassDB::bind_method(D_METHOD("create_convex_shape", "clean", "simplify"), &ArrayMesh::create_convex_shape, DEFVAL(true), DEFVAL(false));
ClassDB::bind_method(D_METHOD("create_outline", "margin"), &ArrayMesh::create_outline);
ClassDB::bind_method(D_METHOD("regen_normal_maps"), &ArrayMesh::regen_normal_maps);
ClassDB::set_method_flags(get_class_static(), _scs_create("regen_normal_maps"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h
index 02cab9a5e1..27b0eb098b 100644
--- a/scene/resources/mesh.h
+++ b/scene/resources/mesh.h
@@ -149,7 +149,7 @@ public:
void generate_debug_mesh_indices(Vector<Vector3> &r_points);
Ref<Shape3D> create_trimesh_shape() const;
- Ref<Shape3D> create_convex_shape() const;
+ Ref<Shape3D> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
Ref<Mesh> create_outline(float p_margin) const;
@@ -159,11 +159,11 @@ public:
Size2i get_lightmap_size_hint() const;
void clear_cache() const;
- typedef Vector<Vector<Face3>> (*ConvexDecompositionFunc)(const Vector<Face3> &);
+ typedef Vector<Vector<Face3>> (*ConvexDecompositionFunc)(const Vector<Face3> &p_faces, int p_max_convex_hulls);
static ConvexDecompositionFunc convex_composition_function;
- Vector<Ref<Shape3D>> convex_decompose() const;
+ Vector<Ref<Shape3D>> convex_decompose(int p_max_convex_hulls = -1) const;
virtual int get_builtin_bind_pose_count() const;
virtual Transform3D get_builtin_bind_pose(int p_index) const;
diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp
index d2be2bdba1..ddc50c0490 100644
--- a/scene/resources/navigation_mesh.cpp
+++ b/scene/resources/navigation_mesh.cpp
@@ -329,9 +329,7 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() {
Vector3 *tw = tmeshfaces.ptrw();
int tidx = 0;
- for (List<Face3>::Element *E = faces.front(); E; E = E->next()) {
- const Face3 &f = E->get();
-
+ for (const Face3 &f : faces) {
for (int j = 0; j < 3; j++) {
tw[tidx++] = f.vertex[j];
_EdgeKey ek;
@@ -366,8 +364,8 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() {
{
Vector3 *w = varr.ptrw();
int idx = 0;
- for (List<Vector3>::Element *E = lines.front(); E; E = E->next()) {
- w[idx++] = E->get();
+ for (const Vector3 &E : lines) {
+ w[idx++] = E;
}
}
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 9bb2a4ddb8..eddbb9a842 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -206,8 +206,8 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
node->set(snames[nprops[j].name], props[nprops[j].value], &valid);
//restore old state for new script, if exists
- for (List<Pair<StringName, Variant>>::Element *E = old_state.front(); E; E = E->next()) {
- node->set(E->get().first, E->get().second);
+ for (const Pair<StringName, Variant> &E : old_state) {
+ node->set(E.first, E.second);
}
} else {
Variant value = props[nprops[j].value];
@@ -477,13 +477,13 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
script->update_exports();
}
- for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
+ for (const PropertyInfo &E : plist) {
+ if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
- String name = E->get().name;
- Variant value = p_node->get(E->get().name);
+ String name = E.name;
+ Variant value = p_node->get(E.name);
bool isdefault = false;
Variant default_value = ClassDB::class_get_default_property_value(type, name);
@@ -497,7 +497,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
}
// the version above makes more sense, because it does not rely on placeholder or usage flag
// in the script, just the default value function.
- // if (E->get().usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) {
+ // if (E.usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) {
// isdefault = true; //is script default value
// }
@@ -507,7 +507,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
// only save what has been changed
// only save changed properties in instance
- if ((E->get().usage & PROPERTY_USAGE_NO_INSTANCE_STATE) || E->get().name == "__meta__") {
+ if ((E.usage & PROPERTY_USAGE_NO_INSTANCE_STATE) || E.name == "__meta__") {
//property has requested that no instance state is saved, sorry
//also, meta won't be overridden or saved
continue;
@@ -520,7 +520,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
//check all levels of pack to see if the property exists somewhere
const PackState &ps = F->get();
- original = ps.state->get_property_value(ps.node, E->get().name, exists);
+ original = ps.state->get_property_value(ps.node, E.name, exists);
if (exists) {
break;
}
@@ -565,9 +565,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
List<Node::GroupInfo> groups;
p_node->get_groups(&groups);
- for (List<Node::GroupInfo>::Element *E = groups.front(); E; E = E->next()) {
- Node::GroupInfo &gi = E->get();
-
+ for (const Node::GroupInfo &gi : groups) {
if (!gi.persistent) {
continue;
}
@@ -577,9 +575,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
*/
bool skip = false;
- for (List<PackState>::Element *F = pack_state_stack.front(); F; F = F->next()) {
+ for (const PackState &F : pack_state_stack) {
//check all levels of pack to see if the group was added somewhere
- const PackState &ps = F->get();
+ const PackState &ps = F;
if (ps.state->is_node_in_group(ps.node, gi.name)) {
skip = true;
break;
@@ -679,14 +677,14 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
//ERR_FAIL_COND_V( !node_map.has(p_node), ERR_BUG);
//NodeData &nd = nodes[node_map[p_node]];
- for (List<MethodInfo>::Element *E = _signals.front(); E; E = E->next()) {
+ for (const MethodInfo &E : _signals) {
List<Node::Connection> conns;
- p_node->get_signal_connection_list(E->get().name, &conns);
+ p_node->get_signal_connection_list(E.name, &conns);
conns.sort();
- for (List<Node::Connection>::Element *F = conns.front(); F; F = F->next()) {
- const Node::Connection &c = F->get();
+ for (const Node::Connection &F : conns) {
+ const Node::Connection &c = F;
if (!(c.flags & CONNECT_PERSIST)) { //only persistent connections get saved
continue;
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index 2bde98abe0..7da9cb96ee 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -90,6 +90,10 @@ void ParticlesMaterial::init_shaders() {
shader_names->emission_texture_points = "emission_texture_points";
shader_names->emission_texture_normal = "emission_texture_normal";
shader_names->emission_texture_color = "emission_texture_color";
+ shader_names->emission_ring_axis = "emission_ring_axis";
+ shader_names->emission_ring_height = "emission_ring_height";
+ shader_names->emission_ring_radius = "emission_ring_radius";
+ shader_names->emission_ring_inner_radius = "emission_ring_inner_radius";
shader_names->gravity = "gravity";
@@ -194,6 +198,12 @@ void ParticlesMaterial::_update_shader() {
code += "uniform sampler2D emission_texture_color : hint_white;\n";
}
} break;
+ case EMISSION_SHAPE_RING: {
+ code += "uniform vec3 " + shader_names->emission_ring_axis + ";\n";
+ code += "uniform float " + shader_names->emission_ring_height + ";\n";
+ code += "uniform float " + shader_names->emission_ring_radius + ";\n";
+ code += "uniform float " + shader_names->emission_ring_inner_radius + ";\n";
+ } break;
case EMISSION_SHAPE_MAX: { // Max value for validity check.
break;
}
@@ -396,6 +406,28 @@ void ParticlesMaterial::_update_shader() {
}
}
} break;
+ case EMISSION_SHAPE_RING: {
+ code += " float ring_spawn_angle = rand_from_seed(alt_seed) * 2.0 * pi;\n";
+ code += " float ring_random_radius = rand_from_seed(alt_seed) * (emission_ring_radius - emission_ring_inner_radius) + emission_ring_inner_radius;\n";
+ code += " vec3 axis = normalize(emission_ring_axis);\n";
+ code += " vec3 ortho_axis = vec3(0.0);\n";
+ code += " if (axis == vec3(1.0, 0.0, 0.0)) {\n";
+ code += " ortho_axis = cross(axis, vec3(0.0, 1.0, 0.0));\n";
+ code += " } else {\n";
+ code += " ortho_axis = cross(axis, vec3(1.0, 0.0, 0.0));\n";
+ code += " }\n";
+ code += " ortho_axis = normalize(ortho_axis);\n";
+ code += " float s = sin(ring_spawn_angle);\n";
+ code += " float c = cos(ring_spawn_angle);\n";
+ code += " float oc = 1.0 - c;\n";
+ code += " ortho_axis = mat3(\n";
+ code += " vec3(c + axis.x * axis.x * oc, axis.x * axis.y * oc - axis.z * s, axis.x * axis.z *oc + axis.y * s),\n";
+ code += " vec3(axis.x * axis.y * oc + s * axis.z, c + axis.y * axis.y * oc, axis.y * axis.z * oc - axis.x * s),\n";
+ code += " vec3(axis.z * axis.x * oc - axis.y * s, axis.z * axis.y * oc + axis.x * s, c + axis.z * axis.z * oc)\n";
+ code += " ) * ortho_axis;\n";
+ code += " ortho_axis = normalize(ortho_axis);\n";
+ code += " TRANSFORM[3].xyz = ortho_axis * ring_random_radius + (rand_from_seed(alt_seed) * emission_ring_height - emission_ring_height / 2.0) * axis;\n";
+ } break;
case EMISSION_SHAPE_MAX: { // Max value for validity check.
break;
}
@@ -569,7 +601,7 @@ void ParticlesMaterial::_update_shader() {
code += " vec4(1.250, -1.050, -0.203, 0.0),\n";
code += " vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_s;\n";
if (color_ramp.is_valid()) {
- code += " COLOR = hue_rot_mat * textureLod(color_ramp, vec2(tv, 0.0), 0.0);\n";
+ code += " COLOR = hue_rot_mat * textureLod(color_ramp, vec2(tv, 0.0), 0.0) * color_value;\n";
} else {
code += " COLOR = hue_rot_mat * color_value;\n";
}
@@ -990,6 +1022,26 @@ void ParticlesMaterial::set_emission_point_count(int p_count) {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_point_count, p_count);
}
+void ParticlesMaterial::set_emission_ring_axis(Vector3 p_axis) {
+ emission_ring_axis = p_axis;
+ RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_axis, p_axis);
+}
+
+void ParticlesMaterial::set_emission_ring_height(float p_height) {
+ emission_ring_height = p_height;
+ RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_height, p_height);
+}
+
+void ParticlesMaterial::set_emission_ring_radius(float p_radius) {
+ emission_ring_radius = p_radius;
+ RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_radius, p_radius);
+}
+
+void ParticlesMaterial::set_emission_ring_inner_radius(float p_radius) {
+ emission_ring_inner_radius = p_radius;
+ RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_inner_radius, p_radius);
+}
+
ParticlesMaterial::EmissionShape ParticlesMaterial::get_emission_shape() const {
return emission_shape;
}
@@ -1018,6 +1070,22 @@ int ParticlesMaterial::get_emission_point_count() const {
return emission_point_count;
}
+Vector3 ParticlesMaterial::get_emission_ring_axis() const {
+ return emission_ring_axis;
+}
+
+float ParticlesMaterial::get_emission_ring_height() const {
+ return emission_ring_height;
+}
+
+float ParticlesMaterial::get_emission_ring_radius() const {
+ return emission_ring_radius;
+}
+
+float ParticlesMaterial::get_emission_ring_inner_radius() const {
+ return emission_ring_inner_radius;
+}
+
void ParticlesMaterial::set_gravity(const Vector3 &p_gravity) {
gravity = p_gravity;
Vector3 gset = gravity;
@@ -1046,10 +1114,6 @@ RID ParticlesMaterial::get_shader_rid() const {
}
void ParticlesMaterial::_validate_property(PropertyInfo &property) const {
- if (property.name == "color" && color_ramp.is_valid()) {
- property.usage = PROPERTY_USAGE_NONE;
- }
-
if (property.name == "emission_sphere_radius" && emission_shape != EMISSION_SHAPE_SPHERE) {
property.usage = PROPERTY_USAGE_NONE;
}
@@ -1058,7 +1122,7 @@ void ParticlesMaterial::_validate_property(PropertyInfo &property) const {
property.usage = PROPERTY_USAGE_NONE;
}
- if ((property.name == "emission_point_texture" || property.name == "emission_color_texture") && (emission_shape < EMISSION_SHAPE_POINTS)) {
+ if ((property.name == "emission_point_texture" || property.name == "emission_color_texture") && (emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS)) {
property.usage = PROPERTY_USAGE_NONE;
}
@@ -1070,6 +1134,10 @@ void ParticlesMaterial::_validate_property(PropertyInfo &property) const {
property.usage = PROPERTY_USAGE_NONE;
}
+ if (property.name.begins_with("emission_ring_") && emission_shape != EMISSION_SHAPE_RING) {
+ property.usage = PROPERTY_USAGE_NONE;
+ }
+
if (property.name == "sub_emitter_frequency" && sub_emitter_mode != SUB_EMITTER_CONSTANT) {
property.usage = PROPERTY_USAGE_NONE;
}
@@ -1216,6 +1284,18 @@ void ParticlesMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_emission_point_count", "point_count"), &ParticlesMaterial::set_emission_point_count);
ClassDB::bind_method(D_METHOD("get_emission_point_count"), &ParticlesMaterial::get_emission_point_count);
+ ClassDB::bind_method(D_METHOD("set_emission_ring_axis", "axis"), &ParticlesMaterial::set_emission_ring_axis);
+ ClassDB::bind_method(D_METHOD("get_emission_ring_axis"), &ParticlesMaterial::get_emission_ring_axis);
+
+ ClassDB::bind_method(D_METHOD("set_emission_ring_height", "height"), &ParticlesMaterial::set_emission_ring_height);
+ ClassDB::bind_method(D_METHOD("get_emission_ring_height"), &ParticlesMaterial::get_emission_ring_height);
+
+ ClassDB::bind_method(D_METHOD("set_emission_ring_radius", "radius"), &ParticlesMaterial::set_emission_ring_radius);
+ ClassDB::bind_method(D_METHOD("get_emission_ring_radius"), &ParticlesMaterial::get_emission_ring_radius);
+
+ ClassDB::bind_method(D_METHOD("set_emission_ring_inner_radius", "inner_radius"), &ParticlesMaterial::set_emission_ring_inner_radius);
+ ClassDB::bind_method(D_METHOD("get_emission_ring_inner_radius"), &ParticlesMaterial::get_emission_ring_inner_radius);
+
ClassDB::bind_method(D_METHOD("get_gravity"), &ParticlesMaterial::get_gravity);
ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &ParticlesMaterial::set_gravity);
@@ -1253,13 +1333,17 @@ void ParticlesMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
ADD_GROUP("Emission Shape", "emission_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Box,Points,Directed Points"), "set_emission_shape", "get_emission_shape");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Box,Points,Directed Points,Ring"), "set_emission_shape", "get_emission_shape");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_sphere_radius", PROPERTY_HINT_RANGE, "0.01,128,0.01,or_greater"), "set_emission_sphere_radius", "get_emission_sphere_radius");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_box_extents"), "set_emission_box_extents", "get_emission_box_extents");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "emission_point_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_emission_point_texture", "get_emission_point_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "emission_normal_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_emission_normal_texture", "get_emission_normal_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "emission_color_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_emission_color_texture", "get_emission_color_texture");
ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_point_count", PROPERTY_HINT_RANGE, "0,1000000,1"), "set_emission_point_count", "get_emission_point_count");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_ring_axis"), "set_emission_ring_axis", "get_emission_ring_axis");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_height"), "set_emission_ring_height", "get_emission_ring_height");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_radius"), "set_emission_ring_radius", "get_emission_ring_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_inner_radius"), "set_emission_ring_inner_radius", "get_emission_ring_inner_radius");
ADD_GROUP("ParticleFlags", "particle_flag_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_align_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_rotate_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ROTATE_Y);
@@ -1359,6 +1443,7 @@ void ParticlesMaterial::_bind_methods() {
BIND_ENUM_CONSTANT(EMISSION_SHAPE_BOX);
BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINTS);
BIND_ENUM_CONSTANT(EMISSION_SHAPE_DIRECTED_POINTS);
+ BIND_ENUM_CONSTANT(EMISSION_SHAPE_RING);
BIND_ENUM_CONSTANT(EMISSION_SHAPE_MAX);
BIND_ENUM_CONSTANT(SUB_EMITTER_DISABLED);
@@ -1388,6 +1473,10 @@ ParticlesMaterial::ParticlesMaterial() :
set_emission_shape(EMISSION_SHAPE_POINT);
set_emission_sphere_radius(1);
set_emission_box_extents(Vector3(1, 1, 1));
+ set_emission_ring_axis(Vector3(0, 0, 1.0));
+ set_emission_ring_height(1);
+ set_emission_ring_radius(1);
+ set_emission_ring_inner_radius(0);
set_gravity(Vector3(0, -9.8, 0));
set_lifetime_randomness(0);
diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h
index 3f874bd68c..8b0b26a3d1 100644
--- a/scene/resources/particles_material.h
+++ b/scene/resources/particles_material.h
@@ -74,6 +74,7 @@ public:
EMISSION_SHAPE_BOX,
EMISSION_SHAPE_POINTS,
EMISSION_SHAPE_DIRECTED_POINTS,
+ EMISSION_SHAPE_RING,
EMISSION_SHAPE_MAX
};
@@ -195,6 +196,10 @@ private:
StringName emission_texture_points;
StringName emission_texture_normal;
StringName emission_texture_color;
+ StringName emission_ring_axis;
+ StringName emission_ring_height;
+ StringName emission_ring_radius;
+ StringName emission_ring_inner_radius;
StringName gravity;
@@ -235,6 +240,10 @@ private:
Ref<Texture2D> emission_point_texture;
Ref<Texture2D> emission_normal_texture;
Ref<Texture2D> emission_color_texture;
+ Vector3 emission_ring_axis;
+ float emission_ring_height;
+ float emission_ring_radius;
+ float emission_ring_inner_radius;
int emission_point_count = 1;
bool anim_loop;
@@ -293,6 +302,10 @@ public:
void set_emission_point_texture(const Ref<Texture2D> &p_points);
void set_emission_normal_texture(const Ref<Texture2D> &p_normals);
void set_emission_color_texture(const Ref<Texture2D> &p_colors);
+ void set_emission_ring_axis(Vector3 p_axis);
+ void set_emission_ring_height(float p_height);
+ void set_emission_ring_radius(float p_radius);
+ void set_emission_ring_inner_radius(float p_radius);
void set_emission_point_count(int p_count);
EmissionShape get_emission_shape() const;
@@ -301,6 +314,10 @@ public:
Ref<Texture2D> get_emission_point_texture() const;
Ref<Texture2D> get_emission_normal_texture() const;
Ref<Texture2D> get_emission_color_texture() const;
+ Vector3 get_emission_ring_axis() const;
+ float get_emission_ring_height() const;
+ float get_emission_ring_radius() const;
+ float get_emission_ring_inner_radius() const;
int get_emission_point_count() const;
void set_gravity(const Vector3 &p_gravity);
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index cc3346d182..dfa45cc810 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -714,7 +714,7 @@ int BoxMesh::get_subdivide_depth() const {
BoxMesh::BoxMesh() {}
/**
- CylinderMesh
+ CylinderMesh
*/
void CylinderMesh::_create_mesh_array(Array &p_arr) const {
@@ -955,7 +955,7 @@ void PlaneMesh::_create_mesh_array(Array &p_arr) const {
u /= (subdivide_w + 1.0);
v /= (subdivide_d + 1.0);
- points.push_back(Vector3(-x, 0.0, -z));
+ points.push_back(Vector3(-x, 0.0, -z) + center_offset);
normals.push_back(Vector3(0.0, 1.0, 0.0));
ADD_TANGENT(1.0, 0.0, 0.0, 1.0);
uvs.push_back(Vector2(1.0 - u, 1.0 - v)); /* 1.0 - uv to match orientation with Quad */
@@ -993,10 +993,13 @@ void PlaneMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_subdivide_width"), &PlaneMesh::get_subdivide_width);
ClassDB::bind_method(D_METHOD("set_subdivide_depth", "subdivide"), &PlaneMesh::set_subdivide_depth);
ClassDB::bind_method(D_METHOD("get_subdivide_depth"), &PlaneMesh::get_subdivide_depth);
+ ClassDB::bind_method(D_METHOD("set_center_offset", "offset"), &PlaneMesh::set_center_offset);
+ ClassDB::bind_method(D_METHOD("get_center_offset"), &PlaneMesh::get_center_offset);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_width", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_width", "get_subdivide_width");
ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_depth", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_depth", "get_subdivide_depth");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_offset"), "set_center_offset", "get_center_offset");
}
void PlaneMesh::set_size(const Size2 &p_size) {
@@ -1026,6 +1029,15 @@ int PlaneMesh::get_subdivide_depth() const {
return subdivide_d;
}
+void PlaneMesh::set_center_offset(const Vector3 p_offset) {
+ center_offset = p_offset;
+ _request_update();
+}
+
+Vector3 PlaneMesh::get_center_offset() const {
+ return center_offset;
+}
+
PlaneMesh::PlaneMesh() {}
/**
@@ -1326,10 +1338,10 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const {
Vector2 _size = Vector2(size.x / 2.0f, size.y / 2.0f);
Vector3 quad_faces[4] = {
- Vector3(-_size.x, -_size.y, 0),
- Vector3(-_size.x, _size.y, 0),
- Vector3(_size.x, _size.y, 0),
- Vector3(_size.x, -_size.y, 0),
+ Vector3(-_size.x, -_size.y, 0) + center_offset,
+ Vector3(-_size.x, _size.y, 0) + center_offset,
+ Vector3(_size.x, _size.y, 0) + center_offset,
+ Vector3(_size.x, -_size.y, 0) + center_offset,
};
static const int indices[6] = {
@@ -1365,7 +1377,11 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const {
void QuadMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_size", "size"), &QuadMesh::set_size);
ClassDB::bind_method(D_METHOD("get_size"), &QuadMesh::get_size);
+ ClassDB::bind_method(D_METHOD("set_center_offset", "center_offset"), &QuadMesh::set_center_offset);
+ ClassDB::bind_method(D_METHOD("get_center_offset"), &QuadMesh::get_center_offset);
+
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_offset"), "set_center_offset", "get_center_offset");
}
QuadMesh::QuadMesh() {
@@ -1381,6 +1397,15 @@ Size2 QuadMesh::get_size() const {
return size;
}
+void QuadMesh::set_center_offset(Vector3 p_center_offset) {
+ center_offset = p_center_offset;
+ _request_update();
+}
+
+Vector3 QuadMesh::get_center_offset() const {
+ return center_offset;
+}
+
/**
SphereMesh
*/
diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h
index bd6f94921e..a3de34d3e3 100644
--- a/scene/resources/primitive_meshes.h
+++ b/scene/resources/primitive_meshes.h
@@ -211,6 +211,7 @@ private:
Size2 size = Size2(2.0, 2.0);
int subdivide_w = 0;
int subdivide_d = 0;
+ Vector3 center_offset;
protected:
static void _bind_methods();
@@ -226,6 +227,9 @@ public:
void set_subdivide_depth(const int p_divisions);
int get_subdivide_depth() const;
+ void set_center_offset(const Vector3 p_offset);
+ Vector3 get_center_offset() const;
+
PlaneMesh();
};
@@ -274,6 +278,7 @@ class QuadMesh : public PrimitiveMesh {
private:
Size2 size = Size2(1.0, 1.0);
+ Vector3 center_offset;
protected:
static void _bind_methods();
@@ -284,6 +289,9 @@ public:
void set_size(const Size2 &p_size);
Size2 get_size() const;
+
+ void set_center_offset(const Vector3 p_offset);
+ Vector3 get_center_offset() const;
};
/**
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index ee61e64ed3..3f6e926aa7 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -35,8 +35,9 @@
#include "core/io/resource_format_binary.h"
#include "core/version.h"
-//version 2: changed names for basis, aabb, Vectors, etc.
-#define FORMAT_VERSION 2
+// Version 2: changed names for Basis, AABB, Vectors, etc.
+// Version 3: new string ID for ext/subresources, breaks forward compat.
+#define FORMAT_VERSION 3
#include "core/io/dir_access.h"
#include "core/version.h"
@@ -56,22 +57,23 @@ Ref<Resource> ResourceLoaderText::get_resource() {
Error ResourceLoaderText::_parse_sub_resource_dummy(DummyReadData *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
VariantParser::Token token;
VariantParser::get_token(p_stream, token, line, r_err_str);
- if (token.type != VariantParser::TK_NUMBER) {
- r_err_str = "Expected number (sub-resource index)";
+ if (token.type != VariantParser::TK_NUMBER && token.type != VariantParser::TK_STRING) {
+ r_err_str = "Expected number (old style) or string (sub-resource index)";
return ERR_PARSE_ERROR;
}
- int index = token.value;
+ String unique_id = token.value;
- if (!p_data->resource_map.has(index)) {
+ if (!p_data->resource_map.has(unique_id)) {
Ref<DummyResource> dr;
dr.instantiate();
- dr->set_subindex(index);
- p_data->resource_map[index] = dr;
- p_data->resource_set.insert(dr);
+ dr->set_scene_unique_id(unique_id);
+ p_data->resource_map[unique_id] = dr;
+ uint32_t im_size = p_data->resource_index_map.size();
+ p_data->resource_index_map.insert(dr, im_size);
}
- r_res = p_data->resource_map[index];
+ r_res = p_data->resource_map[unique_id];
VariantParser::get_token(p_stream, token, line, r_err_str);
if (token.type != VariantParser::TK_PARENTHESIS_CLOSE) {
@@ -85,12 +87,12 @@ Error ResourceLoaderText::_parse_sub_resource_dummy(DummyReadData *p_data, Varia
Error ResourceLoaderText::_parse_ext_resource_dummy(DummyReadData *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
VariantParser::Token token;
VariantParser::get_token(p_stream, token, line, r_err_str);
- if (token.type != VariantParser::TK_NUMBER) {
- r_err_str = "Expected number (sub-resource index)";
+ if (token.type != VariantParser::TK_NUMBER && token.type != VariantParser::TK_STRING) {
+ r_err_str = "Expected number (old style sub-resource index) or String (ext-resource ID)";
return ERR_PARSE_ERROR;
}
- int id = token.value;
+ String id = token.value;
ERR_FAIL_COND_V(!p_data->rev_external_resources.has(id), ERR_PARSE_ERROR);
@@ -108,14 +110,14 @@ Error ResourceLoaderText::_parse_ext_resource_dummy(DummyReadData *p_data, Varia
Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
VariantParser::Token token;
VariantParser::get_token(p_stream, token, line, r_err_str);
- if (token.type != VariantParser::TK_NUMBER) {
- r_err_str = "Expected number (sub-resource index)";
+ if (token.type != VariantParser::TK_NUMBER && token.type != VariantParser::TK_STRING) {
+ r_err_str = "Expected number (old style sub-resource index) or string";
return ERR_PARSE_ERROR;
}
- int index = token.value;
- ERR_FAIL_COND_V(!int_resources.has(index), ERR_INVALID_PARAMETER);
- r_res = int_resources[index];
+ String id = token.value;
+ ERR_FAIL_COND_V(!int_resources.has(id), ERR_INVALID_PARAMETER);
+ r_res = int_resources[id];
VariantParser::get_token(p_stream, token, line, r_err_str);
if (token.type != VariantParser::TK_PARENTHESIS_CLOSE) {
@@ -129,16 +131,16 @@ Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, R
Error ResourceLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
VariantParser::Token token;
VariantParser::get_token(p_stream, token, line, r_err_str);
- if (token.type != VariantParser::TK_NUMBER) {
- r_err_str = "Expected number (sub-resource index)";
+ if (token.type != VariantParser::TK_NUMBER && token.type != VariantParser::TK_STRING) {
+ r_err_str = "Expected number (old style sub-resource index) or String (ext-resource ID)";
return ERR_PARSE_ERROR;
}
- int id = token.value;
+ String id = token.value;
if (!ignore_resource_parsing) {
if (!ext_resources.has(id)) {
- r_err_str = "Can't load cached ext-resource #" + itos(id);
+ r_err_str = "Can't load cached ext-resource id: " + id;
return ERR_PARSE_ERROR;
}
@@ -409,7 +411,18 @@ Error ResourceLoaderText::load() {
String path = next_tag.fields["path"];
String type = next_tag.fields["type"];
- int index = next_tag.fields["id"];
+ String id = next_tag.fields["id"];
+
+ if (next_tag.fields.has("uid")) {
+ String uidt = next_tag.fields["uid"];
+ ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(uidt);
+ if (uid != ResourceUID::INVALID_ID && ResourceUID::get_singleton()->has_id(uid)) {
+ // If a UID is found and the path is valid, it will be used, otherwise, it falls back to the path.
+ path = ResourceUID::get_singleton()->get_id_path(uid);
+ } else {
+ WARN_PRINT(String(res_path + ":" + itos(lines) + " - ext_resource, invalid UUID: " + uidt + " - using text path instead: " + path).utf8().get_data());
+ }
+ }
if (path.find("://") == -1 && path.is_rel_path()) {
// path is relative to file being loaded, so convert to a resource path
@@ -453,14 +466,14 @@ Error ResourceLoaderText::load() {
} else {
#ifdef TOOLS_ENABLED
//remember ID for saving
- res->set_id_for_path(local_path, index);
+ res->set_id_for_path(local_path, id);
#endif
}
er.cache = res;
}
- ext_resources[index] = er;
+ ext_resources[id] = er;
error = VariantParser::parse_tag(&stream, lines, error_text, next_tag, &rp);
@@ -489,15 +502,15 @@ Error ResourceLoaderText::load() {
if (!next_tag.fields.has("id")) {
error = ERR_FILE_CORRUPT;
- error_text = "Missing 'index' in external resource tag";
+ error_text = "Missing 'id' in external resource tag";
_printerr();
return error;
}
String type = next_tag.fields["type"];
- int id = next_tag.fields["id"];
+ String id = next_tag.fields["id"];
- String path = local_path + "::" + itos(id);
+ String path = local_path + "::" + id;
//bool exists=ResourceCache::has(path);
@@ -575,7 +588,7 @@ Error ResourceLoaderText::load() {
int_resources[id] = res; //always assign int resources
if (do_assign && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
- res->set_subindex(id);
+ res->set_scene_unique_id(id);
}
if (progress && resources_total > 0) {
@@ -736,7 +749,7 @@ void ResourceLoaderText::get_dependencies(FileAccess *p_f, List<String> *p_depen
if (!next_tag.fields.has("id")) {
error = ERR_FILE_CORRUPT;
- error_text = "Missing 'index' in external resource tag";
+ error_text = "Missing 'id' in external resource tag";
_printerr();
return;
}
@@ -744,7 +757,18 @@ void ResourceLoaderText::get_dependencies(FileAccess *p_f, List<String> *p_depen
String path = next_tag.fields["path"];
String type = next_tag.fields["type"];
- if (path.find("://") == -1 && path.is_rel_path()) {
+ bool using_uid = false;
+ if (next_tag.fields.has("uid")) {
+ //if uid exists, return uid in text format, not the path
+ String uidt = next_tag.fields["uid"];
+ ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(uidt);
+ if (uid != ResourceUID::INVALID_ID) {
+ path = ResourceUID::get_singleton()->id_to_text(uid);
+ using_uid = true;
+ }
+ }
+
+ if (!using_uid && path.find("://") == -1 && path.is_rel_path()) {
// path is relative to file being loaded, so convert to a resource path
path = ProjectSettings::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
}
@@ -814,9 +838,17 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p
}
String path = next_tag.fields["path"];
- int index = next_tag.fields["id"];
+ String id = next_tag.fields["id"];
String type = next_tag.fields["type"];
+ if (next_tag.fields.has("uid")) {
+ String uidt = next_tag.fields["uid"];
+ ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(uidt);
+ if (uid != ResourceUID::INVALID_ID && ResourceUID::get_singleton()->has_id(uid)) {
+ // If a UID is found and the path is valid, it will be used, otherwise, it falls back to the path.
+ path = ResourceUID::get_singleton()->get_id_path(uid);
+ }
+ }
bool relative = false;
if (!path.begins_with("res://")) {
path = base_path.plus_file(path).simplify_path();
@@ -833,7 +865,14 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p
path = base_path.path_to_file(path);
}
- fw->store_line("[ext_resource path=\"" + path + "\" type=\"" + type + "\" id=" + itos(index) + "]");
+ String s = "[ext_resource type=\"" + type + "\"";
+
+ ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(path);
+ if (uid != ResourceUID::INVALID_ID) {
+ s += " uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\"";
+ }
+ s += " path=\"" + path + "\" id=\"" + id + "\"]";
+ fw->store_line(s); // Bundled.
tag_end = f->get_position();
}
@@ -919,6 +958,12 @@ void ResourceLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) {
return;
}
+ if (tag.fields.has("uid")) {
+ res_uid = ResourceUID::get_singleton()->text_to_id(tag.fields["uid"]);
+ } else {
+ res_uid = ResourceUID::INVALID_ID;
+ }
+
if (tag.fields.has("load_steps")) {
resources_total = tag.fields["load_steps"];
} else {
@@ -974,7 +1019,12 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
bs_save_unicode_string(wf.f, is_scene ? "PackedScene" : resource_type);
wf->store_64(0); //offset to import metadata, this is no longer used
- for (int i = 0; i < 14; i++) {
+
+ f->store_32(ResourceFormatSaverBinaryInstance::FORMAT_FLAG_NAMED_SCENE_IDS | ResourceFormatSaverBinaryInstance::FORMAT_FLAG_UIDS);
+
+ f->store_64(res_uid);
+
+ for (int i = 0; i < 5; i++) {
wf->store_32(0); // reserved
}
@@ -1015,17 +1065,23 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
String path = next_tag.fields["path"];
String type = next_tag.fields["type"];
- int index = next_tag.fields["id"];
+ String id = next_tag.fields["id"];
+ ResourceUID::ID uid = ResourceUID::INVALID_ID;
+ if (next_tag.fields.has("uid")) {
+ String uidt = next_tag.fields["uid"];
+ uid = ResourceUID::get_singleton()->text_to_id(uidt);
+ }
bs_save_unicode_string(wf.f, type);
bs_save_unicode_string(wf.f, path);
+ wf.f->store_64(uid);
int lindex = dummy_read.external_resources.size();
Ref<DummyResource> dr;
dr.instantiate();
dr->set_path("res://dummy" + itos(lindex)); //anything is good to detect it for saving as external
dummy_read.external_resources[dr] = lindex;
- dummy_read.rev_external_resources[index] = dr;
+ dummy_read.rev_external_resources[id] = dr;
error = VariantParser::parse_tag(&stream, lines, error_text, next_tag, &rp);
@@ -1069,7 +1125,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
if (!next_tag.fields.has("id")) {
error = ERR_FILE_CORRUPT;
- error_text = "Missing 'index' in external resource tag";
+ error_text = "Missing 'id' in external resource tag";
_printerr();
return error;
}
@@ -1114,7 +1170,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
if (assign != String()) {
Map<StringName, int> empty_string_map; //unused
bs_save_unicode_string(wf2, assign, true);
- ResourceFormatSaverBinaryInstance::write_variant(wf2, value, dummy_read.resource_set, dummy_read.external_resources, empty_string_map);
+ ResourceFormatSaverBinaryInstance::write_variant(wf2, value, dummy_read.resource_index_map, dummy_read.external_resources, empty_string_map);
prop_count++;
} else if (next_tag.name != String()) {
@@ -1165,17 +1221,17 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
int prop_count = 0;
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
+ for (const PropertyInfo &E : props) {
+ if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
- String name = E->get().name;
+ String name = E.name;
Variant value = packed_scene->get(name);
Map<StringName, int> empty_string_map; //unused
bs_save_unicode_string(wf2, name, true);
- ResourceFormatSaverBinaryInstance::write_variant(wf2, value, dummy_read.resource_set, dummy_read.external_resources, empty_string_map);
+ ResourceFormatSaverBinaryInstance::write_variant(wf2, value, dummy_read.resource_index_map, dummy_read.external_resources, empty_string_map);
prop_count++;
}
@@ -1255,6 +1311,32 @@ String ResourceLoaderText::recognize(FileAccess *p_f) {
return tag.fields["type"];
}
+ResourceUID::ID ResourceLoaderText::get_uid(FileAccess *p_f) {
+ error = OK;
+
+ lines = 1;
+ f = p_f;
+
+ stream.f = f;
+
+ ignore_resource_parsing = true;
+
+ VariantParser::Tag tag;
+ Error err = VariantParser::parse_tag(&stream, lines, error_text, tag);
+
+ if (err) {
+ _printerr();
+ return ResourceUID::INVALID_ID;
+ }
+
+ if (tag.fields.has("uid")) { //field is optional
+ String uidt = tag.fields["uid"];
+ return ResourceUID::get_singleton()->text_to_id(uidt);
+ }
+
+ return ResourceUID::INVALID_ID;
+}
+
/////////////////////
RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
@@ -1275,7 +1357,6 @@ RES ResourceFormatLoaderText::load(const String &p_path, const String &p_origina
loader.local_path = ProjectSettings::get_singleton()->localize_path(path);
loader.progress = r_progress;
loader.res_path = loader.local_path;
- //loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
loader.open(f);
err = loader.load();
if (r_error) {
@@ -1318,7 +1399,7 @@ String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
return String();
}
- //for anyhting else must test..
+ // ...for anything else must test...
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
@@ -1328,11 +1409,28 @@ String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
ResourceLoaderText loader;
loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
loader.res_path = loader.local_path;
- //loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
String r = loader.recognize(f);
return ClassDB::get_compatibility_remapped_class(r);
}
+ResourceUID::ID ResourceFormatLoaderText::get_resource_uid(const String &p_path) const {
+ String ext = p_path.get_extension().to_lower();
+
+ if (ext != "tscn" && ext != "tres") {
+ return ResourceUID::INVALID_ID;
+ }
+
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
+ if (!f) {
+ return ResourceUID::INVALID_ID; //could not read
+ }
+
+ ResourceLoaderText loader;
+ loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ loader.res_path = loader.local_path;
+ return loader.get_uid(f);
+}
+
void ResourceFormatLoaderText::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
@@ -1342,7 +1440,6 @@ void ResourceFormatLoaderText::get_dependencies(const String &p_path, List<Strin
ResourceLoaderText loader;
loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
loader.res_path = loader.local_path;
- //loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
loader.get_dependencies(f, p_dependencies, p_add_types);
}
@@ -1355,7 +1452,6 @@ Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const
ResourceLoaderText loader;
loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
loader.res_path = loader.local_path;
- //loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
return loader.rename_dependencies(f, p_path, p_map);
}
@@ -1371,7 +1467,6 @@ Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path,
const String &path = p_src_path;
loader.local_path = ProjectSettings::get_singleton()->localize_path(path);
loader.res_path = loader.local_path;
- //loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
loader.open(f);
return loader.save_as_binary(f, p_dst_path);
}
@@ -1394,10 +1489,10 @@ String ResourceFormatSaverTextInstance::_write_resources(void *ud, const RES &p_
String ResourceFormatSaverTextInstance::_write_resource(const RES &res) {
if (external_resources.has(res)) {
- return "ExtResource( " + itos(external_resources[res]) + " )";
+ return "ExtResource( \"" + external_resources[res] + "\" )";
} else {
if (internal_resources.has(res)) {
- return "SubResource( " + itos(internal_resources[res]) + " )";
+ return "SubResource( \"" + internal_resources[res] + "\" )";
} else if (res->get_path().length() && res->get_path().find("::") == -1) {
if (res->get_path() == local_path) { //circular reference attempt
return "null";
@@ -1426,8 +1521,11 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
ERR_PRINT("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded.");
return;
}
- int index = external_resources.size();
- external_resources[res] = index;
+
+ // Use a numeric ID as a base, because they are sorted in natural order before saving.
+ // This increases the chances of thread loading to fetch them first.
+ String id = itos(external_resources.size() + 1) + "_" + Resource::generate_scene_unique_id();
+ external_resources[res] = id;
return;
}
@@ -1483,8 +1581,8 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
Dictionary d = p_variant;
List<Variant> keys;
d.get_key_list(&keys);
- for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
- Variant v = d[E->get()];
+ for (const Variant &E : keys) {
+ Variant v = d[E];
_find_resources(v);
}
} break;
@@ -1513,11 +1611,11 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
takeover_paths = false;
}
- // save resources
+ // Save resources.
_find_resources(p_resource, true);
if (packed_scene.is_valid()) {
- //add instances to external resources if saving a packed scene
+ // Add instances to external resources if saving a packed scene.
for (int i = 0; i < packed_scene->get_state()->get_node_count(); i++) {
if (packed_scene->get_state()->is_node_instance_placeholder(i)) {
continue;
@@ -1525,8 +1623,8 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
Ref<PackedScene> instance = packed_scene->get_state()->get_node_instance(i);
if (instance.is_valid() && !external_resources.has(instance)) {
- int index = external_resources.size();
- external_resources[instance] = index;
+ int index = external_resources.size() + 1;
+ external_resources[instance] = itos(index) + "_" + Resource::generate_scene_unique_id(); // Keep the order for improved thread loading performance.
}
}
}
@@ -1537,64 +1635,74 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
title += "type=\"" + p_resource->get_class() + "\" ";
}
int load_steps = saved_resources.size() + external_resources.size();
- /*
- if (packed_scene.is_valid()) {
- load_steps+=packed_scene->get_node_count();
- }
- //no, better to not use load steps from nodes, no point to that
- */
if (load_steps > 1) {
title += "load_steps=" + itos(load_steps) + " ";
}
title += "format=" + itos(FORMAT_VERSION) + "";
+ ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(local_path, true);
+
+ if (uid != ResourceUID::INVALID_ID) {
+ title += " uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\"";
+ }
+
f->store_string(title);
- f->store_line("]\n"); //one empty line
+ f->store_line("]\n"); // One empty line.
}
#ifdef TOOLS_ENABLED
- //keep order from cached ids
- Set<int> cached_ids_found;
- for (Map<RES, int>::Element *E = external_resources.front(); E; E = E->next()) {
- int cached_id = E->key()->get_id_for_path(local_path);
- if (cached_id < 0 || cached_ids_found.has(cached_id)) {
- E->get() = -1; //reset
+ // Keep order from cached ids.
+ Set<String> cached_ids_found;
+ for (Map<RES, String>::Element *E = external_resources.front(); E; E = E->next()) {
+ String cached_id = E->key()->get_id_for_path(local_path);
+ if (cached_id == "" || cached_ids_found.has(cached_id)) {
+ int sep_pos = E->get().find("_");
+ if (sep_pos != -1) {
+ E->get() = E->get().substr(0, sep_pos + 1); // Keep the order found, for improved thread loading performance.
+ } else {
+ E->get() = "";
+ }
+
} else {
E->get() = cached_id;
cached_ids_found.insert(cached_id);
}
}
- //create IDs for non cached resources
- for (Map<RES, int>::Element *E = external_resources.front(); E; E = E->next()) {
- if (cached_ids_found.has(E->get())) { //already cached, go on
+ // Create IDs for non cached resources.
+ for (Map<RES, String>::Element *E = external_resources.front(); E; E = E->next()) {
+ if (cached_ids_found.has(E->get())) { // Already cached, go on.
continue;
}
- int attempt = 1; //start from one, more readable format
- while (cached_ids_found.has(attempt)) {
- attempt++;
+ String attempt;
+ while (true) {
+ attempt = E->get() + Resource::generate_scene_unique_id();
+ if (!cached_ids_found.has(attempt)) {
+ break;
+ }
}
cached_ids_found.insert(attempt);
E->get() = attempt;
- //update also in resource
+ // Update also in resource.
Ref<Resource> res = E->key();
res->set_id_for_path(local_path, attempt);
}
#else
- //make sure to start from one, as it makes format more readable
- for (Map<RES, int>::Element *E = external_resources.front(); E; E = E->next()) {
- E->get() = E->get() + 1;
+ // Make sure to start from one, as it makes format more readable.
+ int counter = 1;
+ for (Map<RES, String>::Element *E = external_resources.front(); E; E = E->next()) {
+ E->get() = itos(counter++);
}
#endif
Vector<ResourceSort> sorted_er;
- for (Map<RES, int>::Element *E = external_resources.front(); E; E = E->next()) {
+ for (Map<RES, String>::Element *E = external_resources.front(); E; E = E->next()) {
ResourceSort rs;
rs.resource = E->key();
- rs.index = E->get();
+ rs.id = E->get();
sorted_er.push_back(rs);
}
@@ -1603,23 +1711,30 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
for (int i = 0; i < sorted_er.size(); i++) {
String p = sorted_er[i].resource->get_path();
- f->store_string("[ext_resource path=\"" + p + "\" type=\"" + sorted_er[i].resource->get_save_class() + "\" id=" + itos(sorted_er[i].index) + "]\n"); //bundled
+ String s = "[ext_resource type=\"" + sorted_er[i].resource->get_save_class() + "\"";
+
+ ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(p, false);
+ if (uid != ResourceUID::INVALID_ID) {
+ s += " uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\"";
+ }
+ s += " path=\"" + p + "\" id=\"" + sorted_er[i].id + "\"]\n";
+ f->store_string(s); // Bundled.
}
if (external_resources.size()) {
- f->store_line(String()); //separate
+ f->store_line(String()); // Separate.
}
- Set<int> used_indices;
+ Set<String> used_unique_ids;
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
RES res = E->get();
if (E->next() && (res->get_path() == "" || res->get_path().find("::") != -1)) {
- if (res->get_subindex() != 0) {
- if (used_indices.has(res->get_subindex())) {
- res->set_subindex(0); //repeated
+ if (res->get_scene_unique_id() != "") {
+ if (used_unique_ids.has(res->get_scene_unique_id())) {
+ res->set_scene_unique_id(""); // Repeated.
} else {
- used_indices.insert(res->get_subindex());
+ used_unique_ids.insert(res->get_scene_unique_id());
}
}
}
@@ -1631,31 +1746,35 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
bool main = (E->next() == nullptr);
if (main && packed_scene.is_valid()) {
- break; //save as a scene
+ break; // Save as a scene.
}
if (main) {
f->store_line("[resource]");
} else {
String line = "[sub_resource ";
- if (res->get_subindex() == 0) {
- int new_subindex = 1;
- if (used_indices.size()) {
- new_subindex = used_indices.back()->get() + 1;
+ if (res->get_scene_unique_id() == "") {
+ String new_id;
+ while (true) {
+ new_id = res->get_class() + "_" + Resource::generate_scene_unique_id();
+
+ if (!used_unique_ids.has(new_id)) {
+ break;
+ }
}
- res->set_subindex(new_subindex);
- used_indices.insert(new_subindex);
+ res->set_scene_unique_id(new_id);
+ used_unique_ids.insert(new_id);
}
- int idx = res->get_subindex();
- line += "type=\"" + res->get_class() + "\" id=" + itos(idx);
- f->store_line(line + "]");
+ String id = res->get_scene_unique_id();
+ line += "type=\"" + res->get_class() + "\" id=\"" + id;
+ f->store_line(line + "\"]");
if (takeover_paths) {
- res->set_path(p_path + "::" + itos(idx), true);
+ res->set_path(p_path + "::" + id, true);
}
- internal_resources[res] = idx;
+ internal_resources[res] = id;
#ifdef TOOLS_ENABLED
res->set_edited(false);
#endif
@@ -1663,7 +1782,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
List<PropertyInfo> property_list;
res->get_property_list(&property_list);
- //property_list.sort();
for (List<PropertyInfo>::Element *PE = property_list.front(); PE; PE = PE->next()) {
if (skip_editor && PE->get().name.begins_with("__editor")) {
continue;
@@ -1704,7 +1822,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
}
if (packed_scene.is_valid()) {
- //if this is a scene, save nodes and connections!
+ // If this is a scene, save nodes and connections!
Ref<SceneState> state = packed_scene->get_state();
for (int i = 0; i < state->get_node_count(); i++) {
StringName type = state->get_node_type(i);
@@ -1812,7 +1930,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
}
f->close();
- //memdelete(f);
return OK;
}
diff --git a/scene/resources/resource_format_text.h b/scene/resources/resource_format_text.h
index f5d9cca859..373e71b2c4 100644
--- a/scene/resources/resource_format_text.h
+++ b/scene/resources/resource_format_text.h
@@ -58,10 +58,8 @@ class ResourceLoaderText {
bool ignore_resource_parsing = false;
- //Map<String,String> remaps;
-
- Map<int, ExtResource> ext_resources;
- Map<int, RES> int_resources;
+ Map<String, ExtResource> ext_resources;
+ Map<String, RES> int_resources;
int resources_total = 0;
int resource_current = 0;
@@ -76,8 +74,9 @@ class ResourceLoaderText {
mutable int lines = 0;
+ ResourceUID::ID res_uid = ResourceUID::INVALID_ID;
+
Map<String, String> remaps;
- //void _printerr();
static Error _parse_sub_resources(void *p_self, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) { return reinterpret_cast<ResourceLoaderText *>(p_self)->_parse_sub_resource(p_stream, r_res, line, r_err_str); }
static Error _parse_ext_resources(void *p_self, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) { return reinterpret_cast<ResourceLoaderText *>(p_self)->_parse_ext_resource(p_stream, r_res, line, r_err_str); }
@@ -92,9 +91,9 @@ class ResourceLoaderText {
struct DummyReadData {
Map<RES, int> external_resources;
- Map<int, RES> rev_external_resources;
- Set<RES> resource_set;
- Map<int, RES> resource_map;
+ Map<String, RES> rev_external_resources;
+ Map<RES, int> resource_index_map;
+ Map<String, RES> resource_map;
};
static Error _parse_sub_resource_dummys(void *p_self, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) { return _parse_sub_resource_dummy((DummyReadData *)(p_self), p_stream, r_res, line, r_err_str); }
@@ -123,6 +122,7 @@ public:
void open(FileAccess *p_f, bool p_skip_first_tag = false);
String recognize(FileAccess *p_f);
+ ResourceUID::ID get_uid(FileAccess *p_f);
void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types);
Error rename_dependencies(FileAccess *p_f, const String &p_path, const Map<String, String> &p_map);
@@ -139,6 +139,7 @@ public:
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
+ virtual ResourceUID::ID get_resource_uid(const String &p_path) const;
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
virtual Error rename_dependencies(const String &p_path, const Map<String, String> &p_map);
@@ -168,14 +169,14 @@ class ResourceFormatSaverTextInstance {
Set<RES> resource_set;
List<RES> saved_resources;
- Map<RES, int> external_resources;
- Map<RES, int> internal_resources;
+ Map<RES, String> external_resources;
+ Map<RES, String> internal_resources;
struct ResourceSort {
RES resource;
- int index = 0;
+ String id;
bool operator<(const ResourceSort &p_right) const {
- return index < p_right.index;
+ return id.naturalnocasecmp_to(p_right.id) < 0;
}
};
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index f19d08dbb1..424a54f344 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -72,13 +72,12 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const {
params_cache.clear();
params_cache_dirty = false;
- for (List<PropertyInfo>::Element *E = local.front(); E; E = E->next()) {
- PropertyInfo pi = E->get();
+ for (PropertyInfo &pi : local) {
if (default_textures.has(pi.name)) { //do not show default textures
continue;
}
pi.name = "shader_param/" + pi.name;
- params_cache[pi.name] = E->get().name;
+ params_cache[pi.name] = pi.name;
if (p_params) {
//small little hack
if (pi.type == Variant::RID) {
diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp
index 89b3336118..ec00f9d7b7 100644
--- a/scene/resources/sky_material.cpp
+++ b/scene/resources/sky_material.cpp
@@ -30,6 +30,9 @@
#include "sky_material.h"
+Mutex ProceduralSkyMaterial::shader_mutex;
+RID ProceduralSkyMaterial::shader;
+
void ProceduralSkyMaterial::set_sky_top_color(const Color &p_sky_top) {
sky_top_color = p_sky_top;
RS::get_singleton()->material_set_param(_get_material(), "sky_top_color", sky_top_color.to_linear());
@@ -128,7 +131,17 @@ Shader::Mode ProceduralSkyMaterial::get_shader_mode() const {
return Shader::MODE_SKY;
}
+RID ProceduralSkyMaterial::get_rid() const {
+ _update_shader();
+ if (!shader_set) {
+ RS::get_singleton()->material_set_shader(_get_material(), shader);
+ shader_set = true;
+ }
+ return _get_material();
+}
+
RID ProceduralSkyMaterial::get_shader_rid() const {
+ _update_shader();
return shader;
}
@@ -180,72 +193,89 @@ void ProceduralSkyMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_curve", PROPERTY_HINT_EXP_EASING), "set_sun_curve", "get_sun_curve");
}
-ProceduralSkyMaterial::ProceduralSkyMaterial() {
- String code = "shader_type sky;\n\n";
-
- code += "uniform vec4 sky_top_color : hint_color = vec4(0.35, 0.46, 0.71, 1.0);\n";
- code += "uniform vec4 sky_horizon_color : hint_color = vec4(0.55, 0.69, 0.81, 1.0);\n";
- code += "uniform float sky_curve : hint_range(0, 1) = 0.09;\n";
- code += "uniform float sky_energy = 1.0;\n\n";
- code += "uniform vec4 ground_bottom_color : hint_color = vec4(0.12, 0.12, 0.13, 1.0);\n";
- code += "uniform vec4 ground_horizon_color : hint_color = vec4(0.37, 0.33, 0.31, 1.0);\n";
- code += "uniform float ground_curve : hint_range(0, 1) = 0.02;\n";
- code += "uniform float ground_energy = 1.0;\n\n";
- code += "uniform float sun_angle_max = 1.74;\n";
- code += "uniform float sun_curve : hint_range(0, 1) = 0.05;\n\n";
- code += "void sky() {\n";
- code += "\tfloat v_angle = acos(clamp(EYEDIR.y, -1.0, 1.0));\n";
- code += "\tfloat c = (1.0 - v_angle / (PI * 0.5));\n";
- code += "\tvec3 sky = mix(sky_horizon_color.rgb, sky_top_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / sky_curve), 0.0, 1.0));\n";
- code += "\tsky *= sky_energy;\n";
- code += "\tif (LIGHT0_ENABLED) {\n";
- code += "\t\tfloat sun_angle = acos(dot(LIGHT0_DIRECTION, EYEDIR));\n";
- code += "\t\tif (sun_angle < LIGHT0_SIZE) {\n";
- code += "\t\t\tsky = LIGHT0_COLOR * LIGHT0_ENERGY;\n";
- code += "\t\t} else if (sun_angle < sun_angle_max) {\n";
- code += "\t\t\tfloat c2 = (sun_angle - LIGHT0_SIZE) / (sun_angle_max - LIGHT0_SIZE);\n";
- code += "\t\t\tsky = mix(LIGHT0_COLOR * LIGHT0_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n";
- code += "\t\t}\n";
- code += "\t}\n";
- code += "\tif (LIGHT1_ENABLED) {\n";
- code += "\t\tfloat sun_angle = acos(dot(LIGHT1_DIRECTION, EYEDIR));\n";
- code += "\t\tif (sun_angle < LIGHT1_SIZE) {\n";
- code += "\t\t\tsky = LIGHT1_COLOR * LIGHT1_ENERGY;\n";
- code += "\t\t} else if (sun_angle < sun_angle_max) {\n";
- code += "\t\t\tfloat c2 = (sun_angle - LIGHT1_SIZE) / (sun_angle_max - LIGHT1_SIZE);\n";
- code += "\t\t\tsky = mix(LIGHT1_COLOR * LIGHT1_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n";
- code += "\t\t}\n";
- code += "\t}\n";
- code += "\tif (LIGHT2_ENABLED) {\n";
- code += "\t\tfloat sun_angle = acos(dot(LIGHT2_DIRECTION, EYEDIR));\n";
- code += "\t\tif (sun_angle < LIGHT2_SIZE) {\n";
- code += "\t\t\tsky = LIGHT2_COLOR * LIGHT2_ENERGY;\n";
- code += "\t\t} else if (sun_angle < sun_angle_max) {\n";
- code += "\t\t\tfloat c2 = (sun_angle - LIGHT2_SIZE) / (sun_angle_max - LIGHT2_SIZE);\n";
- code += "\t\t\tsky = mix(LIGHT2_COLOR * LIGHT2_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n";
- code += "\t\t}\n";
- code += "\t}\n";
- code += "\tif (LIGHT3_ENABLED) {\n";
- code += "\t\tfloat sun_angle = acos(dot(LIGHT3_DIRECTION, EYEDIR));\n";
- code += "\t\tif (sun_angle < LIGHT3_SIZE) {\n";
- code += "\t\t\tsky = LIGHT3_COLOR * LIGHT3_ENERGY;\n";
- code += "\t\t} else if (sun_angle < sun_angle_max) {\n";
- code += "\t\t\tfloat c2 = (sun_angle - LIGHT3_SIZE) / (sun_angle_max - LIGHT3_SIZE);\n";
- code += "\t\t\tsky = mix(LIGHT3_COLOR * LIGHT3_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n";
- code += "\t\t}\n";
- code += "\t}\n";
- code += "\tc = (v_angle - (PI * 0.5)) / (PI * 0.5);\n";
- code += "\tvec3 ground = mix(ground_horizon_color.rgb, ground_bottom_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / ground_curve), 0.0, 1.0));\n";
- code += "\tground *= ground_energy;\n";
- code += "\tCOLOR = mix(ground, sky, step(0.0, EYEDIR.y));\n";
- code += "}\n";
-
- shader = RS::get_singleton()->shader_create();
-
- RS::get_singleton()->shader_set_code(shader, code);
-
- RS::get_singleton()->material_set_shader(_get_material(), shader);
+void ProceduralSkyMaterial::cleanup_shader() {
+ if (shader.is_valid()) {
+ RS::get_singleton()->free(shader);
+ }
+}
+
+void ProceduralSkyMaterial::_update_shader() {
+ shader_mutex.lock();
+ if (shader.is_null()) {
+ shader = RS::get_singleton()->shader_create();
+
+ RS::get_singleton()->shader_set_code(shader, R"(
+shader_type sky;
+
+uniform vec4 sky_top_color : hint_color = vec4(0.35, 0.46, 0.71, 1.0);
+uniform vec4 sky_horizon_color : hint_color = vec4(0.55, 0.69, 0.81, 1.0);
+uniform float sky_curve : hint_range(0, 1) = 0.09;
+uniform float sky_energy = 1.0;
+uniform vec4 ground_bottom_color : hint_color = vec4(0.12, 0.12, 0.13, 1.0);
+uniform vec4 ground_horizon_color : hint_color = vec4(0.37, 0.33, 0.31, 1.0);
+uniform float ground_curve : hint_range(0, 1) = 0.02;
+uniform float ground_energy = 1.0;
+uniform float sun_angle_max = 1.74;
+uniform float sun_curve : hint_range(0, 1) = 0.05;
+
+void sky() {
+ float v_angle = acos(clamp(EYEDIR.y, -1.0, 1.0));
+ float c = (1.0 - v_angle / (PI * 0.5));
+ vec3 sky = mix(sky_horizon_color.rgb, sky_top_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / sky_curve), 0.0, 1.0));
+ sky *= sky_energy;
+
+ if (LIGHT0_ENABLED) {
+ float sun_angle = acos(dot(LIGHT0_DIRECTION, EYEDIR));
+ if (sun_angle < LIGHT0_SIZE) {
+ sky = LIGHT0_COLOR * LIGHT0_ENERGY;
+ } else if (sun_angle < sun_angle_max) {
+ float c2 = (sun_angle - LIGHT0_SIZE) / (sun_angle_max - LIGHT0_SIZE);
+ sky = mix(LIGHT0_COLOR * LIGHT0_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));
+ }
+ }
+
+ if (LIGHT1_ENABLED) {
+ float sun_angle = acos(dot(LIGHT1_DIRECTION, EYEDIR));
+ if (sun_angle < LIGHT1_SIZE) {
+ sky = LIGHT1_COLOR * LIGHT1_ENERGY;
+ } else if (sun_angle < sun_angle_max) {
+ float c2 = (sun_angle - LIGHT1_SIZE) / (sun_angle_max - LIGHT1_SIZE);
+ sky = mix(LIGHT1_COLOR * LIGHT1_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));
+ }
+ }
+
+ if (LIGHT2_ENABLED) {
+ float sun_angle = acos(dot(LIGHT2_DIRECTION, EYEDIR));
+ if (sun_angle < LIGHT2_SIZE) {
+ sky = LIGHT2_COLOR * LIGHT2_ENERGY;
+ } else if (sun_angle < sun_angle_max) {
+ float c2 = (sun_angle - LIGHT2_SIZE) / (sun_angle_max - LIGHT2_SIZE);
+ sky = mix(LIGHT2_COLOR * LIGHT2_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));
+ }
+ }
+
+ if (LIGHT3_ENABLED) {
+ float sun_angle = acos(dot(LIGHT3_DIRECTION, EYEDIR));
+ if (sun_angle < LIGHT3_SIZE) {
+ sky = LIGHT3_COLOR * LIGHT3_ENERGY;
+ } else if (sun_angle < sun_angle_max) {
+ float c2 = (sun_angle - LIGHT3_SIZE) / (sun_angle_max - LIGHT3_SIZE);
+ sky = mix(LIGHT3_COLOR * LIGHT3_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));
+ }
+ }
+
+ c = (v_angle - (PI * 0.5)) / (PI * 0.5);
+ vec3 ground = mix(ground_horizon_color.rgb, ground_bottom_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / ground_curve), 0.0, 1.0));
+ ground *= ground_energy;
+
+ COLOR = mix(ground, sky, step(0.0, EYEDIR.y));
+}
+)");
+ }
+ shader_mutex.unlock();
+}
+ProceduralSkyMaterial::ProceduralSkyMaterial() {
set_sky_top_color(Color(0.35, 0.46, 0.71));
set_sky_horizon_color(Color(0.55, 0.69, 0.81));
set_sky_curve(0.09);
@@ -261,7 +291,6 @@ ProceduralSkyMaterial::ProceduralSkyMaterial() {
}
ProceduralSkyMaterial::~ProceduralSkyMaterial() {
- RS::get_singleton()->free(shader);
RS::get_singleton()->material_set_shader(_get_material(), RID());
}
@@ -286,7 +315,17 @@ Shader::Mode PanoramaSkyMaterial::get_shader_mode() const {
return Shader::MODE_SKY;
}
+RID PanoramaSkyMaterial::get_rid() const {
+ _update_shader();
+ if (!shader_set) {
+ RS::get_singleton()->material_set_shader(_get_material(), shader);
+ shader_set = true;
+ }
+ return _get_material();
+}
+
RID PanoramaSkyMaterial::get_shader_rid() const {
+ _update_shader();
return shader;
}
@@ -297,23 +336,38 @@ void PanoramaSkyMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "panorama", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_panorama", "get_panorama");
}
-PanoramaSkyMaterial::PanoramaSkyMaterial() {
- String code = "shader_type sky;\n\n";
+Mutex PanoramaSkyMaterial::shader_mutex;
+RID PanoramaSkyMaterial::shader;
+
+void PanoramaSkyMaterial::cleanup_shader() {
+ if (shader.is_valid()) {
+ RS::get_singleton()->free(shader);
+ }
+}
+
+void PanoramaSkyMaterial::_update_shader() {
+ shader_mutex.lock();
+ if (shader.is_null()) {
+ shader = RS::get_singleton()->shader_create();
- code += "uniform sampler2D source_panorama : filter_linear;\n";
- code += "void sky() {\n";
- code += "\tCOLOR = texture(source_panorama, SKY_COORDS).rgb;\n";
- code += "}";
+ RS::get_singleton()->shader_set_code(shader, R"(
+shader_type sky;
- shader = RS::get_singleton()->shader_create();
+uniform sampler2D source_panorama : filter_linear;
- RS::get_singleton()->shader_set_code(shader, code);
+void sky() {
+ COLOR = texture(source_panorama, SKY_COORDS).rgb;
+}
+)");
+ }
+
+ shader_mutex.unlock();
+}
- RS::get_singleton()->material_set_shader(_get_material(), shader);
+PanoramaSkyMaterial::PanoramaSkyMaterial() {
}
PanoramaSkyMaterial::~PanoramaSkyMaterial() {
- RS::get_singleton()->free(shader);
RS::get_singleton()->material_set_shader(_get_material(), RID());
}
@@ -428,10 +482,23 @@ Shader::Mode PhysicalSkyMaterial::get_shader_mode() const {
return Shader::MODE_SKY;
}
+RID PhysicalSkyMaterial::get_rid() const {
+ _update_shader();
+ if (!shader_set) {
+ RS::get_singleton()->material_set_shader(_get_material(), shader);
+ shader_set = true;
+ }
+ return _get_material();
+}
+
RID PhysicalSkyMaterial::get_shader_rid() const {
+ _update_shader();
return shader;
}
+Mutex PhysicalSkyMaterial::shader_mutex;
+RID PhysicalSkyMaterial::shader;
+
void PhysicalSkyMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_rayleigh_coefficient", "rayleigh"), &PhysicalSkyMaterial::set_rayleigh_coefficient);
ClassDB::bind_method(D_METHOD("get_rayleigh_coefficient"), &PhysicalSkyMaterial::get_rayleigh_coefficient);
@@ -483,106 +550,117 @@ void PhysicalSkyMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "night_sky", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_night_sky", "get_night_sky");
}
-PhysicalSkyMaterial::PhysicalSkyMaterial() {
- String code = "shader_type sky;\n\n";
-
- code += "uniform float rayleigh : hint_range(0, 64) = 2.0;\n";
- code += "uniform vec4 rayleigh_color : hint_color = vec4(0.056, 0.14, 0.3, 1.0);\n";
- code += "uniform float mie : hint_range(0, 1) = 0.005;\n";
- code += "uniform float mie_eccentricity : hint_range(-1, 1) = 0.8;\n";
- code += "uniform vec4 mie_color : hint_color = vec4(0.36, 0.56, 0.82, 1.0);\n\n";
-
- code += "uniform float turbidity : hint_range(0, 1000) = 10.0;\n";
- code += "uniform float sun_disk_scale : hint_range(0, 360) = 1.0;\n";
- code += "uniform vec4 ground_color : hint_color = vec4(1.0);\n";
- code += "uniform float exposure : hint_range(0, 128) = 0.1;\n";
- code += "uniform float dither_strength : hint_range(0, 10) = 1.0;\n\n";
-
- code += "uniform sampler2D night_sky : hint_black;";
-
- code += "const vec3 UP = vec3( 0.0, 1.0, 0.0 );\n\n";
-
- code += "// Sun constants\n";
- code += "const float SUN_ENERGY = 1000.0;\n\n";
-
- code += "// optical length at zenith for molecules\n";
- code += "const float rayleigh_zenith_size = 8.4e3;\n";
- code += "const float mie_zenith_size = 1.25e3;\n\n";
-
- code += "float henyey_greenstein(float cos_theta, float g) {\n";
- code += "\tconst float k = 0.0795774715459;\n";
- code += "\treturn k * (1.0 - g * g) / (pow(1.0 + g * g - 2.0 * g * cos_theta, 1.5));\n";
- code += "}\n\n";
-
- code += "// From: https://www.shadertoy.com/view/4sfGzS credit to iq\n";
- code += "float hash(vec3 p) {\n";
- code += "\tp = fract( p * 0.3183099 + 0.1 );\n";
- code += "\tp *= 17.0;\n";
- code += "\treturn fract(p.x * p.y * p.z * (p.x + p.y + p.z));\n";
- code += "}\n\n";
-
- code += "void sky() {\n";
- code += "\tif (LIGHT0_ENABLED) {\n";
- code += "\t\tfloat zenith_angle = clamp( dot(UP, normalize(LIGHT0_DIRECTION)), -1.0, 1.0 );\n";
- code += "\t\tfloat sun_energy = max(0.0, 1.0 - exp(-((PI * 0.5) - acos(zenith_angle)))) * SUN_ENERGY * LIGHT0_ENERGY;\n";
- code += "\t\tfloat sun_fade = 1.0 - clamp(1.0 - exp(LIGHT0_DIRECTION.y), 0.0, 1.0);\n\n";
-
- code += "\t\t// rayleigh coefficients\n";
- code += "\t\tfloat rayleigh_coefficient = rayleigh - ( 1.0 * ( 1.0 - sun_fade ) );\n";
- code += "\t\tvec3 rayleigh_beta = rayleigh_coefficient * rayleigh_color.rgb * 0.0001;\n";
- code += "\t\t// mie coefficients from Preetham\n";
- code += "\t\tvec3 mie_beta = turbidity * mie * mie_color.rgb * 0.000434;\n\n";
-
- code += "\t\t// optical length\n";
- code += "\t\tfloat zenith = acos(max(0.0, dot(UP, EYEDIR)));\n";
- code += "\t\tfloat optical_mass = 1.0 / (cos(zenith) + 0.15 * pow(93.885 - degrees(zenith), -1.253));\n";
- code += "\t\tfloat rayleigh_scatter = rayleigh_zenith_size * optical_mass;\n";
- code += "\t\tfloat mie_scatter = mie_zenith_size * optical_mass;\n\n";
-
- code += "\t\t// light extinction based on thickness of atmosphere\n";
- code += "\t\tvec3 extinction = exp(-(rayleigh_beta * rayleigh_scatter + mie_beta * mie_scatter));\n\n";
-
- code += "\t\t// in scattering\n";
- code += "\t\tfloat cos_theta = dot(EYEDIR, normalize(LIGHT0_DIRECTION));\n\n";
-
- code += "\t\tfloat rayleigh_phase = (3.0 / (16.0 * PI)) * (1.0 + pow(cos_theta * 0.5 + 0.5, 2.0));\n";
- code += "\t\tvec3 betaRTheta = rayleigh_beta * rayleigh_phase;\n\n";
-
- code += "\t\tfloat mie_phase = henyey_greenstein(cos_theta, mie_eccentricity);\n";
- code += "\t\tvec3 betaMTheta = mie_beta * mie_phase;\n\n";
-
- code += "\t\tvec3 Lin = pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * (1.0 - extinction), vec3(1.5));\n";
- code += "\t\t// Hack from https://github.com/mrdoob/three.js/blob/master/examples/jsm/objects/Sky.js\n";
- code += "\t\tLin *= mix(vec3(1.0), pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * extinction, vec3(0.5)), clamp(pow(1.0 - zenith_angle, 5.0), 0.0, 1.0));\n\n";
-
- code += "\t\t// Hack in the ground color\n";
- code += "\t\tLin *= mix(ground_color.rgb, vec3(1.0), smoothstep(-0.1, 0.1, dot(UP, EYEDIR)));\n\n";
-
- code += "\t\t// Solar disk and out-scattering\n";
- code += "\t\tfloat sunAngularDiameterCos = cos(LIGHT0_SIZE * sun_disk_scale);\n";
- code += "\t\tfloat sunAngularDiameterCos2 = cos(LIGHT0_SIZE * sun_disk_scale*0.5);\n";
- code += "\t\tfloat sundisk = smoothstep(sunAngularDiameterCos, sunAngularDiameterCos2, cos_theta);\n";
- code += "\t\tvec3 L0 = (sun_energy * 1900.0 * extinction) * sundisk * LIGHT0_COLOR;\n";
- code += "\t\tL0 += texture(night_sky, SKY_COORDS).xyz * extinction;\n\n";
-
- code += "\t\tvec3 color = (Lin + L0) * 0.04;\n";
- code += "\t\tCOLOR = pow(color, vec3(1.0 / (1.2 + (1.2 * sun_fade))));\n";
- code += "\t\tCOLOR *= exposure;\n";
- code += "\t\t// Make optional, eliminates banding\n";
- code += "\t\tCOLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.016 * dither_strength;\n";
- code += "\t} else {\n";
- code += "\t\t// There is no sun, so display night_sky and nothing else\n";
- code += "\t\tCOLOR = texture(night_sky, SKY_COORDS).xyz * 0.04;\n";
- code += "\t\tCOLOR *= exposure;\n";
- code += "\t}\n";
- code += "}\n";
-
- shader = RS::get_singleton()->shader_create();
-
- RS::get_singleton()->shader_set_code(shader, code);
-
- RS::get_singleton()->material_set_shader(_get_material(), shader);
+void PhysicalSkyMaterial::cleanup_shader() {
+ if (shader.is_valid()) {
+ RS::get_singleton()->free(shader);
+ }
+}
+
+void PhysicalSkyMaterial::_update_shader() {
+ shader_mutex.lock();
+ if (shader.is_null()) {
+ shader = RS::get_singleton()->shader_create();
+
+ RS::get_singleton()->shader_set_code(shader, R"(
+shader_type sky;
+
+uniform float rayleigh : hint_range(0, 64) = 2.0;
+uniform vec4 rayleigh_color : hint_color = vec4(0.056, 0.14, 0.3, 1.0);
+uniform float mie : hint_range(0, 1) = 0.005;
+uniform float mie_eccentricity : hint_range(-1, 1) = 0.8;
+uniform vec4 mie_color : hint_color = vec4(0.36, 0.56, 0.82, 1.0);
+uniform float turbidity : hint_range(0, 1000) = 10.0;
+uniform float sun_disk_scale : hint_range(0, 360) = 1.0;
+uniform vec4 ground_color : hint_color = vec4(1.0);
+uniform float exposure : hint_range(0, 128) = 0.1;
+uniform float dither_strength : hint_range(0, 10) = 1.0;
+
+uniform sampler2D night_sky : hint_black;
+
+const vec3 UP = vec3( 0.0, 1.0, 0.0 );
+
+// Sun constants
+const float SUN_ENERGY = 1000.0;
+
+// Optical length at zenith for molecules.
+const float rayleigh_zenith_size = 8.4e3;
+const float mie_zenith_size = 1.25e3;
+
+float henyey_greenstein(float cos_theta, float g) {
+ const float k = 0.0795774715459;
+ return k * (1.0 - g * g) / (pow(1.0 + g * g - 2.0 * g * cos_theta, 1.5));
+}
+
+// From: https://www.shadertoy.com/view/4sfGzS credit to iq
+float hash(vec3 p) {
+ p = fract( p * 0.3183099 + 0.1 );
+ p *= 17.0;
+ return fract(p.x * p.y * p.z * (p.x + p.y + p.z));
+}
+
+void sky() {
+ if (LIGHT0_ENABLED) {
+ float zenith_angle = clamp( dot(UP, normalize(LIGHT0_DIRECTION)), -1.0, 1.0 );
+ float sun_energy = max(0.0, 1.0 - exp(-((PI * 0.5) - acos(zenith_angle)))) * SUN_ENERGY * LIGHT0_ENERGY;
+ float sun_fade = 1.0 - clamp(1.0 - exp(LIGHT0_DIRECTION.y), 0.0, 1.0);
+
+ // Rayleigh coefficients.
+ float rayleigh_coefficient = rayleigh - ( 1.0 * ( 1.0 - sun_fade ) );
+ vec3 rayleigh_beta = rayleigh_coefficient * rayleigh_color.rgb * 0.0001;
+ // mie coefficients from Preetham
+ vec3 mie_beta = turbidity * mie * mie_color.rgb * 0.000434;
+
+ // Optical length.
+ float zenith = acos(max(0.0, dot(UP, EYEDIR)));
+ float optical_mass = 1.0 / (cos(zenith) + 0.15 * pow(93.885 - degrees(zenith), -1.253));
+ float rayleigh_scatter = rayleigh_zenith_size * optical_mass;
+ float mie_scatter = mie_zenith_size * optical_mass;
+
+ // Light extinction based on thickness of atmosphere.
+ vec3 extinction = exp(-(rayleigh_beta * rayleigh_scatter + mie_beta * mie_scatter));
+
+ // In scattering.
+ float cos_theta = dot(EYEDIR, normalize(LIGHT0_DIRECTION));
+
+ float rayleigh_phase = (3.0 / (16.0 * PI)) * (1.0 + pow(cos_theta * 0.5 + 0.5, 2.0));
+ vec3 betaRTheta = rayleigh_beta * rayleigh_phase;
+
+ float mie_phase = henyey_greenstein(cos_theta, mie_eccentricity);
+ vec3 betaMTheta = mie_beta * mie_phase;
+
+ vec3 Lin = pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * (1.0 - extinction), vec3(1.5));
+ // Hack from https://github.com/mrdoob/three.js/blob/master/examples/jsm/objects/Sky.js
+ Lin *= mix(vec3(1.0), pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * extinction, vec3(0.5)), clamp(pow(1.0 - zenith_angle, 5.0), 0.0, 1.0));
+
+ // Hack in the ground color.
+ Lin *= mix(ground_color.rgb, vec3(1.0), smoothstep(-0.1, 0.1, dot(UP, EYEDIR)));
+
+ // Solar disk and out-scattering.
+ float sunAngularDiameterCos = cos(LIGHT0_SIZE * sun_disk_scale);
+ float sunAngularDiameterCos2 = cos(LIGHT0_SIZE * sun_disk_scale*0.5);
+ float sundisk = smoothstep(sunAngularDiameterCos, sunAngularDiameterCos2, cos_theta);
+ vec3 L0 = (sun_energy * 1900.0 * extinction) * sundisk * LIGHT0_COLOR;
+ L0 += texture(night_sky, SKY_COORDS).xyz * extinction;
+
+ vec3 color = (Lin + L0) * 0.04;
+ COLOR = pow(color, vec3(1.0 / (1.2 + (1.2 * sun_fade))));
+ COLOR *= exposure;
+ // Make optional, eliminates banding.
+ COLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.016 * dither_strength;
+ } else {
+ // There is no sun, so display night_sky and nothing else.
+ COLOR = texture(night_sky, SKY_COORDS).xyz * 0.04;
+ COLOR *= exposure;
+ }
+}
+)");
+ }
+
+ shader_mutex.unlock();
+}
+
+PhysicalSkyMaterial::PhysicalSkyMaterial() {
set_rayleigh_coefficient(2.0);
set_rayleigh_color(Color(0.056, 0.14, 0.3));
set_mie_coefficient(0.005);
@@ -596,5 +674,4 @@ PhysicalSkyMaterial::PhysicalSkyMaterial() {
}
PhysicalSkyMaterial::~PhysicalSkyMaterial() {
- RS::get_singleton()->free(shader);
}
diff --git a/scene/resources/sky_material.h b/scene/resources/sky_material.h
index 8fe015519d..63e730617b 100644
--- a/scene/resources/sky_material.h
+++ b/scene/resources/sky_material.h
@@ -51,7 +51,10 @@ private:
float sun_angle_max;
float sun_curve;
- RID shader;
+ static Mutex shader_mutex;
+ static RID shader;
+ static void _update_shader();
+ mutable bool shader_set = false;
protected:
static void _bind_methods();
@@ -90,6 +93,9 @@ public:
virtual Shader::Mode get_shader_mode() const override;
virtual RID get_shader_rid() const override;
+ virtual RID get_rid() const override;
+
+ static void cleanup_shader();
ProceduralSkyMaterial();
~ProceduralSkyMaterial();
@@ -103,7 +109,11 @@ class PanoramaSkyMaterial : public Material {
private:
Ref<Texture2D> panorama;
- RID shader;
+
+ static Mutex shader_mutex;
+ static RID shader;
+ static void _update_shader();
+ mutable bool shader_set = false;
protected:
static void _bind_methods();
@@ -115,6 +125,9 @@ public:
virtual Shader::Mode get_shader_mode() const override;
virtual RID get_shader_rid() const override;
+ virtual RID get_rid() const override;
+
+ static void cleanup_shader();
PanoramaSkyMaterial();
~PanoramaSkyMaterial();
@@ -127,7 +140,8 @@ class PhysicalSkyMaterial : public Material {
GDCLASS(PhysicalSkyMaterial, Material);
private:
- RID shader;
+ static Mutex shader_mutex;
+ static RID shader;
float rayleigh;
Color rayleigh_color;
@@ -140,6 +154,8 @@ private:
float exposure;
float dither_strength;
Ref<Texture2D> night_sky;
+ static void _update_shader();
+ mutable bool shader_set = false;
protected:
static void _bind_methods();
@@ -182,6 +198,9 @@ public:
virtual Shader::Mode get_shader_mode() const override;
virtual RID get_shader_rid() const override;
+ static void cleanup_shader();
+ virtual RID get_rid() const override;
+
PhysicalSkyMaterial();
~PhysicalSkyMaterial();
};
diff --git a/scene/resources/sprite_frames.cpp b/scene/resources/sprite_frames.cpp
index df80084c5c..e9adf67559 100644
--- a/scene/resources/sprite_frames.cpp
+++ b/scene/resources/sprite_frames.cpp
@@ -100,8 +100,8 @@ Vector<String> SpriteFrames::_get_animation_list() const {
Vector<String> ret;
List<StringName> al;
get_animation_list(&al);
- for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
- ret.push_back(E->get());
+ for (const StringName &E : al) {
+ ret.push_back(E);
}
return ret;
diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp
index 9dd00849f4..173ce2adce 100644
--- a/scene/resources/syntax_highlighter.cpp
+++ b/scene/resources/syntax_highlighter.cpp
@@ -405,7 +405,7 @@ void CodeHighlighter::_clear_highlighting_cache() {
}
void CodeHighlighter::_update_cache() {
- font_color = text_edit->get_theme_color("font_color");
+ font_color = text_edit->get_theme_color(SNAME("font_color"));
}
void CodeHighlighter::add_keyword_color(const String &p_keyword, const Color &p_color) {
@@ -529,8 +529,8 @@ void CodeHighlighter::set_color_regions(const Dictionary &p_color_regions) {
List<Variant> keys;
p_color_regions.get_key_list(&keys);
- for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
- String key = E->get();
+ for (const Variant &E : keys) {
+ String key = E;
String start_key = key.get_slice(" ", 0);
String end_key = key.get_slice_count(" ") > 1 ? key.get_slice(" ", 1) : String();
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 98997e482a..38042d84fd 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -1545,19 +1545,19 @@ CurveTexture::~CurveTexture() {
//////////////////
-void Curve3Texture::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_width", "width"), &Curve3Texture::set_width);
+void CurveXYZTexture::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_width", "width"), &CurveXYZTexture::set_width);
- ClassDB::bind_method(D_METHOD("set_curve_x", "curve"), &Curve3Texture::set_curve_x);
- ClassDB::bind_method(D_METHOD("get_curve_x"), &Curve3Texture::get_curve_x);
+ ClassDB::bind_method(D_METHOD("set_curve_x", "curve"), &CurveXYZTexture::set_curve_x);
+ ClassDB::bind_method(D_METHOD("get_curve_x"), &CurveXYZTexture::get_curve_x);
- ClassDB::bind_method(D_METHOD("set_curve_y", "curve"), &Curve3Texture::set_curve_y);
- ClassDB::bind_method(D_METHOD("get_curve_y"), &Curve3Texture::get_curve_y);
+ ClassDB::bind_method(D_METHOD("set_curve_y", "curve"), &CurveXYZTexture::set_curve_y);
+ ClassDB::bind_method(D_METHOD("get_curve_y"), &CurveXYZTexture::get_curve_y);
- ClassDB::bind_method(D_METHOD("set_curve_z", "curve"), &Curve3Texture::set_curve_z);
- ClassDB::bind_method(D_METHOD("get_curve_z"), &Curve3Texture::get_curve_z);
+ ClassDB::bind_method(D_METHOD("set_curve_z", "curve"), &CurveXYZTexture::set_curve_z);
+ ClassDB::bind_method(D_METHOD("get_curve_z"), &CurveXYZTexture::get_curve_z);
- ClassDB::bind_method(D_METHOD("_update"), &Curve3Texture::_update);
+ ClassDB::bind_method(D_METHOD("_update"), &CurveXYZTexture::_update);
ADD_PROPERTY(PropertyInfo(Variant::INT, "width", PROPERTY_HINT_RANGE, "1,4096"), "set_width", "get_width");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve_x", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve_x", "get_curve_x");
@@ -1565,7 +1565,7 @@ void Curve3Texture::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve_z", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve_z", "get_curve_z");
}
-void Curve3Texture::set_width(int p_width) {
+void CurveXYZTexture::set_width(int p_width) {
ERR_FAIL_COND(p_width < 32 || p_width > 4096);
if (_width == p_width) {
@@ -1576,11 +1576,11 @@ void Curve3Texture::set_width(int p_width) {
_update();
}
-int Curve3Texture::get_width() const {
+int CurveXYZTexture::get_width() const {
return _width;
}
-void Curve3Texture::ensure_default_setup(float p_min, float p_max) {
+void CurveXYZTexture::ensure_default_setup(float p_min, float p_max) {
if (_curve_x.is_null()) {
Ref<Curve> curve = Ref<Curve>(memnew(Curve));
curve->add_point(Vector2(0, 1));
@@ -1609,46 +1609,46 @@ void Curve3Texture::ensure_default_setup(float p_min, float p_max) {
}
}
-void Curve3Texture::set_curve_x(Ref<Curve> p_curve) {
+void CurveXYZTexture::set_curve_x(Ref<Curve> p_curve) {
if (_curve_x != p_curve) {
if (_curve_x.is_valid()) {
- _curve_x->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update));
+ _curve_x->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveXYZTexture::_update));
}
_curve_x = p_curve;
if (_curve_x.is_valid()) {
- _curve_x->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update), varray(), CONNECT_REFERENCE_COUNTED);
+ _curve_x->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveXYZTexture::_update), varray(), CONNECT_REFERENCE_COUNTED);
}
_update();
}
}
-void Curve3Texture::set_curve_y(Ref<Curve> p_curve) {
+void CurveXYZTexture::set_curve_y(Ref<Curve> p_curve) {
if (_curve_y != p_curve) {
if (_curve_y.is_valid()) {
- _curve_y->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update));
+ _curve_y->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveXYZTexture::_update));
}
_curve_y = p_curve;
if (_curve_y.is_valid()) {
- _curve_y->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update), varray(), CONNECT_REFERENCE_COUNTED);
+ _curve_y->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveXYZTexture::_update), varray(), CONNECT_REFERENCE_COUNTED);
}
_update();
}
}
-void Curve3Texture::set_curve_z(Ref<Curve> p_curve) {
+void CurveXYZTexture::set_curve_z(Ref<Curve> p_curve) {
if (_curve_z != p_curve) {
if (_curve_z.is_valid()) {
- _curve_z->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update));
+ _curve_z->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveXYZTexture::_update));
}
_curve_z = p_curve;
if (_curve_z.is_valid()) {
- _curve_z->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update), varray(), CONNECT_REFERENCE_COUNTED);
+ _curve_z->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveXYZTexture::_update), varray(), CONNECT_REFERENCE_COUNTED);
}
_update();
}
}
-void Curve3Texture::_update() {
+void CurveXYZTexture::_update() {
Vector<uint8_t> data;
data.resize(_width * sizeof(float) * 3);
@@ -1714,28 +1714,28 @@ void Curve3Texture::_update() {
emit_changed();
}
-Ref<Curve> Curve3Texture::get_curve_x() const {
+Ref<Curve> CurveXYZTexture::get_curve_x() const {
return _curve_x;
}
-Ref<Curve> Curve3Texture::get_curve_y() const {
+Ref<Curve> CurveXYZTexture::get_curve_y() const {
return _curve_y;
}
-Ref<Curve> Curve3Texture::get_curve_z() const {
+Ref<Curve> CurveXYZTexture::get_curve_z() const {
return _curve_z;
}
-RID Curve3Texture::get_rid() const {
+RID CurveXYZTexture::get_rid() const {
if (!_texture.is_valid()) {
_texture = RS::get_singleton()->texture_2d_placeholder_create();
}
return _texture;
}
-Curve3Texture::Curve3Texture() {}
+CurveXYZTexture::CurveXYZTexture() {}
-Curve3Texture::~Curve3Texture() {
+CurveXYZTexture::~CurveXYZTexture() {
if (_texture.is_valid()) {
RS::get_singleton()->free(_texture);
}
@@ -1790,7 +1790,7 @@ void GradientTexture::_queue_update() {
}
update_pending = true;
- call_deferred("_update");
+ call_deferred(SNAME("_update"));
}
void GradientTexture::_update() {
diff --git a/scene/resources/texture.h b/scene/resources/texture.h
index 73390039cb..98aa61138d 100644
--- a/scene/resources/texture.h
+++ b/scene/resources/texture.h
@@ -628,8 +628,8 @@ public:
VARIANT_ENUM_CAST(CurveTexture::TextureMode)
-class Curve3Texture : public Texture2D {
- GDCLASS(Curve3Texture, Texture2D);
+class CurveXYZTexture : public Texture2D {
+ GDCLASS(CurveXYZTexture, Texture2D);
RES_BASE_EXTENSION("curvetex")
private:
@@ -665,8 +665,8 @@ public:
virtual int get_height() const override { return 1; }
virtual bool has_alpha() const override { return false; }
- Curve3Texture();
- ~Curve3Texture();
+ CurveXYZTexture();
+ ~CurveXYZTexture();
};
class GradientTexture : public Texture2D {
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 89ac033207..e4a731c7f7 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -263,6 +263,21 @@ Vector<String> Theme::_get_theme_item_type_list(DataType p_data_type) const {
return Vector<String>();
}
+Vector<String> Theme::_get_type_variation_list(const StringName &p_theme_type) const {
+ Vector<String> ilret;
+ List<StringName> il;
+
+ get_type_variation_list(p_theme_type, &il);
+ ilret.resize(il.size());
+
+ int i = 0;
+ String *w = ilret.ptrw();
+ for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
+ w[i] = E->get();
+ }
+ return ilret;
+}
+
Vector<String> Theme::_get_type_list() const {
Vector<String> ilret;
List<StringName> il;
@@ -292,10 +307,14 @@ bool Theme::_set(const StringName &p_name, const Variant &p_value) {
set_stylebox(name, theme_type, p_value);
} else if (type == "fonts") {
set_font(name, theme_type, p_value);
+ } else if (type == "font_sizes") {
+ set_font_size(name, theme_type, p_value);
} else if (type == "colors") {
set_color(name, theme_type, p_value);
} else if (type == "constants") {
set_constant(name, theme_type, p_value);
+ } else if (type == "base_type") {
+ set_type_variation(theme_type, p_value);
} else {
return false;
}
@@ -332,10 +351,14 @@ bool Theme::_get(const StringName &p_name, Variant &r_ret) const {
} else {
r_ret = get_font(name, theme_type);
}
+ } else if (type == "font_sizes") {
+ r_ret = get_font_size(name, theme_type);
} else if (type == "colors") {
r_ret = get_color(name, theme_type);
} else if (type == "constants") {
r_ret = get_constant(name, theme_type);
+ } else if (type == "base_type") {
+ r_ret = get_type_variation_base(theme_type);
} else {
return false;
}
@@ -351,6 +374,14 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
const StringName *key = nullptr;
+ // Type variations.
+ while ((key = variation_map.next(key))) {
+ list.push_back(PropertyInfo(Variant::STRING_NAME, String() + *key + "/base_type"));
+ }
+
+ key = nullptr;
+
+ // Icons.
while ((key = icon_map.next(key))) {
const StringName *key2 = nullptr;
@@ -361,6 +392,7 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
key = nullptr;
+ // Styles.
while ((key = style_map.next(key))) {
const StringName *key2 = nullptr;
@@ -371,6 +403,7 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
key = nullptr;
+ // Fonts.
while ((key = font_map.next(key))) {
const StringName *key2 = nullptr;
@@ -381,6 +414,18 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
key = nullptr;
+ // Font sizes.
+ while ((key = font_size_map.next(key))) {
+ const StringName *key2 = nullptr;
+
+ while ((key2 = font_size_map[*key].next(key2))) {
+ list.push_back(PropertyInfo(Variant::INT, String() + *key + "/font_sizes/" + *key2));
+ }
+ }
+
+ key = nullptr;
+
+ // Colors.
while ((key = color_map.next(key))) {
const StringName *key2 = nullptr;
@@ -391,6 +436,7 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
key = nullptr;
+ // Constants.
while ((key = constant_map.next(key))) {
const StringName *key2 = nullptr;
@@ -399,9 +445,10 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
}
}
+ // Sort and store properties.
list.sort();
- for (List<PropertyInfo>::Element *E = list.front(); E; E = E->next()) {
- p_list->push_back(E->get());
+ for (const PropertyInfo &E : list) {
+ p_list->push_back(E);
}
}
@@ -1183,6 +1230,63 @@ void Theme::get_theme_item_type_list(DataType p_data_type, List<StringName> *p_l
}
}
+void Theme::set_type_variation(const StringName &p_theme_type, const StringName &p_base_type) {
+ ERR_FAIL_COND_MSG(p_theme_type == StringName(), "An empty theme type cannot be marked as a variation of another type.");
+ ERR_FAIL_COND_MSG(ClassDB::class_exists(p_theme_type), "A type associated with a built-in class cannot be marked as a variation of another type.");
+ ERR_FAIL_COND_MSG(p_base_type == StringName(), "An empty theme type cannot be the base type of a variation. Use clear_type_variation() instead if you want to unmark '" + String(p_theme_type) + "' as a variation.");
+
+ if (variation_map.has(p_theme_type)) {
+ StringName old_base = variation_map[p_theme_type];
+ variation_base_map[old_base].erase(p_theme_type);
+ }
+
+ variation_map[p_theme_type] = p_base_type;
+ variation_base_map[p_base_type].push_back(p_theme_type);
+
+ _emit_theme_changed();
+}
+
+bool Theme::is_type_variation(const StringName &p_theme_type, const StringName &p_base_type) const {
+ return (variation_map.has(p_theme_type) && variation_map[p_theme_type] == p_base_type);
+}
+
+void Theme::clear_type_variation(const StringName &p_theme_type) {
+ ERR_FAIL_COND_MSG(!variation_map.has(p_theme_type), "Cannot clear the type variation '" + String(p_theme_type) + "' because it does not exist.");
+
+ StringName base_type = variation_map[p_theme_type];
+ variation_base_map[base_type].erase(p_theme_type);
+ variation_map.erase(p_theme_type);
+
+ _emit_theme_changed();
+}
+
+StringName Theme::get_type_variation_base(const StringName &p_theme_type) const {
+ if (!variation_map.has(p_theme_type)) {
+ return StringName();
+ }
+
+ return variation_map[p_theme_type];
+}
+
+void Theme::get_type_variation_list(const StringName &p_base_type, List<StringName> *p_list) const {
+ ERR_FAIL_NULL(p_list);
+
+ if (!variation_base_map.has(p_base_type)) {
+ return;
+ }
+
+ for (const StringName &E : variation_base_map[p_base_type]) {
+ // Prevent infinite loops if variants were set to be cross-dependent (that's still invalid usage, but handling for stability sake).
+ if (p_list->find(E)) {
+ continue;
+ }
+
+ p_list->push_back(E);
+ // Continue looking for sub-variations.
+ get_type_variation_list(E, p_list);
+ }
+}
+
void Theme::_freeze_change_propagation() {
no_change_propagation = true;
}
@@ -1236,9 +1340,13 @@ void Theme::clear() {
icon_map.clear();
style_map.clear();
font_map.clear();
+ font_size_map.clear();
color_map.clear();
constant_map.clear();
+ variation_map.clear();
+ variation_base_map.clear();
+
_emit_theme_changed();
}
@@ -1291,6 +1399,9 @@ void Theme::copy_theme(const Ref<Theme> &p_other) {
color_map = p_other->color_map;
constant_map = p_other->constant_map;
+ variation_map = p_other->variation_map;
+ variation_base_map = p_other->variation_base_map;
+
_unfreeze_and_propagate_changes();
}
@@ -1300,30 +1411,42 @@ void Theme::get_type_list(List<StringName> *p_list) const {
Set<StringName> types;
const StringName *key = nullptr;
+ // Icons.
while ((key = icon_map.next(key))) {
types.insert(*key);
}
key = nullptr;
+ // StyleBoxes.
while ((key = style_map.next(key))) {
types.insert(*key);
}
key = nullptr;
+ // Fonts.
while ((key = font_map.next(key))) {
types.insert(*key);
}
key = nullptr;
+ // Font sizes.
+ while ((key = font_size_map.next(key))) {
+ types.insert(*key);
+ }
+
+ key = nullptr;
+
+ // Colors.
while ((key = color_map.next(key))) {
types.insert(*key);
}
key = nullptr;
+ // Constants.
while ((key = constant_map.next(key))) {
types.insert(*key);
}
@@ -1333,10 +1456,25 @@ void Theme::get_type_list(List<StringName> *p_list) const {
}
}
-void Theme::get_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) {
+void Theme::get_type_dependencies(const StringName &p_base_type, const StringName &p_type_variation, List<StringName> *p_list) {
ERR_FAIL_NULL(p_list);
- StringName class_name = p_theme_type;
+ // Build the dependency chain for type variations.
+ if (p_type_variation != StringName()) {
+ StringName variation_name = p_type_variation;
+ while (variation_name != StringName()) {
+ p_list->push_back(variation_name);
+ variation_name = get_type_variation_base(variation_name);
+
+ // If we have reached the base type dependency, it's safe to stop (assuming no funny business was done to the Theme).
+ if (variation_name == p_base_type) {
+ break;
+ }
+ }
+ }
+
+ // Continue building the chain using native class hierarchy.
+ StringName class_name = p_base_type;
while (class_name != StringName()) {
p_list->push_back(class_name);
class_name = ClassDB::get_parent_class_nocheck(class_name);
@@ -1346,6 +1484,7 @@ void Theme::get_type_dependencies(const StringName &p_theme_type, List<StringNam
void Theme::reset_state() {
clear();
}
+
void Theme::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_icon", "name", "theme_type", "texture"), &Theme::set_icon);
ClassDB::bind_method(D_METHOD("get_icon", "name", "theme_type"), &Theme::get_icon);
@@ -1411,6 +1550,12 @@ void Theme::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_theme_item_list", "data_type", "theme_type"), &Theme::_get_theme_item_list);
ClassDB::bind_method(D_METHOD("get_theme_item_type_list", "data_type"), &Theme::_get_theme_item_type_list);
+ ClassDB::bind_method(D_METHOD("set_type_variation", "theme_type", "base_type"), &Theme::set_type_variation);
+ ClassDB::bind_method(D_METHOD("is_type_variation", "theme_type", "base_type"), &Theme::is_type_variation);
+ ClassDB::bind_method(D_METHOD("clear_type_variation", "theme_type"), &Theme::clear_type_variation);
+ ClassDB::bind_method(D_METHOD("get_type_variation_base", "theme_type"), &Theme::get_type_variation_base);
+ ClassDB::bind_method(D_METHOD("get_type_variation_list", "base_type"), &Theme::_get_type_variation_list);
+
ClassDB::bind_method(D_METHOD("get_type_list"), &Theme::_get_type_list);
ClassDB::bind_method("copy_default_theme", &Theme::copy_default_theme);
diff --git a/scene/resources/theme.h b/scene/resources/theme.h
index fe64fd7290..8a8fc28be1 100644
--- a/scene/resources/theme.h
+++ b/scene/resources/theme.h
@@ -69,6 +69,8 @@ private:
HashMap<StringName, HashMap<StringName, int>> font_size_map;
HashMap<StringName, HashMap<StringName, Color>> color_map;
HashMap<StringName, HashMap<StringName, int>> constant_map;
+ HashMap<StringName, StringName> variation_map;
+ HashMap<StringName, List<StringName>> variation_base_map;
Vector<String> _get_icon_list(const String &p_theme_type) const;
Vector<String> _get_icon_type_list() const;
@@ -85,6 +87,8 @@ private:
Vector<String> _get_theme_item_list(DataType p_data_type, const String &p_theme_type) const;
Vector<String> _get_theme_item_type_list(DataType p_data_type) const;
+
+ Vector<String> _get_type_variation_list(const StringName &p_theme_type) const;
Vector<String> _get_type_list() const;
protected:
@@ -197,8 +201,14 @@ public:
void add_theme_item_type(DataType p_data_type, const StringName &p_theme_type);
void get_theme_item_type_list(DataType p_data_type, List<StringName> *p_list) const;
+ void set_type_variation(const StringName &p_theme_type, const StringName &p_base_type);
+ bool is_type_variation(const StringName &p_theme_type, const StringName &p_base_type) const;
+ void clear_type_variation(const StringName &p_theme_type);
+ StringName get_type_variation_base(const StringName &p_theme_type) const;
+ void get_type_variation_list(const StringName &p_base_type, List<StringName> *p_list) const;
+
void get_type_list(List<StringName> *p_list) const;
- static void get_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list);
+ void get_type_dependencies(const StringName &p_base_type, const StringName &p_type_variant, List<StringName> *p_list);
void copy_default_theme();
void copy_theme(const Ref<Theme> &p_other);
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index deee22f05f..737b47ed95 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -41,6 +41,8 @@
/////////////////////////////// TileSet //////////////////////////////////////
+const int TileSet::INVALID_SOURCE = -1;
+
const char *TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[] = {
"right_side",
"right_corner",
@@ -127,8 +129,8 @@ void TileSet::_compute_next_source_id() {
// Sources management
int TileSet::add_source(Ref<TileSetSource> p_tile_set_source, int p_atlas_source_id_override) {
- ERR_FAIL_COND_V(!p_tile_set_source.is_valid(), -1);
- ERR_FAIL_COND_V_MSG(p_atlas_source_id_override >= 0 && (sources.has(p_atlas_source_id_override)), -1, vformat("Cannot create TileSet atlas source. Another atlas source exists with id %d.", p_atlas_source_id_override));
+ ERR_FAIL_COND_V(!p_tile_set_source.is_valid(), TileSet::INVALID_SOURCE);
+ ERR_FAIL_COND_V_MSG(p_atlas_source_id_override >= 0 && (sources.has(p_atlas_source_id_override)), TileSet::INVALID_SOURCE, vformat("Cannot create TileSet atlas source. Another atlas source exists with id %d.", p_atlas_source_id_override));
int new_source_id = p_atlas_source_id_override >= 0 ? p_atlas_source_id_override : next_source_id;
sources[new_source_id] = p_tile_set_source;
@@ -191,7 +193,7 @@ int TileSet::get_source_count() const {
}
int TileSet::get_source_id(int p_index) const {
- ERR_FAIL_INDEX_V(p_index, source_ids.size(), -1);
+ ERR_FAIL_INDEX_V(p_index, source_ids.size(), TileSet::INVALID_SOURCE);
return source_ids[p_index];
}
@@ -607,6 +609,254 @@ Variant::Type TileSet::get_custom_data_type(int p_layer_id) const {
return custom_data_layers[p_layer_id].type;
}
+void TileSet::set_source_level_tile_proxy(int p_source_from, int p_source_to) {
+ ERR_FAIL_COND(p_source_from == TileSet::INVALID_SOURCE || p_source_to == TileSet::INVALID_SOURCE);
+
+ source_level_proxies[p_source_from] = p_source_to;
+
+ emit_changed();
+}
+
+int TileSet::get_source_level_tile_proxy(int p_source_from) {
+ ERR_FAIL_COND_V(!source_level_proxies.has(p_source_from), TileSet::INVALID_SOURCE);
+
+ return source_level_proxies[p_source_from];
+}
+
+bool TileSet::has_source_level_tile_proxy(int p_source_from) {
+ return source_level_proxies.has(p_source_from);
+}
+
+void TileSet::remove_source_level_tile_proxy(int p_source_from) {
+ ERR_FAIL_COND(!source_level_proxies.has(p_source_from));
+
+ source_level_proxies.erase(p_source_from);
+
+ emit_changed();
+}
+
+void TileSet::set_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_source_to, Vector2i p_coords_to) {
+ ERR_FAIL_COND(p_source_from == TileSet::INVALID_SOURCE || p_source_to == TileSet::INVALID_SOURCE);
+ ERR_FAIL_COND(p_coords_from == TileSetSource::INVALID_ATLAS_COORDS || p_coords_to == TileSetSource::INVALID_ATLAS_COORDS);
+
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+
+ Array to;
+ to.push_back(p_source_to);
+ to.push_back(p_coords_to);
+
+ coords_level_proxies[from] = to;
+
+ emit_changed();
+}
+
+Array TileSet::get_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from) {
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+
+ ERR_FAIL_COND_V(!coords_level_proxies.has(from), Array());
+
+ return coords_level_proxies[from];
+}
+
+bool TileSet::has_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from) {
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+
+ return coords_level_proxies.has(from);
+}
+
+void TileSet::remove_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from) {
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+
+ ERR_FAIL_COND(!coords_level_proxies.has(from));
+
+ coords_level_proxies.erase(from);
+
+ emit_changed();
+}
+
+void TileSet::set_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from, int p_source_to, Vector2i p_coords_to, int p_alternative_to) {
+ ERR_FAIL_COND(p_source_from == TileSet::INVALID_SOURCE || p_source_to == TileSet::INVALID_SOURCE);
+ ERR_FAIL_COND(p_coords_from == TileSetSource::INVALID_ATLAS_COORDS || p_coords_to == TileSetSource::INVALID_ATLAS_COORDS);
+
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+ from.push_back(p_alternative_from);
+
+ Array to;
+ to.push_back(p_source_to);
+ to.push_back(p_coords_to);
+ to.push_back(p_alternative_to);
+
+ alternative_level_proxies[from] = to;
+
+ emit_changed();
+}
+
+Array TileSet::get_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) {
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+ from.push_back(p_alternative_from);
+
+ ERR_FAIL_COND_V(!alternative_level_proxies.has(from), Array());
+
+ return alternative_level_proxies[from];
+}
+
+bool TileSet::has_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) {
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+ from.push_back(p_alternative_from);
+
+ return alternative_level_proxies.has(from);
+}
+
+void TileSet::remove_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) {
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+ from.push_back(p_alternative_from);
+
+ ERR_FAIL_COND(!alternative_level_proxies.has(from));
+
+ alternative_level_proxies.erase(from);
+
+ emit_changed();
+}
+
+Array TileSet::get_source_level_tile_proxies() const {
+ Array output;
+ for (Map<int, int>::Element *E = source_level_proxies.front(); E; E = E->next()) {
+ Array proxy;
+ proxy.push_back(E->key());
+ proxy.push_back(E->get());
+ output.push_back(proxy);
+ }
+ return output;
+}
+
+Array TileSet::get_coords_level_tile_proxies() const {
+ Array output;
+ for (Map<Array, Array>::Element *E = coords_level_proxies.front(); E; E = E->next()) {
+ Array proxy;
+ proxy.append_array(E->key());
+ proxy.append_array(E->get());
+ output.push_back(proxy);
+ }
+ return output;
+}
+
+Array TileSet::get_alternative_level_tile_proxies() const {
+ Array output;
+ for (Map<Array, Array>::Element *E = alternative_level_proxies.front(); E; E = E->next()) {
+ Array proxy;
+ proxy.append_array(E->key());
+ proxy.append_array(E->get());
+ output.push_back(proxy);
+ }
+ return output;
+}
+
+Array TileSet::map_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) const {
+ Array from;
+ from.push_back(p_source_from);
+ from.push_back(p_coords_from);
+ from.push_back(p_alternative_from);
+
+ // Check if the tile is valid, and if so, don't map the tile and return the input.
+ if (has_source(p_source_from)) {
+ Ref<TileSetSource> source = get_source(p_source_from);
+ if (source->has_tile(p_coords_from) && source->has_alternative_tile(p_coords_from, p_alternative_from)) {
+ return from;
+ }
+ }
+
+ // Source, coords and alternative match.
+ if (alternative_level_proxies.has(from)) {
+ return alternative_level_proxies[from].duplicate();
+ }
+
+ // Source and coords match.
+ from.pop_back();
+ if (coords_level_proxies.has(from)) {
+ Array output = coords_level_proxies[from].duplicate();
+ output.push_back(p_alternative_from);
+ return output;
+ }
+
+ // Source matches.
+ if (source_level_proxies.has(p_source_from)) {
+ Array output;
+ output.push_back(source_level_proxies[p_source_from]);
+ output.push_back(p_coords_from);
+ output.push_back(p_alternative_from);
+ return output;
+ }
+
+ Array output;
+ output.push_back(p_source_from);
+ output.push_back(p_coords_from);
+ output.push_back(p_alternative_from);
+ return output;
+}
+
+void TileSet::cleanup_invalid_tile_proxies() {
+ // Source level.
+ Vector<int> source_to_remove;
+ for (Map<int, int>::Element *E = source_level_proxies.front(); E; E = E->next()) {
+ if (has_source(E->key())) {
+ source_to_remove.append(E->key());
+ }
+ }
+ for (int i = 0; i < source_to_remove.size(); i++) {
+ remove_source_level_tile_proxy(source_to_remove[i]);
+ }
+
+ // Coords level.
+ Vector<Array> coords_to_remove;
+ for (Map<Array, Array>::Element *E = coords_level_proxies.front(); E; E = E->next()) {
+ Array a = E->key();
+ if (has_source(a[0]) && get_source(a[0])->has_tile(a[1])) {
+ coords_to_remove.append(a);
+ }
+ }
+ for (int i = 0; i < coords_to_remove.size(); i++) {
+ Array a = coords_to_remove[i];
+ remove_coords_level_tile_proxy(a[0], a[1]);
+ }
+
+ // Alternative level.
+ Vector<Array> alternative_to_remove;
+ for (Map<Array, Array>::Element *E = alternative_level_proxies.front(); E; E = E->next()) {
+ Array a = E->key();
+ if (has_source(a[0]) && get_source(a[0])->has_tile(a[1]) && get_source(a[0])->has_alternative_tile(a[1], a[2])) {
+ alternative_to_remove.append(a);
+ }
+ }
+ for (int i = 0; i < alternative_to_remove.size(); i++) {
+ Array a = alternative_to_remove[i];
+ remove_alternative_level_tile_proxy(a[0], a[1], a[2]);
+ }
+}
+
+void TileSet::clear_tile_proxies() {
+ source_level_proxies.clear();
+ coords_level_proxies.clear();
+ alternative_level_proxies.clear();
+
+ emit_changed();
+}
+
Vector<Vector2> TileSet::get_tile_shape_polygon() {
Vector<Vector2> points;
if (tile_shape == TileSet::TILE_SHAPE_SQUARE) {
@@ -1539,7 +1789,7 @@ const Vector2i TileSetSource::INVALID_ATLAS_COORDS = Vector2i(-1, -1);
const int TileSetSource::INVALID_TILE_ALTERNATIVE = -1;
#ifndef DISABLE_DEPRECATED
-void TileSet::compatibility_conversion() {
+void TileSet::_compatibility_conversion() {
for (Map<int, CompatibilityTileData *>::Element *E = compatibility_data.front(); E; E = E->next()) {
CompatibilityTileData *ctd = E->value();
@@ -1551,13 +1801,93 @@ void TileSet::compatibility_conversion() {
// Handle each tile as a new source. Not optimal but at least it should stay compatible.
switch (ctd->tile_mode) {
- case 0: // SINGLE_TILE
- // TODO
- break;
- case 1: // AUTO_TILE
- // TODO
- break;
- case 2: // ATLAS_TILE
+ case COMPATIBILITY_TILE_MODE_SINGLE_TILE: {
+ atlas_source->set_margins(ctd->region.get_position());
+ atlas_source->set_texture_region_size(ctd->region.get_size());
+
+ Vector2i coords;
+ for (int flags = 0; flags < 8; flags++) {
+ bool flip_h = flags & 1;
+ bool flip_v = flags & 2;
+ bool transpose = flags & 4;
+
+ int alternative_tile = 0;
+ if (!atlas_source->has_tile(coords)) {
+ atlas_source->create_tile(coords);
+ } else {
+ alternative_tile = atlas_source->create_alternative_tile(coords);
+ }
+
+ // Add to the mapping.
+ Array key_array;
+ key_array.push_back(flip_h);
+ key_array.push_back(flip_v);
+ key_array.push_back(transpose);
+
+ Array value_array;
+ value_array.push_back(source_id);
+ value_array.push_back(coords);
+ value_array.push_back(alternative_tile);
+
+ if (!compatibility_tilemap_mapping.has(E->key())) {
+ compatibility_tilemap_mapping[E->key()] = Map<Array, Array>();
+ }
+ compatibility_tilemap_mapping[E->key()][key_array] = value_array;
+ compatibility_tilemap_mapping_tile_modes[E->key()] = COMPATIBILITY_TILE_MODE_SINGLE_TILE;
+
+ TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(coords, alternative_tile));
+
+ tile_data->set_flip_h(flip_h);
+ tile_data->set_flip_v(flip_v);
+ tile_data->set_transpose(transpose);
+ tile_data->tile_set_material(ctd->material);
+ tile_data->set_modulate(ctd->modulate);
+ tile_data->set_z_index(ctd->z_index);
+
+ if (ctd->occluder.is_valid()) {
+ if (get_occlusion_layers_count() < 1) {
+ set_occlusion_layers_count(1);
+ }
+ tile_data->set_occluder(0, ctd->occluder);
+ }
+ if (ctd->navigation.is_valid()) {
+ if (get_navigation_layers_count() < 1) {
+ set_navigation_layers_count(1);
+ }
+ tile_data->set_navigation_polygon(0, ctd->autotile_navpoly_map[coords]);
+ }
+
+ tile_data->set_z_index(ctd->z_index);
+
+ // Add the shapes.
+ if (ctd->shapes.size() > 0) {
+ if (get_physics_layers_count() < 1) {
+ set_physics_layers_count(1);
+ }
+ }
+ for (int k = 0; k < ctd->shapes.size(); k++) {
+ CompatibilityShapeData csd = ctd->shapes[k];
+ if (csd.autotile_coords == coords) {
+ Ref<ConvexPolygonShape2D> convex_shape = csd.shape; // Only ConvexPolygonShape2D are supported, which is the default type used by the 3.x editor
+ if (convex_shape.is_valid()) {
+ Vector<Vector2> polygon = convex_shape->get_points();
+ for (int point_index = 0; point_index < polygon.size(); point_index++) {
+ polygon.write[point_index] = csd.transform.xform(polygon[point_index]);
+ }
+ tile_data->set_collision_polygons_count(0, tile_data->get_collision_polygons_count(0) + 1);
+ int index = tile_data->get_collision_polygons_count(0) - 1;
+ tile_data->set_collision_polygon_one_way(0, index, csd.one_way);
+ tile_data->set_collision_polygon_one_way_margin(0, index, csd.one_way_margin);
+ tile_data->set_collision_polygon_points(0, index, polygon);
+ }
+ }
+ }
+ }
+ } break;
+ case COMPATIBILITY_TILE_MODE_AUTO_TILE: {
+ // Not supported. It would need manual conversion.
+ } break;
+ case COMPATIBILITY_TILE_MODE_ATLAS_TILE: {
atlas_source->set_margins(ctd->region.get_position());
atlas_source->set_separation(Vector2i(ctd->autotile_spacing, ctd->autotile_spacing));
atlas_source->set_texture_region_size(ctd->autotile_tile_size);
@@ -1578,6 +1908,25 @@ void TileSet::compatibility_conversion() {
} else {
alternative_tile = atlas_source->create_alternative_tile(coords);
}
+
+ // Add to the mapping.
+ Array key_array;
+ key_array.push_back(coords);
+ key_array.push_back(flip_h);
+ key_array.push_back(flip_v);
+ key_array.push_back(transpose);
+
+ Array value_array;
+ value_array.push_back(source_id);
+ value_array.push_back(coords);
+ value_array.push_back(alternative_tile);
+
+ if (!compatibility_tilemap_mapping.has(E->key())) {
+ compatibility_tilemap_mapping[E->key()] = Map<Array, Array>();
+ }
+ compatibility_tilemap_mapping[E->key()][key_array] = value_array;
+ compatibility_tilemap_mapping_tile_modes[E->key()] = COMPATIBILITY_TILE_MODE_ATLAS_TILE;
+
TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(coords, alternative_tile));
tile_data->set_flip_h(flip_h);
@@ -1641,7 +1990,7 @@ void TileSet::compatibility_conversion() {
}
}
}
- break;
+ } break;
}
// Offset all shapes
@@ -1655,9 +2004,6 @@ void TileSet::compatibility_conversion() {
convex->set_points(points);
}
}
-
- // Add the mapping to the map
- compatibility_source_mapping.insert(E->key(), source_id);
}
// Reset compatibility data
@@ -1666,14 +2012,50 @@ void TileSet::compatibility_conversion() {
}
compatibility_data = Map<int, CompatibilityTileData *>();
}
+
+Array TileSet::compatibility_tilemap_map(int p_tile_id, Vector2i p_coords, bool p_flip_h, bool p_flip_v, bool p_transpose) {
+ Array cannot_convert_array;
+ cannot_convert_array.push_back(TileSet::INVALID_SOURCE);
+ cannot_convert_array.push_back(TileSetAtlasSource::INVALID_ATLAS_COORDS);
+ cannot_convert_array.push_back(TileSetAtlasSource::INVALID_TILE_ALTERNATIVE);
+
+ if (!compatibility_tilemap_mapping.has(p_tile_id)) {
+ return cannot_convert_array;
+ }
+
+ int tile_mode = compatibility_tilemap_mapping_tile_modes[p_tile_id];
+ switch (tile_mode) {
+ case COMPATIBILITY_TILE_MODE_SINGLE_TILE: {
+ Array a;
+ a.push_back(p_flip_h);
+ a.push_back(p_flip_v);
+ a.push_back(p_transpose);
+ return compatibility_tilemap_mapping[p_tile_id][a];
+ }
+ case COMPATIBILITY_TILE_MODE_AUTO_TILE:
+ return cannot_convert_array;
+ break;
+ case COMPATIBILITY_TILE_MODE_ATLAS_TILE: {
+ Array a;
+ a.push_back(p_coords);
+ a.push_back(p_flip_h);
+ a.push_back(p_flip_v);
+ a.push_back(p_transpose);
+ return compatibility_tilemap_mapping[p_tile_id][a];
+ }
+ default:
+ return cannot_convert_array;
+ break;
+ }
+};
+
#endif // DISABLE_DEPRECATED
bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
Vector<String> components = String(p_name).split("/", true, 2);
#ifndef DISABLE_DEPRECATED
- // TODO: THIS IS HOW WE CHECK IF WE HAVE A DEPRECATED RESOURCE
- // This should be moved to a dedicated conversion system
+ // TODO: This should be moved to a dedicated conversion system (see #50691)
if (components.size() >= 1 && components[0].is_valid_int()) {
int id = components[0].to_int();
@@ -1809,29 +2191,23 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
/*
// IGNORED FOR NOW, they seem duplicated data compared to the shapes array
} else if (what == "shape") {
- // TODO
} else if (what == "shape_offset") {
- // TODO
} else if (what == "shape_transform") {
- // TODO
} else if (what == "shape_one_way") {
- // TODO
} else if (what == "shape_one_way_margin") {
- // TODO
}
// IGNORED FOR NOW, maybe useless ?
else if (what == "occluder_offset") {
// Not
} else if (what == "navigation_offset") {
- // TODO
}
*/
} else if (what == "z_index") {
ctd->z_index = p_value;
- // TODO: remove the conversion from here, it's not where it should be done
- compatibility_conversion();
+ // TODO: remove the conversion from here, it's not where it should be done (see #50691)
+ _compatibility_conversion();
} else {
return false;
}
@@ -1966,6 +2342,31 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
add_source(p_value, source_id);
}
return true;
+ } else if (components.size() == 2 && components[0] == "tile_proxies") {
+ ERR_FAIL_COND_V(p_value.get_type() != Variant::ARRAY, false);
+ Array a = p_value;
+ ERR_FAIL_COND_V(a.size() % 2 != 0, false);
+ if (components[1] == "source_level") {
+ for (int i = 0; i < a.size(); i += 2) {
+ set_source_level_tile_proxy(a[i], a[i + 1]);
+ }
+ return true;
+ } else if (components[1] == "coords_level") {
+ for (int i = 0; i < a.size(); i += 2) {
+ Array key = a[i];
+ Array value = a[i + 1];
+ set_coords_level_tile_proxy(key[0], key[1], value[0], value[1]);
+ }
+ return true;
+ } else if (components[1] == "alternative_level") {
+ for (int i = 0; i < a.size(); i += 2) {
+ Array key = a[i];
+ Array value = a[i + 1];
+ set_alternative_level_tile_proxy(key[0], key[1], key[2], value[0], value[1], value[2]);
+ }
+ return true;
+ }
+ return false;
}
#ifndef DISABLE_DEPRECATED
@@ -2065,6 +2466,33 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
} else {
return false;
}
+ } else if (components.size() == 2 && components[0] == "tile_proxies") {
+ if (components[1] == "source_level") {
+ Array a;
+ for (Map<int, int>::Element *E = source_level_proxies.front(); E; E = E->next()) {
+ a.push_back(E->key());
+ a.push_back(E->get());
+ }
+ r_ret = a;
+ return true;
+ } else if (components[1] == "coords_level") {
+ Array a;
+ for (Map<Array, Array>::Element *E = coords_level_proxies.front(); E; E = E->next()) {
+ a.push_back(E->key());
+ a.push_back(E->get());
+ }
+ r_ret = a;
+ return true;
+ } else if (components[1] == "alternative_level") {
+ Array a;
+ for (Map<Array, Array>::Element *E = alternative_level_proxies.front(); E; E = E->next()) {
+ a.push_back(E->key());
+ a.push_back(E->get());
+ }
+ r_ret = a;
+ return true;
+ }
+ return false;
}
return false;
@@ -2138,12 +2566,19 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
for (Map<int, Ref<TileSetSource>>::Element *E_source = sources.front(); E_source; E_source = E_source->next()) {
p_list->push_back(PropertyInfo(Variant::INT, vformat("sources/%d", E_source->key()), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
}
+
+ // Tile Proxies.
+ // Note: proxies need to be set after sources are set.
+ p_list->push_back(PropertyInfo(Variant::NIL, "Tile Proxies", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
+ p_list->push_back(PropertyInfo(Variant::ARRAY, "tile_proxies/source_level", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
+ p_list->push_back(PropertyInfo(Variant::ARRAY, "tile_proxies/coords_level", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
+ p_list->push_back(PropertyInfo(Variant::ARRAY, "tile_proxies/alternative_level", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
}
void TileSet::_bind_methods() {
// Sources management.
ClassDB::bind_method(D_METHOD("get_next_source_id"), &TileSet::get_next_source_id);
- ClassDB::bind_method(D_METHOD("add_source", "atlas_source_id_override"), &TileSet::add_source, DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("add_source", "atlas_source_id_override"), &TileSet::add_source, DEFVAL(TileSet::INVALID_SOURCE));
ClassDB::bind_method(D_METHOD("remove_source", "source_id"), &TileSet::remove_source);
ClassDB::bind_method(D_METHOD("set_source_id", "source_id"), &TileSet::set_source_id);
ClassDB::bind_method(D_METHOD("get_source_count"), &TileSet::get_source_count);
@@ -2212,6 +2647,27 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_custom_data_layers_count", "custom_data_layers_count"), &TileSet::set_custom_data_layers_count);
ClassDB::bind_method(D_METHOD("get_custom_data_layers_count"), &TileSet::get_custom_data_layers_count);
+ // Tile proxies
+ ClassDB::bind_method(D_METHOD("set_source_level_tile_proxy", "source_from", "source_to"), &TileSet::set_source_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("get_source_level_tile_proxy", "source_from"), &TileSet::get_source_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("has_source_level_tile_proxy", "source_from"), &TileSet::has_source_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("remove_source_level_tile_proxy", "source_from"), &TileSet::remove_source_level_tile_proxy);
+
+ ClassDB::bind_method(D_METHOD("set_coords_level_tile_proxy", "p_source_from", "coords_from", "source_to", "coords_to"), &TileSet::set_coords_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("get_coords_level_tile_proxy", "source_from", "coords_from"), &TileSet::get_coords_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("has_coords_level_tile_proxy", "source_from", "coords_from"), &TileSet::has_coords_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("remove_coords_level_tile_proxy", "source_from", "coords_from"), &TileSet::remove_coords_level_tile_proxy);
+
+ ClassDB::bind_method(D_METHOD("set_alternative_level_tile_proxy", "source_from", "coords_from", "alternative_from", "source_to", "coords_to", "alternative_to"), &TileSet::set_alternative_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("get_alternative_level_tile_proxy", "source_from", "coords_from", "alternative_from"), &TileSet::get_alternative_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("has_alternative_level_tile_proxy", "source_from", "coords_from", "alternative_from"), &TileSet::has_alternative_level_tile_proxy);
+ ClassDB::bind_method(D_METHOD("remove_alternative_level_tile_proxy", "source_from", "coords_from", "alternative_from"), &TileSet::remove_alternative_level_tile_proxy);
+
+ ClassDB::bind_method(D_METHOD("map_tile_proxy", "source_from", "coords_from", "alternative_from"), &TileSet::map_tile_proxy);
+
+ ClassDB::bind_method(D_METHOD("cleanup_invalid_tile_proxies"), &TileSet::cleanup_invalid_tile_proxies);
+ ClassDB::bind_method(D_METHOD("clear_tile_proxies"), &TileSet::clear_tile_proxies);
+
ADD_GROUP("Rendering", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uv_clipping"), "set_uv_clipping", "is_uv_clipping");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "y_sorting"), "set_y_sorting", "is_y_sorting");
@@ -2272,7 +2728,7 @@ TileSet::TileSet() {
tile_lines_mesh.instantiate();
tile_filled_mesh.instantiate();
- // Instanciate and list all plugins.
+ // Instantiate and list all plugins.
tile_set_plugins_vector.append(memnew(TileSetPluginAtlasRendering));
tile_set_plugins_vector.append(memnew(TileSetPluginAtlasPhysics));
tile_set_plugins_vector.append(memnew(TileSetPluginAtlasNavigation));
@@ -2569,7 +3025,7 @@ void TileSetAtlasSource::create_tile(const Vector2i p_atlas_coords, const Vector
}
}
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) {
@@ -2595,7 +3051,7 @@ void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) {
tiles_ids.erase(p_atlas_coords);
tiles_ids.sort();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool TileSetAtlasSource::has_tile(Vector2i p_atlas_coords) const {
@@ -2723,7 +3179,7 @@ void TileSetAtlasSource::move_tile_in_atlas(Vector2i p_atlas_coords, Vector2i p_
}
}
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool TileSetAtlasSource::has_tiles_outside_texture() {
@@ -2755,8 +3211,8 @@ void TileSetAtlasSource::clear_tiles_outside_texture() {
}
int TileSetAtlasSource::create_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_id_override) {
- ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), -1, vformat("TileSetAtlasSource has no tile at %s.", String(p_atlas_coords)));
- ERR_FAIL_COND_V_MSG(p_alternative_id_override >= 0 && tiles[p_atlas_coords].alternatives.has(p_alternative_id_override), -1, vformat("Cannot create alternative tile. Another alternative exists with id %d.", p_alternative_id_override));
+ ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), TileSetSource::INVALID_TILE_ALTERNATIVE, vformat("TileSetAtlasSource has no tile at %s.", String(p_atlas_coords)));
+ ERR_FAIL_COND_V_MSG(p_alternative_id_override >= 0 && tiles[p_atlas_coords].alternatives.has(p_alternative_id_override), TileSetSource::INVALID_TILE_ALTERNATIVE, vformat("Cannot create alternative tile. Another alternative exists with id %d.", p_alternative_id_override));
int new_alternative_id = p_alternative_id_override >= 0 ? p_alternative_id_override : tiles[p_atlas_coords].next_alternative_id;
@@ -2768,7 +3224,7 @@ int TileSetAtlasSource::create_alternative_tile(const Vector2i p_atlas_coords, i
tiles[p_atlas_coords].alternatives_ids.sort();
_compute_next_alternative_id(p_atlas_coords);
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
return new_alternative_id;
}
@@ -2783,7 +3239,7 @@ void TileSetAtlasSource::remove_alternative_tile(const Vector2i p_atlas_coords,
tiles[p_atlas_coords].alternatives_ids.erase(p_alternative_tile);
tiles[p_atlas_coords].alternatives_ids.sort();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileSetAtlasSource::set_alternative_tile_id(const Vector2i p_atlas_coords, int p_alternative_tile, int p_new_id) {
@@ -2800,7 +3256,7 @@ void TileSetAtlasSource::set_alternative_tile_id(const Vector2i p_atlas_coords,
tiles[p_atlas_coords].alternatives_ids.erase(p_alternative_tile);
tiles[p_atlas_coords].alternatives_ids.sort();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool TileSetAtlasSource::has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const {
@@ -2809,7 +3265,7 @@ bool TileSetAtlasSource::has_alternative_tile(const Vector2i p_atlas_coords, int
}
int TileSetAtlasSource::get_next_alternative_tile_id(const Vector2i p_atlas_coords) const {
- ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), -1, vformat("The TileSetAtlasSource atlas has no tile at %s.", String(p_atlas_coords)));
+ ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), TileSetSource::INVALID_TILE_ALTERNATIVE, vformat("The TileSetAtlasSource atlas has no tile at %s.", String(p_atlas_coords)));
return tiles[p_atlas_coords].next_alternative_id;
}
@@ -2819,8 +3275,8 @@ int TileSetAtlasSource::get_alternative_tiles_count(const Vector2i p_atlas_coord
}
int TileSetAtlasSource::get_alternative_tile_id(const Vector2i p_atlas_coords, int p_index) const {
- ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), -1, vformat("The TileSetAtlasSource atlas has no tile at %s.", String(p_atlas_coords)));
- ERR_FAIL_INDEX_V(p_index, tiles[p_atlas_coords].alternatives_ids.size(), -1);
+ ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), TileSetSource::INVALID_TILE_ALTERNATIVE, vformat("The TileSetAtlasSource atlas has no tile at %s.", String(p_atlas_coords)));
+ ERR_FAIL_INDEX_V(p_index, tiles[p_atlas_coords].alternatives_ids.size(), TileSetSource::INVALID_TILE_ALTERNATIVE);
return tiles[p_atlas_coords].alternatives_ids[p_index];
}
@@ -2861,7 +3317,7 @@ void TileSetAtlasSource::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tile_at_coords", "atlas_coords"), &TileSetAtlasSource::get_tile_at_coords);
// Alternative tiles
- ClassDB::bind_method(D_METHOD("create_alternative_tile", "atlas_coords", "alternative_id_override"), &TileSetAtlasSource::create_alternative_tile, DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("create_alternative_tile", "atlas_coords", "alternative_id_override"), &TileSetAtlasSource::create_alternative_tile, DEFVAL(INVALID_TILE_ALTERNATIVE));
ClassDB::bind_method(D_METHOD("remove_alternative_tile", "atlas_coords", "alternative_tile"), &TileSetAtlasSource::remove_alternative_tile);
ClassDB::bind_method(D_METHOD("set_alternative_tile_id", "atlas_coords", "alternative_tile", "new_id"), &TileSetAtlasSource::set_alternative_tile_id);
ClassDB::bind_method(D_METHOD("has_alternative_tile", "atlas_coords", "alternative_tile"), &TileSetAtlasSource::has_alternative_tile);
@@ -2948,7 +3404,7 @@ bool TileSetScenesCollectionSource::has_alternative_tile(const Vector2i p_atlas_
}
int TileSetScenesCollectionSource::create_scene_tile(Ref<PackedScene> p_packed_scene, int p_id_override) {
- ERR_FAIL_COND_V_MSG(p_id_override >= 0 && scenes.has(p_id_override), -1, vformat("Cannot create scene tile. Another scene tile exists with id %d.", p_id_override));
+ ERR_FAIL_COND_V_MSG(p_id_override >= 0 && scenes.has(p_id_override), INVALID_TILE_ALTERNATIVE, vformat("Cannot create scene tile. Another scene tile exists with id %d.", p_id_override));
int new_scene_id = p_id_override >= 0 ? p_id_override : next_scene_id;
@@ -2958,7 +3414,7 @@ int TileSetScenesCollectionSource::create_scene_tile(Ref<PackedScene> p_packed_s
set_scene_tile_scene(new_scene_id, p_packed_scene);
_compute_next_alternative_id();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
return new_scene_id;
}
@@ -2978,7 +3434,7 @@ void TileSetScenesCollectionSource::set_scene_tile_id(int p_id, int p_new_id) {
scenes.erase(p_id);
scenes_ids.erase(p_id);
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedScene> p_packed_scene) {
@@ -2997,7 +3453,7 @@ void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedSce
} else {
scenes[p_id].scene = Ref<PackedScene>();
}
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
Ref<PackedScene> TileSetScenesCollectionSource::get_scene_tile_scene(int p_id) const {
@@ -3010,7 +3466,7 @@ void TileSetScenesCollectionSource::set_scene_tile_display_placeholder(int p_id,
scenes[p_id].display_placeholder = p_display_placeholder;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool TileSetScenesCollectionSource::get_scene_tile_display_placeholder(int p_id) const {
@@ -3023,7 +3479,7 @@ void TileSetScenesCollectionSource::remove_scene_tile(int p_id) {
scenes.erase(p_id);
scenes_ids.erase(p_id);
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
int TileSetScenesCollectionSource::get_next_scene_tile_id() const {
@@ -3096,7 +3552,7 @@ void TileSetScenesCollectionSource::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_scene_tiles_count"), &TileSetScenesCollectionSource::get_scene_tiles_count);
ClassDB::bind_method(D_METHOD("get_scene_tile_id", "index"), &TileSetScenesCollectionSource::get_scene_tile_id);
ClassDB::bind_method(D_METHOD("has_scene_tile_id", "id"), &TileSetScenesCollectionSource::has_scene_tile_id);
- ClassDB::bind_method(D_METHOD("create_scene_tile", "packed_scene", "id_override"), &TileSetScenesCollectionSource::create_scene_tile, DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("create_scene_tile", "packed_scene", "id_override"), &TileSetScenesCollectionSource::create_scene_tile, DEFVAL(INVALID_TILE_ALTERNATIVE));
ClassDB::bind_method(D_METHOD("set_scene_tile_id", "id", "new_id"), &TileSetScenesCollectionSource::set_scene_tile_id);
ClassDB::bind_method(D_METHOD("set_scene_tile_scene", "id", "packed_scene"), &TileSetScenesCollectionSource::set_scene_tile_scene);
ClassDB::bind_method(D_METHOD("get_scene_tile_scene", "id"), &TileSetScenesCollectionSource::get_scene_tile_scene);
@@ -3144,7 +3600,7 @@ void TileData::notify_tile_data_properties_should_change() {
}
notify_property_list_changed();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileData::reset_state() {
@@ -3166,7 +3622,7 @@ bool TileData::is_allowing_transform() const {
void TileData::set_flip_h(bool p_flip_h) {
ERR_FAIL_COND_MSG(!allow_transform && p_flip_h, "Transform is only allowed for alternative tiles (with its alternative_id != 0)");
flip_h = p_flip_h;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool TileData::get_flip_h() const {
return flip_h;
@@ -3175,7 +3631,7 @@ bool TileData::get_flip_h() const {
void TileData::set_flip_v(bool p_flip_v) {
ERR_FAIL_COND_MSG(!allow_transform && p_flip_v, "Transform is only allowed for alternative tiles (with its alternative_id != 0)");
flip_v = p_flip_v;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool TileData::get_flip_v() const {
@@ -3185,7 +3641,7 @@ bool TileData::get_flip_v() const {
void TileData::set_transpose(bool p_transpose) {
ERR_FAIL_COND_MSG(!allow_transform && p_transpose, "Transform is only allowed for alternative tiles (with its alternative_id != 0)");
transpose = p_transpose;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool TileData::get_transpose() const {
return transpose;
@@ -3193,7 +3649,7 @@ bool TileData::get_transpose() const {
void TileData::set_texture_offset(Vector2i p_texture_offset) {
tex_offset = p_texture_offset;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
Vector2i TileData::get_texture_offset() const {
@@ -3202,7 +3658,7 @@ Vector2i TileData::get_texture_offset() const {
void TileData::tile_set_material(Ref<ShaderMaterial> p_material) {
material = p_material;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
Ref<ShaderMaterial> TileData::tile_get_material() const {
return material;
@@ -3210,7 +3666,7 @@ Ref<ShaderMaterial> TileData::tile_get_material() const {
void TileData::set_modulate(Color p_modulate) {
modulate = p_modulate;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
Color TileData::get_modulate() const {
return modulate;
@@ -3218,7 +3674,7 @@ Color TileData::get_modulate() const {
void TileData::set_z_index(int p_z_index) {
z_index = p_z_index;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
int TileData::get_z_index() const {
return z_index;
@@ -3226,7 +3682,7 @@ int TileData::get_z_index() const {
void TileData::set_y_sort_origin(int p_y_sort_origin) {
y_sort_origin = p_y_sort_origin;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
int TileData::get_y_sort_origin() const {
return y_sort_origin;
@@ -3235,7 +3691,7 @@ int TileData::get_y_sort_origin() const {
void TileData::set_occluder(int p_layer_id, Ref<OccluderPolygon2D> p_occluder_polygon) {
ERR_FAIL_INDEX(p_layer_id, occluders.size());
occluders.write[p_layer_id] = p_occluder_polygon;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
Ref<OccluderPolygon2D> TileData::get_occluder(int p_layer_id) const {
@@ -3254,20 +3710,20 @@ void TileData::set_collision_polygons_count(int p_layer_id, int p_polygons_count
ERR_FAIL_COND(p_polygons_count < 0);
physics.write[p_layer_id].polygons.resize(p_polygons_count);
notify_property_list_changed();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileData::add_collision_polygon(int p_layer_id) {
ERR_FAIL_INDEX(p_layer_id, physics.size());
physics.write[p_layer_id].polygons.push_back(PhysicsLayerTileData::PolygonShapeTileData());
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileData::remove_collision_polygon(int p_layer_id, int p_polygon_index) {
ERR_FAIL_INDEX(p_layer_id, physics.size());
ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size());
physics.write[p_layer_id].polygons.remove(p_polygon_index);
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void TileData::set_collision_polygon_points(int p_layer_id, int p_polygon_index, Vector<Vector2> p_polygon) {
@@ -3291,7 +3747,7 @@ void TileData::set_collision_polygon_points(int p_layer_id, int p_polygon_index,
}
}
physics.write[p_layer_id].polygons.write[p_polygon_index].polygon = p_polygon;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
Vector<Vector2> TileData::get_collision_polygon_points(int p_layer_id, int p_polygon_index) const {
@@ -3304,7 +3760,7 @@ void TileData::set_collision_polygon_one_way(int p_layer_id, int p_polygon_index
ERR_FAIL_INDEX(p_layer_id, physics.size());
ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size());
physics.write[p_layer_id].polygons.write[p_polygon_index].one_way = p_one_way;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool TileData::is_collision_polygon_one_way(int p_layer_id, int p_polygon_index) const {
@@ -3317,7 +3773,7 @@ void TileData::set_collision_polygon_one_way_margin(int p_layer_id, int p_polygo
ERR_FAIL_INDEX(p_layer_id, physics.size());
ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size());
physics.write[p_layer_id].polygons.write[p_polygon_index].one_way_margin = p_one_way_margin;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
float TileData::get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const {
@@ -3353,7 +3809,7 @@ void TileData::set_terrain_set(int p_terrain_set) {
}
terrain_set = p_terrain_set;
notify_property_list_changed();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
int TileData::get_terrain_set() const {
@@ -3368,7 +3824,7 @@ void TileData::set_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit, int
ERR_FAIL_COND(!is_valid_peering_bit_terrain(p_peering_bit));
}
terrain_peering_bits[p_peering_bit] = p_terrain_index;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
int TileData::get_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit) const {
@@ -3386,7 +3842,7 @@ bool TileData::is_valid_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit)
void TileData::set_navigation_polygon(int p_layer_id, Ref<NavigationPolygon> p_navigation_polygon) {
ERR_FAIL_INDEX(p_layer_id, navigation.size());
navigation.write[p_layer_id] = p_navigation_polygon;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id) const {
@@ -3398,7 +3854,7 @@ Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id) const {
void TileData::set_probability(float p_probability) {
ERR_FAIL_COND(p_probability < 0.0);
probability = p_probability;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
float TileData::get_probability() const {
return probability;
@@ -3422,7 +3878,7 @@ Variant TileData::get_custom_data(String p_layer_name) const {
void TileData::set_custom_data_by_layer_id(int p_layer_id, Variant p_value) {
ERR_FAIL_INDEX(p_layer_id, custom_data.size());
custom_data.write[p_layer_id] = p_value;
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
Variant TileData::get_custom_data_by_layer_id(int p_layer_id) const {
@@ -3901,14 +4357,14 @@ void TileSetPluginAtlasRendering::update_dirty_quadrants(TileMap *p_tile_map, Se
RenderingServer *rs = RenderingServer::get_singleton();
// Free the canvas items.
- for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
- rs->free(E->get());
+ for (const RID &E : q.canvas_items) {
+ rs->free(E);
}
q.canvas_items.clear();
// Free the occluders.
- for (List<RID>::Element *E = q.occluders.front(); E; E = E->next()) {
- rs->free(E->get());
+ for (const RID &E : q.occluders) {
+ rs->free(E);
}
q.occluders.clear();
@@ -3919,7 +4375,7 @@ void TileSetPluginAtlasRendering::update_dirty_quadrants(TileMap *p_tile_map, Se
// Iterate over the cells of the quadrant.
for (Map<Vector2i, Vector2i, TileMapQuadrant::CoordsWorldComparator>::Element *E_cell = q.world_to_map.front(); E_cell; E_cell = E_cell->next()) {
- TileMapCell c = p_tile_map->get_cell(E_cell->value());
+ TileMapCell c = p_tile_map->get_cell(E_cell->value(), true);
TileSetSource *source;
if (tile_set->has_source(c.source_id)) {
@@ -4017,8 +4473,8 @@ void TileSetPluginAtlasRendering::update_dirty_quadrants(TileMap *p_tile_map, Se
// Sort the quadrants
for (Map<Vector2i, Vector2i, TileMapQuadrant::CoordsWorldComparator>::Element *E = world_to_map.front(); E; E = E->next()) {
TileMapQuadrant &q = quadrant_map[E->value()];
- for (List<RID>::Element *F = q.canvas_items.front(); F; F = F->next()) {
- RS::get_singleton()->canvas_item_set_draw_index(F->get(), index++);
+ for (const RID &F : q.canvas_items) {
+ RS::get_singleton()->canvas_item_set_draw_index(F, index++);
}
}
@@ -4035,14 +4491,14 @@ void TileSetPluginAtlasRendering::create_quadrant(TileMap *p_tile_map, TileMapQu
void TileSetPluginAtlasRendering::cleanup_quadrant(TileMap *p_tile_map, TileMapQuadrant *p_quadrant) {
// Free the canvas items.
- for (List<RID>::Element *E = p_quadrant->canvas_items.front(); E; E = E->next()) {
- RenderingServer::get_singleton()->free(E->get());
+ for (const RID &E : p_quadrant->canvas_items) {
+ RenderingServer::get_singleton()->free(E);
}
p_quadrant->canvas_items.clear();
// Free the occluders.
- for (List<RID>::Element *E = p_quadrant->occluders.front(); E; E = E->next()) {
- RenderingServer::get_singleton()->free(E->get());
+ for (const RID &E : p_quadrant->occluders) {
+ RenderingServer::get_singleton()->free(E);
}
p_quadrant->occluders.clear();
}
@@ -4059,7 +4515,7 @@ void TileSetPluginAtlasRendering::draw_quadrant_debug(TileMap *p_tile_map, TileM
RenderingServer *rs = RenderingServer::get_singleton();
Vector2 quadrant_pos = p_tile_map->map_to_world(p_quadrant->coords * p_tile_map->get_effective_quadrant_size());
for (Set<Vector2i>::Element *E_cell = p_quadrant->cells.front(); E_cell; E_cell = E_cell->next()) {
- const TileMapCell &c = p_tile_map->get_cell(E_cell->get());
+ const TileMapCell &c = p_tile_map->get_cell(E_cell->get(), true);
TileSetSource *source;
if (tile_set->has_source(c.source_id)) {
@@ -4151,7 +4607,7 @@ void TileSetPluginAtlasPhysics::update_dirty_quadrants(TileMap *p_tile_map, Self
}
for (Set<Vector2i>::Element *E_cell = q.cells.front(); E_cell; E_cell = E_cell->next()) {
- TileMapCell c = p_tile_map->get_cell(E_cell->get());
+ TileMapCell c = p_tile_map->get_cell(E_cell->get(), true);
TileSetSource *source;
if (tile_set->has_source(c.source_id)) {
@@ -4276,7 +4732,7 @@ void TileSetPluginAtlasPhysics::draw_quadrant_debug(TileMap *p_tile_map, TileMap
Color debug_collision_color = p_tile_map->get_tree()->get_debug_collisions_color();
for (Set<Vector2i>::Element *E_cell = p_quadrant->cells.front(); E_cell; E_cell = E_cell->next()) {
- TileMapCell c = p_tile_map->get_cell(E_cell->get());
+ TileMapCell c = p_tile_map->get_cell(E_cell->get(), true);
Transform2D xform;
xform.set_origin(p_tile_map->map_to_world(E_cell->get()) - quadrant_pos);
@@ -4370,7 +4826,7 @@ void TileSetPluginAtlasNavigation::update_dirty_quadrants(TileMap *p_tile_map, S
// Get the navigation polygons and create regions.
for (Set<Vector2i>::Element *E_cell = q.cells.front(); E_cell; E_cell = E_cell->next()) {
- TileMapCell c = p_tile_map->get_cell(E_cell->get());
+ TileMapCell c = p_tile_map->get_cell(E_cell->get(), true);
TileSetSource *source;
if (tile_set->has_source(c.source_id)) {
@@ -4455,7 +4911,7 @@ void TileSetPluginAtlasNavigation::draw_quadrant_debug(TileMap *p_tile_map, Tile
Vector2 quadrant_pos = p_tile_map->map_to_world(p_quadrant->coords * p_tile_map->get_effective_quadrant_size());
for (Set<Vector2i>::Element *E_cell = p_quadrant->cells.front(); E_cell; E_cell = E_cell->next()) {
- TileMapCell c = p_tile_map->get_cell(E_cell->get());
+ TileMapCell c = p_tile_map->get_cell(E_cell->get(), true);
TileSetSource *source;
if (tile_set->has_source(c.source_id)) {
@@ -4526,7 +4982,7 @@ void TileSetPluginScenesCollections::update_dirty_quadrants(TileMap *p_tile_map,
// Recreate the scenes.
for (Set<Vector2i>::Element *E_cell = q.cells.front(); E_cell; E_cell = E_cell->next()) {
- const TileMapCell &c = p_tile_map->get_cell(E_cell->get());
+ const TileMapCell &c = p_tile_map->get_cell(E_cell->get(), true);
TileSetSource *source;
if (tile_set->has_source(c.source_id)) {
@@ -4585,7 +5041,7 @@ void TileSetPluginScenesCollections::draw_quadrant_debug(TileMap *p_tile_map, Ti
RenderingServer *rs = RenderingServer::get_singleton();
Vector2 quadrant_pos = p_tile_map->map_to_world(p_quadrant->coords * p_tile_map->get_effective_quadrant_size());
for (Set<Vector2i>::Element *E_cell = p_quadrant->cells.front(); E_cell; E_cell = E_cell->next()) {
- const TileMapCell &c = p_tile_map->get_cell(E_cell->get());
+ const TileMapCell &c = p_tile_map->get_cell(E_cell->get(), true);
TileSetSource *source;
if (tile_set->has_source(c.source_id)) {
diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h
index dbf6dbabe6..0a07981171 100644
--- a/scene/resources/tile_set.h
+++ b/scene/resources/tile_set.h
@@ -79,15 +79,15 @@ private:
Vector2 tex_offset;
Ref<ShaderMaterial> material;
Rect2 region;
- int tile_mode;
- Color modulate;
+ int tile_mode = 0;
+ Color modulate = Color(1, 1, 1);
// Atlas or autotiles data
- int autotile_bitmask_mode;
+ int autotile_bitmask_mode = 0;
Vector2 autotile_icon_coordinate;
Size2i autotile_tile_size = Size2i(16, 16);
- int autotile_spacing;
+ int autotile_spacing = 0;
Map<Vector2i, int> autotile_bitmask_flags;
Map<Vector2i, Ref<OccluderPolygon2D>> autotile_occluder_map;
Map<Vector2i, Ref<NavigationPolygon>> autotile_navpoly_map;
@@ -99,23 +99,29 @@ private:
Vector2 occluder_offset;
Ref<NavigationPolygon> navigation;
Vector2 navigation_offset;
- int z_index;
+ int z_index = 0;
};
- Map<int, CompatibilityTileData *> compatibility_data = Map<int, CompatibilityTileData *>();
- Map<int, int> compatibility_source_mapping = Map<int, int>();
+ enum CompatibilityTileMode {
+ COMPATIBILITY_TILE_MODE_SINGLE_TILE = 0,
+ COMPATIBILITY_TILE_MODE_AUTO_TILE,
+ COMPATIBILITY_TILE_MODE_ATLAS_TILE,
+ };
-private:
- void compatibility_conversion();
+ Map<int, CompatibilityTileData *> compatibility_data;
+ Map<int, int> compatibility_tilemap_mapping_tile_modes;
+ Map<int, Map<Array, Array>> compatibility_tilemap_mapping;
-public:
- int compatibility_get_source_for_tile_id(int p_old_source) {
- return compatibility_source_mapping[p_old_source];
- };
+ void _compatibility_conversion();
+public:
+ // Format of output array [source_id, atlas_coords, alternative]
+ Array compatibility_tilemap_map(int p_tile_id, Vector2i p_coords, bool p_flip_h, bool p_flip_v, bool p_transpose);
#endif // DISABLE_DEPRECATED
public:
+ static const int INVALID_SOURCE; // -1;
+
enum CellNeighbor {
CELL_NEIGHBOR_RIGHT_SIDE = 0,
CELL_NEIGHBOR_RIGHT_CORNER,
@@ -165,7 +171,6 @@ public:
TILE_OFFSET_AXIS_VERTICAL,
};
-public:
struct PackedSceneSource {
Ref<PackedScene> scene;
Vector2 offset;
@@ -246,6 +251,11 @@ private:
void _compute_next_source_id();
void _source_changed();
+ // Tile proxies
+ Map<int, int> source_level_proxies;
+ Map<Array, Array> coords_level_proxies;
+ Map<Array, Array> alternative_level_proxies;
+
// Helpers
Vector<Point2> _get_square_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
Vector<Point2> _get_square_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
@@ -341,6 +351,31 @@ public:
void set_custom_data_type(int p_layer_id, Variant::Type p_value);
Variant::Type get_custom_data_type(int p_layer_id) const;
+ // Tiles proxies.
+ void set_source_level_tile_proxy(int p_source_from, int p_source_to);
+ int get_source_level_tile_proxy(int p_source_from);
+ bool has_source_level_tile_proxy(int p_source_from);
+ void remove_source_level_tile_proxy(int p_source_from);
+
+ void set_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_source_to, Vector2i p_coords_to);
+ Array get_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from);
+ bool has_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from);
+ void remove_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from);
+
+ void set_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from, int p_source_to, Vector2i p_coords_to, int p_alternative_to);
+ Array get_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from);
+ bool has_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from);
+ void remove_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from);
+
+ Array get_source_level_tile_proxies() const;
+ Array get_coords_level_tile_proxies() const;
+ Array get_alternative_level_tile_proxies() const;
+
+ Array map_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) const;
+
+ void cleanup_invalid_tile_proxies();
+ void clear_tile_proxies();
+
// Helpers
Vector<Vector2> get_tile_shape_polygon();
void draw_tile_shape(CanvasItem *p_canvas_item, Rect2 p_region, Color p_color, bool p_filled = false, Ref<Texture2D> p_texture = Ref<Texture2D>());
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 54bc7382db..7292728251 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -352,14 +352,14 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::
for (int i = 0; i < get_output_port_count(); i++) {
output_vars.push_back(p_output_vars[i]);
}
- String code = "\t{\n";
+ String code = " {\n";
String _code = (String)get_script_instance()->call("_get_code", input_vars, output_vars, (int)p_mode, (int)p_type);
bool nend = _code.ends_with("\n");
- _code = _code.insert(0, "\t\t");
- _code = _code.replace("\n", "\n\t\t");
+ _code = _code.insert(0, " ");
+ _code = _code.replace("\n", "\n ");
code += _code;
if (!nend) {
- code += "\n\t}";
+ code += "\n }";
} else {
code.remove(code.size() - 1);
code += "}";
@@ -628,8 +628,8 @@ bool VisualShader::is_node_connection(Type p_type, int p_from_node, int p_from_p
ERR_FAIL_INDEX_V(p_type, TYPE_MAX, false);
const Graph *g = &graph[p_type];
- for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
- if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
+ for (const Connection &E : g->connections) {
+ if (E.from_node == p_from_node && E.from_port == p_from_port && E.to_node == p_to_node && E.to_port == p_to_port) {
return true;
}
}
@@ -642,12 +642,12 @@ bool VisualShader::is_nodes_connected_relatively(const Graph *p_graph, int p_nod
const VisualShader::Node &node = p_graph->nodes[p_node];
- for (const List<int>::Element *E = node.prev_connected_nodes.front(); E; E = E->next()) {
- if (E->get() == p_target) {
+ for (const int &E : node.prev_connected_nodes) {
+ if (E == p_target) {
return true;
}
- result = is_nodes_connected_relatively(p_graph, E->get(), p_target);
+ result = is_nodes_connected_relatively(p_graph, E, p_target);
if (result) {
break;
}
@@ -686,8 +686,8 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po
return false;
}
- for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
- if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
+ for (const Connection &E : g->connections) {
+ if (E.from_node == p_from_node && E.from_port == p_from_port && E.to_node == p_to_node && E.to_port == p_to_port) {
return false;
}
}
@@ -739,8 +739,8 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port,
ERR_FAIL_COND_V_MSG(!is_port_types_compatible(from_port_type, to_port_type), ERR_INVALID_PARAMETER, "Incompatible port types (scalar/vec/bool) with transform.");
- for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
- if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
+ for (const Connection &E : g->connections) {
+ if (E.from_node == p_from_node && E.from_port == p_from_port && E.to_node == p_to_node && E.to_port == p_to_port) {
ERR_FAIL_V(ERR_ALREADY_EXISTS);
}
}
@@ -763,7 +763,7 @@ void VisualShader::disconnect_nodes(Type p_type, int p_from_node, int p_from_por
ERR_FAIL_INDEX(p_type, TYPE_MAX);
Graph *g = &graph[p_type];
- for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
+ for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
g->connections.erase(E);
g->nodes[p_to_node].prev_connected_nodes.erase(p_from_node);
@@ -780,12 +780,12 @@ Array VisualShader::_get_node_connections(Type p_type) const {
const Graph *g = &graph[p_type];
Array ret;
- for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
+ for (const Connection &E : g->connections) {
Dictionary d;
- d["from_node"] = E->get().from_node;
- d["from_port"] = E->get().from_port;
- d["to_node"] = E->get().to_node;
- d["to_port"] = E->get().to_port;
+ d["from_node"] = E.from_node;
+ d["from_port"] = E.from_port;
+ d["to_node"] = E.to_node;
+ d["to_port"] = E.to_port;
ret.push_back(d);
}
@@ -796,8 +796,8 @@ void VisualShader::get_node_connections(Type p_type, List<Connection> *r_connect
ERR_FAIL_INDEX(p_type, TYPE_MAX);
const Graph *g = &graph[p_type];
- for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
- r_connections->push_back(E->get());
+ for (const Connection &E : g->connections) {
+ r_connections->push_back(E);
}
}
@@ -900,7 +900,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
String expr = "";
expr += "// " + global_expression->get_caption() + ":" + itos(index++) + "\n";
expr += global_expression->generate_global(get_mode(), Type(i), -1);
- expr = expr.replace("\n", "\n\t");
+ expr = expr.replace("\n", "\n ");
expr += "\n";
global_expressions += expr;
}
@@ -935,13 +935,13 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
ERR_FAIL_COND_V(err != OK, String());
if (node->get_output_port_type(p_port) == VisualShaderNode::PORT_TYPE_SCALAR) {
- code += "\tCOLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " );\n";
+ code += " COLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " );\n";
} else if (node->get_output_port_type(p_port) == VisualShaderNode::PORT_TYPE_SCALAR_INT) {
- code += "\tCOLOR.rgb = vec3(float(n_out" + itos(p_node) + "p" + itos(p_port) + "));\n";
+ code += " COLOR.rgb = vec3(float(n_out" + itos(p_node) + "p" + itos(p_port) + "));\n";
} else if (node->get_output_port_type(p_port) == VisualShaderNode::PORT_TYPE_BOOLEAN) {
- code += "\tCOLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " ? 1.0 : 0.0);\n";
+ code += " COLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " ? 1.0 : 0.0);\n";
} else {
- code += "\tCOLOR.rgb = n_out" + itos(p_node) + "p" + itos(p_port) + ";\n";
+ code += " COLOR.rgb = n_out" + itos(p_node) + "p" + itos(p_port) + ";\n";
}
code += "}\n";
@@ -1190,11 +1190,11 @@ bool VisualShader::_get(const StringName &p_name, Variant &r_ret) const {
String index = name.get_slicec('/', 2);
if (index == "connections") {
Vector<int> conns;
- for (const List<Connection>::Element *E = graph[type].connections.front(); E; E = E->next()) {
- conns.push_back(E->get().from_node);
- conns.push_back(E->get().from_port);
- conns.push_back(E->get().to_node);
- conns.push_back(E->get().to_port);
+ for (const Connection &E : graph[type].connections) {
+ conns.push_back(E.from_node);
+ conns.push_back(E.from_port);
+ conns.push_back(E.to_node);
+ conns.push_back(E.to_port);
}
r_ret = conns;
@@ -1302,7 +1302,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
if (vsnode->is_disabled()) {
code += "// " + vsnode->get_caption() + ":" + itos(node) + "\n";
- code += "\t// Node is disabled and code is not generated.\n";
+ code += " // Node is disabled and code is not generated.\n";
return OK;
}
@@ -1432,19 +1432,19 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
if (defval.get_type() == Variant::FLOAT) {
float val = defval;
inputs[i] = "n_in" + itos(node) + "p" + itos(i);
- node_code += "\tfloat " + inputs[i] + " = " + vformat("%.5f", val) + ";\n";
+ node_code += " float " + inputs[i] + " = " + vformat("%.5f", val) + ";\n";
} else if (defval.get_type() == Variant::INT) {
int val = defval;
inputs[i] = "n_in" + itos(node) + "p" + itos(i);
- node_code += "\tint " + inputs[i] + " = " + itos(val) + ";\n";
+ node_code += " int " + inputs[i] + " = " + itos(val) + ";\n";
} else if (defval.get_type() == Variant::BOOL) {
bool val = defval;
inputs[i] = "n_in" + itos(node) + "p" + itos(i);
- node_code += "\tbool " + inputs[i] + " = " + (val ? "true" : "false") + ";\n";
+ node_code += " bool " + inputs[i] + " = " + (val ? "true" : "false") + ";\n";
} else if (defval.get_type() == Variant::VECTOR3) {
Vector3 val = defval;
inputs[i] = "n_in" + itos(node) + "p" + itos(i);
- node_code += "\tvec3 " + inputs[i] + " = " + vformat("vec3(%.5f, %.5f, %.5f);\n", val.x, val.y, val.z);
+ node_code += " vec3 " + inputs[i] + " = " + vformat("vec3(%.5f, %.5f, %.5f);\n", val.x, val.y, val.z);
} else if (defval.get_type() == Variant::TRANSFORM3D) {
Transform3D val = defval;
val.basis.transpose();
@@ -1459,7 +1459,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
values.push_back(val.origin.y);
values.push_back(val.origin.z);
bool err = false;
- node_code += "\tmat4 " + inputs[i] + " = " + String("mat4(vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 1.0));\n").sprintf(values, &err);
+ node_code += " mat4 " + inputs[i] + " = " + String("mat4(vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 1.0));\n").sprintf(values, &err);
} else {
//will go empty, node is expected to know what it is doing at this point and handle it
}
@@ -1522,19 +1522,19 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
outputs[i] = "n_out" + itos(node) + "p" + itos(j);
switch (vsnode->get_output_port_type(i)) {
case VisualShaderNode::PORT_TYPE_SCALAR:
- code += "\tfloat " + outputs[i] + ";\n";
+ code += " float " + outputs[i] + ";\n";
break;
case VisualShaderNode::PORT_TYPE_SCALAR_INT:
- code += "\tint " + outputs[i] + ";\n";
+ code += " int " + outputs[i] + ";\n";
break;
case VisualShaderNode::PORT_TYPE_VECTOR:
- code += "\tvec3 " + outputs[i] + ";\n";
+ code += " vec3 " + outputs[i] + ";\n";
break;
case VisualShaderNode::PORT_TYPE_BOOLEAN:
- code += "\tbool " + outputs[i] + ";\n";
+ code += " bool " + outputs[i] + ";\n";
break;
case VisualShaderNode::PORT_TYPE_TRANSFORM:
- code += "\tmat4 " + outputs[i] + ";\n";
+ code += " mat4 " + outputs[i] + ";\n";
break;
default: {
}
@@ -1564,7 +1564,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
new_line_inserted = true;
}
String r = "n_out" + itos(node) + "p" + itos(i + 1);
- code += "\tfloat " + r + " = n_out" + itos(node) + "p" + itos(i) + ".r;\n";
+ code += " float " + r + " = n_out" + itos(node) + "p" + itos(i) + ".r;\n";
outputs[i + 1] = r;
}
@@ -1574,7 +1574,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
new_line_inserted = true;
}
String g = "n_out" + itos(node) + "p" + itos(i + 2);
- code += "\tfloat " + g + " = n_out" + itos(node) + "p" + itos(i) + ".g;\n";
+ code += " float " + g + " = n_out" + itos(node) + "p" + itos(i) + ".g;\n";
outputs[i + 2] = g;
}
@@ -1584,7 +1584,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
new_line_inserted = true;
}
String b = "n_out" + itos(node) + "p" + itos(i + 3);
- code += "\tfloat " + b + " = n_out" + itos(node) + "p" + itos(i) + ".b;\n";
+ code += " float " + b + " = n_out" + itos(node) + "p" + itos(i) + ".b;\n";
outputs[i + 3] = b;
}
@@ -1701,7 +1701,7 @@ void VisualShader::_update_shader() const {
String expr = "";
expr += "// " + global_expression->get_caption() + ":" + itos(index++) + "\n";
expr += global_expression->generate_global(get_mode(), Type(i), -1);
- expr = expr.replace("\n", "\n\t");
+ expr = expr.replace("\n", "\n ");
expr += "\n";
global_expressions += expr;
}
@@ -1740,6 +1740,7 @@ void VisualShader::_update_shader() const {
}
Map<int, String> code_map;
+ Set<int> empty_funcs;
for (int i = 0; i < TYPE_MAX; i++) {
if (!has_func_name(RenderingServer::ShaderMode(shader_mode), func_name[i])) {
@@ -1752,6 +1753,11 @@ void VisualShader::_update_shader() const {
StringBuilder func_code;
+ bool is_empty_func = false;
+ if (shader_mode != Shader::MODE_PARTICLES && shader_mode != Shader::MODE_SKY) {
+ is_empty_func = true;
+ }
+
for (const List<Connection>::Element *E = graph[i].connections.front(); E; E = E->next()) {
ConnectionKey from_key;
from_key.node = E->get().from_node;
@@ -1764,7 +1770,17 @@ void VisualShader::_update_shader() const {
to_key.port = E->get().to_port;
input_connections.insert(to_key, E);
+
+ if (is_empty_func && to_key.node == NODE_ID_OUTPUT) {
+ is_empty_func = false;
+ }
+ }
+
+ if (is_empty_func) {
+ empty_funcs.insert(i);
+ continue;
}
+
if (shader_mode != Shader::MODE_PARTICLES) {
func_code += "\nvoid " + String(func_name[i]) + "() {\n";
}
@@ -1775,8 +1791,8 @@ void VisualShader::_update_shader() const {
ERR_FAIL_COND(err != OK);
if (emitters.has(i)) {
- for (List<int>::Element *E = emitters[i].front(); E; E = E->next()) {
- err = _write_node(Type(i), global_code, global_code_per_node, global_code_per_func, func_code, default_tex_params, input_connections, output_connections, E->get(), processed, false, classes);
+ for (int &E : emitters[i]) {
+ err = _write_node(Type(i), global_code, global_code_per_node, global_code_per_func, func_code, default_tex_params, input_connections, output_connections, E, processed, false, classes);
ERR_FAIL_COND(err != OK);
}
}
@@ -1800,112 +1816,112 @@ void VisualShader::_update_shader() const {
code += "void start() {\n";
if (has_start || has_start_custom) {
- code += "\tuint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n";
- code += "\tvec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n";
- code += "\tfloat __radians;\n";
- code += "\tvec3 __vec3_buff1;\n";
- code += "\tvec3 __vec3_buff2;\n";
- code += "\tfloat __scalar_buff1;\n";
- code += "\tfloat __scalar_buff2;\n";
- code += "\tvec3 __ndiff = normalize(__diff);\n\n";
+ code += " uint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n";
+ code += " vec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n";
+ code += " float __radians;\n";
+ code += " vec3 __vec3_buff1;\n";
+ code += " vec3 __vec3_buff2;\n";
+ code += " float __scalar_buff1;\n";
+ code += " float __scalar_buff2;\n";
+ code += " vec3 __ndiff = normalize(__diff);\n\n";
}
if (has_start) {
- code += "\t{\n";
- code += code_map[TYPE_START].replace("\n\t", "\n\t\t");
- code += "\t}\n";
+ code += " {\n";
+ code += code_map[TYPE_START].replace("\n ", "\n ");
+ code += " }\n";
if (has_start_custom) {
- code += "\t\n";
+ code += " \n";
}
}
if (has_start_custom) {
- code += "\t{\n";
- code += code_map[TYPE_START_CUSTOM].replace("\n\t", "\n\t\t");
- code += "\t}\n";
+ code += " {\n";
+ code += code_map[TYPE_START_CUSTOM].replace("\n ", "\n ");
+ code += " }\n";
}
code += "}\n\n";
code += "void process() {\n";
if (has_process || has_process_custom || has_collide) {
- code += "\tuint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n";
- code += "\tvec3 __vec3_buff1;\n";
- code += "\tvec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n";
- code += "\tvec3 __ndiff = normalize(__diff);\n\n";
+ code += " uint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n";
+ code += " vec3 __vec3_buff1;\n";
+ code += " vec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n";
+ code += " vec3 __ndiff = normalize(__diff);\n\n";
}
- code += "\t{\n";
- String tab = "\t";
+ code += " {\n";
+ String tab = " ";
if (has_collide) {
- code += "\t\tif (COLLIDED) {\n\n";
- code += code_map[TYPE_COLLIDE].replace("\n\t", "\n\t\t\t");
+ code += " if (COLLIDED) {\n\n";
+ code += code_map[TYPE_COLLIDE].replace("\n ", "\n ");
if (has_process) {
- code += "\t\t} else {\n\n";
- tab += "\t";
+ code += " } else {\n\n";
+ tab += " ";
}
}
if (has_process) {
- code += code_map[TYPE_PROCESS].replace("\n\t", "\n\t" + tab);
+ code += code_map[TYPE_PROCESS].replace("\n ", "\n " + tab);
}
if (has_collide) {
- code += "\t\t}\n";
+ code += " }\n";
}
- code += "\t}\n";
+ code += " }\n";
if (has_process_custom) {
- code += "\t{\n\n";
- code += code_map[TYPE_PROCESS_CUSTOM].replace("\n\t", "\n\t\t");
- code += "\t}\n";
+ code += " {\n\n";
+ code += code_map[TYPE_PROCESS_CUSTOM].replace("\n ", "\n ");
+ code += " }\n";
}
code += "}\n\n";
global_compute_code += "float __rand_from_seed(inout uint seed) {\n";
- global_compute_code += "\tint k;\n";
- global_compute_code += "\tint s = int(seed);\n";
- global_compute_code += "\tif (s == 0)\n";
- global_compute_code += "\ts = 305420679;\n";
- global_compute_code += "\tk = s / 127773;\n";
- global_compute_code += "\ts = 16807 * (s - k * 127773) - 2836 * k;\n";
- global_compute_code += "\tif (s < 0)\n";
- global_compute_code += "\t\ts += 2147483647;\n";
- global_compute_code += "\tseed = uint(s);\n";
- global_compute_code += "\treturn float(seed % uint(65536)) / 65535.0;\n";
+ global_compute_code += " int k;\n";
+ global_compute_code += " int s = int(seed);\n";
+ global_compute_code += " if (s == 0)\n";
+ global_compute_code += " s = 305420679;\n";
+ global_compute_code += " k = s / 127773;\n";
+ global_compute_code += " s = 16807 * (s - k * 127773) - 2836 * k;\n";
+ global_compute_code += " if (s < 0)\n";
+ global_compute_code += " s += 2147483647;\n";
+ global_compute_code += " seed = uint(s);\n";
+ global_compute_code += " return float(seed % uint(65536)) / 65535.0;\n";
global_compute_code += "}\n\n";
global_compute_code += "float __rand_from_seed_m1_p1(inout uint seed) {\n";
- global_compute_code += "\treturn __rand_from_seed(seed) * 2.0 - 1.0;\n";
+ global_compute_code += " return __rand_from_seed(seed) * 2.0 - 1.0;\n";
global_compute_code += "}\n\n";
global_compute_code += "float __randf_range(inout uint seed, float from, float to) {\n";
- global_compute_code += "\treturn __rand_from_seed(seed) * (to - from) + from;\n";
+ global_compute_code += " return __rand_from_seed(seed) * (to - from) + from;\n";
global_compute_code += "}\n\n";
global_compute_code += "vec3 __randv_range(inout uint seed, vec3 from, vec3 to) {\n";
- global_compute_code += "\treturn vec3(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z));\n";
+ global_compute_code += " return vec3(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z));\n";
global_compute_code += "}\n\n";
global_compute_code += "uint __hash(uint x) {\n";
- global_compute_code += "\tx = ((x >> uint(16)) ^ x) * uint(73244475);\n";
- global_compute_code += "\tx = ((x >> uint(16)) ^ x) * uint(73244475);\n";
- global_compute_code += "\tx = (x >> uint(16)) ^ x;\n";
- global_compute_code += "\treturn x;\n";
+ global_compute_code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n";
+ global_compute_code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n";
+ global_compute_code += " x = (x >> uint(16)) ^ x;\n";
+ global_compute_code += " return x;\n";
global_compute_code += "}\n\n";
global_compute_code += "mat3 __build_rotation_mat3(vec3 axis, float angle) {\n";
- global_compute_code += "\taxis = normalize(axis);\n";
- global_compute_code += "\tfloat s = sin(angle);\n";
- global_compute_code += "\tfloat c = cos(angle);\n";
- global_compute_code += "\tfloat oc = 1.0 - c;\n";
- global_compute_code += "\treturn mat3(vec3(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s), vec3(oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s), vec3(oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c));\n";
+ global_compute_code += " axis = normalize(axis);\n";
+ global_compute_code += " float s = sin(angle);\n";
+ global_compute_code += " float c = cos(angle);\n";
+ global_compute_code += " float oc = 1.0 - c;\n";
+ global_compute_code += " return mat3(vec3(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s), vec3(oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s), vec3(oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c));\n";
global_compute_code += "}\n\n";
global_compute_code += "mat4 __build_rotation_mat4(vec3 axis, float angle) {\n";
- global_compute_code += "\taxis = normalize(axis);\n";
- global_compute_code += "\tfloat s = sin(angle);\n";
- global_compute_code += "\tfloat c = cos(angle);\n";
- global_compute_code += "\tfloat oc = 1.0 - c;\n";
- global_compute_code += "\treturn mat4(vec4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0), vec4(oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0), vec4(oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0), vec4(0, 0, 0, 1));\n";
+ global_compute_code += " axis = normalize(axis);\n";
+ global_compute_code += " float s = sin(angle);\n";
+ global_compute_code += " float c = cos(angle);\n";
+ global_compute_code += " float oc = 1.0 - c;\n";
+ global_compute_code += " return mat4(vec4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0), vec4(oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0), vec4(oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0), vec4(0, 0, 0, 1));\n";
global_compute_code += "}\n\n";
global_compute_code += "vec3 __get_random_unit_vec3(inout uint seed) {\n";
- global_compute_code += "\treturn normalize(vec3(__rand_from_seed_m1_p1(seed), __rand_from_seed_m1_p1(seed), __rand_from_seed_m1_p1(seed)));\n";
+ global_compute_code += " return normalize(vec3(__rand_from_seed_m1_p1(seed), __rand_from_seed_m1_p1(seed), __rand_from_seed_m1_p1(seed)));\n";
global_compute_code += "}\n\n";
}
@@ -1920,7 +1936,11 @@ void VisualShader::_update_shader() const {
if (!has_func_name(RenderingServer::ShaderMode(shader_mode), func_name[i])) {
continue;
}
- tcode = tcode.insert(insertion_pos[i], global_code_per_func[Type(i)]);
+ String func_code = global_code_per_func[Type(i)].as_string();
+ if (empty_funcs.has(Type(i)) && !func_code.is_empty()) {
+ func_code = vformat("%s%s%s", String("\nvoid " + String(func_name[i]) + "() {\n"), func_code, "}\n");
+ }
+ tcode = tcode.insert(insertion_pos[i], func_code);
}
final_code += tcode;
@@ -1929,7 +1949,7 @@ void VisualShader::_update_shader() const {
const_cast<VisualShader *>(this)->set_default_texture_param(default_tex_params[i].name, default_tex_params[i].param);
}
if (previous_code != final_code) {
- const_cast<VisualShader *>(this)->emit_signal("changed");
+ const_cast<VisualShader *>(this)->emit_signal(SNAME("changed"));
}
previous_code = final_code;
}
@@ -1940,7 +1960,7 @@ void VisualShader::_queue_update() {
}
dirty.set();
- call_deferred("_update_shader");
+ call_deferred(SNAME("_update_shader"));
}
void VisualShader::_input_type_changed(Type p_type, int p_id) {
@@ -2366,7 +2386,7 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T
while (preview_ports[idx].mode != Shader::MODE_MAX) {
if (preview_ports[idx].mode == shader_mode && preview_ports[idx].shader_type == shader_type && preview_ports[idx].name == input_name) {
- code = "\t" + p_output_vars[0] + " = " + preview_ports[idx].string + ";\n";
+ code = " " + p_output_vars[0] + " = " + preview_ports[idx].string + ";\n";
break;
}
idx++;
@@ -2375,19 +2395,19 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T
if (code == String()) {
switch (get_output_port_type(0)) {
case PORT_TYPE_SCALAR: {
- code = "\t" + p_output_vars[0] + " = 0.0;\n";
+ code = " " + p_output_vars[0] + " = 0.0;\n";
} break;
case PORT_TYPE_SCALAR_INT: {
- code = "\t" + p_output_vars[0] + " = 0;\n";
+ code = " " + p_output_vars[0] + " = 0;\n";
} break;
case PORT_TYPE_VECTOR: {
- code = "\t" + p_output_vars[0] + " = vec3(0.0);\n";
+ code = " " + p_output_vars[0] + " = vec3(0.0);\n";
} break;
case PORT_TYPE_TRANSFORM: {
- code = "\t" + p_output_vars[0] + " = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code = " " + p_output_vars[0] + " = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
} break;
case PORT_TYPE_BOOLEAN: {
- code = "\t" + p_output_vars[0] + " = false;\n";
+ code = " " + p_output_vars[0] + " = false;\n";
} break;
default: //default (none found) is scalar
break;
@@ -2403,14 +2423,14 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T
while (ports[idx].mode != Shader::MODE_MAX) {
if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type && ports[idx].name == input_name) {
- code = "\t" + p_output_vars[0] + " = " + ports[idx].string + ";\n";
+ code = " " + p_output_vars[0] + " = " + ports[idx].string + ";\n";
break;
}
idx++;
}
if (code == String()) {
- code = "\t" + p_output_vars[0] + " = 0.0;\n"; //default (none found) is scalar
+ code = " " + p_output_vars[0] + " = 0.0;\n"; //default (none found) is scalar
}
return code;
@@ -2422,7 +2442,7 @@ void VisualShaderNodeInput::set_input_name(String p_name) {
input_name = p_name;
emit_changed();
if (get_input_type_by_name(input_name) != prev_type) {
- emit_signal("input_type_changed");
+ emit_signal(SNAME("input_type_changed"));
}
}
@@ -2566,8 +2586,8 @@ void VisualShaderNodeUniformRef::clear_uniforms() {
}
bool VisualShaderNodeUniformRef::has_uniform(const String &p_name) {
- for (List<VisualShaderNodeUniformRef::Uniform>::Element *E = uniforms.front(); E; E = E->next()) {
- if (E->get().name == p_name) {
+ for (const VisualShaderNodeUniformRef::Uniform &E : uniforms) {
+ if (E.name == p_name) {
return true;
}
}
@@ -2708,24 +2728,46 @@ VisualShaderNodeUniformRef::UniformType VisualShaderNodeUniformRef::get_uniform_
return UniformType::UNIFORM_TYPE_FLOAT;
}
+VisualShaderNodeUniformRef::PortType VisualShaderNodeUniformRef::get_port_type_by_index(int p_idx) const {
+ if (p_idx >= 0 && p_idx < uniforms.size()) {
+ switch (uniforms[p_idx].type) {
+ case UniformType::UNIFORM_TYPE_FLOAT:
+ return PORT_TYPE_SCALAR;
+ case UniformType::UNIFORM_TYPE_INT:
+ return PORT_TYPE_SCALAR_INT;
+ case UniformType::UNIFORM_TYPE_SAMPLER:
+ return PORT_TYPE_SAMPLER;
+ case UniformType::UNIFORM_TYPE_VECTOR:
+ return PORT_TYPE_VECTOR;
+ case UniformType::UNIFORM_TYPE_TRANSFORM:
+ return PORT_TYPE_TRANSFORM;
+ case UniformType::UNIFORM_TYPE_COLOR:
+ return PORT_TYPE_VECTOR;
+ default:
+ break;
+ }
+ }
+ return PORT_TYPE_SCALAR;
+}
+
String VisualShaderNodeUniformRef::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 {
switch (uniform_type) {
case UniformType::UNIFORM_TYPE_FLOAT:
if (uniform_name == "[None]") {
- return "\t" + p_output_vars[0] + " = 0.0;\n";
+ return " " + p_output_vars[0] + " = 0.0;\n";
}
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
case UniformType::UNIFORM_TYPE_INT:
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
case UniformType::UNIFORM_TYPE_BOOLEAN:
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
case UniformType::UNIFORM_TYPE_VECTOR:
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
case UniformType::UNIFORM_TYPE_TRANSFORM:
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
case UniformType::UNIFORM_TYPE_COLOR: {
- String code = "\t" + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n";
- code += "\t" + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n";
+ String code = " " + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n";
+ code += " " + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n";
return code;
} break;
case UniformType::UNIFORM_TYPE_SAMPLER:
@@ -2921,9 +2963,9 @@ String VisualShaderNodeOutput::generate_code(Shader::Mode p_mode, VisualShader::
if (p_input_vars[count] != String()) {
String s = ports[idx].string;
if (s.find(":") != -1) {
- code += "\t" + s.get_slicec(':', 0) + " = " + p_input_vars[count] + "." + s.get_slicec(':', 1) + ";\n";
+ code += " " + s.get_slicec(':', 0) + " = " + p_input_vars[count] + "." + s.get_slicec(':', 1) + ";\n";
} else {
- code += "\t" + s + " = " + p_input_vars[count] + ";\n";
+ code += " " + s + " = " + p_input_vars[count] + ";\n";
}
}
count++;
@@ -2941,7 +2983,7 @@ VisualShaderNodeOutput::VisualShaderNodeOutput() {
void VisualShaderNodeUniform::set_uniform_name(const String &p_name) {
uniform_name = p_name;
- emit_signal("name_changed");
+ emit_signal(SNAME("name_changed"));
emit_changed();
}
@@ -3598,11 +3640,11 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad
String _expression = expression;
_expression = _expression.insert(0, "\n");
- _expression = _expression.replace("\n", "\n\t\t");
+ _expression = _expression.replace("\n", "\n ");
static Vector<String> pre_symbols;
if (pre_symbols.is_empty()) {
- pre_symbols.push_back("\t");
+ pre_symbols.push_back(" ");
pre_symbols.push_back(",");
pre_symbols.push_back(";");
pre_symbols.push_back("{");
@@ -3622,7 +3664,7 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad
static Vector<String> post_symbols;
if (post_symbols.is_empty()) {
- post_symbols.push_back("\t");
+ post_symbols.push_back(" ");
post_symbols.push_back("\n");
post_symbols.push_back(",");
post_symbols.push_back(";");
@@ -3681,14 +3723,14 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad
default:
continue;
}
- output_initializer += "\t" + p_output_vars[i] + " = " + tk + ";\n";
+ output_initializer += " " + p_output_vars[i] + " = " + tk + ";\n";
}
String code;
code += output_initializer;
- code += "\t{";
+ code += " {";
code += _expression;
- code += "\n\t}\n";
+ code += "\n }\n";
return code;
}
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index 454012b7ed..880c401b29 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -517,6 +517,7 @@ public:
String get_uniform_name_by_index(int p_idx) const;
UniformType get_uniform_type_by_name(const String &p_name) const;
UniformType get_uniform_type_by_index(int p_idx) const;
+ PortType get_port_type_by_index(int p_idx) const;
virtual Vector<StringName> get_editable_properties() const override;
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index d3b094de31..6fd6fd8f3b 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -66,7 +66,7 @@ String VisualShaderNodeFloatConstant::get_output_port_name(int p_port) const {
}
String VisualShaderNodeFloatConstant::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 {
- return "\t" + p_output_vars[0] + " = " + vformat("%.6f", constant) + ";\n";
+ return " " + p_output_vars[0] + " = " + vformat("%.6f", constant) + ";\n";
}
void VisualShaderNodeFloatConstant::set_constant(float p_value) {
@@ -125,7 +125,7 @@ String VisualShaderNodeIntConstant::get_output_port_name(int p_port) const {
}
String VisualShaderNodeIntConstant::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 {
- return "\t" + p_output_vars[0] + " = " + itos(constant) + ";\n";
+ return " " + p_output_vars[0] + " = " + itos(constant) + ";\n";
}
void VisualShaderNodeIntConstant::set_constant(int p_value) {
@@ -184,7 +184,7 @@ String VisualShaderNodeBooleanConstant::get_output_port_name(int p_port) const {
}
String VisualShaderNodeBooleanConstant::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 {
- return "\t" + p_output_vars[0] + " = " + (constant ? "true" : "false") + ";\n";
+ return " " + p_output_vars[0] + " = " + (constant ? "true" : "false") + ";\n";
}
void VisualShaderNodeBooleanConstant::set_constant(bool p_value) {
@@ -251,8 +251,8 @@ bool VisualShaderNodeColorConstant::is_output_port_expandable(int p_port) const
String VisualShaderNodeColorConstant::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 {
String code;
- code += "\t" + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.r, constant.g, constant.b) + ";\n";
- code += "\t" + p_output_vars[1] + " = " + vformat("%.6f", constant.a) + ";\n";
+ code += " " + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.r, constant.g, constant.b) + ";\n";
+ code += " " + p_output_vars[1] + " = " + vformat("%.6f", constant.a) + ";\n";
return code;
}
@@ -313,7 +313,7 @@ String VisualShaderNodeVec3Constant::get_output_port_name(int p_port) const {
}
String VisualShaderNodeVec3Constant::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 {
- return "\t" + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.x, constant.y, constant.z) + ";\n";
+ return " " + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.x, constant.y, constant.z) + ";\n";
}
void VisualShaderNodeVec3Constant::set_constant(Vector3 p_value) {
@@ -375,7 +375,7 @@ String VisualShaderNodeTransformConstant::generate_code(Shader::Mode p_mode, Vis
Transform3D t = constant;
t.basis.transpose();
- String code = "\t" + p_output_vars[0] + " = mat4(";
+ String code = " " + p_output_vars[0] + " = mat4(";
code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[0].x, t.basis[0].y, t.basis[0].z);
code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[1].x, t.basis[1].y, t.basis[1].z);
code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[2].x, t.basis[2].y, t.basis[2].z);
@@ -523,20 +523,20 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\tvec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n";
+ code += " vec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n";
} else {
- code += "\tvec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\tvec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
+ code += " vec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
} else {
- code += "\tvec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
+ code += " vec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
}
- code += "\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n";
- code += "\t" + p_output_vars[1] + " = " + id + "_read.a;\n";
+ code += " " + p_output_vars[0] + " = " + id + "_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = " + id + "_read.a;\n";
return code;
}
@@ -544,98 +544,98 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
String id = p_input_vars[2];
String code;
- code += "\t{\n";
+ code += " {\n";
if (id == String()) {
- code += "\t\tvec4 " + id + "_tex_read = vec4(0.0);\n";
+ code += " vec4 " + id + "_tex_read = vec4(0.0);\n";
} else {
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n";
+ code += " vec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n";
} else {
- code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
+ code += " vec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
} else {
- code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
+ code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
}
- code += "\t\t" + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = " + id + "_tex_read.a;\n";
+ code += " " + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = " + id + "_tex_read.a;\n";
}
- code += "\t}\n";
+ code += " }\n";
return code;
}
if (source == SOURCE_SCREEN && (p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) {
- String code = "\t{\n";
+ String code = " {\n";
if (p_input_vars[0] == String() || p_for_preview) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", 0.0 );\n";
+ code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", 0.0 );\n";
} else {
- code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, 0.0);\n";
+ code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, 0.0);\n";
} else {
- code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
+ code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
}
- code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = _tex_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = _tex_read.a;\n";
+ code += " }\n";
return code;
}
if (source == SOURCE_2D_TEXTURE && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) {
- String code = "\t{\n";
+ String code = " {\n";
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\t\tvec4 _tex_read = texture(TEXTURE, " + default_uv + ");\n";
+ code += " vec4 _tex_read = texture(TEXTURE, " + default_uv + ");\n";
} else {
- code += "\t\tvec4 _tex_read = textureLod(TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 _tex_read = textureLod(TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tvec4 _tex_read = texture(TEXTURE, " + p_input_vars[0] + ".xy);\n";
+ code += " vec4 _tex_read = texture(TEXTURE, " + p_input_vars[0] + ".xy);\n";
} else {
- code += "\t\tvec4 _tex_read = textureLod(TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
+ code += " vec4 _tex_read = textureLod(TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
}
- code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = _tex_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = _tex_read.a;\n";
+ code += " }\n";
return code;
}
if (source == SOURCE_2D_NORMAL && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) {
- String code = "\t{\n";
+ String code = " {\n";
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\t\tvec4 _tex_read = texture(NORMAL_TEXTURE, " + default_uv + ");\n";
+ code += " vec4 _tex_read = texture(NORMAL_TEXTURE, " + default_uv + ");\n";
} else {
- code += "\t\tvec4 _tex_read = textureLod(NORMAL_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 _tex_read = textureLod(NORMAL_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tvec4 _tex_read = texture(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy);\n";
+ code += " vec4 _tex_read = texture(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy);\n";
} else {
- code += "\t\tvec4 _tex_read = textureLod(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
+ code += " vec4 _tex_read = textureLod(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
}
- code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = _tex_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = _tex_read.a;\n";
+ code += " }\n";
return code;
}
@@ -643,44 +643,44 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
{
if (source == SOURCE_DEPTH) {
String code;
- code += "\t" + p_output_vars[0] + " = 0.0;\n";
- code += "\t" + p_output_vars[1] + " = 1.0;\n";
+ code += " " + p_output_vars[0] + " = 0.0;\n";
+ code += " " + p_output_vars[1] + " = 1.0;\n";
return code;
}
}
if (source == SOURCE_DEPTH && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) {
- String code = "\t{\n";
+ String code = " {\n";
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\t\tfloat _depth = texture(DEPTH_TEXTURE, " + default_uv + ").r;\n";
+ code += " float _depth = texture(DEPTH_TEXTURE, " + default_uv + ").r;\n";
} else {
- code += "\t\tfloat _depth = textureLod(DEPTH_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ").r;\n";
+ code += " float _depth = textureLod(DEPTH_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ").r;\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tfloat _depth = texture(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy).r;\n";
+ code += " float _depth = texture(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy).r;\n";
} else {
- code += "\t\tfloat _depth = textureLod(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ").r;\n";
+ code += " float _depth = textureLod(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ").r;\n";
}
- code += "\t\t" + p_output_vars[0] + " = _depth;\n";
- code += "\t\t" + p_output_vars[1] + " = 1.0;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = _depth;\n";
+ code += " " + p_output_vars[1] + " = 1.0;\n";
+ code += " }\n";
return code;
} else if (source == SOURCE_DEPTH) {
String code;
- code += "\t" + p_output_vars[0] + " = 0.0;\n";
- code += "\t" + p_output_vars[1] + " = 1.0;\n";
+ code += " " + p_output_vars[0] + " = 0.0;\n";
+ code += " " + p_output_vars[1] + " = 1.0;\n";
return code;
}
//none
String code;
- code += "\t" + p_output_vars[0] + " = vec3(0.0);\n";
- code += "\t" + p_output_vars[1] + " = 1.0;\n";
+ code += " " + p_output_vars[0] + " = vec3(0.0);\n";
+ code += " " + p_output_vars[1] + " = 1.0;\n";
return code;
}
@@ -707,7 +707,7 @@ void VisualShaderNodeTexture::set_source(Source p_source) {
break;
}
emit_changed();
- emit_signal("editor_refresh_request");
+ emit_signal(SNAME("editor_refresh_request"));
}
VisualShaderNodeTexture::Source VisualShaderNodeTexture::get_source() const {
@@ -805,7 +805,7 @@ void VisualShaderNodeTexture::_bind_methods() {
VisualShaderNodeTexture::VisualShaderNodeTexture() {
}
-////////////// Curve
+////////////// CurveTexture
String VisualShaderNodeCurveTexture::get_caption() const {
return "CurveTexture";
@@ -856,11 +856,11 @@ String VisualShaderNodeCurveTexture::generate_global(Shader::Mode p_mode, Visual
String VisualShaderNodeCurveTexture::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 {
if (p_input_vars[0] == String()) {
- return "\t" + p_output_vars[0] + " = 0.0;\n";
+ return " " + p_output_vars[0] + " = 0.0;\n";
}
String id = make_unique_id(p_type, p_id, "curve");
String code;
- code += "\t" + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).r;\n";
+ code += " " + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).r;\n";
return code;
}
@@ -889,6 +889,90 @@ VisualShaderNodeCurveTexture::VisualShaderNodeCurveTexture() {
allow_v_resize = false;
}
+////////////// CurveXYZTexture
+
+String VisualShaderNodeCurveXYZTexture::get_caption() const {
+ return "CurveXYZTexture";
+}
+
+int VisualShaderNodeCurveXYZTexture::get_input_port_count() const {
+ return 1;
+}
+
+VisualShaderNodeCurveXYZTexture::PortType VisualShaderNodeCurveXYZTexture::get_input_port_type(int p_port) const {
+ return PORT_TYPE_SCALAR;
+}
+
+String VisualShaderNodeCurveXYZTexture::get_input_port_name(int p_port) const {
+ return String();
+}
+
+int VisualShaderNodeCurveXYZTexture::get_output_port_count() const {
+ return 1;
+}
+
+VisualShaderNodeCurveXYZTexture::PortType VisualShaderNodeCurveXYZTexture::get_output_port_type(int p_port) const {
+ return PORT_TYPE_VECTOR;
+}
+
+String VisualShaderNodeCurveXYZTexture::get_output_port_name(int p_port) const {
+ return String();
+}
+
+void VisualShaderNodeCurveXYZTexture::set_texture(Ref<CurveXYZTexture> p_texture) {
+ texture = p_texture;
+ emit_changed();
+}
+
+Ref<CurveXYZTexture> VisualShaderNodeCurveXYZTexture::get_texture() const {
+ return texture;
+}
+
+Vector<StringName> VisualShaderNodeCurveXYZTexture::get_editable_properties() const {
+ Vector<StringName> props;
+ props.push_back("texture");
+ return props;
+}
+
+String VisualShaderNodeCurveXYZTexture::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+ return "uniform sampler2D " + make_unique_id(p_type, p_id, "curve3d") + ";\n";
+}
+
+String VisualShaderNodeCurveXYZTexture::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 {
+ if (p_input_vars[0] == String()) {
+ return " " + p_output_vars[0] + " = vec3(0.0);\n";
+ }
+ String id = make_unique_id(p_type, p_id, "curve3d");
+ String code;
+ code += " " + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).rgb;\n";
+ return code;
+}
+
+Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCurveXYZTexture::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
+ VisualShader::DefaultTextureParam dtp;
+ dtp.name = make_unique_id(p_type, p_id, "curve3d");
+ dtp.param = texture;
+ Vector<VisualShader::DefaultTextureParam> ret;
+ ret.push_back(dtp);
+ return ret;
+}
+
+void VisualShaderNodeCurveXYZTexture::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_texture", "texture"), &VisualShaderNodeCurveXYZTexture::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture"), &VisualShaderNodeCurveXYZTexture::get_texture);
+
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "CurveXYZTexture"), "set_texture", "get_texture");
+}
+
+bool VisualShaderNodeCurveXYZTexture::is_use_prop_slots() const {
+ return true;
+}
+
+VisualShaderNodeCurveXYZTexture::VisualShaderNodeCurveXYZTexture() {
+ simple_decl = true;
+ allow_v_resize = false;
+}
+
////////////// Sample3D
int VisualShaderNodeSample3D::get_input_port_count() const {
@@ -956,7 +1040,7 @@ String VisualShaderNodeSample3D::generate_code(Shader::Mode p_mode, VisualShader
String code;
if (source == SOURCE_TEXTURE || source == SOURCE_PORT) {
String id;
- code += "\t{\n";
+ code += " {\n";
if (source == SOURCE_TEXTURE) {
id = make_unique_id(p_type, p_id, "tex3d");
} else {
@@ -965,34 +1049,34 @@ String VisualShaderNodeSample3D::generate_code(Shader::Mode p_mode, VisualShader
if (id != String()) {
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n";
+ code += " vec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n";
} else {
- code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ");\n";
+ code += " vec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ");\n";
} else {
- code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
}
} else {
- code += "\t\tvec4 " + id + "_tex_read = vec4(0.0);\n";
+ code += " vec4 " + id + "_tex_read = vec4(0.0);\n";
}
- code += "\t\t" + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = " + id + "_tex_read.a;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = " + id + "_tex_read.a;\n";
+ code += " }\n";
return code;
}
- code += "\t" + p_output_vars[0] + " = vec3(0.0);\n";
- code += "\t" + p_output_vars[1] + " = 1.0;\n";
+ code += " " + p_output_vars[0] + " = vec3(0.0);\n";
+ code += " " + p_output_vars[1] + " = 1.0;\n";
return code;
}
void VisualShaderNodeSample3D::set_source(Source p_source) {
source = p_source;
emit_changed();
- emit_signal("editor_refresh_request");
+ emit_signal(SNAME("editor_refresh_request"));
}
VisualShaderNodeSample3D::Source VisualShaderNodeSample3D::get_source() const {
@@ -1241,33 +1325,33 @@ String VisualShaderNodeCubemap::generate_code(Shader::Mode p_mode, VisualShader:
return String();
}
- code += "\t{\n";
+ code += " {\n";
if (id == String()) {
- code += "\t\tvec4 " + id + "_read = vec4(0.0);\n";
- code += "\t\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = " + id + "_read.a;\n";
- code += "\t}\n";
+ code += " vec4 " + id + "_read = vec4(0.0);\n";
+ code += " " + p_output_vars[0] + " = " + id + "_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = " + id + "_read.a;\n";
+ code += " }\n";
return code;
}
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\t\tvec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n";
+ code += " vec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n";
} else {
- code += "\t\tvec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + " );\n";
+ code += " vec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + " );\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tvec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ");\n";
+ code += " vec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ");\n";
} else {
- code += "\t\tvec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
}
- code += "\t\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = " + id + "_read.a;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = " + id + "_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = " + id + "_read.a;\n";
+ code += " }\n";
return code;
}
@@ -1282,7 +1366,7 @@ String VisualShaderNodeCubemap::get_input_port_default_hint(int p_port) const {
void VisualShaderNodeCubemap::set_source(Source p_source) {
source = p_source;
emit_changed();
- emit_signal("editor_refresh_request");
+ emit_signal(SNAME("editor_refresh_request"));
}
VisualShaderNodeCubemap::Source VisualShaderNodeCubemap::get_source() const {
@@ -1381,7 +1465,7 @@ String VisualShaderNodeFloatOp::get_output_port_name(int p_port) const {
}
String VisualShaderNodeFloatOp::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 {
- String code = "\t" + p_output_vars[0] + " = ";
+ String code = " " + p_output_vars[0] + " = ";
switch (op) {
case OP_ADD:
code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
@@ -1487,7 +1571,7 @@ String VisualShaderNodeIntOp::get_output_port_name(int p_port) const {
}
String VisualShaderNodeIntOp::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 {
- String code = "\t" + p_output_vars[0] + " = ";
+ String code = " " + p_output_vars[0] + " = ";
switch (op) {
case OP_ADD:
code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
@@ -1581,7 +1665,7 @@ String VisualShaderNodeVectorOp::get_output_port_name(int p_port) const {
}
String VisualShaderNodeVectorOp::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 {
- String code = "\t" + p_output_vars[0] + " = ";
+ String code = " " + p_output_vars[0] + " = ";
switch (op) {
case OP_ADD:
code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
@@ -1699,64 +1783,64 @@ String VisualShaderNodeColorOp::generate_code(Shader::Mode p_mode, VisualShader:
static const char *axisn[3] = { "x", "y", "z" };
switch (op) {
case OP_SCREEN: {
- code += "\t" + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") * (vec3(1.0) - " + p_input_vars[1] + ");\n";
+ code += " " + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") * (vec3(1.0) - " + p_input_vars[1] + ");\n";
} break;
case OP_DIFFERENCE: {
- code += "\t" + p_output_vars[0] + " = abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ");\n";
+ code += " " + p_output_vars[0] + " = abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ");\n";
} break;
case OP_DARKEN: {
- code += "\t" + p_output_vars[0] + " = min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ code += " " + p_output_vars[0] + " = min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
} break;
case OP_LIGHTEN: {
- code += "\t" + p_output_vars[0] + " = max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ code += " " + p_output_vars[0] + " = max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
} break;
case OP_OVERLAY: {
for (int i = 0; i < 3; i++) {
- code += "\t{\n";
- code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += "\t\tif (base < 0.5) {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = 2.0 * base * blend;\n";
- code += "\t\t} else {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n";
- code += "\t\t}\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
+ code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
+ code += " if (base < 0.5) {\n";
+ code += " " + p_output_vars[0] + "." + axisn[i] + " = 2.0 * base * blend;\n";
+ code += " } else {\n";
+ code += " " + p_output_vars[0] + "." + axisn[i] + " = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n";
+ code += " }\n";
+ code += " }\n";
}
} break;
case OP_DODGE: {
- code += "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + ") / (vec3(1.0) - " + p_input_vars[1] + ");\n";
+ code += " " + p_output_vars[0] + " = (" + p_input_vars[0] + ") / (vec3(1.0) - " + p_input_vars[1] + ");\n";
} break;
case OP_BURN: {
- code += "\t" + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") / (" + p_input_vars[1] + ");\n";
+ code += " " + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") / (" + p_input_vars[1] + ");\n";
} break;
case OP_SOFT_LIGHT: {
for (int i = 0; i < 3; i++) {
- code += "\t{\n";
- code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += "\t\tif (base < 0.5) {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (base * (blend + 0.5));\n";
- code += "\t\t} else {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - (blend - 0.5)));\n";
- code += "\t\t}\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
+ code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
+ code += " if (base < 0.5) {\n";
+ code += " " + p_output_vars[0] + "." + axisn[i] + " = (base * (blend + 0.5));\n";
+ code += " } else {\n";
+ code += " " + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - (blend - 0.5)));\n";
+ code += " }\n";
+ code += " }\n";
}
} break;
case OP_HARD_LIGHT: {
for (int i = 0; i < 3; i++) {
- code += "\t{\n";
- code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += "\t\tif (base < 0.5) {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (base * (2.0 * blend));\n";
- code += "\t\t} else {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - 2.0 * (blend - 0.5)));\n";
- code += "\t\t}\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
+ code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
+ code += " if (base < 0.5) {\n";
+ code += " " + p_output_vars[0] + "." + axisn[i] + " = (base * (2.0 * blend));\n";
+ code += " } else {\n";
+ code += " " + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - 2.0 * (blend - 0.5)));\n";
+ code += " }\n";
+ code += " }\n";
}
} break;
@@ -1863,13 +1947,13 @@ String VisualShaderNodeTransformMult::get_output_port_name(int p_port) const {
String VisualShaderNodeTransformMult::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 {
if (op == OP_AxB) {
- return "\t" + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
+ return " " + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
} else if (op == OP_BxA) {
- return "\t" + p_output_vars[0] + " = " + p_input_vars[1] + " * " + p_input_vars[0] + ";\n";
+ return " " + p_output_vars[0] + " = " + p_input_vars[1] + " * " + p_input_vars[0] + ";\n";
} else if (op == OP_AxB_COMP) {
- return "\t" + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
} else {
- return "\t" + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[1] + ", " + p_input_vars[0] + ");\n";
+ return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[1] + ", " + p_input_vars[0] + ");\n";
}
}
@@ -1937,13 +2021,13 @@ String VisualShaderNodeTransformVecMult::get_output_port_name(int p_port) const
String VisualShaderNodeTransformVecMult::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 {
if (op == OP_AxB) {
- return "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 1.0)).xyz;\n";
+ return " " + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 1.0)).xyz;\n";
} else if (op == OP_BxA) {
- return "\t" + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 1.0) * " + p_input_vars[0] + ").xyz;\n";
+ return " " + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 1.0) * " + p_input_vars[0] + ").xyz;\n";
} else if (op == OP_3x3_AxB) {
- return "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 0.0)).xyz;\n";
+ return " " + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 0.0)).xyz;\n";
} else {
- return "\t" + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 0.0) * " + p_input_vars[0] + ").xyz;\n";
+ return " " + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 0.0) * " + p_input_vars[0] + ").xyz;\n";
}
}
@@ -2045,7 +2129,7 @@ String VisualShaderNodeFloatFunc::generate_code(Shader::Mode p_mode, VisualShade
"1.0 - $"
};
- return "\t" + p_output_vars[0] + " = " + String(scalar_func_id[func]).replace("$", p_input_vars[0]) + ";\n";
+ return " " + p_output_vars[0] + " = " + String(scalar_func_id[func]).replace("$", p_input_vars[0]) + ";\n";
}
void VisualShaderNodeFloatFunc::set_function(Function p_func) {
@@ -2144,7 +2228,7 @@ String VisualShaderNodeIntFunc::generate_code(Shader::Mode p_mode, VisualShader:
"sign($)"
};
- return "\t" + p_output_vars[0] + " = " + String(int_func_id[func]).replace("$", p_input_vars[0]) + ";\n";
+ return " " + p_output_vars[0] + " = " + String(int_func_id[func]).replace("$", p_input_vars[0]) + ";\n";
}
void VisualShaderNodeIntFunc::set_function(Function p_func) {
@@ -2249,25 +2333,25 @@ String VisualShaderNodeVectorFunc::generate_code(Shader::Mode p_mode, VisualShad
String code;
if (func == FUNC_RGB2HSV) {
- code += "\t{\n";
- code += "\t\tvec3 c = " + p_input_vars[0] + ";\n";
- code += "\t\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n";
- code += "\t\tvec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n";
- code += "\t\tvec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n";
- code += "\t\tfloat d = q.x - min(q.w, q.y);\n";
- code += "\t\tfloat e = 1.0e-10;\n";
- code += "\t\t" + p_output_vars[0] + " = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " vec3 c = " + p_input_vars[0] + ";\n";
+ code += " vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n";
+ code += " vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n";
+ code += " vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n";
+ code += " float d = q.x - min(q.w, q.y);\n";
+ code += " float e = 1.0e-10;\n";
+ code += " " + p_output_vars[0] + " = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n";
+ code += " }\n";
} else if (func == FUNC_HSV2RGB) {
- code += "\t{\n";
- code += "\t\tvec3 c = " + p_input_vars[0] + ";\n";
- code += "\t\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n";
- code += "\t\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n";
- code += "\t\t" + p_output_vars[0] + " = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " vec3 c = " + p_input_vars[0] + ";\n";
+ code += " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n";
+ code += " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n";
+ code += " " + p_output_vars[0] + " = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n";
+ code += " }\n";
} else {
- code += "\t" + p_output_vars[0] + " = " + String(vec_func_id[func]).replace("$", p_input_vars[0]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + String(vec_func_id[func]).replace("$", p_input_vars[0]) + ";\n";
}
return code;
@@ -2377,22 +2461,22 @@ String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShade
switch (func) {
case FUNC_GRAYSCALE:
- code += "\t{\n";
- code += "\t\tvec3 c = " + p_input_vars[0] + ";\n";
- code += "\t\tfloat max1 = max(c.r, c.g);\n";
- code += "\t\tfloat max2 = max(max1, c.b);\n";
- code += "\t\tfloat max3 = max(max1, max2);\n";
- code += "\t\t" + p_output_vars[0] + " = vec3(max3, max3, max3);\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " vec3 c = " + p_input_vars[0] + ";\n";
+ code += " float max1 = max(c.r, c.g);\n";
+ code += " float max2 = max(max1, c.b);\n";
+ code += " float max3 = max(max1, max2);\n";
+ code += " " + p_output_vars[0] + " = vec3(max3, max3, max3);\n";
+ code += " }\n";
break;
case FUNC_SEPIA:
- code += "\t{\n";
- code += "\t\tvec3 c = " + p_input_vars[0] + ";\n";
- code += "\t\tfloat r = (c.r * .393) + (c.g *.769) + (c.b * .189);\n";
- code += "\t\tfloat g = (c.r * .349) + (c.g *.686) + (c.b * .168);\n";
- code += "\t\tfloat b = (c.r * .272) + (c.g *.534) + (c.b * .131);\n";
- code += "\t\t" + p_output_vars[0] + " = vec3(r, g, b);\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " vec3 c = " + p_input_vars[0] + ";\n";
+ code += " float r = (c.r * .393) + (c.g *.769) + (c.b * .189);\n";
+ code += " float g = (c.r * .349) + (c.g *.686) + (c.b * .168);\n";
+ code += " float b = (c.r * .272) + (c.g *.534) + (c.b * .131);\n";
+ code += " " + p_output_vars[0] + " = vec3(r, g, b);\n";
+ code += " }\n";
break;
}
@@ -2466,7 +2550,7 @@ String VisualShaderNodeTransformFunc::generate_code(Shader::Mode p_mode, VisualS
};
String code;
- code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
return code;
}
@@ -2584,10 +2668,10 @@ String VisualShaderNodeUVFunc::generate_code(Shader::Mode p_mode, VisualShader::
switch (func) {
case FUNC_PANNING: {
- code += vformat("\t%s = fma(%s, %s, %s);\n", p_output_vars[0], offset_pivot, scale, uv);
+ code += vformat(" %s = fma(%s, %s, %s);\n", p_output_vars[0], offset_pivot, scale, uv);
} break;
case FUNC_SCALING: {
- code += vformat("\t%s = fma((%s - %s), %s, %s);\n", p_output_vars[0], uv, offset_pivot, scale, offset_pivot);
+ code += vformat(" %s = fma((%s - %s), %s, %s);\n", p_output_vars[0], uv, offset_pivot, scale, offset_pivot);
} break;
case FUNC_MAX:
break;
@@ -2667,7 +2751,7 @@ String VisualShaderNodeDotProduct::get_output_port_name(int p_port) const {
}
String VisualShaderNodeDotProduct::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 {
- return "\t" + p_output_vars[0] + " = dot(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ return " " + p_output_vars[0] + " = dot(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
}
VisualShaderNodeDotProduct::VisualShaderNodeDotProduct() {
@@ -2706,7 +2790,7 @@ String VisualShaderNodeVectorLen::get_output_port_name(int p_port) const {
}
String VisualShaderNodeVectorLen::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 {
- return "\t" + p_output_vars[0] + " = length(" + p_input_vars[0] + ");\n";
+ return " " + p_output_vars[0] + " = length(" + p_input_vars[0] + ");\n";
}
VisualShaderNodeVectorLen::VisualShaderNodeVectorLen() {
@@ -2744,7 +2828,7 @@ String VisualShaderNodeDeterminant::get_output_port_name(int p_port) const {
}
String VisualShaderNodeDeterminant::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 {
- return "\t" + p_output_vars[0] + " = determinant(" + p_input_vars[0] + ");\n";
+ return " " + p_output_vars[0] + " = determinant(" + p_input_vars[0] + ");\n";
}
VisualShaderNodeDeterminant::VisualShaderNodeDeterminant() {
@@ -2789,7 +2873,7 @@ String VisualShaderNodeScalarDerivativeFunc::generate_code(Shader::Mode p_mode,
};
String code;
- code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
return code;
}
@@ -2861,7 +2945,7 @@ String VisualShaderNodeVectorDerivativeFunc::generate_code(Shader::Mode p_mode,
};
String code;
- code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
return code;
}
@@ -2949,7 +3033,7 @@ String VisualShaderNodeClamp::get_output_port_name(int p_port) const {
}
String VisualShaderNodeClamp::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 {
- return "\t" + p_output_vars[0] + " = clamp(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
+ return " " + p_output_vars[0] + " = clamp(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
}
void VisualShaderNodeClamp::set_op_type(OpType p_op_type) {
@@ -3048,7 +3132,7 @@ String VisualShaderNodeFaceForward::get_output_port_name(int p_port) const {
}
String VisualShaderNodeFaceForward::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 {
- return "\t" + p_output_vars[0] + " = faceforward(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
+ return " " + p_output_vars[0] + " = faceforward(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
}
VisualShaderNodeFaceForward::VisualShaderNodeFaceForward() {
@@ -3095,7 +3179,7 @@ String VisualShaderNodeOuterProduct::get_output_port_name(int p_port) const {
}
String VisualShaderNodeOuterProduct::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 {
- return "\t" + p_output_vars[0] + " = outerProduct(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0));\n";
+ return " " + p_output_vars[0] + " = outerProduct(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0));\n";
}
VisualShaderNodeOuterProduct::VisualShaderNodeOuterProduct() {
@@ -3199,7 +3283,7 @@ VisualShaderNodeStep::OpType VisualShaderNodeStep::get_op_type() const {
}
String VisualShaderNodeStep::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 {
- return "\t" + p_output_vars[0] + " = step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ return " " + p_output_vars[0] + " = step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
}
Vector<StringName> VisualShaderNodeStep::get_editable_properties() const {
@@ -3326,7 +3410,7 @@ VisualShaderNodeSmoothStep::OpType VisualShaderNodeSmoothStep::get_op_type() con
}
String VisualShaderNodeSmoothStep::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 {
- return "\t" + p_output_vars[0] + " = smoothstep(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
+ return " " + p_output_vars[0] + " = smoothstep(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
}
Vector<StringName> VisualShaderNodeSmoothStep::get_editable_properties() const {
@@ -3389,7 +3473,7 @@ String VisualShaderNodeVectorDistance::get_output_port_name(int p_port) const {
}
String VisualShaderNodeVectorDistance::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 {
- return "\t" + p_output_vars[0] + " = distance(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ return " " + p_output_vars[0] + " = distance(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
}
VisualShaderNodeVectorDistance::VisualShaderNodeVectorDistance() {
@@ -3439,7 +3523,7 @@ String VisualShaderNodeVectorRefract::get_output_port_name(int p_port) const {
}
String VisualShaderNodeVectorRefract::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 {
- return "\t" + p_output_vars[0] + " = refract(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
+ return " " + p_output_vars[0] + " = refract(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
}
VisualShaderNodeVectorRefract::VisualShaderNodeVectorRefract() {
@@ -3542,7 +3626,7 @@ VisualShaderNodeMix::OpType VisualShaderNodeMix::get_op_type() const {
}
String VisualShaderNodeMix::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 {
- return "\t" + p_output_vars[0] + " = mix(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
+ return " " + p_output_vars[0] + " = mix(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
}
Vector<StringName> VisualShaderNodeMix::get_editable_properties() const {
@@ -3606,7 +3690,7 @@ String VisualShaderNodeVectorCompose::get_output_port_name(int p_port) const {
}
String VisualShaderNodeVectorCompose::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 {
- return "\t" + p_output_vars[0] + " = vec3(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
+ return " " + p_output_vars[0] + " = vec3(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
}
VisualShaderNodeVectorCompose::VisualShaderNodeVectorCompose() {
@@ -3654,7 +3738,7 @@ String VisualShaderNodeTransformCompose::get_output_port_name(int p_port) const
}
String VisualShaderNodeTransformCompose::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 {
- return "\t" + p_output_vars[0] + " = mat4(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0), vec4(" + p_input_vars[2] + ", 0.0), vec4(" + p_input_vars[3] + ", 1.0));\n";
+ return " " + p_output_vars[0] + " = mat4(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0), vec4(" + p_input_vars[2] + ", 0.0), vec4(" + p_input_vars[3] + ", 1.0));\n";
}
VisualShaderNodeTransformCompose::VisualShaderNodeTransformCompose() {
@@ -3701,9 +3785,9 @@ String VisualShaderNodeVectorDecompose::get_output_port_name(int p_port) const {
String VisualShaderNodeVectorDecompose::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 {
String code;
- code += "\t" + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n";
- code += "\t" + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n";
- code += "\t" + p_output_vars[2] + " = " + p_input_vars[0] + ".z;\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n";
+ code += " " + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n";
+ code += " " + p_output_vars[2] + " = " + p_input_vars[0] + ".z;\n";
return code;
}
@@ -3751,10 +3835,10 @@ String VisualShaderNodeTransformDecompose::get_output_port_name(int p_port) cons
String VisualShaderNodeTransformDecompose::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 {
String code;
- code += "\t" + p_output_vars[0] + " = " + p_input_vars[0] + "[0].xyz;\n";
- code += "\t" + p_output_vars[1] + " = " + p_input_vars[0] + "[1].xyz;\n";
- code += "\t" + p_output_vars[2] + " = " + p_input_vars[0] + "[2].xyz;\n";
- code += "\t" + p_output_vars[3] + " = " + p_input_vars[0] + "[3].xyz;\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[0] + "[0].xyz;\n";
+ code += " " + p_output_vars[1] + " = " + p_input_vars[0] + "[1].xyz;\n";
+ code += " " + p_output_vars[2] + " = " + p_input_vars[0] + "[2].xyz;\n";
+ code += " " + p_output_vars[3] + " = " + p_input_vars[0] + "[3].xyz;\n";
return code;
}
@@ -3809,7 +3893,7 @@ String VisualShaderNodeFloatUniform::generate_global(Shader::Mode p_mode, Visual
}
String VisualShaderNodeFloatUniform::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 {
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
}
bool VisualShaderNodeFloatUniform::is_show_prop_names() const {
@@ -3980,7 +4064,7 @@ String VisualShaderNodeIntUniform::generate_global(Shader::Mode p_mode, VisualSh
}
String VisualShaderNodeIntUniform::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 {
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
}
bool VisualShaderNodeIntUniform::is_show_prop_names() const {
@@ -4166,7 +4250,7 @@ String VisualShaderNodeBooleanUniform::generate_global(Shader::Mode p_mode, Visu
}
String VisualShaderNodeBooleanUniform::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 {
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
}
bool VisualShaderNodeBooleanUniform::is_show_prop_names() const {
@@ -4266,8 +4350,8 @@ String VisualShaderNodeColorUniform::generate_global(Shader::Mode p_mode, Visual
}
String VisualShaderNodeColorUniform::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 {
- String code = "\t" + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n";
- code += "\t" + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n";
+ String code = " " + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n";
+ code += " " + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n";
return code;
}
@@ -4364,7 +4448,7 @@ String VisualShaderNodeVec3Uniform::generate_global(Shader::Mode p_mode, VisualS
}
String VisualShaderNodeVec3Uniform::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 {
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
}
void VisualShaderNodeVec3Uniform::_bind_methods() {
@@ -4468,7 +4552,7 @@ String VisualShaderNodeTransformUniform::generate_global(Shader::Mode p_mode, Vi
}
String VisualShaderNodeTransformUniform::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 {
- return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
+ return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
}
void VisualShaderNodeTransformUniform::_bind_methods() {
@@ -4600,23 +4684,23 @@ String VisualShaderNodeTextureUniform::generate_code(Shader::Mode p_mode, Visual
}
String id = get_uniform_name();
- String code = "\t{\n";
+ String code = " {\n";
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\t\tvec4 n_tex_read = texture(" + id + ", " + default_uv + ");\n";
+ code += " vec4 n_tex_read = texture(" + id + ", " + default_uv + ");\n";
} else {
- code += "\t\tvec4 n_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 n_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tvec4 n_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
+ code += " vec4 n_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
} else {
- code += "\t\tvec4 n_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
+ code += " vec4 n_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
}
- code += "\t\t" + p_output_vars[0] + " = n_tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = n_tex_read.a;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = n_tex_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = n_tex_read.a;\n";
+ code += " }\n";
return code;
}
@@ -4721,20 +4805,20 @@ String VisualShaderNodeTextureUniformTriplanar::generate_global_per_node(Shader:
String code;
code += "// TRIPLANAR FUNCTION GLOBAL CODE\n";
- code += "\tvec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) {\n";
- code += "\t\tvec4 samp = vec4(0.0);\n";
- code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z;\n";
- code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y;\n";
- code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x;\n";
- code += "\t\treturn samp;\n";
- code += "\t}\n";
+ code += " vec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) {\n";
+ code += " vec4 samp = vec4(0.0);\n";
+ code += " samp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z;\n";
+ code += " samp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y;\n";
+ code += " samp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x;\n";
+ code += " return samp;\n";
+ code += " }\n";
code += "\n";
- code += "\tuniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0);\n";
- code += "\tuniform vec3 triplanar_offset;\n";
- code += "\tuniform float triplanar_sharpness = 0.5;\n";
+ code += " uniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0);\n";
+ code += " uniform vec3 triplanar_offset;\n";
+ code += " uniform float triplanar_sharpness = 0.5;\n";
code += "\n";
- code += "\tvarying vec3 triplanar_power_normal;\n";
- code += "\tvarying vec3 triplanar_pos;\n";
+ code += " varying vec3 triplanar_power_normal;\n";
+ code += " varying vec3 triplanar_pos;\n";
return code;
}
@@ -4743,11 +4827,11 @@ String VisualShaderNodeTextureUniformTriplanar::generate_global_per_func(Shader:
String code;
if (p_type == VisualShader::TYPE_VERTEX) {
- code += "\t// TRIPLANAR FUNCTION VERTEX CODE\n";
- code += "\t\ttriplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness));\n";
- code += "\t\ttriplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0));\n";
- code += "\t\ttriplanar_pos = VERTEX * triplanar_scale + triplanar_offset;\n";
- code += "\t\ttriplanar_pos *= vec3(1.0, -1.0, 1.0);\n";
+ code += " // TRIPLANAR FUNCTION VERTEX CODE\n";
+ code += " triplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness));\n";
+ code += " triplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0));\n";
+ code += " triplanar_pos = VERTEX * triplanar_scale + triplanar_offset;\n";
+ code += " triplanar_pos *= vec3(1.0, -1.0, 1.0);\n";
}
return code;
@@ -4755,21 +4839,21 @@ String VisualShaderNodeTextureUniformTriplanar::generate_global_per_func(Shader:
String VisualShaderNodeTextureUniformTriplanar::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 {
String id = get_uniform_name();
- String code = "\t{\n";
+ String code = " {\n";
if (p_input_vars[0] == String() && p_input_vars[1] == String()) {
- code += "\t\tvec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, triplanar_pos);\n";
+ code += " vec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, triplanar_pos);\n";
} else if (p_input_vars[0] != String() && p_input_vars[1] == String()) {
- code += "\t\tvec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", triplanar_pos);\n";
+ code += " vec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", triplanar_pos);\n";
} else if (p_input_vars[0] == String() && p_input_vars[1] != String()) {
- code += "\t\tvec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, " + p_input_vars[1] + ");\n";
+ code += " vec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, " + p_input_vars[1] + ");\n";
} else {
- code += "\t\tvec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ code += " vec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
}
- code += "\t\t" + p_output_vars[0] + " = n_tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = n_tex_read.a;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = n_tex_read.rgb;\n";
+ code += " " + p_output_vars[1] + " = n_tex_read.a;\n";
+ code += " }\n";
return code;
}
@@ -5046,18 +5130,18 @@ String VisualShaderNodeIf::get_output_port_name(int p_port) const {
String VisualShaderNodeIf::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 {
String code;
- code += "\tif(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ")\n"; // abs(a - b) < tolerance eg. a == b
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[3] + ";\n";
- code += "\t}\n";
- code += "\telse if(" + p_input_vars[0] + " < " + p_input_vars[1] + ")\n"; // a < b
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[5] + ";\n";
- code += "\t}\n";
- code += "\telse\n"; // a > b (or a >= b if abs(a - b) < tolerance is false)
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[4] + ";\n";
- code += "\t}\n";
+ code += " if(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ")\n"; // abs(a - b) < tolerance eg. a == b
+ code += " {\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[3] + ";\n";
+ code += " }\n";
+ code += " else if(" + p_input_vars[0] + " < " + p_input_vars[1] + ")\n"; // a < b
+ code += " {\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[5] + ";\n";
+ code += " }\n";
+ code += " else\n"; // a > b (or a >= b if abs(a - b) < tolerance is false)
+ code += " {\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[4] + ";\n";
+ code += " }\n";
return code;
}
@@ -5198,14 +5282,14 @@ void VisualShaderNodeSwitch::_bind_methods() { // static
String VisualShaderNodeSwitch::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 {
String code;
- code += "\tif(" + p_input_vars[0] + ")\n";
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
- code += "\t}\n";
- code += "\telse\n";
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
- code += "\t}\n";
+ code += " if(" + p_input_vars[0] + ")\n";
+ code += " {\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
+ code += " }\n";
+ code += " else\n";
+ code += " {\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
+ code += " }\n";
return code;
}
@@ -5290,12 +5374,12 @@ String VisualShaderNodeFresnel::generate_code(Shader::Mode p_mode, VisualShader:
}
if (is_input_port_connected(2)) {
- return "\t" + p_output_vars[0] + " = " + p_input_vars[2] + " ? (pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ")) : (pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + "));\n";
+ return " " + p_output_vars[0] + " = " + p_input_vars[2] + " ? (pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ")) : (pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + "));\n";
} else {
if (get_input_port_default_value(2)) {
- return "\t" + p_output_vars[0] + " = pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
+ return " " + p_output_vars[0] + " = pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
} else {
- return "\t" + p_output_vars[0] + " = pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
+ return " " + p_output_vars[0] + " = pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
}
}
}
@@ -5351,7 +5435,7 @@ String VisualShaderNodeIs::generate_code(Shader::Mode p_mode, VisualShader::Type
};
String code;
- code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
return code;
}
@@ -5478,37 +5562,37 @@ String VisualShaderNodeCompare::generate_code(Shader::Mode p_mode, VisualShader:
switch (ctype) {
case CTYPE_SCALAR:
if (func == FUNC_EQUAL) {
- code += "\t" + p_output_vars[0] + " = (abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");";
+ code += " " + p_output_vars[0] + " = (abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");";
} else if (func == FUNC_NOT_EQUAL) {
- code += "\t" + p_output_vars[0] + " = !(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");";
+ code += " " + p_output_vars[0] + " = !(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");";
} else {
- code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
}
break;
case CTYPE_SCALAR_INT:
- code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
break;
case CTYPE_VECTOR:
- code += "\t{\n";
- code += "\t\tbvec3 _bv = " + String(funcs[func]).replace("$", p_input_vars[0] + ", " + p_input_vars[1]) + ";\n";
- code += "\t\t" + p_output_vars[0] + " = " + String(conds[condition]).replace("$", "_bv") + ";\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " bvec3 _bv = " + String(funcs[func]).replace("$", p_input_vars[0] + ", " + p_input_vars[1]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + String(conds[condition]).replace("$", "_bv") + ";\n";
+ code += " }\n";
break;
case CTYPE_BOOLEAN:
if (func > FUNC_NOT_EQUAL) {
- return "\t" + p_output_vars[0] + " = false;\n";
+ return " " + p_output_vars[0] + " = false;\n";
}
- code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
break;
case CTYPE_TRANSFORM:
if (func > FUNC_NOT_EQUAL) {
- return "\t" + p_output_vars[0] + " = false;\n";
+ return " " + p_output_vars[0] + " = false;\n";
}
- code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
+ code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
break;
default:
@@ -5664,7 +5748,7 @@ String VisualShaderNodeMultiplyAdd::get_output_port_name(int p_port) const {
}
String VisualShaderNodeMultiplyAdd::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 {
- return "\t" + p_output_vars[0] + " = fma(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
+ return " " + p_output_vars[0] + " = fma(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
}
void VisualShaderNodeMultiplyAdd::set_op_type(OpType p_op_type) {
@@ -5752,34 +5836,34 @@ String VisualShaderNodeBillboard::generate_code(Shader::Mode p_mode, VisualShade
switch (billboard_type) {
case BILLBOARD_TYPE_ENABLED:
- code += "\t{\n";
- code += "\t\tmat4 __mvm = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0], CAMERA_MATRIX[1], CAMERA_MATRIX[2], WORLD_MATRIX[3]);\n";
+ code += " {\n";
+ code += " mat4 __mvm = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0], CAMERA_MATRIX[1], CAMERA_MATRIX[2], WORLD_MATRIX[3]);\n";
if (keep_scale) {
- code += "\t\t__mvm = __mvm * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code += " __mvm = __mvm * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
}
- code += "\t\t" + p_output_vars[0] + " = __mvm;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = __mvm;\n";
+ code += " }\n";
break;
case BILLBOARD_TYPE_FIXED_Y:
- code += "\t{\n";
- code += "\t\tmat4 __mvm = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0], WORLD_MATRIX[1], vec4(normalize(cross(CAMERA_MATRIX[0].xyz, WORLD_MATRIX[1].xyz)), 0.0), WORLD_MATRIX[3]);\n";
+ code += " {\n";
+ code += " mat4 __mvm = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0], WORLD_MATRIX[1], vec4(normalize(cross(CAMERA_MATRIX[0].xyz, WORLD_MATRIX[1].xyz)), 0.0), WORLD_MATRIX[3]);\n";
if (keep_scale) {
- code += "\t\t__mvm = __mvm * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code += " __mvm = __mvm * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
} else {
- code += "\t\t__mvm = __mvm * mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0 / length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code += " __mvm = __mvm * mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0 / length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
}
- code += "\t\t" + p_output_vars[0] + " = __mvm;\n";
- code += "\t}\n";
+ code += " " + p_output_vars[0] + " = __mvm;\n";
+ code += " }\n";
break;
case BILLBOARD_TYPE_PARTICLES:
- code += "\t{\n";
- code += "\t\tmat4 __wm = mat4(normalize(CAMERA_MATRIX[0]) * length(WORLD_MATRIX[0]), normalize(CAMERA_MATRIX[1]) * length(WORLD_MATRIX[0]), normalize(CAMERA_MATRIX[2]) * length(WORLD_MATRIX[2]), WORLD_MATRIX[3]);\n";
- code += "\t\t__wm = __wm * mat4(vec4(cos(INSTANCE_CUSTOM.x), -sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
- code += "\t\t" + p_output_vars[0] + " = INV_CAMERA_MATRIX * __wm;\n";
- code += "\t}\n";
+ code += " {\n";
+ code += " mat4 __wm = mat4(normalize(CAMERA_MATRIX[0]) * length(WORLD_MATRIX[0]), normalize(CAMERA_MATRIX[1]) * length(WORLD_MATRIX[0]), normalize(CAMERA_MATRIX[2]) * length(WORLD_MATRIX[2]), WORLD_MATRIX[3]);\n";
+ code += " __wm = __wm * mat4(vec4(cos(INSTANCE_CUSTOM.x), -sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code += " " + p_output_vars[0] + " = INV_CAMERA_MATRIX * __wm;\n";
+ code += " }\n";
break;
default:
- code += "\t" + p_output_vars[0] + " = mat4(1.0);\n";
+ code += " " + p_output_vars[0] + " = mat4(1.0);\n";
break;
}
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index 5b44e9f776..33a45a4384 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -338,6 +338,39 @@ public:
///////////////////////////////////////
+class VisualShaderNodeCurveXYZTexture : public VisualShaderNodeResizableBase {
+ GDCLASS(VisualShaderNodeCurveXYZTexture, VisualShaderNodeResizableBase);
+ Ref<CurveXYZTexture> texture;
+
+protected:
+ static void _bind_methods();
+
+public:
+ virtual String get_caption() const override;
+
+ virtual int get_input_port_count() const override;
+ virtual PortType get_input_port_type(int p_port) const override;
+ virtual String get_input_port_name(int p_port) const override;
+
+ virtual int get_output_port_count() const override;
+ virtual PortType get_output_port_type(int p_port) const override;
+ virtual String get_output_port_name(int p_port) const override;
+
+ virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
+ virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
+ virtual String 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 = false) const override;
+
+ void set_texture(Ref<CurveXYZTexture> p_value);
+ Ref<CurveXYZTexture> get_texture() const;
+
+ virtual Vector<StringName> get_editable_properties() const override;
+ virtual bool is_use_prop_slots() const override;
+
+ VisualShaderNodeCurveXYZTexture();
+};
+
+///////////////////////////////////////
+
class VisualShaderNodeSample3D : public VisualShaderNode {
GDCLASS(VisualShaderNodeSample3D, VisualShaderNode);
diff --git a/scene/resources/visual_shader_particle_nodes.cpp b/scene/resources/visual_shader_particle_nodes.cpp
index 29d583a82a..2250cf8d95 100644
--- a/scene/resources/visual_shader_particle_nodes.cpp
+++ b/scene/resources/visual_shader_particle_nodes.cpp
@@ -76,14 +76,14 @@ String VisualShaderNodeParticleSphereEmitter::get_input_port_name(int p_port) co
String VisualShaderNodeParticleSphereEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
String code;
code += "vec3 __get_random_point_in_sphere(inout uint seed, float radius, float inner_radius) {\n";
- code += "\treturn __get_random_unit_vec3(seed) * __randf_range(seed, inner_radius, radius);\n";
+ code += " return __get_random_unit_vec3(seed) * __randf_range(seed, inner_radius, radius);\n";
code += "}\n\n";
return code;
}
String VisualShaderNodeParticleSphereEmitter::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 {
String code;
- code += "\t" + p_output_vars[0] + " = __get_random_point_in_sphere(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n";
+ code += " " + p_output_vars[0] + " = __get_random_point_in_sphere(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n";
return code;
}
@@ -119,15 +119,15 @@ String VisualShaderNodeParticleBoxEmitter::get_input_port_name(int p_port) const
String VisualShaderNodeParticleBoxEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
String code;
code += "vec3 __get_random_point_in_box(inout uint seed, vec3 extents) {\n";
- code += "\tvec3 half_extents = extents / 2.0;\n";
- code += "\treturn vec3(__randf_range(seed, -half_extents.x, half_extents.x), __randf_range(seed, -half_extents.y, half_extents.y), __randf_range(seed, -half_extents.z, half_extents.z));\n";
+ code += " vec3 half_extents = extents / 2.0;\n";
+ code += " return vec3(__randf_range(seed, -half_extents.x, half_extents.x), __randf_range(seed, -half_extents.y, half_extents.y), __randf_range(seed, -half_extents.z, half_extents.z));\n";
code += "}\n\n";
return code;
}
String VisualShaderNodeParticleBoxEmitter::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 {
String code;
- code += "\t" + p_output_vars[0] + " = __get_random_point_in_box(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ");\n";
+ code += " " + p_output_vars[0] + " = __get_random_point_in_box(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ");\n";
return code;
}
@@ -163,16 +163,16 @@ String VisualShaderNodeParticleRingEmitter::get_input_port_name(int p_port) cons
String VisualShaderNodeParticleRingEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
String code;
code += "vec3 __get_random_point_on_ring(inout uint seed, float radius, float inner_radius, float height) {\n";
- code += "\tfloat angle = __rand_from_seed(seed) * PI * 2.0;\n";
- code += "\tvec2 ring = vec2(sin(angle), cos(angle)) * __randf_range(seed, inner_radius, radius);\n";
- code += "\treturn vec3(ring.x, __randf_range(seed, min(0.0, height), max(0.0, height)), ring.y);\n";
+ code += " float angle = __rand_from_seed(seed) * PI * 2.0;\n";
+ code += " vec2 ring = vec2(sin(angle), cos(angle)) * __randf_range(seed, inner_radius, radius);\n";
+ code += " return vec3(ring.x, __randf_range(seed, min(0.0, height), max(0.0, height)), ring.y);\n";
code += "}\n\n";
return code;
}
String VisualShaderNodeParticleRingEmitter::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 {
String code;
- code = "\t" + p_output_vars[0] + " = __get_random_point_on_ring(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ", " + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ");\n";
+ code = " " + p_output_vars[0] + " = __get_random_point_on_ring(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ", " + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ");\n";
return code;
}
@@ -242,9 +242,9 @@ String VisualShaderNodeParticleMultiplyByAxisAngle::get_output_port_name(int p_p
String VisualShaderNodeParticleMultiplyByAxisAngle::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 {
String code;
if (degrees_mode) {
- code += "\t" + p_output_vars[0] + " = __build_rotation_mat3(" + (p_input_vars[1].is_empty() ? ("vec3" + (String)get_input_port_default_value(1)) : p_input_vars[1]) + ", radians(" + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ")) * " + (p_input_vars[0].is_empty() ? "vec3(0.0)" : p_input_vars[0]) + ";\n";
+ code += " " + p_output_vars[0] + " = __build_rotation_mat3(" + (p_input_vars[1].is_empty() ? ("vec3" + (String)get_input_port_default_value(1)) : p_input_vars[1]) + ", radians(" + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ")) * " + (p_input_vars[0].is_empty() ? "vec3(0.0)" : p_input_vars[0]) + ";\n";
} else {
- code += "\t" + p_output_vars[0] + " = __build_rotation_mat3(" + (p_input_vars[1].is_empty() ? ("vec3" + (String)get_input_port_default_value(1)) : p_input_vars[1]) + ", " + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ") * " + (p_input_vars[0].is_empty() ? "vec3(0.0)" : p_input_vars[0]) + ";\n";
+ code += " " + p_output_vars[0] + " = __build_rotation_mat3(" + (p_input_vars[1].is_empty() ? ("vec3" + (String)get_input_port_default_value(1)) : p_input_vars[1]) + ", " + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ") * " + (p_input_vars[0].is_empty() ? "vec3(0.0)" : p_input_vars[0]) + ";\n";
}
return code;
}
@@ -315,16 +315,16 @@ String VisualShaderNodeParticleConeVelocity::get_output_port_name(int p_port) co
String VisualShaderNodeParticleConeVelocity::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 {
String code;
- code += "\t__radians = radians(" + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n";
- code += "\t__scalar_buff1 = __rand_from_seed_m1_p1(__seed) * __radians;\n";
- code += "\t__scalar_buff2 = __rand_from_seed_m1_p1(__seed) * __radians;\n";
- code += "\t__vec3_buff1 = " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + ";\n";
- code += "\t__scalar_buff1 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.x, __vec3_buff1.z) : sign(__vec3_buff1.x) * (PI / 2.0);\n";
- code += "\t__scalar_buff2 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.z)) : (__vec3_buff1.x != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.x)) : sign(__vec3_buff1.y) * (PI / 2.0));\n";
- code += "\t__vec3_buff1 = vec3(sin(__scalar_buff1), 0.0, cos(__scalar_buff1));\n";
- code += "\t__vec3_buff2 = vec3(0.0, sin(__scalar_buff2), cos(__scalar_buff2));\n";
- code += "\t__vec3_buff2.z = __vec3_buff2.z / max(0.0001, sqrt(abs(__vec3_buff2.z)));\n";
- code += "\t" + p_output_vars[0] + " = normalize(vec3(__vec3_buff1.x * __vec3_buff2.z, __vec3_buff2.y, __vec3_buff1.z * __vec3_buff2.z));\n";
+ code += " __radians = radians(" + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n";
+ code += " __scalar_buff1 = __rand_from_seed_m1_p1(__seed) * __radians;\n";
+ code += " __scalar_buff2 = __rand_from_seed_m1_p1(__seed) * __radians;\n";
+ code += " __vec3_buff1 = " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + ";\n";
+ code += " __scalar_buff1 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.x, __vec3_buff1.z) : sign(__vec3_buff1.x) * (PI / 2.0);\n";
+ code += " __scalar_buff2 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.z)) : (__vec3_buff1.x != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.x)) : sign(__vec3_buff1.y) * (PI / 2.0));\n";
+ code += " __vec3_buff1 = vec3(sin(__scalar_buff1), 0.0, cos(__scalar_buff1));\n";
+ code += " __vec3_buff2 = vec3(0.0, sin(__scalar_buff2), cos(__scalar_buff2));\n";
+ code += " __vec3_buff2.z = __vec3_buff2.z / max(0.0001, sqrt(abs(__vec3_buff2.z)));\n";
+ code += " " + p_output_vars[0] + " = normalize(vec3(__vec3_buff1.x * __vec3_buff2.z, __vec3_buff2.y, __vec3_buff1.z * __vec3_buff2.z));\n";
return code;
}
@@ -394,9 +394,9 @@ String VisualShaderNodeParticleRandomness::get_input_port_name(int p_port) const
String VisualShaderNodeParticleRandomness::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 {
String code;
if (op_type == OP_TYPE_SCALAR) {
- code += vformat("\t%s = __randf_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
+ code += vformat(" %s = __randf_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
} else if (op_type == OP_TYPE_VECTOR) {
- code += vformat("\t%s = __randv_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
+ code += vformat(" %s = __randv_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
}
return code;
}
@@ -491,14 +491,14 @@ String VisualShaderNodeParticleAccelerator::generate_code(Shader::Mode p_mode, V
String code;
switch (mode) {
case MODE_LINEAR:
- code += "\t" + p_output_vars[0] + " = length(VELOCITY) > 0.0 ? " + "normalize(VELOCITY) * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n";
+ code += " " + p_output_vars[0] + " = length(VELOCITY) > 0.0 ? " + "normalize(VELOCITY) * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n";
break;
case MODE_RADIAL:
- code += "\t" + p_output_vars[0] + " = length(__diff) > 0.0 ? __ndiff * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n";
+ code += " " + p_output_vars[0] + " = length(__diff) > 0.0 ? __ndiff * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n";
break;
case MODE_TANGENTIAL:
- code += "\t__vec3_buff1 = cross(__ndiff, normalize(" + (p_input_vars[2].is_empty() ? "vec3" + (String)get_input_port_default_value(2) : p_input_vars[2]) + "));\n";
- code += "\t" + p_output_vars[0] + " = length(__vec3_buff1) > 0.0 ? normalize(__vec3_buff1) * (" + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ")) : vec3(0.0);\n";
+ code += " __vec3_buff1 = cross(__ndiff, normalize(" + (p_input_vars[2].is_empty() ? "vec3" + (String)get_input_port_default_value(2) : p_input_vars[2]) + "));\n";
+ code += " " + p_output_vars[0] + " = length(__vec3_buff1) > 0.0 ? normalize(__vec3_buff1) * (" + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ")) : vec3(0.0);\n";
break;
case MODE_MAX:
break;
@@ -693,7 +693,7 @@ bool VisualShaderNodeParticleOutput::is_port_separator(int p_index) const {
String VisualShaderNodeParticleOutput::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 {
String code;
- String tab = "\t";
+ String tab = " ";
if (shader_type == VisualShader::TYPE_START_CUSTOM || shader_type == VisualShader::TYPE_PROCESS_CUSTOM) {
if (!p_input_vars[0].is_empty()) { // custom.rgb
@@ -718,7 +718,7 @@ String VisualShaderNodeParticleOutput::generate_code(Shader::Mode p_mode, Visual
if (!p_input_vars[0].is_empty()) { // active (begin)
code += tab + "ACTIVE = " + p_input_vars[0] + ";\n";
code += tab + "if(ACTIVE) {\n";
- tab += "\t";
+ tab += " ";
}
if (!p_input_vars[1].is_empty()) { // velocity
code += tab + "VELOCITY = " + p_input_vars[1] + ";\n";
@@ -734,14 +734,14 @@ String VisualShaderNodeParticleOutput::generate_code(Shader::Mode p_mode, Visual
if (shader_type == VisualShader::TYPE_START) {
code += tab + "if (RESTART_POSITION) {\n";
if (!p_input_vars[4].is_empty()) {
- code += tab + "\tTRANSFORM = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(" + p_input_vars[4] + ", 1.0));\n";
+ code += tab + " TRANSFORM = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(" + p_input_vars[4] + ", 1.0));\n";
} else {
- code += tab + "\tTRANSFORM = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
+ code += tab + " TRANSFORM = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
}
- code += tab + "\tif (RESTART_VELOCITY) {\n";
- code += tab + "\t\tVELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY, 0.0)).xyz;\n";
- code += tab + "\t}\n";
- code += tab + "\tTRANSFORM = EMISSION_TRANSFORM * TRANSFORM;\n";
+ code += tab + " if (RESTART_VELOCITY) {\n";
+ code += tab + " VELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY, 0.0)).xyz;\n";
+ code += tab + " }\n";
+ code += tab + " TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;\n";
code += tab + "}\n";
} else if (shader_type == VisualShader::TYPE_COLLIDE) { // position
if (!p_input_vars[4].is_empty()) {
@@ -779,7 +779,7 @@ String VisualShaderNodeParticleOutput::generate_code(Shader::Mode p_mode, Visual
}
}
if (!p_input_vars[0].is_empty()) { // active (end)
- code += "\t}\n";
+ code += " }\n";
}
}
return code;
@@ -926,12 +926,12 @@ String VisualShaderNodeParticleEmit::generate_code(Shader::Mode p_mode, VisualSh
if (!is_input_port_connected(0)) {
default_condition = true;
if (get_input_port_default_value(0)) {
- tab = "\t";
+ tab = " ";
} else {
return code;
}
} else {
- tab = "\t\t";
+ tab = " ";
}
String transform;
@@ -1008,13 +1008,13 @@ String VisualShaderNodeParticleEmit::generate_code(Shader::Mode p_mode, VisualSh
}
if (!default_condition) {
- code += "\tif (" + p_input_vars[0] + ") {\n";
+ code += " if (" + p_input_vars[0] + ") {\n";
}
code += tab + "emit_subparticle(" + transform + ", " + velocity + ", vec4(" + color + ", " + alpha + "), vec4(" + custom + ", " + custom_alpha + "), " + flags + ");\n";
if (!default_condition) {
- code += "\t}\n";
+ code += " }\n";
}
return code;
diff --git a/scene/resources/visual_shader_sdf_nodes.cpp b/scene/resources/visual_shader_sdf_nodes.cpp
index d25e32b070..14c655b129 100644
--- a/scene/resources/visual_shader_sdf_nodes.cpp
+++ b/scene/resources/visual_shader_sdf_nodes.cpp
@@ -61,7 +61,7 @@ String VisualShaderNodeSDFToScreenUV::get_output_port_name(int p_port) const {
}
String VisualShaderNodeSDFToScreenUV::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 {
- return "\t" + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
}
VisualShaderNodeSDFToScreenUV::VisualShaderNodeSDFToScreenUV() {
@@ -105,7 +105,7 @@ String VisualShaderNodeScreenUVToSDF::get_input_port_default_hint(int p_port) co
}
String VisualShaderNodeScreenUVToSDF::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 {
- return "\t" + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0] == String() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0] == String() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
}
VisualShaderNodeScreenUVToSDF::VisualShaderNodeScreenUVToSDF() {
@@ -142,7 +142,7 @@ String VisualShaderNodeTextureSDF::get_output_port_name(int p_port) const {
}
String VisualShaderNodeTextureSDF::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 {
- return "\t" + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n";
+ return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n";
}
VisualShaderNodeTextureSDF::VisualShaderNodeTextureSDF() {
@@ -179,7 +179,7 @@ String VisualShaderNodeTextureSDFNormal::get_output_port_name(int p_port) const
}
String VisualShaderNodeTextureSDFNormal::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 {
- return "\t" + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
}
VisualShaderNodeTextureSDFNormal::VisualShaderNodeTextureSDFNormal() {
@@ -240,40 +240,40 @@ String VisualShaderNodeSDFRaymarch::get_output_port_name(int p_port) const {
String VisualShaderNodeSDFRaymarch::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 {
String code;
- code += "\t{\n";
+ code += " {\n";
if (p_input_vars[0] == String()) {
- code += "\t\tvec2 __from_pos = vec2(0.0f);\n";
+ code += " vec2 __from_pos = vec2(0.0f);\n";
} else {
- code += "\t\tvec2 __from_pos = " + p_input_vars[0] + ".xy;\n";
+ code += " vec2 __from_pos = " + p_input_vars[0] + ".xy;\n";
}
if (p_input_vars[1] == String()) {
- code += "\t\tvec2 __to_pos = vec2(0.0f);\n";
+ code += " vec2 __to_pos = vec2(0.0f);\n";
} else {
- code += "\t\tvec2 __to_pos = " + p_input_vars[1] + ".xy;\n";
+ code += " vec2 __to_pos = " + p_input_vars[1] + ".xy;\n";
}
- code += "\n\t\tvec2 __at = __from_pos;\n";
- code += "\t\tfloat __max_dist = distance(__from_pos, __to_pos);\n";
- code += "\t\tvec2 __dir = normalize(__to_pos - __from_pos);\n\n";
-
- code += "\t\tfloat __accum = 0.0f;\n";
- code += "\t\twhile(__accum < __max_dist) {\n";
- code += "\t\t\tfloat __d = texture_sdf(__at);\n";
- code += "\t\t\t__accum += __d;\n";
- code += "\t\t\tif (__d < 0.01f) {\n";
- code += "\t\t\t\tbreak;\n";
- code += "\t\t\t}\n";
- code += "\t\t\t__at += __d * __dir;\n";
- code += "\t\t}\n";
-
- code += "\t\tfloat __dist = min(__max_dist, __accum);\n";
- code += "\t\t" + p_output_vars[0] + " = __dist;\n";
- code += "\t\t" + p_output_vars[1] + " = __accum < __max_dist;\n";
- code += "\t\t" + p_output_vars[2] + " = vec3(__from_pos + __dir * __dist, 0.0f);\n";
-
- code += "\t}\n";
+ code += "\n vec2 __at = __from_pos;\n";
+ code += " float __max_dist = distance(__from_pos, __to_pos);\n";
+ code += " vec2 __dir = normalize(__to_pos - __from_pos);\n\n";
+
+ code += " float __accum = 0.0f;\n";
+ code += " while(__accum < __max_dist) {\n";
+ code += " float __d = texture_sdf(__at);\n";
+ code += " __accum += __d;\n";
+ code += " if (__d < 0.01f) {\n";
+ code += " break;\n";
+ code += " }\n";
+ code += " __at += __d * __dir;\n";
+ code += " }\n";
+
+ code += " float __dist = min(__max_dist, __accum);\n";
+ code += " " + p_output_vars[0] + " = __dist;\n";
+ code += " " + p_output_vars[1] + " = __accum < __max_dist;\n";
+ code += " " + p_output_vars[2] + " = vec3(__from_pos + __dir * __dist, 0.0f);\n";
+
+ code += " }\n";
return code;
}
diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp
index 35f8a506fc..b8173c9623 100644
--- a/scene/scene_string_names.cpp
+++ b/scene/scene_string_names.cpp
@@ -66,6 +66,8 @@ SceneStringNames::SceneStringNames() {
mouse_entered = StaticCString::create("mouse_entered");
mouse_exited = StaticCString::create("mouse_exited");
+ mouse_shape_entered = StaticCString::create("mouse_shape_entered");
+ mouse_shape_exited = StaticCString::create("mouse_shape_exited");
focus_entered = StaticCString::create("focus_entered");
focus_exited = StaticCString::create("focus_exited");
@@ -134,6 +136,7 @@ SceneStringNames::SceneStringNames() {
_spatial_editor_group = StaticCString::create("_spatial_editor_group");
_request_gizmo = StaticCString::create("_request_gizmo");
+ _clear_subgizmo_selection = StaticCString::create("_clear_subgizmo_selection");
offset = StaticCString::create("offset");
unit_offset = StaticCString::create("unit_offset");
@@ -169,6 +172,8 @@ SceneStringNames::SceneStringNames() {
_mouse_enter = StaticCString::create("_mouse_enter");
_mouse_exit = StaticCString::create("_mouse_exit");
+ _mouse_shape_enter = StaticCString::create("_mouse_shape_enter");
+ _mouse_shape_exit = StaticCString::create("_mouse_shape_exit");
_pressed = StaticCString::create("_pressed");
_toggled = StaticCString::create("_toggled");
diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h
index 01865b0d2f..eddb0c33eb 100644
--- a/scene/scene_string_names.h
+++ b/scene/scene_string_names.h
@@ -84,6 +84,8 @@ public:
StringName mouse_entered;
StringName mouse_exited;
+ StringName mouse_shape_entered;
+ StringName mouse_shape_exited;
StringName focus_entered;
StringName focus_exited;
@@ -154,6 +156,7 @@ public:
StringName _spatial_editor_group;
StringName _request_gizmo;
+ StringName _clear_subgizmo_selection;
StringName offset;
StringName unit_offset;
@@ -181,6 +184,8 @@ public:
StringName _mouse_enter;
StringName _mouse_exit;
+ StringName _mouse_shape_enter;
+ StringName _mouse_shape_exit;
StringName frame_changed;
StringName texture_changed;