3232
3333#include " core/config/project_settings.h"
3434#include " core/io/resource_loader.h"
35- #include " core/io/resource_uid.h"
3635#include " core/math/math_defs.h"
3736#include " core/os/keyboard.h"
3837#include " core/version_generated.gen.h"
@@ -1550,7 +1549,7 @@ void VisualShaderEditor::edit_shader(const Ref<Shader> &p_shader) {
15501549 _update_options_menu ();
15511550 _update_preview ();
15521551 _update_graph ();
1553- call_deferred ( " _restore_editor_state" );
1552+ callable_mp ( this , &VisualShaderEditor:: _restore_editor_state). call_deferred ( );
15541553 }
15551554 }
15561555}
@@ -1577,17 +1576,13 @@ void VisualShaderEditor::validate_script() {
15771576void VisualShaderEditor::set_current_shader_type (VisualShader::Type p_type) {
15781577 current_type = p_type;
15791578
1580- String id_string = visual_shader->get_path ();
1581- const ResourceUID::ID uid = ResourceLoader::get_resource_uid (id_string);
1582- if (uid != ResourceUID::INVALID_ID) {
1583- id_string = ResourceUID::get_singleton ()->id_to_text (uid);
1584- }
1579+ const String id_string = _get_vs_editor_cache_id_string ();
15851580
1586- vs_editor_cache->set_value (" visual_shader " , id_string + " : edited_type" , p_type);
1581+ vs_editor_cache->set_value (id_string, " edited_type" , p_type);
15871582 vs_editor_cache->save (EditorPaths::get_singleton ()->get_project_settings_dir ().path_join (" vs_editor_cache.cfg" ));
15881583
1589- const Vector2 saved_scroll_offset = vs_editor_cache->get_value (" visual_shader " , id_string + " : type" + itos (p_type) + " :offset" , Vector2 ());
1590- const real_t saved_zoom = vs_editor_cache->get_value (" visual_shader " , id_string + " : type" + itos (p_type) + " :zoom" , 1.0 );
1584+ const Vector2 saved_scroll_offset = vs_editor_cache->get_value (id_string, " type" + itos (p_type) + " :offset" , Vector2 ());
1585+ const real_t saved_zoom = vs_editor_cache->get_value (id_string, " type" + itos (p_type) + " :zoom" , 1.0 );
15911586
15921587 graph->set_zoom (saved_zoom);
15931588 graph->set_scroll_offset (saved_scroll_offset);
@@ -2485,13 +2480,9 @@ void VisualShaderEditor::_set_mode(int p_which) {
24852480 mode = MODE_FLAGS_SPATIAL_CANVASITEM;
24862481 }
24872482
2488- String id_string = visual_shader->get_path ();
2489- const ResourceUID::ID uid = ResourceLoader::get_resource_uid (id_string);
2490- if (uid != ResourceUID::INVALID_ID) {
2491- id_string = ResourceUID::get_singleton ()->id_to_text (uid);
2492- }
2483+ const String id_string = _get_vs_editor_cache_id_string ();
24932484
2494- int saved_type = vs_editor_cache->get_value (" visual_shader " , id_string + " : edited_type" , 0 );
2485+ int saved_type = vs_editor_cache->get_value (id_string, " edited_type" , 0 );
24952486 edit_type->select (saved_type);
24962487 set_current_shader_type ((VisualShader::Type)saved_type);
24972488}
@@ -2652,25 +2643,28 @@ void VisualShaderEditor::_update_graph() {
26522643}
26532644
26542645void VisualShaderEditor::_restore_editor_state () {
2655- String id_string = visual_shader->get_path ();
2656- const ResourceUID::ID uid = ResourceLoader::get_resource_uid (id_string);
2657- if (uid != ResourceUID::INVALID_ID) {
2658- id_string = ResourceUID::get_singleton ()->id_to_text (uid);
2659- }
2646+ const String id_string = _get_vs_editor_cache_id_string ();
26602647
26612648 const int type = get_current_shader_type ();
2662- // const Vector2 saved_scroll_offset = EditorSettings::get_singleton()->get_project_metadata("visual_shader", uid_text + ":type" + itos(type) + ":offset", Vector2());
2663- const Vector2 saved_scroll_offset = vs_editor_cache->get_value (" visual_shader" , id_string + " :type" + itos (type) + " :offset" , Vector2 ());
2664- // const real_t saved_zoom = EditorSettings::get_singleton()->get_project_metadata("visual_shader", uid_text + ":type" + itos(type) + ":zoom", 1.0);
2665- const real_t saved_zoom = vs_editor_cache->get_value (" visual_shader" , id_string + " :type" + itos (type) + " :zoom" , 1.0 );
2649+ const Vector2 saved_scroll_offset = vs_editor_cache->get_value (id_string, " type" + itos (type) + " :offset" , Vector2 ());
2650+ const real_t saved_zoom = vs_editor_cache->get_value (id_string, " type" + itos (type) + " :zoom" , 1.0 );
26662651
26672652 // Setting the scroll offset needs to be double-deferred because it requires min/max scroll offset to be final (as it gets clamped).
2668- graph-> call_deferred ( " set_zoom " , saved_zoom);
2669- graph-> call_deferred ( " set_scroll_offset " , saved_scroll_offset);
2653+ callable_mp (graph, &GraphEdit::set_zoom). call_deferred ( saved_zoom);
2654+ callable_mp (graph, &GraphEdit::set_scroll_offset). call_deferred ( saved_scroll_offset);
26702655
26712656 shader_fully_loaded = true ;
26722657}
26732658
2659+ String VisualShaderEditor::_get_vs_editor_cache_id_string () const {
2660+ String id_string = visual_shader->get_path ();
2661+ const ResourceUID::ID uid = EditorFileSystem::get_singleton ()->get_file_uid (id_string);
2662+ if (uid != ResourceUID::INVALID_ID) {
2663+ id_string = ResourceUID::get_singleton ()->id_to_text (uid);
2664+ }
2665+ return id_string;
2666+ }
2667+
26742668void VisualShaderEditor::_add_input_port (int p_node, int p_port, int p_port_type, const String &p_name) {
26752669 VisualShader::Type type = get_current_shader_type ();
26762670 Ref<VisualShaderNodeExpression> node = visual_shader->get_node (type, p_node);
@@ -5192,15 +5186,11 @@ void VisualShaderEditor::_param_unselected() {
51925186}
51935187
51945188void VisualShaderEditor::_panning_debounce_timer_timeout () {
5195- String id_string = visual_shader->get_path ();
5196- const ResourceUID::ID uid = ResourceLoader::get_resource_uid (id_string);
5197- if (uid != ResourceUID::INVALID_ID) {
5198- id_string = ResourceUID::get_singleton ()->id_to_text (uid);
5199- }
5189+ const String id_string = _get_vs_editor_cache_id_string ();
52005190
52015191 const int type = get_current_shader_type ();
5202- vs_editor_cache->set_value (" visual_shader " , id_string + " : type" + itos (type) + " :offset" , graph->get_scroll_offset () / EDSCALE);
5203- vs_editor_cache->set_value (" visual_shader " , id_string + " : type" + itos (type) + " :zoom" , graph->get_zoom ());
5192+ vs_editor_cache->set_value (id_string, " type" + itos (type) + " :offset" , graph->get_scroll_offset () / EDSCALE);
5193+ vs_editor_cache->set_value (id_string, " type" + itos (type) + " :zoom" , graph->get_zoom ());
52045194 vs_editor_cache->save (EditorPaths::get_singleton ()->get_project_settings_dir ().path_join (" vs_editor_cache.cfg" ));
52055195}
52065196
@@ -6453,7 +6443,6 @@ void VisualShaderEditor::_bind_methods() {
64536443 ClassDB::bind_method (" _update_parameter" , &VisualShaderEditor::_update_parameter);
64546444 ClassDB::bind_method (" _update_next_previews" , &VisualShaderEditor::_update_next_previews);
64556445 ClassDB::bind_method (" _update_current_param" , &VisualShaderEditor::_update_current_param);
6456- ClassDB::bind_method (" _restore_editor_state" , &VisualShaderEditor::_restore_editor_state);
64576446}
64586447
64596448VisualShaderEditor::VisualShaderEditor () {
@@ -7724,7 +7713,7 @@ VisualShaderEditor::VisualShaderEditor() {
77247713
77257714 panning_debounce_timer = memnew (Timer);
77267715 panning_debounce_timer->set_one_shot (true );
7727- panning_debounce_timer->set_wait_time (0.25 );
7716+ panning_debounce_timer->set_wait_time (1.0 );
77287717 panning_debounce_timer->connect (" timeout" , callable_mp (this , &VisualShaderEditor::_panning_debounce_timer_timeout));
77297718 add_child (panning_debounce_timer);
77307719}
0 commit comments