Path: blob/master/editor/shader/visual_shader_editor_plugin.h
9903 views
/**************************************************************************/1/* visual_shader_editor_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/inspector/editor_properties.h"33#include "editor/plugins/editor_plugin.h"34#include "editor/plugins/editor_resource_conversion_plugin.h"35#include "editor/shader/shader_editor.h"36#include "scene/gui/graph_edit.h"37#include "scene/resources/syntax_highlighter.h"38#include "scene/resources/visual_shader.h"3940class CodeEdit;41class ColorPicker;42class CurveEditor;43class GraphElement;44class GraphFrame;45class HFlowContainer;46class MenuButton;47class PopupPanel;48class RichTextLabel;49class Tree;5051class VisualShaderEditor;52class MaterialEditor;5354class VisualShaderNodePlugin : public RefCounted {55GDCLASS(VisualShaderNodePlugin, RefCounted);5657protected:58VisualShaderEditor *vseditor = nullptr;5960protected:61static void _bind_methods();6263GDVIRTUAL2RC(Object *, _create_editor, Ref<Resource>, Ref<VisualShaderNode>)6465public:66void set_editor(VisualShaderEditor *p_editor);67virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node);68};6970class VSGraphNode : public GraphNode {71GDCLASS(VSGraphNode, GraphNode);7273protected:74void _draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color, const Color &p_rim_color);75virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) override;76};7778class VSRerouteNode : public VSGraphNode {79GDCLASS(VSRerouteNode, GraphNode);8081const float FADE_ANIMATION_LENGTH_SEC = 0.3;8283float icon_opacity = 0.0;8485protected:86void _notification(int p_what);8788virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) override;8990public:91VSRerouteNode();92void set_icon_opacity(float p_opacity);9394void _on_mouse_entered();95void _on_mouse_exited();96};9798class VisualShaderGraphPlugin : public RefCounted {99GDCLASS(VisualShaderGraphPlugin, RefCounted);100101private:102VisualShaderEditor *editor = nullptr;103104struct InputPort {105Button *default_input_button = nullptr;106};107108struct Port {109VisualShaderNode::PortType type = VisualShaderNode::PORT_TYPE_SCALAR;110TextureButton *preview_button = nullptr;111};112113struct Link {114VisualShader::Type type = VisualShader::Type::TYPE_MAX;115VisualShaderNode *visual_node = nullptr;116GraphElement *graph_element = nullptr;117bool preview_visible = false;118int preview_pos = 0;119HashMap<int, InputPort> input_ports;120HashMap<int, Port> output_ports;121VBoxContainer *preview_box = nullptr;122LineEdit *parameter_name = nullptr;123CodeEdit *expression_edit = nullptr;124CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr };125};126127Ref<VisualShader> visual_shader;128HashMap<int, Link> links;129List<VisualShader::Connection> connections;130131Color vector_expanded_color[4];132133// Visual shader specific theme for using MSDF fonts (on GraphNodes) which reduce aliasing at higher zoom levels.134Ref<Theme> vs_msdf_fonts_theme;135136protected:137static void _bind_methods();138139public:140void set_editor(VisualShaderEditor *p_editor);141void register_shader(VisualShader *p_visual_shader);142void set_connections(const List<VisualShader::Connection> &p_connections);143void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element);144void register_output_port(int p_id, int p_port, VisualShaderNode::PortType p_port_type, TextureButton *p_button);145void register_parameter_name(int p_id, LineEdit *p_parameter_name);146void register_default_input_button(int p_node_id, int p_port_id, Button *p_button);147void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit);148void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor);149void clear_links();150void set_shader_type(VisualShader::Type p_type);151bool is_preview_visible(int p_id) const;152void update_node(VisualShader::Type p_type, int p_id);153void update_node_deferred(VisualShader::Type p_type, int p_node_id);154void add_node(VisualShader::Type p_type, int p_id, bool p_just_update, bool p_update_frames);155void remove_node(VisualShader::Type p_type, int p_id, bool p_just_update);156void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);157void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);158void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid);159void update_frames(VisualShader::Type p_type, int p_node);160void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position);161void refresh_node_ports(VisualShader::Type p_type, int p_node);162void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, const Variant &p_value);163void update_parameter_refs();164void set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name);165void update_curve(int p_node_id);166void update_curve_xyz(int p_node_id);167void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression);168void attach_node_to_frame(VisualShader::Type p_type, int p_node_id, int p_frame_id);169void detach_node_from_frame(VisualShader::Type p_type, int p_node_id);170void set_frame_color_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable);171void set_frame_color(VisualShader::Type p_type, int p_node_id, const Color &p_color);172void set_frame_autoshrink_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable);173void update_reroute_nodes();174int get_constant_index(float p_constant) const;175Ref<Script> get_node_script(int p_node_id) const;176void update_theme();177bool is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const;178179VisualShaderGraphPlugin();180};181182class VisualShaderEditedProperty : public RefCounted {183GDCLASS(VisualShaderEditedProperty, RefCounted);184185private:186Variant edited_property;187188protected:189static void _bind_methods();190191public:192void set_edited_property(const Variant &p_variant);193Variant get_edited_property() const;194};195196class VisualShaderEditor : public ShaderEditor {197GDCLASS(VisualShaderEditor, ShaderEditor);198friend class VisualShaderGraphPlugin;199200Ref<ConfigFile> vs_editor_cache; // Keeps the graph offsets and zoom levels for each VisualShader that has been edited.201202PopupPanel *property_editor_popup = nullptr;203EditorProperty *property_editor = nullptr;204int editing_node = -1;205int editing_port = -1;206Ref<VisualShaderEditedProperty> edited_property_holder;207208MaterialEditor *material_editor = nullptr;209Ref<VisualShader> visual_shader;210Ref<ShaderMaterial> preview_material;211Ref<Environment> env;212String param_filter_name;213EditorProperty *current_prop = nullptr;214VBoxContainer *shader_preview_vbox = nullptr;215Button *site_search = nullptr;216Button *toggle_files_button = nullptr;217Control *toggle_files_list = nullptr;218GraphEdit *graph = nullptr;219Button *add_node = nullptr;220MenuButton *varying_button = nullptr;221Button *code_preview_button = nullptr;222Button *shader_preview_button = nullptr;223HFlowContainer *toolbar_hflow = nullptr;224225int last_to_node = -1;226int last_to_port = -1;227Label *info_label = nullptr;228229OptionButton *edit_type = nullptr;230OptionButton *edit_type_standard = nullptr;231OptionButton *edit_type_particles = nullptr;232OptionButton *edit_type_sky = nullptr;233OptionButton *edit_type_fog = nullptr;234CheckBox *custom_mode_box = nullptr;235bool custom_mode_enabled = false;236237bool pending_update_preview = false;238bool shader_error = false;239AcceptDialog *code_preview_window = nullptr;240VBoxContainer *code_preview_vbox = nullptr;241CodeEdit *preview_text = nullptr;242Ref<CodeHighlighter> syntax_highlighter = nullptr;243PanelContainer *error_panel = nullptr;244Label *error_label = nullptr;245246bool pending_custom_scripts_to_delete = false;247List<Ref<Script>> custom_scripts_to_delete;248249bool _block_update_options_menu = false;250bool _block_rebuild_shader = false;251252Point2 saved_node_pos;253bool saved_node_pos_dirty = false;254255ConfirmationDialog *members_dialog = nullptr;256VisualShaderNode::PortType members_input_port_type = VisualShaderNode::PORT_TYPE_MAX;257VisualShaderNode::PortType members_output_port_type = VisualShaderNode::PORT_TYPE_MAX;258PopupMenu *popup_menu = nullptr;259PopupMenu *connection_popup_menu = nullptr;260PopupMenu *constants_submenu = nullptr;261MenuButton *tools = nullptr;262263ConfirmationDialog *add_varying_dialog = nullptr;264OptionButton *varying_type = nullptr;265LineEdit *varying_name = nullptr;266OptionButton *varying_mode = nullptr;267Label *varying_error_label = nullptr;268269ConfirmationDialog *remove_varying_dialog = nullptr;270Tree *varyings = nullptr;271272PopupPanel *frame_title_change_popup = nullptr;273LineEdit *frame_title_change_edit = nullptr;274275PopupPanel *frame_tint_color_pick_popup = nullptr;276ColorPicker *frame_tint_color_picker = nullptr;277278bool code_preview_first = true;279bool code_preview_showed = false;280281bool shader_preview_showed = true;282283LineEdit *param_filter = nullptr;284MenuButton *preview_tools = nullptr;285String selected_param_id;286Tree *parameters = nullptr;287HashMap<String, PropertyInfo> parameter_props;288VBoxContainer *param_vbox = nullptr;289VBoxContainer *param_vbox2 = nullptr;290291enum ShaderModeFlags {292MODE_FLAGS_SPATIAL_CANVASITEM = 1,293MODE_FLAGS_SKY = 2,294MODE_FLAGS_PARTICLES = 4,295MODE_FLAGS_FOG = 8,296};297298int mode = MODE_FLAGS_SPATIAL_CANVASITEM;299VisualShader::Type current_type = VisualShader::Type::TYPE_VERTEX; // The type of the currently edited VisualShader.300301enum TypeFlags {302TYPE_FLAGS_VERTEX = 1,303TYPE_FLAGS_FRAGMENT = 2,304TYPE_FLAGS_LIGHT = 4,305};306307enum ParticlesTypeFlags {308TYPE_FLAGS_EMIT = 1,309TYPE_FLAGS_PROCESS = 2,310TYPE_FLAGS_COLLIDE = 4,311TYPE_FLAGS_EMIT_CUSTOM = 8,312TYPE_FLAGS_PROCESS_CUSTOM = 16,313};314315enum SkyTypeFlags {316TYPE_FLAGS_SKY = 1,317};318319enum FogTypeFlags {320TYPE_FLAGS_FOG = 1,321};322323enum ToolsMenuOptions {324EXPAND_ALL,325COLLAPSE_ALL326};327328enum PreviewToolsMenuOptions {329COPY_PARAMS_FROM_MATERIAL,330PASTE_PARAMS_TO_MATERIAL,331};332333enum NodeMenuOptions {334ADD,335SEPARATOR, // ignore336CUT,337COPY,338PASTE,339DELETE_, // Conflict with WinAPI.340DUPLICATE,341CLEAR_COPY_BUFFER,342SEPARATOR2, // ignore343FLOAT_CONSTANTS,344CONVERT_CONSTANTS_TO_PARAMETERS,345CONVERT_PARAMETERS_TO_CONSTANTS,346UNLINK_FROM_PARENT_FRAME,347SEPARATOR3, // ignore348SET_FRAME_TITLE,349ENABLE_FRAME_COLOR,350SET_FRAME_COLOR,351ENABLE_FRAME_AUTOSHRINK,352};353354enum ConnectionMenuOptions {355INSERT_NEW_NODE,356INSERT_NEW_REROUTE,357DISCONNECT,358};359360enum class VaryingMenuOptions {361ADD,362REMOVE,363};364365Tree *members = nullptr;366AcceptDialog *alert = nullptr;367LineEdit *node_filter = nullptr;368RichTextLabel *node_desc = nullptr;369Label *highend_label = nullptr;370371void _tools_menu_option(int p_idx);372void _show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type = VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PortType p_output_port_type = VisualShaderNode::PORT_TYPE_MAX);373374void _varying_menu_id_pressed(int p_idx);375void _show_add_varying_dialog();376void _show_remove_varying_dialog();377378void _preview_tools_menu_option(int p_idx);379void _clear_preview_param();380void _update_preview_parameter_list();381bool _update_preview_parameter_tree();382383void _update_nodes();384void _update_graph();385386void _restore_editor_state();387388String _get_cache_id_string() const;389String _get_cache_key(const String &p_prop_name) const;390391struct AddOption {392String name;393String category;394String type;395String description;396Vector<Variant> ops;397Ref<Script> script;398int mode = 0;399int return_type = 0;400int func = 0;401bool highend = false;402bool is_custom = false;403bool is_native = false;404mutable int temp_idx = 0;405406AddOption(const String &p_name = String(), const String &p_category = String(), const String &p_type = String(), const String &p_description = String(), const Vector<Variant> &p_ops = Vector<Variant>(), int p_return_type = -1, int p_mode = -1, int p_func = -1, bool p_highend = false) {407name = p_name;408type = p_type;409category = p_category;410description = p_description;411ops = p_ops;412return_type = p_return_type;413mode = p_mode;414func = p_func;415highend = p_highend;416}417};418struct _OptionComparator {419_FORCE_INLINE_ bool operator()(const AddOption &a, const AddOption &b) const {420return a.category.count("/") > b.category.count("/") || (a.category + "/" + a.name).naturalnocasecmp_to(b.category + "/" + b.name) < 0;421}422};423424Vector<AddOption> add_options;425int cubemap_node_option_idx;426int texture2d_node_option_idx;427int texture2d_array_node_option_idx;428int texture3d_node_option_idx;429int custom_node_option_idx;430int curve_node_option_idx;431int curve_xyz_node_option_idx;432int mesh_emitter_option_idx;433List<String> keyword_list;434435List<VisualShaderNodeParameterRef> uniform_refs;436437void _draw_color_over_button(Object *p_obj, Color p_color);438439void _setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops);440void _add_node(int p_idx, const Vector<Variant> &p_ops, const String &p_resource_path = "", int p_node_idx = -1);441void _add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type);442void _remove_varying(const String &p_name);443void _update_options_menu();444void _set_mode(int p_which);445446void _show_preview_text();447void _preview_close_requested();448void _preview_size_changed();449void _update_preview();450void _update_next_previews(int p_node_id);451void _get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const;452String _get_description(int p_idx);453454void _show_shader_preview();455456void _toggle_files_pressed();457458Vector<int> nodes_link_to_frame_buffer; // Contains the nodes that are requested to be linked to a frame. This is used to perform one Undo/Redo operation for dragging nodes.459int frame_node_id_to_link_to = -1;460461struct DragOp {462VisualShader::Type type = VisualShader::Type::TYPE_MAX;463int node = 0;464Vector2 from;465Vector2 to;466};467List<DragOp> drag_buffer;468469Timer *panning_debounce_timer = nullptr;470bool shader_fully_loaded = false;471472bool drag_dirty = false;473void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node);474void _nodes_dragged();475476void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);477void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);478479void _scroll_offset_changed(const Vector2 &p_scroll);480void _node_selected(Object *p_node);481482void _delete_nodes(int p_type, const List<int> &p_nodes);483void _delete_node_request(int p_type, int p_node);484void _delete_nodes_request(const TypedArray<StringName> &p_nodes);485486void _node_changed(int p_id);487488void _nodes_linked_to_frame_request(const TypedArray<StringName> &p_nodes, const StringName &p_frame);489void _frame_rect_changed(const GraphFrame *p_frame, const Rect2 &p_new_rect);490491void _edit_port_default_input(Object *p_button, int p_node, int p_port);492void _port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);493494int to_node = -1;495int to_slot = -1;496int from_node = -1;497int from_slot = -1;498499Ref<GraphEdit::Connection> clicked_connection;500bool connection_node_insert_requested = false;501502HashSet<int> selected_constants;503HashSet<int> selected_parameters;504int selected_frame = -1;505int selected_float_constant = -1;506507void _convert_constants_to_parameters(bool p_vice_versa);508void _detach_nodes_from_frame_request();509void _detach_nodes_from_frame(int p_type, const List<int> &p_nodes);510void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to);511void _update_constant(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port);512void _update_parameter(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port);513514void _unlink_node_from_parent_frame(int p_node_id);515516void _connection_drag_ended();517void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);518void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);519bool _check_node_drop_on_connection(const Vector2 &p_position, Ref<GraphEdit::Connection> *r_closest_connection, int *r_node_id = nullptr, int *r_to_port = nullptr);520void _handle_node_drop_on_connection();521522void _frame_title_popup_show(const Point2 &p_position, int p_node_id);523void _frame_title_popup_hide();524void _frame_title_popup_focus_out();525void _frame_title_text_changed(const String &p_new_text);526void _frame_title_text_submitted(const String &p_new_text);527528void _frame_color_enabled_changed(int p_node_id);529void _frame_color_popup_show(const Point2 &p_position, int p_node_id);530void _frame_color_popup_hide();531void _frame_color_confirm();532void _frame_color_changed(const Color &p_color);533534void _frame_autoshrink_enabled_changed(int p_node_id);535536void _parameter_line_edit_changed(const String &p_text, int p_node_id);537void _parameter_line_edit_focus_out(Object *p_line_edit, int p_node_id);538539void _port_name_focus_out(Object *p_line_edit, int p_node_id, int p_port_id, bool p_output);540541struct CopyItem {542int id;543Ref<VisualShaderNode> node;544Vector2 position;545Vector2 size;546String group_inputs;547String group_outputs;548String expression;549bool disabled = false;550};551552void _dup_copy_nodes(int p_type, List<CopyItem> &r_nodes, List<VisualShader::Connection> &r_connections);553void _dup_paste_nodes(int p_type, List<CopyItem> &r_items, const List<VisualShader::Connection> &p_connections, const Vector2 &p_offset, bool p_duplicate);554555void _duplicate_nodes();556557static Vector2 selection_center;558static List<CopyItem> copy_items_buffer;559static List<VisualShader::Connection> copy_connections_buffer;560561void _clear_copy_buffer();562void _copy_nodes(bool p_cut);563void _paste_nodes(bool p_use_custom_position = false, const Vector2 &p_custom_position = Vector2());564565Vector<Ref<VisualShaderNodePlugin>> plugins;566Ref<VisualShaderGraphPlugin> graph_plugin;567568void _type_selected(int p_id);569void _custom_mode_toggled(bool p_enabled);570571void _input_select_item(Ref<VisualShaderNodeInput> p_input, const String &p_name);572void _parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, const String &p_name);573void _varying_select_item(Ref<VisualShaderNodeVarying> p_varying, const String &p_name);574575void _float_constant_selected(int p_which);576577void _add_input_port(int p_node, int p_port, int p_port_type, const String &p_name);578void _remove_input_port(int p_node, int p_port);579void _change_input_port_type(int p_type, int p_node, int p_port);580void _change_input_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port);581582void _add_output_port(int p_node, int p_port, int p_port_type, const String &p_name);583void _remove_output_port(int p_node, int p_port);584void _change_output_port_type(int p_type, int p_node, int p_port);585void _change_output_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port);586void _expand_output_port(int p_node, int p_port, bool p_expand);587588void _expression_focus_out(Object *p_code_edit, int p_node);589590void _set_node_size(int p_type, int p_node, const Size2 &p_size);591void _node_resized(const Vector2 &p_new_size, int p_type, int p_node);592593void _preview_select_port(int p_node, int p_port);594void _graph_gui_input(const Ref<InputEvent> &p_event);595596void _member_filter_changed(const String &p_text);597void _sbox_input(const Ref<InputEvent> &p_event);598void _member_selected();599void _member_create();600void _member_cancel();601602void _varying_create();603void _varying_validate();604void _varying_type_changed(int p_index);605void _varying_mode_changed(int p_index);606void _varying_name_changed(const String &p_name);607void _varying_deleted();608void _varying_selected();609void _varying_unselected();610void _update_varying_tree();611612void _set_custom_node_option(int p_index, int p_node, int p_op);613614Vector2 menu_point;615void _node_menu_id_pressed(int p_idx);616void _connection_menu_id_pressed(int p_idx);617618Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);619bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;620void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);621622bool _is_available(int p_mode);623void _update_parameters(bool p_update_refs);624void _update_parameter_refs(HashSet<String> &p_names);625void _update_varyings();626627void _update_options_menu_deferred();628void _rebuild_shader_deferred();629630void _visibility_changed();631632void _get_current_mode_limits(int &r_begin_type, int &r_end_type) const;633void _update_custom_script(const Ref<Script> &p_script);634void _script_created(const Ref<Script> &p_script);635void _resource_saved(const Ref<Resource> &p_resource);636void _resource_removed(const Ref<Resource> &p_resource);637void _resources_removed();638639void _param_property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false);640void _update_current_param();641void _param_filter_changed(const String &p_text);642void _param_selected();643void _param_unselected();644645void _help_open();646647protected:648void _notification(int p_what);649static void _bind_methods();650651public:652virtual void edit_shader(const Ref<Shader> &p_shader) override;653virtual void use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) override;654virtual void apply_shaders() override;655virtual bool is_unsaved() const override;656virtual void save_external_data(const String &p_str = "") override;657virtual void validate_script() override;658659void save_editor_layout();660661void set_current_shader_type(VisualShader::Type p_type);662VisualShader::Type get_current_shader_type() const;663664void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);665void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);666667VisualShaderGraphPlugin *get_graph_plugin() { return graph_plugin.ptr(); }668669void clear_custom_types();670void add_custom_type(const String &p_name, const String &p_type, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend);671void set_toggle_list_control(Control *p_control);672673Dictionary get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node);674void update_custom_type(const Ref<Resource> &p_resource);675676virtual Size2 get_minimum_size() const override;677void update_toggle_files_button();678679Ref<VisualShader> get_visual_shader() const { return visual_shader; }680681VisualShaderEditor();682~VisualShaderEditor();683};684685class VisualShaderNodePluginDefault : public VisualShaderNodePlugin {686GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin);687688public:689virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) override;690};691692class EditorPropertyVisualShaderMode : public EditorProperty {693GDCLASS(EditorPropertyVisualShaderMode, EditorProperty);694OptionButton *options = nullptr;695696void _option_selected(int p_which);697698public:699void setup(const Vector<String> &p_options);700virtual void update_property() override;701void set_option_button_clip(bool p_enable);702EditorPropertyVisualShaderMode();703};704705class EditorInspectorVisualShaderModePlugin : public EditorInspectorPlugin {706GDCLASS(EditorInspectorVisualShaderModePlugin, EditorInspectorPlugin);707708public:709virtual bool can_handle(Object *p_object) override;710virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;711};712713class VisualShaderNodePortPreview : public Control {714GDCLASS(VisualShaderNodePortPreview, Control);715TextureRect *checkerboard = nullptr;716Ref<VisualShader> shader;717Ref<ShaderMaterial> preview_mat;718VisualShader::Type type = VisualShader::Type::TYPE_MAX;719int node = 0;720int port = 0;721bool is_valid = false;722void _shader_changed(); //must regen723protected:724void _notification(int p_what);725726public:727virtual Size2 get_minimum_size() const override;728void setup(const Ref<VisualShader> &p_shader, Ref<ShaderMaterial> &p_preview_material, VisualShader::Type p_type, bool p_has_transparency, int p_node, int p_port, bool p_is_valid);729};730731class VisualShaderConversionPlugin : public EditorResourceConversionPlugin {732GDCLASS(VisualShaderConversionPlugin, EditorResourceConversionPlugin);733734public:735virtual String converts_to() const override;736virtual bool handles(const Ref<Resource> &p_resource) const override;737virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;738};739740741