diff options
Diffstat (limited to 'editor/plugins')
63 files changed, 937 insertions, 2178 deletions
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index c8a36a3a99..b2d132b3da 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -573,7 +573,7 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); // All polygon points are sharp, so use the sharp handle icon - const Ref<Texture> handle = get_icon("EditorPathSharpHandle", "EditorIcons"); + const Ref<Texture2D> handle = get_icon("EditorPathSharpHandle", "EditorIcons"); const Vertex active_point = get_active_point(); const int n_polygons = _get_polygon_count(); @@ -612,7 +612,7 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl Vector2 point = xform.xform(p); Vector2 next_point = xform.xform(p2); - p_overlay->draw_line(point, next_point, col, Math::round(2 * EDSCALE), true); + p_overlay->draw_line(point, next_point, col, Math::round(2 * EDSCALE)); } } @@ -636,7 +636,7 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl p2 = points[(i + 1) % n_points] + offset; const Vector2 next_point = xform.xform(p2); - p_overlay->draw_line(point, next_point, col, Math::round(2 * EDSCALE), true); + p_overlay->draw_line(point, next_point, col, Math::round(2 * EDSCALE)); } } @@ -661,7 +661,7 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl if (edge_point.valid()) { - Ref<Texture> add_handle = get_icon("EditorHandleAdd", "EditorIcons"); + Ref<Texture2D> add_handle = get_icon("EditorHandleAdd", "EditorIcons"); p_overlay->draw_texture(add_handle, edge_point.pos - add_handle->get_size() * 0.5); } } diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index d743d1ac2f..9261613ddd 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -202,8 +202,8 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { linecolor_soft.a *= 0.5; Ref<Font> font = get_font("font", "Label"); - Ref<Texture> icon = get_icon("KeyValue", "EditorIcons"); - Ref<Texture> icon_selected = get_icon("KeySelected", "EditorIcons"); + Ref<Texture2D> icon = get_icon("KeyValue", "EditorIcons"); + Ref<Texture2D> icon_selected = get_icon("KeySelected", "EditorIcons"); Size2 s = blend_space_draw->get_size(); diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index dc7754ba9a..fdd8ffd58f 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -410,8 +410,8 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { Color linecolor_soft = linecolor; linecolor_soft.a *= 0.5; Ref<Font> font = get_font("font", "Label"); - Ref<Texture> icon = get_icon("KeyValue", "EditorIcons"); - Ref<Texture> icon_selected = get_icon("KeySelected", "EditorIcons"); + Ref<Texture2D> icon = get_icon("KeyValue", "EditorIcons"); + Ref<Texture2D> icon_selected = get_icon("KeySelected", "EditorIcons"); Size2 s = blend_space_draw->get_size(); @@ -497,7 +497,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { } for (int j = 0; j < 3; j++) { - blend_space_draw->draw_line(points[j], points[(j + 1) % 3], linecolor, 1, true); + blend_space_draw->draw_line(points[j], points[(j + 1) % 3], linecolor, 1); } Color color; @@ -553,9 +553,9 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { } for (int i = 0; i < points.size() - 1; i++) { - blend_space_draw->draw_line(points[i], points[i + 1], linecolor, 2, true); + blend_space_draw->draw_line(points[i], points[i + 1], linecolor, 2); } - blend_space_draw->draw_line(points[points.size() - 1], blend_space_draw->get_local_mouse_position(), linecolor, 2, true); + blend_space_draw->draw_line(points[points.size() - 1], blend_space_draw->get_local_mouse_position(), linecolor, 2); } ///draw cursor position diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 2de224c043..a100525d10 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -312,7 +312,7 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instance(base_type)); ERR_FAIL_COND(!an); anode = Ref<AnimationNode>(an); - anode->set_script(add_options[p_idx].script.get_ref_ptr()); + anode->set_script(add_options[p_idx].script); base_name = add_options[p_idx].name; } diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 5e69ce4e69..d8bbac9c49 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -1322,11 +1322,10 @@ void AnimationPlayerEditor::_allocate_onion_layers() { // 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); VS::get_singleton()->viewport_set_update_mode(onion.captures[i], VS::VIEWPORT_UPDATE_ALWAYS); VS::get_singleton()->viewport_set_transparent_background(onion.captures[i], !is_present); - VS::get_singleton()->viewport_set_vflip(onion.captures[i], true); VS::get_singleton()->viewport_attach_canvas(onion.captures[i], onion.capture.canvas); } diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index 55c2f365ce..ab9db279d5 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -105,7 +105,7 @@ class AnimationPlayerEditor : public VBoxContainer { LineEdit *name; Label *name_title; UndoRedo *undo_redo; - Ref<Texture> autoplay_icon; + Ref<Texture2D> autoplay_icon; bool last_active; float timeline_position; diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 2a582a1249..035a67b821 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -514,7 +514,7 @@ void AnimationNodeStateMachineEditor::_connection_draw(const Vector2 &p_from, co accent.a *= 0.6; } - Ref<Texture> icons[6] = { + Ref<Texture2D> icons[6] = { get_icon("TransitionImmediateBig", "EditorIcons"), get_icon("TransitionSyncBig", "EditorIcons"), get_icon("TransitionEndBig", "EditorIcons"), @@ -524,16 +524,16 @@ void AnimationNodeStateMachineEditor::_connection_draw(const Vector2 &p_from, co }; if (p_selected) { - state_machine_draw->draw_line(p_from, p_to, accent, 6, true); + state_machine_draw->draw_line(p_from, p_to, accent, 6); } if (p_travel) { linecolor = accent; linecolor.set_hsv(1.0, linecolor.get_s(), linecolor.get_v()); } - state_machine_draw->draw_line(p_from, p_to, linecolor, 2, true); + state_machine_draw->draw_line(p_from, p_to, linecolor, 2); - Ref<Texture> icon = icons[p_mode + (p_auto_advance ? 3 : 0)]; + Ref<Texture2D> icon = icons[p_mode + (p_auto_advance ? 3 : 0)]; Transform2D xf; xf.elements[0] = (p_to - p_from).normalized(); @@ -578,9 +578,9 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { Ref<Font> font = get_font("title_font", "GraphNode"); Color font_color = get_color("title_color", "GraphNode"); - Ref<Texture> play = get_icon("Play", "EditorIcons"); - Ref<Texture> auto_play = get_icon("AutoPlay", "EditorIcons"); - Ref<Texture> edit = get_icon("Edit", "EditorIcons"); + Ref<Texture2D> play = get_icon("Play", "EditorIcons"); + Ref<Texture2D> auto_play = get_icon("AutoPlay", "EditorIcons"); + Ref<Texture2D> edit = get_icon("Edit", "EditorIcons"); Color accent = get_color("accent_color", "Editor"); Color linecolor = get_color("font_color", "Label"); linecolor.a *= 0.3; @@ -686,7 +686,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { _connection_draw(from, to, AnimationNodeStateMachineTransition::SwitchMode(transition_mode->get_selected()), true, false, false, false); } - Ref<Texture> tr_reference_icon = get_icon("TransitionImmediateBig", "EditorIcons"); + Ref<Texture2D> tr_reference_icon = get_icon("TransitionImmediateBig", "EditorIcons"); float tr_bidi_offset = int(tr_reference_icon->get_height() * 0.8); //draw transition lines @@ -796,7 +796,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { nr.play.position = offset + Vector2(0, (h - play->get_height()) / 2).floor(); nr.play.size = play->get_size(); - Ref<Texture> play_tex = onstart ? auto_play : play; + Ref<Texture2D> play_tex = onstart ? auto_play : play; if (over_node == name && over_node_what == 0) { state_machine_draw->draw_texture(play_tex, nr.play.position, accent); @@ -918,14 +918,6 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { transition_mode->add_icon_item(get_icon("TransitionSync", "EditorIcons"), TTR("Sync")); transition_mode->add_icon_item(get_icon("TransitionEnd", "EditorIcons"), TTR("At End")); - //force filter on those, so they deform better - get_icon("TransitionImmediateBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER); - get_icon("TransitionEndBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER); - get_icon("TransitionSyncBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER); - get_icon("TransitionImmediateAutoBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER); - get_icon("TransitionEndAutoBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER); - get_icon("TransitionSyncAutoBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER); - tool_erase->set_icon(get_icon("Remove", "EditorIcons")); tool_autoplay->set_icon(get_icon("AutoPlay", "EditorIcons")); tool_end->set_icon(get_icon("AutoEnd", "EditorIcons")); diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index 8dc7e4638d..a729c90160 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -59,7 +59,7 @@ void AnimationTreeEditor::edit(AnimationTree *p_tree) { path = tree->get_meta("_tree_edit_path"); edit_path(path); } else { - current_root = 0; + current_root = ObjectID(); } } @@ -128,7 +128,7 @@ void AnimationTreeEditor::edit_path(const Vector<String> &p_path) { } } } else { - current_root = 0; + current_root = ObjectID(); edited_path = button_path; } @@ -151,7 +151,7 @@ void AnimationTreeEditor::_about_to_show_root() { void AnimationTreeEditor::_notification(int p_what) { if (p_what == NOTIFICATION_PROCESS) { - ObjectID root = 0; + ObjectID root; if (tree && tree->get_tree_root().is_valid()) { root = tree->get_tree_root()->get_instance_id(); } @@ -242,7 +242,6 @@ AnimationTreeEditor::AnimationTreeEditor() { add_child(memnew(HSeparator)); - current_root = 0; singleton = this; editor_base = memnew(PanelContainer); editor_base->set_v_size_flags(SIZE_EXPAND_FILL); diff --git a/editor/plugins/animation_tree_player_editor_plugin.cpp b/editor/plugins/animation_tree_player_editor_plugin.cpp deleted file mode 100644 index 2b365feec5..0000000000 --- a/editor/plugins/animation_tree_player_editor_plugin.cpp +++ /dev/null @@ -1,1451 +0,0 @@ -/*************************************************************************/ -/* animation_tree_player_editor_plugin.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "animation_tree_player_editor_plugin.h" - -#include "core/io/resource_loader.h" -#include "core/os/input.h" -#include "core/os/keyboard.h" -#include "core/project_settings.h" -#include "editor/editor_scale.h" -#include "scene/gui/menu_button.h" -#include "scene/gui/panel.h" -#include "scene/main/viewport.h" - -void AnimationTreePlayerEditor::edit(AnimationTreePlayer *p_anim_tree) { - - anim_tree = p_anim_tree; - - if (!anim_tree) { - hide(); - } else { - order.clear(); - p_anim_tree->get_node_list(&order); - /* - for(List<StringName>::Element* E=order.front();E;E=E->next()) { - - if (E->get() >= (int)last_id) - last_id=E->get()+1; - }*/ - play_button->set_pressed(p_anim_tree->is_active()); - //read the orders - } -} - -Size2 AnimationTreePlayerEditor::_get_maximum_size() { - - Size2 max; - - for (List<StringName>::Element *E = order.front(); E; E = E->next()) { - - Point2 pos = anim_tree->node_get_position(E->get()); - - if (click_type == CLICK_NODE && click_node == E->get()) { - - pos += click_motion - click_pos; - } - pos += get_node_size(E->get()); - if (pos.x > max.x) - max.x = pos.x; - if (pos.y > max.y) - max.y = pos.y; - } - - return max; -} - -const char *AnimationTreePlayerEditor::_node_type_names[] = { "Output", "Animation", "OneShot", "Mix", "Blend2", "Blend3", "Blend4", "TimeScale", "TimeSeek", "Transition" }; - -Size2 AnimationTreePlayerEditor::get_node_size(const StringName &p_node) const { - - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Ref<Font> font = get_font("font", "PopupMenu"); - - Size2 size = style->get_minimum_size(); - - int count = 2; // title and name - int inputs = anim_tree->node_get_input_count(p_node); - count += inputs ? inputs : 1; - String name = p_node; - - float name_w = font->get_string_size(name).width; - float type_w = font->get_string_size(String(_node_type_names[type])).width; - float max_w = MAX(name_w, type_w); - - switch (type) { - case AnimationTreePlayer::NODE_TIMESEEK: - case AnimationTreePlayer::NODE_OUTPUT: { - } break; - case AnimationTreePlayer::NODE_ANIMATION: - case AnimationTreePlayer::NODE_ONESHOT: - case AnimationTreePlayer::NODE_MIX: - case AnimationTreePlayer::NODE_BLEND2: - case AnimationTreePlayer::NODE_BLEND3: - case AnimationTreePlayer::NODE_BLEND4: - case AnimationTreePlayer::NODE_TIMESCALE: - case AnimationTreePlayer::NODE_TRANSITION: { - - size.height += font->get_height(); - } break; - case AnimationTreePlayer::NODE_MAX: { - } - } - - size.x += max_w + 20; - size.y += count * (font->get_height() + get_constant("vseparation", "PopupMenu")); - - return size; -} - -void AnimationTreePlayerEditor::_edit_dialog_changede(String) { - - edit_dialog->hide(); -} - -void AnimationTreePlayerEditor::_edit_dialog_changeds(String s) { - - _edit_dialog_changed(); -} - -void AnimationTreePlayerEditor::_edit_dialog_changedf(float) { - - _edit_dialog_changed(); -} - -void AnimationTreePlayerEditor::_edit_dialog_changed() { - - if (updating_edit) - return; - - if (renaming_edit) { - - if (anim_tree->node_rename(edited_node, edit_line[0]->get_text()) == OK) { - for (List<StringName>::Element *E = order.front(); E; E = E->next()) { - - if (E->get() == edited_node) - E->get() = edit_line[0]->get_text(); - } - edited_node = edit_line[0]->get_text(); - } - update(); - return; - } - - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node); - - switch (type) { - - case AnimationTreePlayer::NODE_TIMESCALE: - anim_tree->timescale_node_set_scale(edited_node, edit_line[0]->get_text().to_double()); - break; - case AnimationTreePlayer::NODE_ONESHOT: - anim_tree->oneshot_node_set_fadein_time(edited_node, edit_line[0]->get_text().to_double()); - anim_tree->oneshot_node_set_fadeout_time(edited_node, edit_line[1]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart_delay(edited_node, edit_line[2]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart_random_delay(edited_node, edit_line[3]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart(edited_node, edit_check->is_pressed()); - anim_tree->oneshot_node_set_mix_mode(edited_node, edit_option->get_selected()); - - break; - - case AnimationTreePlayer::NODE_MIX: - - anim_tree->mix_node_set_amount(edited_node, edit_scroll[0]->get_value()); - break; - case AnimationTreePlayer::NODE_BLEND2: - anim_tree->blend2_node_set_amount(edited_node, edit_scroll[0]->get_value()); - - break; - - case AnimationTreePlayer::NODE_BLEND3: - anim_tree->blend3_node_set_amount(edited_node, edit_scroll[0]->get_value()); - - break; - case AnimationTreePlayer::NODE_BLEND4: - - anim_tree->blend4_node_set_amount(edited_node, Point2(edit_scroll[0]->get_value(), edit_scroll[1]->get_value())); - - break; - - case AnimationTreePlayer::NODE_TRANSITION: { - anim_tree->transition_node_set_xfade_time(edited_node, edit_line[0]->get_text().to_double()); - if (anim_tree->transition_node_get_current(edited_node) != edit_option->get_selected()) - anim_tree->transition_node_set_current(edited_node, edit_option->get_selected()); - } break; - default: { - } - } -} - -void AnimationTreePlayerEditor::_edit_dialog_animation_changed() { - - Ref<Animation> anim = property_editor->get_variant().operator RefPtr(); - anim_tree->animation_node_set_animation(edited_node, anim); - update(); -} - -void AnimationTreePlayerEditor::_edit_dialog_edit_animation() { - - if (Engine::get_singleton()->is_editor_hint()) { - get_tree()->get_root()->get_child(0)->call("_resource_selected", property_editor->get_variant().operator RefPtr()); - }; -}; - -void AnimationTreePlayerEditor::_edit_oneshot_start() { - - anim_tree->oneshot_node_start(edited_node); -} - -void AnimationTreePlayerEditor::_play_toggled() { - - anim_tree->set_active(play_button->is_pressed()); -} - -void AnimationTreePlayerEditor::_master_anim_menu_item(int p_item) { - - if (p_item == 0) - _edit_filters(); - else { - - String str = master_anim_popup->get_item_text(p_item); - anim_tree->animation_node_set_master_animation(edited_node, str); - } - update(); -} - -void AnimationTreePlayerEditor::_popup_edit_dialog() { - - updating_edit = true; - - for (int i = 0; i < 2; i++) - edit_scroll[i]->hide(); - - for (int i = 0; i < 4; i++) { - - edit_line[i]->hide(); - edit_label[i]->hide(); - } - - edit_option->hide(); - edit_button->hide(); - filter_button->hide(); - edit_check->hide(); - - Point2 pos = anim_tree->node_get_position(edited_node) - Point2(h_scroll->get_value(), v_scroll->get_value()); - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Size2 size = get_node_size(edited_node); - Point2 popup_pos(pos.x + style->get_margin(MARGIN_LEFT), pos.y + size.y - style->get_margin(MARGIN_BOTTOM)); - popup_pos += get_global_position(); - - if (renaming_edit) { - - edit_label[0]->set_text(TTR("New name:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15, 25)); - edit_line[0]->set_text(edited_node); - edit_line[0]->show(); - edit_dialog->set_size(Size2(150, 50)); - - } else { - - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node); - - switch (type) { - - case AnimationTreePlayer::NODE_ANIMATION: - - if (anim_tree->get_master_player() != NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && Object::cast_to<AnimationPlayer>(anim_tree->get_node(anim_tree->get_master_player()))) { - - AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(anim_tree->get_node(anim_tree->get_master_player())); - master_anim_popup->clear(); - master_anim_popup->add_item(TTR("Edit Filters")); - master_anim_popup->add_separator(); - List<StringName> sn; - ap->get_animation_list(&sn); - sn.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = sn.front(); E; E = E->next()) { - master_anim_popup->add_item(E->get()); - } - - master_anim_popup->set_position(popup_pos); - master_anim_popup->popup(); - } else { - property_editor->edit(this, "", Variant::OBJECT, anim_tree->animation_node_get_animation(edited_node), PROPERTY_HINT_RESOURCE_TYPE, "Animation"); - property_editor->set_position(popup_pos); - property_editor->popup(); - updating_edit = false; - } - return; - case AnimationTreePlayer::NODE_TIMESCALE: - edit_label[0]->set_text(TTR("Scale:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15, 25)); - edit_line[0]->set_text(rtos(anim_tree->timescale_node_get_scale(edited_node))); - edit_line[0]->show(); - edit_dialog->set_size(Size2(150, 50)); - break; - case AnimationTreePlayer::NODE_ONESHOT: - edit_label[0]->set_text(TTR("Fade In (s):")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15, 25)); - edit_line[0]->set_text(rtos(anim_tree->oneshot_node_get_fadein_time(edited_node))); - edit_line[0]->show(); - edit_label[1]->set_text(TTR("Fade Out (s):")); - edit_label[1]->set_position(Point2(5, 55)); - edit_label[1]->show(); - edit_line[1]->set_begin(Point2(15, 75)); - edit_line[1]->set_text(rtos(anim_tree->oneshot_node_get_fadeout_time(edited_node))); - edit_line[1]->show(); - - edit_option->clear(); - edit_option->add_item(TTR("Blend"), 0); - edit_option->add_item(TTR("Mix"), 1); - edit_option->set_begin(Point2(15, 105)); - - edit_option->select(anim_tree->oneshot_node_get_mix_mode(edited_node)); - edit_option->show(); - - edit_check->set_text(TTR("Auto Restart:")); - edit_check->set_begin(Point2(15, 125)); - edit_check->set_pressed(anim_tree->oneshot_node_has_autorestart(edited_node)); - edit_check->show(); - - edit_label[2]->set_text(TTR("Restart (s):")); - edit_label[2]->set_position(Point2(5, 145)); - edit_label[2]->show(); - edit_line[2]->set_begin(Point2(15, 165)); - edit_line[2]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_delay(edited_node))); - edit_line[2]->show(); - edit_label[3]->set_text(TTR("Random Restart (s):")); - edit_label[3]->set_position(Point2(5, 195)); - edit_label[3]->show(); - edit_line[3]->set_begin(Point2(15, 215)); - edit_line[3]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_random_delay(edited_node))); - edit_line[3]->show(); - - filter_button->set_begin(Point2(10, 245)); - filter_button->show(); - - edit_button->set_begin(Point2(10, 268)); - edit_button->set_text(TTR("Start!")); - - edit_button->show(); - - edit_dialog->set_size(Size2(180, 293)); - - break; - - case AnimationTreePlayer::NODE_MIX: - - edit_label[0]->set_text(TTR("Amount:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(0); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_step(0.01); - edit_scroll[0]->set_value(anim_tree->mix_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15, 25)); - edit_scroll[0]->show(); - edit_dialog->set_size(Size2(150, 50)); - - break; - case AnimationTreePlayer::NODE_BLEND2: - edit_label[0]->set_text(TTR("Blend:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(0); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_step(0.01); - edit_scroll[0]->set_value(anim_tree->blend2_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15, 25)); - edit_scroll[0]->show(); - filter_button->set_begin(Point2(10, 47)); - filter_button->show(); - edit_dialog->set_size(Size2(150, 74)); - - break; - - case AnimationTreePlayer::NODE_BLEND3: - edit_label[0]->set_text(TTR("Blend:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(-1); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_step(0.01); - edit_scroll[0]->set_value(anim_tree->blend3_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15, 25)); - edit_scroll[0]->show(); - edit_dialog->set_size(Size2(150, 50)); - - break; - case AnimationTreePlayer::NODE_BLEND4: - - edit_label[0]->set_text(TTR("Blend 0:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(0); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_step(0.01); - edit_scroll[0]->set_value(anim_tree->blend4_node_get_amount(edited_node).x); - edit_scroll[0]->set_begin(Point2(15, 25)); - edit_scroll[0]->show(); - edit_label[1]->set_text(TTR("Blend 1:")); - edit_label[1]->set_position(Point2(5, 55)); - edit_label[1]->show(); - edit_scroll[1]->set_min(0); - edit_scroll[1]->set_max(1); - edit_scroll[1]->set_step(0.01); - edit_scroll[1]->set_value(anim_tree->blend4_node_get_amount(edited_node).y); - edit_scroll[1]->set_begin(Point2(15, 75)); - edit_scroll[1]->show(); - edit_dialog->set_size(Size2(150, 100)); - - break; - - case AnimationTreePlayer::NODE_TRANSITION: { - - edit_label[0]->set_text(TTR("X-Fade Time (s):")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15, 25)); - edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node))); - edit_line[0]->show(); - - edit_label[1]->set_text(TTR("Current:")); - edit_label[1]->set_position(Point2(5, 55)); - edit_label[1]->show(); - edit_option->set_begin(Point2(15, 75)); - - edit_option->clear(); - - for (int i = 0; i < anim_tree->transition_node_get_input_count(edited_node); i++) { - edit_option->add_item(itos(i), i); - } - - edit_option->select(anim_tree->transition_node_get_current(edited_node)); - edit_option->show(); - edit_dialog->set_size(Size2(150, 100)); - - } break; - default: { - } - } - } - - edit_dialog->set_position(popup_pos); - edit_dialog->popup(); - - updating_edit = false; -} - -void AnimationTreePlayerEditor::_draw_node(const StringName &p_node) { - - RID ci = get_canvas_item(); - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Ref<Font> font = get_font("font", "PopupMenu"); - Color font_color = get_color("font_color", "PopupMenu"); - Color font_color_title = get_color("font_color_hover", "PopupMenu"); - font_color_title.a *= 0.8; - Ref<Texture> slot_icon = get_icon("VisualShaderPort", "EditorIcons"); - - Size2 size = get_node_size(p_node); - Point2 pos = anim_tree->node_get_position(p_node); - if (click_type == CLICK_NODE && click_node == p_node) { - - pos += click_motion - click_pos; - if (pos.x < 5) - pos.x = 5; - if (pos.y < 5) - pos.y = 5; - } - - pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - - style->draw(ci, Rect2(pos, size)); - - float w = size.width - style->get_minimum_size().width; - float h = font->get_height() + get_constant("vseparation", "PopupMenu"); - - Point2 ofs = style->get_offset() + pos; - Point2 ascofs(0, font->get_ascent()); - - Color bx = font_color_title; - bx.a *= 0.1; - draw_rect(Rect2(ofs, Size2(size.width - style->get_minimum_size().width, font->get_height())), bx); - font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, String(_node_type_names[type]), font_color_title); - - ofs.y += h; - font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, p_node, font_color); - ofs.y += h; - - int inputs = anim_tree->node_get_input_count(p_node); - - float icon_h_ofs = Math::floor((font->get_height() - slot_icon->get_height()) / 2.0) + 1; - - if (type != AnimationTreePlayer::NODE_OUTPUT) - slot_icon->draw(ci, ofs + Point2(w, icon_h_ofs)); //output - - if (inputs) { - for (int i = 0; i < inputs; i++) { - - slot_icon->draw(ci, ofs + Point2(-slot_icon->get_width(), icon_h_ofs)); - String text; - switch (type) { - - case AnimationTreePlayer::NODE_TIMESCALE: - case AnimationTreePlayer::NODE_TIMESEEK: text = "in"; break; - case AnimationTreePlayer::NODE_OUTPUT: text = "out"; break; - case AnimationTreePlayer::NODE_ANIMATION: break; - case AnimationTreePlayer::NODE_ONESHOT: text = (i == 0 ? "in" : "add"); break; - case AnimationTreePlayer::NODE_BLEND2: - case AnimationTreePlayer::NODE_MIX: text = (i == 0 ? "a" : "b"); break; - case AnimationTreePlayer::NODE_BLEND3: - switch (i) { - case 0: text = "b-"; break; - case 1: text = "a"; break; - case 2: text = "b+"; break; - } - break; - - case AnimationTreePlayer::NODE_BLEND4: - switch (i) { - case 0: text = "a0"; break; - case 1: text = "b0"; break; - case 2: text = "a1"; break; - case 3: text = "b1"; break; - } - break; - - case AnimationTreePlayer::NODE_TRANSITION: - text = itos(i); - if (anim_tree->transition_node_has_input_auto_advance(p_node, i)) - text += "->"; - - break; - default: { - } - } - font->draw(ci, ofs + ascofs + Point2(3, 0), text, font_color); - - ofs.y += h; - } - } else { - ofs.y += h; - } - - Ref<StyleBox> pg_bg = get_stylebox("bg", "ProgressBar"); - Ref<StyleBox> pg_fill = get_stylebox("fill", "ProgressBar"); - Rect2 pg_rect(ofs, Size2(w, h)); - - bool editable = true; - switch (type) { - case AnimationTreePlayer::NODE_ANIMATION: { - - Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node); - String text; - if (anim_tree->animation_node_get_master_animation(p_node) != "") - text = anim_tree->animation_node_get_master_animation(p_node); - else if (anim.is_null()) - text = "load..."; - else - text = anim->get_name(); - - font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, text, font_color_title); - - } break; - case AnimationTreePlayer::NODE_ONESHOT: - case AnimationTreePlayer::NODE_MIX: - case AnimationTreePlayer::NODE_BLEND2: - case AnimationTreePlayer::NODE_BLEND3: - case AnimationTreePlayer::NODE_BLEND4: - case AnimationTreePlayer::NODE_TIMESCALE: - case AnimationTreePlayer::NODE_TRANSITION: { - - font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, "edit...", font_color_title); - } break; - default: editable = false; - } - - if (editable) { - - Ref<Texture> arrow = get_icon("GuiDropdown", "EditorIcons"); - Point2 arrow_ofs(w - arrow->get_width(), Math::floor((h - arrow->get_height()) / 2)); - arrow->draw(ci, ofs + arrow_ofs); - } -} - -AnimationTreePlayerEditor::ClickType AnimationTreePlayerEditor::_locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const { - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Ref<Font> font = get_font("font", "PopupMenu"); - - float h = (font->get_height() + get_constant("vseparation", "PopupMenu")); - - for (const List<StringName>::Element *E = order.back(); E; E = E->prev()) { - - const StringName &node = E->get(); - - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(node); - - Point2 pos = anim_tree->node_get_position(node); - Size2 size = get_node_size(node); - - pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - - if (!Rect2(pos, size).has_point(p_click)) - continue; - - if (p_node_id) - *p_node_id = node; - - pos = p_click - pos; - - float y = pos.y - style->get_offset().height; - - if (y < 2 * h) - return CLICK_NODE; - y -= 2 * h; - - int inputs = anim_tree->node_get_input_count(node); - int count = MAX(inputs, 1); - - if (inputs == 0 || (pos.x > size.width / 2 && type != AnimationTreePlayer::NODE_OUTPUT)) { - - if (y < count * h) { - - if (p_slot_index) - *p_slot_index = 0; - return CLICK_OUTPUT_SLOT; - } - } - - for (int i = 0; i < count; i++) { - - if (y < h) { - if (p_slot_index) - *p_slot_index = i; - return CLICK_INPUT_SLOT; - } - y -= h; - } - - bool has_parameters = type != AnimationTreePlayer::NODE_OUTPUT && type != AnimationTreePlayer::NODE_TIMESEEK; - return has_parameters ? CLICK_PARAMETER : CLICK_NODE; - } - - return CLICK_NONE; -} - -Point2 AnimationTreePlayerEditor::_get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot) { - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Ref<Font> font = get_font("font", "PopupMenu"); - Ref<Texture> slot_icon = get_icon("VisualShaderPort", "EditorIcons"); - - Size2 size = get_node_size(p_node_id); - Point2 pos = anim_tree->node_get_position(p_node_id); - - if (click_type == CLICK_NODE && click_node == p_node_id) { - - pos += click_motion - click_pos; - if (pos.x < 5) - pos.x = 5; - if (pos.y < 5) - pos.y = 5; - } - - pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - - float w = size.width - style->get_minimum_size().width; - float h = font->get_height() + get_constant("vseparation", "PopupMenu"); - - pos += style->get_offset(); - - pos.y += h * 2; - - pos.y += h * p_slot; - - pos += Point2(-slot_icon->get_width() / 2.0, h / 2.0).floor(); - - if (!p_input) { - pos.x += w + slot_icon->get_width(); - } - - return pos; -} - -void AnimationTreePlayerEditor::_gui_input(Ref<InputEvent> p_event) { - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid()) { - - if (mb->is_pressed()) { - - if (mb->get_button_index() == 1) { - click_pos = Point2(mb->get_position().x, mb->get_position().y); - click_motion = click_pos; - click_type = _locate_click(click_pos, &click_node, &click_slot); - if (click_type != CLICK_NONE) { - - order.erase(click_node); - order.push_back(click_node); - update(); - } - - switch (click_type) { - case CLICK_INPUT_SLOT: { - click_pos = _get_slot_pos(click_node, true, click_slot); - } break; - case CLICK_OUTPUT_SLOT: { - click_pos = _get_slot_pos(click_node, false, click_slot); - } break; - case CLICK_PARAMETER: { - - edited_node = click_node; - renaming_edit = false; - _popup_edit_dialog(); - //open editor - //_node_edit_property(click_node); - } break; - default: { - } - } - } - if (mb->get_button_index() == 2) { - - if (click_type != CLICK_NONE) { - click_type = CLICK_NONE; - update(); - } else { - // try to disconnect/remove - - Point2 rclick_pos = Point2(mb->get_position().x, mb->get_position().y); - rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot); - if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) { - - node_popup->clear(); - node_popup->set_size(Size2(1, 1)); - node_popup->add_item(TTR("Disconnect"), NODE_DISCONNECT); - if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) { - node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT); - if (rclick_type == CLICK_INPUT_SLOT) { - if (anim_tree->transition_node_has_input_auto_advance(rclick_node, rclick_slot)) - node_popup->add_item(TTR("Clear Auto-Advance"), NODE_CLEAR_AUTOADVANCE); - else - node_popup->add_item(TTR("Set Auto-Advance"), NODE_SET_AUTOADVANCE); - node_popup->add_item(TTR("Delete Input"), NODE_DELETE_INPUT); - } - } - - node_popup->set_position(rclick_pos + get_global_position()); - node_popup->popup(); - } - - if (rclick_type == CLICK_NODE) { - node_popup->clear(); - node_popup->set_size(Size2(1, 1)); - node_popup->add_item(TTR("Rename"), NODE_RENAME); - node_popup->add_item(TTR("Remove"), NODE_ERASE); - if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) - node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT); - node_popup->set_position(rclick_pos + get_global_position()); - node_popup->popup(); - } - } - } - } else { - - if (mb->get_button_index() == 1 && click_type != CLICK_NONE) { - - switch (click_type) { - case CLICK_INPUT_SLOT: - case CLICK_OUTPUT_SLOT: { - - Point2 dst_click_pos = Point2(mb->get_position().x, mb->get_position().y); - StringName id; - int slot; - ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot); - - if (dst_click_type == CLICK_INPUT_SLOT && click_type == CLICK_OUTPUT_SLOT) { - - anim_tree->connect_nodes(click_node, id, slot); - } - if (click_type == CLICK_INPUT_SLOT && dst_click_type == CLICK_OUTPUT_SLOT) { - - anim_tree->connect_nodes(id, click_node, click_slot); - } - - } break; - case CLICK_NODE: { - Point2 new_pos = anim_tree->node_get_position(click_node) + (click_motion - click_pos); - if (new_pos.x < 5) - new_pos.x = 5; - if (new_pos.y < 5) - new_pos.y = 5; - anim_tree->node_set_position(click_node, new_pos); - - } break; - default: { - } - } - - click_type = CLICK_NONE; - update(); - } - } - } - - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - if (mm->get_button_mask() & 1 && click_type != CLICK_NONE) { - - click_motion = Point2(mm->get_position().x, mm->get_position().y); - update(); - } - if (mm->get_button_mask() & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE)) { - - h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x); - v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y); - update(); - } - } -} - -void AnimationTreePlayerEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color) { - - static const int steps = 20; - - Rect2 r; - r.position = p_from; - r.expand_to(p_to); - Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1); - bool flip = sign.x * sign.y < 0; - - Vector2 prev; - for (int i = 0; i <= steps; i++) { - - float d = i / float(steps); - float c = -Math::cos(d * Math_PI) * 0.5 + 0.5; - if (flip) - c = 1.0 - c; - Vector2 p = r.position + Vector2(d * r.size.width, c * r.size.height); - - if (i > 0) { - - draw_line(prev, p, p_color, 2); - } - - prev = p; - } -} - -void AnimationTreePlayerEditor::_notification(int p_what) { - - switch (p_what) { - - case NOTIFICATION_ENTER_TREE: { - - play_button->set_icon(get_icon("Play", "EditorIcons")); - add_menu->set_icon(get_icon("Add", "EditorIcons")); - } break; - case NOTIFICATION_DRAW: { - - _update_scrollbars(); - //VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1)); - get_stylebox("bg", "Tree")->draw(get_canvas_item(), Rect2(Point2(), get_size())); - - for (List<StringName>::Element *E = order.front(); E; E = E->next()) { - - _draw_node(E->get()); - } - - if (click_type == CLICK_INPUT_SLOT || click_type == CLICK_OUTPUT_SLOT) { - - _draw_cos_line(click_pos, click_motion, Color(0.5, 1, 0.5, 0.8)); - } - - List<AnimationTreePlayer::Connection> connections; - anim_tree->get_connection_list(&connections); - - for (List<AnimationTreePlayer::Connection>::Element *E = connections.front(); E; E = E->next()) { - - const AnimationTreePlayer::Connection &c = E->get(); - Point2 source = _get_slot_pos(c.src_node, false, 0); - Point2 dest = _get_slot_pos(c.dst_node, true, c.dst_input); - Color col = Color(1, 1, 0.5, 0.8); - /* - if (click_type==CLICK_NODE && click_node==c.src_node) { - - source+=click_motion-click_pos; - } - - if (click_type==CLICK_NODE && click_node==c.dst_node) { - - dest+=click_motion-click_pos; - }*/ - - _draw_cos_line(source, dest, col); - } - - const Ref<Font> f = get_font("font", "Label"); - const Point2 status_offset = Point2(5, 25) * EDSCALE + Point2(0, f->get_ascent()); - - switch (anim_tree->get_last_error()) { - - case AnimationTreePlayer::CONNECT_OK: { - - f->draw(get_canvas_item(), status_offset, TTR("Animation tree is valid."), Color(0, 1, 0.6, 0.8)); - } break; - default: { - - f->draw(get_canvas_item(), status_offset, TTR("Animation tree is invalid."), Color(1, 0.6, 0.0, 0.8)); - } break; - } - - } break; - } -} - -void AnimationTreePlayerEditor::_update_scrollbars() { - - Size2 size = get_size(); - Size2 hmin = h_scroll->get_combined_minimum_size(); - Size2 vmin = v_scroll->get_combined_minimum_size(); - - v_scroll->set_begin(Point2(size.width - vmin.width, 0)); - v_scroll->set_end(Point2(size.width, size.height)); - - h_scroll->set_begin(Point2(0, size.height - hmin.height)); - h_scroll->set_end(Point2(size.width - vmin.width, size.height)); - - Size2 min = _get_maximum_size(); - - if (min.height < size.height - hmin.height) { - - v_scroll->hide(); - offset.y = 0; - } else { - - v_scroll->show(); - v_scroll->set_max(min.height); - v_scroll->set_page(size.height - hmin.height); - offset.y = v_scroll->get_value(); - } - - if (min.width < size.width - vmin.width) { - - h_scroll->hide(); - offset.x = 0; - } else { - - h_scroll->show(); - h_scroll->set_max(min.width); - h_scroll->set_page(size.width - vmin.width); - offset.x = h_scroll->get_value(); - } -} - -void AnimationTreePlayerEditor::_scroll_moved(float) { - - offset.x = h_scroll->get_value(); - offset.y = v_scroll->get_value(); - update(); -} - -void AnimationTreePlayerEditor::_node_menu_item(int p_item) { - - switch (p_item) { - - case NODE_DISCONNECT: { - - if (rclick_type == CLICK_INPUT_SLOT) { - - anim_tree->disconnect_nodes(rclick_node, rclick_slot); - update(); - } - - if (rclick_type == CLICK_OUTPUT_SLOT) { - - List<AnimationTreePlayer::Connection> connections; - anim_tree->get_connection_list(&connections); - - for (List<AnimationTreePlayer::Connection>::Element *E = connections.front(); E; E = E->next()) { - - const AnimationTreePlayer::Connection &c = E->get(); - if (c.dst_node == rclick_node) { - - anim_tree->disconnect_nodes(c.dst_node, c.dst_input); - } - } - update(); - } - - } break; - case NODE_RENAME: { - - renaming_edit = true; - edited_node = rclick_node; - _popup_edit_dialog(); - - } break; - case NODE_ADD_INPUT: { - - anim_tree->transition_node_set_input_count(rclick_node, anim_tree->transition_node_get_input_count(rclick_node) + 1); - update(); - } break; - case NODE_DELETE_INPUT: { - - anim_tree->transition_node_delete_input(rclick_node, rclick_slot); - update(); - } break; - case NODE_SET_AUTOADVANCE: { - - anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, true); - update(); - - } break; - case NODE_CLEAR_AUTOADVANCE: { - - anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, false); - update(); - - } break; - - case NODE_ERASE: { - - if (rclick_node == "out") - break; - order.erase(rclick_node); - anim_tree->remove_node(rclick_node); - update(); - } break; - } -} - -StringName AnimationTreePlayerEditor::_add_node(int p_item) { - - static const char *bname[] = { - "out", - "anim", - "oneshot", - "mix", - "blend2", - "blend3", - "blend4", - "scale", - "seek", - "transition" - }; - - String name; - int idx = 1; - - while (true) { - - name = bname[p_item]; - if (idx > 1) - name += " " + itos(idx); - if (anim_tree->node_exists(name)) - idx++; - else - break; - } - - anim_tree->add_node((AnimationTreePlayer::NodeType)p_item, name); - anim_tree->node_set_position(name, Point2(last_x, last_y)); - order.push_back(name); - last_x += 10; - last_y += 10; - last_x = last_x % (int)get_size().width; - last_y = last_y % (int)get_size().height; - update(); - - return name; -}; - -void AnimationTreePlayerEditor::_file_dialog_selected(String p_path) { - - switch (file_op) { - - case MENU_IMPORT_ANIMATIONS: { - Vector<String> files = file_dialog->get_selected_files(); - - for (int i = 0; i < files.size(); i++) { - - StringName node = _add_node(AnimationTreePlayer::NODE_ANIMATION); - - RES anim = ResourceLoader::load(files[i]); - anim_tree->animation_node_set_animation(node, anim); - //anim_tree->node_set_name(node, files[i].get_file()); - }; - } break; - - default: - break; - }; -}; - -void AnimationTreePlayerEditor::_add_menu_item(int p_item) { - - if (p_item == MENU_GRAPH_CLEAR) { - - //clear - } else if (p_item == MENU_IMPORT_ANIMATIONS) { - - file_op = MENU_IMPORT_ANIMATIONS; - file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); - file_dialog->popup_centered_ratio(); - - } else { - - _add_node(p_item); - } -} - -Size2 AnimationTreePlayerEditor::get_minimum_size() const { - - return Size2(10, 200); -} - -void AnimationTreePlayerEditor::_find_paths_for_filter(const StringName &p_node, Set<String> &paths) { - - ERR_FAIL_COND(!anim_tree->node_exists(p_node)); - - for (int i = 0; i < anim_tree->node_get_input_count(p_node); i++) { - - StringName port = anim_tree->node_get_input_source(p_node, i); - if (port == StringName()) - continue; - _find_paths_for_filter(port, paths); - } - - if (anim_tree->node_get_type(p_node) == AnimationTreePlayer::NODE_ANIMATION) { - - Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node); - if (anim.is_valid()) { - - for (int i = 0; i < anim->get_track_count(); i++) { - paths.insert(anim->track_get_path(i)); - } - } - } -} - -void AnimationTreePlayerEditor::_filter_edited() { - - TreeItem *ed = filter->get_edited(); - if (!ed) - return; - - if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) { - anim_tree->oneshot_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); - } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) { - anim_tree->blend2_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); - } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) { - anim_tree->animation_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); - } -} - -void AnimationTreePlayerEditor::_edit_filters() { - - filter_dialog->popup_centered_ratio(); - filter->clear(); - - Set<String> npb; - _find_paths_for_filter(edited_node, npb); - - TreeItem *root = filter->create_item(); - filter->set_hide_root(true); - Map<String, TreeItem *> pm; - - Node *base = anim_tree->get_node(anim_tree->get_base_path()); - - for (Set<String>::Element *E = npb.front(); E; E = E->next()) { - - TreeItem *parent = root; - String descr = E->get(); - if (base) { - NodePath np = E->get(); - - if (np.get_subname_count() == 1) { - Node *n = base->get_node(np); - Skeleton *s = Object::cast_to<Skeleton>(n); - if (s) { - - String skelbase = E->get().substr(0, E->get().find(":")); - - int bidx = s->find_bone(np.get_subname(0)); - - if (bidx != -1) { - int bparent = s->get_bone_parent(bidx); - // - if (bparent != -1) { - - String bpn = skelbase + ":" + s->get_bone_name(bparent); - if (pm.has(bpn)) { - parent = pm[bpn]; - descr = np.get_subname(0); - } - } else { - - if (pm.has(skelbase)) { - parent = pm[skelbase]; - } - } - } - } - } - } - - TreeItem *it = filter->create_item(parent); - it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); - it->set_text(0, descr); - it->set_metadata(0, NodePath(E->get())); - it->set_editable(0, true); - if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) { - it->set_checked(0, anim_tree->oneshot_node_is_path_filtered(edited_node, E->get())); - } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) { - it->set_checked(0, anim_tree->blend2_node_is_path_filtered(edited_node, E->get())); - } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) { - it->set_checked(0, anim_tree->animation_node_is_path_filtered(edited_node, E->get())); - } - pm[E->get()] = it; - } -} - -void AnimationTreePlayerEditor::_bind_methods() { - - ClassDB::bind_method("_add_menu_item", &AnimationTreePlayerEditor::_add_menu_item); - ClassDB::bind_method("_node_menu_item", &AnimationTreePlayerEditor::_node_menu_item); - ClassDB::bind_method("_gui_input", &AnimationTreePlayerEditor::_gui_input); - //ClassDB::bind_method( "_node_param_changed", &AnimationTreeEditor::_node_param_changed ); - ClassDB::bind_method("_scroll_moved", &AnimationTreePlayerEditor::_scroll_moved); - ClassDB::bind_method("_edit_dialog_changeds", &AnimationTreePlayerEditor::_edit_dialog_changeds); - ClassDB::bind_method("_edit_dialog_changede", &AnimationTreePlayerEditor::_edit_dialog_changede); - ClassDB::bind_method("_edit_dialog_changedf", &AnimationTreePlayerEditor::_edit_dialog_changedf); - ClassDB::bind_method("_edit_dialog_changed", &AnimationTreePlayerEditor::_edit_dialog_changed); - ClassDB::bind_method("_edit_dialog_animation_changed", &AnimationTreePlayerEditor::_edit_dialog_animation_changed); - ClassDB::bind_method("_edit_dialog_edit_animation", &AnimationTreePlayerEditor::_edit_dialog_edit_animation); - ClassDB::bind_method("_play_toggled", &AnimationTreePlayerEditor::_play_toggled); - ClassDB::bind_method("_edit_oneshot_start", &AnimationTreePlayerEditor::_edit_oneshot_start); - ClassDB::bind_method("_file_dialog_selected", &AnimationTreePlayerEditor::_file_dialog_selected); - ClassDB::bind_method("_master_anim_menu_item", &AnimationTreePlayerEditor::_master_anim_menu_item); - ClassDB::bind_method("_edit_filters", &AnimationTreePlayerEditor::_edit_filters); - ClassDB::bind_method("_filter_edited", &AnimationTreePlayerEditor::_filter_edited); -} - -AnimationTreePlayerEditor::AnimationTreePlayerEditor() { - - set_focus_mode(FOCUS_ALL); - - PopupMenu *p; - List<PropertyInfo> defaults; - - add_menu = memnew(MenuButton); - //add_menu->set_ - add_menu->set_position(Point2(0, 0)); - add_menu->set_size(Point2(25, 15)); - add_child(add_menu); - - p = add_menu->get_popup(); - p->add_item(TTR("Animation Node"), AnimationTreePlayer::NODE_ANIMATION); - p->add_item(TTR("OneShot Node"), AnimationTreePlayer::NODE_ONESHOT); - p->add_item(TTR("Mix Node"), AnimationTreePlayer::NODE_MIX); - p->add_item(TTR("Blend2 Node"), AnimationTreePlayer::NODE_BLEND2); - p->add_item(TTR("Blend3 Node"), AnimationTreePlayer::NODE_BLEND3); - p->add_item(TTR("Blend4 Node"), AnimationTreePlayer::NODE_BLEND4); - p->add_item(TTR("TimeScale Node"), AnimationTreePlayer::NODE_TIMESCALE); - p->add_item(TTR("TimeSeek Node"), AnimationTreePlayer::NODE_TIMESEEK); - p->add_item(TTR("Transition Node"), AnimationTreePlayer::NODE_TRANSITION); - p->add_separator(); - p->add_item(TTR("Import Animations..."), MENU_IMPORT_ANIMATIONS); // wtf - p->add_separator(); - p->add_item(TTR("Clear"), MENU_GRAPH_CLEAR); - - p->connect("id_pressed", this, "_add_menu_item"); - - play_button = memnew(Button); - play_button->set_position(Point2(25, 0) * EDSCALE); - play_button->set_size(Point2(25, 15)); - add_child(play_button); - play_button->set_toggle_mode(true); - play_button->connect("pressed", this, "_play_toggled"); - - last_x = 50; - last_y = 50; - - property_editor = memnew(CustomPropertyEditor); - add_child(property_editor); - property_editor->connect("variant_changed", this, "_edit_dialog_animation_changed"); - property_editor->connect("resource_edit_request", this, "_edit_dialog_edit_animation"); - - h_scroll = memnew(HScrollBar); - v_scroll = memnew(VScrollBar); - - add_child(h_scroll); - add_child(v_scroll); - - h_scroll->connect("value_changed", this, "_scroll_moved"); - v_scroll->connect("value_changed", this, "_scroll_moved"); - - node_popup = memnew(PopupMenu); - add_child(node_popup); - node_popup->set_as_toplevel(true); - - master_anim_popup = memnew(PopupMenu); - add_child(master_anim_popup); - master_anim_popup->connect("id_pressed", this, "_master_anim_menu_item"); - - node_popup->connect("id_pressed", this, "_node_menu_item"); - - updating_edit = false; - - edit_dialog = memnew(PopupPanel); - //edit_dialog->get_ok()->hide(); - //edit_dialog->get_cancel()->hide(); - add_child(edit_dialog); - - edit_option = memnew(OptionButton); - edit_option->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_option->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_option); - edit_option->connect("item_selected", this, "_edit_dialog_changedf"); - edit_option->hide(); - - for (int i = 0; i < 2; i++) { - edit_scroll[i] = memnew(HSlider); - edit_scroll[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_scroll[i]->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_scroll[i]); - edit_scroll[i]->hide(); - edit_scroll[i]->connect("value_changed", this, "_edit_dialog_changedf"); - } - for (int i = 0; i < 4; i++) { - edit_line[i] = memnew(LineEdit); - edit_line[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_line[i]->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_line[i]); - edit_line[i]->hide(); - edit_line[i]->connect("text_changed", this, "_edit_dialog_changeds"); - edit_line[i]->connect("text_entered", this, "_edit_dialog_changede"); - edit_label[i] = memnew(Label); - edit_dialog->add_child(edit_label[i]); - edit_label[i]->hide(); - } - - edit_button = memnew(Button); - edit_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_button->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_button); - edit_button->hide(); - edit_button->connect("pressed", this, "_edit_oneshot_start"); - - edit_check = memnew(CheckButton); - edit_check->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_check->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_check); - edit_check->hide(); - edit_check->connect("pressed", this, "_edit_dialog_changed"); - - file_dialog = memnew(EditorFileDialog); - file_dialog->set_enable_multiple_selection(true); - file_dialog->set_current_dir(ProjectSettings::get_singleton()->get_resource_path()); - add_child(file_dialog); - file_dialog->connect("file_selected", this, "_file_dialog_selected"); - - filter_dialog = memnew(AcceptDialog); - filter_dialog->set_title(TTR("Edit Node Filters")); - add_child(filter_dialog); - - filter = memnew(Tree); - filter_dialog->add_child(filter); - //filter_dialog->set_child_rect(filter); - filter->connect("item_edited", this, "_filter_edited"); - - filter_button = memnew(Button); - filter_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); - filter_button->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(filter_button); - filter_button->hide(); - filter_button->set_text(TTR("Filters...")); - filter_button->connect("pressed", this, "_edit_filters"); - - set_clip_contents(true); -} - -void AnimationTreePlayerEditorPlugin::edit(Object *p_object) { - - anim_tree_editor->edit(Object::cast_to<AnimationTreePlayer>(p_object)); -} - -bool AnimationTreePlayerEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("AnimationTreePlayer"); -} - -void AnimationTreePlayerEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - //editor->hide_animation_player_editors(); - //editor->animation_panel_make_visible(true); - button->show(); - editor->make_bottom_panel_item_visible(anim_tree_editor); - anim_tree_editor->set_physics_process(true); - } else { - - if (anim_tree_editor->is_visible_in_tree()) - editor->hide_bottom_panel(); - button->hide(); - anim_tree_editor->set_physics_process(false); - } -} - -AnimationTreePlayerEditorPlugin::AnimationTreePlayerEditorPlugin(EditorNode *p_node) { - - editor = p_node; - anim_tree_editor = memnew(AnimationTreePlayerEditor); - anim_tree_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE); - - button = editor->add_bottom_panel_item(TTR("AnimationTree"), anim_tree_editor); - button->hide(); -} - -AnimationTreePlayerEditorPlugin::~AnimationTreePlayerEditorPlugin() { -} diff --git a/editor/plugins/animation_tree_player_editor_plugin.h b/editor/plugins/animation_tree_player_editor_plugin.h deleted file mode 100644 index d3fd6ae362..0000000000 --- a/editor/plugins/animation_tree_player_editor_plugin.h +++ /dev/null @@ -1,184 +0,0 @@ -/*************************************************************************/ -/* animation_tree_player_editor_plugin.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef ANIMATION_TREE_PLAYER_EDITOR_PLUGIN_H -#define ANIMATION_TREE_PLAYER_EDITOR_PLUGIN_H - -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "editor/property_editor.h" -#include "scene/animation/animation_tree_player.h" -#include "scene/gui/button.h" -#include "scene/gui/popup.h" -#include "scene/gui/tree.h" - -class AnimationTreePlayerEditor : public Control { - - GDCLASS(AnimationTreePlayerEditor, Control); - - static const char *_node_type_names[]; - - enum ClickType { - CLICK_NONE, - CLICK_NAME, - CLICK_NODE, - CLICK_INPUT_SLOT, - CLICK_OUTPUT_SLOT, - CLICK_PARAMETER - }; - - enum { - - MENU_GRAPH_CLEAR = 100, - MENU_IMPORT_ANIMATIONS = 101, - NODE_DISCONNECT, - NODE_RENAME, - NODE_ERASE, - NODE_ADD_INPUT, - NODE_DELETE_INPUT, - NODE_SET_AUTOADVANCE, - NODE_CLEAR_AUTOADVANCE - }; - - bool renaming_edit; - StringName edited_node; - bool updating_edit; - Popup *edit_dialog; - HSlider *edit_scroll[2]; - LineEdit *edit_line[4]; - OptionButton *edit_option; - Label *edit_label[4]; - Button *edit_button; - Button *filter_button; - CheckButton *edit_check; - EditorFileDialog *file_dialog; - int file_op; - - void _popup_edit_dialog(); - - void _setup_edit_dialog(const StringName &p_node); - PopupMenu *master_anim_popup; - PopupMenu *node_popup; - PopupMenu *add_popup; - HScrollBar *h_scroll; - VScrollBar *v_scroll; - MenuButton *add_menu; - - CustomPropertyEditor *property_editor; - - AnimationTreePlayer *anim_tree; - List<StringName> order; - Set<StringName> active_nodes; - - int last_x, last_y; - - Point2 offset; - ClickType click_type; - Point2 click_pos; - StringName click_node; - int click_slot; - Point2 click_motion; - ClickType rclick_type; - StringName rclick_node; - int rclick_slot; - - Button *play_button; - - Size2 _get_maximum_size(); - Size2 get_node_size(const StringName &p_node) const; - void _draw_node(const StringName &p_node); - - AcceptDialog *filter_dialog; - Tree *filter; - - void _draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color); - void _update_scrollbars(); - void _scroll_moved(float); - void _play_toggled(); - /* - void _node_param_changed(); - void _node_add_callback(); - void _node_add(VisualServer::AnimationTreeNodeType p_type); - void _node_edit_property(const StringName& p_node); -*/ - - void _master_anim_menu_item(int p_item); - void _node_menu_item(int p_item); - void _add_menu_item(int p_item); - - void _filter_edited(); - void _find_paths_for_filter(const StringName &p_node, Set<String> &paths); - void _edit_filters(); - - void _edit_oneshot_start(); - void _edit_dialog_animation_changed(); - void _edit_dialog_edit_animation(); - void _edit_dialog_changeds(String); - void _edit_dialog_changede(String); - void _edit_dialog_changedf(float); - void _edit_dialog_changed(); - void _dialog_changed() const; - ClickType _locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const; - Point2 _get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot); - - StringName _add_node(int p_item); - void _file_dialog_selected(String p_path); - -protected: - void _notification(int p_what); - void _gui_input(Ref<InputEvent> p_event); - static void _bind_methods(); - -public: - virtual Size2 get_minimum_size() const; - void edit(AnimationTreePlayer *p_anim_tree); - AnimationTreePlayerEditor(); -}; - -class AnimationTreePlayerEditorPlugin : public EditorPlugin { - - GDCLASS(AnimationTreePlayerEditorPlugin, EditorPlugin); - - AnimationTreePlayerEditor *anim_tree_editor; - EditorNode *editor; - Button *button; - -public: - virtual String get_name() const { return "AnimTree"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - - AnimationTreePlayerEditorPlugin(EditorNode *p_node); - ~AnimationTreePlayerEditorPlugin(); -}; - -#endif // ANIMATION_TREE_EDITOR_PLUGIN_H diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 4f73a5eaea..a479703527 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -31,6 +31,8 @@ #include "asset_library_editor_plugin.h" #include "core/io/json.h" +#include "core/os/input.h" +#include "core/os/keyboard.h" #include "core/version.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" @@ -48,7 +50,7 @@ void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, co price->set_text(p_cost); } -void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Texture> &p_image) { +void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Texture2D> &p_image) { ERR_FAIL_COND(p_type != EditorAssetLibrary::IMAGE_QUEUE_ICON); ERR_FAIL_COND(p_index != 0); @@ -139,13 +141,11 @@ EditorAssetLibraryItem::EditorAssetLibraryItem() { set_custom_minimum_size(Size2(250, 100) * EDSCALE); set_h_size_flags(SIZE_EXPAND_FILL); - - set_mouse_filter(MOUSE_FILTER_PASS); } ////////////////////////////////////////////////////////////////////////////// -void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const Ref<Texture> &p_image) { +void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const Ref<Texture2D> &p_image) { switch (p_type) { @@ -393,7 +393,7 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int set_process(false); } -void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asset_id, const Ref<Texture> &p_preview, const String &p_download_url, const String &p_sha256_hash) { +void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asset_id, const Ref<Texture2D> &p_preview, const String &p_download_url, const String &p_sha256_hash) { title->set_text(p_title); icon->set_texture(p_preview); @@ -622,6 +622,21 @@ void EditorAssetLibrary::_notification(int p_what) { } } +void EditorAssetLibrary::_unhandled_input(const Ref<InputEvent> &p_event) { + + const Ref<InputEventKey> key = p_event; + + if (key.is_valid() && key->is_pressed()) { + + if (key->get_scancode_with_modifiers() == (KEY_MASK_CMD | KEY_F) && is_visible_in_tree()) { + + filter->grab_focus(); + filter->select_all(); + accept_event(); + } + } +} + void EditorAssetLibrary::_install_asset() { ERR_FAIL_COND(!description); @@ -812,7 +827,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons _image_update(p_code == HTTPClient::RESPONSE_NOT_MODIFIED, true, p_data, p_queue_id); } else { - WARN_PRINTS("Error getting image file from URL: " + image_queue[p_queue_id].image_url); + WARN_PRINT("Error getting image file from URL: " + image_queue[p_queue_id].image_url); Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target); if (obj) { obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("FileBrokenBigThumb", "EditorIcons")); @@ -1322,6 +1337,7 @@ void EditorAssetLibrary::disable_community_support() { void EditorAssetLibrary::_bind_methods() { + ClassDB::bind_method("_unhandled_input", &EditorAssetLibrary::_unhandled_input); ClassDB::bind_method("_http_request_completed", &EditorAssetLibrary::_http_request_completed); ClassDB::bind_method("_select_asset", &EditorAssetLibrary::_select_asset); ClassDB::bind_method("_select_author", &EditorAssetLibrary::_select_author); @@ -1455,7 +1471,6 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { library_scroll->add_child(library_vb_border); library_vb_border->add_style_override("panel", border2); library_vb_border->set_h_size_flags(SIZE_EXPAND_FILL); - library_vb_border->set_mouse_filter(MOUSE_FILTER_PASS); library_vb = memnew(VBoxContainer); library_vb->set_h_size_flags(SIZE_EXPAND_FILL); @@ -1505,6 +1520,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { description = NULL; set_process(true); + set_process_unhandled_input(true); downloads_scroll = memnew(ScrollContainer); downloads_scroll->set_enable_h_scroll(true); diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index aa3c735810..e13d8a6149 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -68,7 +68,7 @@ class EditorAssetLibraryItem : public PanelContainer { void _category_clicked(); void _author_clicked(); - void set_image(int p_type, int p_index, const Ref<Texture> &p_image); + void set_image(int p_type, int p_index, const Ref<Texture2D> &p_image); protected: void _notification(int p_what); @@ -95,19 +95,19 @@ class EditorAssetLibraryItemDescription : public ConfirmationDialog { bool is_video; String video_link; Button *button; - Ref<Texture> image; + Ref<Texture2D> image; }; Vector<Preview> preview_images; TextureRect *preview; - void set_image(int p_type, int p_index, const Ref<Texture> &p_image); + void set_image(int p_type, int p_index, const Ref<Texture2D> &p_image); int asset_id; String download_url; String title; String sha256; - Ref<Texture> icon; + Ref<Texture2D> icon; void _link_click(const String &p_url); void _preview_click(int p_id); @@ -121,7 +121,7 @@ public: void add_preview(int p_id, bool p_video, const String &p_url); String get_title() { return title; } - Ref<Texture> get_preview_icon() { return icon; } + Ref<Texture2D> get_preview_icon() { return icon; } String get_download_url() { return download_url; } int get_asset_id() { return asset_id; } String get_sha256() { return sha256; } @@ -165,7 +165,7 @@ protected: public: void set_external_install(bool p_enable) { external_install = p_enable; } int get_asset_id() { return asset_id; } - void configure(const String &p_title, int p_asset_id, const Ref<Texture> &p_preview, const String &p_download_url, const String &p_sha256_hash); + void configure(const String &p_title, int p_asset_id, const Ref<Texture2D> &p_preview, const String &p_download_url, const String &p_sha256_hash); EditorAssetLibraryItemDownload(); }; @@ -300,6 +300,7 @@ class EditorAssetLibrary : public PanelContainer { protected: static void _bind_methods(); void _notification(int p_what); + void _unhandled_input(const Ref<InputEvent> &p_event); public: void disable_community_support(); diff --git a/editor/plugins/baked_lightmap_editor_plugin.cpp b/editor/plugins/baked_lightmap_editor_plugin.cpp index 7db936ccb8..6bc9562c5a 100644 --- a/editor/plugins/baked_lightmap_editor_plugin.cpp +++ b/editor/plugins/baked_lightmap_editor_plugin.cpp @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#if 0 #include "baked_lightmap_editor_plugin.h" void BakedLightmapEditorPlugin::_bake() { @@ -124,3 +125,4 @@ BakedLightmapEditorPlugin::BakedLightmapEditorPlugin(EditorNode *p_node) { BakedLightmapEditorPlugin::~BakedLightmapEditorPlugin() { } +#endif diff --git a/editor/plugins/baked_lightmap_editor_plugin.h b/editor/plugins/baked_lightmap_editor_plugin.h index 8b94257a62..818cdfe8fa 100644 --- a/editor/plugins/baked_lightmap_editor_plugin.h +++ b/editor/plugins/baked_lightmap_editor_plugin.h @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#if 0 #ifndef BAKED_LIGHTMAP_EDITOR_PLUGIN_H #define BAKED_LIGHTMAP_EDITOR_PLUGIN_H @@ -67,3 +68,4 @@ public: }; #endif // BAKED_LIGHTMAP_EDITOR_PLUGIN_H +#endif diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 1d8f3a2bbd..f7a3b50052 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -58,6 +58,7 @@ #define RULER_WIDTH (15 * EDSCALE) #define SCALE_HANDLE_DISTANCE 25 +#define MOVE_HANDLE_DISTANCE 25 class SnapDialog : public ConfirmationDialog { @@ -605,7 +606,7 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no } } -void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items) { +void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, bool p_allow_locked) { Node *scene = editor->get_edited_scene(); @@ -620,14 +621,16 @@ void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_Sel node = node->get_parent(); }; - // Replace the node by the group if grouped CanvasItem *canvas_item = Object::cast_to<CanvasItem>(node); - while (node && node != scene->get_parent()) { - CanvasItem *canvas_item_tmp = Object::cast_to<CanvasItem>(node); - if (canvas_item_tmp && node->has_meta("_edit_group_")) { - canvas_item = canvas_item_tmp; + if (!p_allow_locked) { + // Replace the node by the group if grouped + while (node && node != scene->get_parent()) { + CanvasItem *canvas_item_tmp = Object::cast_to<CanvasItem>(node); + if (canvas_item_tmp && node->has_meta("_edit_group_")) { + canvas_item = canvas_item_tmp; + } + node = node->get_parent(); } - node = node->get_parent(); } // Check if the canvas item is already in the list (for groups or scenes) @@ -640,7 +643,7 @@ void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_Sel } //Remove the item if invalid - if (!canvas_item || duplicate || (canvas_item != scene && canvas_item->get_owner() != scene && !scene->is_editable_instance(canvas_item->get_owner())) || _is_node_locked(canvas_item)) { + if (!canvas_item || duplicate || (canvas_item != scene && canvas_item->get_owner() != scene && !scene->is_editable_instance(canvas_item->get_owner())) || (!p_allow_locked && _is_node_locked(canvas_item))) { r_items.remove(i); i--; } else { @@ -1866,14 +1869,16 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) { drag_type = DRAG_SCALE_BOTH; - Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); - Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); - if (x_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { - drag_type = DRAG_SCALE_X; - } - Rect2 y_handle_rect = Rect2(-5 * EDSCALE, -(scale_factor.y + 10) * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); - if (y_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { - drag_type = DRAG_SCALE_Y; + if (show_transformation_gizmos) { + Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); + Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + if (x_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { + drag_type = DRAG_SCALE_X; + } + Rect2 y_handle_rect = Rect2(-5 * EDSCALE, scale_factor.y * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + if (y_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { + drag_type = DRAG_SCALE_Y; + } } drag_from = transform.affine_inverse().xform(b->get_position()); @@ -1924,7 +1929,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) { scale.y = scale.x * ratio; } } else if (drag_type == DRAG_SCALE_Y) { - scale.y += scale_factor.y; + scale.y -= scale_factor.y; if (uniform) { scale.x = scale.y / ratio; } @@ -1983,6 +1988,24 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { if (selection.size() > 0) { drag_type = DRAG_MOVE; + + CanvasItem *canvas_item = selection[0]; + Transform2D parent_xform = canvas_item->get_global_transform_with_canvas() * canvas_item->get_transform().affine_inverse(); + Transform2D unscaled_transform = (transform * parent_xform * canvas_item->_edit_get_transform()).orthonormalized(); + Transform2D simple_xform = viewport->get_transform() * unscaled_transform; + + if (show_transformation_gizmos) { + Size2 move_factor = Size2(MOVE_HANDLE_DISTANCE, MOVE_HANDLE_DISTANCE); + Rect2 x_handle_rect = Rect2(move_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + if (x_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { + drag_type = DRAG_MOVE_X; + } + Rect2 y_handle_rect = Rect2(-5 * EDSCALE, move_factor.y * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + if (y_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { + drag_type = DRAG_MOVE_Y; + } + } + drag_from = transform.affine_inverse().xform(b->get_position()); drag_selection = selection; _save_canvas_item_state(drag_selection); @@ -1992,7 +2015,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } } - if (drag_type == DRAG_MOVE) { + if (drag_type == DRAG_MOVE || drag_type == DRAG_MOVE_X || drag_type == DRAG_MOVE_Y) { // Move the nodes if (m.is_valid()) { @@ -2014,7 +2037,15 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } else { previous_pos = _get_encompassing_rect_from_list(drag_selection).position; } + Point2 new_pos = snap_point(previous_pos + (drag_to - drag_from), SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL | SNAP_NODE_PARENT | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES, 0, NULL, drag_selection); + + if (drag_type == DRAG_MOVE_X) { + new_pos.y = previous_pos.y; + } else if (drag_type == DRAG_MOVE_Y) { + new_pos.x = previous_pos.x; + } + bool single_axis = m->get_shift(); if (single_axis) { if (ABS(new_pos.x - previous_pos.x) > ABS(new_pos.y - previous_pos.y)) { @@ -2077,7 +2108,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } // Move the canvas items with the arrow keys - if (k.is_valid() && k->is_pressed() && tool == TOOL_SELECT && + if (k.is_valid() && k->is_pressed() && (tool == TOOL_SELECT || tool == TOOL_MOVE) && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_LEFT || k->get_scancode() == KEY_RIGHT)) { if (!k->is_echo()) { // Start moving the canvas items with the keyboard @@ -2194,7 +2225,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { // Popup the selection menu list Point2 click = transform.affine_inverse().xform(b->get_position()); - _get_canvas_items_at_pos(click, selection_results); + _get_canvas_items_at_pos(click, selection_results, b->get_alt() && tool != TOOL_LIST_SELECT); if (selection_results.size() == 1) { CanvasItem *item = selection_results[0].item; @@ -2213,10 +2244,32 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { for (int i = 0; i < selection_results.size(); i++) { CanvasItem *item = selection_results[i].item; - Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(item, "Node"); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(item, "Node"); String node_path = "/" + root_name + "/" + root_path.rel_path_to(item->get_path()); - selection_menu->add_item(item->get_name()); + int locked = 0; + if (_is_node_locked(item)) { + locked = 1; + } else { + Node *scene = editor->get_edited_scene(); + Node *node = item; + + while (node && node != scene->get_parent()) { + CanvasItem *canvas_item_tmp = Object::cast_to<CanvasItem>(node); + if (canvas_item_tmp && node->has_meta("_edit_group_")) { + locked = 2; + } + node = node->get_parent(); + } + } + + String suffix = String(); + if (locked == 1) { + suffix = " (" + TTR("Locked") + ")"; + } else if (locked == 2) { + suffix = " (" + TTR("Grouped") + ")"; + } + selection_menu->add_item((String)item->get_name() + suffix); selection_menu->set_item_icon(i, icon); selection_menu->set_item_metadata(i, node_path); selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path); @@ -2806,7 +2859,7 @@ void CanvasItemEditor::_draw_ruler_tool() { bool draw_secondary_lines = !(Math::is_equal_approx(begin.y, corner.y) || Math::is_equal_approx(end.x, corner.x)); - viewport->draw_line(begin, end, ruler_primary_color, Math::round(EDSCALE * 3), true); + viewport->draw_line(begin, end, ruler_primary_color, Math::round(EDSCALE * 3)); if (draw_secondary_lines) { viewport->draw_line(begin, corner, ruler_secondary_color, Math::round(EDSCALE)); viewport->draw_line(corner, end, ruler_secondary_color, Math::round(EDSCALE)); @@ -2913,7 +2966,7 @@ void CanvasItemEditor::_draw_ruler_tool() { } else { if (grid_snap_active) { - Ref<Texture> position_icon = get_icon("EditorPosition", "EditorIcons"); + Ref<Texture2D> position_icon = get_icon("EditorPosition", "EditorIcons"); viewport->draw_texture(get_icon("EditorPosition", "EditorIcons"), (ruler_tool_origin - view_offset) * zoom - position_icon->get_size() / 2); } } @@ -3126,9 +3179,9 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) { } void CanvasItemEditor::_draw_selection() { - Ref<Texture> pivot_icon = get_icon("EditorPivot", "EditorIcons"); - Ref<Texture> position_icon = get_icon("EditorPosition", "EditorIcons"); - Ref<Texture> previous_position_icon = get_icon("EditorPositionPrevious", "EditorIcons"); + Ref<Texture2D> pivot_icon = get_icon("EditorPivot", "EditorIcons"); + Ref<Texture2D> position_icon = get_icon("EditorPosition", "EditorIcons"); + Ref<Texture2D> previous_position_icon = get_icon("EditorPositionPrevious", "EditorIcons"); RID ci = viewport->get_canvas_item(); @@ -3157,7 +3210,7 @@ void CanvasItemEditor::_draw_selection() { }; for (int i = 0; i < 4; i++) { - viewport->draw_line(pre_drag_endpoints[i], pre_drag_endpoints[(i + 1) % 4], pre_drag_color, Math::round(2 * EDSCALE), true); + viewport->draw_line(pre_drag_endpoints[i], pre_drag_endpoints[(i + 1) % 4], pre_drag_color, Math::round(2 * EDSCALE)); } } else { viewport->draw_texture(previous_position_icon, (pre_drag_xform.xform(Point2()) - (previous_position_icon->get_size() / 2)).floor()); @@ -3179,7 +3232,7 @@ void CanvasItemEditor::_draw_selection() { Color c = Color(1, 0.6, 0.4, 0.7); for (int i = 0; i < 4; i++) { - viewport->draw_line(endpoints[i], endpoints[(i + 1) % 4], c, Math::round(2 * EDSCALE), true); + viewport->draw_line(endpoints[i], endpoints[(i + 1) % 4], c, Math::round(2 * EDSCALE)); } } else { @@ -3235,10 +3288,39 @@ void CanvasItemEditor::_draw_selection() { } } - // Draw the rescale handles + // Draw the move handles bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CONTROL); bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT); - if ((is_alt && is_ctrl) || tool == TOOL_SCALE || drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) { + if (tool == TOOL_MOVE && show_transformation_gizmos) { + if (_is_node_movable(canvas_item)) { + Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized(); + Transform2D simple_xform = viewport->get_transform() * unscaled_transform; + + Size2 move_factor = Size2(MOVE_HANDLE_DISTANCE, MOVE_HANDLE_DISTANCE); + viewport->draw_set_transform_matrix(simple_xform); + + Vector<Point2> points; + points.push_back(Vector2(move_factor.x * EDSCALE, 5 * EDSCALE)); + points.push_back(Vector2(move_factor.x * EDSCALE, -5 * EDSCALE)); + points.push_back(Vector2((move_factor.x + 10) * EDSCALE, 0)); + + viewport->draw_colored_polygon(points, get_color("axis_x_color", "Editor")); + viewport->draw_line(Point2(), Point2(move_factor.x * EDSCALE, 0), get_color("axis_x_color", "Editor"), Math::round(EDSCALE)); + + points.clear(); + points.push_back(Vector2(5 * EDSCALE, move_factor.y * EDSCALE)); + points.push_back(Vector2(-5 * EDSCALE, move_factor.y * EDSCALE)); + points.push_back(Vector2(0, (move_factor.y + 10) * EDSCALE)); + + viewport->draw_colored_polygon(points, get_color("axis_y_color", "Editor")); + viewport->draw_line(Point2(), Point2(0, move_factor.y * EDSCALE), get_color("axis_y_color", "Editor"), Math::round(EDSCALE)); + + viewport->draw_set_transform_matrix(viewport->get_transform()); + } + } + + // Draw the rescale handles + if (show_transformation_gizmos && ((is_alt && is_ctrl) || tool == TOOL_SCALE || drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y)) { if (_is_node_movable(canvas_item)) { Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized(); Transform2D simple_xform = viewport->get_transform() * unscaled_transform; @@ -3253,20 +3335,20 @@ void CanvasItemEditor::_draw_selection() { scale_factor.y += offset.x; } } else if (drag_type == DRAG_SCALE_Y) { - scale_factor.y -= offset.y; + scale_factor.y += offset.y; if (uniform) { - scale_factor.x -= offset.y; + scale_factor.x += offset.y; } } viewport->draw_set_transform_matrix(simple_xform); Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); viewport->draw_rect(x_handle_rect, get_color("axis_x_color", "Editor")); - viewport->draw_line(Point2(), Point2(scale_factor.x * EDSCALE, 0), get_color("axis_x_color", "Editor"), Math::round(EDSCALE), true); + viewport->draw_line(Point2(), Point2(scale_factor.x * EDSCALE, 0), get_color("axis_x_color", "Editor"), Math::round(EDSCALE)); - Rect2 y_handle_rect = Rect2(-5 * EDSCALE, -(scale_factor.y + 10) * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + Rect2 y_handle_rect = Rect2(-5 * EDSCALE, scale_factor.y * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); viewport->draw_rect(y_handle_rect, get_color("axis_y_color", "Editor")); - viewport->draw_line(Point2(), Point2(0, -scale_factor.y * EDSCALE), get_color("axis_y_color", "Editor"), Math::round(EDSCALE), true); + viewport->draw_line(Point2(), Point2(0, scale_factor.y * EDSCALE), get_color("axis_y_color", "Editor"), Math::round(EDSCALE)); viewport->draw_set_transform_matrix(viewport->get_transform()); } @@ -3296,8 +3378,7 @@ void CanvasItemEditor::_draw_selection() { transform.xform(drag_rotation_center), transform.xform(drag_to), get_color("accent_color", "Editor") * Color(1, 1, 1, 0.6), - Math::round(2 * EDSCALE), - true); + Math::round(2 * EDSCALE)); } } @@ -3458,7 +3539,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans Transform2D xform = transform * canvas_xform * parent_xform; // Draw the node's position - Ref<Texture> position_icon = get_icon("EditorPositionUnselected", "EditorIcons"); + Ref<Texture2D> position_icon = get_icon("EditorPositionUnselected", "EditorIcons"); Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized(); Transform2D simple_xform = viewport->get_transform() * unscaled_transform; viewport->draw_set_transform_matrix(simple_xform); @@ -3472,7 +3553,7 @@ void CanvasItemEditor::_draw_hover() { for (int i = 0; i < hovering_results.size(); i++) { - Ref<Texture> node_icon = hovering_results[i].icon; + Ref<Texture2D> node_icon = hovering_results[i].icon; String node_name = hovering_results[i].name; Ref<Font> font = get_font("font", "Label"); @@ -3526,13 +3607,13 @@ void CanvasItemEditor::_draw_locks_and_groups(Node *p_node, const Transform2D &p if (canvas_item) { float offset = 0; - Ref<Texture> lock = get_icon("LockViewport", "EditorIcons"); + Ref<Texture2D> lock = get_icon("LockViewport", "EditorIcons"); if (p_node->has_meta("_edit_lock_") && show_edit_locks) { lock->draw(viewport_canvas_item, (transform * canvas_xform * parent_xform).xform(Point2(0, 0)) + Point2(offset, 0)); offset += lock->get_size().x; } - Ref<Texture> group = get_icon("GroupViewport", "EditorIcons"); + Ref<Texture2D> group = get_icon("GroupViewport", "EditorIcons"); if (canvas_item->has_meta("_edit_group_") && show_edit_locks) { group->draw(viewport_canvas_item, (transform * canvas_xform * parent_xform).xform(Point2(0, 0)) + Point2(offset, 0)); //offset += group->get_size().x; @@ -3578,7 +3659,7 @@ bool CanvasItemEditor::_build_bones_list(Node *p_node) { // Add a last bone if the Bone2D has no Bone2D child BoneKey bk; bk.from = canvas_item->get_instance_id(); - bk.to = 0; + bk.to = ObjectID(); if (!bone_list.has(bk)) { BoneList b; b.length = 0; @@ -4381,10 +4462,8 @@ void CanvasItemEditor::_update_override_camera_button(bool p_game_running) { } void CanvasItemEditor::_popup_callback(int p_op) { - last_option = MenuOption(p_op); switch (p_op) { - case SHOW_GRID: { show_grid = !show_grid; int idx = view_menu->get_popup()->get_item_index(SHOW_GRID); @@ -4409,6 +4488,12 @@ void CanvasItemEditor::_popup_callback(int p_op) { view_menu->get_popup()->set_item_checked(idx, show_edit_locks); viewport->update(); } break; + case SHOW_TRANSFORMATION_GIZMOS: { + show_transformation_gizmos = !show_transformation_gizmos; + int idx = view_menu->get_popup()->get_item_index(SHOW_TRANSFORMATION_GIZMOS); + view_menu->get_popup()->set_item_checked(idx, show_transformation_gizmos); + viewport->update(); + } break; case SNAP_USE_NODE_PARENT: { snap_node_parent = !snap_node_parent; int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_PARENT); @@ -4967,6 +5052,7 @@ void CanvasItemEditor::_focus_selection(int p_op) { zoom = scale_x < scale_y ? scale_x : scale_y; zoom *= 0.90; viewport->update(); + _update_zoom_label(); call_deferred("_popup_callback", VIEW_CENTER_TO_SELECTION); } } @@ -5034,6 +5120,7 @@ Dictionary CanvasItemEditor::get_state() const { state["show_helpers"] = show_helpers; state["show_zoom_control"] = zoom_hb->is_visible(); state["show_edit_locks"] = show_edit_locks; + state["show_transformation_gizmos"] = show_transformation_gizmos; state["snap_rotation"] = snap_rotation; state["snap_scale"] = snap_scale; state["snap_relative"] = snap_relative; @@ -5172,6 +5259,12 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) { view_menu->get_popup()->set_item_checked(idx, show_edit_locks); } + if (state.has("show_transformation_gizmos")) { + show_transformation_gizmos = state["show_transformation_gizmos"]; + int idx = view_menu->get_popup()->get_item_index(SHOW_TRANSFORMATION_GIZMOS); + view_menu->get_popup()->set_item_checked(idx, show_transformation_gizmos); + } + if (state.has("show_zoom_control")) { // This one is not user-controllable, but instrumentable zoom_hb->set_visible(state["show_zoom_control"]); @@ -5264,6 +5357,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { show_helpers = false; show_rulers = true; show_guides = true; + show_transformation_gizmos = true; show_edit_locks = true; zoom = 1.0 / MAX(1, EDSCALE); view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH); @@ -5595,6 +5689,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_origin", TTR("Show Origin")), SHOW_ORIGIN); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_viewport", TTR("Show Viewport")), SHOW_VIEWPORT); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_edit_locks", TTR("Show Group And Lock Icons")), SHOW_EDIT_LOCKS); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_transformation_gizmos", TTR("Show Transformation Gizmos")), SHOW_TRANSFORMATION_GIZMOS); p->add_separator(); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION); @@ -5791,7 +5886,7 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons String path = files[i]; RES res = ResourceLoader::load(path); ERR_FAIL_COND(res.is_null()); - Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(*res)); + Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res)); Ref<PackedScene> scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*res)); if (texture != NULL || scene != NULL) { if (texture != NULL) { @@ -5848,7 +5943,7 @@ bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_targe void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) { child->set_name(path.get_file().get_basename()); - Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(ResourceCache::get(path))); + Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(ResourceCache::get(path))); Size2 texture_size = texture->get_size(); if (parent) { @@ -5985,7 +6080,7 @@ void CanvasItemEditorViewport::_perform_drop_data() { } } } else { - Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(*res)); + Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res)); if (texture != NULL && texture.is_valid()) { Node *child; if (default_type == "Light2D") @@ -6040,7 +6135,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian continue; } memdelete(instanced_scene); - } else if (type == "Texture" || + } else if (type == "Texture2D" || type == "ImageTexture" || type == "ViewportTexture" || type == "CurveTexture" || @@ -6048,7 +6143,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian type == "StreamTexture" || type == "AtlasTexture" || type == "LargeTexture") { - Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(*res)); + Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res)); if (!texture.is_valid()) { continue; } diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 3291d6b9bf..3c4cacf5c8 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -119,6 +119,7 @@ private: SHOW_ORIGIN, SHOW_VIEWPORT, SHOW_EDIT_LOCKS, + SHOW_TRANSFORMATION_GIZMOS, LOCK_SELECTED, UNLOCK_SELECTED, GROUP_SELECTED, @@ -189,7 +190,6 @@ private: SKELETON_SHOW_BONES, SKELETON_SET_IK_CHAIN, SKELETON_CLEAR_IK_CHAIN - }; enum DragType { @@ -209,6 +209,8 @@ private: DRAG_ANCHOR_BOTTOM_LEFT, DRAG_ANCHOR_ALL, DRAG_MOVE, + DRAG_MOVE_X, + DRAG_MOVE_Y, DRAG_SCALE_X, DRAG_SCALE_Y, DRAG_SCALE_BOTH, @@ -248,6 +250,8 @@ private: bool show_viewport; bool show_helpers; bool show_edit_locks; + bool show_transformation_gizmos; + float zoom; Point2 view_offset; Point2 previous_update_view_offset; @@ -302,7 +306,7 @@ private: struct _HoverResult { Point2 position; - Ref<Texture> icon; + Ref<Texture2D> icon; String name; }; Vector<_HoverResult> hovering_results; @@ -402,8 +406,8 @@ private: Point2 box_selecting_to; Ref<StyleBoxTexture> select_sb; - Ref<Texture> select_handle; - Ref<Texture> anchor_handle; + Ref<Texture2D> select_handle; + Ref<Texture2D> anchor_handle; Ref<ShortCut> drag_pivot_shortcut; Ref<ShortCut> set_pivot_shortcut; @@ -414,7 +418,7 @@ private: bool _is_node_locked(const Node *p_node); bool _is_node_movable(const Node *p_node, bool p_popup_warning = false); void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D()); - void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items); + void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, bool p_allow_locked = false); void _get_bones_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items); void _find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_node, List<CanvasItem *> *r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D()); diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp index 8620437ac6..3de67589ee 100644 --- a/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_editor_plugin.cpp @@ -384,7 +384,7 @@ void Polygon3DEditor::_polygon_draw() { imgeom->clear(); imgeom->set_material_override(line_material); - imgeom->begin(Mesh::PRIMITIVE_LINES, Ref<Texture>()); + imgeom->begin(Mesh::PRIMITIVE_LINES, Ref<Texture2D>()); Rect2 rect; @@ -463,9 +463,7 @@ void Polygon3DEditor::_polygon_draw() { imgeom->end(); - while (m->get_surface_count()) { - m->surface_remove(0); - } + m->clear_surfaces(); if (poly.size() == 0) return; @@ -547,23 +545,22 @@ Polygon3DEditor::Polygon3DEditor(EditorNode *p_editor) { imgeom = memnew(ImmediateGeometry); imgeom->set_transform(Transform(Basis(), Vector3(0, 0, 0.00001))); - line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - line_material->set_line_width(3.0); - line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); + line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + line_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + line_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + line_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); line_material->set_albedo(Color(1, 1, 1)); - handle_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - handle_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - handle_material->set_flag(SpatialMaterial::FLAG_USE_POINT_SIZE, true); - handle_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - handle_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - handle_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); - Ref<Texture> handle = editor->get_gui_base()->get_icon("Editor3DHandle", "EditorIcons"); + handle_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); + handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true); + handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + handle_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + handle_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); + Ref<Texture2D> handle = editor->get_gui_base()->get_icon("Editor3DHandle", "EditorIcons"); handle_material->set_point_size(handle->get_width()); - handle_material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, handle); + handle_material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, handle); pointsm = memnew(MeshInstance); imgeom->add_child(pointsm); diff --git a/editor/plugins/collision_polygon_editor_plugin.h b/editor/plugins/collision_polygon_editor_plugin.h index 1871c6ee7e..3b6c25ac17 100644 --- a/editor/plugins/collision_polygon_editor_plugin.h +++ b/editor/plugins/collision_polygon_editor_plugin.h @@ -57,8 +57,8 @@ class Polygon3DEditor : public HBoxContainer { ToolButton *button_create; ToolButton *button_edit; - Ref<SpatialMaterial> line_material; - Ref<SpatialMaterial> handle_material; + Ref<StandardMaterial3D> line_material; + Ref<StandardMaterial3D> handle_material; EditorNode *editor; Panel *panel; diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index be9e5b0e3a..01b4a61a85 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -435,7 +435,7 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref<Texture> h = get_icon("EditorHandle", "EditorIcons"); + Ref<Texture2D> h = get_icon("EditorHandle", "EditorIcons"); Vector2 size = h->get_size() * 0.5; handles.clear(); @@ -448,8 +448,8 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla float radius = shape->get_radius(); float height = shape->get_height() / 2; - handles.write[0] = Point2(radius, -height); - handles.write[1] = Point2(0, -(height + radius)); + handles.write[0] = Point2(radius, height); + handles.write[1] = Point2(0, height + radius); p_overlay->draw_texture(h, gt.xform(handles[0]) - size); p_overlay->draw_texture(h, gt.xform(handles[1]) - size); @@ -502,8 +502,8 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla handles.resize(3); Vector2 ext = shape->get_extents(); handles.write[0] = Point2(ext.x, 0); - handles.write[1] = Point2(0, -ext.y); - handles.write[2] = Point2(ext.x, -ext.y); + handles.write[1] = Point2(0, ext.y); + handles.write[2] = Point2(ext.x, ext.y); p_overlay->draw_texture(h, gt.xform(handles[0]) - size); p_overlay->draw_texture(h, gt.xform(handles[1]) - size); diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index a4fc9b37ad..0af983f780 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -612,7 +612,7 @@ struct CanvasItemPlotCurve { void operator()(Vector2 pos0, Vector2 pos1, bool in_definition) { // FIXME: Using a line width greater than 1 breaks curve rendering - ci.draw_line(pos0, pos1, in_definition ? color1 : color2, 1, true); + ci.draw_line(pos0, pos1, in_definition ? color1 : color2, 1); } }; @@ -693,13 +693,13 @@ void CurveEditor::_draw() { if (i != 0) { Vector2 control_pos = get_tangent_view_pos(i, TANGENT_LEFT); - draw_line(get_view_pos(pos), control_pos, tangent_color, Math::round(EDSCALE), true); + draw_line(get_view_pos(pos), control_pos, tangent_color, Math::round(EDSCALE)); draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(2), tangent_color); } if (i != curve.get_point_count() - 1) { Vector2 control_pos = get_tangent_view_pos(i, TANGENT_RIGHT); - draw_line(get_view_pos(pos), control_pos, tangent_color, Math::round(EDSCALE), true); + draw_line(get_view_pos(pos), control_pos, tangent_color, Math::round(EDSCALE)); draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(2), tangent_color); } } @@ -787,10 +787,10 @@ bool CurvePreviewGenerator::handles(const String &p_type) const { return p_type == "Curve"; } -Ref<Texture> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { +Ref<Texture2D> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { Ref<Curve> curve_ref = p_from; - ERR_FAIL_COND_V_MSG(curve_ref.is_null(), Ref<Texture>(), "It's not a reference to a valid Resource object."); + ERR_FAIL_COND_V_MSG(curve_ref.is_null(), Ref<Texture2D>(), "It's not a reference to a valid Resource object."); Curve &curve = **curve_ref; // FIXME: Should be ported to use p_size as done in b2633a97 @@ -848,6 +848,6 @@ Ref<Texture> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, const Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img_ref, 0); + ptex->create_from_image(img_ref); return ptex; } diff --git a/editor/plugins/curve_editor_plugin.h b/editor/plugins/curve_editor_plugin.h index 06e2692373..c00aa3eca5 100644 --- a/editor/plugins/curve_editor_plugin.h +++ b/editor/plugins/curve_editor_plugin.h @@ -141,7 +141,7 @@ class CurvePreviewGenerator : public EditorResourcePreviewGenerator { public: virtual bool handles(const String &p_type) const; - virtual Ref<Texture> generate(const Ref<Resource> &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size) const; }; #endif // CURVE_EDITOR_PLUGIN_H diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 9b0d5d3daf..6e8aef0aea 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -76,34 +76,34 @@ void post_process_preview(Ref<Image> p_image) { bool EditorTexturePreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Texture"); + return ClassDB::is_parent_class(p_type, "Texture2D"); } bool EditorTexturePreviewPlugin::generate_small_preview_automatically() const { return true; } -Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { +Ref<Texture2D> EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { Ref<Image> img; Ref<AtlasTexture> atex = p_from; Ref<LargeTexture> ltex = p_from; if (atex.is_valid()) { - Ref<Texture> tex = atex->get_atlas(); + Ref<Texture2D> tex = atex->get_atlas(); if (!tex.is_valid()) { - return Ref<Texture>(); + return Ref<Texture2D>(); } Ref<Image> atlas = tex->get_data(); if (!atlas.is_valid()) { - return Ref<Texture>(); + return Ref<Texture2D>(); } img = atlas->get_rect(atex->get_region()); } else if (ltex.is_valid()) { img = ltex->to_image(); } else { - Ref<Texture> tex = p_from; + Ref<Texture2D> tex = p_from; if (tex.is_valid()) { img = tex->get_data(); if (img.is_valid()) { @@ -113,13 +113,13 @@ Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 } if (img.is_null() || img->empty()) - return Ref<Texture>(); + return Ref<Texture2D>(); img->clear_mipmaps(); if (img->is_compressed()) { if (img->decompress() != OK) - return Ref<Texture>(); + return Ref<Texture2D>(); } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { img->convert(Image::FORMAT_RGBA8); } @@ -137,7 +137,7 @@ Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img, 0); + ptex->create_from_image(img); return ptex; } @@ -151,7 +151,7 @@ bool EditorImagePreviewPlugin::handles(const String &p_type) const { return p_type == "Image"; } -Ref<Texture> EditorImagePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { +Ref<Texture2D> EditorImagePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { Ref<Image> img = p_from; @@ -182,7 +182,7 @@ Ref<Texture> EditorImagePreviewPlugin::generate(const RES &p_from, const Size2 & Ref<ImageTexture> ptex; ptex.instance(); - ptex->create_from_image(img, 0); + ptex->create_from_image(img); return ptex; } @@ -199,12 +199,12 @@ bool EditorBitmapPreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "BitMap"); } -Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { +Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { Ref<BitMap> bm = p_from; if (bm->get_size() == Size2()) { - return Ref<Texture>(); + return Ref<Texture2D>(); } PoolVector<uint8_t> data; @@ -231,7 +231,7 @@ Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size2 if (img->is_compressed()) { if (img->decompress() != OK) - return Ref<Texture>(); + return Ref<Texture2D>(); } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { img->convert(Image::FORMAT_RGBA8); } @@ -249,7 +249,7 @@ Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size2 Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img, 0); + ptex->create_from_image(img); return ptex; } @@ -266,12 +266,13 @@ bool EditorPackedScenePreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "PackedScene"); } -Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { + +Ref<Texture2D> EditorPackedScenePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { return generate_from_path(p_from->get_path(), p_size); } -Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { +Ref<Texture2D> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { String temp_path = EditorSettings::get_singleton()->get_cache_dir(); String cache_base = ProjectSettings::get_singleton()->globalize_path(p_path).md5_text(); @@ -282,7 +283,7 @@ Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_ String path = cache_base + ".png"; if (!FileAccess::exists(path)) - return Ref<Texture>(); + return Ref<Texture2D>(); Ref<Image> img; img.instance(); @@ -292,11 +293,11 @@ Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_ Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); post_process_preview(img); - ptex->create_from_image(img, 0); + ptex->create_from_image(img); return ptex; } else { - return Ref<Texture>(); + return Ref<Texture2D>(); } } @@ -324,10 +325,10 @@ bool EditorMaterialPreviewPlugin::generate_small_preview_automatically() const { return true; } -Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { +Ref<Texture2D> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { Ref<Material> material = p_from; - ERR_FAIL_COND_V(material.is_null(), Ref<Texture>()); + ERR_FAIL_COND_V(material.is_null(), Ref<Texture2D>()); if (material->get_shader_mode() == Shader::MODE_SPATIAL) { @@ -342,7 +343,7 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Size OS::get_singleton()->delay_usec(10); } - Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture); + Ref<Image> img = VS::get_singleton()->texture_2d_get(viewport_texture); VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID()); ERR_FAIL_COND_V(!img.is_valid(), Ref<ImageTexture>()); @@ -352,11 +353,11 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Size img->resize(thumbnail_size, thumbnail_size, Image::INTERPOLATE_CUBIC); post_process_preview(img); Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img, 0); + ptex->create_from_image(img); return ptex; } - return Ref<Texture>(); + return Ref<Texture2D>(); } EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { @@ -369,7 +370,6 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { VS::get_singleton()->viewport_set_size(viewport, 128, 128); VS::get_singleton()->viewport_set_transparent_background(viewport, true); VS::get_singleton()->viewport_set_active(viewport, true); - VS::get_singleton()->viewport_set_vflip(viewport, true); viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); camera = VS::get_singleton()->camera_create(); @@ -490,15 +490,15 @@ bool EditorScriptPreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "Script"); } -Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { +Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { Ref<Script> scr = p_from; if (scr.is_null()) - return Ref<Texture>(); + return Ref<Texture2D>(); String code = scr->get_source_code().strip_edges(); if (code == "") - return Ref<Texture>(); + return Ref<Texture2D>(); List<String> kwors; scr->get_language()->get_reserved_words(&kwors); @@ -599,7 +599,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2 Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img, 0); + ptex->create_from_image(img); return ptex; } @@ -612,10 +612,10 @@ bool EditorAudioStreamPreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "AudioStream"); } -Ref<Texture> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { +Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { Ref<AudioStream> stream = p_from; - ERR_FAIL_COND_V(stream.is_null(), Ref<Texture>()); + ERR_FAIL_COND_V(stream.is_null(), Ref<Texture2D>()); PoolVector<uint8_t> img; @@ -627,7 +627,7 @@ Ref<Texture> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const S uint8_t *imgw = imgdata.ptr(); Ref<AudioStreamPlayback> playback = stream->instance_playback(); - ERR_FAIL_COND_V(playback.is_null(), Ref<Texture>()); + ERR_FAIL_COND_V(playback.is_null(), Ref<Texture2D>()); float len_s = stream->get_length(); if (len_s == 0) { @@ -687,7 +687,7 @@ Ref<Texture> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const S Ref<Image> image; image.instance(); image->create(w, h, false, Image::FORMAT_RGB8, img); - ptex->create_from_image(image, 0); + ptex->create_from_image(image); return ptex; } @@ -710,10 +710,10 @@ bool EditorMeshPreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "Mesh"); //any Mesh } -Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { +Ref<Texture2D> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { Ref<Mesh> mesh = p_from; - ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture>()); + ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture2D>()); VS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid()); @@ -726,7 +726,7 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 &p AABB rot_aabb = xform.xform(aabb); float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5; if (m == 0) - return Ref<Texture>(); + return Ref<Texture2D>(); m = 1.0 / m; m *= 0.5; xform.basis.scale(Vector3(m, m, m)); @@ -743,7 +743,7 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 &p OS::get_singleton()->delay_usec(10); } - Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture); + Ref<Image> img = VS::get_singleton()->texture_2d_get(viewport_texture); ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>()); VS::get_singleton()->instance_set_base(mesh_instance, RID()); @@ -762,7 +762,7 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 &p post_process_preview(img); Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img, 0); + ptex->create_from_image(img); return ptex; } @@ -772,7 +772,6 @@ EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() { viewport = VS::get_singleton()->viewport_create(); VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_DISABLED); - VS::get_singleton()->viewport_set_vflip(viewport, true); VS::get_singleton()->viewport_set_scenario(viewport, scenario); VS::get_singleton()->viewport_set_size(viewport, 128, 128); VS::get_singleton()->viewport_set_transparent_background(viewport, true); @@ -831,7 +830,7 @@ bool EditorFontPreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "DynamicFontData") || ClassDB::is_parent_class(p_type, "DynamicFont"); } -Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { +Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { RES res = ResourceLoader::load(p_path); Ref<DynamicFont> sampled_font; @@ -868,7 +867,7 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, c VS::get_singleton()->canvas_item_clear(canvas_item); - Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture); + Ref<Image> img = VS::get_singleton()->texture_2d_get(viewport_texture); ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>()); img->convert(Image::FORMAT_RGBA8); @@ -885,16 +884,16 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, c post_process_preview(img); Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img, 0); + ptex->create_from_image(img); return ptex; } -Ref<Texture> EditorFontPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { +Ref<Texture2D> EditorFontPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const { String path = p_from->get_path(); if (!FileAccess::exists(path)) { - return Ref<Texture>(); + return Ref<Texture2D>(); } return generate_from_path(path, p_size); } @@ -903,7 +902,6 @@ EditorFontPreviewPlugin::EditorFontPreviewPlugin() { viewport = VS::get_singleton()->viewport_create(); VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_DISABLED); - VS::get_singleton()->viewport_set_vflip(viewport, true); VS::get_singleton()->viewport_set_size(viewport, 128, 128); VS::get_singleton()->viewport_set_active(viewport, true); viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h index e6e4aff8de..840fa2410a 100644 --- a/editor/plugins/editor_preview_plugins.h +++ b/editor/plugins/editor_preview_plugins.h @@ -41,7 +41,7 @@ class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator { public: virtual bool handles(const String &p_type) const; virtual bool generate_small_preview_automatically() const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; EditorTexturePreviewPlugin(); }; @@ -52,7 +52,7 @@ class EditorImagePreviewPlugin : public EditorResourcePreviewGenerator { public: virtual bool handles(const String &p_type) const; virtual bool generate_small_preview_automatically() const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; EditorImagePreviewPlugin(); }; @@ -63,7 +63,7 @@ class EditorBitmapPreviewPlugin : public EditorResourcePreviewGenerator { public: virtual bool handles(const String &p_type) const; virtual bool generate_small_preview_automatically() const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; EditorBitmapPreviewPlugin(); }; @@ -72,8 +72,8 @@ class EditorPackedScenePreviewPlugin : public EditorResourcePreviewGenerator { public: virtual bool handles(const String &p_type) const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; - virtual Ref<Texture> generate_from_path(const String &p_path, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate_from_path(const String &p_path, const Size2 &p_size) const; EditorPackedScenePreviewPlugin(); }; @@ -102,7 +102,7 @@ protected: public: virtual bool handles(const String &p_type) const; virtual bool generate_small_preview_automatically() const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; EditorMaterialPreviewPlugin(); ~EditorMaterialPreviewPlugin(); @@ -111,7 +111,7 @@ public: class EditorScriptPreviewPlugin : public EditorResourcePreviewGenerator { public: virtual bool handles(const String &p_type) const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; EditorScriptPreviewPlugin(); }; @@ -119,7 +119,7 @@ public: class EditorAudioStreamPreviewPlugin : public EditorResourcePreviewGenerator { public: virtual bool handles(const String &p_type) const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; EditorAudioStreamPreviewPlugin(); }; @@ -146,7 +146,7 @@ protected: public: virtual bool handles(const String &p_type) const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; EditorMeshPreviewPlugin(); ~EditorMeshPreviewPlugin(); @@ -169,8 +169,8 @@ protected: public: virtual bool handles(const String &p_type) const; - virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; - virtual Ref<Texture> generate_from_path(const String &p_path, const Size2 &p_size) const; + virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; + virtual Ref<Texture2D> generate_from_path(const String &p_path, const Size2 &p_size) const; EditorFontPreviewPlugin(); ~EditorFontPreviewPlugin(); diff --git a/editor/plugins/gi_probe_editor_plugin.cpp b/editor/plugins/gi_probe_editor_plugin.cpp index 8914e0ed01..fe2c0d33b7 100644 --- a/editor/plugins/gi_probe_editor_plugin.cpp +++ b/editor/plugins/gi_probe_editor_plugin.cpp @@ -33,6 +33,18 @@ void GIProbeEditorPlugin::_bake() { if (gi_probe) { + if (gi_probe->get_probe_data().is_null()) { + String path = get_tree()->get_edited_scene_root()->get_filename(); + if (path == String()) { + path = "res://" + gi_probe->get_name() + "_data.res"; + } else { + String ext = path.get_extension(); + path = path.get_basename() + "." + gi_probe->get_name() + "_data.res"; + } + probe_file->set_current_path(path); + probe_file->popup_centered_ratio(); + return; + } gi_probe->bake(); } } @@ -51,13 +63,42 @@ bool GIProbeEditorPlugin::handles(Object *p_object) const { return p_object->is_class("GIProbe"); } +void GIProbeEditorPlugin::_notification(int p_what) { + + if (p_what == NOTIFICATION_PROCESS) { + if (!gi_probe) { + return; + } + + String text; + + Vector3i size = gi_probe->get_estimated_cell_size(); + text = itos(size.x) + ", " + itos(size.y) + ", " + itos(size.z); + int data_size = 4; + if (GLOBAL_GET("rendering/quality/gi_probes/anisotropic")) { + data_size += 4; + } + text += " - VRAM Size: " + String::num(size.x * size.y * size.z * data_size / (1024.0 * 1024.0), 2) + " Mb."; + + if (bake_info->get_text() == text) { + return; + } + + bake_info->add_color_override("font_color", bake_info->get_color("success_color", "Editor")); + + bake_info->set_text(text); + } +} + void GIProbeEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - bake->show(); + bake_hb->show(); + set_process(true); } else { - bake->hide(); + bake_hb->hide(); + set_process(false); } } @@ -82,21 +123,45 @@ void GIProbeEditorPlugin::bake_func_end() { tmp_progress = NULL; } +void GIProbeEditorPlugin::_giprobe_save_path_and_bake(const String &p_path) { + probe_file->hide(); + if (gi_probe) { + gi_probe->bake(); + ERR_FAIL_COND(gi_probe->get_probe_data().is_null()); + ResourceSaver::save(p_path, gi_probe->get_probe_data(), ResourceSaver::FLAG_CHANGE_PATH); + } +} + void GIProbeEditorPlugin::_bind_methods() { ClassDB::bind_method("_bake", &GIProbeEditorPlugin::_bake); + ClassDB::bind_method("_giprobe_save_path_and_bake", &GIProbeEditorPlugin::_giprobe_save_path_and_bake); } GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) { editor = p_node; + bake_hb = memnew(HBoxContainer); + bake_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + bake_hb->hide(); bake = memnew(ToolButton); bake->set_icon(editor->get_gui_base()->get_icon("Bake", "EditorIcons")); bake->set_text(TTR("Bake GI Probe")); - bake->hide(); bake->connect("pressed", this, "_bake"); - add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, bake); + bake_hb->add_child(bake); + bake_info = memnew(Label); + bake_info->set_h_size_flags(Control::SIZE_EXPAND_FILL); + bake_info->set_clip_text(true); + bake_hb->add_child(bake_info); + + add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, bake_hb); gi_probe = NULL; + probe_file = memnew(EditorFileDialog); + probe_file->set_mode(EditorFileDialog::MODE_SAVE_FILE); + probe_file->add_filter("*.res"); + probe_file->connect("file_selected", this, "_giprobe_save_path_and_bake"); + get_editor_interface()->get_base_control()->add_child(probe_file); + probe_file->set_title(TTR("Select path for GIProbe Data File")); GIProbe::bake_begin_function = bake_func_begin; GIProbe::bake_step_function = bake_func_step; diff --git a/editor/plugins/gi_probe_editor_plugin.h b/editor/plugins/gi_probe_editor_plugin.h index 5db682835d..2068ebaaa8 100644 --- a/editor/plugins/gi_probe_editor_plugin.h +++ b/editor/plugins/gi_probe_editor_plugin.h @@ -42,18 +42,24 @@ class GIProbeEditorPlugin : public EditorPlugin { GIProbe *gi_probe; + HBoxContainer *bake_hb; + Label *bake_info; ToolButton *bake; EditorNode *editor; + EditorFileDialog *probe_file; + static EditorProgress *tmp_progress; static void bake_func_begin(int p_steps); static void bake_func_step(int p_step, const String &p_description); static void bake_func_end(); void _bake(); + void _giprobe_save_path_and_bake(const String &p_path); protected: static void _bind_methods(); + void _notification(int p_what); public: virtual String get_name() const { return "GIProbe"; } diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp index 9f836ed0d3..b7dfe97081 100644 --- a/editor/plugins/item_list_editor_plugin.cpp +++ b/editor/plugins/item_list_editor_plugin.cpp @@ -105,7 +105,7 @@ void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const { String base = itos(i) + "/"; p_list->push_back(PropertyInfo(Variant::STRING, base + "text")); - p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture")); + p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D")); int flags = get_flags(); diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h index 8a73367bf7..8dcf938139 100644 --- a/editor/plugins/item_list_editor_plugin.h +++ b/editor/plugins/item_list_editor_plugin.h @@ -66,8 +66,8 @@ public: virtual void set_item_text(int p_idx, const String &p_text) {} virtual String get_item_text(int p_idx) const { return ""; }; - virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) {} - virtual Ref<Texture> get_item_icon(int p_idx) const { return Ref<Texture>(); }; + virtual void set_item_icon(int p_idx, const Ref<Texture2D> &p_tex) {} + virtual Ref<Texture2D> get_item_icon(int p_idx) const { return Ref<Texture2D>(); }; virtual void set_item_checkable(int p_idx, bool p_check) {} virtual void set_item_radio_checkable(int p_idx, bool p_check) {} @@ -109,8 +109,8 @@ public: virtual void set_item_text(int p_idx, const String &p_text) { ob->set_item_text(p_idx, p_text); } virtual String get_item_text(int p_idx) const { return ob->get_item_text(p_idx); } - virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { ob->set_item_icon(p_idx, p_tex); } - virtual Ref<Texture> get_item_icon(int p_idx) const { return ob->get_item_icon(p_idx); } + virtual void set_item_icon(int p_idx, const Ref<Texture2D> &p_tex) { ob->set_item_icon(p_idx, p_tex); } + virtual Ref<Texture2D> get_item_icon(int p_idx) const { return ob->get_item_icon(p_idx); } virtual void set_item_enabled(int p_idx, int p_enabled) { ob->set_item_disabled(p_idx, !p_enabled); } virtual bool is_item_enabled(int p_idx) const { return !ob->is_item_disabled(p_idx); } @@ -139,8 +139,8 @@ public: virtual void set_item_text(int p_idx, const String &p_text) { pp->set_item_text(p_idx, p_text); } virtual String get_item_text(int p_idx) const { return pp->get_item_text(p_idx); } - virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { pp->set_item_icon(p_idx, p_tex); } - virtual Ref<Texture> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); } + virtual void set_item_icon(int p_idx, const Ref<Texture2D> &p_tex) { pp->set_item_icon(p_idx, p_tex); } + virtual Ref<Texture2D> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); } virtual void set_item_checkable(int p_idx, bool p_check) { pp->set_item_as_checkable(p_idx, p_check); } virtual void set_item_radio_checkable(int p_idx, bool p_check) { pp->set_item_as_radio_checkable(p_idx, p_check); } @@ -182,8 +182,8 @@ public: virtual void set_item_text(int p_idx, const String &p_text) { pp->set_item_text(p_idx, p_text); } virtual String get_item_text(int p_idx) const { return pp->get_item_text(p_idx); } - virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { pp->set_item_icon(p_idx, p_tex); } - virtual Ref<Texture> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); } + virtual void set_item_icon(int p_idx, const Ref<Texture2D> &p_tex) { pp->set_item_icon(p_idx, p_tex); } + virtual Ref<Texture2D> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); } virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx, !p_enabled); } virtual bool is_item_enabled(int p_idx) const { return !pp->is_item_disabled(p_idx); } diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 750f814319..4e44082853 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -59,7 +59,7 @@ void MaterialEditor::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<Texture> checkerboard = get_icon("Checkerboard", "EditorIcons"); + Ref<Texture2D> checkerboard = get_icon("Checkerboard", "EditorIcons"); Size2 size = get_size(); draw_texture_rect(checkerboard, Rect2(Point2(), size), true); @@ -225,7 +225,9 @@ EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() { env.instance(); Ref<ProceduralSky> proc_sky = memnew(ProceduralSky(true)); env->set_sky(proc_sky); - env->set_background(Environment::BG_COLOR_SKY); + env->set_background(Environment::BG_COLOR); + env->set_ambient_source(Environment::AMBIENT_SOURCE_SKY); + env->set_reflection_source(Environment::REFLECTION_SOURCE_SKY); } MaterialEditorPlugin::MaterialEditorPlugin(EditorNode *p_node) { @@ -235,18 +237,18 @@ MaterialEditorPlugin::MaterialEditorPlugin(EditorNode *p_node) { add_inspector_plugin(plugin); } -String SpatialMaterialConversionPlugin::converts_to() const { +String StandardMaterial3DConversionPlugin::converts_to() const { return "ShaderMaterial"; } -bool SpatialMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { +bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const { - Ref<SpatialMaterial> mat = p_resource; + Ref<StandardMaterial3D> mat = p_resource; return mat.is_valid(); } -Ref<Resource> SpatialMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const { +Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const { - Ref<SpatialMaterial> mat = p_resource; + Ref<StandardMaterial3D> mat = p_resource; ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); Ref<ShaderMaterial> smat; @@ -266,9 +268,9 @@ Ref<Resource> SpatialMaterialConversionPlugin::convert(const Ref<Resource> &p_re for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { - // Texture parameter has to be treated specially since SpatialMaterial saved it + // Texture parameter has to be treated specially since StandardMaterial3D saved it // as RID but ShaderMaterial needs Texture itself - Ref<Texture> texture = mat->get_texture_by_name(E->get().name); + Ref<Texture2D> texture = mat->get_texture_by_name(E->get().name); if (texture.is_valid()) { smat->set_shader_param(E->get().name, texture); } else { diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index 7f0a373dc7..95a6c4bf8f 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -100,8 +100,8 @@ public: MaterialEditorPlugin(EditorNode *p_node); }; -class SpatialMaterialConversionPlugin : public EditorResourceConversionPlugin { - GDCLASS(SpatialMaterialConversionPlugin, EditorResourceConversionPlugin); +class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin { + GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin); public: virtual String converts_to() const; diff --git a/editor/plugins/mesh_instance_editor_plugin.cpp b/editor/plugins/mesh_instance_editor_plugin.cpp index 25329906a9..aaba6406c7 100644 --- a/editor/plugins/mesh_instance_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_editor_plugin.cpp @@ -32,7 +32,7 @@ #include "editor/editor_scale.h" #include "scene/3d/collision_shape.h" -#include "scene/3d/navigation_mesh.h" +#include "scene/3d/navigation_mesh_instance.h" #include "scene/3d/physics_body.h" #include "scene/gui/box_container.h" #include "spatial_editor_plugin.h" @@ -60,10 +60,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { } switch (p_option) { - case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: - case MENU_OPTION_CREATE_STATIC_CONVEX_BODY: { - - bool trimesh_shape = (p_option == MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); + case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: { EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); @@ -71,9 +68,12 @@ void MeshInstanceEditor::_menu_option(int p_option) { List<Node *> selection = editor_selection->get_selected_node_list(); if (selection.empty()) { - Ref<Shape> shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); - if (shape.is_null()) + Ref<Shape> shape = mesh->create_trimesh_shape(); + if (shape.is_null()) { + err_dialog->set_text(TTR("Couldn't create a Trimesh collision shape.")); + err_dialog->popup_centered_minsize(); return; + } CollisionShape *cshape = memnew(CollisionShape); cshape->set_shape(shape); @@ -82,11 +82,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { Node *owner = node == get_tree()->get_edited_scene_root() ? node : node->get_owner(); - if (trimesh_shape) - ur->create_action(TTR("Create Static Trimesh Body")); - else - ur->create_action(TTR("Create Static Convex Body")); - + ur->create_action(TTR("Create Static Trimesh Body")); ur->add_do_method(node, "add_child", body); ur->add_do_method(body, "set_owner", owner); ur->add_do_method(cshape, "set_owner", owner); @@ -108,7 +104,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { if (m.is_null()) continue; - Ref<Shape> shape = trimesh_shape ? m->create_trimesh_shape() : m->create_convex_shape(); + Ref<Shape> shape = m->create_trimesh_shape(); if (shape.is_null()) continue; @@ -158,10 +154,44 @@ void MeshInstanceEditor::_menu_option(int p_option) { ur->add_undo_method(node->get_parent(), "remove_child", cshape); ur->commit_action(); } break; - case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: { + case MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE: { if (node == get_tree()->get_edited_scene_root()) { - err_dialog->set_text(TTR("This doesn't work on scene root!")); + err_dialog->set_text(TTR("Can't create a single convex collision shape for the scene root.")); + err_dialog->popup_centered_minsize(); + return; + } + + Ref<Shape> shape = mesh->create_convex_shape(); + + if (shape.is_null()) { + err_dialog->set_text(TTR("Couldn't create a single convex collision shape.")); + err_dialog->popup_centered_minsize(); + return; + } + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + ur->create_action(TTR("Create Single Convex Shape")); + + CollisionShape *cshape = memnew(CollisionShape); + cshape->set_shape(shape); + cshape->set_transform(node->get_transform()); + + Node *owner = node->get_owner(); + + ur->add_do_method(node->get_parent(), "add_child", cshape); + ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1); + ur->add_do_method(cshape, "set_owner", owner); + ur->add_do_reference(cshape); + ur->add_undo_method(node->get_parent(), "remove_child", cshape); + + ur->commit_action(); + + } break; + case MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES: { + + if (node == get_tree()->get_edited_scene_root()) { + err_dialog->set_text(TTR("Can't create multiple convex collision shapes for the scene root.")); err_dialog->popup_centered_minsize(); return; } @@ -169,13 +199,13 @@ void MeshInstanceEditor::_menu_option(int p_option) { Vector<Ref<Shape> > shapes = mesh->convex_decompose(); if (!shapes.size()) { - err_dialog->set_text(TTR("Failed creating shapes!")); + err_dialog->set_text(TTR("Couldn't create any collision shapes.")); err_dialog->popup_centered_minsize(); return; } UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - ur->create_action(TTR("Create Convex Shape(s)")); + ur->create_action(TTR("Create Multiple Convex Shapes")); for (int i = 0; i < shapes.size(); i++) { @@ -421,13 +451,19 @@ MeshInstanceEditor::MeshInstanceEditor() { options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshInstance", "EditorIcons")); options->get_popup()->add_item(TTR("Create Trimesh Static Body"), MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); + options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a StaticBody and assigns a polygon-based collision shape to it automatically.\nThis is the most accurate (but slowest) option for collision detection.")); options->get_popup()->add_separator(); options->get_popup()->add_item(TTR("Create Trimesh Collision Sibling"), MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); - options->get_popup()->add_item(TTR("Create Convex Collision Sibling(s)"), MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE); + options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a polygon-based collision shape.\nThis is the most accurate (but slowest) option for collision detection.")); + options->get_popup()->add_item(TTR("Create Single Convex Collision Siblings"), MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE); + options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a single convex collision shape.\nThis is the fastest (but least accurate) option for collision detection.")); + options->get_popup()->add_item(TTR("Create Multiple Convex Collision Siblings"), MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES); + options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a polygon-based collision shape.\nThis is a performance middle-ground between the two above options.")); options->get_popup()->add_separator(); options->get_popup()->add_item(TTR("Create Navigation Mesh"), MENU_OPTION_CREATE_NAVMESH); options->get_popup()->add_separator(); options->get_popup()->add_item(TTR("Create Outline Mesh..."), MENU_OPTION_CREATE_OUTLINE_MESH); + options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a static outline mesh. The outline mesh will have its normals flipped automatically.\nThis can be used instead of the SpatialMaterial Grow property when using that property isn't possible.")); options->get_popup()->add_separator(); options->get_popup()->add_item(TTR("View UV1"), MENU_OPTION_DEBUG_UV1); options->get_popup()->add_item(TTR("View UV2"), MENU_OPTION_DEBUG_UV2); diff --git a/editor/plugins/mesh_instance_editor_plugin.h b/editor/plugins/mesh_instance_editor_plugin.h index 5c95676fc4..5ca9aa3fec 100644 --- a/editor/plugins/mesh_instance_editor_plugin.h +++ b/editor/plugins/mesh_instance_editor_plugin.h @@ -43,9 +43,9 @@ class MeshInstanceEditor : public Control { enum Menu { MENU_OPTION_CREATE_STATIC_TRIMESH_BODY, - MENU_OPTION_CREATE_STATIC_CONVEX_BODY, MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE, - MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE, + MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE, + MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES, MENU_OPTION_CREATE_NAVMESH, MENU_OPTION_CREATE_OUTLINE_MESH, MENU_OPTION_CREATE_UV2, diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp index 92898ff9c3..b77cb6453f 100644 --- a/editor/plugins/mesh_library_editor_plugin.cpp +++ b/editor/plugins/mesh_library_editor_plugin.cpp @@ -34,7 +34,7 @@ #include "editor/editor_settings.h" #include "main/main.h" #include "scene/3d/mesh_instance.h" -#include "scene/3d/navigation_mesh.h" +#include "scene/3d/navigation_mesh_instance.h" #include "scene/3d/physics_body.h" #include "scene/main/viewport.h" #include "scene/resources/packed_scene.h" @@ -182,7 +182,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, } } - Vector<Ref<Texture> > textures = EditorInterface::get_singleton()->make_mesh_previews(meshes, &transforms, EditorSettings::get_singleton()->get("editors/grid_map/preview_size")); + Vector<Ref<Texture2D> > textures = EditorInterface::get_singleton()->make_mesh_previews(meshes, &transforms, EditorSettings::get_singleton()->get("editors/grid_map/preview_size")); int j = 0; for (int i = 0; i < ids.size(); i++) { diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp index 5dc222f84c..ddd27b5e97 100644 --- a/editor/plugins/multimesh_editor_plugin.cpp +++ b/editor/plugins/multimesh_editor_plugin.cpp @@ -172,7 +172,7 @@ void MultiMeshEditor::_populate() { int instance_count = populate_amount->get_value(); multimesh->set_transform_format(MultiMesh::TRANSFORM_3D); - multimesh->set_color_format(MultiMesh::COLOR_NONE); + multimesh->set_use_colors(false); multimesh->set_instance_count(instance_count); float _tilt_random = populate_tilt_random->get_value(); diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index b036368bc8..3a48673d8e 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -292,7 +292,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() { Ref<ImageTexture> imgt; imgt.instance(); - imgt->create_from_image(img, 0); + imgt->create_from_image(img); pm->set_emission_point_texture(imgt); pm->set_emission_point_count(vpc); @@ -314,7 +314,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() { img->create(w, h, false, Image::FORMAT_RGBA8, colordata); imgt.instance(); - imgt->create_from_image(img, 0); + imgt->create_from_image(img); pm->set_emission_color_texture(imgt); } @@ -337,7 +337,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() { img->create(w, h, false, Image::FORMAT_RGF, normdata); imgt.instance(); - imgt->create_from_image(img, 0); + imgt->create_from_image(img); pm->set_emission_normal_texture(imgt); } else { diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index f869dabf9a..cb29e11b9d 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -410,7 +410,6 @@ void ParticlesEditor::_generate_emission_points() { Ref<ImageTexture> tex; tex.instance(); - tex->create_from_image(image, Texture::FLAG_FILTER); Ref<ParticlesMaterial> material = node->get_process_material(); ERR_FAIL_COND(material.is_null()); @@ -440,7 +439,6 @@ void ParticlesEditor::_generate_emission_points() { Ref<ImageTexture> tex2; tex2.instance(); - tex2->create_from_image(image2, Texture::FLAG_FILTER); material->set_emission_normal_texture(tex2); } else { diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 3737dbdd57..383dada590 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -373,12 +373,12 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - const Ref<Texture> path_sharp_handle = get_icon("EditorPathSharpHandle", "EditorIcons"); - const Ref<Texture> path_smooth_handle = get_icon("EditorPathSmoothHandle", "EditorIcons"); + const Ref<Texture2D> path_sharp_handle = get_icon("EditorPathSharpHandle", "EditorIcons"); + const Ref<Texture2D> path_smooth_handle = get_icon("EditorPathSmoothHandle", "EditorIcons"); // Both handle icons must be of the same size const Size2 handle_size = path_sharp_handle->get_size(); - const Ref<Texture> curve_handle = get_icon("EditorCurveHandle", "EditorIcons"); + const Ref<Texture2D> curve_handle = get_icon("EditorCurveHandle", "EditorIcons"); const Size2 curve_handle_size = curve_handle->get_size(); Ref<Curve2D> curve = node->get_curve(); @@ -396,8 +396,8 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { if (point != pointout) { smooth = true; // Draw the line with a dark and light color to be visible on all backgrounds - vpc->draw_line(point, pointout, Color(0, 0, 0, 0.5), Math::round(EDSCALE), true); - vpc->draw_line(point, pointout, Color(1, 1, 1, 0.5), Math::round(EDSCALE), true); + vpc->draw_line(point, pointout, Color(0, 0, 0, 0.5), Math::round(EDSCALE)); + vpc->draw_line(point, pointout, Color(1, 1, 1, 0.5), Math::round(EDSCALE)); vpc->draw_texture_rect(curve_handle, Rect2(pointout - curve_handle_size * 0.5, curve_handle_size), false, Color(1, 1, 1, 0.75)); } } @@ -407,8 +407,8 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { if (point != pointin) { smooth = true; // Draw the line with a dark and light color to be visible on all backgrounds - vpc->draw_line(point, pointin, Color(0, 0, 0, 0.5), Math::round(EDSCALE), true); - vpc->draw_line(point, pointin, Color(1, 1, 1, 0.5), Math::round(EDSCALE), true); + vpc->draw_line(point, pointin, Color(0, 0, 0, 0.5), Math::round(EDSCALE)); + vpc->draw_line(point, pointin, Color(1, 1, 1, 0.5), Math::round(EDSCALE)); vpc->draw_texture_rect(curve_handle, Rect2(pointin - curve_handle_size * 0.5, curve_handle_size), false, Color(1, 1, 1, 0.75)); } } @@ -420,7 +420,7 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } if (on_edge) { - Ref<Texture> add_handle = get_icon("EditorHandleAdd", "EditorIcons"); + Ref<Texture2D> add_handle = get_icon("EditorHandleAdd", "EditorIcons"); p_overlay->draw_texture(add_handle, edge_point - add_handle->get_size() * 0.5); } } diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp index 67889bc074..92f21d8428 100644 --- a/editor/plugins/path_editor_plugin.cpp +++ b/editor/plugins/path_editor_plugin.cpp @@ -221,9 +221,9 @@ void PathSpatialGizmo::redraw() { clear(); - Ref<SpatialMaterial> path_material = gizmo_plugin->get_material("path_material", this); - Ref<SpatialMaterial> path_thin_material = gizmo_plugin->get_material("path_thin_material", this); - Ref<SpatialMaterial> handles_material = gizmo_plugin->get_material("handles"); + Ref<StandardMaterial3D> path_material = gizmo_plugin->get_material("path_material", this); + Ref<StandardMaterial3D> path_thin_material = gizmo_plugin->get_material("path_thin_material", this); + Ref<StandardMaterial3D> handles_material = gizmo_plugin->get_material("handles"); Ref<Curve3D> c = path->get_curve(); if (c.is_null()) diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 35c0142d4b..14e22625d9 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -980,7 +980,7 @@ void Polygon2DEditor::_uv_draw() { if (!uv_edit->is_visible() || !_get_node()) return; - Ref<Texture> base_tex = node->get_texture(); + Ref<Texture2D> base_tex = node->get_texture(); if (base_tex.is_null()) return; @@ -1050,7 +1050,7 @@ void Polygon2DEditor::_uv_draw() { } // All UV points are sharp, so use the sharp handle icon - Ref<Texture> handle = get_icon("EditorPathSharpHandle", "EditorIcons"); + Ref<Texture2D> handle = get_icon("EditorPathSharpHandle", "EditorIcons"); Color poly_line_color = Color(0.9, 0.5, 0.5); if (polygons.size() || polygon_create.size()) { @@ -1078,7 +1078,7 @@ void Polygon2DEditor::_uv_draw() { int next = uv_draw_max > 0 ? (i + 1) % uv_draw_max : 0; if (i < uv_draw_max && uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) { - uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, Math::round(EDSCALE), true); + uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, Math::round(EDSCALE)); } Vector2 next_point = uvs[next]; @@ -1086,7 +1086,7 @@ void Polygon2DEditor::_uv_draw() { next_point = uv_create_to; } if (i < uv_draw_max /*&& polygons.size() == 0 && polygon_create.size() == 0*/) { //if using or creating polygons, do not show outline (will show polygons instead) - uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, Math::round(EDSCALE), true); + uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, Math::round(EDSCALE)); } rect.expand_to(mtx.basis_xform(uvs[i])); @@ -1107,7 +1107,7 @@ void Polygon2DEditor::_uv_draw() { if (idx_next < 0 || idx_next >= uvs.size()) continue; - uv_edit_draw->draw_line(mtx.xform(uvs[idx]), mtx.xform(uvs[idx_next]), polygon_line_color, Math::round(EDSCALE), true); + uv_edit_draw->draw_line(mtx.xform(uvs[idx]), mtx.xform(uvs[idx_next]), polygon_line_color, Math::round(EDSCALE)); } if (points.size() >= 3) { uv_edit_draw->draw_polygon(polypoints, polygon_fill_color); @@ -1134,7 +1134,7 @@ void Polygon2DEditor::_uv_draw() { for (int i = 0; i < polygon_create.size(); i++) { Vector2 from = uvs[polygon_create[i]]; Vector2 to = (i + 1) < polygon_create.size() ? uvs[polygon_create[i + 1]] : uv_create_to; - uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), polygon_line_color, Math::round(EDSCALE), true); + uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), polygon_line_color, Math::round(EDSCALE)); } } diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index 3489537fa4..1349de5d8e 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -205,7 +205,7 @@ void EditorPropertyRootMotion::update_property() { assign->set_tooltip(p); if (p == NodePath()) { - assign->set_icon(Ref<Texture>()); + assign->set_icon(Ref<Texture2D>()); assign->set_text(TTR("Assign...")); assign->set_flat(false); return; @@ -222,7 +222,7 @@ void EditorPropertyRootMotion::update_property() { } if (!base_node || !base_node->has_node(p)) { - assign->set_icon(Ref<Texture>()); + assign->set_icon(Ref<Texture2D>()); assign->set_text(p); return; } @@ -242,7 +242,7 @@ void EditorPropertyRootMotion::setup(const NodePath &p_base_hint) { void EditorPropertyRootMotion::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - Ref<Texture> t = get_icon("Clear", "EditorIcons"); + Ref<Texture2D> t = get_icon("Clear", "EditorIcons"); clear->set_icon(t); } } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index f13abd47a9..76312df20a 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -62,6 +62,7 @@ void ScriptEditorBase::_bind_methods() { ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what"))); // TODO: This signal is no use for VisualScript. ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text"))); + ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text"))); } static bool _is_built_in_script(Script *p_script) { @@ -1093,6 +1094,10 @@ void ScriptEditor::_menu_option(int p_option) { _on_find_in_files_requested(""); } break; + case REPLACE_IN_FILES: { + + _on_replace_in_files_requested(""); + } break; case SEARCH_HELP: { help_search_dialog->popup_dialog(); @@ -1252,7 +1257,7 @@ void ScriptEditor::_menu_option(int p_option) { } Ref<EditorScript> es = memnew(EditorScript); - es->set_script(scr.get_ref_ptr()); + es->set_script(scr); es->set_editor(EditorNode::get_singleton()); es->_run(); @@ -1647,7 +1652,7 @@ struct _ScriptEditorItemData { String name; String sort_key; - Ref<Texture> icon; + Ref<Texture2D> icon; int index; String tooltip; bool used; @@ -1832,7 +1837,7 @@ void ScriptEditor::_update_script_names() { ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); if (se) { - Ref<Texture> icon = se->get_icon(); + Ref<Texture2D> icon = se->get_icon(); String path = se->get_edited_resource()->get_path(); bool built_in = !path.is_resource_file(); String name; @@ -1893,7 +1898,7 @@ void ScriptEditor::_update_script_names() { if (eh) { String name = eh->get_class(); - Ref<Texture> icon = get_icon("Help", "EditorIcons"); + Ref<Texture2D> icon = get_icon("Help", "EditorIcons"); String tooltip = vformat(TTR("%s Class Reference"), name); _ScriptEditorItemData sd; @@ -2196,6 +2201,7 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra se->connect("go_to_help", this, "_help_class_goto"); se->connect("request_save_history", this, "_save_history"); se->connect("search_in_files_requested", this, "_on_find_in_files_requested"); + se->connect("replace_in_files_requested", this, "_on_replace_in_files_requested"); //test for modification, maybe the script was not edited but was loaded @@ -2416,7 +2422,7 @@ Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { HBoxContainer *drag_preview = memnew(HBoxContainer); String preview_name = ""; - Ref<Texture> preview_icon; + Ref<Texture2D> preview_icon; ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(cur_node); if (se) { @@ -3025,7 +3031,16 @@ void ScriptEditor::_script_changed() { void ScriptEditor::_on_find_in_files_requested(String text) { + find_in_files_dialog->set_find_in_files_mode(FindInFilesDialog::SEARCH_MODE); + find_in_files_dialog->set_search_text(text); + find_in_files_dialog->popup_centered_minsize(); +} + +void ScriptEditor::_on_replace_in_files_requested(String text) { + + find_in_files_dialog->set_find_in_files_mode(FindInFilesDialog::REPLACE_MODE); find_in_files_dialog->set_search_text(text); + find_in_files_dialog->set_replace_text(""); find_in_files_dialog->popup_centered_minsize(); } @@ -3078,6 +3093,7 @@ void ScriptEditor::_start_find_in_files(bool with_replace) { f->set_filter(find_in_files_dialog->get_filter()); find_in_files->set_with_replace(with_replace); + find_in_files->set_replace_text(find_in_files_dialog->get_replace_text()); find_in_files->start_search(); editor->make_bottom_panel_item_visible(find_in_files); @@ -3153,6 +3169,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_filter_methods_text_changed", &ScriptEditor::_filter_methods_text_changed); ClassDB::bind_method("_update_recent_scripts", &ScriptEditor::_update_recent_scripts); ClassDB::bind_method("_on_find_in_files_requested", &ScriptEditor::_on_find_in_files_requested); + ClassDB::bind_method("_on_replace_in_files_requested", &ScriptEditor::_on_replace_in_files_requested); ClassDB::bind_method("_start_find_in_files", &ScriptEditor::_start_find_in_files); ClassDB::bind_method("_on_find_in_files_result_selected", &ScriptEditor::_on_find_in_files_result_selected); ClassDB::bind_method("_on_find_in_files_modified_files", &ScriptEditor::_on_find_in_files_modified_files); @@ -3209,7 +3226,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { script_list = memnew(ItemList); scripts_vbox->add_child(script_list); - script_list->set_custom_minimum_size(Size2(150, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing + script_list->set_custom_minimum_size(Size2(150, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing script_list->set_v_size_flags(SIZE_EXPAND_FILL); script_split->set_split_offset(140); _sort_list_on_update = true; @@ -3254,14 +3271,14 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { overview_vbox->add_child(members_overview); members_overview->set_allow_reselect(true); - members_overview->set_custom_minimum_size(Size2(0, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing + members_overview->set_custom_minimum_size(Size2(0, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing members_overview->set_v_size_flags(SIZE_EXPAND_FILL); members_overview->set_allow_rmb_select(true); help_overview = memnew(ItemList); overview_vbox->add_child(help_overview); help_overview->set_allow_reselect(true); - help_overview->set_custom_minimum_size(Size2(0, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing + help_overview->set_custom_minimum_size(Size2(0, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing help_overview->set_v_size_flags(SIZE_EXPAND_FILL); tab_container = memnew(TabContainer); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index a41480c80d..4087b7cd55 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -92,7 +92,7 @@ public: virtual void set_edited_resource(const RES &p_res) = 0; virtual void reload_text() = 0; virtual String get_name() = 0; - virtual Ref<Texture> get_icon() = 0; + virtual Ref<Texture2D> get_icon() = 0; virtual bool is_unsaved() = 0; virtual Variant get_edit_state() = 0; virtual void set_edit_state(const Variant &p_state) = 0; @@ -163,6 +163,7 @@ class ScriptEditor : public PanelContainer { DEBUG_SHOW_KEEP_OPEN, DEBUG_WITH_EXTERNAL_EDITOR, SEARCH_IN_FILES, + REPLACE_IN_FILES, SEARCH_HELP, SEARCH_WEBSITE, REQUEST_DOCS, @@ -404,6 +405,7 @@ class ScriptEditor : public PanelContainer { Error _save_text_file(Ref<TextFile> p_text_file, const String &p_path); void _on_find_in_files_requested(String text); + void _on_replace_in_files_requested(String text); void _on_find_in_files_result_selected(String fpath, int line_number, int begin, int end); void _start_find_in_files(bool with_replace); void _on_find_in_files_modified_files(PoolStringArray paths); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 1432c3fc63..1ec425d09d 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -548,13 +548,13 @@ String ScriptTextEditor::get_name() { return name; } -Ref<Texture> ScriptTextEditor::get_icon() { +Ref<Texture2D> ScriptTextEditor::get_icon() { if (get_parent_control() && get_parent_control()->has_icon(script->get_class(), "EditorIcons")) { return get_parent_control()->get_icon(script->get_class(), "EditorIcons"); } - return Ref<Texture>(); + return Ref<Texture2D>(); } void ScriptTextEditor::_validate_script() { @@ -1258,6 +1258,12 @@ void ScriptTextEditor::_edit_option(int p_op) { // So this will be delegated to the ScriptEditor. emit_signal("search_in_files_requested", selected_text); } break; + case REPLACE_IN_FILES: { + + String selected_text = code_editor->get_text_edit()->get_selection_text(); + + emit_signal("replace_in_files_requested", selected_text); + } break; case SEARCH_LOCATE_FUNCTION: { quick_open->popup_dialog(get_functions()); @@ -1882,6 +1888,7 @@ ScriptTextEditor::ScriptTextEditor() { search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE); search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES); + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace_in_files"), REPLACE_IN_FILES); search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL); search_menu->get_popup()->connect("id_pressed", this, "_edit_option"); @@ -1990,6 +1997,7 @@ void ScriptTextEditor::register_editor() { #endif ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F); + ED_SHORTCUT("script_text_editor/replace_in_files", TTR("Replace in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_R); #ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 9018e9d3c2..359f0b0019 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -133,6 +133,7 @@ class ScriptTextEditor : public ScriptEditorBase { SEARCH_LOCATE_FUNCTION, SEARCH_GOTO_LINE, SEARCH_IN_FILES, + REPLACE_IN_FILES, BOOKMARK_TOGGLE, BOOKMARK_GOTO_NEXT, BOOKMARK_GOTO_PREV, @@ -199,7 +200,7 @@ public: virtual Vector<String> get_functions(); virtual void reload_text(); virtual String get_name(); - virtual Ref<Texture> get_icon(); + virtual Ref<Texture2D> get_icon(); virtual bool is_unsaved(); virtual Variant get_edit_state(); virtual void set_edit_state(const Variant &p_state); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index c24a666c55..a19f0b4975 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -369,6 +369,7 @@ void ShaderEditor::_editor_settings_changed() { shader_editor->get_text_edit()->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type")); shader_editor->get_text_edit()->set_auto_indent(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent")); shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); + shader_editor->get_text_edit()->set_draw_spaces(EditorSettings::get_singleton()->get("text_editor/indent/draw_spaces")); shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_numbers")); shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting")); shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); @@ -381,6 +382,9 @@ void ShaderEditor::_editor_settings_changed() { shader_editor->get_text_edit()->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/navigation/v_scroll_speed")); shader_editor->get_text_edit()->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/navigation/show_minimap")); shader_editor->get_text_edit()->set_minimap_width((int)EditorSettings::get_singleton()->get("text_editor/navigation/minimap_width") * EDSCALE); + shader_editor->get_text_edit()->set_show_line_length_guideline(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guideline")); + shader_editor->get_text_edit()->set_line_length_guideline_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_column")); + shader_editor->get_text_edit()->set_breakpoint_gutter_enabled(false); } void ShaderEditor::_bind_methods() { diff --git a/editor/plugins/skeleton_editor_plugin.cpp b/editor/plugins/skeleton_editor_plugin.cpp index 8b5fe7d2c5..9101c64eab 100644 --- a/editor/plugins/skeleton_editor_plugin.cpp +++ b/editor/plugins/skeleton_editor_plugin.cpp @@ -103,8 +103,10 @@ void SkeletonEditor::create_physical_skeleton() { PhysicalBone *SkeletonEditor::create_physical_bone(int bone_id, int bone_child_id, const Vector<BoneInfo> &bones_infos) { - real_t half_height(skeleton->get_bone_rest(bone_child_id).origin.length() * 0.5); - real_t radius(half_height * 0.2); + const Transform child_rest = skeleton->get_bone_rest(bone_child_id); + + const real_t half_height(child_rest.origin.length() * 0.5); + const real_t radius(half_height * 0.2); CapsuleShape *bone_shape_capsule = memnew(CapsuleShape); bone_shape_capsule->set_height((half_height - radius) * 2); @@ -114,7 +116,8 @@ PhysicalBone *SkeletonEditor::create_physical_bone(int bone_id, int bone_child_i bone_shape->set_shape(bone_shape_capsule); Transform body_transform; - body_transform.origin = Vector3(0, 0, -half_height); + body_transform.set_look_at(Vector3(0, 0, 0), child_rest.origin, Vector3(0, 1, 0)); + body_transform.origin = body_transform.basis.xform(Vector3(0, 0, -half_height)); Transform joint_transform; joint_transform.origin = Vector3(0, 0, half_height); diff --git a/editor/plugins/skeleton_ik_editor_plugin.cpp b/editor/plugins/skeleton_ik_editor_plugin.cpp index 43dc13b270..eb6ad9498d 100644 --- a/editor/plugins/skeleton_ik_editor_plugin.cpp +++ b/editor/plugins/skeleton_ik_editor_plugin.cpp @@ -41,21 +41,12 @@ void SkeletonIKEditorPlugin::_play() { return; if (play_btn->is_pressed()) { - - initial_bone_poses.resize(skeleton_ik->get_parent_skeleton()->get_bone_count()); - for (int i = 0; i < skeleton_ik->get_parent_skeleton()->get_bone_count(); ++i) { - initial_bone_poses.write[i] = skeleton_ik->get_parent_skeleton()->get_bone_pose(i); - } - skeleton_ik->start(); } else { skeleton_ik->stop(); - if (initial_bone_poses.size() != skeleton_ik->get_parent_skeleton()->get_bone_count()) - return; - for (int i = 0; i < skeleton_ik->get_parent_skeleton()->get_bone_count(); ++i) { - skeleton_ik->get_parent_skeleton()->set_bone_pose(i, initial_bone_poses[i]); + skeleton_ik->get_parent_skeleton()->set_bone_global_pose_override(i, Transform(), 0); } } } diff --git a/editor/plugins/skeleton_ik_editor_plugin.h b/editor/plugins/skeleton_ik_editor_plugin.h index 06c07031f6..814eb8ff5b 100644 --- a/editor/plugins/skeleton_ik_editor_plugin.h +++ b/editor/plugins/skeleton_ik_editor_plugin.h @@ -44,7 +44,6 @@ class SkeletonIKEditorPlugin : public EditorPlugin { Button *play_btn; EditorNode *editor; - Vector<Transform> initial_bone_poses; void _play(); diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 31e6b65640..e916f6f028 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -250,9 +250,9 @@ void SpatialEditorViewport::_clear_selected() { editor_selection->clear(); } -void SpatialEditorViewport::_select_clicked(bool p_append, bool p_single) { +void SpatialEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_allow_locked) { - if (!clicked) + if (clicked.is_null()) return; Node *node = Object::cast_to<Node>(ObjectDB::get_instance(clicked)); @@ -260,17 +260,20 @@ void SpatialEditorViewport::_select_clicked(bool p_append, bool p_single) { if (!selected) return; - // Replace the node by the group if grouped - while (node && node != editor->get_edited_scene()->get_parent()) { - Spatial *selected_tmp = Object::cast_to<Spatial>(node); - if (selected_tmp && node->has_meta("_edit_group_")) { - selected = selected_tmp; + if (!p_allow_locked) { + // Replace the node by the group if grouped + while (node && node != editor->get_edited_scene()->get_parent()) { + Spatial *selected_tmp = Object::cast_to<Spatial>(node); + if (selected_tmp && node->has_meta("_edit_group_")) { + selected = selected_tmp; + } + node = node->get_parent(); } - node = node->get_parent(); } - if (!_is_node_locked(selected)) + if (p_allow_locked || !_is_node_locked(selected)) { _select(selected, clicked_wants_append, true); + } } void SpatialEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { @@ -306,7 +309,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, Set<Ref<EditorSpatialGizmo> > found_gizmos; Node *edited_scene = get_tree()->get_edited_scene_root(); - ObjectID closest = 0; + ObjectID closest; Node *item = NULL; float closest_dist = 1e20; int selected_handle = -1; @@ -353,7 +356,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, } if (!item) - return 0; + return ObjectID(); if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle >= 0)) { @@ -847,9 +850,9 @@ void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) { clicked = selection_results[0].item->get_instance_id(); selection_results.clear(); - if (clicked) { - _select_clicked(clicked_wants_append, true); - clicked = 0; + if (clicked.is_valid()) { + _select_clicked(clicked_wants_append, true, spatial_editor->get_tool_mode() != SpatialEditor::TOOL_MODE_LIST_SELECT); + clicked = ObjectID(); } } else if (!selection_results.empty()) { @@ -861,11 +864,33 @@ void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) { Spatial *spat = selection_results[i].item; - Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(spat, "Node"); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(spat, "Node"); String node_path = "/" + root_name + "/" + root_path.rel_path_to(spat->get_path()); - selection_menu->add_item(spat->get_name()); + int locked = 0; + if (_is_node_locked(spat)) { + locked = 1; + } else { + Node *ed_scene = editor->get_edited_scene(); + Node *node = spat; + + while (node && node != ed_scene->get_parent()) { + Spatial *selected_tmp = Object::cast_to<Spatial>(node); + if (selected_tmp && node->has_meta("_edit_group_")) { + locked = 2; + } + node = node->get_parent(); + } + } + + String suffix = String(); + if (locked == 1) { + suffix = " (" + TTR("Locked") + ")"; + } else if (locked == 2) { + suffix = " (" + TTR("Grouped") + ")"; + } + selection_menu->add_item((String)spat->get_name() + suffix); selection_menu->set_item_icon(i, icon); selection_menu->set_item_metadata(i, node_path); selection_menu->set_item_tooltip(i, String(spat->get_name()) + "\nType: " + spat->get_class() + "\nPath: " + node_path); @@ -1070,7 +1095,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (_gizmo_select(_edit.mouse_pos)) break; - clicked = 0; + clicked = ObjectID(); clicked_includes_current = false; if ((spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT && b->get_control()) || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE) { @@ -1114,7 +1139,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { clicked_wants_append = b->get_shift(); - if (!clicked) { + if (clicked.is_null()) { if (!clicked_wants_append) _clear_selected(); @@ -1125,7 +1150,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { cursor.region_end = b->get_position(); } - if (clicked && gizmo_handle >= 0) { + if (clicked.is_valid() && gizmo_handle >= 0) { Spatial *spa = Object::cast_to<Spatial>(ObjectDB::get_instance(clicked)); if (spa) { @@ -1150,10 +1175,10 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { _edit.gizmo = Ref<EditorSpatialGizmo>(); break; } - if (clicked) { + if (clicked.is_valid()) { _select_clicked(clicked_wants_append, true); // Processing was deferred. - clicked = 0; + clicked = ObjectID(); } if (cursor.region_select) { @@ -1254,7 +1279,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } else if (nav_scheme == NAVIGATION_MODO && m->get_alt()) { nav_mode = NAVIGATION_ORBIT; } else { - if (clicked) { + if (clicked.is_valid()) { if (!clicked_includes_current) { @@ -1263,7 +1288,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } _compute_edit(_edit.mouse_pos); - clicked = 0; + clicked = ObjectID(); _edit.mode = TRANSFORM_TRANSLATE; } @@ -2247,9 +2272,6 @@ void SpatialEditorViewport::_notification(int p_what) { int msaa_mode = ProjectSettings::get_singleton()->get("rendering/quality/filters/msaa"); viewport->set_msaa(Viewport::MSAA(msaa_mode)); - bool hdr = ProjectSettings::get_singleton()->get("rendering/quality/depth/hdr"); - viewport->set_hdr(hdr); - bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION)); info_label->set_visible(show_info); @@ -2346,7 +2368,7 @@ void SpatialEditorViewport::_notification(int p_what) { } } -static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture> icon) { +static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture2D> icon) { // Adjust bar size from control height Vector2 surface_size = surface.get_size(); @@ -2417,8 +2439,7 @@ void SpatialEditorViewport::_draw() { _edit.mouse_pos, center, get_color("accent_color", "Editor") * Color(1, 1, 1, 0.6), - Math::round(2 * EDSCALE), - true); + Math::round(2 * EDSCALE)); } if (previewing) { @@ -2738,43 +2759,76 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked(idx, !current); } break; - case VIEW_DISPLAY_NORMAL: { - - viewport->set_debug_draw(Viewport::DEBUG_DRAW_DISABLED); - - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); - } break; - case VIEW_DISPLAY_WIREFRAME: { - - viewport->set_debug_draw(Viewport::DEBUG_DRAW_WIREFRAME); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); - - } break; - case VIEW_DISPLAY_OVERDRAW: { - - viewport->set_debug_draw(Viewport::DEBUG_DRAW_OVERDRAW); - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); - - } break; - case VIEW_DISPLAY_SHADELESS: { - - viewport->set_debug_draw(Viewport::DEBUG_DRAW_UNSHADED); - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), true); + case VIEW_DISPLAY_NORMAL: + case VIEW_DISPLAY_WIREFRAME: + case VIEW_DISPLAY_OVERDRAW: + case VIEW_DISPLAY_SHADELESS: + case VIEW_DISPLAY_LIGHTING: + case VIEW_DISPLAY_NORMAL_BUFFER: + case VIEW_DISPLAY_DEBUG_SHADOW_ATLAS: + case VIEW_DISPLAY_DEBUG_DIRECTIONAL_SHADOW_ATLAS: + case VIEW_DISPLAY_DEBUG_GIPROBE_ALBEDO: + case VIEW_DISPLAY_DEBUG_GIPROBE_LIGHTING: + case VIEW_DISPLAY_DEBUG_GIPROBE_EMISSION: + case VIEW_DISPLAY_DEBUG_SCENE_LUMINANCE: + case VIEW_DISPLAY_DEBUG_SSAO: + case VIEW_DISPLAY_DEBUG_ROUGHNESS_LIMITER: { + + static const int display_options[] = { + VIEW_DISPLAY_NORMAL, + VIEW_DISPLAY_WIREFRAME, + VIEW_DISPLAY_OVERDRAW, + VIEW_DISPLAY_SHADELESS, + VIEW_DISPLAY_LIGHTING, + VIEW_DISPLAY_NORMAL_BUFFER, + VIEW_DISPLAY_WIREFRAME, + VIEW_DISPLAY_DEBUG_SHADOW_ATLAS, + VIEW_DISPLAY_DEBUG_DIRECTIONAL_SHADOW_ATLAS, + VIEW_DISPLAY_DEBUG_GIPROBE_ALBEDO, + VIEW_DISPLAY_DEBUG_GIPROBE_LIGHTING, + VIEW_DISPLAY_DEBUG_GIPROBE_EMISSION, + VIEW_DISPLAY_DEBUG_SCENE_LUMINANCE, + VIEW_DISPLAY_DEBUG_SSAO, + VIEW_DISPLAY_DEBUG_ROUGHNESS_LIMITER, + VIEW_MAX + }; + static const Viewport::DebugDraw debug_draw_modes[] = { + Viewport::DEBUG_DRAW_DISABLED, + Viewport::DEBUG_DRAW_WIREFRAME, + Viewport::DEBUG_DRAW_OVERDRAW, + Viewport::DEBUG_DRAW_UNSHADED, + Viewport::DEBUG_DRAW_LIGHTING, + Viewport::DEBUG_DRAW_NORMAL_BUFFER, + Viewport::DEBUG_DRAW_WIREFRAME, + Viewport::DEBUG_DRAW_SHADOW_ATLAS, + Viewport::DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS, + Viewport::DEBUG_DRAW_GI_PROBE_ALBEDO, + Viewport::DEBUG_DRAW_GI_PROBE_LIGHTING, + Viewport::DEBUG_DRAW_GI_PROBE_EMISSION, + Viewport::DEBUG_DRAW_SCENE_LUMINANCE, + Viewport::DEBUG_DRAW_SSAO, + Viewport::DEBUG_DRAW_ROUGHNESS_LIMITER, + }; + + int idx = 0; + + while (display_options[idx] != VIEW_MAX) { + + int id = display_options[idx]; + int item_idx = view_menu->get_popup()->get_item_index(id); + if (item_idx != -1) { + view_menu->get_popup()->set_item_checked(item_idx, id == p_option); + } + item_idx = display_submenu->get_item_index(id); + if (item_idx != -1) { + display_submenu->set_item_checked(item_idx, id == p_option); + } + if (id == p_option) { + viewport->set_debug_draw(debug_draw_modes[idx]); + } + idx++; + } } break; } } @@ -2891,9 +2945,9 @@ void SpatialEditorViewport::_selection_result_pressed(int p_result) { clicked = selection_results[p_result].item->get_instance_id(); - if (clicked) { - _select_clicked(clicked_wants_append, true); - clicked = 0; + if (clicked.is_valid()) { + _select_clicked(clicked_wants_append, true, spatial_editor->get_tool_mode() != SpatialEditor::TOOL_MODE_LIST_SELECT); + clicked = ObjectID(); } } @@ -3527,7 +3581,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed editor_data = editor->get_scene_tree_dock()->get_editor_data(); editor_selection = editor->get_editor_selection(); undo_redo = editor->get_undo_redo(); - clicked = 0; + clicked_includes_current = false; orthogonal = false; lock_rotation = false; @@ -3569,6 +3623,9 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed vbox->add_child(view_menu); view_menu->set_h_size_flags(0); + display_submenu = memnew(PopupMenu); + view_menu->get_popup()->add_child(display_submenu); + view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/top_view"), VIEW_TOP); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/bottom_view"), VIEW_BOTTOM); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/left_view"), VIEW_LEFT); @@ -3585,8 +3642,25 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_normal", TTR("Display Normal")), VIEW_DISPLAY_NORMAL); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_wireframe", TTR("Display Wireframe")), VIEW_DISPLAY_WIREFRAME); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_overdraw", TTR("Display Overdraw")), VIEW_DISPLAY_OVERDRAW); + view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_lighting", TTR("Display Lighting")), VIEW_DISPLAY_LIGHTING); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_unshaded", TTR("Display Unshaded")), VIEW_DISPLAY_SHADELESS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), true); + display_submenu->add_radio_check_item(TTR("Normal Buffer"), VIEW_DISPLAY_NORMAL_BUFFER); + display_submenu->add_separator(); + display_submenu->add_radio_check_item(TTR("Shadow Atlas"), VIEW_DISPLAY_DEBUG_SHADOW_ATLAS); + display_submenu->add_radio_check_item(TTR("Directional Shadow"), VIEW_DISPLAY_DEBUG_DIRECTIONAL_SHADOW_ATLAS); + display_submenu->add_separator(); + display_submenu->add_radio_check_item(TTR("GIProbe Lighting"), VIEW_DISPLAY_DEBUG_GIPROBE_LIGHTING); + display_submenu->add_radio_check_item(TTR("GIProbe Albedo"), VIEW_DISPLAY_DEBUG_GIPROBE_ALBEDO); + display_submenu->add_radio_check_item(TTR("GIProbe Emission"), VIEW_DISPLAY_DEBUG_GIPROBE_EMISSION); + display_submenu->add_separator(); + display_submenu->add_radio_check_item(TTR("Scene Luminance"), VIEW_DISPLAY_DEBUG_SCENE_LUMINANCE); + display_submenu->add_separator(); + display_submenu->add_radio_check_item(TTR("SSAO"), VIEW_DISPLAY_DEBUG_SSAO); + display_submenu->add_separator(); + display_submenu->add_radio_check_item(TTR("Roughness Limiter"), VIEW_DISPLAY_DEBUG_ROUGHNESS_LIMITER); + display_submenu->set_name("display_advanced"); + view_menu->get_popup()->add_submenu_item(TTR("Display Advanced..."), "display_advanced"); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("View Gizmos")), VIEW_GIZMOS); @@ -3609,11 +3683,11 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/align_transform_with_view"), VIEW_ALIGN_TRANSFORM_WITH_VIEW); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/align_rotation_with_view"), VIEW_ALIGN_ROTATION_WITH_VIEW); view_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - + display_submenu->connect("id_pressed", this, "_menu_option"); view_menu->set_disable_shortcuts(true); if (OS::get_singleton()->get_current_video_driver() == OS::VIDEO_DRIVER_GLES2) { - // Alternate display modes only work when using the GLES3 renderer; make this explicit. + // Alternate display modes only work when using the Vulkan renderer; make this explicit. const int normal_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL); const int wireframe_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME); const int overdraw_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW); @@ -3816,12 +3890,12 @@ void SpatialEditorViewportContainer::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW && mouseover) { - Ref<Texture> h_grabber = get_icon("grabber", "HSplitContainer"); - Ref<Texture> v_grabber = get_icon("grabber", "VSplitContainer"); + Ref<Texture2D> h_grabber = get_icon("grabber", "HSplitContainer"); + Ref<Texture2D> v_grabber = get_icon("grabber", "VSplitContainer"); - Ref<Texture> hdiag_grabber = get_icon("GuiViewportHdiagsplitter", "EditorIcons"); - Ref<Texture> vdiag_grabber = get_icon("GuiViewportVdiagsplitter", "EditorIcons"); - Ref<Texture> vh_grabber = get_icon("GuiViewportVhsplitter", "EditorIcons"); + Ref<Texture2D> hdiag_grabber = get_icon("GuiViewportHdiagsplitter", "EditorIcons"); + Ref<Texture2D> vdiag_grabber = get_icon("GuiViewportVdiagsplitter", "EditorIcons"); + Ref<Texture2D> vh_grabber = get_icon("GuiViewportVhsplitter", "EditorIcons"); Vector2 size = get_size(); @@ -4173,12 +4247,12 @@ void SpatialEditor::_generate_selection_box() { st->add_vertex(b); } - Ref<SpatialMaterial> mat = memnew(SpatialMaterial); - mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D); + mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); mat->set_albedo(Color(1, 1, 1)); - mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); st->set_material(mat); selection_box = st->commit(); } @@ -4732,9 +4806,9 @@ void SpatialEditor::_init_indicators() { grid_enabled = true; indicator_mat.instance(); - indicator_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - indicator_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - indicator_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + indicator_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + indicator_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + indicator_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); Vector<Color> origin_colors; Vector<Vector3> origin_points; @@ -4817,14 +4891,14 @@ void SpatialEditor::_init_indicators() { scale_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); scale_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); - Ref<SpatialMaterial> mat = memnew(SpatialMaterial); - mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D); + mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); mat->set_on_top_of_alpha(); - mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); mat->set_albedo(col); gizmo_color[i] = mat; - Ref<SpatialMaterial> mat_hl = mat->duplicate(); + Ref<StandardMaterial3D> mat_hl = mat->duplicate(); mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); gizmo_color_hl[i] = mat_hl; @@ -4912,17 +4986,17 @@ void SpatialEditor::_init_indicators() { surftool->add_vertex(points[2]); surftool->add_vertex(points[3]); - Ref<SpatialMaterial> plane_mat = memnew(SpatialMaterial); - plane_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + Ref<StandardMaterial3D> plane_mat = memnew(StandardMaterial3D); + plane_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); plane_mat->set_on_top_of_alpha(); - plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); + plane_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + plane_mat->set_cull_mode(StandardMaterial3D::CULL_DISABLED); plane_mat->set_albedo(col); plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides surftool->set_material(plane_mat); surftool->commit(move_plane_gizmo[i]); - Ref<SpatialMaterial> plane_mat_hl = plane_mat->duplicate(); + Ref<StandardMaterial3D> plane_mat_hl = plane_mat->duplicate(); plane_mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides } @@ -5042,17 +5116,17 @@ void SpatialEditor::_init_indicators() { surftool->add_vertex(points[2]); surftool->add_vertex(points[3]); - Ref<SpatialMaterial> plane_mat = memnew(SpatialMaterial); - plane_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + Ref<StandardMaterial3D> plane_mat = memnew(StandardMaterial3D); + plane_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); plane_mat->set_on_top_of_alpha(); - plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); + plane_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + plane_mat->set_cull_mode(StandardMaterial3D::CULL_DISABLED); plane_mat->set_albedo(col); plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides surftool->set_material(plane_mat); surftool->commit(scale_plane_gizmo[i]); - Ref<SpatialMaterial> plane_mat_hl = plane_mat->duplicate(); + Ref<StandardMaterial3D> plane_mat_hl = plane_mat->duplicate(); plane_mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides } @@ -5566,7 +5640,7 @@ void SpatialEditor::_register_all_gizmos() { add_gizmo_plugin(Ref<CPUParticlesGizmoPlugin>(memnew(CPUParticlesGizmoPlugin))); add_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin))); add_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin))); - add_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin))); + // add_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin))); add_gizmo_plugin(Ref<CollisionShapeSpatialGizmoPlugin>(memnew(CollisionShapeSpatialGizmoPlugin))); add_gizmo_plugin(Ref<CollisionPolygonSpatialGizmoPlugin>(memnew(CollisionPolygonSpatialGizmoPlugin))); add_gizmo_plugin(Ref<NavigationMeshSpatialGizmoPlugin>(memnew(NavigationMeshSpatialGizmoPlugin))); @@ -6118,13 +6192,13 @@ void EditorSpatialGizmoPlugin::create_material(const String &p_name, const Color Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6)); - Vector<Ref<SpatialMaterial> > mats; + Vector<Ref<StandardMaterial3D> > mats; for (int i = 0; i < 4; i++) { bool selected = i % 2 == 1; bool instanced = i < 2; - Ref<SpatialMaterial> material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); + Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); Color color = instanced ? instanced_color : p_color; @@ -6133,17 +6207,17 @@ void EditorSpatialGizmoPlugin::create_material(const String &p_name, const Color } material->set_albedo(color); - material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - material->set_render_priority(SpatialMaterial::RENDER_PRIORITY_MIN + 1); + material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 1); if (p_use_vertex_color) { - material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); } if (p_billboard) { - material->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); + material->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); } if (p_on_top && selected) { @@ -6156,17 +6230,17 @@ void EditorSpatialGizmoPlugin::create_material(const String &p_name, const Color materials[p_name] = mats; } -void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top, const Color &p_albedo) { +void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top, const Color &p_albedo) { Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6)); - Vector<Ref<SpatialMaterial> > icons; + Vector<Ref<StandardMaterial3D> > icons; for (int i = 0; i < 4; i++) { bool selected = i % 2 == 1; bool instanced = i < 2; - Ref<SpatialMaterial> icon = Ref<SpatialMaterial>(memnew(SpatialMaterial)); + Ref<StandardMaterial3D> icon = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); Color color = instanced ? instanced_color : p_albedo; @@ -6176,16 +6250,16 @@ void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const icon->set_albedo(color); - icon->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - icon->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - icon->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); - icon->set_cull_mode(SpatialMaterial::CULL_DISABLED); - icon->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_DISABLED); - icon->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, p_texture); - icon->set_flag(SpatialMaterial::FLAG_FIXED_SIZE, true); - icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); - icon->set_render_priority(SpatialMaterial::RENDER_PRIORITY_MIN); + icon->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + icon->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + icon->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); + icon->set_cull_mode(StandardMaterial3D::CULL_DISABLED); + icon->set_depth_draw_mode(StandardMaterial3D::DEPTH_DRAW_DISABLED); + icon->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + icon->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, p_texture); + icon->set_flag(StandardMaterial3D::FLAG_FIXED_SIZE, true); + icon->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); + icon->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN); if (p_on_top && selected) { icon->set_on_top_of_alpha(); @@ -6198,46 +6272,46 @@ void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const } void EditorSpatialGizmoPlugin::create_handle_material(const String &p_name, bool p_billboard) { - Ref<SpatialMaterial> handle_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); + Ref<StandardMaterial3D> handle_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); - handle_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - handle_material->set_flag(SpatialMaterial::FLAG_USE_POINT_SIZE, true); - Ref<Texture> handle_t = SpatialEditor::get_singleton()->get_icon("Editor3DHandle", "EditorIcons"); + handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true); + Ref<Texture2D> handle_t = SpatialEditor::get_singleton()->get_icon("Editor3DHandle", "EditorIcons"); handle_material->set_point_size(handle_t->get_width()); - handle_material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, handle_t); + handle_material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, handle_t); handle_material->set_albedo(Color(1, 1, 1)); - handle_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - handle_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - handle_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + handle_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + handle_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); handle_material->set_on_top_of_alpha(); if (p_billboard) { - handle_material->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); + handle_material->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); handle_material->set_on_top_of_alpha(); } - materials[p_name] = Vector<Ref<SpatialMaterial> >(); + materials[p_name] = Vector<Ref<StandardMaterial3D> >(); materials[p_name].push_back(handle_material); } -void EditorSpatialGizmoPlugin::add_material(const String &p_name, Ref<SpatialMaterial> p_material) { - materials[p_name] = Vector<Ref<SpatialMaterial> >(); +void EditorSpatialGizmoPlugin::add_material(const String &p_name, Ref<StandardMaterial3D> p_material) { + materials[p_name] = Vector<Ref<StandardMaterial3D> >(); materials[p_name].push_back(p_material); } -Ref<SpatialMaterial> EditorSpatialGizmoPlugin::get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo) { - ERR_FAIL_COND_V(!materials.has(p_name), Ref<SpatialMaterial>()); - ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<SpatialMaterial>()); +Ref<StandardMaterial3D> EditorSpatialGizmoPlugin::get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo) { + ERR_FAIL_COND_V(!materials.has(p_name), Ref<StandardMaterial3D>()); + ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<StandardMaterial3D>()); if (p_gizmo.is_null() || materials[p_name].size() == 1) return materials[p_name][0]; int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0); - Ref<SpatialMaterial> mat = materials[p_name][index]; + Ref<StandardMaterial3D> mat = materials[p_name][index]; if (current_state == ON_TOP && p_gizmo->is_selected()) { - mat->set_flag(SpatialMaterial::FLAG_DISABLE_DEPTH_TEST, true); + mat->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true); } else { - mat->set_flag(SpatialMaterial::FLAG_DISABLE_DEPTH_TEST, false); + mat->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, false); } return mat; diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 5cc2b24cbb..a4d6b13389 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -167,8 +167,19 @@ class SpatialEditorViewport : public Control { VIEW_DISPLAY_WIREFRAME, VIEW_DISPLAY_OVERDRAW, VIEW_DISPLAY_SHADELESS, + VIEW_DISPLAY_LIGHTING, + VIEW_DISPLAY_NORMAL_BUFFER, + VIEW_DISPLAY_DEBUG_SHADOW_ATLAS, + VIEW_DISPLAY_DEBUG_DIRECTIONAL_SHADOW_ATLAS, + VIEW_DISPLAY_DEBUG_GIPROBE_ALBEDO, + VIEW_DISPLAY_DEBUG_GIPROBE_LIGHTING, + VIEW_DISPLAY_DEBUG_GIPROBE_EMISSION, + VIEW_DISPLAY_DEBUG_SCENE_LUMINANCE, + VIEW_DISPLAY_DEBUG_SSAO, + VIEW_DISPLAY_DEBUG_ROUGHNESS_LIMITER, VIEW_LOCK_ROTATION, - VIEW_CINEMATIC_PREVIEW + VIEW_CINEMATIC_PREVIEW, + VIEW_MAX }; public: @@ -205,6 +216,7 @@ private: ViewportContainer *viewport_container; MenuButton *view_menu; + PopupMenu *display_submenu; Control *surface; Viewport *viewport; @@ -234,7 +246,7 @@ private: void _update_name(); void _compute_edit(const Point2 &p_point); void _clear_selected(); - void _select_clicked(bool p_append, bool p_single); + void _select_clicked(bool p_append, bool p_single, bool p_allow_locked = false); void _select(Node *p_node, bool p_append, bool p_single); ObjectID _select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle = NULL, bool p_alt_select = false); void _find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select = false); @@ -527,10 +539,10 @@ private: bool grid_enabled; Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[3], scale_gizmo[3], scale_plane_gizmo[3]; - Ref<SpatialMaterial> gizmo_color[3]; - Ref<SpatialMaterial> plane_gizmo_color[3]; - Ref<SpatialMaterial> gizmo_color_hl[3]; - Ref<SpatialMaterial> plane_gizmo_color_hl[3]; + Ref<StandardMaterial3D> gizmo_color[3]; + Ref<StandardMaterial3D> plane_gizmo_color[3]; + Ref<StandardMaterial3D> gizmo_color_hl[3]; + Ref<StandardMaterial3D> plane_gizmo_color_hl[3]; int over_gizmo_handle; @@ -539,8 +551,8 @@ private: RID indicators_instance; RID cursor_mesh; RID cursor_instance; - Ref<SpatialMaterial> indicator_mat; - Ref<SpatialMaterial> cursor_material; + Ref<StandardMaterial3D> indicator_mat; + Ref<StandardMaterial3D> cursor_material; // Scene drag and drop support Spatial *preview_node; @@ -776,7 +788,7 @@ public: private: int current_state; List<EditorSpatialGizmo *> current_gizmos; - HashMap<String, Vector<Ref<SpatialMaterial> > > materials; + HashMap<String, Vector<Ref<StandardMaterial3D> > > materials; protected: static void _bind_methods(); @@ -785,11 +797,11 @@ protected: public: void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false); - void create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1)); + void create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1)); void create_handle_material(const String &p_name, bool p_billboard = false); - void add_material(const String &p_name, Ref<SpatialMaterial> p_material); + void add_material(const String &p_name, Ref<StandardMaterial3D> p_material); - Ref<SpatialMaterial> get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo = Ref<EditorSpatialGizmo>()); + Ref<StandardMaterial3D> get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo = Ref<EditorSpatialGizmo>()); virtual String get_name() const; virtual int get_priority() const; diff --git a/editor/plugins/sprite_editor_plugin.cpp b/editor/plugins/sprite_editor_plugin.cpp index 6757b180a3..2736bbfd3a 100644 --- a/editor/plugins/sprite_editor_plugin.cpp +++ b/editor/plugins/sprite_editor_plugin.cpp @@ -167,7 +167,7 @@ void SpriteEditor::_menu_option(int p_option) { void SpriteEditor::_update_mesh_data() { - Ref<Texture> texture = node->get_texture(); + Ref<Texture2D> texture = node->get_texture(); if (texture.is_null()) { err_dialog->set_text(TTR("Sprite is empty!")); err_dialog->popup_centered_minsize(); @@ -330,7 +330,7 @@ void SpriteEditor::_convert_to_mesh_2d_node() { a[Mesh::ARRAY_TEX_UV] = computed_uv; a[Mesh::ARRAY_INDEX] = computed_indices; - mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a, Array(), Mesh::ARRAY_FLAG_USE_2D_VERTICES); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a, Array(), Dictionary(), Mesh::ARRAY_FLAG_USE_2D_VERTICES); MeshInstance2D *mesh_instance = memnew(MeshInstance2D); mesh_instance->set_mesh(mesh); @@ -476,7 +476,7 @@ void SpriteEditor::_add_as_sibling_or_child(Node *p_own_node, Node *p_new_node) void SpriteEditor::_debug_uv_draw() { - Ref<Texture> tex = node->get_texture(); + Ref<Texture2D> tex = node->get_texture(); ERR_FAIL_COND(!tex.is_valid()); Point2 draw_pos_offset = Point2(1.0, 1.0); diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 4101980e29..2d756af213 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -44,7 +44,7 @@ void SpriteFramesEditor::_open_sprite_sheet() { file_split_sheet->clear_filters(); List<String> extensions; - ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions); + ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); for (int i = 0; i < extensions.size(); i++) { file_split_sheet->add_filter("*." + extensions[i]); } @@ -249,11 +249,11 @@ void SpriteFramesEditor::_file_load_request(const PoolVector<String> &p_path, in ERR_FAIL_COND(!frames->has_animation(edited_anim)); - List<Ref<Texture> > resources; + List<Ref<Texture2D> > resources; for (int i = 0; i < p_path.size(); i++) { - Ref<Texture> resource; + Ref<Texture2D> resource; resource = ResourceLoader::load(p_path[i]); if (resource.is_null()) { @@ -278,7 +278,7 @@ void SpriteFramesEditor::_file_load_request(const PoolVector<String> &p_path, in int count = 0; - for (List<Ref<Texture> >::Element *E = resources.front(); E; E = E->next()) { + for (List<Ref<Texture2D> >::Element *E = resources.front(); E; E = E->next()) { undo_redo->add_do_method(frames, "add_frame", edited_anim, E->get(), p_at_pos == -1 ? -1 : p_at_pos + count); undo_redo->add_undo_method(frames, "remove_frame", edited_anim, p_at_pos == -1 ? fc : p_at_pos); @@ -297,7 +297,7 @@ void SpriteFramesEditor::_load_pressed() { file->clear_filters(); List<String> extensions; - ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions); + ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); for (int i = 0; i < extensions.size(); i++) file->add_filter("*." + extensions[i]); @@ -310,7 +310,7 @@ void SpriteFramesEditor::_paste_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - Ref<Texture> r = EditorSettings::get_singleton()->get_resource_clipboard(); + Ref<Texture2D> r = EditorSettings::get_singleton()->get_resource_clipboard(); if (!r.is_valid()) { dialog->set_text(TTR("Resource clipboard is empty or not a texture!")); dialog->set_title(TTR("Error!")); @@ -333,7 +333,7 @@ void SpriteFramesEditor::_copy_pressed() { if (tree->get_current() < 0) return; - Ref<Texture> r = frames->get_frame(edited_anim, tree->get_current()); + Ref<Texture2D> r = frames->get_frame(edited_anim, tree->get_current()); if (!r.is_valid()) { return; } @@ -356,7 +356,7 @@ void SpriteFramesEditor::_empty_pressed() { from = frames->get_frame_count(edited_anim); } - Ref<Texture> r; + Ref<Texture2D> r; undo_redo->create_action(TTR("Add Empty")); undo_redo->add_do_method(frames, "add_frame", edited_anim, r, from); @@ -381,7 +381,7 @@ void SpriteFramesEditor::_empty2_pressed() { from = frames->get_frame_count(edited_anim); } - Ref<Texture> r; + Ref<Texture2D> r; undo_redo->create_action(TTR("Add Empty")); undo_redo->add_do_method(frames, "add_frame", edited_anim, r, from + 1); @@ -603,7 +603,7 @@ void SpriteFramesEditor::_animation_remove_confirmed() { undo_redo->add_undo_method(frames, "set_animation_loop", edited_anim, frames->get_animation_loop(edited_anim)); int fc = frames->get_frame_count(edited_anim); for (int i = 0; i < fc; i++) { - Ref<Texture> frame = frames->get_frame(edited_anim, i); + Ref<Texture2D> frame = frames->get_frame(edited_anim, i); undo_redo->add_undo_method(frames, "add_frame", edited_anim, frame); } undo_redo->add_do_method(this, "_update_library"); @@ -688,7 +688,7 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { for (int i = 0; i < frames->get_frame_count(edited_anim); i++) { String name; - Ref<Texture> icon; + Ref<Texture2D> icon; if (frames->get_frame(edited_anim, i).is_null()) { @@ -775,7 +775,7 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; - Ref<Texture> texture = r; + Ref<Texture2D> texture = r; if (texture.is_valid()) { @@ -794,7 +794,7 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant & String file = files[i]; String ftype = EditorFileSystem::get_singleton()->get_file_type(file); - if (!ClassDB::is_parent_class(ftype, "Texture")) { + if (!ClassDB::is_parent_class(ftype, "Texture2D")) { return false; } } @@ -819,7 +819,7 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; - Ref<Texture> texture = r; + Ref<Texture2D> texture = r; if (texture.is_valid()) { bool reorder = false; diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 57447abf47..69f1bcfa2e 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -163,7 +163,7 @@ String TextEditor::get_name() { return name; } -Ref<Texture> TextEditor::get_icon() { +Ref<Texture2D> TextEditor::get_icon() { return EditorNode::get_singleton()->get_object_icon(text_file.operator->(), ""); } @@ -491,6 +491,12 @@ void TextEditor::_edit_option(int p_op) { // So this will be delegated to the ScriptEditor. emit_signal("search_in_files_requested", selected_text); } break; + case REPLACE_IN_FILES: { + + String selected_text = code_editor->get_text_edit()->get_selection_text(); + + emit_signal("replace_in_files_requested", selected_text); + } break; case SEARCH_GOTO_LINE: { goto_line_dialog->popup_find_line(tx); @@ -655,6 +661,7 @@ TextEditor::TextEditor() { search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE); search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES); + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace_in_files"), REPLACE_IN_FILES); edit_menu = memnew(MenuButton); edit_hb->add_child(edit_menu); diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index fe157a29e6..c976cd87f1 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -88,6 +88,7 @@ private: SEARCH_FIND_PREV, SEARCH_REPLACE, SEARCH_IN_FILES, + REPLACE_IN_FILES, SEARCH_GOTO_LINE, BOOKMARK_TOGGLE, BOOKMARK_GOTO_NEXT, @@ -120,7 +121,7 @@ public: virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter); virtual String get_name(); - virtual Ref<Texture> get_icon(); + virtual Ref<Texture2D> get_icon(); virtual RES get_edited_resource() const; virtual void set_edited_resource(const RES &p_res); void set_edited_file(const Ref<TextFile> &p_file); diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 9489836984..60f9bb5dc1 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -46,7 +46,7 @@ void TextureEditor::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<Texture> checkerboard = get_icon("Checkerboard", "EditorIcons"); + Ref<Texture2D> checkerboard = get_icon("Checkerboard", "EditorIcons"); Size2 size = get_size(); draw_texture_rect(checkerboard, Rect2(Point2(), size), true); @@ -110,7 +110,7 @@ void TextureEditor::_changed_callback(Object *p_changed, const char *p_prop) { update(); } -void TextureEditor::edit(Ref<Texture> p_texture) { +void TextureEditor::edit(Ref<Texture2D> p_texture) { if (!texture.is_null()) texture->remove_change_receptor(this); @@ -132,6 +132,7 @@ void TextureEditor::_bind_methods() { TextureEditor::TextureEditor() { + set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED); set_custom_minimum_size(Size2(1, 150)); } @@ -148,11 +149,11 @@ bool EditorInspectorPluginTexture::can_handle(Object *p_object) { void EditorInspectorPluginTexture::parse_begin(Object *p_object) { - Texture *texture = Object::cast_to<Texture>(p_object); + Texture2D *texture = Object::cast_to<Texture2D>(p_object); if (!texture) { return; } - Ref<Texture> m(texture); + Ref<Texture2D> m(texture); TextureEditor *editor = memnew(TextureEditor); editor->edit(m); diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h index f587579902..29ad0183dc 100644 --- a/editor/plugins/texture_editor_plugin.h +++ b/editor/plugins/texture_editor_plugin.h @@ -39,7 +39,7 @@ class TextureEditor : public Control { GDCLASS(TextureEditor, Control); - Ref<Texture> texture; + Ref<Texture2D> texture; protected: void _notification(int p_what); @@ -48,7 +48,7 @@ protected: static void _bind_methods(); public: - void edit(Ref<Texture> p_texture); + void edit(Ref<Texture2D> p_texture); TextureEditor(); ~TextureEditor(); }; @@ -66,7 +66,7 @@ class TextureEditorPlugin : public EditorPlugin { GDCLASS(TextureEditorPlugin, EditorPlugin); public: - virtual String get_name() const { return "Texture"; } + virtual String get_name() const { return "Texture2D"; } TextureEditorPlugin(EditorNode *p_node); }; diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 507ea0b83d..2350c20cb7 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -49,7 +49,7 @@ void draw_margin_line(Control *edit_draw, Vector2 from, Vector2 to) { } void TextureRegionEditor::_region_draw() { - Ref<Texture> base_tex = NULL; + Ref<Texture2D> base_tex = NULL; if (node_sprite) base_tex = node_sprite->get_texture(); else if (node_sprite_3d) @@ -134,7 +134,7 @@ void TextureRegionEditor::_region_draw() { } } - Ref<Texture> select_handle = get_icon("EditorHandle", "EditorIcons"); + Ref<Texture2D> select_handle = get_icon("EditorHandle", "EditorIcons"); Rect2 scroll_rect(Point2(), base_tex->get_size()); @@ -546,6 +546,17 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { edit_draw->update(); } } + + Ref<InputEventMagnifyGesture> magnify_gesture = p_input; + if (magnify_gesture.is_valid()) { + _zoom_on_position(draw_zoom * magnify_gesture->get_factor(), magnify_gesture->get_position()); + } + + Ref<InputEventPanGesture> pan_gesture = p_input; + if (pan_gesture.is_valid()) { + hscroll->set_value(hscroll->get_value() + hscroll->get_page() * pan_gesture->get_delta().x / 8); + vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y / 8); + } } void TextureRegionEditor::_scroll_changed(float) { @@ -661,7 +672,7 @@ void TextureRegionEditor::_update_autoslice() { autoslice_is_dirty = false; autoslice_cache.clear(); - Ref<Texture> texture = NULL; + Ref<Texture2D> texture = NULL; if (node_sprite) texture = node_sprite->get_texture(); else if (node_sprite_3d) @@ -852,7 +863,7 @@ void TextureRegionEditor::_changed_callback(Object *p_changed, const char *p_pro } void TextureRegionEditor::_edit_region() { - Ref<Texture> texture = NULL; + Ref<Texture2D> texture = NULL; if (node_sprite) texture = node_sprite->get_texture(); else if (node_sprite_3d) diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 22105f7ed4..48d80a0017 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -122,7 +122,7 @@ struct _TECategory { Set<RefItem<StyleBox> > stylebox_items; Set<RefItem<Font> > font_items; - Set<RefItem<Texture> > icon_items; + Set<RefItem<Texture2D> > icon_items; Set<Item<Color> > color_items; Set<Item<int> > constant_items; @@ -167,7 +167,7 @@ void ThemeEditor::_save_template_cbk(String fname) { List<StringName> icon_list; Theme::get_default()->get_icon_list(E->key(), &icon_list); for (List<StringName>::Element *F = icon_list.front(); F; F = F->next()) { - _TECategory::RefItem<Texture> it; + _TECategory::RefItem<Texture2D> it; it.name = F->get(); it.item = Theme::get_default()->get_icon(F->get(), E->key()); tc.icon_items.insert(it); @@ -291,7 +291,7 @@ void ThemeEditor::_save_template_cbk(String fname) { if (tc.icon_items.size()) file->store_line("\n; Icon Items:\n"); - for (Set<_TECategory::RefItem<Texture> >::Element *F = tc.icon_items.front(); F; F = F->next()) { + for (Set<_TECategory::RefItem<Texture2D> >::Element *F = tc.icon_items.front(); F; F = F->next()) { file->store_line(E->key() + "." + F->get().name + " = default"); } @@ -324,7 +324,7 @@ void ThemeEditor::_dialog_cbk() { switch (type_select->get_selected()) { - case 0: theme->set_icon(name_edit->get_text(), type_edit->get_text(), Ref<Texture>()); break; + case 0: theme->set_icon(name_edit->get_text(), type_edit->get_text(), Ref<Texture2D>()); break; case 1: theme->set_stylebox(name_edit->get_text(), type_edit->get_text(), Ref<StyleBox>()); break; case 2: theme->set_font(name_edit->get_text(), type_edit->get_text(), Ref<Font>()); break; case 3: theme->set_color(name_edit->get_text(), type_edit->get_text(), Color()); break; @@ -341,7 +341,7 @@ void ThemeEditor::_dialog_cbk() { names.clear(); Theme::get_default()->get_icon_list(fromtype, &names); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - theme->set_icon(E->get(), fromtype, Ref<Texture>()); + theme->set_icon(E->get(), fromtype, Ref<Texture2D>()); } } { @@ -454,7 +454,7 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { base_theme->get_icon_list(type, &icons); for (List<StringName>::Element *E = icons.front(); E; E = E->next()) { - theme->set_icon(E->get(), type, import ? base_theme->get_icon(E->get(), type) : Ref<Texture>()); + theme->set_icon(E->get(), type, import ? base_theme->get_icon(E->get(), type) : Ref<Texture2D>()); } List<StringName> shaders; diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index f889228f87..425a759dac 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -468,7 +468,7 @@ void TileMapEditor::_update_palette() { palette->add_item(String()); } - Ref<Texture> tex = tileset->tile_get_texture(entries[i].id); + Ref<Texture2D> tex = tileset->tile_get_texture(entries[i].id); if (tex.is_valid()) { Rect2 region = tileset->tile_get_region(entries[i].id); @@ -528,7 +528,7 @@ void TileMapEditor::_update_palette() { }; entries2.sort_custom<SwapComparator>(); - Ref<Texture> tex = tileset->tile_get_texture(sel_tile); + Ref<Texture2D> tex = tileset->tile_get_texture(sel_tile); for (int i = 0; i < entries2.size(); i++) { @@ -761,7 +761,7 @@ void TileMapEditor::_erase_selection() { void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord, const Transform2D &p_xform) { - Ref<Texture> t = node->get_tileset()->tile_get_texture(p_cell); + Ref<Texture2D> t = node->get_tileset()->tile_get_texture(p_cell); if (t.is_null()) return; @@ -2026,13 +2026,13 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { toolbar->add_child(bucket_fill_button); picker_button = memnew(ToolButton); - picker_button->set_shortcut(ED_SHORTCUT("tile_map_editor/pick_tile", TTR("Pick Tile"), KEY_CONTROL)); + picker_button->set_shortcut(ED_SHORTCUT("tile_map_editor/pick_tile", TTR("Pick Tile"), KEY_I)); picker_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_PICKING)); picker_button->set_toggle_mode(true); toolbar->add_child(picker_button); select_button = memnew(ToolButton); - select_button->set_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_MASK_CMD + KEY_B)); + select_button->set_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_M)); select_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_SELECTING)); select_button->set_toggle_mode(true); toolbar->add_child(select_button); diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index b24d5add9f..ce865510b4 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -62,8 +62,8 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) { } Sprite *mi = Object::cast_to<Sprite>(child); - Ref<Texture> texture = mi->get_texture(); - Ref<Texture> normal_map = mi->get_normal_map(); + Ref<Texture2D> texture = mi->get_texture(); + Ref<Texture2D> normal_map = mi->get_normal_map(); Ref<ShaderMaterial> material = mi->get_material(); if (texture.is_null()) @@ -195,7 +195,7 @@ bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_dat if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; - Ref<Texture> texture = r; + Ref<Texture2D> texture = r; if (texture.is_valid()) { @@ -237,7 +237,7 @@ void TileSetEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, C if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; - Ref<Texture> texture = r; + Ref<Texture2D> texture = r; if (texture.is_valid()) add_texture(texture); @@ -639,7 +639,7 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { texture_dialog->clear_filters(); List<String> extensions; - ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions); + ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { texture_dialog->add_filter("*." + E->get() + " ; " + E->get().to_upper()); @@ -753,7 +753,7 @@ void TileSetEditor::_on_texture_list_selected(int p_index) { void TileSetEditor::_on_textures_added(const PoolStringArray &p_paths) { int invalid_count = 0; for (int i = 0; i < p_paths.size(); i++) { - Ref<Texture> t = Ref<Texture>(ResourceLoader::load(p_paths[i])); + Ref<Texture2D> t = Ref<Texture2D>(ResourceLoader::load(p_paths[i])); ERR_CONTINUE_MSG(!t.is_valid(), "'" + p_paths[i] + "' is not a valid texture."); @@ -1183,7 +1183,7 @@ void TileSetEditor::_on_workspace_overlay_draw() { if (t_id < 0) return; - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); + Ref<Texture2D> handle = get_icon("EditorHandle", "EditorIcons"); if (draw_handles) { for (int i = 0; i < current_shape.size(); i++) { workspace_overlay->draw_texture(handle, current_shape[i] * workspace->get_scale().x - handle->get_size() * 0.5); @@ -1794,13 +1794,13 @@ void TileSetEditor::_on_tool_clicked(int p_tool) { Array sd = tileset->call("tile_get_shapes", get_current_tile()); if (convex.is_valid()) { - // Make concave + // Make concave. undo_redo->create_action(TTR("Make Polygon Concave")); Ref<ConcavePolygonShape2D> _concave = memnew(ConcavePolygonShape2D); edited_collision_shape = _concave; _set_edited_shape_points(_get_collision_shape_points(convex)); } else if (concave.is_valid()) { - // Make convex + // Make convex. undo_redo->create_action(TTR("Make Polygon Convex")); Ref<ConvexPolygonShape2D> _convex = memnew(ConvexPolygonShape2D); edited_collision_shape = _convex; @@ -1810,14 +1810,20 @@ void TileSetEditor::_on_tool_clicked(int p_tool) { if (sd[i].get("shape") == previous_shape) { undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.duplicate()); sd.remove(i); - sd.insert(i, edited_collision_shape); - undo_redo->add_do_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd); - undo_redo->add_do_method(this, "_select_edited_shape_coord"); - undo_redo->add_undo_method(this, "_select_edited_shape_coord"); - undo_redo->commit_action(); break; } } + + undo_redo->add_do_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd); + if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) { + undo_redo->add_do_method(tileset.ptr(), "tile_add_shape", get_current_tile(), edited_collision_shape, Transform2D(), false, edited_shape_coord); + } else { + undo_redo->add_do_method(tileset.ptr(), "tile_add_shape", get_current_tile(), edited_collision_shape, Transform2D()); + } + undo_redo->add_do_method(this, "_select_edited_shape_coord"); + undo_redo->add_undo_method(this, "_select_edited_shape_coord"); + undo_redo->commit_action(); + _update_toggle_shape_button(); workspace->update(); workspace_container->update(); @@ -1984,11 +1990,8 @@ void TileSetEditor::_set_edited_shape_points(const Vector<Vector2> &points) { } segments.push_back(points[points.size() - 1]); segments.push_back(points[0]); - concave->set_segments(segments); undo_redo->add_do_method(concave.ptr(), "set_segments", segments); undo_redo->add_undo_method(concave.ptr(), "set_segments", concave->get_segments()); - } else { - // Invalid shape } } @@ -2662,9 +2665,9 @@ void TileSetEditor::draw_polygon_shapes() { if (coord == edited_shape_coord || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) { if (!creating_shape) { for (int j = 0; j < polygon.size() - 1; j++) { - workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1, true); + workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1); } - workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1, true); + workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1); } if (shape == edited_collision_shape) { draw_handles = true; @@ -2700,9 +2703,9 @@ void TileSetEditor::draw_polygon_shapes() { if (!creating_shape) { if (polygon.size() > 1) { for (int j = 0; j < polygon.size() - 1; j++) { - workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1, true); + workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1); } - workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1, true); + workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1); } } if (shape == edited_occlusion_shape) { @@ -2749,9 +2752,9 @@ void TileSetEditor::draw_polygon_shapes() { if (coord == edited_shape_coord) { if (!creating_shape) { for (int j = 0; j < polygon.size() - 1; j++) { - workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1, true); + workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1); } - workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1, true); + workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1); } if (shape == edited_occlusion_shape) { draw_handles = true; @@ -2789,9 +2792,9 @@ void TileSetEditor::draw_polygon_shapes() { if (!creating_shape) { for (int j = 0; j < polygon.size() - 1; j++) { - workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1, true); + workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1); } - workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1, true); + workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1); } if (shape == edited_navigation_shape) { draw_handles = true; @@ -2838,9 +2841,9 @@ void TileSetEditor::draw_polygon_shapes() { if (coord == edited_shape_coord) { if (!creating_shape) { for (int j = 0; j < polygon.size() - 1; j++) { - workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1, true); + workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1); } - workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1, true); + workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1); } if (shape == edited_navigation_shape) { draw_handles = true; @@ -2856,9 +2859,9 @@ void TileSetEditor::draw_polygon_shapes() { if (creating_shape) { for (int j = 0; j < current_shape.size() - 1; j++) { - workspace->draw_line(current_shape[j], current_shape[j + 1], Color(0, 1, 1), 1, true); + workspace->draw_line(current_shape[j], current_shape[j + 1], Color(0, 1, 1), 1); } - workspace->draw_line(current_shape[current_shape.size() - 1], snap_point(workspace->get_local_mouse_position()), Color(0, 1, 1), 1, true); + workspace->draw_line(current_shape[current_shape.size() - 1], snap_point(workspace->get_local_mouse_position()), Color(0, 1, 1), 1); draw_handles = true; } } @@ -3098,13 +3101,13 @@ Vector2 TileSetEditor::snap_point(const Vector2 &point) { return p; } -void TileSetEditor::add_texture(Ref<Texture> p_texture) { +void TileSetEditor::add_texture(Ref<Texture2D> p_texture) { texture_list->add_item(p_texture->get_path().get_file()); texture_map.insert(p_texture->get_rid(), p_texture); texture_list->set_item_metadata(texture_list->get_item_count() - 1, p_texture->get_rid()); } -void TileSetEditor::remove_texture(Ref<Texture> p_texture) { +void TileSetEditor::remove_texture(Ref<Texture2D> p_texture) { texture_list->remove_item(texture_list->find_metadata(p_texture->get_rid())); texture_map.erase(p_texture->get_rid()); @@ -3117,7 +3120,7 @@ void TileSetEditor::remove_texture(Ref<Texture> p_texture) { } void TileSetEditor::update_texture_list() { - Ref<Texture> selected_texture = get_current_texture(); + Ref<Texture2D> selected_texture = get_current_texture(); helper->set_tileset(tileset); @@ -3326,9 +3329,9 @@ void TileSetEditor::set_current_tile(int p_id) { } } -Ref<Texture> TileSetEditor::get_current_texture() { +Ref<Texture2D> TileSetEditor::get_current_texture() { if (texture_list->get_selected_items().size() == 0) - return Ref<Texture>(); + return Ref<Texture2D>(); else return texture_map[texture_list->get_item_metadata(texture_list->get_selected_items()[0])]; } @@ -3487,7 +3490,7 @@ void TilesetEditorContext::_get_property_list(List<PropertyInfo> *p_list) const int id = tileset_editor->get_current_tile(); p_list->push_back(PropertyInfo(Variant::NIL, "Selected Tile", PROPERTY_HINT_NONE, "tile_", PROPERTY_USAGE_GROUP)); p_list->push_back(PropertyInfo(Variant::STRING, "tile_name")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D")); p_list->push_back(PropertyInfo(Variant::VECTOR2, "tile_tex_offset")); p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial")); p_list->push_back(PropertyInfo(Variant::COLOR, "tile_modulate")); diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h index 0e0bd6448c..26340824a0 100644 --- a/editor/plugins/tile_set_editor_plugin.h +++ b/editor/plugins/tile_set_editor_plugin.h @@ -114,7 +114,7 @@ class TileSetEditor : public HSplitContainer { int option; ToolButton *tileset_toolbar_buttons[TOOL_TILESET_MAX]; MenuButton *tileset_toolbar_tools; - Map<RID, Ref<Texture> > texture_map; + Map<RID, Ref<Texture2D> > texture_map; bool creating_shape; int dragging_point; @@ -165,10 +165,10 @@ class TileSetEditor : public HSplitContainer { void update_texture_list(); void update_texture_list_icon(); - void add_texture(Ref<Texture> p_texture); - void remove_texture(Ref<Texture> p_texture); + void add_texture(Ref<Texture2D> p_texture); + void remove_texture(Ref<Texture2D> p_texture); - Ref<Texture> get_current_texture(); + Ref<Texture2D> get_current_texture(); static void _import_node(Node *p_node, Ref<TileSet> p_library); static void _import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge); diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index c53fc7e6c5..e17e6a9d16 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -124,7 +124,7 @@ void VersionControlEditorPlugin::_initialize_vcs() { ERR_FAIL_COND_MSG(!addon_script_instance, "Failed to create addon script instance."); // The addon is attached as a script to the VCS interface as a proxy end-point - vcs_interface->set_script_and_instance(script.get_ref_ptr(), addon_script_instance); + vcs_interface->set_script_and_instance(script, addon_script_instance); EditorVCSInterface::set_singleton(vcs_interface); EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_refresh_stage_area"); @@ -203,7 +203,7 @@ void VersionControlEditorPlugin::_refresh_stage_area() { } } else { - WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu.") + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu."); } } diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index e334d4b093..ecc140d7d2 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -116,7 +116,7 @@ void VisualShaderEditor::clear_custom_types() { } } -void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, const String &p_subcategory) { +void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, const String &p_subcategory, bool p_highend) { ERR_FAIL_COND(!p_name.is_valid_identifier()); ERR_FAIL_COND(!p_script.is_valid()); @@ -135,6 +135,7 @@ void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> ao.description = p_description; ao.category = p_category; ao.sub_category = p_subcategory; + ao.highend = p_highend; ao.is_custom = true; bool begin = false; @@ -215,7 +216,7 @@ void VisualShaderEditor::update_custom_nodes() { Ref<VisualShaderNodeCustom> ref; ref.instance(); - ref->set_script(script.get_ref_ptr()); + ref->set_script(script); String name; if (ref->has_method("_get_name")) { @@ -247,6 +248,11 @@ void VisualShaderEditor::update_custom_nodes() { subcategory = (String)ref->call("_get_subcategory"); } + bool highend = false; + if (ref->has_method("_is_highend")) { + highend = (bool)ref->call("_is_highend"); + } + Dictionary dict; dict["name"] = name; dict["script"] = script; @@ -254,6 +260,7 @@ void VisualShaderEditor::update_custom_nodes() { dict["return_icon_type"] = return_icon_type; dict["category"] = category; dict["subcategory"] = subcategory; + dict["highend"] = highend; String key; key = category; @@ -277,18 +284,14 @@ void VisualShaderEditor::update_custom_nodes() { const Dictionary &value = (Dictionary)added[key]; - add_custom_type(value["name"], value["script"], value["description"], value["return_icon_type"], value["category"], value["subcategory"]); + add_custom_type(value["name"], value["script"], value["description"], value["return_icon_type"], value["category"], value["subcategory"], value["highend"]); } _update_options_menu(); } String VisualShaderEditor::_get_description(int p_idx) { - if (add_options[p_idx].highend) { - return TTR("(GLES3 only)") + " " + add_options[p_idx].description; // TODO: change it to (Vulkan Only) when its ready - } else { - return add_options[p_idx].description; - } + return add_options[p_idx].description; } void VisualShaderEditor::_update_options_menu() { @@ -556,6 +559,7 @@ void VisualShaderEditor::_update_graph() { } Ref<VisualShaderNodeUniform> uniform = vsnode; + Ref<VisualShaderNodeScalarUniform> scalar_uniform = vsnode; if (uniform.is_valid()) { graph->add_child(node); _update_created_node(node); @@ -570,7 +574,9 @@ void VisualShaderEditor::_update_graph() { //shortcut VisualShaderNode::PortType port_right = vsnode->get_output_port_type(0); node->set_slot(0, false, VisualShaderNode::PORT_TYPE_SCALAR, Color(), true, port_right, type_color[port_right]); - continue; + if (!scalar_uniform.is_valid()) { + continue; + } } port_offset++; } @@ -582,11 +588,16 @@ void VisualShaderEditor::_update_graph() { } } - if (custom_editor && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) { + if (custom_editor && !scalar_uniform.is_valid() && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) { //will be embedded in first port } else if (custom_editor) { + port_offset++; node->add_child(custom_editor); + if (scalar_uniform.is_valid()) { + custom_editor->call_deferred("_show_prop_names", true); + continue; + } custom_editor = NULL; } @@ -1404,7 +1415,7 @@ VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(base_type)); ERR_FAIL_COND_V(!vsn, NULL); vsnode = Ref<VisualShaderNode>(vsn); - vsnode->set_script(add_options[p_idx].script.get_ref_ptr()); + vsnode->set_script(add_options[p_idx].script); } Point2 position = graph->get_scroll_ofs(); @@ -1672,6 +1683,8 @@ void VisualShaderEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + highend_label->set_modulate(get_color("vulkan_color", "Editor")); + error_panel->add_style_override("panel", get_stylebox("bg", "Tree")); error_label->add_color_override("font_color", get_color("error_color", "Editor")); @@ -2029,8 +2042,10 @@ void VisualShaderEditor::_member_selected() { if (item != NULL && item->has_meta("id")) { members_dialog->get_ok()->set_disabled(false); + highend_label->set_visible(add_options[item->get_meta("id")].highend); node_desc->set_text(_get_description(item->get_meta("id"))); } else { + highend_label->set_visible(false); members_dialog->get_ok()->set_disabled(true); node_desc->set_text(""); } @@ -2164,7 +2179,7 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da _add_custom_node(arr[i]); j++; } - } else if (ClassDB::get_parent_class(type) == "Texture") { + } else if (ClassDB::get_parent_class(type) == "Texture2D") { saved_node_pos = p_point + Vector2(0, j * 210 * EDSCALE); saved_node_pos_dirty = true; _add_texture_node(arr[i]); @@ -2417,10 +2432,22 @@ VisualShaderEditor::VisualShaderEditor() { members->connect("item_selected", this, "_member_selected"); members->connect("nothing_selected", this, "_member_unselected"); + HBoxContainer *desc_hbox = memnew(HBoxContainer); + members_vb->add_child(desc_hbox); + Label *desc_label = memnew(Label); - members_vb->add_child(desc_label); + desc_hbox->add_child(desc_label); desc_label->set_text(TTR("Description:")); + desc_hbox->add_spacer(); + + highend_label = memnew(Label); + desc_hbox->add_child(highend_label); + highend_label->set_visible(false); + highend_label->set_text("Vulkan"); + highend_label->set_mouse_filter(Control::MOUSE_FILTER_STOP); + highend_label->set_tooltip(TTR("High-end node")); + node_desc = memnew(RichTextLabel); members_vb->add_child(node_desc); node_desc->set_h_size_flags(SIZE_EXPAND_FILL); @@ -2683,11 +2710,10 @@ VisualShaderEditor::VisualShaderEditor() { // TEXTURES - add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubeMap", TTR("Perform the cubic texture lookup."), -1, -1)); + add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), -1, -1)); texture_node_option_idx = add_options.size(); - add_options.push_back(AddOption("Texture", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, -1)); - - add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubeMapUniform", TTR("Cubic texture uniform lookup."), -1, -1)); + add_options.push_back(AddOption("Texture2D", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, -1)); + add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubemapUniform", TTR("Cubic texture uniform lookup."), -1, -1)); add_options.push_back(AddOption("TextureUniform", "Textures", "Variables", "VisualShaderNodeTextureUniform", TTR("2D texture uniform lookup."), -1, -1)); add_options.push_back(AddOption("TextureUniformTriplanar", "Textures", "Variables", "VisualShaderNodeTextureUniformTriplanar", TTR("2D texture uniform lookup with triplanar."), -1, -1, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); @@ -2886,7 +2912,7 @@ public: void setup(const Ref<VisualShaderNodeInput> &p_input) { input = p_input; - Ref<Texture> type_icon[5] = { + Ref<Texture2D> type_icon[5] = { EditorNode::get_singleton()->get_gui_base()->get_icon("float", "EditorIcons"), EditorNode::get_singleton()->get_gui_base()->get_icon("Vector3", "EditorIcons"), EditorNode::get_singleton()->get_gui_base()->get_icon("bool", "EditorIcons"), @@ -2972,6 +2998,13 @@ public: bool updating; Ref<VisualShaderNode> node; Vector<EditorProperty *> properties; + Vector<Label *> prop_names; + + void _show_prop_names(bool p_show) { + for (int i = 0; i < prop_names.size(); i++) { + prop_names[i]->set_visible(p_show); + } + } void setup(Ref<Resource> p_parent_resource, Vector<EditorProperty *> p_properties, const Vector<StringName> &p_names, Ref<VisualShaderNode> p_node) { parent_resource = p_parent_resource; @@ -2981,7 +3014,20 @@ public: for (int i = 0; i < p_properties.size(); i++) { - add_child(p_properties[i]); + HBoxContainer *hbox = memnew(HBoxContainer); + hbox->set_h_size_flags(SIZE_EXPAND_FILL); + add_child(hbox); + + Label *prop_name = memnew(Label); + String prop_name_str = p_names[i]; + prop_name_str = prop_name_str.capitalize() + ":"; + prop_name->set_text(prop_name_str); + prop_name->set_visible(false); + hbox->add_child(prop_name); + prop_names.push_back(prop_name); + + p_properties[i]->set_h_size_flags(SIZE_EXPAND_FILL); + hbox->add_child(p_properties[i]); bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]); if (res_prop) { @@ -3003,6 +3049,7 @@ public: ClassDB::bind_method("_refresh_request", &VisualShaderNodePluginDefaultEditor::_refresh_request); ClassDB::bind_method("_resource_selected", &VisualShaderNodePluginDefaultEditor::_resource_selected); ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); + ClassDB::bind_method("_show_prop_names", &VisualShaderNodePluginDefaultEditor::_show_prop_names); } }; diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 8c5dd8e82f..150cf16167 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -94,6 +94,7 @@ class VisualShaderEditor : public VBoxContainer { AcceptDialog *alert; LineEdit *node_filter; RichTextLabel *node_desc; + Label *highend_label; void _tools_menu_option(int p_idx); void _show_members_dialog(bool at_mouse_pos); @@ -264,7 +265,7 @@ public: static VisualShaderEditor *get_singleton() { return singleton; } void clear_custom_types(); - void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, const String &p_subcategory); + void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, const String &p_subcategory, bool p_highend); virtual Size2 get_minimum_size() const; void edit(VisualShader *p_visual_shader); |