summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/abstract_polygon_2d_editor.cpp7
-rw-r--r--editor/plugins/animation_blend_space_1d_editor.cpp14
-rw-r--r--editor/plugins/animation_blend_space_2d_editor.cpp20
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.cpp21
-rw-r--r--editor/plugins/animation_state_machine_editor.cpp18
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp4
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp32
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h1
-rw-r--r--editor/plugins/cpu_particles_2d_editor_plugin.cpp307
-rw-r--r--editor/plugins/cpu_particles_2d_editor_plugin.h92
-rw-r--r--editor/plugins/editor_preview_plugins.cpp16
-rw-r--r--editor/plugins/gradient_editor_plugin.cpp2
-rw-r--r--editor/plugins/item_list_editor_plugin.cpp1
-rw-r--r--editor/plugins/material_editor_plugin.cpp204
-rw-r--r--editor/plugins/material_editor_plugin.h65
-rw-r--r--editor/plugins/mesh_editor_plugin.cpp77
-rw-r--r--editor/plugins/mesh_editor_plugin.h15
-rw-r--r--editor/plugins/mesh_library_editor_plugin.cpp5
-rw-r--r--editor/plugins/particles_2d_editor_plugin.cpp7
-rw-r--r--editor/plugins/particles_editor_plugin.cpp6
-rw-r--r--editor/plugins/path_editor_plugin.cpp4
-rw-r--r--editor/plugins/path_editor_plugin.h1
-rw-r--r--editor/plugins/script_editor_plugin.cpp25
-rw-r--r--editor/plugins/script_editor_plugin.h2
-rw-r--r--editor/plugins/script_text_editor.cpp112
-rw-r--r--editor/plugins/script_text_editor.h1
-rw-r--r--editor/plugins/shader_editor_plugin.cpp69
-rw-r--r--editor/plugins/skeleton_2d_editor_plugin.cpp4
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp164
-rw-r--r--editor/plugins/spatial_editor_plugin.h8
-rw-r--r--editor/plugins/sprite_editor_plugin.cpp2
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp6
-rw-r--r--editor/plugins/texture_editor_plugin.cpp44
-rw-r--r--editor/plugins/texture_editor_plugin.h16
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp56
-rw-r--r--editor/plugins/texture_region_editor_plugin.h1
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp34
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp636
-rw-r--r--editor/plugins/tile_set_editor_plugin.h29
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp24
40 files changed, 1730 insertions, 422 deletions
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp
index 28f786e99a..4a4e7f25b8 100644
--- a/editor/plugins/abstract_polygon_2d_editor.cpp
+++ b/editor/plugins/abstract_polygon_2d_editor.cpp
@@ -638,6 +638,13 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl
const Color modulate = vertex == active_point ? Color(0.5, 1, 2) : Color(1, 1, 1);
p_overlay->draw_texture(handle, point - handle->get_size() * 0.5, modulate);
+
+ if (vertex == hover_point) {
+ Ref<Font> font = get_font("font", "Label");
+ String num = String::num(vertex.vertex);
+ Size2 num_size = font->get_string_size(num);
+ p_overlay->draw_string(font, point - num_size * 0.5, num, Color(1.0, 1.0, 1.0, 0.5));
+ }
}
}
diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp
index 3029ad978a..2ae39d90de 100644
--- a/editor/plugins/animation_blend_space_1d_editor.cpp
+++ b/editor/plugins/animation_blend_space_1d_editor.cpp
@@ -142,7 +142,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
}
updating = true;
- undo_redo->create_action("Move Node Point");
+ undo_redo->create_action(TTR("Move Node Point"));
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, point);
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
undo_redo->add_do_method(this, "_update_space");
@@ -325,7 +325,7 @@ void AnimationNodeBlendSpace1DEditor::_config_changed(double) {
return;
updating = true;
- undo_redo->create_action("Change BlendSpace1D Limits");
+ undo_redo->create_action(TTR("Change BlendSpace1D Limits"));
undo_redo->add_do_method(blend_space.ptr(), "set_max_space", max_value->get_value());
undo_redo->add_undo_method(blend_space.ptr(), "set_max_space", blend_space->get_max_space());
undo_redo->add_do_method(blend_space.ptr(), "set_min_space", min_value->get_value());
@@ -345,7 +345,7 @@ void AnimationNodeBlendSpace1DEditor::_labels_changed(String) {
return;
updating = true;
- undo_redo->create_action("Change BlendSpace1D Labels", UndoRedo::MERGE_ENDS);
+ undo_redo->create_action(TTR("Change BlendSpace1D Labels"), UndoRedo::MERGE_ENDS);
undo_redo->add_do_method(blend_space.ptr(), "set_value_label", label_value->get_text());
undo_redo->add_undo_method(blend_space.ptr(), "set_value_label", blend_space->get_value_label());
undo_redo->add_do_method(this, "_update_space");
@@ -401,7 +401,7 @@ void AnimationNodeBlendSpace1DEditor::_add_menu_type(int p_index) {
}
updating = true;
- undo_redo->create_action("Add Node Point");
+ undo_redo->create_action(TTR("Add Node Point"));
undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", node, add_point_pos);
undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
undo_redo->add_do_method(this, "_update_space");
@@ -419,7 +419,7 @@ void AnimationNodeBlendSpace1DEditor::_add_animation_type(int p_index) {
anim->set_animation(animations_to_add[p_index]);
updating = true;
- undo_redo->create_action("Add Animation Point");
+ undo_redo->create_action(TTR("Add Animation Point"));
undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", anim, add_point_pos);
undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
undo_redo->add_do_method(this, "_update_space");
@@ -489,7 +489,7 @@ void AnimationNodeBlendSpace1DEditor::_erase_selected() {
if (selected_point != -1) {
updating = true;
- undo_redo->create_action("Remove BlendSpace1D Point");
+ undo_redo->create_action(TTR("Remove BlendSpace1D Point"));
undo_redo->add_do_method(blend_space.ptr(), "remove_blend_point", selected_point);
undo_redo->add_undo_method(blend_space.ptr(), "add_blend_point", blend_space->get_blend_point_node(selected_point), blend_space->get_blend_point_position(selected_point), selected_point);
undo_redo->add_do_method(this, "_update_space");
@@ -507,7 +507,7 @@ void AnimationNodeBlendSpace1DEditor::_edit_point_pos(double) {
return;
updating = true;
- undo_redo->create_action("Move BlendSpace1D Node Point");
+ undo_redo->create_action(TTR("Move BlendSpace1D Node Point"));
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, edit_value->get_value());
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
undo_redo->add_do_method(this, "_update_space");
diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp
index 038e2d0b3e..918f3a2149 100644
--- a/editor/plugins/animation_blend_space_2d_editor.cpp
+++ b/editor/plugins/animation_blend_space_2d_editor.cpp
@@ -200,7 +200,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
}
updating = true;
- undo_redo->create_action("Add Triangle");
+ undo_redo->create_action(TTR("Add Triangle"));
undo_redo->add_do_method(blend_space.ptr(), "add_triangle", making_triangle[0], making_triangle[1], making_triangle[2]);
undo_redo->add_undo_method(blend_space.ptr(), "remove_triangle", blend_space->get_triangle_count());
undo_redo->add_do_method(this, "_update_space");
@@ -225,7 +225,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
}
updating = true;
- undo_redo->create_action("Move Node Point");
+ undo_redo->create_action(TTR("Move Node Point"));
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, point);
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
undo_redo->add_do_method(this, "_update_space");
@@ -333,7 +333,7 @@ void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) {
}
updating = true;
- undo_redo->create_action("Add Node Point");
+ undo_redo->create_action(TTR("Add Node Point"));
undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", node, add_point_pos);
undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
undo_redo->add_do_method(this, "_update_space");
@@ -352,7 +352,7 @@ void AnimationNodeBlendSpace2DEditor::_add_animation_type(int p_index) {
anim->set_animation(animations_to_add[p_index]);
updating = true;
- undo_redo->create_action("Add Animation Point");
+ undo_redo->create_action(TTR("Add Animation Point"));
undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", anim, add_point_pos);
undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
undo_redo->add_do_method(this, "_update_space");
@@ -639,7 +639,7 @@ void AnimationNodeBlendSpace2DEditor::_config_changed(double) {
return;
updating = true;
- undo_redo->create_action("Change BlendSpace2D Limits");
+ undo_redo->create_action(TTR("Change BlendSpace2D Limits"));
undo_redo->add_do_method(blend_space.ptr(), "set_max_space", Vector2(max_x_value->get_value(), max_y_value->get_value()));
undo_redo->add_undo_method(blend_space.ptr(), "set_max_space", blend_space->get_max_space());
undo_redo->add_do_method(blend_space.ptr(), "set_min_space", Vector2(min_x_value->get_value(), min_y_value->get_value()));
@@ -661,7 +661,7 @@ void AnimationNodeBlendSpace2DEditor::_labels_changed(String) {
return;
updating = true;
- undo_redo->create_action("Change BlendSpace2D Labels", UndoRedo::MERGE_ENDS);
+ undo_redo->create_action(TTR("Change BlendSpace2D Labels"), UndoRedo::MERGE_ENDS);
undo_redo->add_do_method(blend_space.ptr(), "set_x_label", label_x->get_text());
undo_redo->add_undo_method(blend_space.ptr(), "set_x_label", blend_space->get_x_label());
undo_redo->add_do_method(blend_space.ptr(), "set_y_label", label_y->get_text());
@@ -677,7 +677,7 @@ void AnimationNodeBlendSpace2DEditor::_erase_selected() {
if (selected_point != -1) {
updating = true;
- undo_redo->create_action("Remove BlendSpace2D Point");
+ undo_redo->create_action(TTR("Remove BlendSpace2D Point"));
undo_redo->add_do_method(blend_space.ptr(), "remove_blend_point", selected_point);
undo_redo->add_undo_method(blend_space.ptr(), "add_blend_point", blend_space->get_blend_point_node(selected_point), blend_space->get_blend_point_position(selected_point), selected_point);
@@ -700,7 +700,7 @@ void AnimationNodeBlendSpace2DEditor::_erase_selected() {
} else if (selected_triangle != -1) {
updating = true;
- undo_redo->create_action("Remove BlendSpace2D Triangle");
+ undo_redo->create_action(TTR("Remove BlendSpace2D Triangle"));
undo_redo->add_do_method(blend_space.ptr(), "remove_triangle", selected_triangle);
undo_redo->add_undo_method(blend_space.ptr(), "add_triangle", blend_space->get_triangle_point(selected_triangle, 0), blend_space->get_triangle_point(selected_triangle, 1), blend_space->get_triangle_point(selected_triangle, 2), selected_triangle);
@@ -737,7 +737,7 @@ void AnimationNodeBlendSpace2DEditor::_edit_point_pos(double) {
if (updating)
return;
updating = true;
- undo_redo->create_action("Move Node Point");
+ undo_redo->create_action(TTR("Move Node Point"));
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, Vector2(edit_x->get_value(), edit_y->get_value()));
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
undo_redo->add_do_method(this, "_update_space");
@@ -814,7 +814,7 @@ void AnimationNodeBlendSpace2DEditor::_removed_from_graph() {
void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() {
- undo_redo->create_action("Toggle Auto Triangles");
+ undo_redo->create_action(TTR("Toggle Auto Triangles"));
undo_redo->add_do_method(blend_space.ptr(), "set_auto_triangles", auto_triangles->is_pressed());
undo_redo->add_undo_method(blend_space.ptr(), "set_auto_triangles", blend_space->get_auto_triangles());
undo_redo->add_do_method(this, "_update_space");
diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp
index e615856195..afe2573898 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp
@@ -91,7 +91,7 @@ void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_propert
AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_tree();
updating = true;
- undo_redo->create_action("Parameter Changed: " + String(p_property), UndoRedo::MERGE_ENDS);
+ undo_redo->create_action(TTR("Parameter Changed") + ": " + String(p_property), UndoRedo::MERGE_ENDS);
undo_redo->add_do_property(tree, p_property, p_value);
undo_redo->add_undo_property(tree, p_property, tree->get(p_property));
undo_redo->add_do_method(this, "_update_graph");
@@ -231,6 +231,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() {
}
pb->set_percent_visible(false);
+ pb->set_custom_minimum_size(Vector2(0, 14) * EDSCALE);
animations[E->get()] = pb;
node->add_child(pb);
@@ -325,7 +326,7 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) {
name = base_name + " " + itos(base);
}
- undo_redo->create_action("Add Node to BlendTree");
+ undo_redo->create_action(TTR("Add Node to BlendTree"));
undo_redo->add_do_method(blend_tree.ptr(), "add_node", name, anode, instance_pos / EDSCALE);
undo_redo->add_undo_method(blend_tree.ptr(), "remove_node", name);
undo_redo->add_do_method(this, "_update_graph");
@@ -336,7 +337,7 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) {
void AnimationNodeBlendTreeEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which) {
updating = true;
- undo_redo->create_action("Node Moved");
+ undo_redo->create_action(TTR("Node Moved"));
undo_redo->add_do_method(blend_tree.ptr(), "set_node_position", p_which, p_to / EDSCALE);
undo_redo->add_undo_method(blend_tree.ptr(), "set_node_position", p_which, p_from / EDSCALE);
undo_redo->add_do_method(this, "_update_graph");
@@ -354,7 +355,7 @@ void AnimationNodeBlendTreeEditor::_connection_request(const String &p_from, int
return;
}
- undo_redo->create_action("Nodes Connected");
+ undo_redo->create_action(TTR("Nodes Connected"));
undo_redo->add_do_method(blend_tree.ptr(), "connect_node", p_to, p_to_index, p_from);
undo_redo->add_undo_method(blend_tree.ptr(), "disconnect_node", p_to, p_to_index);
undo_redo->add_do_method(this, "_update_graph");
@@ -367,7 +368,7 @@ void AnimationNodeBlendTreeEditor::_disconnection_request(const String &p_from,
graph->disconnect_node(p_from, p_from_index, p_to, p_to_index);
updating = true;
- undo_redo->create_action("Nodes Disconnected");
+ undo_redo->create_action(TTR("Nodes Disconnected"));
undo_redo->add_do_method(blend_tree.ptr(), "disconnect_node", p_to, p_to_index);
undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", p_to, p_to_index, p_from);
undo_redo->add_do_method(this, "_update_graph");
@@ -383,7 +384,7 @@ void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options,
Ref<AnimationNodeAnimation> anim = blend_tree->get_node(p_node);
ERR_FAIL_COND(!anim.is_valid());
- undo_redo->create_action("Set Animation");
+ undo_redo->create_action(TTR("Set Animation"));
undo_redo->add_do_method(anim.ptr(), "set_animation", option);
undo_redo->add_undo_method(anim.ptr(), "set_animation", anim->get_animation());
undo_redo->add_do_method(this, "_update_graph");
@@ -393,7 +394,7 @@ void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options,
void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) {
- undo_redo->create_action("Delete Node");
+ undo_redo->create_action(TTR("Delete Node"));
undo_redo->add_do_method(blend_tree.ptr(), "remove_node", p_which);
undo_redo->add_undo_method(blend_tree.ptr(), "add_node", p_which, blend_tree->get_node(p_which), blend_tree.ptr()->get_node_position(p_which));
@@ -434,7 +435,7 @@ void AnimationNodeBlendTreeEditor::_open_in_editor(const String &p_which) {
void AnimationNodeBlendTreeEditor::_filter_toggled() {
updating = true;
- undo_redo->create_action("Toggle filter on/off");
+ undo_redo->create_action(TTR("Toggle Filter On/Off"));
undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_enabled", filter_enabled->is_pressed());
undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_enabled", _filter_edit->is_filter_enabled());
undo_redo->add_do_method(this, "_update_filters", _filter_edit);
@@ -452,7 +453,7 @@ void AnimationNodeBlendTreeEditor::_filter_edited() {
bool filtered = edited->is_checked(0);
updating = true;
- undo_redo->create_action("Change filter");
+ undo_redo->create_action(TTR("Change Filter"));
undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_path", edited_path, filtered);
undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_path", edited_path, _filter_edit->is_path_filtered(edited_path));
undo_redo->add_do_method(this, "_update_filters", _filter_edit);
@@ -769,7 +770,7 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima
String base_path = AnimationTreeEditor::get_singleton()->get_base_path();
updating = true;
- undo_redo->create_action("Node Renamed");
+ undo_redo->create_action(TTR("Node Renamed"));
undo_redo->add_do_method(blend_tree.ptr(), "rename_node", prev_name, name);
undo_redo->add_undo_method(blend_tree.ptr(), "rename_node", name, prev_name);
undo_redo->add_do_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + prev_name, base_path + name);
diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp
index e73c4ebd8a..cb3e5a8129 100644
--- a/editor/plugins/animation_state_machine_editor.cpp
+++ b/editor/plugins/animation_state_machine_editor.cpp
@@ -226,7 +226,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
Ref<AnimationNode> an = state_machine->get_node(selected_node);
updating = true;
- undo_redo->create_action("Move Node");
+ undo_redo->create_action(TTR("Move Node"));
undo_redo->add_do_method(state_machine.ptr(), "set_node_position", selected_node, state_machine->get_node_position(selected_node) + drag_ofs / EDSCALE);
undo_redo->add_undo_method(state_machine.ptr(), "set_node_position", selected_node, state_machine->get_node_position(selected_node));
undo_redo->add_do_method(this, "_update_graph");
@@ -271,7 +271,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
tr->set_switch_mode(AnimationNodeStateMachineTransition::SwitchMode(transition_mode->get_selected()));
updating = true;
- undo_redo->create_action("Add Transition");
+ undo_redo->create_action(TTR("Add Transition"));
undo_redo->add_do_method(state_machine.ptr(), "add_transition", connecting_from, connecting_to_node, tr);
undo_redo->add_undo_method(state_machine.ptr(), "remove_transition", connecting_from, connecting_to_node);
undo_redo->add_do_method(this, "_update_graph");
@@ -463,7 +463,7 @@ void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) {
}
updating = true;
- undo_redo->create_action("Add Node");
+ undo_redo->create_action(TTR("Add Node"));
undo_redo->add_do_method(state_machine.ptr(), "add_node", name, node, add_node_pos);
undo_redo->add_undo_method(state_machine.ptr(), "remove_node", name);
undo_redo->add_do_method(this, "_update_graph");
@@ -490,7 +490,7 @@ void AnimationNodeStateMachineEditor::_add_animation_type(int p_index) {
}
updating = true;
- undo_redo->create_action("Add Node");
+ undo_redo->create_action(TTR("Add Node"));
undo_redo->add_do_method(state_machine.ptr(), "add_node", name, anim, add_node_pos);
undo_redo->add_undo_method(state_machine.ptr(), "remove_node", name);
undo_redo->add_do_method(this, "_update_graph");
@@ -1088,7 +1088,7 @@ void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) {
}
updating = true;
- undo_redo->create_action("Node Renamed");
+ undo_redo->create_action(TTR("Node Renamed"));
undo_redo->add_do_method(state_machine.ptr(), "rename_node", prev_name, name);
undo_redo->add_undo_method(state_machine.ptr(), "rename_node", name, prev_name);
undo_redo->add_do_method(this, "_update_graph");
@@ -1119,7 +1119,7 @@ void AnimationNodeStateMachineEditor::_erase_selected() {
if (selected_node != StringName() && state_machine->has_node(selected_node)) {
updating = true;
- undo_redo->create_action("Node Removed");
+ undo_redo->create_action(TTR("Node Removed"));
undo_redo->add_do_method(state_machine.ptr(), "remove_node", selected_node);
undo_redo->add_undo_method(state_machine.ptr(), "add_node", selected_node, state_machine->get_node(selected_node), state_machine->get_node_position(selected_node));
for (int i = 0; i < state_machine->get_transition_count(); i++) {
@@ -1143,7 +1143,7 @@ void AnimationNodeStateMachineEditor::_erase_selected() {
Ref<AnimationNodeStateMachineTransition> tr = state_machine->get_transition(state_machine->find_transition(selected_transition_from, selected_transition_to));
updating = true;
- undo_redo->create_action("Transition Removed");
+ undo_redo->create_action(TTR("Transition Removed"));
undo_redo->add_do_method(state_machine.ptr(), "remove_transition", selected_transition_from, selected_transition_to);
undo_redo->add_undo_method(state_machine.ptr(), "add_transition", selected_transition_from, selected_transition_to, tr);
undo_redo->add_do_method(this, "_update_graph");
@@ -1169,7 +1169,7 @@ void AnimationNodeStateMachineEditor::_autoplay_selected() {
}
updating = true;
- undo_redo->create_action("Set Start Node (Autoplay)");
+ undo_redo->create_action(TTR("Set Start Node (Autoplay)"));
undo_redo->add_do_method(state_machine.ptr(), "set_start_node", new_start_node);
undo_redo->add_undo_method(state_machine.ptr(), "set_start_node", state_machine->get_start_node());
undo_redo->add_do_method(this, "_update_graph");
@@ -1192,7 +1192,7 @@ void AnimationNodeStateMachineEditor::_end_selected() {
}
updating = true;
- undo_redo->create_action("Set Start Node (Autoplay)");
+ undo_redo->create_action(TTR("Set Start Node (Autoplay)"));
undo_redo->add_do_method(state_machine.ptr(), "set_end_node", new_end_node);
undo_redo->add_undo_method(state_machine.ptr(), "set_end_node", state_machine->get_end_node());
undo_redo->add_do_method(this, "_update_graph");
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index ab3936407b..6d2cdfc583 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -177,6 +177,8 @@ void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const
thumbnail = thumbnail->duplicate();
Point2 overlay_pos = Point2((thumbnail->get_width() - overlay->get_width()) / 2, (thumbnail->get_height() - overlay->get_height()) / 2);
+ // Overlay and thumbnail need the same format for `blend_rect` to work.
+ thumbnail->convert(Image::FORMAT_RGBA8);
thumbnail->lock();
thumbnail->blend_rect(overlay, overlay->get_used_rect(), overlay_pos);
thumbnail->unlock();
@@ -816,7 +818,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons
_image_update(p_code == HTTPClient::RESPONSE_NOT_MODIFIED, true, p_data, p_queue_id);
} else {
- // WARN_PRINTS("Error getting image file from URL: " + image_queue[p_queue_id].image_url);
+ WARN_PRINTS("Error getting image file from URL: " + image_queue[p_queue_id].image_url);
Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target);
if (obj) {
obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("DefaultProjectIcon", "EditorIcons"));
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index ac05b03ed2..11eec528c7 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -2261,6 +2261,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
break;
case DRAG_PAN:
c = CURSOR_DRAG;
+ break;
default:
break;
}
@@ -2597,6 +2598,7 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) {
case DRAG_TOP_LEFT:
case DRAG_BOTTOM_LEFT:
_draw_margin_at_position(control->get_size().width, parent_transform.xform(Vector2((node_pos_in_parent[0] + node_pos_in_parent[2]) / 2, node_pos_in_parent[3])) + Vector2(0, 5), MARGIN_BOTTOM);
+ FALLTHROUGH;
case DRAG_MOVE:
start = Vector2(node_pos_in_parent[0], Math::lerp(node_pos_in_parent[1], node_pos_in_parent[3], ratio));
end = start - Vector2(control->get_margin(MARGIN_LEFT), 0);
@@ -2611,6 +2613,7 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) {
case DRAG_TOP_RIGHT:
case DRAG_BOTTOM_RIGHT:
_draw_margin_at_position(control->get_size().width, parent_transform.xform(Vector2((node_pos_in_parent[0] + node_pos_in_parent[2]) / 2, node_pos_in_parent[3])) + Vector2(0, 5), MARGIN_BOTTOM);
+ FALLTHROUGH;
case DRAG_MOVE:
start = Vector2(node_pos_in_parent[2], Math::lerp(node_pos_in_parent[3], node_pos_in_parent[1], ratio));
end = start - Vector2(control->get_margin(MARGIN_RIGHT), 0);
@@ -2625,6 +2628,7 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) {
case DRAG_TOP_LEFT:
case DRAG_TOP_RIGHT:
_draw_margin_at_position(control->get_size().height, parent_transform.xform(Vector2(node_pos_in_parent[2], (node_pos_in_parent[1] + node_pos_in_parent[3]) / 2)) + Vector2(5, 0), MARGIN_RIGHT);
+ FALLTHROUGH;
case DRAG_MOVE:
start = Vector2(Math::lerp(node_pos_in_parent[0], node_pos_in_parent[2], ratio), node_pos_in_parent[1]);
end = start - Vector2(0, control->get_margin(MARGIN_TOP));
@@ -2639,6 +2643,7 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) {
case DRAG_BOTTOM_LEFT:
case DRAG_BOTTOM_RIGHT:
_draw_margin_at_position(control->get_size().height, parent_transform.xform(Vector2(node_pos_in_parent[2], (node_pos_in_parent[1] + node_pos_in_parent[3]) / 2) + Vector2(5, 0)), MARGIN_RIGHT);
+ FALLTHROUGH;
case DRAG_MOVE:
start = Vector2(Math::lerp(node_pos_in_parent[2], node_pos_in_parent[0], ratio), node_pos_in_parent[3]);
end = start - Vector2(0, control->get_margin(MARGIN_BOTTOM));
@@ -2828,13 +2833,20 @@ void CanvasItemEditor::_draw_selection() {
Point2 bsfrom = transform.xform(drag_from);
Point2 bsto = transform.xform(box_selecting_to);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(bsfrom, bsto - bsfrom), Color(0.7, 0.7, 1.0, 0.3));
+ VisualServer::get_singleton()->canvas_item_add_rect(
+ ci,
+ Rect2(bsfrom, bsto - bsfrom),
+ get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375));
}
- Color rotate_color(0.4, 0.7, 1.0, 0.8);
if (drag_type == DRAG_ROTATE) {
// Draw the line when rotating a node
- viewport->draw_line(transform.xform(drag_rotation_center), transform.xform(drag_to), rotate_color);
+ viewport->draw_line(
+ transform.xform(drag_rotation_center),
+ transform.xform(drag_to),
+ get_color("accent_color", "Editor") * Color(1, 1, 1, 0.6),
+ Math::round(2 * EDSCALE),
+ true);
}
}
@@ -4144,6 +4156,14 @@ void CanvasItemEditor::_popup_callback(int p_op) {
_focus_selection(p_op);
} break;
+ case PREVIEW_CANVAS_SCALE: {
+
+ bool preview = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(PREVIEW_CANVAS_SCALE));
+ preview = !preview;
+ VS::get_singleton()->canvas_set_disable_scale(!preview);
+ view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(PREVIEW_CANVAS_SCALE), preview);
+
+ } break;
case SKELETON_MAKE_BONES: {
Map<Node *, Object *> &selection = editor_selection->get_selection();
@@ -4162,6 +4182,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
if (!skeleton_show_bones)
skeleton_menu->get_popup()->activate_item(skeleton_menu->get_popup()->get_item_index(SKELETON_SHOW_BONES));
}
+ _queue_update_bone_list();
viewport->update();
} break;
@@ -4181,6 +4202,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
if (!skeleton_show_bones)
skeleton_menu->get_popup()->activate_item(skeleton_menu->get_popup()->get_item_index(SKELETON_SHOW_BONES));
}
+ _queue_update_bone_list();
viewport->update();
} break;
@@ -4817,6 +4839,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
p->add_separator();
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION);
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION);
+ p->add_separator();
+ p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_P), PREVIEW_CANVAS_SCALE);
presets_menu = memnew(MenuButton);
presets_menu->set_text(TTR("Layout"));
@@ -4922,7 +4946,6 @@ void CanvasItemEditorPlugin::make_visible(bool p_visible) {
canvas_item_editor->show();
canvas_item_editor->set_physics_process(true);
VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), false);
- canvas_item_editor->viewport->grab_focus();
} else {
@@ -5415,6 +5438,7 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
label_desc->add_constant_override("line_spacing", 0);
label_desc->hide();
editor->get_gui_base()->add_child(label_desc);
+ VS::get_singleton()->canvas_set_disable_scale(true);
}
CanvasItemEditorViewport::~CanvasItemEditorViewport() {
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 7b6563944e..4d8c0282fd 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -171,6 +171,7 @@ private:
ANIM_CLEAR_POSE,
VIEW_CENTER_TO_SELECTION,
VIEW_FRAME_TO_SELECTION,
+ PREVIEW_CANVAS_SCALE,
SKELETON_MAKE_BONES,
SKELETON_CLEAR_BONES,
SKELETON_SHOW_BONES,
diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp
new file mode 100644
index 0000000000..559558cdb8
--- /dev/null
+++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp
@@ -0,0 +1,307 @@
+/*************************************************************************/
+/* cpu_particles_2d_editor_plugin.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "cpu_particles_2d_editor_plugin.h"
+
+#include "canvas_item_editor_plugin.h"
+#include "core/io/image_loader.h"
+#include "scene/2d/cpu_particles_2d.h"
+#include "scene/gui/separator.h"
+#include "scene/resources/particles_material.h"
+
+void CPUParticles2DEditorPlugin::edit(Object *p_object) {
+
+ particles = Object::cast_to<CPUParticles2D>(p_object);
+}
+
+bool CPUParticles2DEditorPlugin::handles(Object *p_object) const {
+
+ return p_object->is_class("CPUParticles2D");
+}
+
+void CPUParticles2DEditorPlugin::make_visible(bool p_visible) {
+
+ if (p_visible) {
+
+ toolbar->show();
+ } else {
+
+ toolbar->hide();
+ }
+}
+
+void CPUParticles2DEditorPlugin::_file_selected(const String &p_file) {
+
+ source_emission_file = p_file;
+ emission_mask->popup_centered_minsize();
+}
+
+void CPUParticles2DEditorPlugin::_menu_callback(int p_idx) {
+
+ switch (p_idx) {
+ case MENU_LOAD_EMISSION_MASK: {
+
+ file->popup_centered_ratio();
+
+ } break;
+ case MENU_CLEAR_EMISSION_MASK: {
+
+ emission_mask->popup_centered_minsize();
+ } break;
+ }
+}
+
+void CPUParticles2DEditorPlugin::_generate_emission_mask() {
+
+ Ref<Image> img;
+ img.instance();
+ Error err = ImageLoader::load_image(source_emission_file, img);
+ ERR_EXPLAIN(TTR("Error loading image:") + " " + source_emission_file);
+ ERR_FAIL_COND(err != OK);
+
+ if (img->is_compressed()) {
+ img->decompress();
+ }
+ img->convert(Image::FORMAT_RGBA8);
+ ERR_FAIL_COND(img->get_format() != Image::FORMAT_RGBA8);
+ Size2i s = Size2(img->get_width(), img->get_height());
+ ERR_FAIL_COND(s.width == 0 || s.height == 0);
+
+ Vector<Point2> valid_positions;
+ Vector<Point2> valid_normals;
+ Vector<uint8_t> valid_colors;
+
+ valid_positions.resize(s.width * s.height);
+
+ EmissionMode emode = (EmissionMode)emission_mask_mode->get_selected();
+
+ if (emode == EMISSION_MODE_BORDER_DIRECTED) {
+ valid_normals.resize(s.width * s.height);
+ }
+
+ bool capture_colors = emission_colors->is_pressed();
+
+ if (capture_colors) {
+ valid_colors.resize(s.width * s.height * 4);
+ }
+
+ int vpc = 0;
+
+ {
+ PoolVector<uint8_t> data = img->get_data();
+ PoolVector<uint8_t>::Read r = data.read();
+
+ for (int i = 0; i < s.width; i++) {
+ for (int j = 0; j < s.height; j++) {
+
+ uint8_t a = r[(j * s.width + i) * 4 + 3];
+
+ if (a > 128) {
+
+ if (emode == EMISSION_MODE_SOLID) {
+
+ if (capture_colors) {
+ valid_colors.write[vpc * 4 + 0] = r[(j * s.width + i) * 4 + 0];
+ valid_colors.write[vpc * 4 + 1] = r[(j * s.width + i) * 4 + 1];
+ valid_colors.write[vpc * 4 + 2] = r[(j * s.width + i) * 4 + 2];
+ valid_colors.write[vpc * 4 + 3] = r[(j * s.width + i) * 4 + 3];
+ }
+ valid_positions.write[vpc++] = Point2(i, j);
+
+ } else {
+
+ bool on_border = false;
+ for (int x = i - 1; x <= i + 1; x++) {
+ for (int y = j - 1; y <= j + 1; y++) {
+
+ if (x < 0 || y < 0 || x >= s.width || y >= s.height || r[(y * s.width + x) * 4 + 3] <= 128) {
+ on_border = true;
+ break;
+ }
+ }
+
+ if (on_border)
+ break;
+ }
+
+ if (on_border) {
+ valid_positions.write[vpc] = Point2(i, j);
+
+ if (emode == EMISSION_MODE_BORDER_DIRECTED) {
+ Vector2 normal;
+ for (int x = i - 2; x <= i + 2; x++) {
+ for (int y = j - 2; y <= j + 2; y++) {
+
+ if (x == i && y == j)
+ continue;
+
+ if (x < 0 || y < 0 || x >= s.width || y >= s.height || r[(y * s.width + x) * 4 + 3] <= 128) {
+ normal += Vector2(x - i, y - j).normalized();
+ }
+ }
+ }
+
+ normal.normalize();
+ valid_normals.write[vpc] = normal;
+ }
+
+ if (capture_colors) {
+ valid_colors.write[vpc * 4 + 0] = r[(j * s.width + i) * 4 + 0];
+ valid_colors.write[vpc * 4 + 1] = r[(j * s.width + i) * 4 + 1];
+ valid_colors.write[vpc * 4 + 2] = r[(j * s.width + i) * 4 + 2];
+ valid_colors.write[vpc * 4 + 3] = r[(j * s.width + i) * 4 + 3];
+ }
+
+ vpc++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ valid_positions.resize(vpc);
+ if (valid_normals.size()) {
+ valid_normals.resize(vpc);
+ }
+
+ ERR_EXPLAIN(TTR("No pixels with transparency > 128 in image..."));
+ ERR_FAIL_COND(valid_positions.size() == 0);
+
+ if (capture_colors) {
+ PoolColorArray pca;
+ pca.resize(vpc);
+ PoolColorArray::Write pcaw = pca.write();
+ for (int i = 0; i < vpc; i += 1) {
+ Color color;
+ color.r = valid_colors[i * 4 + 0] / 255.0f;
+ color.g = valid_colors[i * 4 + 1] / 255.0f;
+ color.b = valid_colors[i * 4 + 2] / 255.0f;
+ color.a = valid_colors[i * 4 + 3] / 255.0f;
+ pcaw[i] = color;
+ }
+ particles->set_emission_colors(pca);
+ }
+
+ if (valid_normals.size()) {
+ particles->set_emission_shape(CPUParticles2D::EMISSION_SHAPE_DIRECTED_POINTS);
+ PoolVector2Array norms;
+ norms.resize(valid_normals.size());
+ PoolVector2Array::Write normsw = norms.write();
+ for (int i = 0; i < valid_normals.size(); i += 1) {
+ normsw[i] = valid_normals[i];
+ }
+ particles->set_emission_normals(norms);
+ } else {
+ particles->set_emission_shape(CPUParticles2D::EMISSION_SHAPE_POINTS);
+ }
+
+ {
+ PoolVector2Array points;
+ points.resize(valid_positions.size());
+ PoolVector2Array::Write pointsw = points.write();
+ for (int i = 0; i < valid_positions.size(); i += 1) {
+ pointsw[i] = valid_positions[i];
+ }
+ particles->set_emission_points(points);
+ }
+}
+
+void CPUParticles2DEditorPlugin::_notification(int p_what) {
+
+ if (p_what == NOTIFICATION_ENTER_TREE) {
+
+ menu->get_popup()->connect("id_pressed", this, "_menu_callback");
+ menu->set_icon(menu->get_popup()->get_icon("Particles2D", "EditorIcons"));
+ file->connect("file_selected", this, "_file_selected");
+ }
+}
+
+void CPUParticles2DEditorPlugin::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("_menu_callback"), &CPUParticles2DEditorPlugin::_menu_callback);
+ ClassDB::bind_method(D_METHOD("_file_selected"), &CPUParticles2DEditorPlugin::_file_selected);
+ ClassDB::bind_method(D_METHOD("_generate_emission_mask"), &CPUParticles2DEditorPlugin::_generate_emission_mask);
+}
+
+CPUParticles2DEditorPlugin::CPUParticles2DEditorPlugin(EditorNode *p_node) {
+
+ particles = NULL;
+ editor = p_node;
+ undo_redo = editor->get_undo_redo();
+
+ toolbar = memnew(HBoxContainer);
+ add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, toolbar);
+ toolbar->hide();
+
+ toolbar->add_child(memnew(VSeparator));
+
+ menu = memnew(MenuButton);
+ menu->get_popup()->add_item(TTR("Load Emission Mask"), MENU_LOAD_EMISSION_MASK);
+ // menu->get_popup()->add_item(TTR("Clear Emission Mask"), MENU_CLEAR_EMISSION_MASK);
+ menu->set_text(TTR("Particles"));
+ toolbar->add_child(menu);
+
+ file = memnew(EditorFileDialog);
+ List<String> ext;
+ ImageLoader::get_recognized_extensions(&ext);
+ for (List<String>::Element *E = ext.front(); E; E = E->next()) {
+ file->add_filter("*." + E->get() + "; " + E->get().to_upper());
+ }
+ file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
+ toolbar->add_child(file);
+
+ epoints = memnew(SpinBox);
+ epoints->set_min(1);
+ epoints->set_max(8192);
+ epoints->set_step(1);
+ epoints->set_value(512);
+ file->get_vbox()->add_margin_child(TTR("Generated Point Count:"), epoints);
+
+ emission_mask = memnew(ConfirmationDialog);
+ emission_mask->set_title(TTR("Load Emission Mask"));
+ VBoxContainer *emvb = memnew(VBoxContainer);
+ emission_mask->add_child(emvb);
+ emission_mask_mode = memnew(OptionButton);
+ emvb->add_margin_child(TTR("Emission Mask"), emission_mask_mode);
+ emission_mask_mode->add_item("Solid Pixels", EMISSION_MODE_SOLID);
+ emission_mask_mode->add_item("Border Pixels", EMISSION_MODE_BORDER);
+ emission_mask_mode->add_item("Directed Border Pixels", EMISSION_MODE_BORDER_DIRECTED);
+ emission_colors = memnew(CheckBox);
+ emission_colors->set_text(TTR("Capture from Pixel"));
+ emvb->add_margin_child(TTR("Emission Colors"), emission_colors);
+
+ toolbar->add_child(emission_mask);
+
+ emission_mask->connect("confirmed", this, "_generate_emission_mask");
+}
+
+CPUParticles2DEditorPlugin::~CPUParticles2DEditorPlugin() {
+}
diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.h b/editor/plugins/cpu_particles_2d_editor_plugin.h
new file mode 100644
index 0000000000..f715abd87b
--- /dev/null
+++ b/editor/plugins/cpu_particles_2d_editor_plugin.h
@@ -0,0 +1,92 @@
+/*************************************************************************/
+/* cpu_particles_2d_editor_plugin.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef CPU_PARTICLES_2D_EDITOR_PLUGIN_H
+#define CPU_PARTICLES_2D_EDITOR_PLUGIN_H
+
+#include "editor/editor_node.h"
+#include "editor/editor_plugin.h"
+#include "scene/2d/collision_polygon_2d.h"
+#include "scene/2d/cpu_particles_2d.h"
+#include "scene/gui/box_container.h"
+#include "scene/gui/file_dialog.h"
+
+class CPUParticles2DEditorPlugin : public EditorPlugin {
+
+ GDCLASS(CPUParticles2DEditorPlugin, EditorPlugin);
+
+ enum {
+ MENU_LOAD_EMISSION_MASK,
+ MENU_CLEAR_EMISSION_MASK
+ };
+
+ enum EmissionMode {
+ EMISSION_MODE_SOLID,
+ EMISSION_MODE_BORDER,
+ EMISSION_MODE_BORDER_DIRECTED
+ };
+
+ CPUParticles2D *particles;
+
+ EditorFileDialog *file;
+ EditorNode *editor;
+
+ HBoxContainer *toolbar;
+ MenuButton *menu;
+
+ SpinBox *epoints;
+
+ ConfirmationDialog *emission_mask;
+ OptionButton *emission_mask_mode;
+ CheckBox *emission_colors;
+
+ String source_emission_file;
+
+ UndoRedo *undo_redo;
+ void _file_selected(const String &p_file);
+ void _menu_callback(int p_idx);
+ void _generate_emission_mask();
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ virtual String get_name() const { return "CPUParticles2D"; }
+ bool has_main_screen() const { return false; }
+ virtual void edit(Object *p_object);
+ virtual bool handles(Object *p_object) const;
+ virtual void make_visible(bool p_visible);
+
+ CPUParticles2DEditorPlugin(EditorNode *p_node);
+ ~CPUParticles2DEditorPlugin();
+};
+
+#endif // CPU_PARTICLES_2D_EDITOR_PLUGIN_H
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index 071a0287e6..58d7968723 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -92,7 +92,12 @@ Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2
if (!tex.is_valid()) {
return Ref<Texture>();
}
+
Ref<Image> atlas = tex->get_data();
+ if (!atlas.is_valid()) {
+ return Ref<Texture>();
+ }
+
img = atlas->get_rect(atex->get_region());
} else if (ltex.is_valid()) {
img = ltex->to_image();
@@ -845,15 +850,16 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, c
font->draw(canvas_item, pos, sampled_text);
- VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
-
preview_done = false;
+ VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
VS::get_singleton()->request_frame_drawn_callback(const_cast<EditorFontPreviewPlugin *>(this), "_preview_done", Variant());
while (!preview_done) {
OS::get_singleton()->delay_usec(10);
}
+ VS::get_singleton()->canvas_item_clear(canvas_item);
+
Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture);
ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>());
@@ -878,7 +884,11 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, c
Ref<Texture> EditorFontPreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
- return generate_from_path(p_from->get_path(), p_size);
+ String path = p_from->get_path();
+ if (!FileAccess::exists(path)) {
+ return Ref<Texture>();
+ }
+ return generate_from_path(path, p_size);
}
EditorFontPreviewPlugin::EditorFontPreviewPlugin() {
diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp
index 62a9ce719b..e85c475ad7 100644
--- a/editor/plugins/gradient_editor_plugin.cpp
+++ b/editor/plugins/gradient_editor_plugin.cpp
@@ -51,7 +51,7 @@ void GradientEditor::_ramp_changed() {
editing = true;
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
- undo_redo->create_action("Gradient Edited");
+ undo_redo->create_action(TTR("Gradient Edited"));
undo_redo->add_do_method(gradient.ptr(), "set_offsets", get_offsets());
undo_redo->add_do_method(gradient.ptr(), "set_colors", get_colors());
undo_redo->add_undo_method(gradient.ptr(), "set_offsets", gradient->get_offsets());
diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp
index db0816064c..b3f3ccf501 100644
--- a/editor/plugins/item_list_editor_plugin.cpp
+++ b/editor/plugins/item_list_editor_plugin.cpp
@@ -353,6 +353,7 @@ void ItemListEditor::_bind_methods() {
ItemListEditor::ItemListEditor() {
selected_idx = -1;
+ item_list = NULL;
toolbar_button = memnew(ToolButton);
toolbar_button->set_text(TTR("Items"));
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp
index ce8cc77802..ebacccb03c 100644
--- a/editor/plugins/material_editor_plugin.cpp
+++ b/editor/plugins/material_editor_plugin.cpp
@@ -32,6 +32,210 @@
#include "scene/resources/particles_material.h"
+void MaterialEditor::_notification(int p_what) {
+
+ if (p_what == NOTIFICATION_PHYSICS_PROCESS) {
+ }
+
+ if (p_what == NOTIFICATION_READY) {
+
+ //get_scene()->connect("node_removed",this,"_node_removed");
+
+ if (first_enter) {
+ //it's in propertyeditor so.. could be moved around
+
+ light_1_switch->set_normal_texture(get_icon("MaterialPreviewLight1", "EditorIcons"));
+ light_1_switch->set_pressed_texture(get_icon("MaterialPreviewLight1Off", "EditorIcons"));
+ light_2_switch->set_normal_texture(get_icon("MaterialPreviewLight2", "EditorIcons"));
+ light_2_switch->set_pressed_texture(get_icon("MaterialPreviewLight2Off", "EditorIcons"));
+
+ sphere_switch->set_normal_texture(get_icon("MaterialPreviewSphereOff", "EditorIcons"));
+ sphere_switch->set_pressed_texture(get_icon("MaterialPreviewSphere", "EditorIcons"));
+ box_switch->set_normal_texture(get_icon("MaterialPreviewCubeOff", "EditorIcons"));
+ box_switch->set_pressed_texture(get_icon("MaterialPreviewCube", "EditorIcons"));
+
+ first_enter = false;
+ }
+ }
+
+ if (p_what == NOTIFICATION_DRAW) {
+
+ Ref<Texture> checkerboard = get_icon("Checkerboard", "EditorIcons");
+ Size2 size = get_size();
+
+ draw_texture_rect(checkerboard, Rect2(Point2(), size), true);
+ }
+}
+
+void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_env) {
+
+ material = p_material;
+ camera->set_environment(p_env);
+ if (!material.is_null()) {
+ sphere_instance->set_material_override(material);
+ box_instance->set_material_override(material);
+ } else {
+
+ hide();
+ }
+}
+
+void MaterialEditor::_button_pressed(Node *p_button) {
+
+ if (p_button == light_1_switch) {
+ light1->set_visible(!light_1_switch->is_pressed());
+ }
+
+ if (p_button == light_2_switch) {
+ light2->set_visible(!light_2_switch->is_pressed());
+ }
+
+ if (p_button == box_switch) {
+ box_instance->show();
+ sphere_instance->hide();
+ box_switch->set_pressed(true);
+ sphere_switch->set_pressed(false);
+ }
+
+ if (p_button == sphere_switch) {
+ box_instance->hide();
+ sphere_instance->show();
+ box_switch->set_pressed(false);
+ sphere_switch->set_pressed(true);
+ }
+}
+
+void MaterialEditor::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("_button_pressed"), &MaterialEditor::_button_pressed);
+}
+
+MaterialEditor::MaterialEditor() {
+
+ vc = memnew(ViewportContainer);
+ vc->set_stretch(true);
+ add_child(vc);
+ vc->set_anchors_and_margins_preset(PRESET_WIDE);
+ viewport = memnew(Viewport);
+ Ref<World> world;
+ world.instance();
+ viewport->set_world(world); //use own world
+ vc->add_child(viewport);
+ viewport->set_disable_input(true);
+ viewport->set_transparent_background(true);
+ viewport->set_msaa(Viewport::MSAA_4X);
+
+ camera = memnew(Camera);
+ camera->set_transform(Transform(Basis(), Vector3(0, 0, 3)));
+ camera->set_perspective(45, 0.1, 10);
+ camera->make_current();
+ viewport->add_child(camera);
+
+ light1 = memnew(DirectionalLight);
+ light1->set_transform(Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0)));
+ viewport->add_child(light1);
+
+ light2 = memnew(DirectionalLight);
+ light2->set_transform(Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1)));
+ light2->set_color(Color(0.7, 0.7, 0.7));
+ viewport->add_child(light2);
+
+ sphere_instance = memnew(MeshInstance);
+ viewport->add_child(sphere_instance);
+
+ box_instance = memnew(MeshInstance);
+ viewport->add_child(box_instance);
+
+ Transform box_xform;
+ box_xform.basis.rotate(Vector3(1, 0, 0), Math::deg2rad(25.0));
+ box_xform.basis = box_xform.basis * Basis().rotated(Vector3(0, 1, 0), Math::deg2rad(-25.0));
+ box_xform.basis.scale(Vector3(0.8, 0.8, 0.8));
+ box_xform.origin.y = 0.2;
+ box_instance->set_transform(box_xform);
+
+ sphere_mesh.instance();
+ sphere_instance->set_mesh(sphere_mesh);
+ box_mesh.instance();
+ box_instance->set_mesh(box_mesh);
+ box_instance->hide();
+
+ set_custom_minimum_size(Size2(1, 150) * EDSCALE);
+
+ HBoxContainer *hb = memnew(HBoxContainer);
+ add_child(hb);
+ hb->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 2);
+
+ VBoxContainer *vb_shape = memnew(VBoxContainer);
+ hb->add_child(vb_shape);
+
+ sphere_switch = memnew(TextureButton);
+ sphere_switch->set_toggle_mode(true);
+ sphere_switch->set_pressed(true);
+ vb_shape->add_child(sphere_switch);
+ sphere_switch->connect("pressed", this, "_button_pressed", varray(sphere_switch));
+
+ box_switch = memnew(TextureButton);
+ box_switch->set_toggle_mode(true);
+ box_switch->set_pressed(false);
+ vb_shape->add_child(box_switch);
+ box_switch->connect("pressed", this, "_button_pressed", varray(box_switch));
+
+ hb->add_spacer();
+
+ VBoxContainer *vb_light = memnew(VBoxContainer);
+ hb->add_child(vb_light);
+
+ light_1_switch = memnew(TextureButton);
+ light_1_switch->set_toggle_mode(true);
+ vb_light->add_child(light_1_switch);
+ light_1_switch->connect("pressed", this, "_button_pressed", varray(light_1_switch));
+
+ light_2_switch = memnew(TextureButton);
+ light_2_switch->set_toggle_mode(true);
+ vb_light->add_child(light_2_switch);
+ light_2_switch->connect("pressed", this, "_button_pressed", varray(light_2_switch));
+
+ first_enter = true;
+}
+
+///////////////////////
+
+bool EditorInspectorPluginMaterial::can_handle(Object *p_object) {
+
+ Material *material = Object::cast_to<Material>(p_object);
+ if (!material)
+ return false;
+
+ return material->get_shader_mode() == Shader::MODE_SPATIAL;
+}
+
+void EditorInspectorPluginMaterial::parse_begin(Object *p_object) {
+
+ Material *material = Object::cast_to<Material>(p_object);
+ if (!material) {
+ return;
+ }
+ Ref<Material> m(material);
+
+ MaterialEditor *editor = memnew(MaterialEditor);
+ editor->edit(m, env);
+ add_custom_control(editor);
+}
+
+EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() {
+ env.instance();
+ Ref<ProceduralSky> proc_sky = memnew(ProceduralSky(true));
+ env->set_sky(proc_sky);
+ env->set_background(Environment::BG_COLOR_SKY);
+}
+
+MaterialEditorPlugin::MaterialEditorPlugin(EditorNode *p_node) {
+
+ Ref<EditorInspectorPluginMaterial> plugin;
+ plugin.instance();
+ add_inspector_plugin(plugin);
+}
+
String SpatialMaterialConversionPlugin::converts_to() const {
return "ShaderMaterial";
diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h
index 39935d3e12..c3f14c27e5 100644
--- a/editor/plugins/material_editor_plugin.h
+++ b/editor/plugins/material_editor_plugin.h
@@ -32,6 +32,71 @@
#define MATERIAL_EDITOR_PLUGIN_H
#include "editor/property_editor.h"
+#include "scene/resources/primitive_meshes.h"
+
+#include "editor/editor_node.h"
+#include "editor/editor_plugin.h"
+#include "scene/3d/camera.h"
+#include "scene/3d/light.h"
+#include "scene/3d/mesh_instance.h"
+#include "scene/resources/material.h"
+
+class MaterialEditor : public Control {
+
+ GDCLASS(MaterialEditor, Control);
+
+ ViewportContainer *vc;
+ Viewport *viewport;
+ MeshInstance *sphere_instance;
+ MeshInstance *box_instance;
+ DirectionalLight *light1;
+ DirectionalLight *light2;
+ Camera *camera;
+
+ Ref<SphereMesh> sphere_mesh;
+ Ref<CubeMesh> box_mesh;
+
+ TextureButton *sphere_switch;
+ TextureButton *box_switch;
+
+ TextureButton *light_1_switch;
+ TextureButton *light_2_switch;
+
+ Ref<Material> material;
+
+ void _button_pressed(Node *p_button);
+ bool first_enter;
+
+protected:
+ void _notification(int p_what);
+
+ static void _bind_methods();
+
+public:
+ void edit(Ref<Material> p_material, const Ref<Environment> &p_env);
+ MaterialEditor();
+};
+
+class EditorInspectorPluginMaterial : public EditorInspectorPlugin {
+ GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin)
+ Ref<Environment> env;
+
+public:
+ virtual bool can_handle(Object *p_object);
+ virtual void parse_begin(Object *p_object);
+
+ EditorInspectorPluginMaterial();
+};
+
+class MaterialEditorPlugin : public EditorPlugin {
+
+ GDCLASS(MaterialEditorPlugin, EditorPlugin);
+
+public:
+ virtual String get_name() const { return "Material"; }
+
+ MaterialEditorPlugin(EditorNode *p_node);
+};
class SpatialMaterialConversionPlugin : public EditorResourceConversionPlugin {
GDCLASS(SpatialMaterialConversionPlugin, EditorResourceConversionPlugin)
diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp
index fcf515e3fc..6203035e25 100644
--- a/editor/plugins/mesh_editor_plugin.cpp
+++ b/editor/plugins/mesh_editor_plugin.cpp
@@ -80,26 +80,21 @@ void MeshEditor::edit(Ref<Mesh> p_mesh) {
mesh = p_mesh;
mesh_instance->set_mesh(mesh);
- if (mesh.is_null()) {
-
- hide();
- } else {
- rot_x = 0;
- rot_y = 0;
- _update_rotation();
-
- AABB aabb = mesh->get_aabb();
- Vector3 ofs = aabb.position + aabb.size * 0.5;
- float m = aabb.get_longest_axis_size();
- if (m != 0) {
- m = 1.0 / m;
- m *= 0.5;
- Transform xform;
- xform.basis.scale(Vector3(m, m, m));
- xform.origin = -xform.basis.xform(ofs); //-ofs*m;
- //xform.origin.z -= aabb.get_longest_axis_size() * 2;
- mesh_instance->set_transform(xform);
- }
+ rot_x = Math::deg2rad(-15.0);
+ rot_y = Math::deg2rad(30.0);
+ _update_rotation();
+
+ AABB aabb = mesh->get_aabb();
+ Vector3 ofs = aabb.position + aabb.size * 0.5;
+ float m = aabb.get_longest_axis_size();
+ if (m != 0) {
+ m = 1.0 / m;
+ m *= 0.5;
+ Transform xform;
+ xform.basis.scale(Vector3(m, m, m));
+ xform.origin = -xform.basis.xform(ofs); //-ofs*m;
+ //xform.origin.z -= aabb.get_longest_axis_size() * 2;
+ mesh_instance->set_transform(xform);
}
}
@@ -128,8 +123,8 @@ MeshEditor::MeshEditor() {
viewport->set_world(world); //use own world
add_child(viewport);
viewport->set_disable_input(true);
+ viewport->set_msaa(Viewport::MSAA_2X);
set_stretch(true);
-
camera = memnew(Camera);
camera->set_transform(Transform(Basis(), Vector3(0, 0, 1.1)));
camera->set_perspective(45, 0.1, 10);
@@ -176,39 +171,29 @@ MeshEditor::MeshEditor() {
rot_y = 0;
}
-void MeshEditorPlugin::edit(Object *p_object) {
-
- Mesh *s = Object::cast_to<Mesh>(p_object);
- if (!s)
- return;
-
- mesh_editor->edit(Ref<Mesh>(s));
-}
+///////////////////////
-bool MeshEditorPlugin::handles(Object *p_object) const {
+bool EditorInspectorPluginMesh::can_handle(Object *p_object) {
- return p_object->is_class("Mesh");
+ return Object::cast_to<Mesh>(p_object) != NULL;
}
-void MeshEditorPlugin::make_visible(bool p_visible) {
+void EditorInspectorPluginMesh::parse_begin(Object *p_object) {
- if (p_visible) {
- mesh_editor->show();
- //mesh_editor->set_process(true);
- } else {
-
- mesh_editor->hide();
- //mesh_editor->set_process(false);
+ Mesh *mesh = Object::cast_to<Mesh>(p_object);
+ if (!mesh) {
+ return;
}
+ Ref<Mesh> m(mesh);
+
+ MeshEditor *editor = memnew(MeshEditor);
+ editor->edit(m);
+ add_custom_control(editor);
}
MeshEditorPlugin::MeshEditorPlugin(EditorNode *p_node) {
- editor = p_node;
- mesh_editor = memnew(MeshEditor);
- add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, mesh_editor);
- mesh_editor->hide();
-}
-
-MeshEditorPlugin::~MeshEditorPlugin() {
+ Ref<EditorInspectorPluginMesh> plugin;
+ plugin.instance();
+ add_inspector_plugin(plugin);
}
diff --git a/editor/plugins/mesh_editor_plugin.h b/editor/plugins/mesh_editor_plugin.h
index 0275f45be9..8ada2dac90 100644
--- a/editor/plugins/mesh_editor_plugin.h
+++ b/editor/plugins/mesh_editor_plugin.h
@@ -72,22 +72,21 @@ public:
MeshEditor();
};
+class EditorInspectorPluginMesh : public EditorInspectorPlugin {
+ GDCLASS(EditorInspectorPluginMesh, EditorInspectorPlugin)
+public:
+ virtual bool can_handle(Object *p_object);
+ virtual void parse_begin(Object *p_object);
+};
+
class MeshEditorPlugin : public EditorPlugin {
GDCLASS(MeshEditorPlugin, EditorPlugin);
- MeshEditor *mesh_editor;
- EditorNode *editor;
-
public:
virtual String get_name() const { return "Mesh"; }
- bool has_main_screen() const { return false; }
- virtual void edit(Object *p_object);
- virtual bool handles(Object *p_object) const;
- virtual void make_visible(bool p_visible);
MeshEditorPlugin(EditorNode *p_node);
- ~MeshEditorPlugin();
};
#endif
diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp
index aedac7b45d..89eb253afe 100644
--- a/editor/plugins/mesh_library_editor_plugin.cpp
+++ b/editor/plugins/mesh_library_editor_plugin.cpp
@@ -127,7 +127,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
continue;
MeshLibrary::ShapeData shape_data;
shape_data.shape = collision;
- shape_data.local_transform = sb->shape_owner_get_transform(E->get());
+ shape_data.local_transform = sb->get_transform() * sb->shape_owner_get_transform(E->get());
collisions.push_back(shape_data);
}
}
@@ -136,17 +136,20 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
p_library->set_item_shapes(id, collisions);
Ref<NavigationMesh> navmesh;
+ Transform navmesh_transform;
for (int j = 0; j < mi->get_child_count(); j++) {
Node *child2 = mi->get_child(j);
if (!Object::cast_to<NavigationMeshInstance>(child2))
continue;
NavigationMeshInstance *sb = Object::cast_to<NavigationMeshInstance>(child2);
navmesh = sb->get_navigation_mesh();
+ navmesh_transform = sb->get_transform();
if (!navmesh.is_null())
break;
}
if (!navmesh.is_null()) {
p_library->set_item_navmesh(id, navmesh);
+ p_library->set_item_navmesh_transform(id, navmesh_transform);
}
}
diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp
index bb7d50a9c1..70d4919e9f 100644
--- a/editor/plugins/particles_2d_editor_plugin.cpp
+++ b/editor/plugins/particles_2d_editor_plugin.cpp
@@ -133,7 +133,10 @@ void Particles2DEditorPlugin::_generate_visibility_rect() {
particles->set_emitting(false);
}
- particles->set_visibility_rect(rect);
+ undo_redo->create_action(TTR("Generate Visibility Rect"));
+ undo_redo->add_do_method(particles, "set_visibility_rect", rect);
+ undo_redo->add_undo_method(particles, "set_visibility_rect", particles->get_visibility_rect());
+ undo_redo->commit_action();
}
void Particles2DEditorPlugin::_generate_emission_mask() {
@@ -405,7 +408,7 @@ Particles2DEditorPlugin::Particles2DEditorPlugin(EditorNode *p_node) {
generate_visibility_rect->connect("confirmed", this, "_generate_visibility_rect");
emission_mask = memnew(ConfirmationDialog);
- emission_mask->set_title(TTR("Generate Visibility Rect"));
+ emission_mask->set_title(TTR("Load Emission Mask"));
VBoxContainer *emvb = memnew(VBoxContainer);
emission_mask->add_child(emvb);
emission_mask_mode = memnew(OptionButton);
diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp
index 95828064ac..0032850535 100644
--- a/editor/plugins/particles_editor_plugin.cpp
+++ b/editor/plugins/particles_editor_plugin.cpp
@@ -353,7 +353,11 @@ void ParticlesEditor::_generate_aabb() {
node->set_emitting(false);
}
- node->set_visibility_aabb(rect);
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Generate Visibility AABB"));
+ ur->add_do_method(node, "set_visibility_aabb", rect);
+ ur->add_undo_method(node, "set_visibility_aabb", node->get_visibility_aabb());
+ ur->commit_action();
}
void ParticlesEditor::edit(Particles *p_particles) {
diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp
index 6efa76ef80..88dc258c5f 100644
--- a/editor/plugins/path_editor_plugin.cpp
+++ b/editor/plugins/path_editor_plugin.cpp
@@ -638,6 +638,10 @@ String PathSpatialGizmoPlugin::get_name() const {
return "Path";
}
+int PathSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
PathSpatialGizmoPlugin::PathSpatialGizmoPlugin() {
Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8));
diff --git a/editor/plugins/path_editor_plugin.h b/editor/plugins/path_editor_plugin.h
index ce3d3799d4..5482d09377 100644
--- a/editor/plugins/path_editor_plugin.h
+++ b/editor/plugins/path_editor_plugin.h
@@ -62,6 +62,7 @@ protected:
public:
String get_name() const;
+ int get_priority() const;
PathSpatialGizmoPlugin();
};
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 9e65d9de10..42aba78e96 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -849,8 +849,7 @@ void ScriptEditor::_file_dialog_action(String p_file) {
}
file->close();
memdelete(file);
-
- // fallthrough to open the file.
+ FALLTHROUGH;
}
case FILE_OPEN: {
@@ -979,6 +978,10 @@ void ScriptEditor::_menu_option(int p_option) {
OS::get_singleton()->shell_open("https://docs.godotengine.org/");
} break;
+ case REQUEST_DOCS: {
+
+ OS::get_singleton()->shell_open("https://github.com/godotengine/godot-docs/issues/new");
+ } break;
case WINDOW_NEXT: {
@@ -1308,6 +1311,7 @@ void ScriptEditor::_notification(int p_what) {
EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
help_search->set_icon(get_icon("HelpSearch", "EditorIcons"));
site_search->set_icon(get_icon("Instance", "EditorIcons"));
+ request_docs->set_icon(get_icon("Issue", "EditorIcons"));
script_forward->set_icon(get_icon("Forward", "EditorIcons"));
script_back->set_icon(get_icon("Back", "EditorIcons"));
@@ -1951,8 +1955,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
if (is_visible_in_tree())
se->ensure_focus();
- if (p_line >= 0)
+ if (p_line > 0) {
se->goto_line(p_line - 1);
+ }
}
return true;
}
@@ -2012,8 +2017,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
_test_script_times_on_disk(p_resource);
_update_modified_scripts_for_external_editor(p_resource);
- if (p_line >= 0)
+ if (p_line > 0) {
se->goto_line(p_line - 1);
+ }
notify_script_changed(p_resource);
_add_recent_script(p_resource->get_path());
@@ -2206,6 +2212,9 @@ void ScriptEditor::_script_split_dragged(float) {
Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
+ if (tab_container->get_child_count() == 0)
+ return Variant();
+
Node *cur_node = tab_container->get_child(tab_container->get_current_tab());
HBoxContainer *drag_preview = memnew(HBoxContainer);
@@ -3074,7 +3083,13 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
site_search->set_text(TTR("Online Docs"));
site_search->connect("pressed", this, "_menu_option", varray(SEARCH_WEBSITE));
menu_hb->add_child(site_search);
- site_search->set_tooltip(TTR("Open Godot online documentation"));
+ site_search->set_tooltip(TTR("Open Godot online documentation."));
+
+ request_docs = memnew(ToolButton);
+ request_docs->set_text(TTR("Request Docs"));
+ request_docs->connect("pressed", this, "_menu_option", varray(REQUEST_DOCS));
+ menu_hb->add_child(request_docs);
+ request_docs->set_tooltip(TTR("Help improve the Godot documentation by giving feedback."));
help_search = memnew(ToolButton);
help_search->set_text(TTR("Search Help"));
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index 11f4589f00..954b014935 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -157,6 +157,7 @@ class ScriptEditor : public PanelContainer {
DEBUG_WITH_EXTERNAL_EDITOR,
SEARCH_HELP,
SEARCH_WEBSITE,
+ REQUEST_DOCS,
HELP_SEARCH_FIND,
HELP_SEARCH_FIND_NEXT,
WINDOW_MOVE_UP,
@@ -200,6 +201,7 @@ class ScriptEditor : public PanelContainer {
Button *help_search;
Button *site_search;
+ Button *request_docs;
EditorHelpSearch *help_search_dialog;
ItemList *script_list;
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index e95b1356bf..9fc42e3862 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -620,7 +620,9 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c
}
ScriptLanguage::LookupResult result;
- if (p_symbol.is_resource_file()) {
+ if (ScriptServer::is_global_class(p_symbol)) {
+ EditorNode::get_singleton()->load_resource(ScriptServer::get_global_class_path(p_symbol));
+ } else if (p_symbol.is_resource_file()) {
List<String> scene_extensions;
ResourceLoader::get_recognized_extensions_for_type("PackedScene", &scene_extensions);
@@ -794,92 +796,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
} break;
case EDIT_TOGGLE_COMMENT: {
- Ref<Script> scr = script;
- if (scr.is_null())
- return;
-
- String delimiter = "#";
- List<String> comment_delimiters;
- scr->get_language()->get_comment_delimiters(&comment_delimiters);
-
- for (List<String>::Element *E = comment_delimiters.front(); E; E = E->next()) {
- String script_delimiter = E->get();
- if (script_delimiter.find(" ") == -1) {
- delimiter = script_delimiter;
- break;
- }
- }
-
- tx->begin_complex_operation();
- if (tx->is_selection_active()) {
- int begin = tx->get_selection_from_line();
- int end = tx->get_selection_to_line();
-
- // End of selection ends on the first column of the last line, ignore it.
- if (tx->get_selection_to_column() == 0)
- end -= 1;
-
- int col_to = tx->get_selection_to_column();
- int cursor_pos = tx->cursor_get_column();
-
- // Check if all lines in the selected block are commented
- bool is_commented = true;
- for (int i = begin; i <= end; i++) {
- if (!tx->get_line(i).begins_with(delimiter)) {
- is_commented = false;
- break;
- }
- }
- for (int i = begin; i <= end; i++) {
- String line_text = tx->get_line(i);
-
- if (line_text.strip_edges().empty()) {
- line_text = delimiter;
- } else {
- if (is_commented) {
- line_text = line_text.substr(delimiter.length(), line_text.length());
- } else {
- line_text = delimiter + line_text;
- }
- }
- tx->set_line(i, line_text);
- }
-
- // Adjust selection & cursor position.
- int offset = is_commented ? -1 : 1;
- int col_from = tx->get_selection_from_column() > 0 ? tx->get_selection_from_column() + offset : 0;
-
- if (is_commented && tx->cursor_get_column() == tx->get_line(tx->cursor_get_line()).length() + 1)
- cursor_pos += 1;
-
- if (tx->get_selection_to_column() != 0 && col_to != tx->get_line(tx->get_selection_to_line()).length() + 1)
- col_to += offset;
-
- if (tx->cursor_get_column() != 0)
- cursor_pos += offset;
-
- tx->select(begin, col_from, tx->get_selection_to_line(), col_to);
- tx->cursor_set_column(cursor_pos);
-
- } else {
- int begin = tx->cursor_get_line();
- String line_text = tx->get_line(begin);
-
- int col = tx->cursor_get_column();
- if (line_text.begins_with(delimiter)) {
- line_text = line_text.substr(delimiter.length(), line_text.length());
- col -= 1;
- } else {
- line_text = delimiter + line_text;
- col += 1;
- }
-
- tx->set_line(begin, line_text);
- tx->cursor_set_column(col);
- }
- tx->end_complex_operation();
- tx->update();
-
+ _edit_option_toggle_inline_comment();
} break;
case EDIT_COMPLETE: {
@@ -993,7 +910,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
tx->set_line_as_breakpoint(line, dobreak);
ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(script->get_path(), line + 1, dobreak);
}
- }
+ } break;
case DEBUG_GOTO_NEXT_BREAKPOINT: {
List<int> bpoints;
@@ -1066,6 +983,25 @@ void ScriptTextEditor::_edit_option(int p_op) {
}
}
+void ScriptTextEditor::_edit_option_toggle_inline_comment() {
+ if (script.is_null())
+ return;
+
+ String delimiter = "#";
+ List<String> comment_delimiters;
+ script->get_language()->get_comment_delimiters(&comment_delimiters);
+
+ for (List<String>::Element *E = comment_delimiters.front(); E; E = E->next()) {
+ String script_delimiter = E->get();
+ if (script_delimiter.find(" ") == -1) {
+ delimiter = script_delimiter;
+ break;
+ }
+ }
+
+ code_editor->toggle_inline_comment(delimiter);
+}
+
void ScriptTextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
highlighters[p_highlighter->get_name()] = p_highlighter;
highlighter_menu->add_radio_check_item(p_highlighter->get_name());
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index f83aadddef..b081a31c18 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -136,6 +136,7 @@ protected:
void _change_syntax_highlighter(int p_idx);
void _edit_option(int p_op);
+ void _edit_option_toggle_inline_comment();
void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition);
void _text_edit_gui_input(const Ref<InputEvent> &ev);
void _color_changed(const Color &p_color);
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index cc2e65cf6d..d39e521113 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -47,12 +47,16 @@ Ref<Shader> ShaderTextEditor::get_edited_shader() const {
}
void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) {
+ if (shader == p_shader) {
+ return;
+ }
shader = p_shader;
_load_theme_settings();
get_text_edit()->set_text(p_shader->get_code());
+ _validate_script();
_line_col_changed();
}
@@ -244,19 +248,19 @@ void ShaderEditor::_menu_option(int p_option) {
} break;
case EDIT_INDENT_LEFT: {
- TextEdit *tx = shader_editor->get_text_edit();
if (shader.is_null())
return;
+ TextEdit *tx = shader_editor->get_text_edit();
tx->indent_left();
} break;
case EDIT_INDENT_RIGHT: {
- TextEdit *tx = shader_editor->get_text_edit();
if (shader.is_null())
return;
+ TextEdit *tx = shader_editor->get_text_edit();
tx->indent_right();
} break;
@@ -268,54 +272,10 @@ void ShaderEditor::_menu_option(int p_option) {
} break;
case EDIT_TOGGLE_COMMENT: {
- TextEdit *tx = shader_editor->get_text_edit();
if (shader.is_null())
return;
- tx->begin_complex_operation();
- if (tx->is_selection_active()) {
- int begin = tx->get_selection_from_line();
- int end = tx->get_selection_to_line();
-
- // End of selection ends on the first column of the last line, ignore it.
- if (tx->get_selection_to_column() == 0)
- end -= 1;
-
- // Check if all lines in the selected block are commented
- bool is_commented = true;
- for (int i = begin; i <= end; i++) {
- if (!tx->get_line(i).begins_with("//")) {
- is_commented = false;
- break;
- }
- }
- for (int i = begin; i <= end; i++) {
- String line_text = tx->get_line(i);
-
- if (line_text.strip_edges().empty()) {
- line_text = "//";
- } else {
- if (is_commented) {
- line_text = line_text.substr(2, line_text.length());
- } else {
- line_text = "//" + line_text;
- }
- }
- tx->set_line(i, line_text);
- }
- } else {
- int begin = tx->cursor_get_line();
- String line_text = tx->get_line(begin);
-
- if (line_text.begins_with("//"))
- line_text = line_text.substr(2, line_text.length());
- else
- line_text = "//" + line_text;
- tx->set_line(begin, line_text);
- }
- tx->end_complex_operation();
- tx->update();
- //tx->deselect();
+ shader_editor->toggle_inline_comment("//");
} break;
case EDIT_COMPLETE: {
@@ -351,8 +311,8 @@ void ShaderEditor::_menu_option(int p_option) {
void ShaderEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- if (is_visible_in_tree())
- shader_editor->get_text_edit()->grab_focus();
+ //if (is_visible_in_tree())
+ // shader_editor->get_text_edit()->grab_focus();
}
}
@@ -414,6 +374,9 @@ void ShaderEditor::edit(const Ref<Shader> &p_shader) {
if (p_shader.is_null() || !p_shader->is_text_shader())
return;
+ if (shader == p_shader)
+ return;
+
shader = p_shader;
shader_editor->set_edited_shader(p_shader);
@@ -437,8 +400,12 @@ void ShaderEditor::save_external_data() {
void ShaderEditor::apply_shaders() {
if (shader.is_valid()) {
- shader->set_code(shader_editor->get_text_edit()->get_text());
- shader->set_edited(true);
+ String shader_code = shader->get_code();
+ String editor_code = shader_editor->get_text_edit()->get_text();
+ if (shader_code != editor_code) {
+ shader->set_code(editor_code);
+ shader->set_edited(true);
+ }
}
}
diff --git a/editor/plugins/skeleton_2d_editor_plugin.cpp b/editor/plugins/skeleton_2d_editor_plugin.cpp
index 619d54b202..ef3e17279c 100644
--- a/editor/plugins/skeleton_2d_editor_plugin.cpp
+++ b/editor/plugins/skeleton_2d_editor_plugin.cpp
@@ -63,7 +63,7 @@ void Skeleton2DEditor::_menu_option(int p_option) {
return;
}
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
- ur->create_action("Create Rest Pose from Bones");
+ ur->create_action(TTR("Create Rest Pose from Bones"));
for (int i = 0; i < node->get_bone_count(); i++) {
Bone2D *bone = node->get_bone(i);
ur->add_do_method(bone, "set_rest", bone->get_transform());
@@ -79,7 +79,7 @@ void Skeleton2DEditor::_menu_option(int p_option) {
return;
}
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
- ur->create_action("Set Rest Pose to Bones");
+ ur->create_action(TTR("Set Rest Pose to Bones"));
for (int i = 0; i < node->get_bone_count(); i++) {
Bone2D *bone = node->get_bone(i);
ur->add_do_method(bone, "set_transform", bone->get_rest());
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index f578d5037d..f48887d342 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -1021,7 +1021,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
_edit.mouse_pos = b->get_position();
- _edit.snap = false;
+ _edit.snap = spatial_editor->is_snap_enabled();
_edit.mode = TRANSFORM_NONE;
//gizmo has priority over everything
@@ -1772,7 +1772,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) {
if (_edit.mode != TRANSFORM_NONE) {
- _edit.snap = true;
+ _edit.snap = !_edit.snap;
}
}
if (ED_IS_SHORTCUT("spatial_editor/bottom_view", p_event)) {
@@ -2108,9 +2108,11 @@ void SpatialEditorViewport::_notification(int p_what) {
set_process(visible);
- if (visible)
+ if (visible) {
_update_camera(0);
-
+ } else {
+ set_freelook_active(false);
+ }
call_deferred("update_transform_gizmo_view");
}
@@ -2380,7 +2382,10 @@ void SpatialEditorViewport::_draw() {
if (cursor.region_select) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin), Color(0.7, 0.7, 1.0, 0.3));
+ VisualServer::get_singleton()->canvas_item_add_rect(
+ ci,
+ Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin),
+ get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375));
}
if (message_time > 0) {
@@ -2394,7 +2399,13 @@ void SpatialEditorViewport::_draw() {
if (_edit.mode == TRANSFORM_ROTATE) {
Point2 center = _point_to_screen(_edit.center);
- VisualServer::get_singleton()->canvas_item_add_line(ci, _edit.mouse_pos, center, Color(0.4, 0.7, 1.0, 0.8));
+ VisualServer::get_singleton()->canvas_item_add_line(
+ ci,
+ _edit.mouse_pos,
+ center,
+ get_color("accent_color", "Editor") * Color(1, 1, 1, 0.6),
+ Math::round(2 * EDSCALE),
+ true);
}
if (previewing) {
@@ -2546,7 +2557,7 @@ void SpatialEditorViewport::_menu_option(int p_option) {
List<Node *> &selection = editor_selection->get_selected_node_list();
- undo_redo->create_action(TTR("Align with view"));
+ undo_redo->create_action(TTR("Align with View"));
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Spatial *sp = Object::cast_to<Spatial>(E->get());
@@ -2999,7 +3010,7 @@ void SpatialEditorViewport::set_state(const Dictionary &p_state) {
previewing = Object::cast_to<Camera>(pv);
previewing->connect("tree_exiting", this, "_preview_exited_scene");
VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), previewing->get_camera()); //replace
- view_menu->hide();
+ view_menu->set_disabled(true);
surface->update();
preview_camera->set_pressed(true);
preview_camera->show();
@@ -4115,10 +4126,10 @@ Dictionary SpatialEditor::get_state() const {
d["zfar"] = get_zfar();
Dictionary gizmos_status;
- for (int i = 0; i < gizmo_plugins.size(); i++) {
- if (!gizmo_plugins[i]->can_be_hidden()) continue;
+ for (int i = 0; i < gizmo_plugins_by_name.size(); i++) {
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) continue;
int state = gizmos_menu->get_item_state(gizmos_menu->get_item_index(i));
- String name = gizmo_plugins[i]->get_name();
+ String name = gizmo_plugins_by_name[i]->get_name();
gizmos_status[name] = state;
}
@@ -4168,9 +4179,13 @@ void SpatialEditor::set_state(const Dictionary &p_state) {
if (d.has("viewports")) {
Array vp = d["viewports"];
- ERR_FAIL_COND(vp.size() > 4);
+ uint32_t vp_size = static_cast<uint32_t>(vp.size());
+ if (vp_size > VIEWPORTS_COUNT) {
+ WARN_PRINT("Ignoring superfluous viewport settings from spatial editor state.")
+ vp_size = VIEWPORTS_COUNT;
+ }
- for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) {
+ for (uint32_t i = 0; i < vp_size; i++) {
viewports[i]->set_state(vp[i]);
}
}
@@ -4203,32 +4218,19 @@ void SpatialEditor::set_state(const Dictionary &p_state) {
List<Variant> keys;
gizmos_status.get_key_list(&keys);
- for (int j = 0; j < gizmo_plugins.size(); ++j) {
- if (!gizmo_plugins[j]->can_be_hidden()) continue;
- int state = EditorSpatialGizmoPlugin::ON_TOP;
+ for (int j = 0; j < gizmo_plugins_by_name.size(); ++j) {
+ if (!gizmo_plugins_by_name[j]->can_be_hidden()) continue;
+ int state = EditorSpatialGizmoPlugin::VISIBLE;
for (int i = 0; i < keys.size(); i++) {
- if (gizmo_plugins.write[j]->get_name() == keys[i]) {
+ if (gizmo_plugins_by_name.write[j]->get_name() == keys[i]) {
state = gizmos_status[keys[i]];
+ break;
}
}
- const int idx = gizmos_menu->get_item_index(j);
-
- gizmos_menu->set_item_multistate(idx, state);
- gizmo_plugins.write[j]->set_state(state);
-
- switch (state) {
- case EditorSpatialGizmoPlugin::VISIBLE:
- gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_visible"));
- break;
- case EditorSpatialGizmoPlugin::ON_TOP:
- gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_xray"));
- break;
- case EditorSpatialGizmoPlugin::HIDDEN:
- gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_hidden"));
- break;
- }
+ gizmo_plugins_by_name.write[j]->set_state(state);
}
+ _update_gizmos_menu();
}
}
@@ -4342,7 +4344,7 @@ void SpatialEditor::_menu_gizmo_toggled(int p_option) {
break;
}
- gizmo_plugins.write[p_option]->set_state(state);
+ gizmo_plugins_by_name.write[p_option]->set_state(state);
update_all_gizmos();
}
@@ -4838,30 +4840,46 @@ void SpatialEditor::_init_indicators() {
_generate_selection_box();
}
-struct _GizmoPluginComparator {
-
- bool operator()(const Ref<EditorSpatialGizmoPlugin> &p_a, const Ref<EditorSpatialGizmoPlugin> &p_b) const {
- return p_a->get_name() < p_b->get_name();
- }
-};
-
void SpatialEditor::_update_gizmos_menu() {
gizmos_menu->clear();
- gizmo_plugins.sort_custom<_GizmoPluginComparator>();
- for (int i = 0; i < gizmo_plugins.size(); ++i) {
- if (!gizmo_plugins[i]->can_be_hidden()) continue;
- String plugin_name = gizmo_plugins[i]->get_name();
- gizmos_menu->add_multistate_item(TTR(plugin_name), 3, EditorSpatialGizmoPlugin::VISIBLE, i);
- gizmos_menu->set_item_icon(gizmos_menu->get_item_index(i), gizmos_menu->get_icon("visibility_visible"));
+ for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) {
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) continue;
+ String plugin_name = gizmo_plugins_by_name[i]->get_name();
+ const int plugin_state = gizmo_plugins_by_name[i]->get_state();
+ gizmos_menu->add_multistate_item(TTR(plugin_name), 3, plugin_state, i);
+ const int idx = gizmos_menu->get_item_index(i);
+ switch (plugin_state) {
+ case EditorSpatialGizmoPlugin::VISIBLE:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_visible"));
+ break;
+ case EditorSpatialGizmoPlugin::ON_TOP:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_xray"));
+ break;
+ case EditorSpatialGizmoPlugin::HIDDEN:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_hidden"));
+ break;
+ }
}
}
void SpatialEditor::_update_gizmos_menu_theme() {
- for (int i = 0; i < gizmo_plugins.size(); ++i) {
- if (!gizmo_plugins[i]->can_be_hidden()) continue;
- gizmos_menu->set_item_icon(gizmos_menu->get_item_index(i), gizmos_menu->get_icon("visibility_visible"));
+ for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) {
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) continue;
+ const int plugin_state = gizmo_plugins_by_name[i]->get_state();
+ const int idx = gizmos_menu->get_item_index(i);
+ switch (plugin_state) {
+ case EditorSpatialGizmoPlugin::VISIBLE:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_visible"));
+ break;
+ case EditorSpatialGizmoPlugin::ON_TOP:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_xray"));
+ break;
+ case EditorSpatialGizmoPlugin::HIDDEN:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_hidden"));
+ break;
+ }
}
}
@@ -5055,7 +5073,7 @@ void SpatialEditor::snap_selected_nodes_to_floor() {
Array keys = snap_data.keys();
if (keys.size()) {
- undo_redo->create_action("Snap Nodes To Floor");
+ undo_redo->create_action(TTR("Snap Nodes To Floor"));
for (int i = 0; i < keys.size(); i++) {
Node *node = keys[i];
@@ -5223,8 +5241,8 @@ void SpatialEditor::_request_gizmo(Object *p_obj) {
Ref<EditorSpatialGizmo> seg;
- for (int i = 0; i < gizmo_plugins.size(); ++i) {
- seg = gizmo_plugins.write[i]->get_gizmo(sp);
+ for (int i = 0; i < gizmo_plugins_by_priority.size(); ++i) {
+ seg = gizmo_plugins_by_priority.write[i]->get_gizmo(sp);
if (seg.is_valid()) {
sp->set_gizmo(seg);
@@ -5749,15 +5767,39 @@ void SpatialEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) {
spatial_editor->snap_cursor_to_plane(p_plane);
}
+struct _GizmoPluginPriorityComparator {
+
+ bool operator()(const Ref<EditorSpatialGizmoPlugin> &p_a, const Ref<EditorSpatialGizmoPlugin> &p_b) const {
+ if (p_a->get_priority() == p_b->get_priority()) {
+ return p_a->get_name() < p_b->get_name();
+ }
+ return p_a->get_priority() > p_b->get_priority();
+ }
+};
+
+struct _GizmoPluginNameComparator {
+
+ bool operator()(const Ref<EditorSpatialGizmoPlugin> &p_a, const Ref<EditorSpatialGizmoPlugin> &p_b) const {
+ return p_a->get_name() < p_b->get_name();
+ }
+};
+
void SpatialEditor::add_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin) {
ERR_FAIL_NULL(p_plugin.ptr());
- gizmo_plugins.push_back(p_plugin);
+
+ gizmo_plugins_by_priority.push_back(p_plugin);
+ gizmo_plugins_by_priority.sort_custom<_GizmoPluginPriorityComparator>();
+
+ gizmo_plugins_by_name.push_back(p_plugin);
+ gizmo_plugins_by_name.sort_custom<_GizmoPluginNameComparator>();
+
_update_gizmos_menu();
SpatialEditor::get_singleton()->update_all_gizmos();
}
void SpatialEditor::remove_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin) {
- gizmo_plugins.erase(p_plugin);
+ gizmo_plugins_by_priority.erase(p_plugin);
+ gizmo_plugins_by_name.erase(p_plugin);
_update_gizmos_menu();
}
@@ -5910,6 +5952,13 @@ String EditorSpatialGizmoPlugin::get_name() const {
return TTR("Nameless gizmo");
}
+int EditorSpatialGizmoPlugin::get_priority() const {
+ if (get_script_instance() && get_script_instance()->has_method("get_priority")) {
+ return get_script_instance()->call("get_priority");
+ }
+ return 0;
+}
+
Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::get_gizmo(Spatial *p_spatial) {
if (get_script_instance() && get_script_instance()->has_method("get_gizmo")) {
@@ -5942,6 +5991,7 @@ void EditorSpatialGizmoPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorSpatialGizmoPlugin::get_material); //, DEFVAL(Ref<EditorSpatialGizmo>()));
BIND_VMETHOD(MethodInfo(Variant::STRING, "get_name"));
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "get_priority"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_be_hidden"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_selectable_when_hidden"));
@@ -6041,6 +6091,10 @@ void EditorSpatialGizmoPlugin::set_state(int p_state) {
}
}
+int EditorSpatialGizmoPlugin::get_state() const {
+ return current_state;
+}
+
void EditorSpatialGizmoPlugin::unregister_gizmo(EditorSpatialGizmo *p_gizmo) {
current_gizmos.erase(p_gizmo);
}
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 364b0085f7..4a9d34a7f7 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -60,6 +60,7 @@ public:
RID instance;
Ref<ArrayMesh> mesh;
+ Ref<Material> material;
RID skeleton;
bool billboard;
bool unscaled;
@@ -103,7 +104,7 @@ protected:
public:
void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false);
- void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID());
+ void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID(), const Ref<Material> &p_material = Ref<Material>());
void add_collision_segments(const Vector<Vector3> &p_lines);
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1);
@@ -638,7 +639,8 @@ private:
static SpatialEditor *singleton;
void _node_removed(Node *p_node);
- Vector<Ref<EditorSpatialGizmoPlugin> > gizmo_plugins;
+ Vector<Ref<EditorSpatialGizmoPlugin> > gizmo_plugins_by_priority;
+ Vector<Ref<EditorSpatialGizmoPlugin> > gizmo_plugins_by_name;
void _register_all_gizmos();
@@ -781,6 +783,7 @@ public:
Ref<SpatialMaterial> get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo = Ref<EditorSpatialGizmo>());
virtual String get_name() const;
+ virtual int get_priority() const;
virtual bool can_be_hidden() const;
virtual bool is_selectable_when_hidden() const;
@@ -793,6 +796,7 @@ public:
Ref<EditorSpatialGizmo> get_gizmo(Spatial *p_spatial);
void set_state(int p_state);
+ int get_state() const;
void unregister_gizmo(EditorSpatialGizmo *p_gizmo);
EditorSpatialGizmoPlugin();
diff --git a/editor/plugins/sprite_editor_plugin.cpp b/editor/plugins/sprite_editor_plugin.cpp
index c1718dd8bf..3854d27567 100644
--- a/editor/plugins/sprite_editor_plugin.cpp
+++ b/editor/plugins/sprite_editor_plugin.cpp
@@ -91,6 +91,8 @@ Vector<Vector2> expand(const Vector<Vector2> &points, const Rect2i &rect, float
Vector<Vector2> outPoints;
ClipperLib::PolyNode *p2 = out.GetFirst();
+ ERR_FAIL_COND_V(!p2, points);
+
while (p2->IsHole()) {
p2 = p2->GetNext();
}
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index 89bb7440fe..5ba2fde763 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -347,9 +347,6 @@ void SpriteFramesEditor::_animation_name_edited() {
for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) {
String current = E->get()->call("get_animation");
- if (current != edited_anim)
- continue;
-
undo_redo->add_do_method(E->get(), "set_animation", name);
undo_redo->add_undo_method(E->get(), "set_animation", edited_anim);
}
@@ -382,9 +379,6 @@ void SpriteFramesEditor::_animation_add() {
for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) {
String current = E->get()->call("get_animation");
- if (frames->has_animation(current))
- continue;
-
undo_redo->add_do_method(E->get(), "set_animation", name);
undo_redo->add_undo_method(E->get(), "set_animation", current);
}
diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp
index 0482ae86f3..0aa4a7662c 100644
--- a/editor/plugins/texture_editor_plugin.cpp
+++ b/editor/plugins/texture_editor_plugin.cpp
@@ -138,39 +138,33 @@ TextureEditor::TextureEditor() {
set_custom_minimum_size(Size2(1, 150));
}
-void TextureEditorPlugin::edit(Object *p_object) {
-
- Texture *s = Object::cast_to<Texture>(p_object);
- if (!s)
- return;
-
- texture_editor->edit(Ref<Texture>(s));
+TextureEditor::~TextureEditor() {
+ if (!texture.is_null()) {
+ texture->remove_change_receptor(this);
+ }
}
+//
+bool EditorInspectorPluginTexture::can_handle(Object *p_object) {
-bool TextureEditorPlugin::handles(Object *p_object) const {
-
- return p_object->is_class("Texture");
+ return Object::cast_to<ImageTexture>(p_object) != NULL || Object::cast_to<AtlasTexture>(p_object) != NULL || Object::cast_to<StreamTexture>(p_object) != NULL || Object::cast_to<LargeTexture>(p_object) != NULL || Object::cast_to<AnimatedTexture>(p_object) != NULL;
}
-void TextureEditorPlugin::make_visible(bool p_visible) {
+void EditorInspectorPluginTexture::parse_begin(Object *p_object) {
- if (p_visible) {
- texture_editor->show();
- //texture_editor->set_process(true);
- } else {
-
- texture_editor->hide();
- //texture_editor->set_process(false);
+ Texture *texture = Object::cast_to<Texture>(p_object);
+ if (!texture) {
+ return;
}
+ Ref<Texture> m(texture);
+
+ TextureEditor *editor = memnew(TextureEditor);
+ editor->edit(m);
+ add_custom_control(editor);
}
TextureEditorPlugin::TextureEditorPlugin(EditorNode *p_node) {
- editor = p_node;
- texture_editor = memnew(TextureEditor);
- add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, texture_editor);
- texture_editor->hide();
-}
-
-TextureEditorPlugin::~TextureEditorPlugin() {
+ Ref<EditorInspectorPluginTexture> plugin;
+ plugin.instance();
+ add_inspector_plugin(plugin);
}
diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h
index 80ff4d6416..bcbda1fbd7 100644
--- a/editor/plugins/texture_editor_plugin.h
+++ b/editor/plugins/texture_editor_plugin.h
@@ -50,24 +50,24 @@ protected:
public:
void edit(Ref<Texture> p_texture);
TextureEditor();
+ ~TextureEditor();
+};
+
+class EditorInspectorPluginTexture : public EditorInspectorPlugin {
+ GDCLASS(EditorInspectorPluginTexture, EditorInspectorPlugin)
+public:
+ virtual bool can_handle(Object *p_object);
+ virtual void parse_begin(Object *p_object);
};
class TextureEditorPlugin : public EditorPlugin {
GDCLASS(TextureEditorPlugin, EditorPlugin);
- TextureEditor *texture_editor;
- EditorNode *editor;
-
public:
virtual String get_name() const { return "Texture"; }
- bool has_main_screen() const { return false; }
- virtual void edit(Object *p_object);
- virtual bool handles(Object *p_object) const;
- virtual void make_visible(bool p_visible);
TextureEditorPlugin(EditorNode *p_node);
- ~TextureEditorPlugin();
};
#endif // TEXTURE_EDITOR_PLUGIN_H
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index 3eeb871380..0a59fc69e3 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -64,7 +64,7 @@ void TextureRegionEditor::_region_draw() {
return;
Transform2D mtx;
- mtx.elements[2] = -draw_ofs;
+ mtx.elements[2] = -draw_ofs * draw_zoom;
mtx.scale_basis(Vector2(draw_zoom, draw_zoom));
VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), mtx);
@@ -128,7 +128,7 @@ void TextureRegionEditor::_region_draw() {
};
for (int i = 0; i < 4; i++) {
int next = (i + 1) % 4;
- edit_draw->draw_line(endpoints[i] - draw_ofs, endpoints[next] - draw_ofs, Color(0.3, 0.7, 1, 1), 2);
+ edit_draw->draw_line(endpoints[i] - draw_ofs * draw_zoom, endpoints[next] - draw_ofs * draw_zoom, Color(0.3, 0.7, 1, 1), 2);
}
}
}
@@ -153,16 +153,16 @@ void TextureRegionEditor::_region_draw() {
Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
ofs *= 1.4144 * (select_handle->get_size().width / 2);
- edit_draw->draw_line(endpoints[i] - draw_ofs, endpoints[next] - draw_ofs, color, 2);
+ edit_draw->draw_line(endpoints[i] - draw_ofs * draw_zoom, endpoints[next] - draw_ofs * draw_zoom, color, 2);
if (snap_mode != SNAP_AUTOSLICE)
- edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs);
+ edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs * draw_zoom);
ofs = (endpoints[next] - endpoints[i]) / 2;
ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2);
if (snap_mode != SNAP_AUTOSLICE)
- edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs);
+ edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs * draw_zoom);
scroll_rect.expand_to(endpoints[i]);
}
@@ -220,7 +220,7 @@ void TextureRegionEditor::_region_draw() {
void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
Transform2D mtx;
- mtx.elements[2] = -draw_ofs;
+ mtx.elements[2] = -draw_ofs * draw_zoom;
mtx.scale_basis(Vector2(draw_zoom, draw_zoom));
Vector2 endpoints[8] = {
@@ -255,10 +255,10 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT);
}
Vector2 pos[4] = {
- mtx.basis_xform(rect.position + Vector2(0, margins[0])) - draw_ofs,
- mtx.basis_xform(rect.position + rect.size - Vector2(0, margins[1])) - draw_ofs,
- mtx.basis_xform(rect.position + Vector2(margins[2], 0)) - draw_ofs,
- mtx.basis_xform(rect.position + rect.size - Vector2(margins[3], 0)) - draw_ofs
+ mtx.basis_xform(rect.position + Vector2(0, margins[0])) - draw_ofs * draw_zoom,
+ mtx.basis_xform(rect.position + rect.size - Vector2(0, margins[1])) - draw_ofs * draw_zoom,
+ mtx.basis_xform(rect.position + Vector2(margins[2], 0)) - draw_ofs * draw_zoom,
+ mtx.basis_xform(rect.position + rect.size - Vector2(margins[3], 0)) - draw_ofs * draw_zoom
};
if (Math::abs(mb->get_position().y - pos[0].y) < 8) {
edited_margin = 0;
@@ -415,9 +415,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
}
}
} else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
- _zoom_in();
+ _zoom_on_position(draw_zoom * ((0.95 + (0.05 * mb->get_factor())) / 0.95), mb->get_position());
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
- _zoom_out();
+ _zoom_on_position(draw_zoom * (1 - (0.05 * mb->get_factor())), mb->get_position());
}
}
@@ -427,7 +427,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
if (mm->get_button_mask() & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
- Vector2 draged(mm->get_relative().x, mm->get_relative().y);
+ Vector2 draged(mm->get_relative().x / draw_zoom, mm->get_relative().y / draw_zoom);
hscroll->set_value(hscroll->get_value() - draged.x);
vscroll->set_value(vscroll->get_value() - draged.y);
@@ -578,25 +578,30 @@ void TextureRegionEditor::_set_snap_sep_y(float p_val) {
edit_draw->update();
}
+void TextureRegionEditor::_zoom_on_position(float p_zoom, Point2 p_position) {
+ if (p_zoom < 0.25 || p_zoom > 8)
+ return;
+
+ float prev_zoom = draw_zoom;
+ draw_zoom = p_zoom;
+ Point2 ofs = p_position;
+ ofs = ofs / prev_zoom - ofs / draw_zoom;
+ draw_ofs.x = Math::round(draw_ofs.x + ofs.x);
+ draw_ofs.y = Math::round(draw_ofs.y + ofs.y);
+
+ edit_draw->update();
+}
+
void TextureRegionEditor::_zoom_in() {
- if (draw_zoom < 8) {
- draw_zoom *= 2;
- edit_draw->update();
- }
+ _zoom_on_position(draw_zoom * 1.5, edit_draw->get_size() / 2.0);
}
void TextureRegionEditor::_zoom_reset() {
- if (draw_zoom == 1)
- return;
- draw_zoom = 1;
- edit_draw->update();
+ _zoom_on_position(1.0, edit_draw->get_size() / 2.0);
}
void TextureRegionEditor::_zoom_out() {
- if (draw_zoom > 0.25) {
- draw_zoom /= 2;
- edit_draw->update();
- }
+ _zoom_on_position(draw_zoom / 1.5, edit_draw->get_size() / 2.0);
}
void TextureRegionEditor::apply_rect(const Rect2 &p_rect) {
@@ -743,6 +748,7 @@ void TextureRegionEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_snap_step_y"), &TextureRegionEditor::_set_snap_step_y);
ClassDB::bind_method(D_METHOD("_set_snap_sep_x"), &TextureRegionEditor::_set_snap_sep_x);
ClassDB::bind_method(D_METHOD("_set_snap_sep_y"), &TextureRegionEditor::_set_snap_sep_y);
+ ClassDB::bind_method(D_METHOD("_zoom_on_position"), &TextureRegionEditor::_zoom_on_position);
ClassDB::bind_method(D_METHOD("_zoom_in"), &TextureRegionEditor::_zoom_in);
ClassDB::bind_method(D_METHOD("_zoom_reset"), &TextureRegionEditor::_zoom_reset);
ClassDB::bind_method(D_METHOD("_zoom_out"), &TextureRegionEditor::_zoom_out);
diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h
index 19eaef9bc3..a49e0fb96c 100644
--- a/editor/plugins/texture_region_editor_plugin.h
+++ b/editor/plugins/texture_region_editor_plugin.h
@@ -110,6 +110,7 @@ class TextureRegionEditor : public VBoxContainer {
void _set_snap_step_y(float p_val);
void _set_snap_sep_x(float p_val);
void _set_snap_sep_y(float p_val);
+ void _zoom_on_position(float p_zoom, Point2 p_position = Point2());
void _zoom_in();
void _zoom_reset();
void _zoom_out();
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index 3670c78f1f..8a18af7ae8 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -299,7 +299,11 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p
}
}
- node->set_cell(p_pos.x, p_pos.y, p_value, p_flip_h, p_flip_v, p_transpose, p_autotile_coord);
+ Variant v_pos_x = p_pos.x, v_pos_y = p_pos.y, v_tile = p_value, v_flip_h = p_flip_h, v_flip_v = p_flip_v, v_transpose = p_transpose, v_autotile_coord = Vector2(p_autotile_coord.x, p_autotile_coord.y);
+ const Variant *args[7] = { &v_pos_x, &v_pos_y, &v_tile, &v_flip_h, &v_flip_v, &v_transpose, &v_autotile_coord };
+ Variant::CallError ce;
+ node->call("set_cell", args, 7, ce);
+
if (manual_autotile || (p_value != -1 && node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE)) {
if (current != -1) {
node->set_cell_autotile_coord(p_pos.x, p_pos.y, position);
@@ -1157,7 +1161,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (points.size() == 0)
return false;
- undo_redo->create_action("Bucket Fill");
+ undo_redo->create_action(TTR("Bucket Fill"));
undo_redo->add_do_method(this, "_erase_points", points);
undo_redo->add_undo_method(this, "_fill_points", points, pop);
@@ -1434,9 +1438,9 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
aabb.expand_to(node->world_to_map(xform_inv.xform(screen_size)));
Rect2i si = aabb.grow(1.0);
- if (node->get_half_offset() != TileMap::HALF_OFFSET_X) {
+ if (node->get_half_offset() != TileMap::HALF_OFFSET_X && node->get_half_offset() != TileMap::HALF_OFFSET_NEGATIVE_X) {
- int max_lines = 2000; //avoid crash if size too smal
+ int max_lines = 2000; //avoid crash if size too small
for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) {
@@ -1450,7 +1454,7 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
}
} else {
- int max_lines = 10000; //avoid crash if size too smal
+ int max_lines = 10000; //avoid crash if size too small
for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) {
@@ -1458,23 +1462,26 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
Vector2 ofs;
if (ABS(j) & 1) {
- ofs = cell_xf[0] * 0.5;
+ ofs = cell_xf[0] * (node->get_half_offset() == TileMap::HALF_OFFSET_X ? 0.5 : -0.5);
}
Vector2 from = xform.xform(node->map_to_world(Vector2(i, j), true) + ofs);
Vector2 to = xform.xform(node->map_to_world(Vector2(i, j + 1), true) + ofs);
+
Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2);
p_overlay->draw_line(from, to, col, 1);
- if (max_lines-- == 0)
+ if (--max_lines == 0)
break;
}
+ if (max_lines == 0)
+ break;
}
}
int max_lines = 10000; //avoid crash if size too smal
- if (node->get_half_offset() != TileMap::HALF_OFFSET_Y) {
+ if (node->get_half_offset() != TileMap::HALF_OFFSET_Y && node->get_half_offset() != TileMap::HALF_OFFSET_NEGATIVE_Y) {
for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) {
@@ -1495,17 +1502,20 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
Vector2 ofs;
if (ABS(j) & 1) {
- ofs = cell_xf[1] * 0.5;
+ ofs = cell_xf[1] * (node->get_half_offset() == TileMap::HALF_OFFSET_Y ? 0.5 : -0.5);
}
Vector2 from = xform.xform(node->map_to_world(Vector2(j, i), true) + ofs);
Vector2 to = xform.xform(node->map_to_world(Vector2(j + 1, i), true) + ofs);
+
Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2);
p_overlay->draw_line(from, to, col, 1);
- if (max_lines-- == 0)
+ if (--max_lines == 0)
break;
}
+ if (max_lines == 0)
+ break;
}
}
}
@@ -1533,8 +1543,12 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
for (int i = 0; i < 4; i++) {
if (node->get_half_offset() == TileMap::HALF_OFFSET_X && ABS(over_tile.y) & 1)
endpoints[i] += cell_xf[0] * 0.5;
+ if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_X && ABS(over_tile.y) & 1)
+ endpoints[i] += cell_xf[0] * -0.5;
if (node->get_half_offset() == TileMap::HALF_OFFSET_Y && ABS(over_tile.x) & 1)
endpoints[i] += cell_xf[1] * 0.5;
+ if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_Y && ABS(over_tile.x) & 1)
+ endpoints[i] += cell_xf[1] * -0.5;
endpoints[i] = xform.xform(endpoints[i]);
}
Color col;
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index 36fe1af33f..8fc080c819 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -201,11 +201,13 @@ void TileSetEditor::_bind_methods() {
ClassDB::bind_method("_zoom_out", &TileSetEditor::_zoom_out);
ClassDB::bind_method("_zoom_reset", &TileSetEditor::_zoom_reset);
ClassDB::bind_method("_select_edited_shape_coord", &TileSetEditor::_select_edited_shape_coord);
+ ClassDB::bind_method("_sort_tiles", &TileSetEditor::_sort_tiles);
ClassDB::bind_method("edit", &TileSetEditor::edit);
ClassDB::bind_method("add_texture", &TileSetEditor::add_texture);
ClassDB::bind_method("remove_texture", &TileSetEditor::remove_texture);
ClassDB::bind_method("update_texture_list_icon", &TileSetEditor::update_texture_list_icon);
+ ClassDB::bind_method("update_workspace_minsize", &TileSetEditor::update_workspace_minsize);
}
void TileSetEditor::_notification(int p_what) {
@@ -233,6 +235,8 @@ void TileSetEditor::_notification(int p_what) {
tools[BITMASK_CLEAR]->set_icon(get_icon("Clear", "EditorIcons"));
tools[SHAPE_NEW_POLYGON]->set_icon(get_icon("CollisionPolygon2D", "EditorIcons"));
tools[SHAPE_NEW_RECTANGLE]->set_icon(get_icon("CollisionShape2D", "EditorIcons"));
+ tools[SELECT_PREVIOUS]->set_icon(get_icon("ArrowLeft", "EditorIcons"));
+ tools[SELECT_NEXT]->set_icon(get_icon("ArrowRight", "EditorIcons"));
tools[SHAPE_DELETE]->set_icon(get_icon("Remove", "EditorIcons"));
tools[SHAPE_KEEP_INSIDE_TILE]->set_icon(get_icon("Snap", "EditorIcons"));
tools[TOOL_GRID_SNAP]->set_icon(get_icon("SnapGrid", "EditorIcons"));
@@ -240,6 +244,7 @@ void TileSetEditor::_notification(int p_what) {
tools[ZOOM_1]->set_icon(get_icon("ZoomReset", "EditorIcons"));
tools[ZOOM_IN]->set_icon(get_icon("ZoomMore", "EditorIcons"));
tools[VISIBLE_INFO]->set_icon(get_icon("InformationSign", "EditorIcons"));
+ _update_toggle_shape_button();
tool_editmode[EDITMODE_REGION]->set_icon(get_icon("RegionEdit", "EditorIcons"));
tool_editmode[EDITMODE_COLLISION]->set_icon(get_icon("StaticBody2D", "EditorIcons"));
@@ -323,11 +328,29 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) {
tool_workspacemode[i]->connect("pressed", this, "_on_workspace_mode_changed", varray(i));
tool_hb->add_child(tool_workspacemode[i]);
}
+
Control *spacer = memnew(Control);
spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
tool_hb->add_child(spacer);
tool_hb->move_child(spacer, WORKSPACE_CREATE_SINGLE);
+ tools[SELECT_NEXT] = memnew(ToolButton);
+ tool_hb->add_child(tools[SELECT_NEXT]);
+ tool_hb->move_child(tools[SELECT_NEXT], WORKSPACE_CREATE_SINGLE);
+ tools[SELECT_NEXT]->set_shortcut(ED_SHORTCUT("tileset_editor/next_shape", TTR("Next Coordinate"), KEY_PAGEDOWN));
+ tools[SELECT_NEXT]->connect("pressed", this, "_on_tool_clicked", varray(SELECT_NEXT));
+ tools[SELECT_NEXT]->set_tooltip(TTR("Select the next shape, subtile, or Tile."));
+ tools[SELECT_PREVIOUS] = memnew(ToolButton);
+ tool_hb->add_child(tools[SELECT_PREVIOUS]);
+ tool_hb->move_child(tools[SELECT_PREVIOUS], WORKSPACE_CREATE_SINGLE);
+ tools[SELECT_PREVIOUS]->set_shortcut(ED_SHORTCUT("tileset_editor/previous_shape", TTR("Previous Coordinate"), KEY_PAGEUP));
+ tools[SELECT_PREVIOUS]->set_tooltip(TTR("Select the previous shape, subtile, or Tile."));
+ tools[SELECT_PREVIOUS]->connect("pressed", this, "_on_tool_clicked", varray(SELECT_PREVIOUS));
+
+ VSeparator *separator_shape_selection = memnew(VSeparator);
+ tool_hb->add_child(separator_shape_selection);
+ tool_hb->move_child(separator_shape_selection, WORKSPACE_CREATE_SINGLE);
+
tool_workspacemode[WORKSPACE_EDIT]->set_pressed(true);
workspace_mode = WORKSPACE_EDIT;
@@ -390,6 +413,12 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) {
tools[SHAPE_NEW_POLYGON]->set_button_group(tg);
tools[SHAPE_NEW_POLYGON]->set_tooltip(TTR("Create a new polygon."));
+ separator_shape_toggle = memnew(VSeparator);
+ toolbar->add_child(separator_shape_toggle);
+ tools[SHAPE_TOGGLE_TYPE] = memnew(ToolButton);
+ tools[SHAPE_TOGGLE_TYPE]->connect("pressed", this, "_on_tool_clicked", varray(SHAPE_TOGGLE_TYPE));
+ toolbar->add_child(tools[SHAPE_TOGGLE_TYPE]);
+
separator_delete = memnew(VSeparator);
toolbar->add_child(separator_delete);
tools[SHAPE_DELETE] = memnew(ToolButton);
@@ -590,16 +619,15 @@ void TileSetEditor::_on_texture_list_selected(int p_index) {
if (get_current_texture().is_valid()) {
current_item_index = p_index;
preview->set_texture(get_current_texture());
- workspace->set_custom_minimum_size(get_current_texture()->get_size() + WORKSPACE_MARGIN * 2);
- workspace_container->set_custom_minimum_size(get_current_texture()->get_size() + WORKSPACE_MARGIN * 2);
- workspace_overlay->set_custom_minimum_size(get_current_texture()->get_size() + WORKSPACE_MARGIN * 2);
update_workspace_tile_mode();
+ update_workspace_minsize();
} else {
current_item_index = -1;
preview->set_texture(NULL);
workspace->set_custom_minimum_size(Size2i());
update_workspace_tile_mode();
}
+
set_current_tile(-1);
workspace->update();
}
@@ -744,6 +772,7 @@ void TileSetEditor::_on_edit_mode_changed(int p_edit_mode) {
} break;
default: {}
}
+ _update_toggle_shape_button();
workspace->update();
}
@@ -1082,7 +1111,23 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
undo_redo->create_action(TTR("Set Tile Region"));
undo_redo->add_do_method(tileset.ptr(), "tile_set_region", get_current_tile(), edited_region);
undo_redo->add_undo_method(tileset.ptr(), "tile_set_region", get_current_tile(), tileset->tile_get_region(get_current_tile()));
+
+ Size2 tile_workspace_size = edited_region.position + edited_region.size + WORKSPACE_MARGIN * 2;
+ Size2 workspace_minsize = workspace->get_custom_minimum_size();
+ if (tile_workspace_size.x > workspace_minsize.x && tile_workspace_size.y > workspace_minsize.y) {
+ undo_redo->add_do_method(workspace, "set_custom_minimum_size", tile_workspace_size);
+ undo_redo->add_undo_method(workspace, "set_custom_minimum_size", workspace_minsize);
+ undo_redo->add_do_method(workspace_container, "set_custom_minimum_size", tile_workspace_size);
+ undo_redo->add_undo_method(workspace_container, "set_custom_minimum_size", workspace_minsize);
+ undo_redo->add_do_method(workspace_overlay, "set_custom_minimum_size", tile_workspace_size);
+ undo_redo->add_undo_method(workspace_overlay, "set_custom_minimum_size", workspace_minsize);
+ } else if (workspace_minsize.x > get_current_texture()->get_size().x + WORKSPACE_MARGIN.x * 2 || workspace_minsize.y > get_current_texture()->get_size().y + WORKSPACE_MARGIN.y * 2) {
+ undo_redo->add_do_method(this, "update_workspace_minsize");
+ undo_redo->add_undo_method(this, "update_workspace_minsize");
+ }
+
edited_region = Rect2();
+
undo_redo->add_do_method(workspace, "update");
undo_redo->add_undo_method(workspace, "update");
undo_redo->add_do_method(workspace_overlay, "update");
@@ -1106,6 +1151,19 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
tool_workspacemode[WORKSPACE_EDIT]->set_pressed(true);
tool_editmode[EDITMODE_COLLISION]->set_pressed(true);
edit_mode = EDITMODE_COLLISION;
+
+ Size2 tile_workspace_size = edited_region.position + edited_region.size + WORKSPACE_MARGIN * 2;
+ Size2 workspace_minsize = workspace->get_custom_minimum_size();
+ if (tile_workspace_size.x > workspace_minsize.x || tile_workspace_size.y > workspace_minsize.y) {
+ Size2 new_workspace_minsize = Size2(MAX(tile_workspace_size.x, workspace_minsize.x), MAX(tile_workspace_size.y, workspace_minsize.y));
+ undo_redo->add_do_method(workspace, "set_custom_minimum_size", new_workspace_minsize);
+ undo_redo->add_undo_method(workspace, "set_custom_minimum_size", workspace_minsize);
+ undo_redo->add_do_method(workspace_container, "set_custom_minimum_size", new_workspace_minsize);
+ undo_redo->add_undo_method(workspace_container, "set_custom_minimum_size", workspace_minsize);
+ undo_redo->add_do_method(workspace_overlay, "set_custom_minimum_size", new_workspace_minsize);
+ undo_redo->add_undo_method(workspace_overlay, "set_custom_minimum_size", workspace_minsize);
+ }
+
edited_region = Rect2();
undo_redo->add_do_method(workspace, "update");
@@ -1346,8 +1404,7 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
undo_redo->create_action(TTR("Edit Collision Polygon"));
- undo_redo->add_do_method(edited_collision_shape.ptr(), "set_points", points);
- undo_redo->add_undo_method(edited_collision_shape.ptr(), "set_points", edited_collision_shape->get_points());
+ _set_edited_shape_points(points);
undo_redo->add_do_method(this, "_select_edited_shape_coord");
undo_redo->add_undo_method(this, "_select_edited_shape_coord");
undo_redo->commit_action();
@@ -1425,6 +1482,7 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
workspace->update();
} else {
creating_shape = true;
+ _set_edited_collision_shape(Ref<ConvexPolygonShape2D>());
current_shape.resize(0);
current_shape.push_back(snap_point(pos));
workspace->update();
@@ -1444,6 +1502,7 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
} else if (tools[SHAPE_NEW_RECTANGLE]->is_pressed()) {
if (mb.is_valid()) {
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+ _set_edited_collision_shape(Ref<ConvexPolygonShape2D>());
current_shape.resize(0);
current_shape.push_back(snap_point(shape_anchor));
current_shape.push_back(snap_point(shape_anchor + Vector2(current_tile_region.size.x, 0)));
@@ -1488,6 +1547,49 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
undo_redo->add_do_method(workspace, "update");
undo_redo->add_undo_method(workspace, "update");
undo_redo->commit_action();
+ } else if (p_tool == SHAPE_TOGGLE_TYPE) {
+ if (edited_collision_shape.is_valid()) {
+ Ref<ConvexPolygonShape2D> convex = edited_collision_shape;
+ Ref<ConcavePolygonShape2D> concave = edited_collision_shape;
+ Ref<Shape2D> previous_shape = edited_collision_shape;
+ Array sd = tileset->call("tile_get_shapes", get_current_tile());
+
+ if (convex.is_valid()) {
+ // Make concave
+ undo_redo->create_action(TTR("Make Polygon Concave"));
+ Ref<ConcavePolygonShape2D> _concave = memnew(ConcavePolygonShape2D);
+ edited_collision_shape = _concave;
+ _set_edited_shape_points(_get_collision_shape_points(convex));
+ } else if (concave.is_valid()) {
+ // Make convex
+ undo_redo->create_action(TTR("Make Polygon Convex"));
+ Ref<ConvexPolygonShape2D> _convex = memnew(ConvexPolygonShape2D);
+ edited_collision_shape = _convex;
+ _set_edited_shape_points(_get_collision_shape_points(concave));
+ } else {
+ // Shoudn't haphen
+ }
+ for (int i = 0; i < sd.size(); i++) {
+ if (sd[i].get("shape") == previous_shape) {
+ undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.duplicate());
+ sd.remove(i);
+ sd.insert(i, edited_collision_shape);
+ undo_redo->add_do_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd);
+ undo_redo->add_do_method(this, "_select_edited_shape_coord");
+ undo_redo->add_undo_method(this, "_select_edited_shape_coord");
+ undo_redo->commit_action();
+ break;
+ }
+ }
+ _update_toggle_shape_button();
+ workspace->update();
+ workspace_container->update();
+ helper->_change_notify("");
+ }
+ } else if (p_tool == SELECT_NEXT) {
+ _select_next_shape();
+ } else if (p_tool == SELECT_PREVIOUS) {
+ _select_previous_shape();
} else if (p_tool == SHAPE_DELETE) {
if (creating_shape) {
creating_shape = false;
@@ -1502,6 +1604,14 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
undo_redo->add_do_method(tileset.ptr(), "remove_tile", t_id);
_undo_tile_removal(t_id);
undo_redo->add_do_method(this, "_validate_current_tile_id");
+
+ Rect2 tile_region = tileset->tile_get_region(get_current_tile());
+ Size2 tile_workspace_size = tile_region.position + tile_region.size;
+ if (tile_workspace_size.x > get_current_texture()->get_size().x || tile_workspace_size.y > get_current_texture()->get_size().y) {
+ undo_redo->add_do_method(this, "update_workspace_minsize");
+ undo_redo->add_undo_method(this, "update_workspace_minsize");
+ }
+
undo_redo->add_do_method(workspace, "update");
undo_redo->add_undo_method(workspace, "update");
undo_redo->add_do_method(workspace_overlay, "update");
@@ -1602,6 +1712,378 @@ void TileSetEditor::_on_grid_snap_toggled(bool p_val) {
workspace->update();
}
+Vector<Vector2> TileSetEditor::_get_collision_shape_points(const Ref<Shape2D> &p_shape) {
+ Ref<ConvexPolygonShape2D> convex = p_shape;
+ Ref<ConcavePolygonShape2D> concave = p_shape;
+ if (convex.is_valid()) {
+ return convex->get_points();
+ } else if (concave.is_valid()) {
+ Vector<Vector2> points;
+ for (int i = 0; i < concave->get_segments().size(); i += 2) {
+ points.push_back(concave->get_segments()[i]);
+ }
+ return points;
+ } else {
+ return Vector<Vector2>();
+ }
+}
+
+Vector<Vector2> TileSetEditor::_get_edited_shape_points() {
+ return _get_collision_shape_points(edited_collision_shape);
+}
+
+void TileSetEditor::_set_edited_shape_points(const Vector<Vector2> points) {
+ Ref<ConvexPolygonShape2D> convex = edited_collision_shape;
+ Ref<ConcavePolygonShape2D> concave = edited_collision_shape;
+ if (convex.is_valid()) {
+ undo_redo->add_do_method(convex.ptr(), "set_points", points);
+ undo_redo->add_undo_method(convex.ptr(), "set_points", _get_edited_shape_points());
+ } else if (concave.is_valid()) {
+ PoolVector2Array segments;
+ for (int i = 0; i < points.size() - 1; i++) {
+ segments.push_back(points[i]);
+ segments.push_back(points[i + 1]);
+ }
+ segments.push_back(points[points.size() - 1]);
+ segments.push_back(points[0]);
+ concave->set_segments(segments);
+ undo_redo->add_do_method(concave.ptr(), "set_segments", segments);
+ undo_redo->add_undo_method(concave.ptr(), "set_segments", concave->get_segments());
+ } else {
+ // Invalid shape
+ }
+}
+
+void TileSetEditor::_update_tile_data() {
+ current_tile_data.clear();
+ if (get_current_tile() < 0)
+ return;
+
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(get_current_tile());
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ SubtileData data;
+ for (int i = 0; i < sd.size(); i++) {
+ data.collisions.push_back(sd[i].shape);
+ }
+ data.navigation_shape = tileset->tile_get_navigation_polygon(get_current_tile());
+ data.occlusion_shape = tileset->tile_get_light_occluder(get_current_tile());
+ current_tile_data[Vector2i()] = data;
+ } else {
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->tile_get_region(get_current_tile()).size;
+ Vector2i cell_count = size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing));
+ for (int y = 0; y < cell_count.y; y++) {
+ for (int x = 0; x < cell_count.x; x++) {
+ SubtileData data;
+ Vector2i coord(x, y);
+ for (int i = 0; i < sd.size(); i++) {
+ if (sd[i].autotile_coord == coord) {
+ data.collisions.push_back(sd[i].shape);
+ }
+ }
+ data.navigation_shape = tileset->autotile_get_navigation_polygon(get_current_tile(), coord);
+ data.occlusion_shape = tileset->tile_get_light_occluder(get_current_tile());
+ current_tile_data[coord] = data;
+ }
+ }
+ }
+}
+
+void TileSetEditor::_update_toggle_shape_button() {
+ Ref<ConvexPolygonShape2D> convex = edited_collision_shape;
+ Ref<ConcavePolygonShape2D> concave = edited_collision_shape;
+ separator_shape_toggle->show();
+ tools[SHAPE_TOGGLE_TYPE]->show();
+ if (edit_mode != EDITMODE_COLLISION || !edited_collision_shape.is_valid()) {
+ separator_shape_toggle->hide();
+ tools[SHAPE_TOGGLE_TYPE]->hide();
+ } else if (concave.is_valid()) {
+ tools[SHAPE_TOGGLE_TYPE]->set_icon(get_icon("ConvexPolygonShape2D", "EditorIcons"));
+ tools[SHAPE_TOGGLE_TYPE]->set_text("Make Convex");
+ } else if (convex.is_valid()) {
+ tools[SHAPE_TOGGLE_TYPE]->set_icon(get_icon("ConcavePolygonShape2D", "EditorIcons"));
+ tools[SHAPE_TOGGLE_TYPE]->set_text("Make Concave");
+ } else {
+ // Shoudn't happen
+ separator_shape_toggle->hide();
+ tools[SHAPE_TOGGLE_TYPE]->hide();
+ }
+}
+
+void TileSetEditor::_select_next_tile() {
+ Array tiles = _get_tiles_in_current_texture(true);
+ if (tiles.size() == 0) {
+ set_current_tile(-1);
+ } else if (get_current_tile() == -1) {
+ set_current_tile(tiles[0]);
+ } else {
+ int index = tiles.find(get_current_tile());
+ if (index < 0) {
+ set_current_tile(tiles[0]);
+ } else if (index == tiles.size() - 1) {
+ set_current_tile(tiles[0]);
+ } else {
+ set_current_tile(tiles[index + 1]);
+ }
+ }
+ if (get_current_tile() == -1) {
+ return;
+ } else if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ return;
+ } else {
+ switch (edit_mode) {
+ case EDITMODE_COLLISION:
+ case EDITMODE_OCCLUSION:
+ case EDITMODE_NAVIGATION:
+ case EDITMODE_PRIORITY:
+ case EDITMODE_Z_INDEX: {
+ edited_shape_coord = Vector2();
+ _select_edited_shape_coord();
+ } break;
+ default: {}
+ }
+ }
+}
+
+void TileSetEditor::_select_previous_tile() {
+ Array tiles = _get_tiles_in_current_texture(true);
+ if (tiles.size() == 0) {
+ set_current_tile(-1);
+ } else if (get_current_tile() == -1) {
+ set_current_tile(tiles[tiles.size() - 1]);
+ } else {
+ int index = tiles.find(get_current_tile());
+ if (index <= 0) {
+ set_current_tile(tiles[tiles.size() - 1]);
+ } else {
+ set_current_tile(tiles[index - 1]);
+ }
+ }
+ if (get_current_tile() == -1) {
+ return;
+ } else if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ return;
+ } else {
+ switch (edit_mode) {
+ case EDITMODE_COLLISION:
+ case EDITMODE_OCCLUSION:
+ case EDITMODE_NAVIGATION:
+ case EDITMODE_PRIORITY:
+ case EDITMODE_Z_INDEX: {
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->tile_get_region(get_current_tile()).size;
+ Vector2i cell_count = size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing));
+ cell_count -= Vector2(1, 1);
+ edited_shape_coord = cell_count;
+ _select_edited_shape_coord();
+ } break;
+ default: {}
+ }
+ }
+}
+
+Array TileSetEditor::_get_tiles_in_current_texture(bool sorted) {
+ Array a;
+ List<int> all_tiles;
+ if (!get_current_texture().is_valid()) {
+ return a;
+ }
+ tileset->get_tile_list(&all_tiles);
+ for (int i = 0; i < all_tiles.size(); i++) {
+ if (tileset->tile_get_texture(all_tiles[i]) == get_current_texture()) {
+ a.push_back(all_tiles[i]);
+ }
+ }
+ if (sorted) {
+ a.sort_custom(this, "_sort_tiles");
+ }
+ return a;
+}
+
+bool TileSetEditor::_sort_tiles(Variant p_a, Variant p_b) {
+ int a = p_a;
+ int b = p_b;
+
+ Vector2 pos_a = tileset->tile_get_region(a).position;
+ Vector2 pos_b = tileset->tile_get_region(b).position;
+ if (pos_a.y < pos_b.y) {
+ return true;
+
+ } else if (pos_a.y == pos_b.y) {
+ if (pos_a.x < pos_b.x) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+}
+
+void TileSetEditor::_select_next_subtile() {
+ if (get_current_tile() == -1) {
+ _select_next_tile();
+ return;
+ }
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ _select_next_tile();
+ } else if (edit_mode == EDITMODE_REGION || edit_mode == EDITMODE_BITMASK || edit_mode == EDITMODE_ICON) {
+ _select_next_tile();
+ } else {
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->tile_get_region(get_current_tile()).size;
+ Vector2i cell_count = size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing));
+ if (edited_shape_coord.x >= cell_count.x - 1 && edited_shape_coord.y >= cell_count.y - 1) {
+ _select_next_tile();
+ } else {
+ edited_shape_coord.x++;
+ if (edited_shape_coord.x >= cell_count.x) {
+ edited_shape_coord.x = 0;
+ edited_shape_coord.y++;
+ }
+ _select_edited_shape_coord();
+ }
+ }
+}
+
+void TileSetEditor::_select_previous_subtile() {
+ if (get_current_tile() == -1) {
+ _select_previous_tile();
+ return;
+ }
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ _select_previous_tile();
+ } else if (edit_mode == EDITMODE_REGION || edit_mode == EDITMODE_BITMASK || edit_mode == EDITMODE_ICON) {
+ _select_previous_tile();
+ } else {
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->tile_get_region(get_current_tile()).size;
+ Vector2i cell_count = size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing));
+ if (edited_shape_coord.x <= 0 && edited_shape_coord.y <= 0) {
+ _select_previous_tile();
+ } else {
+ edited_shape_coord.x--;
+ if (edited_shape_coord.x == -1) {
+ edited_shape_coord.x = cell_count.x - 1;
+ edited_shape_coord.y--;
+ }
+ _select_edited_shape_coord();
+ }
+ }
+}
+
+void TileSetEditor::_select_next_shape() {
+ if (get_current_tile() == -1) {
+ _select_next_subtile();
+ } else if (edit_mode != EDITMODE_COLLISION) {
+ _select_next_subtile();
+ } else {
+ Vector2i edited_coord = Vector2();
+ if (tileset->tile_get_tile_mode(get_current_tile()) != TileSet::SINGLE_TILE) {
+ edited_coord = edited_shape_coord;
+ }
+ SubtileData data = current_tile_data[edited_coord];
+ if (data.collisions.size() == 0) {
+ _select_next_subtile();
+ } else {
+ int index = data.collisions.find(edited_collision_shape);
+ if (index < 0) {
+ _set_edited_collision_shape(data.collisions[0]);
+ } else if (index == data.collisions.size() - 1) {
+ _select_next_subtile();
+ } else {
+ _set_edited_collision_shape(data.collisions[index + 1]);
+ }
+ }
+ current_shape.resize(0);
+ Rect2 current_tile_region = tileset->tile_get_region(get_current_tile());
+ current_tile_region.position += WORKSPACE_MARGIN;
+
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->autotile_get_size(get_current_tile());
+ Vector2 shape_anchor = edited_shape_coord;
+ shape_anchor.x *= (size.x + spacing);
+ shape_anchor.y *= (size.y + spacing);
+ current_tile_region.position += shape_anchor;
+
+ if (edited_collision_shape.is_valid()) {
+ for (int i = 0; i < _get_edited_shape_points().size(); i++) {
+ current_shape.push_back(_get_edited_shape_points()[i] + current_tile_region.position);
+ }
+ }
+ workspace->update();
+ workspace_container->update();
+ helper->_change_notify("");
+ }
+}
+
+void TileSetEditor::_select_previous_shape() {
+ if (get_current_tile() == -1) {
+ _select_previous_subtile();
+ if (get_current_tile() != -1 && edit_mode == EDITMODE_COLLISION) {
+ SubtileData data = current_tile_data[Vector2i(edited_shape_coord)];
+ if (data.collisions.size() > 1) {
+ _set_edited_collision_shape(data.collisions[data.collisions.size() - 1]);
+ }
+ } else {
+ return;
+ }
+ } else if (edit_mode != EDITMODE_COLLISION) {
+ _select_previous_subtile();
+ } else {
+ Vector2i edited_coord = Vector2();
+ if (tileset->tile_get_tile_mode(get_current_tile()) != TileSet::SINGLE_TILE) {
+ edited_coord = edited_shape_coord;
+ }
+ SubtileData data = current_tile_data[edited_coord];
+ if (data.collisions.size() == 0) {
+ _select_previous_subtile();
+ data = current_tile_data[Vector2i(edited_shape_coord)];
+ if (data.collisions.size() > 1) {
+ _set_edited_collision_shape(data.collisions[data.collisions.size() - 1]);
+ }
+ } else {
+ int index = data.collisions.find(edited_collision_shape);
+ if (index < 0) {
+ _set_edited_collision_shape(data.collisions[data.collisions.size() - 1]);
+ } else if (index == 0) {
+ _select_previous_subtile();
+ data = current_tile_data[Vector2i(edited_shape_coord)];
+ if (data.collisions.size() > 1) {
+ _set_edited_collision_shape(data.collisions[data.collisions.size() - 1]);
+ }
+ } else {
+ _set_edited_collision_shape(data.collisions[index - 1]);
+ }
+ }
+
+ current_shape.resize(0);
+ Rect2 current_tile_region = tileset->tile_get_region(get_current_tile());
+ current_tile_region.position += WORKSPACE_MARGIN;
+
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->autotile_get_size(get_current_tile());
+ Vector2 shape_anchor = edited_shape_coord;
+ shape_anchor.x *= (size.x + spacing);
+ shape_anchor.y *= (size.y + spacing);
+ current_tile_region.position += shape_anchor;
+
+ if (edited_collision_shape.is_valid()) {
+ for (int i = 0; i < _get_edited_shape_points().size(); i++) {
+ current_shape.push_back(_get_edited_shape_points()[i] + current_tile_region.position);
+ }
+ }
+ workspace->update();
+ workspace_container->update();
+ helper->_change_notify("");
+ }
+}
+
+void TileSetEditor::_set_edited_collision_shape(const Ref<Shape2D> &p_shape) {
+ edited_collision_shape = p_shape;
+ _update_toggle_shape_button();
+}
+
void TileSetEditor::_set_snap_step(Vector2 p_val) {
snap_step.x = CLAMP(p_val.x, 0, 256);
snap_step.y = CLAMP(p_val.y, 0, 256);
@@ -1898,16 +2380,29 @@ void TileSetEditor::draw_polygon_shapes() {
}
anchor += WORKSPACE_MARGIN;
anchor += tileset->tile_get_region(t_id).position;
- Ref<ConvexPolygonShape2D> shape = sd[i].shape;
+ Ref<Shape2D> shape = sd[i].shape;
if (shape.is_valid()) {
Color c_bg;
Color c_border;
+ Ref<ConvexPolygonShape2D> convex = shape;
+ bool is_convex = convex.is_valid();
if ((tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE || coord == edited_shape_coord) && sd[i].shape == edited_collision_shape) {
- c_bg = Color(0, 1, 1, 0.5);
- c_border = Color(0, 1, 1);
+ if (is_convex) {
+ c_bg = Color(0, 1, 1, 0.5);
+ c_border = Color(0, 1, 1);
+ } else {
+ c_bg = Color(0.8, 0, 1, 0.5);
+ c_border = Color(0.8, 0, 1);
+ }
} else {
- c_bg = Color(0.9, 0.7, 0.07, 0.5);
- c_border = Color(0.9, 0.7, 0.07, 1);
+ if (is_convex) {
+ c_bg = Color(0.9, 0.7, 0.07, 0.5);
+ c_border = Color(0.9, 0.7, 0.07, 1);
+
+ } else {
+ c_bg = Color(0.9, 0.45, 0.075, 0.5);
+ c_border = Color(0.9, 0.45, 0.075);
+ }
}
Vector<Vector2> polygon;
Vector<Color> colors;
@@ -1917,11 +2412,13 @@ void TileSetEditor::draw_polygon_shapes() {
colors.push_back(c_bg);
}
} else {
- for (int j = 0; j < shape->get_points().size(); j++) {
- polygon.push_back(shape->get_points()[j] + anchor);
+ for (int j = 0; j < _get_collision_shape_points(shape).size(); j++) {
+ polygon.push_back(_get_collision_shape_points(shape)[j] + anchor);
colors.push_back(c_bg);
}
}
+ if (polygon.size() == 0)
+ continue;
if (polygon.size() > 2) {
workspace->draw_polygon(polygon, colors);
}
@@ -1965,10 +2462,12 @@ void TileSetEditor::draw_polygon_shapes() {
workspace->draw_polygon(polygon, colors);
if (!creating_shape) {
- for (int j = 0; j < polygon.size() - 1; j++) {
- workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1, true);
+ if (polygon.size() > 1) {
+ for (int j = 0; j < polygon.size() - 1; j++) {
+ workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1, true);
+ }
+ workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1, true);
}
- workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1, true);
}
if (shape == edited_occlusion_shape) {
draw_handles = true;
@@ -2135,11 +2634,11 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
if (current_shape.size() >= 3) {
Ref<ConvexPolygonShape2D> shape = memnew(ConvexPolygonShape2D);
- Vector<Vector2> segments;
+ Vector<Vector2> points;
float p_total = 0;
for (int i = 0; i < current_shape.size(); i++) {
- segments.push_back(current_shape[i] - shape_anchor);
+ points.push_back(current_shape[i] - shape_anchor);
if (i != current_shape.size() - 1)
p_total += ((current_shape[i + 1].x - current_shape[i].x) * (-current_shape[i + 1].y + (-current_shape[i].y)));
@@ -2148,9 +2647,9 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
}
if (p_total < 0)
- segments.invert();
+ points.invert();
- shape->set_points(segments);
+ shape->set_points(points);
undo_redo->create_action(TTR("Create Collision Polygon"));
// Necessary to get the version that returns a Array instead of a Vector.
@@ -2235,6 +2734,7 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
}
void TileSetEditor::select_coord(const Vector2 &coord) {
+ _update_tile_data();
current_shape = PoolVector2Array();
if (get_current_tile() == -1)
return;
@@ -2242,7 +2742,7 @@ void TileSetEditor::select_coord(const Vector2 &coord) {
current_tile_region.position += WORKSPACE_MARGIN;
if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
if (edited_collision_shape != tileset->tile_get_shape(get_current_tile(), 0))
- edited_collision_shape = tileset->tile_get_shape(get_current_tile(), 0);
+ _set_edited_collision_shape(tileset->tile_get_shape(get_current_tile(), 0));
if (edited_occlusion_shape != tileset->tile_get_light_occluder(get_current_tile()))
edited_occlusion_shape = tileset->tile_get_light_occluder(get_current_tile());
if (edited_navigation_shape != tileset->tile_get_navigation_polygon(get_current_tile()))
@@ -2251,8 +2751,8 @@ void TileSetEditor::select_coord(const Vector2 &coord) {
if (edit_mode == EDITMODE_COLLISION) {
current_shape.resize(0);
if (edited_collision_shape.is_valid()) {
- for (int i = 0; i < edited_collision_shape->get_points().size(); i++) {
- current_shape.push_back(edited_collision_shape->get_points()[i] + current_tile_region.position);
+ for (int i = 0; i < _get_edited_shape_points().size(); i++) {
+ current_shape.push_back(_get_edited_shape_points()[i] + current_tile_region.position);
}
}
} else if (edit_mode == EDITMODE_OCCLUSION) {
@@ -2279,13 +2779,13 @@ void TileSetEditor::select_coord(const Vector2 &coord) {
for (int i = 0; i < sd.size(); i++) {
if (sd[i].autotile_coord == coord) {
if (edited_collision_shape != sd[i].shape)
- edited_collision_shape = sd[i].shape;
+ _set_edited_collision_shape(sd[i].shape);
found_collision_shape = true;
break;
}
}
if (!found_collision_shape)
- edited_collision_shape = Ref<ConvexPolygonShape2D>(NULL);
+ _set_edited_collision_shape(Ref<ConvexPolygonShape2D>(NULL));
if (edited_occlusion_shape != tileset->autotile_get_light_occluder(get_current_tile(), coord))
edited_occlusion_shape = tileset->autotile_get_light_occluder(get_current_tile(), coord);
if (edited_navigation_shape != tileset->autotile_get_navigation_polygon(get_current_tile(), coord))
@@ -2300,8 +2800,8 @@ void TileSetEditor::select_coord(const Vector2 &coord) {
if (edit_mode == EDITMODE_COLLISION) {
current_shape.resize(0);
if (edited_collision_shape.is_valid()) {
- for (int j = 0; j < edited_collision_shape->get_points().size(); j++) {
- current_shape.push_back(edited_collision_shape->get_points()[j] + shape_anchor);
+ for (int j = 0; j < _get_edited_shape_points().size(); j++) {
+ current_shape.push_back(_get_edited_shape_points()[j] + shape_anchor);
}
}
} else if (edit_mode == EDITMODE_OCCLUSION) {
@@ -2422,7 +2922,8 @@ void TileSetEditor::update_texture_list_icon() {
for (int current_idx = 0; current_idx < texture_list->get_item_count(); current_idx++) {
RID rid = texture_list->get_item_metadata(current_idx);
texture_list->set_item_icon(current_idx, texture_map[rid]);
- texture_list->set_item_icon_region(current_idx, Rect2(0, 0, 150, 100));
+ Size2 texture_size = texture_map[rid]->get_size();
+ texture_list->set_item_icon_region(current_idx, Rect2(0, 0, MIN(texture_size.x, 150), MIN(texture_size.y, 100)));
}
texture_list->update();
}
@@ -2435,10 +2936,14 @@ void TileSetEditor::update_workspace_tile_mode() {
for (int i = 1; i < WORKSPACE_MODE_MAX; i++) {
tool_workspacemode[i]->set_disabled(true);
}
+ tools[SELECT_NEXT]->set_disabled(true);
+ tools[SELECT_PREVIOUS]->set_disabled(true);
} else {
for (int i = 1; i < WORKSPACE_MODE_MAX; i++) {
tool_workspacemode[i]->set_disabled(false);
}
+ tools[SELECT_NEXT]->set_disabled(false);
+ tools[SELECT_PREVIOUS]->set_disabled(false);
}
if (workspace_mode != WORKSPACE_EDIT) {
@@ -2456,7 +2961,7 @@ void TileSetEditor::update_workspace_tile_mode() {
for (int i = 0; i < EDITMODE_MAX; i++) {
tool_editmode[i]->hide();
}
- for (int i = 0; i < ZOOM_OUT; i++) {
+ for (int i = TOOL_SELECT; i < ZOOM_OUT; i++) {
tools[i]->hide();
}
@@ -2504,6 +3009,26 @@ void TileSetEditor::update_workspace_tile_mode() {
_on_edit_mode_changed(edit_mode);
}
+void TileSetEditor::update_workspace_minsize() {
+ Size2 workspace_min_size = get_current_texture()->get_size();
+ RID current_texture_rid = get_current_texture()->get_rid();
+ List<int> *tiles = new List<int>();
+ tileset->get_tile_list(tiles);
+ for (List<int>::Element *E = tiles->front(); E; E = E->next()) {
+ if (tileset->tile_get_texture(E->get())->get_rid() == current_texture_rid) {
+ Rect2i region = tileset->tile_get_region(E->get());
+ if (region.position.x + region.size.x > workspace_min_size.x)
+ workspace_min_size.x = region.position.x + region.size.x;
+ if (region.position.y + region.size.y > workspace_min_size.y)
+ workspace_min_size.y = region.position.y + region.size.y;
+ }
+ }
+
+ workspace->set_custom_minimum_size(workspace_min_size + WORKSPACE_MARGIN * 2);
+ workspace_container->set_custom_minimum_size(workspace_min_size + WORKSPACE_MARGIN * 2);
+ workspace_overlay->set_custom_minimum_size(workspace_min_size + WORKSPACE_MARGIN * 2);
+}
+
void TileSetEditor::update_edited_region(const Vector2 &end_point) {
edited_region = Rect2(region_from, Size2());
if (tools[TOOL_GRID_SNAP]->is_pressed()) {
@@ -2536,6 +3061,11 @@ void TileSetEditor::set_current_tile(int p_id) {
helper->_change_notify("");
select_coord(Vector2(0, 0));
update_workspace_tile_mode();
+ if (p_id == -1) {
+ editor->get_inspector()->edit(tileset.ptr());
+ } else {
+ editor->get_inspector()->edit(helper);
+ }
}
}
@@ -2597,6 +3127,24 @@ bool TilesetEditorContext::_set(const StringName &p_name, const Variant &p_value
} else if (name == "tileset_script") {
tileset->set_script(p_value);
return true;
+ } else if (name == "selected_collision_one_way") {
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(tileset_editor->get_current_tile());
+ for (int index = 0; index < sd.size(); index++) {
+ if (sd[index].shape == tileset_editor->edited_collision_shape) {
+ tileset->tile_set_shape_one_way(tileset_editor->get_current_tile(), index, p_value);
+ return true;
+ }
+ }
+ return false;
+ } else if (name == "selected_collision_one_way_margin") {
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(tileset_editor->get_current_tile());
+ for (int index = 0; index < sd.size(); index++) {
+ if (sd[index].shape == tileset_editor->edited_collision_shape) {
+ tileset->tile_set_shape_one_way_margin(tileset_editor->get_current_tile(), index, p_value);
+ return true;
+ }
+ }
+ return false;
}
tileset_editor->err_dialog->set_text(TTR("This property can't be changed."));
@@ -2639,6 +3187,24 @@ bool TilesetEditorContext::_get(const StringName &p_name, Variant &r_ret) const
} else if (name == "selected_collision") {
r_ret = tileset_editor->edited_collision_shape;
v = true;
+ } else if (name == "selected_collision_one_way") {
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(tileset_editor->get_current_tile());
+ for (int index = 0; index < sd.size(); index++) {
+ if (sd[index].shape == tileset_editor->edited_collision_shape) {
+ r_ret = sd[index].one_way_collision;
+ v = true;
+ break;
+ }
+ }
+ } else if (name == "selected_collision_one_way_margin") {
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(tileset_editor->get_current_tile());
+ for (int index = 0; index < sd.size(); index++) {
+ if (sd[index].shape == tileset_editor->edited_collision_shape) {
+ r_ret = sd[index].one_way_collision_margin;
+ v = true;
+ break;
+ }
+ }
} else if (name == "selected_navigation") {
r_ret = tileset_editor->edited_navigation_shape;
v = true;
@@ -2685,6 +3251,10 @@ void TilesetEditorContext::_get_property_list(List<PropertyInfo> *p_list) const
}
if (tileset_editor->edit_mode == TileSetEditor::EDITMODE_COLLISION && tileset_editor->edited_collision_shape.is_valid()) {
p_list->push_back(PropertyInfo(Variant::OBJECT, "selected_collision", PROPERTY_HINT_RESOURCE_TYPE, tileset_editor->edited_collision_shape->get_class()));
+ if (tileset_editor->edited_collision_shape.is_valid()) {
+ p_list->push_back(PropertyInfo(Variant::BOOL, "selected_collision_one_way", PROPERTY_HINT_NONE));
+ p_list->push_back(PropertyInfo(Variant::REAL, "selected_collision_one_way_margin", PROPERTY_HINT_NONE));
+ }
}
if (tileset_editor->edit_mode == TileSetEditor::EDITMODE_NAVIGATION && tileset_editor->edited_navigation_shape.is_valid()) {
p_list->push_back(PropertyInfo(Variant::OBJECT, "selected_navigation", PROPERTY_HINT_RESOURCE_TYPE, tileset_editor->edited_navigation_shape->get_class()));
@@ -2705,13 +3275,13 @@ void TilesetEditorContext::_bind_methods() {
TilesetEditorContext::TilesetEditorContext(TileSetEditor *p_tileset_editor) {
tileset_editor = p_tileset_editor;
+ snap_options_visible = false;
}
void TileSetEditorPlugin::edit(Object *p_node) {
if (Object::cast_to<TileSet>(p_node)) {
tileset_editor->edit(Object::cast_to<TileSet>(p_node));
- editor->get_inspector()->edit(tileset_editor->helper);
}
}
@@ -2740,6 +3310,7 @@ Dictionary TileSetEditorPlugin::get_state() const {
state["snap_separation"] = tileset_editor->snap_separation;
state["snap_enabled"] = tileset_editor->tools[TileSetEditor::TOOL_GRID_SNAP]->is_pressed();
state["keep_inside_tile"] = tileset_editor->tools[TileSetEditor::SHAPE_KEEP_INSIDE_TILE]->is_pressed();
+ state["show_information"] = tileset_editor->tools[TileSetEditor::VISIBLE_INFO]->is_pressed();
return state;
}
@@ -2760,11 +3331,18 @@ void TileSetEditorPlugin::set_state(const Dictionary &p_state) {
if (state.has("snap_enabled")) {
tileset_editor->tools[TileSetEditor::TOOL_GRID_SNAP]->set_pressed(state["snap_enabled"]);
+ if (tileset_editor->helper) {
+ tileset_editor->_on_grid_snap_toggled(state["snap_enabled"]);
+ }
}
if (state.has("keep_inside_tile")) {
tileset_editor->tools[TileSetEditor::SHAPE_KEEP_INSIDE_TILE]->set_pressed(state["keep_inside_tile"]);
}
+
+ if (state.has("show_information")) {
+ tileset_editor->tools[TileSetEditor::VISIBLE_INFO]->set_pressed(state["show_information"]);
+ }
}
TileSetEditorPlugin::TileSetEditorPlugin(EditorNode *p_node) {
diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h
index 6bbfee8714..2827964592 100644
--- a/editor/plugins/tile_set_editor_plugin.h
+++ b/editor/plugins/tile_set_editor_plugin.h
@@ -34,6 +34,7 @@
#include "editor/editor_name_dialog.h"
#include "editor/editor_node.h"
#include "scene/2d/sprite.h"
+#include "scene/resources/concave_polygon_shape_2d.h"
#include "scene/resources/convex_polygon_shape_2d.h"
#include "scene/resources/tile_set.h"
@@ -76,12 +77,15 @@ class TileSetEditor : public HSplitContainer {
};
enum TileSetTools {
+ SELECT_PREVIOUS,
+ SELECT_NEXT,
TOOL_SELECT,
BITMASK_COPY,
BITMASK_PASTE,
BITMASK_CLEAR,
SHAPE_NEW_POLYGON,
SHAPE_NEW_RECTANGLE,
+ SHAPE_TOGGLE_TYPE,
SHAPE_DELETE,
SHAPE_KEEP_INSIDE_TILE,
TOOL_GRID_SNAP,
@@ -92,6 +96,12 @@ class TileSetEditor : public HSplitContainer {
TOOL_MAX
};
+ struct SubtileData {
+ Array collisions;
+ Ref<OccluderPolygon2D> occlusion_shape;
+ Ref<NavigationPolygon> navigation_shape;
+ };
+
Ref<TileSet> tileset;
TilesetEditorContext *helper;
EditorNode *editor;
@@ -115,13 +125,14 @@ class TileSetEditor : public HSplitContainer {
bool draw_edited_region;
Vector2 edited_shape_coord;
PoolVector2Array current_shape;
+ Map<Vector2i, SubtileData> current_tile_data;
Map<Vector2, uint16_t> bitmask_map_copy;
Vector2 snap_step;
Vector2 snap_offset;
Vector2 snap_separation;
- Ref<ConvexPolygonShape2D> edited_collision_shape;
+ Ref<Shape2D> edited_collision_shape;
Ref<OccluderPolygon2D> edited_occlusion_shape;
Ref<NavigationPolygon> edited_navigation_shape;
@@ -137,6 +148,7 @@ class TileSetEditor : public HSplitContainer {
HSeparator *separator_editmode;
HBoxContainer *toolbar;
ToolButton *tools[TOOL_MAX];
+ VSeparator *separator_shape_toggle;
VSeparator *separator_bitmask;
VSeparator *separator_delete;
VSeparator *separator_grid;
@@ -188,6 +200,20 @@ private:
void _on_priority_changed(float val);
void _on_z_index_changed(float val);
void _on_grid_snap_toggled(bool p_val);
+ Vector<Vector2> _get_collision_shape_points(const Ref<Shape2D> &p_shape);
+ Vector<Vector2> _get_edited_shape_points();
+ void _set_edited_shape_points(const Vector<Vector2> points);
+ void _update_tile_data();
+ void _update_toggle_shape_button();
+ void _select_next_tile();
+ void _select_previous_tile();
+ Array _get_tiles_in_current_texture(bool sorted = false);
+ bool _sort_tiles(Variant p_a, Variant p_b);
+ void _select_next_subtile();
+ void _select_previous_subtile();
+ void _select_next_shape();
+ void _select_previous_shape();
+ void _set_edited_collision_shape(const Ref<Shape2D> &p_shape);
void _set_snap_step(Vector2 p_val);
void _set_snap_off(Vector2 p_val);
void _set_snap_sep(Vector2 p_val);
@@ -210,6 +236,7 @@ private:
void select_coord(const Vector2 &coord);
Vector2 snap_point(const Vector2 &point);
void update_workspace_tile_mode();
+ void update_workspace_minsize();
void update_edited_region(const Vector2 &end_point);
int get_current_tile() const;
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 734cd505d2..7bd26de092 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -393,7 +393,7 @@ void VisualShaderEditor::_preview_select_port(int p_node, int p_port) {
if (node->get_output_port_for_preview() == p_port) {
p_port = -1; //toggle it
}
- undo_redo->create_action("Set Uniform Name");
+ undo_redo->create_action(TTR("Set Uniform Name"));
undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", p_port);
undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", node->get_output_port_for_preview());
undo_redo->add_do_method(this, "_update_graph");
@@ -411,7 +411,7 @@ void VisualShaderEditor::_line_edit_changed(const String &p_text, Object *line_e
String validated_name = visual_shader->validate_uniform_name(p_text, node);
updating = true;
- undo_redo->create_action("Set Uniform Name");
+ undo_redo->create_action(TTR("Set Uniform Name"));
undo_redo->add_do_method(node.ptr(), "set_uniform_name", validated_name);
undo_redo->add_undo_method(node.ptr(), "set_uniform_name", node->get_uniform_name());
undo_redo->add_do_method(this, "_update_graph");
@@ -436,7 +436,7 @@ void VisualShaderEditor::_port_edited() {
Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node);
ERR_FAIL_COND(!vsn.is_valid());
- undo_redo->create_action("Set Input Default Port");
+ undo_redo->create_action(TTR("Set Input Default Port"));
undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, value);
undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
undo_redo->add_do_method(this, "_update_graph");
@@ -487,7 +487,7 @@ void VisualShaderEditor::_add_node(int p_idx) {
int id_to_use = visual_shader->get_valid_node_id(type);
- undo_redo->create_action("Add Node to Visual Shader");
+ undo_redo->create_action(TTR("Add Node to Visual Shader"));
undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, vsnode, position, id_to_use);
undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_to_use);
undo_redo->add_do_method(this, "_update_graph");
@@ -500,7 +500,7 @@ void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_t
VisualShader::Type type = VisualShader::Type(edit_type->get_selected());
updating = true;
- undo_redo->create_action("Node Moved");
+ undo_redo->create_action(TTR("Node Moved"));
undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", type, p_node, p_to);
undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", type, p_node, p_from);
undo_redo->add_do_method(this, "_update_graph");
@@ -521,7 +521,7 @@ void VisualShaderEditor::_connection_request(const String &p_from, int p_from_in
return;
}
- undo_redo->create_action("Nodes Connected");
+ undo_redo->create_action(TTR("Nodes Connected"));
List<VisualShader::Connection> conns;
visual_shader->get_node_connections(type, &conns);
@@ -550,7 +550,7 @@ void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from
int to = p_to.to_int();
//updating = true; seems graph edit can handle this, no need to protect
- undo_redo->create_action("Nodes Disconnected");
+ undo_redo->create_action(TTR("Nodes Disconnected"));
undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
undo_redo->add_do_method(this, "_update_graph");
@@ -566,7 +566,7 @@ void VisualShaderEditor::_delete_request(int which) {
VisualShader::Type type = VisualShader::Type(edit_type->get_selected());
- undo_redo->create_action("Delete Node");
+ undo_redo->create_action(TTR("Delete Node"));
undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, which);
undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, visual_shader->get_node(type, which), visual_shader->get_node_position(type, which), which);
@@ -671,7 +671,7 @@ void VisualShaderEditor::_duplicate_nodes() {
if (nodes.empty())
return;
- undo_redo->create_action("Duplicate Nodes");
+ undo_redo->create_action(TTR("Duplicate Nodes"));
int base_id = visual_shader->get_valid_node_id(type);
int id_from = base_id;
@@ -732,7 +732,7 @@ void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> input, St
bool type_changed = input->get_input_type_by_name(name) != input->get_input_type_by_name(prev_name);
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
- undo_redo->create_action("Visual Shader Input Type Changed");
+ undo_redo->create_action(TTR("Visual Shader Input Type Changed"));
undo_redo->add_do_method(input.ptr(), "set_input_name", name);
undo_redo->add_undo_method(input.ptr(), "set_input_name", prev_name);
@@ -972,7 +972,7 @@ public:
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
updating = true;
- undo_redo->create_action("Edit Visual Property: " + prop, UndoRedo::MERGE_ENDS);
+ undo_redo->create_action(TTR("Edit Visual Property") + ": " + prop, UndoRedo::MERGE_ENDS);
undo_redo->add_do_property(node.ptr(), prop, p_value);
undo_redo->add_undo_property(node.ptr(), prop, node->get(prop));
undo_redo->commit_action();
@@ -1093,7 +1093,7 @@ void EditorPropertyShaderMode::_option_selected(int p_which) {
return;
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
- undo_redo->create_action("Visual Shader Mode Changed");
+ undo_redo->create_action(TTR("Visual Shader Mode Changed"));
//do is easy
undo_redo->add_do_method(visual_shader.ptr(), "set_mode", p_which);
undo_redo->add_undo_method(visual_shader.ptr(), "set_mode", visual_shader->get_mode());