| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "editor/inspector/editor_properties.h" |
| 34 |
#include "editor/plugins/editor_plugin.h" |
| 35 |
#include "editor/plugins/editor_resource_conversion_plugin.h" |
| 36 |
#include "editor/shader/shader_editor.h" |
| 37 |
#include "scene/gui/graph_edit.h" |
| 38 |
#include "scene/resources/syntax_highlighter.h" |
| 39 |
#include "scene/resources/visual_shader.h" |
| 40 |
|
| 41 |
class CodeEdit; |
| 42 |
class ColorPicker; |
| 43 |
class CurveEditor; |
| 44 |
class GraphElement; |
| 45 |
class GraphFrame; |
| 46 |
class HFlowContainer; |
| 47 |
class MenuButton; |
| 48 |
class PopupPanel; |
| 49 |
class RichTextLabel; |
| 50 |
class Tree; |
| 51 |
|
| 52 |
class VisualShaderEditor; |
| 53 |
class MaterialEditor; |
| 54 |
|
| 55 |
class VisualShaderNodePlugin : public RefCounted { |
| 56 |
GDCLASS(VisualShaderNodePlugin, RefCounted); |
| 57 |
|
| 58 |
protected: |
| 59 |
VisualShaderEditor *vseditor = nullptr; |
| 60 |
|
| 61 |
protected: |
| 62 |
static void _bind_methods(); |
| 63 |
|
| 64 |
GDVIRTUAL2RC(Object *, _create_editor, Ref<Resource>, Ref<VisualShaderNode>) |
| 65 |
|
| 66 |
public: |
| 67 |
void set_editor(VisualShaderEditor *p_editor); |
| 68 |
virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node); |
| 69 |
}; |
| 70 |
|
| 71 |
class VSGraphNode : public GraphNode { |
| 72 |
GDCLASS(VSGraphNode, GraphNode); |
| 73 |
|
| 74 |
protected: |
| 75 |
void _draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color, const Color &p_rim_color); |
| 76 |
virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) override; |
| 77 |
}; |
| 78 |
|
| 79 |
class VSRerouteNode : public VSGraphNode { |
| 80 |
GDCLASS(VSRerouteNode, GraphNode); |
| 81 |
|
| 82 |
const float FADE_ANIMATION_LENGTH_SEC = 0.3; |
| 83 |
|
| 84 |
float icon_opacity = 0.0; |
| 85 |
|
| 86 |
protected: |
| 87 |
void _notification(int p_what); |
| 88 |
|
| 89 |
virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) override; |
| 90 |
|
| 91 |
public: |
| 92 |
VSRerouteNode(); |
| 93 |
void set_icon_opacity(float p_opacity); |
| 94 |
|
| 95 |
void _on_mouse_entered(); |
| 96 |
void _on_mouse_exited(); |
| 97 |
}; |
| 98 |
|
| 99 |
class VisualShaderGraphPlugin : public RefCounted { |
| 100 |
GDCLASS(VisualShaderGraphPlugin, RefCounted); |
| 101 |
|
| 102 |
private: |
| 103 |
VisualShaderEditor *editor = nullptr; |
| 104 |
|
| 105 |
struct InputPort { |
| 106 |
Button *default_input_button = nullptr; |
| 107 |
}; |
| 108 |
|
| 109 |
struct Port { |
| 110 |
VisualShaderNode::PortType type = VisualShaderNode::PORT_TYPE_SCALAR; |
| 111 |
TextureButton *preview_button = nullptr; |
| 112 |
}; |
| 113 |
|
| 114 |
struct Link { |
| 115 |
VisualShader::Type type = VisualShader::Type::TYPE_MAX; |
| 116 |
VisualShaderNode *visual_node = nullptr; |
| 117 |
GraphElement *graph_element = nullptr; |
| 118 |
bool preview_visible = false; |
| 119 |
int preview_pos = 0; |
| 120 |
HashMap<int, InputPort> input_ports; |
| 121 |
HashMap<int, Port> output_ports; |
| 122 |
VBoxContainer *preview_box = nullptr; |
| 123 |
LineEdit *parameter_name = nullptr; |
| 124 |
CodeEdit *expression_edit = nullptr; |
| 125 |
CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr }; |
| 126 |
}; |
| 127 |
|
| 128 |
Ref<VisualShader> visual_shader; |
| 129 |
HashMap<int, Link> links; |
| 130 |
List<VisualShader::Connection> connections; |
| 131 |
|
| 132 |
Color vector_expanded_color[4]; |
| 133 |
|
| 134 |
|
| 135 |
Ref<Theme> vs_msdf_fonts_theme; |
| 136 |
|
| 137 |
protected: |
| 138 |
static void _bind_methods(); |
| 139 |
|
| 140 |
public: |
| 141 |
void set_editor(VisualShaderEditor *p_editor); |
| 142 |
void register_shader(VisualShader *p_visual_shader); |
| 143 |
void set_connections(const List<VisualShader::Connection> &p_connections); |
| 144 |
void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element); |
| 145 |
void register_output_port(int p_id, int p_port, VisualShaderNode::PortType p_port_type, TextureButton *p_button); |
| 146 |
void register_parameter_name(int p_id, LineEdit *p_parameter_name); |
| 147 |
void register_default_input_button(int p_node_id, int p_port_id, Button *p_button); |
| 148 |
void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit); |
| 149 |
void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor); |
| 150 |
void clear_links(); |
| 151 |
void set_shader_type(VisualShader::Type p_type); |
| 152 |
bool is_preview_visible(int p_id) const; |
| 153 |
void update_node(VisualShader::Type p_type, int p_id); |
| 154 |
void update_node_deferred(VisualShader::Type p_type, int p_node_id); |
| 155 |
void add_node(VisualShader::Type p_type, int p_id, bool p_just_update, bool p_update_frames); |
| 156 |
void remove_node(VisualShader::Type p_type, int p_id, bool p_just_update); |
| 157 |
void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); |
| 158 |
void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); |
| 159 |
void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid); |
| 160 |
void update_frames(VisualShader::Type p_type, int p_node); |
| 161 |
void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position); |
| 162 |
void refresh_node_ports(VisualShader::Type p_type, int p_node); |
| 163 |
void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, const Variant &p_value); |
| 164 |
void update_parameter_refs(); |
| 165 |
void set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name); |
| 166 |
void update_curve(int p_node_id); |
| 167 |
void update_curve_xyz(int p_node_id); |
| 168 |
void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression); |
| 169 |
void attach_node_to_frame(VisualShader::Type p_type, int p_node_id, int p_frame_id); |
| 170 |
void detach_node_from_frame(VisualShader::Type p_type, int p_node_id); |
| 171 |
void set_frame_color_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable); |
| 172 |
void set_frame_color(VisualShader::Type p_type, int p_node_id, const Color &p_color); |
| 173 |
void set_frame_autoshrink_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable); |
| 174 |
void update_reroute_nodes(); |
| 175 |
int get_constant_index(float p_constant) const; |
| 176 |
Ref<Script> get_node_script(int p_node_id) const; |
| 177 |
void update_theme(); |
| 178 |
bool is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const; |
| 179 |
|
| 180 |
VisualShaderGraphPlugin(); |
| 181 |
}; |
| 182 |
|
| 183 |
class VisualShaderEditedProperty : public RefCounted { |
| 184 |
GDCLASS(VisualShaderEditedProperty, RefCounted); |
| 185 |
|
| 186 |
private: |
| 187 |
Variant edited_property; |
| 188 |
|
| 189 |
protected: |
| 190 |
static void _bind_methods(); |
| 191 |
|
| 192 |
public: |
| 193 |
void set_edited_property(const Variant &p_variant); |
| 194 |
Variant get_edited_property() const; |
| 195 |
}; |
| 196 |
|
| 197 |
class VisualShaderEditor : public ShaderEditor { |
| 198 |
GDCLASS(VisualShaderEditor, ShaderEditor); |
| 199 |
friend class VisualShaderGraphPlugin; |
| 200 |
|
| 201 |
Ref<ConfigFile> vs_editor_cache; |
| 202 |
|
| 203 |
PopupPanel *property_editor_popup = nullptr; |
| 204 |
EditorProperty *property_editor = nullptr; |
| 205 |
int editing_node = -1; |
| 206 |
int editing_port = -1; |
| 207 |
Ref<VisualShaderEditedProperty> edited_property_holder; |
| 208 |
|
| 209 |
MaterialEditor *material_editor = nullptr; |
| 210 |
Ref<VisualShader> visual_shader; |
| 211 |
Ref<ShaderMaterial> preview_material; |
| 212 |
Ref<Environment> env; |
| 213 |
String param_filter_name; |
| 214 |
EditorProperty *current_prop = nullptr; |
| 215 |
VBoxContainer *shader_preview_vbox = nullptr; |
| 216 |
Button *site_search = nullptr; |
| 217 |
Button *toggle_files_button = nullptr; |
| 218 |
Control *toggle_files_list = nullptr; |
| 219 |
GraphEdit *graph = nullptr; |
| 220 |
Button *add_node = nullptr; |
| 221 |
MenuButton *varying_button = nullptr; |
| 222 |
Button *code_preview_button = nullptr; |
| 223 |
Button *shader_preview_button = nullptr; |
| 224 |
HFlowContainer *toolbar_hflow = nullptr; |
| 225 |
|
| 226 |
int last_to_node = -1; |
| 227 |
int last_to_port = -1; |
| 228 |
Label *info_label = nullptr; |
| 229 |
|
| 230 |
OptionButton *edit_type = nullptr; |
| 231 |
OptionButton *edit_type_standard = nullptr; |
| 232 |
OptionButton *edit_type_particles = nullptr; |
| 233 |
OptionButton *edit_type_sky = nullptr; |
| 234 |
OptionButton *edit_type_fog = nullptr; |
| 235 |
CheckBox *custom_mode_box = nullptr; |
| 236 |
bool custom_mode_enabled = false; |
| 237 |
|
| 238 |
bool theme_dirty = false; |
| 239 |
bool pending_update_preview = false; |
| 240 |
bool shader_error = false; |
| 241 |
AcceptDialog *code_preview_window = nullptr; |
| 242 |
VBoxContainer *code_preview_vbox = nullptr; |
| 243 |
CodeEdit *preview_text = nullptr; |
| 244 |
Ref<CodeHighlighter> syntax_highlighter = nullptr; |
| 245 |
PanelContainer *error_panel = nullptr; |
| 246 |
Label *error_label = nullptr; |
| 247 |
|
| 248 |
bool pending_custom_scripts_to_delete = false; |
| 249 |
List<Ref<Script>> custom_scripts_to_delete; |
| 250 |
|
| 251 |
bool _block_update_options_menu = false; |
| 252 |
bool _block_rebuild_shader = false; |
| 253 |
|
| 254 |
Point2 saved_node_pos; |
| 255 |
bool saved_node_pos_dirty = false; |
| 256 |
|
| 257 |
ConfirmationDialog *members_dialog = nullptr; |
| 258 |
VisualShaderNode::PortType members_input_port_type = VisualShaderNode::PORT_TYPE_MAX; |
| 259 |
VisualShaderNode::PortType members_output_port_type = VisualShaderNode::PORT_TYPE_MAX; |
| 260 |
PopupMenu *popup_menu = nullptr; |
| 261 |
PopupMenu *connection_popup_menu = nullptr; |
| 262 |
PopupMenu *constants_submenu = nullptr; |
| 263 |
MenuButton *tools = nullptr; |
| 264 |
|
| 265 |
ConfirmationDialog *add_varying_dialog = nullptr; |
| 266 |
OptionButton *varying_type = nullptr; |
| 267 |
LineEdit *varying_name = nullptr; |
| 268 |
OptionButton *varying_mode = nullptr; |
| 269 |
Label *varying_error_label = nullptr; |
| 270 |
|
| 271 |
ConfirmationDialog *remove_varying_dialog = nullptr; |
| 272 |
Tree *varyings = nullptr; |
| 273 |
|
| 274 |
PopupPanel *frame_title_change_popup = nullptr; |
| 275 |
LineEdit *frame_title_change_edit = nullptr; |
| 276 |
|
| 277 |
PopupPanel *frame_tint_color_pick_popup = nullptr; |
| 278 |
ColorPicker *frame_tint_color_picker = nullptr; |
| 279 |
|
| 280 |
bool code_preview_first = true; |
| 281 |
bool code_preview_showed = false; |
| 282 |
|
| 283 |
bool shader_preview_showed = true; |
| 284 |
|
| 285 |
LineEdit *param_filter = nullptr; |
| 286 |
MenuButton *preview_tools = nullptr; |
| 287 |
String selected_param_id; |
| 288 |
Tree *parameters = nullptr; |
| 289 |
HashMap<String, PropertyInfo> parameter_props; |
| 290 |
VBoxContainer *param_vbox = nullptr; |
| 291 |
VBoxContainer *param_vbox2 = nullptr; |
| 292 |
|
| 293 |
float cached_theme_base_scale = 1.0f; |
| 294 |
|
| 295 |
enum ShaderModeFlags { |
| 296 |
MODE_FLAGS_SPATIAL_CANVASITEM = 1, |
| 297 |
MODE_FLAGS_SKY = 2, |
| 298 |
MODE_FLAGS_PARTICLES = 4, |
| 299 |
MODE_FLAGS_FOG = 8, |
| 300 |
}; |
| 301 |
|
| 302 |
int mode = MODE_FLAGS_SPATIAL_CANVASITEM; |
| 303 |
VisualShader::Type current_type = VisualShader::Type::TYPE_VERTEX; |
| 304 |
|
| 305 |
enum TypeFlags { |
| 306 |
TYPE_FLAGS_VERTEX = 1, |
| 307 |
TYPE_FLAGS_FRAGMENT = 2, |
| 308 |
TYPE_FLAGS_LIGHT = 4, |
| 309 |
}; |
| 310 |
|
| 311 |
enum ParticlesTypeFlags { |
| 312 |
TYPE_FLAGS_EMIT = 1, |
| 313 |
TYPE_FLAGS_PROCESS = 2, |
| 314 |
TYPE_FLAGS_COLLIDE = 4, |
| 315 |
TYPE_FLAGS_EMIT_CUSTOM = 8, |
| 316 |
TYPE_FLAGS_PROCESS_CUSTOM = 16, |
| 317 |
}; |
| 318 |
|
| 319 |
enum SkyTypeFlags { |
| 320 |
TYPE_FLAGS_SKY = 1, |
| 321 |
}; |
| 322 |
|
| 323 |
enum FogTypeFlags { |
| 324 |
TYPE_FLAGS_FOG = 1, |
| 325 |
}; |
| 326 |
|
| 327 |
enum ToolsMenuOptions { |
| 328 |
EXPAND_ALL, |
| 329 |
COLLAPSE_ALL |
| 330 |
}; |
| 331 |
|
| 332 |
enum PreviewToolsMenuOptions { |
| 333 |
COPY_PARAMS_FROM_MATERIAL, |
| 334 |
PASTE_PARAMS_TO_MATERIAL, |
| 335 |
}; |
| 336 |
|
| 337 |
enum NodeMenuOptions { |
| 338 |
ADD, |
| 339 |
SEPARATOR, |
| 340 |
CUT, |
| 341 |
COPY, |
| 342 |
PASTE, |
| 343 |
DELETE_, |
| 344 |
DUPLICATE, |
| 345 |
CLEAR_COPY_BUFFER, |
| 346 |
SEPARATOR2, |
| 347 |
FLOAT_CONSTANTS, |
| 348 |
CONVERT_CONSTANTS_TO_PARAMETERS, |
| 349 |
CONVERT_PARAMETERS_TO_CONSTANTS, |
| 350 |
UNLINK_FROM_PARENT_FRAME, |
| 351 |
SEPARATOR3, |
| 352 |
SET_FRAME_TITLE, |
| 353 |
ENABLE_FRAME_COLOR, |
| 354 |
SET_FRAME_COLOR, |
| 355 |
ENABLE_FRAME_AUTOSHRINK, |
| 356 |
}; |
| 357 |
|
| 358 |
enum ConnectionMenuOptions { |
| 359 |
INSERT_NEW_NODE, |
| 360 |
INSERT_NEW_REROUTE, |
| 361 |
DISCONNECT, |
| 362 |
}; |
| 363 |
|
| 364 |
enum class VaryingMenuOptions { |
| 365 |
ADD, |
| 366 |
REMOVE, |
| 367 |
}; |
| 368 |
|
| 369 |
Tree *members = nullptr; |
| 370 |
AcceptDialog *alert = nullptr; |
| 371 |
LineEdit *node_filter = nullptr; |
| 372 |
RichTextLabel *node_desc = nullptr; |
| 373 |
Label *highend_label = nullptr; |
| 374 |
|
| 375 |
void _tools_menu_option(int p_idx); |
| 376 |
void _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); |
| 377 |
|
| 378 |
void _varying_menu_id_pressed(int p_idx); |
| 379 |
void _show_add_varying_dialog(); |
| 380 |
void _show_remove_varying_dialog(); |
| 381 |
|
| 382 |
void _preview_tools_menu_option(int p_idx); |
| 383 |
void _clear_preview_param(); |
| 384 |
void _update_preview_parameter_list(); |
| 385 |
bool _update_preview_parameter_tree(); |
| 386 |
|
| 387 |
void _update_nodes(); |
| 388 |
void _update_graph(); |
| 389 |
|
| 390 |
void _restore_editor_state(); |
| 391 |
|
| 392 |
String _get_cache_id_string() const; |
| 393 |
String _get_cache_key(const String &p_prop_name) const; |
| 394 |
|
| 395 |
struct AddOption { |
| 396 |
String name; |
| 397 |
String category; |
| 398 |
String type; |
| 399 |
String description; |
| 400 |
Vector<Variant> ops; |
| 401 |
Ref<Script> script; |
| 402 |
int mode = 0; |
| 403 |
int return_type = 0; |
| 404 |
int func = 0; |
| 405 |
bool highend = false; |
| 406 |
bool is_custom = false; |
| 407 |
bool is_native = false; |
| 408 |
mutable int temp_idx = 0; |
| 409 |
|
| 410 |
AddOption(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) { |
| 411 |
name = p_name; |
| 412 |
type = p_type; |
| 413 |
category = p_category; |
| 414 |
description = p_description; |
| 415 |
ops = p_ops; |
| 416 |
return_type = p_return_type; |
| 417 |
mode = p_mode; |
| 418 |
func = p_func; |
| 419 |
highend = p_highend; |
| 420 |
} |
| 421 |
}; |
| 422 |
struct _OptionComparator { |
| 423 |
_FORCE_INLINE_ bool operator()(const AddOption &a, const AddOption &b) const { |
| 424 |
return a.category.count("/") > b.category.count("/") || (a.category + "/" + a.name).naturalnocasecmp_to(b.category + "/" + b.name) < 0; |
| 425 |
} |
| 426 |
}; |
| 427 |
|
| 428 |
Vector<AddOption> add_options; |
| 429 |
int cubemap_node_option_idx; |
| 430 |
int texture2d_node_option_idx; |
| 431 |
int texture2d_array_node_option_idx; |
| 432 |
int texture3d_node_option_idx; |
| 433 |
int custom_node_option_idx; |
| 434 |
int curve_node_option_idx; |
| 435 |
int curve_xyz_node_option_idx; |
| 436 |
int mesh_emitter_option_idx; |
| 437 |
List<String> keyword_list; |
| 438 |
|
| 439 |
List<VisualShaderNodeParameterRef> uniform_refs; |
| 440 |
|
| 441 |
void _draw_color_over_button(Object *p_obj, Color p_color); |
| 442 |
|
| 443 |
void _setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops); |
| 444 |
void _add_node(int p_idx, const Vector<Variant> &p_ops, const String &p_resource_path = "", int p_node_idx = -1); |
| 445 |
void _add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type); |
| 446 |
void _remove_varying(const String &p_name); |
| 447 |
void _update_options_menu(); |
| 448 |
void _set_mode(int p_which); |
| 449 |
|
| 450 |
void _show_preview_text(); |
| 451 |
void _preview_close_requested(); |
| 452 |
void _preview_size_changed(); |
| 453 |
void _update_preview(); |
| 454 |
void _update_next_previews(int p_node_id); |
| 455 |
void _get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const; |
| 456 |
String _get_description(int p_idx); |
| 457 |
|
| 458 |
void _show_shader_preview(); |
| 459 |
|
| 460 |
void _toggle_files_pressed(); |
| 461 |
|
| 462 |
Vector<int> nodes_link_to_frame_buffer; |
| 463 |
int frame_node_id_to_link_to = -1; |
| 464 |
|
| 465 |
struct DragOp { |
| 466 |
VisualShader::Type type = VisualShader::Type::TYPE_MAX; |
| 467 |
int node = 0; |
| 468 |
Vector2 from; |
| 469 |
Vector2 to; |
| 470 |
}; |
| 471 |
List<DragOp> drag_buffer; |
| 472 |
|
| 473 |
Timer *panning_debounce_timer = nullptr; |
| 474 |
bool shader_fully_loaded = false; |
| 475 |
|
| 476 |
bool drag_dirty = false; |
| 477 |
void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node); |
| 478 |
void _nodes_dragged(); |
| 479 |
|
| 480 |
void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index); |
| 481 |
void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index); |
| 482 |
|
| 483 |
void _scroll_offset_changed(const Vector2 &p_scroll); |
| 484 |
void _node_selected(Object *p_node); |
| 485 |
|
| 486 |
void _delete_nodes(int p_type, const List<int> &p_nodes); |
| 487 |
void _delete_node_request(int p_type, int p_node); |
| 488 |
void _delete_nodes_request(const TypedArray<StringName> &p_nodes); |
| 489 |
|
| 490 |
void _node_changed(int p_id); |
| 491 |
|
| 492 |
void _nodes_linked_to_frame_request(const TypedArray<StringName> &p_nodes, const StringName &p_frame); |
| 493 |
void _frame_rect_changed(const GraphFrame *p_frame, const Rect2 &p_new_rect); |
| 494 |
|
| 495 |
void _edit_port_default_input(Object *p_button, int p_node, int p_port); |
| 496 |
void _port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); |
| 497 |
|
| 498 |
int to_node = -1; |
| 499 |
int to_slot = -1; |
| 500 |
int from_node = -1; |
| 501 |
int from_slot = -1; |
| 502 |
|
| 503 |
Ref<GraphEdit::Connection> clicked_connection; |
| 504 |
bool connection_node_insert_requested = false; |
| 505 |
|
| 506 |
HashSet<int> selected_constants; |
| 507 |
HashSet<int> selected_parameters; |
| 508 |
int selected_frame = -1; |
| 509 |
int selected_float_constant = -1; |
| 510 |
|
| 511 |
void _convert_constants_to_parameters(bool p_vice_versa); |
| 512 |
void _detach_nodes_from_frame_request(); |
| 513 |
void _detach_nodes_from_frame(int p_type, const List<int> &p_nodes); |
| 514 |
void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to); |
| 515 |
void _update_constant(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port); |
| 516 |
void _update_parameter(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port); |
| 517 |
|
| 518 |
void _unlink_node_from_parent_frame(int p_node_id); |
| 519 |
|
| 520 |
void _connection_drag_ended(); |
| 521 |
void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position); |
| 522 |
void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position); |
| 523 |
bool _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); |
| 524 |
void _handle_node_drop_on_connection(); |
| 525 |
|
| 526 |
void _frame_title_popup_show(const Point2 &p_position, int p_node_id); |
| 527 |
void _frame_title_popup_hide(); |
| 528 |
void _frame_title_popup_focus_out(); |
| 529 |
void _frame_title_text_changed(const String &p_new_text); |
| 530 |
void _frame_title_text_submitted(const String &p_new_text); |
| 531 |
|
| 532 |
void _frame_color_enabled_changed(int p_node_id); |
| 533 |
void _frame_color_popup_show(const Point2 &p_position, int p_node_id); |
| 534 |
void _frame_color_popup_hide(); |
| 535 |
void _frame_color_confirm(); |
| 536 |
void _frame_color_changed(const Color &p_color); |
| 537 |
|
| 538 |
void _frame_autoshrink_enabled_changed(int p_node_id); |
| 539 |
|
| 540 |
void _parameter_line_edit_changed(const String &p_text, int p_node_id); |
| 541 |
void _parameter_line_edit_focus_out(Object *p_line_edit, int p_node_id); |
| 542 |
|
| 543 |
void _port_name_focus_out(Object *p_line_edit, int p_node_id, int p_port_id, bool p_output); |
| 544 |
|
| 545 |
struct CopyItem { |
| 546 |
int id; |
| 547 |
Ref<VisualShaderNode> node; |
| 548 |
Vector2 position; |
| 549 |
Vector2 size; |
| 550 |
String group_inputs; |
| 551 |
String group_outputs; |
| 552 |
String expression; |
| 553 |
bool disabled = false; |
| 554 |
}; |
| 555 |
|
| 556 |
void _dup_copy_nodes(int p_type, List<CopyItem> &r_nodes, List<VisualShader::Connection> &r_connections); |
| 557 |
void _dup_paste_nodes(int p_type, List<CopyItem> &r_items, const List<VisualShader::Connection> &p_connections, const Vector2 &p_offset, bool p_duplicate); |
| 558 |
|
| 559 |
void _duplicate_nodes(); |
| 560 |
|
| 561 |
static Vector2 selection_center; |
| 562 |
static List<CopyItem> copy_items_buffer; |
| 563 |
static List<VisualShader::Connection> copy_connections_buffer; |
| 564 |
|
| 565 |
void _clear_copy_buffer(); |
| 566 |
void _copy_nodes(bool p_cut); |
| 567 |
void _paste_nodes(bool p_use_custom_position = false, const Vector2 &p_custom_position = Vector2()); |
| 568 |
|
| 569 |
Vector<Ref<VisualShaderNodePlugin>> plugins; |
| 570 |
Ref<VisualShaderGraphPlugin> graph_plugin; |
| 571 |
|
| 572 |
void _type_selected(int p_id); |
| 573 |
void _custom_mode_toggled(bool p_enabled); |
| 574 |
|
| 575 |
void _input_select_item(Ref<VisualShaderNodeInput> p_input, const String &p_name); |
| 576 |
void _parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, const String &p_name); |
| 577 |
void _varying_select_item(Ref<VisualShaderNodeVarying> p_varying, const String &p_name); |
| 578 |
|
| 579 |
void _float_constant_selected(int p_which); |
| 580 |
|
| 581 |
void _add_input_port(int p_node, int p_port, int p_port_type, const String &p_name); |
| 582 |
void _remove_input_port(int p_node, int p_port); |
| 583 |
void _change_input_port_type(int p_type, int p_node, int p_port); |
| 584 |
void _change_input_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port); |
| 585 |
|
| 586 |
void _add_output_port(int p_node, int p_port, int p_port_type, const String &p_name); |
| 587 |
void _remove_output_port(int p_node, int p_port); |
| 588 |
void _change_output_port_type(int p_type, int p_node, int p_port); |
| 589 |
void _change_output_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port); |
| 590 |
void _expand_output_port(int p_node, int p_port, bool p_expand); |
| 591 |
|
| 592 |
void _expression_focus_out(Object *p_code_edit, int p_node); |
| 593 |
|
| 594 |
void _set_node_size(int p_type, int p_node, const Size2 &p_size); |
| 595 |
void _node_resized(const Vector2 &p_new_size, int p_type, int p_node); |
| 596 |
|
| 597 |
void _preview_select_port(int p_node, int p_port); |
| 598 |
void _graph_gui_input(const Ref<InputEvent> &p_event); |
| 599 |
|
| 600 |
void _member_filter_changed(const String &p_text); |
| 601 |
void _sbox_input(const Ref<InputEvent> &p_event); |
| 602 |
void _member_selected(); |
| 603 |
void _member_create(); |
| 604 |
void _member_cancel(); |
| 605 |
|
| 606 |
void _varying_create(); |
| 607 |
void _varying_validate(); |
| 608 |
void _varying_type_changed(int p_index); |
| 609 |
void _varying_mode_changed(int p_index); |
| 610 |
void _varying_name_changed(const String &p_name); |
| 611 |
void _varying_deleted(); |
| 612 |
void _varying_selected(); |
| 613 |
void _varying_unselected(); |
| 614 |
void _update_varying_tree(); |
| 615 |
|
| 616 |
void _set_custom_node_option(int p_index, int p_node, int p_op); |
| 617 |
|
| 618 |
Vector2 menu_point; |
| 619 |
void _node_menu_id_pressed(int p_idx); |
| 620 |
void _connection_menu_id_pressed(int p_idx); |
| 621 |
|
| 622 |
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); |
| 623 |
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; |
| 624 |
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); |
| 625 |
|
| 626 |
bool _is_available(int p_mode); |
| 627 |
void _update_parameters(bool p_update_refs); |
| 628 |
void _update_parameter_refs(HashSet<String> &p_names); |
| 629 |
void _update_varyings(); |
| 630 |
|
| 631 |
void _update_options_menu_deferred(); |
| 632 |
void _rebuild_shader_deferred(); |
| 633 |
|
| 634 |
void _visibility_changed(); |
| 635 |
|
| 636 |
void _get_current_mode_limits(int &r_begin_type, int &r_end_type) const; |
| 637 |
void _update_custom_script(const Ref<Script> &p_script); |
| 638 |
void _script_created(const Ref<Script> &p_script); |
| 639 |
void _resource_saved(const Ref<Resource> &p_resource); |
| 640 |
void _resource_removed(const Ref<Resource> &p_resource); |
| 641 |
void _resources_removed(); |
| 642 |
|
| 643 |
void _param_property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false); |
| 644 |
void _update_current_param(); |
| 645 |
void _param_filter_changed(const String &p_text); |
| 646 |
void _param_selected(); |
| 647 |
void _param_unselected(); |
| 648 |
|
| 649 |
void _help_open(); |
| 650 |
|
| 651 |
protected: |
| 652 |
void _notification(int p_what); |
| 653 |
static void _bind_methods(); |
| 654 |
|
| 655 |
public: |
| 656 |
virtual void edit_shader(const Ref<Shader> &p_shader) override; |
| 657 |
virtual void use_menu_bar(MenuButton *p_file_menu) override; |
| 658 |
virtual void apply_shaders() override; |
| 659 |
virtual bool is_unsaved() const override; |
| 660 |
virtual void save_external_data(const String &p_str = "") override; |
| 661 |
virtual void validate_script() override; |
| 662 |
|
| 663 |
void save_editor_layout(); |
| 664 |
|
| 665 |
void set_current_shader_type(VisualShader::Type p_type); |
| 666 |
VisualShader::Type get_current_shader_type() const; |
| 667 |
|
| 668 |
void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin); |
| 669 |
void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin); |
| 670 |
|
| 671 |
VisualShaderGraphPlugin *get_graph_plugin() { return graph_plugin.ptr(); } |
| 672 |
|
| 673 |
void clear_custom_types(); |
| 674 |
void 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); |
| 675 |
virtual void set_toggle_list_control(Control *p_toggle_list_control) override; |
| 676 |
|
| 677 |
Dictionary get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node); |
| 678 |
void update_custom_type(const Ref<Resource> &p_resource); |
| 679 |
|
| 680 |
virtual Size2 get_minimum_size() const override; |
| 681 |
virtual void update_toggle_files_button() override; |
| 682 |
|
| 683 |
Ref<VisualShader> get_visual_shader() const { return visual_shader; } |
| 684 |
|
| 685 |
VisualShaderEditor(); |
| 686 |
~VisualShaderEditor(); |
| 687 |
}; |
| 688 |
|
| 689 |
class VisualShaderNodePluginDefault : public VisualShaderNodePlugin { |
| 690 |
GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin); |
| 691 |
|
| 692 |
public: |
| 693 |
virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) override; |
| 694 |
}; |
| 695 |
|
| 696 |
class EditorPropertyVisualShaderMode : public EditorProperty { |
| 697 |
GDCLASS(EditorPropertyVisualShaderMode, EditorProperty); |
| 698 |
OptionButton *options = nullptr; |
| 699 |
|
| 700 |
void _option_selected(int p_which); |
| 701 |
|
| 702 |
public: |
| 703 |
void setup(const Vector<String> &p_options); |
| 704 |
virtual void update_property() override; |
| 705 |
void set_option_button_clip(bool p_enable); |
| 706 |
EditorPropertyVisualShaderMode(); |
| 707 |
}; |
| 708 |
|
| 709 |
class EditorInspectorVisualShaderModePlugin : public EditorInspectorPlugin { |
| 710 |
GDCLASS(EditorInspectorVisualShaderModePlugin, EditorInspectorPlugin); |
| 711 |
|
| 712 |
public: |
| 713 |
virtual bool can_handle(Object *p_object) override; |
| 714 |
virtual 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; |
| 715 |
}; |
| 716 |
|
| 717 |
class VisualShaderNodePortPreview : public Control { |
| 718 |
GDCLASS(VisualShaderNodePortPreview, Control); |
| 719 |
TextureRect *checkerboard = nullptr; |
| 720 |
Ref<VisualShader> shader; |
| 721 |
Ref<ShaderMaterial> preview_mat; |
| 722 |
VisualShader::Type type = VisualShader::Type::TYPE_MAX; |
| 723 |
int node = 0; |
| 724 |
int port = 0; |
| 725 |
bool is_valid = false; |
| 726 |
void _shader_changed(); |
| 727 |
protected: |
| 728 |
void _notification(int p_what); |
| 729 |
|
| 730 |
public: |
| 731 |
virtual Size2 get_minimum_size() const override; |
| 732 |
void 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); |
| 733 |
}; |
| 734 |
|
| 735 |
class VisualShaderConversionPlugin : public EditorResourceConversionPlugin { |
| 736 |
GDCLASS(VisualShaderConversionPlugin, EditorResourceConversionPlugin); |
| 737 |
|
| 738 |
public: |
| 739 |
virtual String converts_to() const override; |
| 740 |
virtual bool handles(const Ref<Resource> &p_resource) const override; |
| 741 |
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
| 742 |
}; |