summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_inspector.cpp4
-rw-r--r--editor/editor_log.cpp2
-rw-r--r--editor/editor_node.cpp16
-rw-r--r--editor/import/resource_importer_layered_texture.cpp3
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp119
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h9
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp2
-rw-r--r--editor/plugins/script_editor_plugin.cpp4
-rw-r--r--editor/plugins/script_text_editor.cpp10
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp118
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h8
11 files changed, 151 insertions, 144 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 679f2e8ce4..9de8b0451a 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -887,7 +887,7 @@ Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
text += "\n" + property_doc;
}
}
- help_bit->set_text(text);
+ help_bit->call_deferred(SNAME("set_text"), text); //hack so it uses proper theme once inside scene
}
return help_bit;
@@ -1102,7 +1102,7 @@ Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) cons
text += "\n" + property_doc;
}
}
- help_bit->set_text(text); //hack so it uses proper theme once inside scene
+ help_bit->call_deferred(SNAME("set_text"), text); //hack so it uses proper theme once inside scene
}
return help_bit;
diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp
index 2cb73664f5..296a33d917 100644
--- a/editor/editor_log.cpp
+++ b/editor/editor_log.cpp
@@ -397,7 +397,7 @@ EditorLog::EditorLog() {
show_search_button->set_focus_mode(FOCUS_NONE);
show_search_button->set_toggle_mode(true);
show_search_button->set_pressed(true);
- show_search_button->set_shortcut(ED_SHORTCUT("editor/open_search", TTR("Open the search box."), KEY_MASK_CMD | KEY_F));
+ show_search_button->set_shortcut(ED_SHORTCUT("editor/open_search", TTR("Focus Search/Filter Bar"), KEY_MASK_CMD | KEY_F));
show_search_button->set_shortcut_context(this);
show_search_button->connect("toggled", callable_mp(this, &EditorLog::_set_search_visible));
hb_tools2->add_child(show_search_button);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 30edbd1e87..19a6d027bc 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -613,8 +613,10 @@ void EditorNode::_notification(int p_what) {
_editor_select(EDITOR_3D);
}
- // Save the project after opening to mark it as last modified.
- ProjectSettings::get_singleton()->save();
+ // Save the project after opening to mark it as last modified, except in headless mode.
+ if (DisplayServer::get_singleton()->window_can_draw()) {
+ ProjectSettings::get_singleton()->save();
+ }
/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
} break;
@@ -6238,9 +6240,9 @@ EditorNode::EditorNode() {
gui_base->add_child(warning);
warning->connect("custom_action", callable_mp(this, &EditorNode::_copy_warning));
- ED_SHORTCUT("editor/next_tab", TTR("Next tab"), KEY_MASK_CMD + KEY_TAB);
- ED_SHORTCUT("editor/prev_tab", TTR("Previous tab"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_TAB);
- ED_SHORTCUT("editor/filter_files", TTR("Filter Files..."), KEY_MASK_CMD + KEY_MASK_ALT + KEY_P);
+ ED_SHORTCUT("editor/next_tab", TTR("Next Scene Tab"), KEY_MASK_CMD + KEY_TAB);
+ ED_SHORTCUT("editor/prev_tab", TTR("Previous Scene Tab"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_TAB);
+ ED_SHORTCUT("editor/filter_files", TTR("Focus FileSystem Filter"), KEY_MASK_CMD + KEY_MASK_ALT + KEY_P);
command_palette = EditorCommandPalette::get_singleton();
command_palette->set_title(TTR("Command Palette"));
@@ -7054,8 +7056,8 @@ EditorNode::EditorNode() {
ED_SHORTCUT_AND_COMMAND("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_CTRL | KEY_F4);
ED_SHORTCUT("editor/command_palette", TTR("Open Command Palette"), KEY_MASK_CTRL | KEY_MASK_SHIFT | KEY_P);
#endif
- ED_SHORTCUT_AND_COMMAND("editor/editor_next", TTR("Open the next Editor"));
- ED_SHORTCUT_AND_COMMAND("editor/editor_prev", TTR("Open the previous Editor"));
+ ED_SHORTCUT_AND_COMMAND("editor/editor_next", TTR("Next Editor Tab"));
+ ED_SHORTCUT_AND_COMMAND("editor/editor_prev", TTR("Next Editor Tab"));
screenshot_timer = memnew(Timer);
screenshot_timer->set_one_shot(true);
diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp
index 2ac8b8bd7d..d5bb21443c 100644
--- a/editor/import/resource_importer_layered_texture.cpp
+++ b/editor/import/resource_importer_layered_texture.cpp
@@ -341,10 +341,7 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
if (compress_mode == COMPRESS_VRAM_COMPRESSED) {
mipmaps = true;
- }
- //optimize
- if (compress_mode == COMPRESS_VRAM_COMPRESSED) {
//if using video ram, optimize
if (channel_pack == 0) {
//remove alpha if not needed, so compression is more efficient
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 7fe12089c8..76c056ed33 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -41,6 +41,7 @@
#include "editor/editor_settings.h"
#include "editor/plugins/animation_player_editor_plugin.h"
#include "editor/plugins/script_editor_plugin.h"
+#include "scene/2d/cpu_particles_2d.h"
#include "scene/2d/gpu_particles_2d.h"
#include "scene/2d/light_2d.h"
#include "scene/2d/polygon_2d.h"
@@ -5740,7 +5741,7 @@ void CanvasItemEditorViewport::_on_change_type_confirmed() {
}
CheckBox *check = Object::cast_to<CheckBox>(button_group->get_pressed_button());
- default_type = check->get_text();
+ default_texture_node_type = check->get_text();
_perform_drop_data();
selector->hide();
}
@@ -5832,14 +5833,13 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
child->set_name(name);
Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(ResourceCache::get(path)));
- Size2 texture_size = texture->get_size();
if (parent) {
editor_data->get_undo_redo().add_do_method(parent, "add_child", child);
editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene());
editor_data->get_undo_redo().add_do_reference(child);
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", child);
- } else { // if we haven't parent, lets try to make a child as a parent.
+ } else { // If no parent is selected, set as root node of the scene.
editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", child);
editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene());
editor_data->get_undo_redo().add_do_reference(child);
@@ -5853,28 +5853,23 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
}
- // handle with different property for texture
- String property = "texture";
- List<PropertyInfo> props;
- child->get_property_list(&props);
- for (const PropertyInfo &E : props) {
- if (E.name == "config/texture") { // Particles2D
- property = "config/texture";
- break;
- } else if (E.name == "texture/texture") { // Polygon2D
- property = "texture/texture";
- break;
- } else if (E.name == "normal") { // TouchScreenButton
- property = "normal";
- break;
- }
+ String node_class = child->get_class();
+ if (node_class == "Polygon2D") {
+ editor_data->get_undo_redo().add_do_property(child, "texture/texture", texture);
+ } else if (node_class == "TouchScreenButton") {
+ editor_data->get_undo_redo().add_do_property(child, "normal", texture);
+ } else if (node_class == "TextureButton") {
+ editor_data->get_undo_redo().add_do_property(child, "texture_button", texture);
+ } else {
+ editor_data->get_undo_redo().add_do_property(child, "texture", texture);
}
- editor_data->get_undo_redo().add_do_property(child, property, texture);
// make visible for certain node type
- if (default_type == "NinePatchRect") {
- editor_data->get_undo_redo().add_do_property(child, "rect/size", texture_size);
- } else if (default_type == "Polygon2D") {
+ if (ClassDB::is_parent_class(node_class, "Control")) {
+ Size2 texture_size = texture->get_size();
+ editor_data->get_undo_redo().add_do_property(child, "rect_size", texture_size);
+ } else if (node_class == "Polygon2D") {
+ Size2 texture_size = texture->get_size();
Vector<Vector2> list;
list.push_back(Vector2(0, 0));
list.push_back(Vector2(texture_size.width, 0));
@@ -5975,23 +5970,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
} else {
Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res));
if (texture != nullptr && texture.is_valid()) {
- Node *child;
- if (default_type == "Light2D") {
- child = memnew(Light2D);
- } else if (default_type == "GPUParticles2D") {
- child = memnew(GPUParticles2D);
- } else if (default_type == "Polygon2D") {
- child = memnew(Polygon2D);
- } else if (default_type == "TouchScreenButton") {
- child = memnew(TouchScreenButton);
- } else if (default_type == "TextureRect") {
- child = memnew(TextureRect);
- } else if (default_type == "NinePatchRect") {
- child = memnew(NinePatchRect);
- } else {
- child = memnew(Sprite2D); // default
- }
-
+ Node *child = _make_texture_node_type(default_texture_node_type);
_create_nodes(target_node, child, path, drop_pos);
}
}
@@ -6029,13 +6008,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian
continue;
}
memdelete(instantiated_scene);
- } else if (type == "Texture2D" ||
- type == "ImageTexture" ||
- type == "ViewportTexture" ||
- type == "CurveTexture" ||
- type == "GradientTexture" ||
- type == "StreamTexture2D" ||
- type == "AtlasTexture") {
+ } else if (ClassDB::is_parent_class(type, "Texture2D")) {
Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res));
if (!texture.is_valid()) {
continue;
@@ -6052,7 +6025,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian
}
Transform2D trans = canvas_item_editor->get_canvas_transform();
preview_node->set_position((p_point - trans.get_origin()) / trans.get_scale().x);
- label->set_text(vformat(TTR("Adding %s..."), default_type));
+ label->set_text(vformat(TTR("Adding %s..."), default_texture_node_type));
}
return can_instantiate;
}
@@ -6068,9 +6041,9 @@ void CanvasItemEditorViewport::_show_resource_type_selector() {
for (int i = 0; i < btn_list.size(); i++) {
CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]);
- check->set_pressed(check->get_text() == default_type);
+ check->set_pressed(check->get_text() == default_texture_node_type);
}
- selector->set_title(vformat(TTR("Add %s"), default_type));
+ selector->set_title(vformat(TTR("Add %s"), default_texture_node_type));
selector->popup_centered();
}
@@ -6126,6 +6099,30 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p
}
}
+Node *CanvasItemEditorViewport::_make_texture_node_type(String texture_node_type) {
+ Node *node = nullptr;
+ if (texture_node_type == "Sprite2D") {
+ node = memnew(Sprite2D);
+ } else if (texture_node_type == "PointLight2D") {
+ node = memnew(PointLight2D);
+ } else if (texture_node_type == "CPUParticles2D") {
+ node = memnew(CPUParticles2D);
+ } else if (texture_node_type == "GPUParticles2D") {
+ node = memnew(GPUParticles2D);
+ } else if (texture_node_type == "Polygon2D") {
+ node = memnew(Polygon2D);
+ } else if (texture_node_type == "TouchScreenButton") {
+ node = memnew(TouchScreenButton);
+ } else if (texture_node_type == "TextureRect") {
+ node = memnew(TextureRect);
+ } else if (texture_node_type == "TextureButton") {
+ node = memnew(TextureButton);
+ } else if (texture_node_type == "NinePatchRect") {
+ node = memnew(NinePatchRect);
+ }
+ return node;
+}
+
void CanvasItemEditorViewport::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -6145,22 +6142,24 @@ void CanvasItemEditorViewport::_bind_methods() {
}
CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas_item_editor) {
- default_type = "Sprite2D";
+ default_texture_node_type = "Sprite2D";
// Node2D
- types.push_back("Sprite2D");
- types.push_back("Light2D");
- types.push_back("GPUParticles2D");
- types.push_back("Polygon2D");
- types.push_back("TouchScreenButton");
+ texture_node_types.push_back("Sprite2D");
+ texture_node_types.push_back("PointLight2D");
+ texture_node_types.push_back("CPUParticles2D");
+ texture_node_types.push_back("GPUParticles2D");
+ texture_node_types.push_back("Polygon2D");
+ texture_node_types.push_back("TouchScreenButton");
// Control
- types.push_back("TextureRect");
- types.push_back("NinePatchRect");
+ texture_node_types.push_back("TextureRect");
+ texture_node_types.push_back("TextureButton");
+ texture_node_types.push_back("NinePatchRect");
target_node = nullptr;
editor = p_node;
editor_data = editor->get_scene_tree_dock()->get_editor_data();
canvas_item_editor = p_canvas_item_editor;
- preview_node = memnew(Node2D);
+ preview_node = memnew(Control);
accept = memnew(AcceptDialog);
editor->get_gui_base()->add_child(accept);
@@ -6182,10 +6181,10 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
btn_group->set_h_size_flags(0);
button_group.instantiate();
- for (int i = 0; i < types.size(); i++) {
+ for (int i = 0; i < texture_node_types.size(); i++) {
CheckBox *check = memnew(CheckBox);
btn_group->add_child(check);
- check->set_text(types[i]);
+ check->set_text(texture_node_types[i]);
check->connect("button_down", callable_mp(this, &CanvasItemEditorViewport::_on_select_type), varray(check));
check->set_button_group(button_group);
}
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 495cd5f515..bff580315e 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -639,8 +639,10 @@ public:
class CanvasItemEditorViewport : public Control {
GDCLASS(CanvasItemEditorViewport, Control);
- String default_type;
- Vector<String> types;
+ // The type of node that will be created when dropping texture into the viewport.
+ String default_texture_node_type;
+ // Node types that are available to select from when dropping texture into viewport.
+ Vector<String> texture_node_types;
Vector<String> selected_files;
Node *target_node;
@@ -649,7 +651,7 @@ class CanvasItemEditorViewport : public Control {
EditorNode *editor;
EditorData *editor_data;
CanvasItemEditor *canvas_item_editor;
- Node2D *preview_node;
+ Control *preview_node;
AcceptDialog *accept;
AcceptDialog *selector;
Label *selector_label;
@@ -662,6 +664,7 @@ class CanvasItemEditorViewport : public Control {
void _on_select_type(Object *selected);
void _on_change_type_confirmed();
void _on_change_type_closed();
+ Node *_make_texture_node_type(String texture_node_type);
void _create_preview(const Vector<String> &files) const;
void _remove_preview();
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 8f0359bd0f..e9a67491aa 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -4030,7 +4030,7 @@ bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant
continue;
}
memdelete(instantiated_scene);
- } else if (type == "Mesh" || type == "ArrayMesh" || type == "PrimitiveMesh") {
+ } else if (ClassDB::is_parent_class(type, "Mesh")) {
Ref<Mesh> mesh = ResourceLoader::load(files[i]);
if (!mesh.is_valid()) {
continue;
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 668a15da37..e6762826dd 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -3409,8 +3409,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
ED_SHORTCUT("script_editor/window_sort", TTR("Sort"));
ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP);
ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN);
- ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work
- ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA);
+ ED_SHORTCUT("script_editor/next_script", TTR("Next Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work
+ ED_SHORTCUT("script_editor/prev_script", TTR("Previous Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA);
set_process_unhandled_key_input(true);
file_menu = memnew(MenuButton);
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 8cd746304c..e06e6eefff 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -1390,6 +1390,7 @@ bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_
if (d.has("type") && (String(d["type"]) == "resource" ||
String(d["type"]) == "files" ||
String(d["type"]) == "nodes" ||
+ String(d["type"]) == "obj_property" ||
String(d["type"]) == "files_and_dirs")) {
return true;
}
@@ -1495,6 +1496,15 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
te->set_caret_column(col);
te->insert_text_at_caret(text_to_drop);
}
+
+ if (d.has("type") && String(d["type"]) == "obj_property") {
+ const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
+ const String text_to_drop = String(d["property"]).c_escape().quote(quote_style);
+
+ te->set_caret_line(row);
+ te->set_caret_column(col);
+ te->insert_text_at_caret(text_to_drop);
+ }
}
void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index d6ac238414..1fbf5eb0e6 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -110,7 +110,6 @@ void VisualShaderGraphPlugin::_bind_methods() {
ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression);
ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve);
ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz);
- ClassDB::bind_method("update_constant", &VisualShaderGraphPlugin::update_constant);
}
void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) {
@@ -237,18 +236,6 @@ int VisualShaderGraphPlugin::get_constant_index(float p_constant) const {
return 0;
}
-void VisualShaderGraphPlugin::update_constant(VisualShader::Type p_type, int p_node_id) {
- if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].const_op) {
- return;
- }
- VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(links[p_node_id].visual_node);
- if (!float_const) {
- return;
- }
- links[p_node_id].const_op->select(get_constant_index(float_const->get_constant()));
- links[p_node_id].graph_node->set_size(Size2(-1, -1));
-}
-
void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) {
if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) {
return;
@@ -267,10 +254,6 @@ void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p
links[p_node_id].input_ports.insert(p_port_id, { p_button });
}
-void VisualShaderGraphPlugin::register_constant_option_btn(int p_node_id, OptionButton *p_button) {
- links[p_node_id].const_op = p_button;
-}
-
void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) {
links[p_node_id].expression_edit = p_expression_edit;
}
@@ -322,7 +305,7 @@ void VisualShaderGraphPlugin::make_dirty(bool p_enabled) {
}
void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) {
- links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } });
+ links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } });
}
void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) {
@@ -498,23 +481,6 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
custom_editor = hbox;
}
- Ref<VisualShaderNodeFloatConstant> float_const = vsnode;
- if (float_const.is_valid()) {
- HBoxContainer *hbox = memnew(HBoxContainer);
-
- hbox->add_child(custom_editor);
- OptionButton *btn = memnew(OptionButton);
- hbox->add_child(btn);
- register_constant_option_btn(p_id, btn);
- btn->add_item("");
- for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
- btn->add_item(float_constant_defs[i].name);
- }
- btn->select(get_constant_index(float_const->get_constant()));
- btn->connect("item_selected", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_float_constant_selected), varray(p_id));
- custom_editor = hbox;
- }
-
if (custom_editor && !vsnode->is_use_prop_slots() && 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) {
@@ -2182,6 +2148,16 @@ void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, int p_op_idx) {
}
}
+ // TRANSFORM_OP
+ {
+ VisualShaderNodeTransformOp *matOp = Object::cast_to<VisualShaderNodeTransformOp>(p_node);
+
+ if (matOp) {
+ matOp->set_operator((VisualShaderNodeTransformOp::Operator)p_op_idx);
+ return;
+ }
+ }
+
// TRANSFORM_FUNC
{
VisualShaderNodeTransformFunc *matFunc = Object::cast_to<VisualShaderNodeTransformFunc>(p_node);
@@ -2944,6 +2920,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
selected_constants.clear();
selected_uniforms.clear();
selected_comment = -1;
+ selected_float_constant = -1;
List<int> to_change;
for (int i = 0; i < graph->get_child_count(); i++) {
@@ -2963,6 +2940,10 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
if (constant_node != nullptr) {
selected_constants.insert(id);
}
+ VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
+ if (float_constant_node != nullptr) {
+ selected_float_constant = id;
+ }
VisualShaderNodeUniform *uniform_node = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
if (uniform_node != nullptr && uniform_node->is_convertible_to_constant()) {
selected_uniforms.insert(id);
@@ -2973,6 +2954,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
if (to_change.size() > 1) {
selected_comment = -1;
+ selected_float_constant = -1;
}
if (to_change.is_empty() && copy_nodes_buffer.is_empty()) {
@@ -2987,6 +2969,10 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
if (temp != -1) {
popup_menu->remove_item(temp);
}
+ temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS);
+ if (temp != -1) {
+ popup_menu->remove_item(temp);
+ }
temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS);
if (temp != -1) {
popup_menu->remove_item(temp);
@@ -3008,14 +2994,23 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
popup_menu->remove_item(temp);
}
- if (selected_comment != -1) {
+ if (selected_constants.size() > 0 || selected_uniforms.size() > 0) {
popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2);
- popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE);
- popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION);
- }
- if (selected_constants.size() > 0 || selected_uniforms.size() > 0) {
- popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3);
+ if (selected_float_constant != -1) {
+ popup_menu->add_submenu_item(TTR("Float Constants"), "FloatConstants", int(NodeMenuOptions::FLOAT_CONSTANTS));
+
+ if (!constants_submenu) {
+ constants_submenu = memnew(PopupMenu);
+ constants_submenu->set_name("FloatConstants");
+
+ for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
+ constants_submenu->add_item(float_constant_defs[i].name, i);
+ }
+ popup_menu->add_child(constants_submenu);
+ constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected));
+ }
+ }
if (selected_constants.size() > 0) {
popup_menu->add_item(TTR("Convert Constant(s) to Uniform(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS);
@@ -3026,6 +3021,12 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
}
}
+ if (selected_comment != -1) {
+ popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3);
+ popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE);
+ popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION);
+ }
+
menu_point = graph->get_local_mouse_position();
Point2 gpos = Input::get_singleton()->get_mouse_position();
popup_menu->set_position(gpos);
@@ -3495,27 +3496,20 @@ void VisualShaderEditor::_uniform_select_item(Ref<VisualShaderNodeUniformRef> p_
undo_redo->commit_action();
}
-void VisualShaderEditor::_float_constant_selected(int p_index, int p_node) {
- if (p_index == 0) {
- graph_plugin->update_node_size(p_node);
- return;
- }
-
- --p_index;
-
- ERR_FAIL_INDEX(p_index, MAX_FLOAT_CONST_DEFS);
+void VisualShaderEditor::_float_constant_selected(int p_which) {
+ ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS);
VisualShader::Type type = get_current_shader_type();
- Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, p_node);
- if (!node.is_valid()) {
- return;
+ Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant);
+ ERR_FAIL_COND(!node.is_valid());
+
+ if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) {
+ return; // same
}
- undo_redo->create_action(TTR("Set constant"));
- undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_index].value);
+ undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name));
+ undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value);
undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant());
- undo_redo->add_do_method(graph_plugin.ptr(), "update_constant", type, p_node);
- undo_redo->add_undo_method(graph_plugin.ptr(), "update_constant", type, p_node);
undo_redo->commit_action();
}
@@ -4460,6 +4454,7 @@ VisualShaderEditor::VisualShaderEditor() {
// TRANSFORM
add_options.push_back(AddOption("TransformFunc", "Transform", "Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
+ add_options.push_back(AddOption("TransformOp", "Transform", "Common", "VisualShaderNodeTransformOp", TTR("Transform operator."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
add_options.push_back(AddOption("OuterProduct", "Transform", "Composition", "VisualShaderNodeOuterProduct", TTR("Calculate the outer product of a pair of vectors.\n\nOuterProduct treats the first parameter 'c' as a column vector (matrix with one column) and the second parameter 'r' as a row vector (matrix with one row) and does a linear algebraic matrix multiply 'c * r', yielding a matrix whose number of rows is the number of components in 'c' and whose number of columns is the number of components in 'r'."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
add_options.push_back(AddOption("TransformCompose", "Transform", "Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
@@ -4470,7 +4465,11 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("Inverse", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), VisualShaderNodeTransformFunc::FUNC_INVERSE, VisualShaderNode::PORT_TYPE_TRANSFORM));
add_options.push_back(AddOption("Transpose", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), VisualShaderNodeTransformFunc::FUNC_TRANSPOSE, VisualShaderNode::PORT_TYPE_TRANSFORM));
- add_options.push_back(AddOption("TransformMult", "Transform", "Operators", "VisualShaderNodeTransformMult", TTR("Multiplies transform by transform."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
+ add_options.push_back(AddOption("Add", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Sums two transforms."), VisualShaderNodeTransformOp::OP_ADD, VisualShaderNode::PORT_TYPE_TRANSFORM));
+ add_options.push_back(AddOption("Divide", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Divides two transforms."), VisualShaderNodeTransformOp::OP_A_DIV_B, VisualShaderNode::PORT_TYPE_TRANSFORM));
+ add_options.push_back(AddOption("Multiply", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Multiplies two transforms."), VisualShaderNodeTransformOp::OP_AxB, VisualShaderNode::PORT_TYPE_TRANSFORM));
+ add_options.push_back(AddOption("MultiplyComp", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Performs per-component multiplication of two transforms."), VisualShaderNodeTransformOp::OP_AxB_COMP, VisualShaderNode::PORT_TYPE_TRANSFORM));
+ add_options.push_back(AddOption("Subtract", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Subtracts two transforms."), VisualShaderNodeTransformOp::OP_A_MINUS_B, VisualShaderNode::PORT_TYPE_TRANSFORM));
add_options.push_back(AddOption("TransformVectorMult", "Transform", "Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("TransformConstant", "Transform", "Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
@@ -4753,9 +4752,6 @@ public:
if (p_property != "constant") {
undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id);
undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id);
- } else {
- undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_constant", shader_type, node_id);
- undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_constant", shader_type, node_id);
}
undo_redo->commit_action();
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index f53726edb9..87bab16a45 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -73,7 +73,6 @@ private:
Map<int, Port> output_ports;
VBoxContainer *preview_box = nullptr;
LineEdit *uniform_name = nullptr;
- OptionButton *const_op = nullptr;
CodeEdit *expression_edit = nullptr;
CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr };
};
@@ -95,7 +94,6 @@ public:
void register_output_port(int p_id, int p_port, TextureButton *p_button);
void register_uniform_name(int p_id, LineEdit *p_uniform_name);
void register_default_input_button(int p_node_id, int p_port_id, Button *p_button);
- void register_constant_option_btn(int p_node_id, OptionButton *p_button);
void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit);
void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor);
void clear_links();
@@ -118,7 +116,6 @@ public:
void set_uniform_name(VisualShader::Type p_type, int p_node_id, const String &p_name);
void update_curve(int p_node_id);
void update_curve_xyz(int p_node_id);
- void update_constant(VisualShader::Type p_type, int p_node_id);
void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression);
int get_constant_index(float p_constant) const;
void update_node_size(int p_node_id);
@@ -164,6 +161,7 @@ class VisualShaderEditor : public VBoxContainer {
ConfirmationDialog *members_dialog;
PopupMenu *popup_menu;
+ PopupMenu *constants_submenu = nullptr;
MenuButton *tools;
PopupPanel *comment_title_change_popup = nullptr;
@@ -214,6 +212,7 @@ class VisualShaderEditor : public VBoxContainer {
DELETE,
DUPLICATE,
SEPARATOR2, // ignore
+ FLOAT_CONSTANTS,
CONVERT_CONSTANTS_TO_UNIFORMS,
CONVERT_UNIFORMS_TO_CONSTANTS,
SEPARATOR3, // ignore
@@ -347,6 +346,7 @@ class VisualShaderEditor : public VBoxContainer {
Set<int> selected_constants;
Set<int> selected_uniforms;
int selected_comment = -1;
+ int selected_float_constant = -1;
void _convert_constants_to_uniforms(bool p_vice_versa);
void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to);
@@ -396,7 +396,7 @@ class VisualShaderEditor : public VBoxContainer {
void _input_select_item(Ref<VisualShaderNodeInput> input, String name);
void _uniform_select_item(Ref<VisualShaderNodeUniformRef> p_uniform, String p_name);
- void _float_constant_selected(int p_index, int p_node);
+ void _float_constant_selected(int p_which);
VisualShader::Type get_current_shader_type() const;