Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Array for node configuration warnings #43180

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
Corresponds to the [constant NOTIFICATION_EXIT_TREE] notification in [method Object._notification] and signal [signal tree_exiting]. To get notified when the node has already left the active tree, connect to the [signal tree_exited].
</description>
</method>
<method name="_get_configuration_warning" qualifiers="virtual">
<return type="String">
<method name="_get_configuration_warnings" qualifiers="virtual">
<return type="Array">
</return>
<description>
The string returned from this method is displayed as a warning in the Scene Dock if the script that overrides it is a [code]tool[/code] script.
Returning an empty string produces no warning.
Call [method update_configuration_warning] when the warning needs to be updated for this node.
The elements in the array returned from this method are displayed as warnings in the Scene Dock if the script that overrides it is a [code]tool[/code] script.
Returning an empty array produces no warnings.
Call [method update_configuration_warnings] when the warnings need to be updated for this node.
</description>
</method>
<method name="_input" qualifiers="virtual">
Expand Down Expand Up @@ -856,12 +856,12 @@
Sets whether this is an instance load placeholder. See [InstancePlaceholder].
</description>
</method>
<method name="update_configuration_warning">
<method name="update_configuration_warnings">
<return type="void">
</return>
<description>
Updates the warning displayed for this node in the Scene Dock.
Use [method _get_configuration_warning] to setup the warning message to display.
Use [method _get_configuration_warnings] to setup the warning message to display.
</description>
</method>
</methods>
Expand Down
6 changes: 3 additions & 3 deletions editor/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
}
undo_redo->commit_action();
} else if (p_id == BUTTON_WARNING) {
String config_err = n->get_configuration_warning();
String config_err = n->get_configuration_warnings_as_string();
if (config_err == String()) {
return;
}
Expand Down Expand Up @@ -252,9 +252,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll

if (can_rename) { //should be can edit..

String warning = p_node->get_configuration_warning();
String warning = p_node->get_configuration_warnings_as_string();
if (!warning.is_empty()) {
item->add_button(0, get_theme_icon("NodeWarning", "EditorIcons"), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + p_node->get_configuration_warning());
item->add_button(0, get_theme_icon("NodeWarning", "EditorIcons"), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + warning);
}

int num_connections = p_node->get_persistent_signal_connection_count();
Expand Down
13 changes: 5 additions & 8 deletions scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
notify_property_list_changed();
_reset_timeout();
update();
update_configuration_warning();
update_configuration_warnings();
}

Ref<SpriteFrames> AnimatedSprite2D::get_sprite_frames() const {
Expand Down Expand Up @@ -440,17 +440,14 @@ StringName AnimatedSprite2D::get_animation() const {
return animation;
}

String AnimatedSprite2D::get_configuration_warning() const {
String warning = Node2D::get_configuration_warning();
TypedArray<String> AnimatedSprite2D::get_configuration_warnings() const {
TypedArray<String> warnings = Node::get_configuration_warnings();

if (frames.is_null()) {
if (!warning.is_empty()) {
warning += "\n\n";
}
warning += TTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite to display frames.");
warnings.push_back(TTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite to display frames."));
}

return warning;
return warnings;
}

void AnimatedSprite2D::_bind_methods() {
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/animated_sprite_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class AnimatedSprite2D : public Node2D {
void set_flip_v(bool p_flip);
bool is_flipped_v() const;

virtual String get_configuration_warning() const override;
TypedArray<String> get_configuration_warnings() const override;
AnimatedSprite2D();
};

Expand Down
23 changes: 9 additions & 14 deletions scene/2d/canvas_modulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void CanvasModulate::_notification(int p_what) {
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}

update_configuration_warning();
update_configuration_warnings();
}
}

Expand All @@ -73,24 +73,19 @@ Color CanvasModulate::get_color() const {
return color;
}

String CanvasModulate::get_configuration_warning() const {
if (!is_visible_in_tree() || !is_inside_tree()) {
return String();
}

String warning = Node2D::get_configuration_warning();
TypedArray<String> CanvasModulate::get_configuration_warnings() const {
TypedArray<String> warnings = Node::get_configuration_warnings();

List<Node *> nodes;
get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes);
if (is_visible_in_tree() && is_inside_tree()) {
List<Node *> nodes;
get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes);

if (nodes.size() > 1) {
if (!warning.is_empty()) {
warning += "\n\n";
if (nodes.size() > 1) {
warnings.push_back(TTR("Only one visible CanvasModulate is allowed per scene (or set of instanced scenes). The first created one will work, while the rest will be ignored."));
}
warning += TTR("Only one visible CanvasModulate is allowed per scene (or set of instanced scenes). The first created one will work, while the rest will be ignored.");
}

return warning;
return warnings;
}

CanvasModulate::CanvasModulate() {
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/canvas_modulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CanvasModulate : public Node2D {
void set_color(const Color &p_color);
Color get_color() const;

String get_configuration_warning() const override;
TypedArray<String> get_configuration_warnings() const override;

CanvasModulate();
~CanvasModulate();
Expand Down
11 changes: 4 additions & 7 deletions scene/2d/collision_object_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,14 @@ void CollisionObject2D::_update_pickable() {
}
}

String CollisionObject2D::get_configuration_warning() const {
String warning = Node2D::get_configuration_warning();
TypedArray<String> CollisionObject2D::get_configuration_warnings() const {
TypedArray<String> warnings = Node::get_configuration_warnings();

if (shapes.is_empty()) {
if (!warning.is_empty()) {
warning += "\n\n";
}
warning += TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape2D or CollisionPolygon2D as a child to define its shape.");
warnings.push_back(TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape2D or CollisionPolygon2D as a child to define its shape."));
}

return warning;
return warnings;
}

void CollisionObject2D::_bind_methods() {
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/collision_object_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CollisionObject2D : public Node2D {
void set_pickable(bool p_enabled);
bool is_pickable() const;

String get_configuration_warning() const override;
TypedArray<String> get_configuration_warnings() const override;

_FORCE_INLINE_ RID get_rid() const { return rid; }

Expand Down
30 changes: 9 additions & 21 deletions scene/2d/collision_polygon_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) {
_update_in_shape_owner();
}
update();
update_configuration_warning();
update_configuration_warnings();
}

Vector<Point2> CollisionPolygon2D::get_polygon() const {
Expand All @@ -219,7 +219,7 @@ void CollisionPolygon2D::set_build_mode(BuildMode p_mode) {
_update_in_shape_owner();
}
update();
update_configuration_warning();
update_configuration_warnings();
}

CollisionPolygon2D::BuildMode CollisionPolygon2D::get_build_mode() const {
Expand All @@ -240,40 +240,28 @@ bool CollisionPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, doubl
}
#endif

String CollisionPolygon2D::get_configuration_warning() const {
String warning = Node2D::get_configuration_warning();
TypedArray<String> CollisionPolygon2D::get_configuration_warnings() const {
TypedArray<String> warnings = Node::get_configuration_warnings();

if (!Object::cast_to<CollisionObject2D>(get_parent())) {
if (!warning.is_empty()) {
warning += "\n\n";
}
warning += TTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape.");
warnings.push_back(TTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape."));
}

int polygon_count = polygon.size();
if (polygon_count == 0) {
if (!warning.is_empty()) {
warning += "\n\n";
}
warning += TTR("An empty CollisionPolygon2D has no effect on collision.");
warnings.push_back(TTR("An empty CollisionPolygon2D has no effect on collision."));
} else {
bool solids = build_mode == BUILD_SOLIDS;
if (solids) {
if (polygon_count < 3) {
if (!warning.is_empty()) {
warning += "\n\n";
}
warning += TTR("Invalid polygon. At least 3 points are needed in 'Solids' build mode.");
warnings.push_back(TTR("Invalid polygon. At least 3 points are needed in 'Solids' build mode."));
}
} else if (polygon_count < 2) {
if (!warning.is_empty()) {
warning += "\n\n";
}
warning += TTR("Invalid polygon. At least 2 points are needed in 'Segments' build mode.");
warnings.push_back(TTR("Invalid polygon. At least 2 points are needed in 'Segments' build mode."));
}
}

return warning;
return warnings;
}

void CollisionPolygon2D::set_disabled(bool p_disabled) {
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/collision_polygon_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CollisionPolygon2D : public Node2D {
void set_polygon(const Vector<Point2> &p_polygon);
Vector<Point2> get_polygon() const;

virtual String get_configuration_warning() const override;
TypedArray<String> get_configuration_warnings() const override;

void set_disabled(bool p_disabled);
bool is_disabled() const;
Expand Down
16 changes: 10 additions & 6 deletions scene/2d/collision_shape_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) {
shape->connect("changed", callable_mp(this, &CollisionShape2D::_shape_changed));
}

update_configuration_warning();
update_configuration_warnings();
}

Ref<Shape2D> CollisionShape2D::get_shape() const {
Expand All @@ -177,19 +177,23 @@ bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double
return shape->_edit_is_selected_on_click(p_point, p_tolerance);
}

String CollisionShape2D::get_configuration_warning() const {
TypedArray<String> CollisionShape2D::get_configuration_warnings() const {
TypedArray<String> warnings = Node::get_configuration_warnings();

if (!Object::cast_to<CollisionObject2D>(get_parent())) {
return TTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape.");
warnings.push_back(TTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape."));
}
if (!shape.is_valid()) {
return TTR("A shape must be provided for CollisionShape2D to function. Please create a shape resource for it!");
warnings.push_back(TTR("A shape must be provided for CollisionShape2D to function. Please create a shape resource for it!"));
}

Ref<ConvexPolygonShape2D> convex = shape;
Ref<ConcavePolygonShape2D> concave = shape;
if (convex.is_valid() || concave.is_valid()) {
return TTR("Polygon-based shapes are not meant be used nor edited directly through the CollisionShape2D node. Please use the CollisionPolygon2D node instead.");
warnings.push_back(TTR("Polygon-based shapes are not meant be used nor edited directly through the CollisionShape2D node. Please use the CollisionPolygon2D node instead."));
}
return String();

return warnings;
}

void CollisionShape2D::set_disabled(bool p_disabled) {
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/collision_shape_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CollisionShape2D : public Node2D {
void set_one_way_collision_margin(real_t p_margin);
real_t get_one_way_collision_margin() const;

virtual String get_configuration_warning() const override;
TypedArray<String> get_configuration_warnings() const override;

CollisionShape2D();
};
Expand Down
9 changes: 3 additions & 6 deletions scene/2d/cpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,15 @@ bool CPUParticles2D::get_fractional_delta() const {
return fractional_delta;
}

String CPUParticles2D::get_configuration_warning() const {
String warnings = Node2D::get_configuration_warning();
TypedArray<String> CPUParticles2D::get_configuration_warnings() const {
TypedArray<String> warnings = Node::get_configuration_warnings();

CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr());

if (get_material().is_null() || (mat && !mat->get_particles_animation())) {
if (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 ||
get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid()) {
if (warnings != String()) {
warnings += "\n";
}
warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.");
warnings.push_back(TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."));
}
}

Expand Down
2 changes: 1 addition & 1 deletion scene/2d/cpu_particles_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class CPUParticles2D : public Node2D {
void set_gravity(const Vector2 &p_gravity);
Vector2 get_gravity() const;

virtual String get_configuration_warning() const override;
TypedArray<String> get_configuration_warnings() const override;

void restart();

Expand Down
20 changes: 7 additions & 13 deletions scene/2d/gpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void GPUParticles2D::set_process_material(const Ref<Material> &p_material) {
}
RS::get_singleton()->particles_set_process_material(particles, material_rid);

update_configuration_warning();
update_configuration_warnings();
}

void GPUParticles2D::set_speed_scale(float p_scale) {
Expand Down Expand Up @@ -216,18 +216,15 @@ bool GPUParticles2D::get_fractional_delta() const {
return fractional_delta;
}

String GPUParticles2D::get_configuration_warning() const {
TypedArray<String> GPUParticles2D::get_configuration_warnings() const {
TypedArray<String> warnings = Node::get_configuration_warnings();

if (RenderingServer::get_singleton()->is_low_end()) {
return TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles2D\" option for this purpose.");
warnings.push_back(TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles2D\" option for this purpose."));
}

String warnings = Node2D::get_configuration_warning();

if (process_material.is_null()) {
if (warnings != String()) {
warnings += "\n";
}
warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted.");
warnings.push_back(TTR("A material to process the particles is not assigned, so no behavior is imprinted."));
} else {
CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr());

Expand All @@ -236,10 +233,7 @@ String GPUParticles2D::get_configuration_warning() const {
if (process &&
(process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) {
if (warnings != String()) {
warnings += "\n";
}
warnings += "- " + TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.");
warnings.push_back(TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/gpu_particles_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class GPUParticles2D : public Node2D {
void set_texture(const Ref<Texture2D> &p_texture);
Ref<Texture2D> get_texture() const;

virtual String get_configuration_warning() const override;
TypedArray<String> get_configuration_warnings() const override;

void restart();
Rect2 capture_rect() const;
Expand Down
Loading