summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_properties.cpp3
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp12
-rw-r--r--editor/plugins/texture_region_editor_plugin.h15
-rw-r--r--editor/scene_tree_editor.cpp76
-rw-r--r--editor/scene_tree_editor.h3
5 files changed, 66 insertions, 43 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 880e51660b..196fba6e9b 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -42,6 +42,7 @@
#include "scene/3d/gpu_particles_3d.h"
#include "scene/main/window.h"
#include "scene/resources/font.h"
+#include "scene/resources/mesh.h"
///////////////////// Nil /////////////////////////
@@ -3172,7 +3173,7 @@ void EditorPropertyResource::_update_preferred_shader() {
shader_picker->set_preferred_mode(Shader::MODE_FOG);
} else if (Object::cast_to<CanvasItem>(object)) {
shader_picker->set_preferred_mode(Shader::MODE_CANVAS_ITEM);
- } else if (Object::cast_to<Node3D>(object)) {
+ } else if (Object::cast_to<Node3D>(object) || Object::cast_to<Mesh>(object)) {
shader_picker->set_preferred_mode(Shader::MODE_SPATIAL);
} else if (Object::cast_to<Sky>(object)) {
shader_picker->set_preferred_mode(Shader::MODE_SKY);
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index 79e09404a0..3f4f9a4f4d 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -83,6 +83,7 @@ void TextureRegionEditor::_region_draw() {
mtx.scale_basis(Vector2(draw_zoom, draw_zoom));
RS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), mtx);
+ edit_draw->draw_rect(Rect2(Point2(), base_tex->get_size()), Color(0.5, 0.5, 0.5, 0.5), false);
edit_draw->draw_texture(base_tex, Point2());
RS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), Transform2D());
@@ -234,6 +235,14 @@ void TextureRegionEditor::_region_draw() {
updating_scroll = false;
+ if (request_center && hscroll->get_min() < 0) {
+ hscroll->set_value((hscroll->get_min() + hscroll->get_max() - hscroll->get_page()) / 2);
+ vscroll->set_value((vscroll->get_min() + vscroll->get_max() - vscroll->get_page()) / 2);
+ // This ensures that the view is updated correctly.
+ callable_bind(callable_mp(this, &TextureRegionEditor::_pan_callback), Vector2(1, 0)).call_deferred(nullptr, 0);
+ request_center = false;
+ }
+
if (node_ninepatch || obj_styleBox.is_valid()) {
float margins[4] = { 0 };
if (node_ninepatch) {
@@ -922,7 +931,8 @@ void TextureRegionEditor::edit(Object *p_obj) {
atlas_tex = Ref<AtlasTexture>(nullptr);
}
edit_draw->update();
- popup_centered_ratio();
+ popup_centered_ratio(0.5);
+ request_center = true;
}
void TextureRegionEditor::_texture_changed() {
diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h
index dd92f6e3eb..a18c87f153 100644
--- a/editor/plugins/texture_region_editor_plugin.h
+++ b/editor/plugins/texture_region_editor_plugin.h
@@ -71,10 +71,10 @@ class TextureRegionEditor : public AcceptDialog {
UndoRedo *undo_redo = nullptr;
Vector2 draw_ofs;
- float draw_zoom;
- bool updating_scroll;
+ float draw_zoom = 0.0;
+ bool updating_scroll = false;
- int snap_mode;
+ int snap_mode = 0;
Vector2 snap_offset;
Vector2 snap_step;
Vector2 snap_separation;
@@ -88,15 +88,16 @@ class TextureRegionEditor : public AcceptDialog {
Rect2 rect;
Rect2 rect_prev;
float prev_margin = 0.0f;
- int edited_margin;
+ int edited_margin = 0;
HashMap<RID, List<Rect2>> cache_map;
List<Rect2> autoslice_cache;
- bool autoslice_is_dirty;
+ bool autoslice_is_dirty = false;
- bool drag;
+ bool drag = false;
bool creating = false;
Vector2 drag_from;
- int drag_index;
+ int drag_index = 0;
+ bool request_center = false;
Ref<ViewPanner> panner;
void _scroll_callback(Vector2 p_scroll_vec, bool p_alt);
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp
index eaec3bab02..32d43d7c59 100644
--- a/editor/scene_tree_editor.cpp
+++ b/editor/scene_tree_editor.cpp
@@ -170,9 +170,9 @@ void SceneTreeEditor::_toggle_visible(Node *p_node) {
}
}
-bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll_to_selected) {
+void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
if (!p_node) {
- return false;
+ return;
}
// only owned nodes are editable, since nodes can create their own (manually owned) child nodes,
@@ -185,7 +185,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
part_of_subscene = true;
//allow
} else {
- return false;
+ return;
}
} else {
part_of_subscene = p_node != get_scene_node() && get_scene_node()->get_scene_inherited_state().is_valid() && get_scene_node()->get_scene_inherited_state()->find_node_by_path(get_scene_node()->get_path_to(p_node)) >= 0;
@@ -431,29 +431,21 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
}
}
- bool scroll = false;
-
if (editor_selection) {
if (editor_selection->is_selected(p_node)) {
item->select(0);
- scroll = p_scroll_to_selected;
}
}
if (selected == p_node) {
if (!editor_selection) {
item->select(0);
- scroll = p_scroll_to_selected;
}
item->set_as_cursor(0);
}
- bool keep = (filter.is_subsequence_ofn(String(p_node->get_name())));
-
for (int i = 0; i < p_node->get_child_count(); i++) {
- bool child_keep = _add_nodes(p_node->get_child(i), item, p_scroll_to_selected);
-
- keep = keep || child_keep;
+ _add_nodes(p_node->get_child(i), item);
}
if (valid_types.size()) {
@@ -466,27 +458,10 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
}
if (!valid) {
- //item->set_selectable(0,marked_selectable);
item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
item->set_selectable(0, false);
}
}
-
- if (!keep) {
- if (editor_selection) {
- Node *n = get_node(item->get_metadata(0));
- if (n) {
- editor_selection->remove_node(n);
- }
- }
- memdelete(item);
- return false;
- } else {
- if (scroll) {
- tree->scroll_to_item(item);
- }
- return true;
- }
}
void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
@@ -592,13 +567,48 @@ void SceneTreeEditor::_update_tree(bool p_scroll_to_selected) {
updating_tree = true;
tree->clear();
if (get_scene_node()) {
- _add_nodes(get_scene_node(), nullptr, p_scroll_to_selected);
+ _add_nodes(get_scene_node(), nullptr);
last_hash = hash_djb2_one_64(0);
_compute_hash(get_scene_node(), last_hash);
}
updating_tree = false;
-
tree_dirty = false;
+
+ if (!filter.is_empty()) {
+ _update_filter(nullptr, p_scroll_to_selected);
+ }
+}
+
+bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_selected) {
+ if (!p_parent) {
+ p_parent = tree->get_root();
+ }
+
+ bool keep = false;
+ for (TreeItem *child = p_parent->get_first_child(); child; child = child->get_next()) {
+ keep = _update_filter(child, p_scroll_to_selected) || keep;
+ }
+
+ if (!keep) {
+ keep = filter.is_subsequence_ofn(p_parent->get_text(0));
+ }
+
+ p_parent->set_visible(keep);
+ if (editor_selection) {
+ Node *n = get_node(p_parent->get_metadata(0));
+ if (keep) {
+ if (p_scroll_to_selected && n && editor_selection->is_selected(n)) {
+ tree->scroll_to_item(p_parent);
+ }
+ } else {
+ if (n && p_parent->is_selected(0)) {
+ editor_selection->remove_node(n);
+ p_parent->deselect(0);
+ }
+ }
+ }
+
+ return keep;
}
void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) {
@@ -898,7 +908,7 @@ void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_child
void SceneTreeEditor::set_filter(const String &p_filter) {
filter = p_filter;
- _update_tree(true);
+ _update_filter(nullptr, true);
}
String SceneTreeEditor::get_filter() const {
@@ -1211,7 +1221,7 @@ void SceneTreeEditor::set_connecting_signal(bool p_enable) {
}
void SceneTreeEditor::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_update_tree", "scroll_to_selected"), &SceneTreeEditor::_update_tree, DEFVAL(false)); // Still used by some connect_compat.
+ ClassDB::bind_method(D_METHOD("_update_tree"), &SceneTreeEditor::_update_tree, DEFVAL(false)); // Still used by some connect_compat.
ClassDB::bind_method("_rename_node", &SceneTreeEditor::_rename_node);
ClassDB::bind_method("_test_update_tree", &SceneTreeEditor::_test_update_tree);
diff --git a/editor/scene_tree_editor.h b/editor/scene_tree_editor.h
index 60387cea3e..5d4230059c 100644
--- a/editor/scene_tree_editor.h
+++ b/editor/scene_tree_editor.h
@@ -73,9 +73,10 @@ class SceneTreeEditor : public Control {
void _compute_hash(Node *p_node, uint64_t &hash);
- bool _add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll_to_selected = false);
+ void _add_nodes(Node *p_node, TreeItem *p_parent);
void _test_update_tree();
void _update_tree(bool p_scroll_to_selected = false);
+ bool _update_filter(TreeItem *p_parent = nullptr, bool p_scroll_to_selected = false);
void _tree_changed();
void _tree_process_mode_changed();
void _node_removed(Node *p_node);