diff options
Diffstat (limited to 'editor/plugins')
48 files changed, 423 insertions, 293 deletions
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index 1afd7df049..2931678c80 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -807,7 +807,7 @@ AbstractPolygon2DEditor::AbstractPolygon2DEditor(EditorNode *p_editor, bool p_wi canvas_item_editor = NULL; editor = p_editor; - undo_redo = editor->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); wip_active = false; edited_point = PosVertex(); diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index 2ae39d90de..e07f041eb1 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -735,7 +735,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() { error_panel->add_child(error_label); error_label->set_text("hmmm"); - undo_redo = EditorNode::get_singleton()->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); menu = memnew(PopupMenu); add_child(menu); @@ -751,7 +751,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() { open_file->set_title(TTR("Open Animation Node")); open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE); open_file->connect("file_selected", this, "_file_opened"); - undo_redo = EditorNode::get_singleton()->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); selected_point = -1; dragging_selected = false; diff --git a/editor/plugins/animation_blend_space_1d_editor.h b/editor/plugins/animation_blend_space_1d_editor.h index ae4db184e4..4a924b46c1 100644 --- a/editor/plugins/animation_blend_space_1d_editor.h +++ b/editor/plugins/animation_blend_space_1d_editor.h @@ -43,7 +43,7 @@ class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeBlendSpace1DEditor, AnimationTreeNodeEditorPlugin) + GDCLASS(AnimationNodeBlendSpace1DEditor, AnimationTreeNodeEditorPlugin); Ref<AnimationNodeBlendSpace1D> blend_space; diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 5e8fb8e059..b422e3e927 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -1043,7 +1043,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() { error_panel->add_child(error_label); error_label->set_text("eh"); - undo_redo = EditorNode::get_singleton()->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); set_custom_minimum_size(Size2(0, 300 * EDSCALE)); @@ -1061,7 +1061,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() { open_file->set_title(TTR("Open Animation Node")); open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE); open_file->connect("file_selected", this, "_file_opened"); - undo_redo = EditorNode::get_singleton()->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); selected_point = -1; selected_triangle = -1; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index dff6eb5c5e..65282ccfc2 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -598,7 +598,7 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano Skeleton *skeleton = Object::cast_to<Skeleton>(node); if (skeleton && skeleton->find_bone(concat) != -1) { //path in skeleton - String bone = concat; + const String &bone = concat; int idx = skeleton->find_bone(bone); List<String> bone_path; while (idx != -1) { @@ -796,7 +796,7 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(prev_name)); ERR_FAIL_COND(!gn); - String new_name = p_text; + const String &new_name = p_text; ERR_FAIL_COND(new_name == "" || new_name.find(".") != -1 || new_name.find("/") != -1); @@ -804,7 +804,7 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima return; //nothing to do } - String base_name = new_name; + const String &base_name = new_name; int base = 1; String name = base_name; while (blend_tree->has_node(name)) { @@ -964,5 +964,5 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() { open_file->set_title(TTR("Open Animation Node")); open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE); open_file->connect("file_selected", this, "_file_opened"); - undo_redo = EditorNode::get_singleton()->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); } diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 5204565c06..5163b372b2 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -58,6 +58,7 @@ void AnimationPlayerEditor::_node_removed(Node *p_node) { } void AnimationPlayerEditor::_notification(int p_what) { + switch (p_what) { case NOTIFICATION_PROCESS: { @@ -84,17 +85,13 @@ void AnimationPlayerEditor::_notification(int p_what) { EditorNode::get_singleton()->get_inspector()->refresh(); } else if (last_active) { - //need the last frame after it stopped - + // Need the last frame after it stopped. frame->set_value(player->get_current_animation_position()); } last_active = player->is_playing(); - //seek->set_val(player->get_position()); updating = false; - } break; - case NOTIFICATION_ENTER_TREE: { tool_anim->get_popup()->connect("id_pressed", this, "_animation_tool_menu"); @@ -107,12 +104,10 @@ void AnimationPlayerEditor::_notification(int p_what) { add_style_override("panel", editor->get_gui_base()->get_stylebox("panel", "Panel")); } break; - case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { add_style_override("panel", editor->get_gui_base()->get_stylebox("panel", "Panel")); } break; - case NOTIFICATION_THEME_CHANGED: { autoplay->set_icon(get_icon("AutoPlay", "EditorIcons")); @@ -144,9 +139,6 @@ void AnimationPlayerEditor::_notification(int p_what) { ITEM_ICON(TOOL_EDIT_TRANSITIONS, "Blend"); ITEM_ICON(TOOL_EDIT_RESOURCE, "Edit"); ITEM_ICON(TOOL_REMOVE_ANIM, "Remove"); - //ITEM_ICON(TOOL_COPY_ANIM, "Copy"); - //ITEM_ICON(TOOL_PASTE_ANIM, "Paste"); - } break; } } @@ -197,8 +189,6 @@ void AnimationPlayerEditor::_play_pressed() { //unstop stop->set_pressed(false); - //unpause - //pause->set_pressed(false); } void AnimationPlayerEditor::_play_from_pressed() { @@ -224,8 +214,6 @@ void AnimationPlayerEditor::_play_from_pressed() { //unstop stop->set_pressed(false); - //unpause - //pause->set_pressed(false); } void AnimationPlayerEditor::_play_bw_pressed() { @@ -245,8 +233,6 @@ void AnimationPlayerEditor::_play_bw_pressed() { //unstop stop->set_pressed(false); - //unpause - //pause->set_pressed(false); } void AnimationPlayerEditor::_play_bw_from_pressed() { @@ -269,8 +255,6 @@ void AnimationPlayerEditor::_play_bw_from_pressed() { //unstop stop->set_pressed(false); - //unpause - //pause->set_pressed(false); } void AnimationPlayerEditor::_stop_pressed() { @@ -281,14 +265,8 @@ void AnimationPlayerEditor::_stop_pressed() { player->stop(false); play->set_pressed(false); stop->set_pressed(true); - //pause->set_pressed(false); - //player->set_pause(false); } -void AnimationPlayerEditor::_pause_pressed() { - - //player->set_pause( pause->is_pressed() ); -} void AnimationPlayerEditor::_animation_selected(int p_which) { if (updating) @@ -469,13 +447,17 @@ void AnimationPlayerEditor::_animation_remove_confirmed() { if (player->get_autoplay() == current) { undo_redo->add_do_method(player, "set_autoplay", ""); undo_redo->add_undo_method(player, "set_autoplay", current); - // Avoid having the autoplay icon linger around if there is only one animation in the player + // Avoid having the autoplay icon linger around if there is only one animation in the player. undo_redo->add_do_method(this, "_animation_player_changed", player); } undo_redo->add_do_method(player, "remove_animation", current); undo_redo->add_undo_method(player, "add_animation", current, anim); undo_redo->add_do_method(this, "_animation_player_changed", player); undo_redo->add_undo_method(this, "_animation_player_changed", player); + if (animation->get_item_count() == 1) { + undo_redo->add_do_method(this, "_stop_onion_skinning"); + undo_redo->add_undo_method(this, "_start_onion_skinning"); + } undo_redo->commit_action(); } @@ -545,6 +527,10 @@ void AnimationPlayerEditor::_animation_name_edited() { undo_redo->add_undo_method(player, "remove_animation", new_name); undo_redo->add_do_method(this, "_animation_player_changed", player); undo_redo->add_undo_method(this, "_animation_player_changed", player); + if (animation->get_item_count() == 0) { + undo_redo->add_do_method(this, "_start_onion_skinning"); + undo_redo->add_undo_method(this, "_stop_onion_skinning"); + } undo_redo->commit_action(); _select_anim_by_name(new_name); @@ -844,7 +830,8 @@ void AnimationPlayerEditor::_update_player() { animation->set_disabled(animlist.size() == 0); autoplay->set_disabled(animlist.size() == 0); tool_anim->set_disabled(player == NULL); - onion_skinning->set_disabled(player == NULL); + onion_toggle->set_disabled(animlist.size() == 0); + onion_skinning->set_disabled(animlist.size() == 0); pin->set_disabled(player == NULL); if (!player) { @@ -895,17 +882,25 @@ void AnimationPlayerEditor::_update_player() { void AnimationPlayerEditor::edit(AnimationPlayer *p_player) { - if (onion.enabled) - _start_onion_skinning(); - if (player && pin->is_pressed()) - return; //ignore, pinned + return; // Ignore, pinned. player = p_player; if (player) { _update_player(); + + if (onion.enabled) { + if (animation->get_item_count() > 0) + _start_onion_skinning(); + else + _stop_onion_skinning(); + } + track_editor->show_select_node_warning(false); } else { + if (onion.enabled) + _stop_onion_skinning(); + track_editor->show_select_node_warning(true); } } @@ -915,13 +910,13 @@ void AnimationPlayerEditor::forward_canvas_force_draw_over_viewport(Control *p_o if (!onion.can_overlay) return; - // Can happen on viewport resize, at least + // Can happen on viewport resize, at least. if (!_are_onion_layers_valid()) return; RID ci = p_overlay->get_canvas_item(); Rect2 src_rect = p_overlay->get_global_rect(); - // Re-flip since captures are already flipped + // Re-flip since captures are already flipped. src_rect.position.y = onion.capture_size.y - (src_rect.position.y + src_rect.size.y); src_rect.size.y *= -1; @@ -955,7 +950,7 @@ void AnimationPlayerEditor::forward_canvas_force_draw_over_viewport(Control *p_o } cidx++; - } while (cidx < base_cidx + onion.steps); // In case there's the present capture at the end, skip it + } while (cidx < base_cidx + onion.steps); // In case there's the present capture at the end, skip it. } } @@ -1053,7 +1048,7 @@ void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) { _update_player(); if (blend_editor.dialog->is_visible_in_tree()) - _animation_blend(); //update + _animation_blend(); // Update. } } @@ -1092,8 +1087,6 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) _seek_value_changed(p_pos, !p_drag); EditorNode::get_singleton()->get_inspector()->refresh(); - - //seekit } void AnimationPlayerEditor::_hide_anim_editors() { @@ -1113,8 +1106,9 @@ void AnimationPlayerEditor::_animation_about_to_show_menu() { void AnimationPlayerEditor::_animation_tool_menu(int p_option) { String current; - if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) + if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { current = animation->get_item_text(animation->get_selected()); + } Ref<Animation> anim; if (current != String()) { @@ -1124,33 +1118,39 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { switch (p_option) { case TOOL_NEW_ANIM: { + _animation_new(); } break; - case TOOL_LOAD_ANIM: { + _animation_load(); - break; } break; case TOOL_SAVE_ANIM: { + if (anim.is_valid()) { _animation_save(anim); } } break; case TOOL_SAVE_AS_ANIM: { + if (anim.is_valid()) { _animation_save_as(anim); } } break; case TOOL_DUPLICATE_ANIM: { + _animation_duplicate(); } break; case TOOL_RENAME_ANIM: { + _animation_rename(); } break; case TOOL_EDIT_TRANSITIONS: { + _animation_blend(); } break; case TOOL_REMOVE_ANIM: { + _animation_remove(); } break; case TOOL_COPY_ANIM: { @@ -1163,9 +1163,7 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { String current2 = animation->get_item_text(animation->get_selected()); Ref<Animation> anim2 = player->get_animation(current2); - //editor->edit_resource(anim2); EditorSettings::get_singleton()->set_resource_clipboard(anim2); - } break; case TOOL_PASTE_ANIM: { @@ -1197,7 +1195,6 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { undo_redo->commit_action(); _select_anim_by_name(name); - } break; case TOOL_EDIT_RESOURCE: { @@ -1210,7 +1207,6 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { String current2 = animation->get_item_text(animation->get_selected()); Ref<Animation> anim2 = player->get_animation(current2); editor->edit_resource(anim2); - } break; } } @@ -1232,22 +1228,19 @@ void AnimationPlayerEditor::_onion_skinning_menu(int p_option) { _stop_onion_skinning(); } break; - case ONION_SKINNING_PAST: { - // Ensure at least one of past/future is checjed + // Ensure at least one of past/future is checked. onion.past = onion.future ? !onion.past : true; menu->set_item_checked(idx, onion.past); } break; - case ONION_SKINNING_FUTURE: { - // Ensure at least one of past/future is checjed + // Ensure at least one of past/future is checked. onion.future = onion.past ? !onion.future : true; menu->set_item_checked(idx, onion.future); } break; - - case ONION_SKINNING_1_STEP: // Fall-through + case ONION_SKINNING_1_STEP: // Fall-through. case ONION_SKINNING_2_STEPS: case ONION_SKINNING_3_STEPS: { @@ -1257,19 +1250,16 @@ void AnimationPlayerEditor::_onion_skinning_menu(int p_option) { menu->set_item_checked(one_frame_idx + i, onion.steps == i + 1); } } break; - case ONION_SKINNING_DIFFERENCES_ONLY: { onion.differences_only = !onion.differences_only; menu->set_item_checked(idx, onion.differences_only); } break; - case ONION_SKINNING_FORCE_WHITE_MODULATE: { onion.force_white_modulate = !onion.force_white_modulate; menu->set_item_checked(idx, onion.force_white_modulate); } break; - case ONION_SKINNING_INCLUDE_GIZMOS: { onion.include_gizmos = !onion.include_gizmos; @@ -1306,7 +1296,7 @@ void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { void AnimationPlayerEditor::_editor_visibility_changed() { - if (is_visible()) { + if (is_visible() && animation->get_item_count() > 0) { _start_onion_skinning(); } } @@ -1332,7 +1322,7 @@ void AnimationPlayerEditor::_allocate_onion_layers() { for (int i = 0; i < captures; i++) { bool is_present = onion.differences_only && i == captures - 1; - // Each capture is a viewport with a canvas item attached that renders a full-size rect with the contents of the main viewport + // Each capture is a viewport with a canvas item attached that renders a full-size rect with the contents of the main viewport. onion.captures.write[i] = VS::get_singleton()->viewport_create(); VS::get_singleton()->viewport_set_usage(onion.captures[i], VS::VIEWPORT_USAGE_2D); VS::get_singleton()->viewport_set_size(onion.captures[i], capture_size.width, capture_size.height); @@ -1342,7 +1332,7 @@ void AnimationPlayerEditor::_allocate_onion_layers() { VS::get_singleton()->viewport_attach_canvas(onion.captures[i], onion.capture.canvas); } - // Reset the capture canvas item to the current root viewport texture (defensive) + // Reset the capture canvas item to the current root viewport texture (defensive). VS::get_singleton()->canvas_item_clear(onion.capture.canvas_item); VS::get_singleton()->canvas_item_add_texture_rect(onion.capture.canvas_item, Rect2(Point2(), capture_size), get_tree()->get_root()->get_texture()->get_rid()); @@ -1362,7 +1352,7 @@ void AnimationPlayerEditor::_free_onion_layers() { void AnimationPlayerEditor::_prepare_onion_layers_1() { - // This would be called per viewport and we want to act once only + // This would be called per viewport and we want to act once only. int64_t frame = get_tree()->get_frame(); if (frame == onion.last_frame) return; @@ -1374,14 +1364,14 @@ void AnimationPlayerEditor::_prepare_onion_layers_1() { onion.last_frame = frame; - // Refresh viewports with no onion layers overlaid + // Refresh viewports with no onion layers overlaid. onion.can_overlay = false; plugin->update_overlays(); if (player->is_playing()) return; - // And go to next step afterwards + // And go to next step afterwards. call_deferred("_prepare_onion_layers_2"); } @@ -1394,7 +1384,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { if (!_are_onion_layers_valid()) _allocate_onion_layers(); - // Hide superfluous elements that would make the overlay unnecessary cluttered + // Hide superfluous elements that would make the overlay unnecessary cluttered. Dictionary canvas_edit_state; Dictionary spatial_edit_state; if (SpatialEditor::get_singleton()->is_visible()) { @@ -1415,7 +1405,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { vp[i] = d; } new_state["viewports"] = vp; - // TODO: Save/restore only affected entries + // TODO: Save/restore only affected entries. SpatialEditor::get_singleton()->set_state(new_state); } else { // CanvasItemEditor // 2D @@ -1426,11 +1416,11 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { new_state["show_guides"] = false; new_state["show_helpers"] = false; new_state["show_zoom_control"] = false; - // TODO: Save/restore only affected entries + // TODO: Save/restore only affected entries. CanvasItemEditor::get_singleton()->set_state(new_state); } - // Tweak the root viewport to ensure it's rendered before our target + // Tweak the root viewport to ensure it's rendered before our target. RID root_vp = get_tree()->get_root()->get_viewport_rid(); Rect2 root_vp_screen_rect = get_tree()->get_root()->get_attach_to_screen_rect(); VS::get_singleton()->viewport_attach_to_screen(root_vp, Rect2()); @@ -1438,7 +1428,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { RID present_rid; if (onion.differences_only) { - // Capture present scene as it is + // Capture present scene as it is. VS::get_singleton()->canvas_item_set_material(onion.capture.canvas_item, RID()); present_rid = onion.captures[onion.captures.size() - 1]; VS::get_singleton()->viewport_set_active(present_rid, true); @@ -1447,11 +1437,11 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { VS::get_singleton()->viewport_set_active(present_rid, false); } - // Backup current animation state + // Backup current animation state. AnimatedValuesBackup values_backup = player->backup_animated_values(); float cpos = player->get_current_animation_position(); - // Render every past/future step with the capture shader + // Render every past/future step with the capture shader. VS::get_singleton()->canvas_item_set_material(onion.capture.canvas_item, onion.capture.material->get_rid()); onion.capture.material->set_shader_param("bkg_color", GLOBAL_GET("rendering/environment/default_clear_color")); @@ -1465,7 +1455,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { for (int step_off = step_off_a; step_off <= step_off_b; step_off++) { if (step_off == 0) { - // Skip present step and switch to the color of future + // Skip present step and switch to the color of future. if (!onion.force_white_modulate) onion.capture.material->set_shader_param("dir_color", EDITOR_GET("editors/animation/onion_layers_future_color")); continue; @@ -1477,8 +1467,8 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { onion.captures_valid.write[cidx] = valid; if (valid) { player->seek(pos, true); - get_tree()->flush_transform_notifications(); // Needed for transforms of Spatials - values_backup.update_skeletons(); // Needed for Skeletons (2D & 3D) + get_tree()->flush_transform_notifications(); // Needed for transforms of Spatials. + values_backup.update_skeletons(); // Needed for Skeletons (2D & 3D). VS::get_singleton()->viewport_set_active(onion.captures[cidx], true); VS::get_singleton()->viewport_set_parent_viewport(root_vp, onion.captures[cidx]); @@ -1489,18 +1479,18 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { cidx++; } - // Restore root viewport + // Restore root viewport. VS::get_singleton()->viewport_set_parent_viewport(root_vp, RID()); VS::get_singleton()->viewport_attach_to_screen(root_vp, root_vp_screen_rect); VS::get_singleton()->viewport_set_update_mode(root_vp, VS::VIEWPORT_UPDATE_WHEN_VISIBLE); // Restore animation state // (Seeking with update=true wouldn't do the trick because the current value of the properties - // may not match their value for the current point in the animation) + // may not match their value for the current point in the animation). player->seek(cpos, false); player->restore_animated_values(values_backup); - // Restor state of main editors + // Restor state of main editors. if (SpatialEditor::get_singleton()->is_visible()) { // 3D SpatialEditor::get_singleton()->set_state(spatial_edit_state); @@ -1509,14 +1499,14 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { CanvasItemEditor::get_singleton()->set_state(canvas_edit_state); } - // Update viewports with skin layers overlaid for the actual engine loop render + // Update viewports with skin layers overlaid for the actual engine loop render. onion.can_overlay = true; plugin->update_overlays(); } void AnimationPlayerEditor::_start_onion_skinning() { - // FIXME: Using "idle_frame" makes onion layers update one frame behind the current + // FIXME: Using "idle_frame" makes onion layers update one frame behind the current. if (!get_tree()->is_connected("idle_frame", this, "call_deferred")) { get_tree()->connect("idle_frame", this, "call_deferred", varray("_prepare_onion_layers_1")); } @@ -1537,6 +1527,7 @@ void AnimationPlayerEditor::_stop_onion_skinning() { } void AnimationPlayerEditor::_pin_pressed() { + EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor()->update_tree(); } @@ -1549,7 +1540,6 @@ void AnimationPlayerEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_play_bw_from_pressed"), &AnimationPlayerEditor::_play_bw_from_pressed); ClassDB::bind_method(D_METHOD("_stop_pressed"), &AnimationPlayerEditor::_stop_pressed); ClassDB::bind_method(D_METHOD("_autoplay_pressed"), &AnimationPlayerEditor::_autoplay_pressed); - ClassDB::bind_method(D_METHOD("_pause_pressed"), &AnimationPlayerEditor::_pause_pressed); ClassDB::bind_method(D_METHOD("_animation_selected"), &AnimationPlayerEditor::_animation_selected); ClassDB::bind_method(D_METHOD("_animation_name_edited"), &AnimationPlayerEditor::_animation_name_edited); ClassDB::bind_method(D_METHOD("_animation_new"), &AnimationPlayerEditor::_animation_new); @@ -1564,10 +1554,7 @@ void AnimationPlayerEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_seek_value_changed"), &AnimationPlayerEditor::_seek_value_changed, DEFVAL(true)); ClassDB::bind_method(D_METHOD("_animation_player_changed"), &AnimationPlayerEditor::_animation_player_changed); ClassDB::bind_method(D_METHOD("_blend_edited"), &AnimationPlayerEditor::_blend_edited); - //ClassDB::bind_method(D_METHOD("_seek_frame_changed"),&AnimationPlayerEditor::_seek_frame_changed); ClassDB::bind_method(D_METHOD("_scale_changed"), &AnimationPlayerEditor::_scale_changed); - //ClassDB::bind_method(D_METHOD("_editor_store_all"),&AnimationPlayerEditor::_editor_store_all); - //ClassDB::bind_method(D_METHOD("_editor_load_all"),&AnimationPlayerEditor::_editor_load_all); ClassDB::bind_method(D_METHOD("_list_changed"), &AnimationPlayerEditor::_list_changed); ClassDB::bind_method(D_METHOD("_animation_key_editor_seek"), &AnimationPlayerEditor::_animation_key_editor_seek); ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_len_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_len_changed); @@ -1582,6 +1569,8 @@ void AnimationPlayerEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_editor_visibility_changed"), &AnimationPlayerEditor::_editor_visibility_changed); ClassDB::bind_method(D_METHOD("_prepare_onion_layers_1"), &AnimationPlayerEditor::_prepare_onion_layers_1); ClassDB::bind_method(D_METHOD("_prepare_onion_layers_2"), &AnimationPlayerEditor::_prepare_onion_layers_2); + ClassDB::bind_method(D_METHOD("_start_onion_skinning"), &AnimationPlayerEditor::_start_onion_skinning); + ClassDB::bind_method(D_METHOD("_stop_onion_skinning"), &AnimationPlayerEditor::_stop_onion_skinning); ClassDB::bind_method(D_METHOD("_pin_pressed"), &AnimationPlayerEditor::_pin_pressed); } @@ -1879,7 +1868,7 @@ AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) { editor = p_node; anim_editor = memnew(AnimationPlayerEditor(editor, this)); - anim_editor->set_undo_redo(editor->get_undo_redo()); + anim_editor->set_undo_redo(EditorNode::get_undo_redo()); editor->add_bottom_panel_item(TTR("Animation"), anim_editor); } diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index dedce16bbc..398ef6ff14 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -170,7 +170,6 @@ class AnimationPlayerEditor : public VBoxContainer { void _play_bw_from_pressed(); void _autoplay_pressed(); void _stop_pressed(); - void _pause_pressed(); void _animation_selected(int p_which); void _animation_new(); void _animation_rename(); diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index e25e7ac7ed..bc22d9315e 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -1094,7 +1094,7 @@ void AnimationNodeStateMachineEditor::_removed_from_graph() { void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) { - String new_name = p_text; + const String &new_name = p_text; ERR_FAIL_COND(new_name == "" || new_name.find(".") != -1 || new_name.find("/") != -1); @@ -1102,7 +1102,7 @@ void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) { return; // Nothing to do. } - String base_name = new_name; + const String &base_name = new_name; int base = 1; String name = base_name; while (state_machine->has_node(name)) { @@ -1365,7 +1365,7 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { error_panel->add_child(error_label); error_panel->hide(); - undo_redo = EditorNode::get_singleton()->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); set_custom_minimum_size(Size2(0, 300 * EDSCALE)); @@ -1390,7 +1390,7 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { open_file->set_title(TTR("Open Animation Node")); open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE); open_file->connect("file_selected", this, "_file_opened"); - undo_redo = EditorNode::get_singleton()->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); over_text = false; diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h index 4a7f933bbf..4ecbf2e05e 100644 --- a/editor/plugins/animation_tree_editor_plugin.h +++ b/editor/plugins/animation_tree_editor_plugin.h @@ -41,7 +41,8 @@ #include "scene/gui/tree.h" class AnimationTreeNodeEditorPlugin : public VBoxContainer { - GDCLASS(AnimationTreeNodeEditorPlugin, VBoxContainer) + GDCLASS(AnimationTreeNodeEditorPlugin, VBoxContainer); + public: virtual bool can_edit(const Ref<AnimationNode> &p_node) = 0; virtual void edit(const Ref<AnimationNode> &p_node) = 0; diff --git a/editor/plugins/animation_tree_player_editor_plugin.cpp b/editor/plugins/animation_tree_player_editor_plugin.cpp index f5d21ffb26..c99ad7f441 100644 --- a/editor/plugins/animation_tree_player_editor_plugin.cpp +++ b/editor/plugins/animation_tree_player_editor_plugin.cpp @@ -511,9 +511,7 @@ void AnimationTreePlayerEditor::_draw_node(const StringName &p_node) { font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, p_node, font_color); ofs.y += h; - int count = 2; // title and name int inputs = anim_tree->node_get_input_count(p_node); - count += inputs ? inputs : 1; float icon_h_ofs = Math::floor((font->get_height() - slot_icon->get_height()) / 2.0) + 1; @@ -618,7 +616,7 @@ AnimationTreePlayerEditor::ClickType AnimationTreePlayerEditor::_locate_click(co for (const List<StringName>::Element *E = order.back(); E; E = E->prev()) { - StringName node = E->get(); + const StringName &node = E->get(); AnimationTreePlayer::NodeType type = anim_tree->node_get_type(node); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 3c24fd19b6..e0e9d4af52 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -71,8 +71,7 @@ class SnapDialog : public ConfirmationDialog { SpinBox *rotation_step; public: - SnapDialog() : - ConfirmationDialog() { + SnapDialog() { const int SPIN_BOX_GRID_RANGE = 256; const int SPIN_BOX_ROTATION_RANGE = 360; Label *label; @@ -490,8 +489,6 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no r_items.push_back(res); } } - - return; } void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items) { @@ -1999,11 +1996,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { return true; } - if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_LEFT || k->get_scancode() == KEY_RIGHT)) { - // Accept the key event in any case - return true; - } - return false; + return (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_LEFT || k->get_scancode() == KEY_RIGHT)); // Accept the key event in any case } bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { @@ -3615,18 +3608,20 @@ void CanvasItemEditor::_update_scrollbars() { // Constraints the view offset and updates the scrollbars Point2 begin = canvas_item_rect.position; Point2 end = canvas_item_rect.position + canvas_item_rect.size - local_rect.size / zoom; + bool constrain_editor_view = bool(EditorSettings::get_singleton()->get("editors/2d/constrain_editor_view")); if (canvas_item_rect.size.height <= (local_rect.size.y / zoom)) { - if (ABS(begin.y - previous_update_view_offset.y) < ABS(begin.y - view_offset.y)) { + float centered = -(size.y / 2) / zoom + screen_rect.y / 2; + if (constrain_editor_view && ABS(centered - previous_update_view_offset.y) < ABS(centered - view_offset.y)) { view_offset.y = previous_update_view_offset.y; } v_scroll->hide(); } else { - if (view_offset.y > end.y && view_offset.y > previous_update_view_offset.y) { + if (constrain_editor_view && view_offset.y > end.y && view_offset.y > previous_update_view_offset.y) { view_offset.y = MAX(end.y, previous_update_view_offset.y); } - if (view_offset.y < begin.y && view_offset.y < previous_update_view_offset.y) { + if (constrain_editor_view && view_offset.y < begin.y && view_offset.y < previous_update_view_offset.y) { view_offset.y = MIN(begin.y, previous_update_view_offset.y); } @@ -3637,16 +3632,17 @@ void CanvasItemEditor::_update_scrollbars() { } if (canvas_item_rect.size.width <= (local_rect.size.x / zoom)) { - if (ABS(begin.x - previous_update_view_offset.x) < ABS(begin.x - view_offset.x)) { + float centered = -(size.x / 2) / zoom + screen_rect.x / 2; + if (constrain_editor_view && ABS(centered - previous_update_view_offset.x) < ABS(centered - view_offset.x)) { view_offset.x = previous_update_view_offset.x; } h_scroll->hide(); } else { - if (view_offset.x > end.x && view_offset.x > previous_update_view_offset.x) { + if (constrain_editor_view && view_offset.x > end.x && view_offset.x > previous_update_view_offset.x) { view_offset.x = MAX(end.x, previous_update_view_offset.x); } - if (view_offset.x < begin.x && view_offset.x < previous_update_view_offset.x) { + if (constrain_editor_view && view_offset.x < begin.x && view_offset.x < previous_update_view_offset.x) { view_offset.x = MIN(begin.x, previous_update_view_offset.x); } @@ -4340,7 +4336,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { continue; if (!n2d->get_parent_item()) continue; - if (n2d->has_meta("_edit_bone_") && (bool)n2d->get_meta("_edit_bone_") == true) + if (n2d->has_meta("_edit_bone_") && n2d->get_meta("_edit_bone_")) continue; undo_redo->add_do_method(n2d, "set_meta", "_edit_bone_", true); @@ -4390,7 +4386,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { continue; if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - if (canvas_item->has_meta("_edit_ik_") && (bool)canvas_item->get_meta("_edit_ik_") == true) + if (canvas_item->has_meta("_edit_ik_") && canvas_item->get_meta("_edit_ik_")) continue; undo_redo->add_do_method(canvas_item, "set_meta", "_edit_ik_", true); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index ff221eb758..a46682d494 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -425,7 +425,7 @@ private: List<CanvasItem *> _get_edited_canvas_items(bool retreive_locked = false, bool remove_canvas_item_if_parent_in_selection = true); Rect2 _get_encompassing_rect_from_list(List<CanvasItem *> p_list); - void _expand_encompassing_rect_using_children(Rect2 &p_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D(), bool include_locked_nodes = true); + void _expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D(), bool include_locked_nodes = true); Rect2 _get_encompassing_rect(const Node *p_node); Object *_get_editor_data(Object *p_what); diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp index 6ab554cb05..87cb0d04a2 100644 --- a/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_editor_plugin.cpp @@ -527,7 +527,7 @@ Polygon3DEditor::Polygon3DEditor(EditorNode *p_editor) { node = NULL; editor = p_editor; - undo_redo = editor->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); add_child(memnew(VSeparator)); button_create = memnew(ToolButton); diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index 1622ce17b2..7c2116f06b 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -75,6 +75,10 @@ void CPUParticles2DEditorPlugin::_menu_callback(int p_idx) { emission_mask->popup_centered_minsize(); } break; + case MENU_RESTART: { + + particles->restart(); + } } } @@ -265,6 +269,8 @@ CPUParticles2DEditorPlugin::CPUParticles2DEditorPlugin(EditorNode *p_node) { menu = memnew(MenuButton); menu->get_popup()->add_item(TTR("Load Emission Mask"), MENU_LOAD_EMISSION_MASK); + menu->get_popup()->add_separator(); + menu->get_popup()->add_item(TTR("Restart"), MENU_RESTART); // menu->get_popup()->add_item(TTR("Clear Emission Mask"), MENU_CLEAR_EMISSION_MASK); menu->set_text(TTR("Particles")); menu->set_switch_on_hover(true); diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.h b/editor/plugins/cpu_particles_2d_editor_plugin.h index f715abd87b..84bbfff095 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.h +++ b/editor/plugins/cpu_particles_2d_editor_plugin.h @@ -44,7 +44,8 @@ class CPUParticles2DEditorPlugin : public EditorPlugin { enum { MENU_LOAD_EMISSION_MASK, - MENU_CLEAR_EMISSION_MASK + MENU_CLEAR_EMISSION_MASK, + MENU_RESTART }; enum EmissionMode { diff --git a/editor/plugins/cpu_particles_editor_plugin.cpp b/editor/plugins/cpu_particles_editor_plugin.cpp index 70be9b95bb..93ffce41fa 100644 --- a/editor/plugins/cpu_particles_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_editor_plugin.cpp @@ -62,6 +62,12 @@ void CPUParticlesEditor::_menu_option(int p_option) { emission_tree_dialog->popup_centered_ratio(); } break; + + case MENU_OPTION_RESTART: { + + node->restart(); + + } break; } } @@ -108,6 +114,8 @@ CPUParticlesEditor::CPUParticlesEditor() { options->set_text(TTR("CPUParticles")); options->get_popup()->add_item(TTR("Create Emission Points From Mesh"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_MESH); options->get_popup()->add_item(TTR("Create Emission Points From Node"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE); + options->get_popup()->add_separator(); + options->get_popup()->add_item(TTR("Restart"), MENU_OPTION_RESTART); options->get_popup()->connect("id_pressed", this, "_menu_option"); } diff --git a/editor/plugins/cpu_particles_editor_plugin.h b/editor/plugins/cpu_particles_editor_plugin.h index 09b0adbe5d..674f00dc9f 100644 --- a/editor/plugins/cpu_particles_editor_plugin.h +++ b/editor/plugins/cpu_particles_editor_plugin.h @@ -43,6 +43,7 @@ class CPUParticlesEditor : public ParticlesEditorBase { MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE, MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_MESH, MENU_OPTION_CLEAR_EMISSION_VOLUME, + MENU_OPTION_RESTART }; diff --git a/editor/plugins/curve_editor_plugin.h b/editor/plugins/curve_editor_plugin.h index b034368b6a..be774a9696 100644 --- a/editor/plugins/curve_editor_plugin.h +++ b/editor/plugins/curve_editor_plugin.h @@ -37,7 +37,8 @@ // Edits a y(x) curve class CurveEditor : public Control { - GDCLASS(CurveEditor, Control) + GDCLASS(CurveEditor, Control); + public: CurveEditor(); @@ -120,14 +121,16 @@ private: }; class EditorInspectorPluginCurve : public EditorInspectorPlugin { - GDCLASS(EditorInspectorPluginCurve, EditorInspectorPlugin) + GDCLASS(EditorInspectorPluginCurve, EditorInspectorPlugin); + public: virtual bool can_handle(Object *p_object); virtual void parse_begin(Object *p_object); }; class CurveEditorPlugin : public EditorPlugin { - GDCLASS(CurveEditorPlugin, EditorPlugin) + GDCLASS(CurveEditorPlugin, EditorPlugin); + public: CurveEditorPlugin(EditorNode *p_node); @@ -135,7 +138,8 @@ public: }; class CurvePreviewGenerator : public EditorResourcePreviewGenerator { - GDCLASS(CurvePreviewGenerator, EditorResourcePreviewGenerator) + GDCLASS(CurvePreviewGenerator, EditorResourcePreviewGenerator); + public: virtual bool handles(const String &p_type) const; virtual Ref<Texture> generate(const Ref<Resource> &p_from, const Size2 p_size) const; diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h index 16b1f3082b..12d693b10a 100644 --- a/editor/plugins/editor_preview_plugins.h +++ b/editor/plugins/editor_preview_plugins.h @@ -36,7 +36,8 @@ void post_process_preview(Ref<Image> p_image); class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorTexturePreviewPlugin, EditorResourcePreviewGenerator) + GDCLASS(EditorTexturePreviewPlugin, EditorResourcePreviewGenerator); + public: virtual bool handles(const String &p_type) const; virtual bool generate_small_preview_automatically() const; @@ -46,7 +47,8 @@ public: }; class EditorImagePreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorImagePreviewPlugin, EditorResourcePreviewGenerator) + GDCLASS(EditorImagePreviewPlugin, EditorResourcePreviewGenerator); + public: virtual bool handles(const String &p_type) const; virtual bool generate_small_preview_automatically() const; @@ -56,7 +58,8 @@ public: }; class EditorBitmapPreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorBitmapPreviewPlugin, EditorResourcePreviewGenerator) + GDCLASS(EditorBitmapPreviewPlugin, EditorResourcePreviewGenerator); + public: virtual bool handles(const String &p_type) const; virtual bool generate_small_preview_automatically() const; @@ -77,7 +80,7 @@ public: class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorMaterialPreviewPlugin, EditorResourcePreviewGenerator) + GDCLASS(EditorMaterialPreviewPlugin, EditorResourcePreviewGenerator); RID scenario; RID sphere; @@ -123,7 +126,7 @@ public: class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorMeshPreviewPlugin, EditorResourcePreviewGenerator) + GDCLASS(EditorMeshPreviewPlugin, EditorResourcePreviewGenerator); RID scenario; RID mesh_instance; @@ -151,7 +154,7 @@ public: class EditorFontPreviewPlugin : public EditorResourcePreviewGenerator { - GDCLASS(EditorFontPreviewPlugin, EditorResourcePreviewGenerator) + GDCLASS(EditorFontPreviewPlugin, EditorResourcePreviewGenerator); RID viewport; RID viewport_texture; diff --git a/editor/plugins/gradient_editor_plugin.h b/editor/plugins/gradient_editor_plugin.h index 91790abee8..a87a5fe0ba 100644 --- a/editor/plugins/gradient_editor_plugin.h +++ b/editor/plugins/gradient_editor_plugin.h @@ -36,7 +36,7 @@ #include "scene/gui/gradient_edit.h" class GradientEditor : public GradientEdit { - GDCLASS(GradientEditor, GradientEdit) + GDCLASS(GradientEditor, GradientEdit); bool editing; Ref<Gradient> gradient; @@ -54,7 +54,8 @@ public: }; class EditorInspectorPluginGradient : public EditorInspectorPlugin { - GDCLASS(EditorInspectorPluginGradient, EditorInspectorPlugin) + GDCLASS(EditorInspectorPluginGradient, EditorInspectorPlugin); + public: virtual bool can_handle(Object *p_object); virtual void parse_begin(Object *p_object); diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index c3f14c27e5..1405127ab3 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -78,7 +78,7 @@ public: }; class EditorInspectorPluginMaterial : public EditorInspectorPlugin { - GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin) + GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin); Ref<Environment> env; public: @@ -99,7 +99,8 @@ public: }; class SpatialMaterialConversionPlugin : public EditorResourceConversionPlugin { - GDCLASS(SpatialMaterialConversionPlugin, EditorResourceConversionPlugin) + GDCLASS(SpatialMaterialConversionPlugin, EditorResourceConversionPlugin); + public: virtual String converts_to() const; virtual bool handles(const Ref<Resource> &p_resource) const; @@ -107,7 +108,8 @@ public: }; class ParticlesMaterialConversionPlugin : public EditorResourceConversionPlugin { - GDCLASS(ParticlesMaterialConversionPlugin, EditorResourceConversionPlugin) + GDCLASS(ParticlesMaterialConversionPlugin, EditorResourceConversionPlugin); + public: virtual String converts_to() const; virtual bool handles(const Ref<Resource> &p_resource) const; @@ -115,7 +117,8 @@ public: }; class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin { - GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin) + GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin); + public: virtual String converts_to() const; virtual bool handles(const Ref<Resource> &p_resource) const; diff --git a/editor/plugins/mesh_editor_plugin.h b/editor/plugins/mesh_editor_plugin.h index 8ada2dac90..4c2a81ed70 100644 --- a/editor/plugins/mesh_editor_plugin.h +++ b/editor/plugins/mesh_editor_plugin.h @@ -73,7 +73,8 @@ public: }; class EditorInspectorPluginMesh : public EditorInspectorPlugin { - GDCLASS(EditorInspectorPluginMesh, EditorInspectorPlugin) + GDCLASS(EditorInspectorPluginMesh, EditorInspectorPlugin); + public: virtual bool can_handle(Object *p_object); virtual void parse_begin(Object *p_object); diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index 6fabdc93c6..e68bca55cb 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -96,12 +96,16 @@ void Particles2DEditorPlugin::_menu_callback(int p_idx) { UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action(TTR("Convert to CPUParticles")); ur->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock(), "replace_node", particles, cpu_particles, true, false); - ur->add_do_reference(particles); + ur->add_do_reference(cpu_particles); ur->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock(), "replace_node", cpu_particles, particles, false, false); - ur->add_undo_reference(this); + ur->add_undo_reference(particles); ur->commit_action(); } break; + case MENU_RESTART: { + + particles->restart(); + } } } @@ -380,6 +384,8 @@ Particles2DEditorPlugin::Particles2DEditorPlugin(EditorNode *p_node) { // menu->get_popup()->add_item(TTR("Clear Emission Mask"), MENU_CLEAR_EMISSION_MASK); menu->get_popup()->add_separator(); menu->get_popup()->add_item(TTR("Convert to CPUParticles"), MENU_OPTION_CONVERT_TO_CPU_PARTICLES); + menu->get_popup()->add_separator(); + menu->get_popup()->add_item(TTR("Restart"), MENU_RESTART); menu->set_text(TTR("Particles")); menu->set_switch_on_hover(true); toolbar->add_child(menu); diff --git a/editor/plugins/particles_2d_editor_plugin.h b/editor/plugins/particles_2d_editor_plugin.h index 35b874fb25..0f092aaa4f 100644 --- a/editor/plugins/particles_2d_editor_plugin.h +++ b/editor/plugins/particles_2d_editor_plugin.h @@ -47,7 +47,8 @@ class Particles2DEditorPlugin : public EditorPlugin { MENU_GENERATE_VISIBILITY_RECT, MENU_LOAD_EMISSION_MASK, MENU_CLEAR_EMISSION_MASK, - MENU_OPTION_CONVERT_TO_CPU_PARTICLES + MENU_OPTION_CONVERT_TO_CPU_PARTICLES, + MENU_RESTART }; enum EmissionMode { diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index 3f4f66a26d..f05e7d65d3 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -315,12 +315,17 @@ void ParticlesEditor::_menu_option(int p_option) { UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action(TTR("Convert to CPUParticles")); ur->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock(), "replace_node", node, cpu_particles, true, false); - ur->add_do_reference(node); + ur->add_do_reference(cpu_particles); ur->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock(), "replace_node", cpu_particles, node, false, false); - ur->add_undo_reference(this); + ur->add_undo_reference(node); ur->commit_action(); } break; + case MENU_OPTION_RESTART: { + + node->restart(); + + } break; } } @@ -471,6 +476,8 @@ ParticlesEditor::ParticlesEditor() { options->get_popup()->add_item(TTR("Create Emission Points From Node"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE); options->get_popup()->add_separator(); options->get_popup()->add_item(TTR("Convert to CPUParticles"), MENU_OPTION_CONVERT_TO_CPU_PARTICLES); + options->get_popup()->add_separator(); + options->get_popup()->add_item(TTR("Restart"), MENU_OPTION_RESTART); options->get_popup()->connect("id_pressed", this, "_menu_option"); diff --git a/editor/plugins/particles_editor_plugin.h b/editor/plugins/particles_editor_plugin.h index b1b3e3c1c0..5d05fbd4ac 100644 --- a/editor/plugins/particles_editor_plugin.h +++ b/editor/plugins/particles_editor_plugin.h @@ -42,7 +42,7 @@ class ParticlesEditorBase : public Control { - GDCLASS(ParticlesEditorBase, Control) + GDCLASS(ParticlesEditorBase, Control); protected: Spatial *base_node; @@ -86,6 +86,7 @@ class ParticlesEditor : public ParticlesEditorBase { MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_MESH, MENU_OPTION_CLEAR_EMISSION_VOLUME, MENU_OPTION_CONVERT_TO_CPU_PARTICLES, + MENU_OPTION_RESTART, }; diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index a10eddb131..b87bd29cbd 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -179,7 +179,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } // Check for segment split. - if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && mode == MODE_EDIT && on_edge == true) { + if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && mode == MODE_EDIT && on_edge) { Vector2 gpoint2 = mb->get_position(); Ref<Curve2D> curve = node->get_curve(); diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index 53300f45ec..b8d95efd49 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -293,10 +293,7 @@ bool ResourcePreloaderEditor::can_drop_data_fw(const Point2 &p_point, const Vari Vector<String> files = d["files"]; - if (files.size() == 0) - return false; - - return true; + return files.size() != 0; } return false; } diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index 326e8394a0..05f682f469 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -131,7 +131,7 @@ void EditorPropertyRootMotion::_node_assign() { Skeleton *skeleton = Object::cast_to<Skeleton>(node); if (skeleton && skeleton->find_bone(concat) != -1) { //path in skeleton - String bone = concat; + const String &bone = concat; int idx = skeleton->find_bone(bone); List<String> bone_path; while (idx != -1) { diff --git a/editor/plugins/root_motion_editor_plugin.h b/editor/plugins/root_motion_editor_plugin.h index e7fd597235..af5d8fc122 100644 --- a/editor/plugins/root_motion_editor_plugin.h +++ b/editor/plugins/root_motion_editor_plugin.h @@ -37,7 +37,7 @@ #include "scene/animation/animation_tree.h" class EditorPropertyRootMotion : public EditorProperty { - GDCLASS(EditorPropertyRootMotion, EditorProperty) + GDCLASS(EditorPropertyRootMotion, EditorProperty); Button *assign; Button *clear; NodePath base_hint; @@ -60,7 +60,7 @@ public: }; class EditorInspectorRootMotionPlugin : public EditorInspectorPlugin { - GDCLASS(EditorInspectorRootMotionPlugin, EditorInspectorPlugin) + GDCLASS(EditorInspectorRootMotionPlugin, EditorInspectorPlugin); public: virtual bool can_handle(Object *p_object); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index b4719b2e6d..1b00889e9a 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -306,8 +306,11 @@ void ScriptEditor::_goto_script_line(REF p_script, int p_line) { editor->push_item(p_script.ptr()); ScriptEditorBase *current = _get_current_editor(); - if (current) + if (ScriptTextEditor *script_text_editor = Object::cast_to<ScriptTextEditor>(current)) { + script_text_editor->goto_line_centered(p_line); + } else if (current) { current->goto_line(p_line, true); + } } } } @@ -1915,9 +1918,7 @@ Ref<TextFile> ScriptEditor::_load_text_file(const String &p_path, Error *r_error Ref<TextFile> text_res(text_file); Error err = text_file->load_text(path); - if (err != OK) { - ERR_FAIL_COND_V(err != OK, RES()); - } + ERR_FAIL_COND_V(err != OK, RES()); text_file->set_file_path(local_path); text_file->set_path(local_path, true); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 0d9168261a..4ad2156779 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -50,7 +50,7 @@ class ScriptEditorQuickOpen : public ConfirmationDialog { - GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog) + GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog); LineEdit *search_box; Tree *search_options; @@ -77,7 +77,7 @@ class ScriptEditorDebugger; class ScriptEditorBase : public VBoxContainer { - GDCLASS(ScriptEditorBase, VBoxContainer) + GDCLASS(ScriptEditorBase, VBoxContainer); protected: static void _bind_methods(); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index ce0859a1f6..9c57dd53f1 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -237,7 +237,7 @@ void ScriptTextEditor::_load_theme_settings() { text_edit->add_color_override("safe_line_number_color", safe_line_number_color); text_edit->add_color_override("caret_color", caret_color); text_edit->add_color_override("caret_background_color", caret_background_color); - text_edit->add_color_override("font_selected_color", text_selected_color); + text_edit->add_color_override("font_color_selected", text_selected_color); text_edit->add_color_override("selection_color", selection_color); text_edit->add_color_override("brace_mismatch_color", brace_mismatch_color); text_edit->add_color_override("current_line_color", current_line_color); @@ -487,6 +487,11 @@ void ScriptTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { code_editor->goto_line_selection(p_line, p_begin, p_end); } +void ScriptTextEditor::goto_line_centered(int p_line) { + + code_editor->goto_line_centered(p_line); +} + void ScriptTextEditor::set_executing_line(int p_line) { code_editor->set_executing_line(p_line); } @@ -569,8 +574,8 @@ void ScriptTextEditor::_validate_script() { Connection connection = E->get(); String base_path = base->get_name(); - String source_path = base == connection.source ? base_path : base_path + "/" + String(base->get_path_to(Object::cast_to<Node>(connection.source))); - String target_path = base == connection.target ? base_path : base_path + "/" + String(base->get_path_to(Object::cast_to<Node>(connection.target))); + String source_path = base == connection.source ? base_path : base_path + "/" + base->get_path_to(Object::cast_to<Node>(connection.source)); + String target_path = base == connection.target ? base_path : base_path + "/" + base->get_path_to(Object::cast_to<Node>(connection.target)); warnings_panel->push_cell(); warnings_panel->push_color(warnings_panel->get_color("warning_color", "Editor")); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 24d40a5eec..89975e061e 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -201,6 +201,7 @@ public: virtual void goto_line(int p_line, bool p_with_error = false); void goto_line_selection(int p_line, int p_begin, int p_end); + void goto_line_centered(int p_line); virtual void set_executing_line(int p_line); virtual void clear_executing_line(); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index f9ca38b919..d02817f6e8 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -124,7 +124,7 @@ void ShaderTextEditor::_load_theme_settings() { get_text_edit()->add_color_override("line_number_color", line_number_color); get_text_edit()->add_color_override("caret_color", caret_color); get_text_edit()->add_color_override("caret_background_color", caret_background_color); - get_text_edit()->add_color_override("font_selected_color", text_selected_color); + get_text_edit()->add_color_override("font_color_selected", text_selected_color); get_text_edit()->add_color_override("selection_color", selection_color); get_text_edit()->add_color_override("brace_mismatch_color", brace_mismatch_color); get_text_edit()->add_color_override("current_line_color", current_line_color); diff --git a/editor/plugins/skeleton_editor_plugin.h b/editor/plugins/skeleton_editor_plugin.h index 33a9128a11..558e954815 100644 --- a/editor/plugins/skeleton_editor_plugin.h +++ b/editor/plugins/skeleton_editor_plugin.h @@ -69,7 +69,7 @@ protected: PhysicalBone *create_physical_bone(int bone_id, int bone_child_id, const Vector<BoneInfo> &bones_infos); public: - void edit(Skeleton *p_mesh); + void edit(Skeleton *p_node); SkeletonEditor(); ~SkeletonEditor(); diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index a1c0b732fa..7f7ae8f273 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -1275,13 +1275,13 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { _edit.mode = TRANSFORM_TRANSLATE; } - if (cursor.region_select && nav_mode == NAVIGATION_NONE) { + if (cursor.region_select) { cursor.region_end = m->get_position(); surface->update(); return; } - if (_edit.mode == TRANSFORM_NONE && nav_mode == NAVIGATION_NONE) + if (_edit.mode == TRANSFORM_NONE) return; Vector3 ray_pos = _get_ray_pos(m->get_position()); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index f3a1e657cc..3bddc6d6d4 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -133,7 +133,7 @@ public: virtual bool is_editable() const; void set_hidden(bool p_hidden); - void set_plugin(EditorSpatialGizmoPlugin *p_gizmo); + void set_plugin(EditorSpatialGizmoPlugin *p_plugin); EditorSpatialGizmo(); ~EditorSpatialGizmo(); @@ -178,6 +178,12 @@ public: GIZMO_GRID_LAYER = 25 }; + enum NavigationScheme { + NAVIGATION_GODOT, + NAVIGATION_MAYA, + NAVIGATION_MODO, + }; + private: int index; String name; @@ -260,12 +266,6 @@ private: PopupMenu *selection_menu; - enum NavigationScheme { - NAVIGATION_GODOT, - NAVIGATION_MAYA, - NAVIGATION_MODO, - }; - enum NavigationZoomStyle { NAVIGATION_ZOOM_VERTICAL, NAVIGATION_ZOOM_HORIZONTAL @@ -431,7 +431,8 @@ public: class SpatialEditorViewportContainer : public Container { - GDCLASS(SpatialEditorViewportContainer, Container) + GDCLASS(SpatialEditorViewportContainer, Container); + public: enum View { VIEW_USE_1_VIEWPORT, diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index c509202a88..d91de6cbf6 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -232,7 +232,8 @@ void SpriteFramesEditor::_notification(int p_what) { _delete->set_icon(get_icon("Remove", "EditorIcons")); new_anim->set_icon(get_icon("New", "EditorIcons")); remove_anim->set_icon(get_icon("Remove", "EditorIcons")); - } // Fallthrough. + FALLTHROUGH; + } case NOTIFICATION_THEME_CHANGED: { splite_sheet_scroll->add_style_override("bg", get_stylebox("bg", "Tree")); } break; diff --git a/editor/plugins/style_box_editor_plugin.h b/editor/plugins/style_box_editor_plugin.h index 95d21b2c44..d31a28b3e4 100644 --- a/editor/plugins/style_box_editor_plugin.h +++ b/editor/plugins/style_box_editor_plugin.h @@ -56,7 +56,8 @@ public: }; class EditorInspectorPluginStyleBox : public EditorInspectorPlugin { - GDCLASS(EditorInspectorPluginStyleBox, EditorInspectorPlugin) + GDCLASS(EditorInspectorPluginStyleBox, EditorInspectorPlugin); + public: virtual bool can_handle(Object *p_object); virtual void parse_begin(Object *p_object); diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index eeef3397d2..787813336d 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -116,7 +116,7 @@ void TextEditor::_load_theme_settings() { text_edit->add_color_override("line_number_color", line_number_color); text_edit->add_color_override("caret_color", caret_color); text_edit->add_color_override("caret_background_color", caret_background_color); - text_edit->add_color_override("font_selected_color", text_selected_color); + text_edit->add_color_override("font_color_selected", text_selected_color); text_edit->add_color_override("selection_color", selection_color); text_edit->add_color_override("brace_mismatch_color", brace_mismatch_color); text_edit->add_color_override("current_line_color", current_line_color); diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index e91909e0ea..277e93fd39 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -35,7 +35,7 @@ class TextEditor : public ScriptEditorBase { - GDCLASS(TextEditor, ScriptEditorBase) + GDCLASS(TextEditor, ScriptEditorBase); private: CodeTextEditor *code_editor; diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h index bcbda1fbd7..ed25783303 100644 --- a/editor/plugins/texture_editor_plugin.h +++ b/editor/plugins/texture_editor_plugin.h @@ -54,7 +54,8 @@ public: }; class EditorInspectorPluginTexture : public EditorInspectorPlugin { - GDCLASS(EditorInspectorPluginTexture, EditorInspectorPlugin) + GDCLASS(EditorInspectorPluginTexture, EditorInspectorPlugin); + public: virtual bool can_handle(Object *p_object); virtual void parse_begin(Object *p_object); diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 16f93b8fd3..6e47d82847 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -61,8 +61,8 @@ void TileMapEditor::_notification(int p_what) { if (is_visible_in_tree()) { _update_palette(); } - - } // fallthrough + FALLTHROUGH; + } case NOTIFICATION_ENTER_TREE: { @@ -1848,7 +1848,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { manual_position = Vector2(0, 0); canvas_item_editor_viewport = NULL; editor = p_editor; - undo_redo = editor->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); tool = TOOL_NONE; selection_active = false; diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 4b225fddf5..35cfdf15be 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -263,7 +263,7 @@ void TileSetEditor::_notification(int p_what) { TileSetEditor::TileSetEditor(EditorNode *p_editor) { editor = p_editor; - undo_redo = editor->get_undo_redo(); + undo_redo = EditorNode::get_undo_redo(); current_tile = -1; VBoxContainer *left_container = memnew(VBoxContainer); @@ -829,8 +829,8 @@ void TileSetEditor::_on_workspace_draw() { case EDITMODE_BITMASK: { Color c(1, 0, 0, 0.5); Color ci(0.3, 0.6, 1, 0.5); - for (float x = 0; x < region.size.x / (spacing + size.x); x++) { - for (float y = 0; y < region.size.y / (spacing + size.y); y++) { + for (int x = 0; x < region.size.x / (spacing + size.x); x++) { + for (int y = 0; y < region.size.y / (spacing + size.y); y++) { Vector2 coord(x, y); Point2 anchor(coord.x * (spacing + size.x), coord.y * (spacing + size.y)); anchor += WORKSPACE_MARGIN; @@ -974,6 +974,7 @@ void TileSetEditor::_on_workspace_draw() { workspace->draw_rect(region, c, false); } } + delete tiles; if (edit_mode == EDITMODE_REGION) { if (workspace_mode != WORKSPACE_EDIT) { @@ -1068,6 +1069,7 @@ void TileSetEditor::_on_workspace_overlay_draw() { c = Color(0.1, 0.1, 0.1); workspace_overlay->draw_string(font, region.position, tile_id_name, c); } + delete tiles; } int t_id = get_current_tile(); @@ -1115,10 +1117,12 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { set_current_tile(t_id); workspace->update(); workspace_overlay->update(); + delete tiles; return; } } } + delete tiles; } } @@ -2009,11 +2013,7 @@ bool TileSetEditor::_sort_tiles(Variant p_a, Variant p_b) { return true; } else if (pos_a.y == pos_b.y) { - if (pos_a.x < pos_b.x) { - return true; - } else { - return false; - } + return (pos_a.x < pos_b.x); } else { return false; } @@ -3122,6 +3122,7 @@ void TileSetEditor::update_workspace_minsize() { workspace_min_size.y = region.position.y + region.size.y; } } + delete tiles; workspace->set_custom_minimum_size(workspace_min_size + WORKSPACE_MARGIN * 2); workspace_container->set_custom_minimum_size(workspace_min_size + WORKSPACE_MARGIN * 2); diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h index 1176e1bb92..04e8d65155 100644 --- a/editor/plugins/tile_set_editor_plugin.h +++ b/editor/plugins/tile_set_editor_plugin.h @@ -31,7 +31,6 @@ #ifndef TILE_SET_EDITOR_PLUGIN_H #define TILE_SET_EDITOR_PLUGIN_H -#include "editor/editor_name_dialog.h" #include "editor/editor_node.h" #include "scene/2d/sprite.h" #include "scene/resources/concave_polygon_shape_2d.h" @@ -46,7 +45,7 @@ class TileSetEditor : public HSplitContainer { friend class TileSetEditorPlugin; friend class TilesetEditorContext; - GDCLASS(TileSetEditor, HSplitContainer) + GDCLASS(TileSetEditor, HSplitContainer); enum TextureToolButtons { TOOL_TILESET_ADD_TEXTURE, diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index a1b903576e..e1929d7489 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -158,10 +158,7 @@ bool VisualShaderEditor::_is_available(int p_mode) { p_mode = temp_mode; } - if (p_mode != -1 && ((p_mode & current_mode) == 0)) { - return false; - } - return true; + return (p_mode == -1 || (p_mode & current_mode) != 0); } void VisualShaderEditor::_update_options_menu() { @@ -573,13 +570,11 @@ void VisualShaderEditor::_update_graph() { name_box->connect("text_entered", this, "_change_input_port_name", varray(name_box, nodes[n_i], i)); name_box->connect("focus_exited", this, "_port_name_focus_out", varray(name_box, nodes[n_i], i, false)); - if (is_group) { - Button *remove_btn = memnew(Button); - remove_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Remove", "EditorIcons")); - remove_btn->set_tooltip(TTR("Remove") + " " + name_left); - remove_btn->connect("pressed", this, "_remove_input_port", varray(nodes[n_i], i), CONNECT_DEFERRED); - hb->add_child(remove_btn); - } + Button *remove_btn = memnew(Button); + remove_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Remove", "EditorIcons")); + remove_btn->set_tooltip(TTR("Remove") + " " + name_left); + remove_btn->connect("pressed", this, "_remove_input_port", varray(nodes[n_i], i), CONNECT_DEFERRED); + hb->add_child(remove_btn); } else { Label *label = memnew(Label); @@ -1243,6 +1238,30 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { undo_redo->add_do_method(expr, "set_size", Size2(250 * EDSCALE, 150 * EDSCALE)); } + if (to_node != -1 && to_slot != -1) { + if (vsnode->get_output_port_count() > 0) { + + int _from_node = id_to_use; + int _from_slot = 0; + + if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(_from_slot), visual_shader->get_node(type, to_node)->get_input_port_type(to_slot))) { + undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot); + undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot); + } + } + } else if (from_node != -1 && from_slot != -1) { + if (vsnode->get_input_port_count() > 0) { + + int _to_node = id_to_use; + int _to_slot = 0; + + if (visual_shader->is_port_types_compatible(visual_shader->get_node(type, from_node)->get_output_port_type(from_slot), vsnode->get_input_port_type(_to_slot))) { + undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot); + undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot); + } + } + } + undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); @@ -1312,6 +1331,15 @@ void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from } void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) { + from_node = p_from.to_int(); + from_slot = p_from_slot; + _show_members_dialog(true); +} + +void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) { + to_node = p_to.to_int(); + to_slot = p_to_slot; + _show_members_dialog(true); } void VisualShaderEditor::_delete_request(int which) { @@ -1377,8 +1405,6 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> p_event) { void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos) { - members_dialog->popup(); - if (at_mouse_pos) { saved_node_pos_dirty = true; saved_node_pos = graph->get_local_mouse_position(); @@ -1387,6 +1413,7 @@ void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos) { members_dialog->popup(); members_dialog->set_position(gpos); } else { + members_dialog->popup(); saved_node_pos_dirty = false; members_dialog->set_position(graph->get_global_position() + Point2(5 * EDSCALE, 65 * EDSCALE)); } @@ -1703,6 +1730,13 @@ void VisualShaderEditor::_member_create() { } } +void VisualShaderEditor::_member_cancel() { + to_node = -1; + to_slot = -1; + from_node = -1; + from_slot = -1; +} + void VisualShaderEditor::_tools_menu_option(int p_idx) { TreeItem *category = members->get_root()->get_children(); @@ -1814,6 +1848,7 @@ void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_edit_port_default_input", &VisualShaderEditor::_edit_port_default_input); ClassDB::bind_method("_port_edited", &VisualShaderEditor::_port_edited); ClassDB::bind_method("_connection_to_empty", &VisualShaderEditor::_connection_to_empty); + ClassDB::bind_method("_connection_from_empty", &VisualShaderEditor::_connection_from_empty); ClassDB::bind_method("_line_edit_focus_out", &VisualShaderEditor::_line_edit_focus_out); ClassDB::bind_method("_line_edit_changed", &VisualShaderEditor::_line_edit_changed); ClassDB::bind_method("_port_name_focus_out", &VisualShaderEditor::_port_name_focus_out); @@ -1845,6 +1880,7 @@ void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_member_selected", &VisualShaderEditor::_member_selected); ClassDB::bind_method("_member_unselected", &VisualShaderEditor::_member_unselected); ClassDB::bind_method("_member_create", &VisualShaderEditor::_member_create); + ClassDB::bind_method("_member_cancel", &VisualShaderEditor::_member_cancel); } VisualShaderEditor *VisualShaderEditor::singleton = NULL; @@ -1857,6 +1893,11 @@ VisualShaderEditor::VisualShaderEditor() { saved_node_pos = Point2(0, 0); ShaderLanguage::get_keyword_list(&keyword_list); + to_node = -1; + to_slot = -1; + from_node = -1; + from_slot = -1; + graph = memnew(GraphEdit); add_child(graph); graph->set_drag_forwarding(this); @@ -1873,6 +1914,8 @@ VisualShaderEditor::VisualShaderEditor() { graph->connect("duplicate_nodes_request", this, "_duplicate_nodes"); graph->connect("delete_nodes_request", this, "_on_nodes_delete"); graph->connect("gui_input", this, "_graph_gui_input"); + graph->connect("connection_to_empty", this, "_connection_to_empty"); + graph->connect("connection_from_empty", this, "_connection_from_empty"); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN); @@ -1958,6 +2001,7 @@ VisualShaderEditor::VisualShaderEditor() { members_dialog->get_ok()->set_disabled(true); members_dialog->set_resizable(true); members_dialog->set_as_minsize(); + members_dialog->connect("hide", this, "_member_cancel"); add_child(members_dialog); alert = memnew(AcceptDialog); @@ -2005,23 +2049,23 @@ VisualShaderEditor::VisualShaderEditor() { // INPUT // SPATIAL-FOR-ALL - - add_options.push_back(AddOption("Camera", "Input", "All", "VisualShaderNodeInput", TTR("'camera' input parameter for all shader modes."), "camera", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("InvCamera", "Input", "All", "VisualShaderNodeInput", TTR("'inv_camera' input parameter for all shader modes."), "inv_camera", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("InvProjection", "Input", "All", "VisualShaderNodeInput", TTR("'inv_projection' input parameter for all shader modes."), "inv_projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Normal", "Input", "All", "VisualShaderNodeInput", TTR("'normal' input parameter for all shader modes."), "normal", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Projection", "Input", "All", "VisualShaderNodeInput", TTR("'projection' input parameter for all shader modes."), "projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Time", "Input", "All", "VisualShaderNodeInput", TTR("'time' input parameter for all shader modes."), "time", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("ViewportSize", "Input", "All", "VisualShaderNodeInput", TTR("'viewport_size' input parameter for all shader modes."), "viewport_size", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("World", "Input", "All", "VisualShaderNodeInput", TTR("'world' input parameter for all shader modes."), "world", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); + const String input_param_shader_modes = "'%s' input parameter for all shader modes."; + add_options.push_back(AddOption("Camera", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "camera"), "camera", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("InvCamera", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "inv_camera"), "inv_camera", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("InvProjection", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "inv_projection"), "inv_projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Normal", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "normal"), "normal", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Projection", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "camera"), "projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Time", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("ViewportSize", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "viewport_size"), "viewport_size", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("World", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "world"), "world", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); // CANVASITEM-FOR-ALL - add_options.push_back(AddOption("Alpha", "Input", "All", "VisualShaderNodeInput", TTR("'alpha' input parameter for all shader modes."), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("Color", "Input", "All", "VisualShaderNodeInput", TTR("'color' input parameter for all shader modes."), "color", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("TexturePixelSize", "Input", "All", "VisualShaderNodeInput", TTR("'texture_pixel_size' input parameter for all shader modes."), "texture_pixel_size", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("Time", "Input", "All", "VisualShaderNodeInput", TTR("'time' input parameter for all shader modes."), "time", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("UV", "Input", "All", "VisualShaderNodeInput", TTR("'uv' input parameter for all shader modes."), "uv", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("Alpha", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("Color", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("TexturePixelSize", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "texture_pixel_size"), "texture_pixel_size", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("Time", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("UV", "Input", "All", "VisualShaderNodeInput", vformat(TTR(input_param_shader_modes), "uv"), "uv", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM)); ///////////////// @@ -2029,81 +2073,88 @@ VisualShaderEditor::VisualShaderEditor() { // SPATIAL INPUTS - add_options.push_back(AddOption("Alpha", "Input", "Fragment", "VisualShaderNodeInput", TTR("'alpha' input parameter for vertex and fragment shader modes."), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Binormal", "Input", "Fragment", "VisualShaderNodeInput", TTR("'binormal' input parameter for vertex and fragment shader modes."), "binormal", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Color", "Input", "Fragment", "VisualShaderNodeInput", TTR("'color' input parameter for vertex and fragment shader modes."), "color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("FragCoord", "Input", "Fragment", "VisualShaderNodeInput", TTR("'fragcoord' input parameter for fragment and light shader modes."), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("PointCoord", "Input", "Fragment", "VisualShaderNodeInput", TTR("'point_coord' input parameter for fragment shader mode."), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", TTR("'screen_uv' input parameter for fragment shader mode."), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Side", "Input", "Fragment", "VisualShaderNodeInput", TTR("'side' input parameter for fragment shader mode."), "side", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Tangent", "Input", "Fragment", "VisualShaderNodeInput", TTR("'tangent' input parameter for vertex and fragment shader modes."), "tangent", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("UV", "Input", "Fragment", "VisualShaderNodeInput", TTR("'uv' input parameter for vertex and fragment shader modes."), "uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("UV2", "Input", "Fragment", "VisualShaderNodeInput", TTR("'uv2' input parameter for vertex and fragment shader modes."), "uv2", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Vertex", "Input", "Fragment", "VisualShaderNodeInput", TTR("'vertex' input parameter for vertex and fragment shader modes."), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("View", "Input", "Fragment", "VisualShaderNodeInput", TTR("'view' input parameter for fragment and light shader modes."), "view", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); - - add_options.push_back(AddOption("Albedo", "Input", "Light", "VisualShaderNodeInput", TTR("'albedo' input parameter for light shader mode."), "albedo", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Attenuation", "Input", "Light", "VisualShaderNodeInput", TTR("'attenuation' input parameter for light shader mode."), "attenuation", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Diffuse", "Input", "Light", "VisualShaderNodeInput", TTR("'diffuse' input parameter for light shader mode."), "diffuse", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("FragCoord", "Input", "Light", "VisualShaderNodeInput", TTR("'fragcoord' input parameter for fragment and light shader modes."), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Light", "Input", "Light", "VisualShaderNodeInput", TTR("'light' input parameter for light shader mode."), "light", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("LightColor", "Input", "Light", "VisualShaderNodeInput", TTR("'light_color' input parameter for light shader mode."), "light_color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Roughness", "Input", "Light", "VisualShaderNodeInput", TTR("'roughness' input parameter for light shader mode."), "roughness", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Specular", "Input", "Light", "VisualShaderNodeInput", TTR("'specular' input parameter for light shader mode."), "specular", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Transmission", "Input", "Light", "VisualShaderNodeInput", TTR("'transmission' input parameter for light shader mode."), "transmission", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("View", "Input", "Light", "VisualShaderNodeInput", TTR("'view' input parameter for fragment and light shader modes."), "view", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); - - add_options.push_back(AddOption("Alpha", "Input", "Vertex", "VisualShaderNodeInput", TTR("'alpha' input parameter for vertex and fragment shader modes."), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Binormal", "Input", "Vertex", "VisualShaderNodeInput", TTR("'binormal' input parameter for vertex and fragment shader modes."), "binormal", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Color", "Input", "Vertex", "VisualShaderNodeInput", TTR("'color' input parameter for vertex and fragment shader modes."), "color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("ModelView", "Input", "Vertex", "VisualShaderNodeInput", TTR("'modelview' input parameter for vertex shader mode."), "modelview", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("PointSize", "Input", "Vertex", "VisualShaderNodeInput", TTR("'point_size' input parameter for vertex shader mode."), "point_size", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Tangent", "Input", "Vertex", "VisualShaderNodeInput", TTR("'tangent' input parameter for vertex and fragment shader mode."), "tangent", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("UV", "Input", "Vertex", "VisualShaderNodeInput", TTR("'uv' input parameter for vertex and fragment shader modes."), "uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("UV2", "Input", "Vertex", "VisualShaderNodeInput", TTR("'uv2' input parameter for vertex and fragment shader modes."), "uv2", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("Vertex", "Input", "Vertex", "VisualShaderNodeInput", TTR("'vertex' input parameter for vertex and fragment shader modes."), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + const String input_param_for_vertex_and_fragment_shader_modes = "'%s' input parameter for vertex and fragment shader modes."; + const String input_param_for_fragment_and_light_shader_modes = "'%s' input parameter for fragment and light shader modes."; + const String input_param_for_fragment_shader_mode = "'%s' input parameter for fragment shader mode."; + const String input_param_for_light_shader_mode = "'%s' input parameter for light shader mode."; + const String input_param_for_vertex_shader_mode = "'%s' input parameter for vertex shader mode."; + const String input_param_for_vertex_and_fragment_shader_mode = "'%s' input parameter for vertex and fragment shader mode."; + + add_options.push_back(AddOption("Alpha", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Binormal", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "binormal"), "binormal", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Color", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("FragCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("PointCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_shader_mode), "point_coord"), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_shader_mode), "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Side", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_shader_mode), "side"), "side", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Tangent", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "tangent"), "tangent", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("UV", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "uv"), "uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("UV2", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "uv2"), "uv2", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Vertex", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "vertex"), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("View", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "view"), "view", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + + add_options.push_back(AddOption("Albedo", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "albedo"), "albedo", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Attenuation", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "attenuation"), "attenuation", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Diffuse", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "diffuse"), "diffuse", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("FragCoord", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Light", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "light"), "light", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("LightColor", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "light_color"), "light_color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Roughness", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "roughness"), "roughness", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Specular", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "specular"), "specular", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Transmission", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "transmission"), "transmission", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("View", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "view"), "view", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + + add_options.push_back(AddOption("Alpha", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Binormal", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "binormal"), "binormal", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Color", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("ModelView", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "modelview"), "modelview", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("PointSize", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "point_size"), "point_size", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Tangent", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_mode), "tangent"), "tangent", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("UV", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "uv"), "uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("UV2", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "uv2"), "uv2", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("Vertex", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "vertex"), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_SPATIAL)); // CANVASITEM INPUTS - add_options.push_back(AddOption("FragCoord", "Input", "Fragment", "VisualShaderNodeInput", TTR("'fragcoord' input parameter for fragment and light shader modes."), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("LightPass", "Input", "Fragment", "VisualShaderNodeInput", TTR("'light_pass' input parameter for vertex and fragment shader modes."), "light_pass", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("PointCoord", "Input", "Fragment", "VisualShaderNodeInput", TTR("'point_coord' input parameter for fragment and light shader modes."), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("ScreenPixelSize", "Input", "Fragment", "VisualShaderNodeInput", TTR("'screen_pixel_size' input parameter for fragment shader mode."), "screen_pixel_size", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", TTR("'screen_uv' input parameter for fragment and light shader modes."), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); - - add_options.push_back(AddOption("FragCoord", "Input", "Light", "VisualShaderNodeInput", TTR("'fragcoord' input parameter for fragment and light shader modes."), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("LightAlpha", "Input", "Light", "VisualShaderNodeInput", TTR("'light_alpha' input parameter for light shader mode."), "light_alpha", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("LightColor", "Input", "Light", "VisualShaderNodeInput", TTR("'light_color' input parameter for light shader mode."), "light_color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("LightHeight", "Input", "Light", "VisualShaderNodeInput", TTR("'light_height' input parameter for light shader mode."), "light_height", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("LightUV", "Input", "Light", "VisualShaderNodeInput", TTR("'light_uv' input parameter for light shader mode."), "light_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("LightVector", "Input", "Light", "VisualShaderNodeInput", TTR("'light_vec' input parameter for light shader mode."), "light_vec", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("Normal", "Input", "Light", "VisualShaderNodeInput", TTR("'normal' input parameter for light shader mode."), "normal", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("PointCoord", "Input", "Light", "VisualShaderNodeInput", TTR("'point_coord' input parameter for fragment and light shader modes."), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("ScreenUV", "Input", "Light", "VisualShaderNodeInput", TTR("'screen_uv' input parameter for fragment and light shader modes."), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("ShadowColor", "Input", "Light", "VisualShaderNodeInput", TTR("'shadow_color' input parameter for light shader mode."), "shadow_color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); - - add_options.push_back(AddOption("Extra", "Input", "Vertex", "VisualShaderNodeInput", TTR("'extra' input parameter for vertex shader mode."), "extra", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("LightPass", "Input", "Vertex", "VisualShaderNodeInput", TTR("'light_pass' input parameter for vertex and fragment shader modes."), "light_pass", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("PointSize", "Input", "Vertex", "VisualShaderNodeInput", TTR("'point_size' input parameter for vertex shader mode."), "point_size", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("Projection", "Input", "Vertex", "VisualShaderNodeInput", TTR("'projection' input parameter for vertex shader mode."), "projection", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("Vertex", "Input", "Vertex", "VisualShaderNodeInput", TTR("'vertex' input parameter for vertex shader mode."), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); - add_options.push_back(AddOption("World", "Input", "Vertex", "VisualShaderNodeInput", TTR("'world' input parameter for vertex shader mode."), "world", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("FragCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("LightPass", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "light_pass"), "light_pass", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("PointCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "point_coord"), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("ScreenPixelSize", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_shader_mode), "screen_pixel_size"), "screen_pixel_size", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_CANVAS_ITEM)); + + add_options.push_back(AddOption("FragCoord", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("LightAlpha", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "light_alpha"), "light_alpha", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("LightColor", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "light_color"), "light_color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("LightHeight", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "light_height"), "light_height", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("LightUV", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "light_uv"), "light_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("LightVector", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "light_vec"), "light_vec", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("Normal", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "normal"), "normal", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("PointCoord", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "point_coord"), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("ScreenUV", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_fragment_and_light_shader_modes), "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("ShadowColor", "Input", "Light", "VisualShaderNodeInput", vformat(TTR(input_param_for_light_shader_mode), "shadow_color"), "shadow_color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_LIGHT, Shader::MODE_CANVAS_ITEM)); + + add_options.push_back(AddOption("Extra", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "extra"), "extra", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("LightPass", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_and_fragment_shader_modes), "light_pass"), "light_pass", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("PointSize", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "point_size"), "point_size", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("Projection", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "projection"), "projection", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("Vertex", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "vertex"), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); + add_options.push_back(AddOption("World", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "world"), "world", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_CANVAS_ITEM)); // PARTICLES INPUTS - add_options.push_back(AddOption("Active", "Input", "Vertex", "VisualShaderNodeInput", TTR("'active' input parameter for vertex shader mode."), "active", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Alpha", "Input", "Vertex", "VisualShaderNodeInput", TTR("'alpha' input parameter for vertex shader mode."), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Color", "Input", "Vertex", "VisualShaderNodeInput", TTR("'color' input parameter for vertex shader mode."), "color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Custom", "Input", "Vertex", "VisualShaderNodeInput", TTR("'custom' input parameter for vertex shader mode."), "custom", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("CustomAlpha", "Input", "Vertex", "VisualShaderNodeInput", TTR("'custom_alpha' input parameter for vertex shader mode."), "custom_alpha", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Delta", "Input", "Vertex", "VisualShaderNodeInput", TTR("'delta' input parameter for vertex shader mode."), "delta", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("EmissionTransform", "Input", "Vertex", "VisualShaderNodeInput", TTR("'emission_transform' input parameter for vertex shader mode."), "emission_transform", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Index", "Input", "Vertex", "VisualShaderNodeInput", TTR("'index' input parameter for vertex shader mode."), "index", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("LifeTime", "Input", "Vertex", "VisualShaderNodeInput", TTR("'lifetime' input parameter for vertex shader mode."), "lifetime", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Restart", "Input", "Vertex", "VisualShaderNodeInput", TTR("'restart' input parameter for vertex shader mode."), "restart", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Time", "Input", "Vertex", "VisualShaderNodeInput", TTR("'time' input parameter for vertex shader mode."), "time", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Transform", "Input", "Vertex", "VisualShaderNodeInput", TTR("'transform' input parameter for vertex shader mode."), "transform", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Velocity", "Input", "Vertex", "VisualShaderNodeInput", TTR("'velocity' input parameter for vertex shader mode."), "velocity", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Active", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "active"), "active", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Alpha", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Color", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Custom", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "custom"), "custom", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("CustomAlpha", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "custom_alpha"), "custom_alpha", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Delta", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "delta"), "delta", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("EmissionTransform", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "emission_transform"), "emission_transform", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Index", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "index"), "index", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("LifeTime", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "lifetime"), "lifetime", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Restart", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "restart"), "restart", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Time", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Transform", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "transform"), "transform", VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Velocity", "Input", "Vertex", "VisualShaderNodeInput", vformat(TTR(input_param_for_vertex_shader_mode), "velocity"), "velocity", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_VERTEX, Shader::MODE_PARTICLES)); // SCALAR @@ -2350,7 +2401,7 @@ VisualShaderEditorPlugin::~VisualShaderEditorPlugin() { //////////////// class VisualShaderNodePluginInputEditor : public OptionButton { - GDCLASS(VisualShaderNodePluginInputEditor, OptionButton) + GDCLASS(VisualShaderNodePluginInputEditor, OptionButton); Ref<VisualShaderNodeInput> input; @@ -2395,7 +2446,8 @@ public: }; class VisualShaderNodePluginDefaultEditor : public VBoxContainer { - GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer) + GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer); + public: void _property_changed(const String &prop, const Variant &p_value, const String &p_field, bool p_changing = false) { @@ -2719,3 +2771,30 @@ void VisualShaderNodePortPreview::_bind_methods() { VisualShaderNodePortPreview::VisualShaderNodePortPreview() { } + +////////////////////////////////// + +String VisualShaderConversionPlugin::converts_to() const { + + return "Shader"; +} + +bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const { + + Ref<VisualShader> vshader = p_resource; + return vshader.is_valid(); +} + +Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const { + + Ref<VisualShader> vshader = p_resource; + ERR_FAIL_COND_V(!vshader.is_valid(), Ref<Resource>()); + + Ref<Shader> shader; + shader.instance(); + + String code = vshader->get_code(); + shader->set_code(code); + + return shader; +} diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 1b009b61d5..fa72b5ec29 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -42,7 +42,8 @@ class VisualShaderNodePlugin : public Reference { - GDCLASS(VisualShaderNodePlugin, Reference) + GDCLASS(VisualShaderNodePlugin, Reference); + protected: static void _bind_methods(); @@ -159,7 +160,13 @@ class VisualShaderEditor : public VBoxContainer { void _edit_port_default_input(Object *p_button, int p_node, int p_port); void _port_edited(); + int to_node; + int to_slot; + int from_node; + int from_slot; + void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position); + void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position); void _line_edit_changed(const String &p_text, Object *line_edit, int p_node_id); void _line_edit_focus_out(Object *line_edit, int p_node_id); @@ -175,12 +182,12 @@ class VisualShaderEditor : public VBoxContainer { void _input_select_item(Ref<VisualShaderNodeInput> input, String name); - void _add_input_port(int p_node, int p_port, int p_type, const String &p_name); + void _add_input_port(int p_node, int p_port, int p_port_type, const String &p_name); void _remove_input_port(int p_node, int p_port); void _change_input_port_type(int p_type, int p_node, int p_port); void _change_input_port_name(const String &p_text, Object *line_edit, int p_node, int p_port); - void _add_output_port(int p_node, int p_port, int p_type, const String &p_name); + void _add_output_port(int p_node, int p_port, int p_port_type, const String &p_name); void _remove_output_port(int p_node, int p_port); void _change_output_port_type(int p_type, int p_node, int p_port); void _change_output_port_name(const String &p_text, Object *line_edit, int p_node, int p_port); @@ -198,12 +205,13 @@ class VisualShaderEditor : public VBoxContainer { void _member_selected(); void _member_unselected(); void _member_create(); + void _member_cancel(); Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); - bool _is_available(int p_flags); + bool _is_available(int p_mode); void _update_created_node(GraphNode *node); protected: @@ -245,14 +253,14 @@ public: class VisualShaderNodePluginDefault : public VisualShaderNodePlugin { - GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin) + GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin); public: virtual Control *create_editor(const Ref<VisualShaderNode> &p_node); }; class EditorPropertyShaderMode : public EditorProperty { - GDCLASS(EditorPropertyShaderMode, EditorProperty) + GDCLASS(EditorPropertyShaderMode, EditorProperty); OptionButton *options; void _option_selected(int p_which); @@ -268,7 +276,7 @@ public: }; class EditorInspectorShaderModePlugin : public EditorInspectorPlugin { - GDCLASS(EditorInspectorShaderModePlugin, EditorInspectorPlugin) + GDCLASS(EditorInspectorShaderModePlugin, EditorInspectorPlugin); public: virtual bool can_handle(Object *p_object); @@ -278,7 +286,7 @@ public: }; class VisualShaderNodePortPreview : public Control { - GDCLASS(VisualShaderNodePortPreview, Control) + GDCLASS(VisualShaderNodePortPreview, Control); Ref<VisualShader> shader; VisualShader::Type type; int node; @@ -294,4 +302,13 @@ public: VisualShaderNodePortPreview(); }; +class VisualShaderConversionPlugin : public EditorResourceConversionPlugin { + GDCLASS(VisualShaderConversionPlugin, EditorResourceConversionPlugin); + +public: + virtual String converts_to() const; + virtual bool handles(const Ref<Resource> &p_resource) const; + virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const; +}; + #endif // VISUAL_SHADER_EDITOR_PLUGIN_H |