From 792ff11642c0bd0d2c2c647a2cc4d828f47d35d0 Mon Sep 17 00:00:00 2001 From: volzhs Date: Wed, 28 Dec 2016 14:27:27 +0900 Subject: [PATCH 1/2] Able to change visibility when ancestor node is hidden --- scene/2d/canvas_item.cpp | 9 ++------- tools/editor/scene_tree_editor.cpp | 13 ------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index ed1d606ba8c..995120bc995 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -261,16 +261,13 @@ void CanvasItem::show() { if (!hidden) return; - hidden=false; VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,true); if (!is_inside_tree()) return; - if (is_visible()) { - _propagate_visibility_changed(true); - } + _propagate_visibility_changed(true); _change_notify("visibility/visible"); } @@ -280,15 +277,13 @@ void CanvasItem::hide() { if (hidden) return; - bool propagate=is_inside_tree() && is_visible(); hidden=true; VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,false); if (!is_inside_tree()) return; - if (propagate) - _propagate_visibility_changed(false); + _propagate_visibility_changed(false); _change_notify("visibility/visible"); } diff --git a/tools/editor/scene_tree_editor.cpp b/tools/editor/scene_tree_editor.cpp index ebfa62528ff..ae3a465b45b 100644 --- a/tools/editor/scene_tree_editor.cpp +++ b/tools/editor/scene_tree_editor.cpp @@ -208,13 +208,6 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item,int p_column,int p_id) if (n->is_type("Spatial")) { - Spatial *ci = n->cast_to(); - if (!ci->is_visible() && ci->get_parent_spatial() && !ci->get_parent_spatial()->is_visible()) { - error->set_text(TTR("This item cannot be made visible because the parent is hidden. Unhide the parent first.")); - error->popup_centered_minsize(); - return; - } - bool v = !bool(n->call("is_hidden")); undo_redo->create_action(TTR("Toggle Spatial Visible")); undo_redo->add_do_method(n,"_set_visible_",!v); @@ -222,12 +215,6 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item,int p_column,int p_id) undo_redo->commit_action(); } else if (n->is_type("CanvasItem")) { - CanvasItem *ci = n->cast_to(); - if (!ci->is_visible() && ci->get_parent_item() && !ci->get_parent_item()->is_visible()) { - error->set_text(TTR("This item cannot be made visible because the parent is hidden. Unhide the parent first.")); - error->popup_centered_minsize(); - return; - } bool v = !bool(n->call("is_hidden")); undo_redo->create_action(TTR("Toggle CanvasItem Visible")); undo_redo->add_do_method(n,v?"hide":"show"); From f33e21e7afc64990bca106e6b349cbe2f7e81c0e Mon Sep 17 00:00:00 2001 From: volzhs Date: Wed, 28 Dec 2016 22:12:08 +0900 Subject: [PATCH 2/2] Show visual notice for visibility on Scene Dock --- scene/gui/tree.cpp | 11 ++++++++++- scene/gui/tree.h | 4 +++- tools/editor/scene_tree_editor.cpp | 15 ++++++++++++++- tools/editor/scene_tree_editor.h | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index d974e09275a..c5c8b60e0fb 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -569,6 +569,15 @@ void TreeItem::set_button(int p_column,int p_idx,const Ref& p_button){ } +void TreeItem::set_button_color(int p_column,int p_idx,const Color& p_color) { + + ERR_FAIL_INDEX( p_column, cells.size() ); + ERR_FAIL_INDEX( p_idx, cells[p_column].buttons.size() ); + cells[p_column].buttons[p_idx].color=p_color; + _changed_notify(p_column); + +} + void TreeItem::set_editable(int p_column,bool p_editable) { ERR_FAIL_INDEX( p_column, cells.size() ); @@ -1061,7 +1070,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& o.y+=(label_h-s.height)/2; o+=cache.button_pressed->get_offset(); - b->draw(ci,o,p_item->cells[i].buttons[j].disabled?Color(1,1,1,0.5):Color(1,1,1,1)); + b->draw(ci,o,p_item->cells[i].buttons[j].disabled?Color(1,1,1,0.5):p_item->cells[i].buttons[j].color); w-=s.width+cache.button_margin; bw+=s.width+cache.button_margin; } diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 1936f926c81..b115d3b9a45 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -93,7 +93,8 @@ friend class Tree; int id; bool disabled; Ref texture; - Button() { id=0; disabled=false; } + Color color; + Button() { id=0; disabled=false; color=Color(1,1,1,1); } }; Vector< Button > buttons; @@ -189,6 +190,7 @@ public: int get_button_by_id(int p_column,int p_id) const; bool is_button_disabled(int p_column,int p_idx) const; void set_button(int p_column,int p_idx,const Ref& p_button); + void set_button_color(int p_column,int p_idx,const Color& p_color); /* range works for mode number or mode combo */ diff --git a/tools/editor/scene_tree_editor.cpp b/tools/editor/scene_tree_editor.cpp index ae3a465b45b..be09e15d05a 100644 --- a/tools/editor/scene_tree_editor.cpp +++ b/tools/editor/scene_tree_editor.cpp @@ -402,6 +402,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) { if (!p_node->is_connected("visibility_changed",this,"_node_visibility_changed")) p_node->connect("visibility_changed",this,"_node_visibility_changed",varray(p_node)); + _update_visibility_color(p_node, item); } else if (p_node->is_type("Spatial")) { bool h = p_node->call("is_hidden"); @@ -413,6 +414,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) { if (!p_node->is_connected("visibility_changed",this,"_node_visibility_changed")) p_node->connect("visibility_changed",this,"_node_visibility_changed",varray(p_node)); + _update_visibility_color(p_node, item); } } @@ -478,9 +480,20 @@ void SceneTreeEditor::_node_visibility_changed(Node *p_node) { else item->set_button(0,idx,get_icon("Visible","EditorIcons")); - + _update_visibility_color(p_node, item); } +void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) { + if (p_node->is_type("CanvasItem") || p_node->is_type("Spatial")) { + Color color(1,1,1,1); + bool visible_on_screen = p_node->call("is_visible"); + if (!visible_on_screen) { + color = Color(0.6,0.6,0.6,1); + } + int idx=p_item->get_button_by_id(0,BUTTON_VISIBILITY); + p_item->set_button_color(0,idx,color); + } +} void SceneTreeEditor::_node_script_changed(Node *p_node) { diff --git a/tools/editor/scene_tree_editor.h b/tools/editor/scene_tree_editor.h index 12d85ecdebf..f23b63ada92 100644 --- a/tools/editor/scene_tree_editor.h +++ b/tools/editor/scene_tree_editor.h @@ -117,6 +117,7 @@ class SceneTreeEditor : public Control { void _update_selection(TreeItem *item); void _node_script_changed(Node *p_node); void _node_visibility_changed(Node *p_node); + void _update_visibility_color(Node *p_node, TreeItem *p_item); void _subscene_option(int p_idx); void _node_replace_owner(Node* p_base,Node* p_node,Node* p_root);