Skip to content

Commit 666d7c0

Browse files
committed
[VisualShader] Fix and improve editor state persistence
1 parent 1218a16 commit 666d7c0

File tree

7 files changed

+139
-106
lines changed

7 files changed

+139
-106
lines changed

doc/classes/VisualShader.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@
186186
</description>
187187
</method>
188188
</methods>
189-
<members>
190-
<member name="graph_offset" type="Vector2" setter="set_graph_offset" getter="get_graph_offset" default="Vector2(0, 0)">
191-
The offset vector of the whole graph.
192-
</member>
193-
</members>
194189
<constants>
195190
<constant name="TYPE_VERTEX" value="0" enum="Type">
196191
A vertex shader, operating on vertices.

editor/plugins/shader_editor_plugin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ void ShaderEditorPlugin::_close_shader(int p_index) {
454454
Control *c = shader_tabs->get_tab_control(p_index);
455455
VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(c);
456456
if (vs_editor) {
457+
vs_editor->save_editor_layout();
457458
file_menu->get_parent()->remove_child(file_menu);
458459
menu_hb->add_child(file_menu);
459460
menu_hb->move_child(file_menu, 0);

editor/plugins/visual_shader_editor_plugin.cpp

Lines changed: 111 additions & 64 deletions
Large diffs are not rendered by default.

editor/plugins/visual_shader_editor_plugin.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ class VisualShaderGraphPlugin : public RefCounted {
175175
Ref<Script> get_node_script(int p_node_id) const;
176176
void update_theme();
177177
bool is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const;
178-
VisualShader::Type get_shader_type() const;
179178

180179
VisualShaderGraphPlugin();
181180
};
@@ -198,6 +197,8 @@ class VisualShaderEditor : public ShaderEditor {
198197
GDCLASS(VisualShaderEditor, ShaderEditor);
199198
friend class VisualShaderGraphPlugin;
200199

200+
Ref<ConfigFile> vs_editor_cache; // Keeps the graph offsets and zoom levels for each VisualShader that has been edited.
201+
201202
PopupPanel *property_editor_popup = nullptr;
202203
EditorProperty *property_editor = nullptr;
203204
int editing_node = -1;
@@ -295,6 +296,7 @@ class VisualShaderEditor : public ShaderEditor {
295296
};
296297

297298
int mode = MODE_FLAGS_SPATIAL_CANVASITEM;
299+
VisualShader::Type current_type = VisualShader::Type::TYPE_VERTEX; // The type of the currently edited VisualShader.
298300

299301
enum TypeFlags {
300302
TYPE_FLAGS_VERTEX = 1,
@@ -381,6 +383,11 @@ class VisualShaderEditor : public ShaderEditor {
381383
void _update_nodes();
382384
void _update_graph();
383385

386+
void _restore_editor_state();
387+
388+
String _get_cache_id_string() const;
389+
String _get_cache_key(const String &p_prop_name) const;
390+
384391
struct AddOption {
385392
String name;
386393
String category;
@@ -459,15 +466,17 @@ class VisualShaderEditor : public ShaderEditor {
459466
};
460467
List<DragOp> drag_buffer;
461468

469+
Timer *panning_debounce_timer = nullptr;
470+
bool shader_fully_loaded = false;
471+
462472
bool drag_dirty = false;
463473
void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node);
464474
void _nodes_dragged();
465-
bool updating = false;
466475

467476
void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
468477
void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
469478

470-
void _scroll_changed(const Vector2 &p_scroll);
479+
void _scroll_offset_changed(const Vector2 &p_scroll);
471480
void _node_selected(Object *p_node);
472481

473482
void _delete_nodes(int p_type, const List<int> &p_nodes);
@@ -556,7 +565,7 @@ class VisualShaderEditor : public ShaderEditor {
556565
Vector<Ref<VisualShaderNodePlugin>> plugins;
557566
Ref<VisualShaderGraphPlugin> graph_plugin;
558567

559-
void _mode_selected(int p_id);
568+
void _type_selected(int p_id);
560569
void _custom_mode_toggled(bool p_enabled);
561570

562571
void _input_select_item(Ref<VisualShaderNodeInput> p_input, const String &p_name);
@@ -565,8 +574,6 @@ class VisualShaderEditor : public ShaderEditor {
565574

566575
void _float_constant_selected(int p_which);
567576

568-
VisualShader::Type get_current_shader_type() const;
569-
570577
void _add_input_port(int p_node, int p_port, int p_port_type, const String &p_name);
571578
void _remove_input_port(int p_node, int p_port);
572579
void _change_input_port_type(int p_type, int p_node, int p_port);
@@ -647,6 +654,12 @@ class VisualShaderEditor : public ShaderEditor {
647654
virtual bool is_unsaved() const override;
648655
virtual void save_external_data(const String &p_str = "") override;
649656
virtual void validate_script() override;
657+
658+
void save_editor_layout();
659+
660+
void set_current_shader_type(VisualShader::Type p_type);
661+
VisualShader::Type get_current_shader_type() const;
662+
650663
virtual Control *get_top_bar() override;
651664

652665
void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);

misc/extension_api_validation/4.4-stable.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,11 @@ Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/a
321321
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments': size changed value in new API, from 11 to 12.
322322

323323
Optional argument added. Compatibility methods registered.
324+
325+
326+
GH-98566
327+
--------
328+
Validate extension JSON: API was removed: classes/VisualShader/methods/set_graph_offset
329+
Validate extension JSON: API was removed: classes/VisualShader/methods/get_graph_offset
330+
331+
The graph_offset property was removed from the resource. This information is now stored in `vs_editor_cache.cfg`.

scene/resources/visual_shader.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -822,14 +822,6 @@ VisualShaderNodeCustom::VisualShaderNodeCustom() {
822822

823823
/////////////////////////////////////////////////////////
824824

825-
void VisualShader::set_shader_type(Type p_type) {
826-
current_type = p_type;
827-
}
828-
829-
VisualShader::Type VisualShader::get_shader_type() const {
830-
return current_type;
831-
}
832-
833825
void VisualShader::add_varying(const String &p_name, VaryingMode p_mode, VaryingType p_type) {
834826
ERR_FAIL_COND(!p_name.is_valid_ascii_identifier());
835827
ERR_FAIL_INDEX((int)p_mode, (int)VARYING_MODE_MAX);
@@ -1466,14 +1458,6 @@ void VisualShader::set_mode(Mode p_mode) {
14661458
notify_property_list_changed();
14671459
}
14681460

1469-
void VisualShader::set_graph_offset(const Vector2 &p_offset) {
1470-
graph_offset = p_offset;
1471-
}
1472-
1473-
Vector2 VisualShader::get_graph_offset() const {
1474-
return graph_offset;
1475-
}
1476-
14771461
Shader::Mode VisualShader::get_mode() const {
14781462
return shader_mode;
14791463
}
@@ -3157,9 +3141,6 @@ void VisualShader::_bind_methods() {
31573141

31583142
ClassDB::bind_method(D_METHOD("get_node_connections", "type"), &VisualShader::_get_node_connections);
31593143

3160-
ClassDB::bind_method(D_METHOD("set_graph_offset", "offset"), &VisualShader::set_graph_offset);
3161-
ClassDB::bind_method(D_METHOD("get_graph_offset"), &VisualShader::get_graph_offset);
3162-
31633144
ClassDB::bind_method(D_METHOD("attach_node_to_frame", "type", "id", "frame"), &VisualShader::attach_node_to_frame);
31643145
ClassDB::bind_method(D_METHOD("detach_node_from_frame", "type", "id"), &VisualShader::detach_node_from_frame);
31653146

@@ -3173,8 +3154,6 @@ void VisualShader::_bind_methods() {
31733154

31743155
ClassDB::bind_method(D_METHOD("_update_shader"), &VisualShader::_update_shader);
31753156

3176-
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "graph_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_graph_offset", "get_graph_offset");
3177-
31783157
ADD_PROPERTY_DEFAULT("code", ""); // Inherited from Shader, prevents showing default code as override in docs.
31793158

31803159
BIND_ENUM_CONSTANT(TYPE_VERTEX);

scene/resources/visual_shader.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ class VisualShader : public Shader {
114114
};
115115

116116
private:
117-
Type current_type;
118-
119117
struct Node {
120118
Ref<VisualShaderNode> node;
121119
Vector2 position;
@@ -133,8 +131,6 @@ class VisualShader : public Shader {
133131

134132
TypedArray<Dictionary> _get_node_connections(Type p_type) const;
135133

136-
Vector2 graph_offset;
137-
138134
HashMap<String, int> modes;
139135
HashSet<StringName> flags;
140136

@@ -180,9 +176,6 @@ class VisualShader : public Shader {
180176
virtual void reset_state() override;
181177

182178
public: // internal methods
183-
void set_shader_type(Type p_type);
184-
Type get_shader_type() const;
185-
186179
enum {
187180
NODE_ID_INVALID = -1,
188181
NODE_ID_OUTPUT = 0,
@@ -249,9 +242,6 @@ class VisualShader : public Shader {
249242

250243
virtual bool is_text_shader() const override;
251244

252-
void set_graph_offset(const Vector2 &p_offset);
253-
Vector2 get_graph_offset() const;
254-
255245
String generate_preview_shader(Type p_type, int p_node, int p_port, Vector<DefaultTextureParam> &r_default_tex_params) const;
256246

257247
String validate_port_name(const String &p_port_name, VisualShaderNode *p_node, int p_port_id, bool p_output) const;

0 commit comments

Comments
 (0)