-Make sure scenes properly update when switching tabs, even if sub-instances changed. Fixes #3201

This commit is contained in:
Juan Linietsky 2016-01-14 11:06:20 -03:00
parent e2be837520
commit 4248c84e20
7 changed files with 37 additions and 5 deletions

View File

@ -725,7 +725,8 @@ Error ResourceInteractiveLoaderBinary::poll(){
} }
} else { } else {
path=res_path; if (!ResourceCache::has(res_path))
path=res_path;
} }
uint64_t offset = internal_resources[s].offset; uint64_t offset = internal_resources[s].offset;

View File

@ -1570,7 +1570,9 @@ Error ResourceInteractiveLoaderXML::poll() {
if (main) { if (main) {
f->close(); f->close();
resource=res; resource=res;
resource->set_path(res_path); if (!ResourceCache::has(res_path)) {
resource->set_path(res_path);
}
error=ERR_FILE_EOF; error=ERR_FILE_EOF;
return error; return error;

View File

@ -1597,6 +1597,16 @@ Node *PackedScene::instance(bool p_gen_edit_state) const {
return s; return s;
} }
void PackedScene::replace_state(Ref<SceneState> p_by) {
state=p_by;
state->set_path(get_path());
#ifdef TOOLS_ENABLED
state->set_last_modified_time(get_last_modified_time());
#endif
}
void PackedScene::recreate_state() { void PackedScene::recreate_state() {
state = Ref<SceneState>( memnew( SceneState )); state = Ref<SceneState>( memnew( SceneState ));

View File

@ -198,6 +198,7 @@ public:
Node *instance(bool p_gen_edit_state=false) const; Node *instance(bool p_gen_edit_state=false) const;
void recreate_state(); void recreate_state();
void replace_state(Ref<SceneState> p_by);
virtual void set_path(const String& p_path,bool p_take_over=false); virtual void set_path(const String& p_path,bool p_take_over=false);
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED

View File

@ -302,6 +302,10 @@ Error ResourceInteractiveLoaderText::poll() {
if (error) { if (error) {
if (error!=ERR_FILE_EOF) { if (error!=ERR_FILE_EOF) {
_printerr(); _printerr();
} else {
if (!ResourceCache::has(res_path)) {
resource->set_path(res_path);
}
} }
return error; return error;
} }
@ -403,6 +407,9 @@ Error ResourceInteractiveLoaderText::poll() {
_printerr(); _printerr();
} else { } else {
resource=packed_scene; resource=packed_scene;
if (!ResourceCache::has(res_path)) {
packed_scene->set_path(res_path);
}
} }
return error; return error;
} }

View File

@ -499,8 +499,8 @@ void EditorData::remove_scene(int p_idx){
bool EditorData::_find_updated_instances(Node* p_root,Node *p_node,Set<String> &checked_paths) { bool EditorData::_find_updated_instances(Node* p_root,Node *p_node,Set<String> &checked_paths) {
if (p_root!=p_node && p_node->get_owner()!=p_root && !p_root->is_editable_instance(p_node->get_owner())) // if (p_root!=p_node && p_node->get_owner()!=p_root && !p_root->is_editable_instance(p_node->get_owner()))
return false; // return false;
Ref<SceneState> ss; Ref<SceneState> ss;

View File

@ -3623,7 +3623,18 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo
add_io_error(txt); add_io_error(txt);
} }
sdata->set_path(lpath,true); //take over path if (ResourceCache::has(lpath)) {
//used from somewhere else? no problem! update state
Ref<PackedScene> ps = Ref<PackedScene>( ResourceCache::get(lpath)->cast_to<PackedScene>() );
if (ps.is_valid()) {
ps->replace_state( sdata->get_state() );
ps->set_last_modified_time( sdata->get_last_modified_time() );
sdata=ps;
}
} else {
sdata->set_path(lpath,true); //take over path
}
Node*new_scene=sdata->instance(true); Node*new_scene=sdata->instance(true);