feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -34,6 +34,7 @@
#include "core/io/resource_loader.h"
#include "core/math/math_defs.h"
#include "core/os/keyboard.h"
#include "core/version_generated.gen.h"
#include "editor/editor_node.h"
#include "editor/editor_properties.h"
#include "editor/editor_properties_vector.h"
@ -79,17 +80,17 @@ struct FloatConstantDef {
};
static FloatConstantDef float_constant_defs[] = {
{ "E", Math_E, TTRC("E constant (2.718282). Represents the base of the natural logarithm.") },
{ "E", Math::E, TTRC("E constant (2.718282). Represents the base of the natural logarithm.") },
{ "Epsilon", CMP_EPSILON, TTRC("Epsilon constant (0.00001). Smallest possible scalar number.") },
{ "Phi", 1.618034f, TTRC("Phi constant (1.618034). Golden ratio.") },
{ "Pi/4", Math_PI / 4, TTRC("Pi/4 constant (0.785398) or 45 degrees.") },
{ "Pi/2", Math_PI / 2, TTRC("Pi/2 constant (1.570796) or 90 degrees.") },
{ "Pi", Math_PI, TTRC("Pi constant (3.141593) or 180 degrees.") },
{ "Tau", Math_TAU, TTRC("Tau constant (6.283185) or 360 degrees.") },
{ "Sqrt2", Math_SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") }
{ "Pi/4", Math::PI / 4, TTRC("Pi/4 constant (0.785398) or 45 degrees.") },
{ "Pi/2", Math::PI / 2, TTRC("Pi/2 constant (1.570796) or 90 degrees.") },
{ "Pi", Math::PI, TTRC("Pi constant (3.141593) or 180 degrees.") },
{ "Tau", Math::TAU, TTRC("Tau constant (6.283185) or 360 degrees.") },
{ "Sqrt2", Math::SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") }
};
const int MAX_FLOAT_CONST_DEFS = sizeof(float_constant_defs) / sizeof(FloatConstantDef);
constexpr int MAX_FLOAT_CONST_DEFS = std::size(float_constant_defs);
///////////////////
@ -1211,6 +1212,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool
if (valid_right) {
if (expanded_port_counter == 0 && vsnode->is_output_port_expandable(i)) {
TextureButton *expand = memnew(TextureButton);
expand->set_accessibility_name(TTRC("Expand output port"));
expand->set_toggle_mode(true);
expand->set_texture_normal(editor->get_editor_theme_icon(SNAME("GuiTreeArrowRight")));
expand->set_texture_pressed(editor->get_editor_theme_icon(SNAME("GuiTreeArrowDown")));
@ -1221,6 +1223,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool
}
if (vsnode->has_output_port_preview(i) && port_right != VisualShaderNode::PORT_TYPE_TRANSFORM && port_right != VisualShaderNode::PORT_TYPE_SAMPLER) {
TextureButton *preview = memnew(TextureButton);
preview->set_accessibility_name(TTRC("Select preview port"));
preview->set_toggle_mode(true);
preview->set_texture_normal(editor->get_editor_theme_icon(SNAME("GuiVisibilityHidden")));
preview->set_texture_pressed(editor->get_editor_theme_icon(SNAME("GuiVisibilityVisible")));
@ -1491,9 +1494,6 @@ void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_
}
}
VisualShaderGraphPlugin::~VisualShaderGraphPlugin() {
}
/////////////////
void VisualShaderEditedProperty::_bind_methods() {
@ -1575,6 +1575,10 @@ void VisualShaderEditor::validate_script() {
}
}
Control *VisualShaderEditor::get_top_bar() {
return toolbar;
}
void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
if (plugins.has(p_plugin)) {
return;
@ -2195,8 +2199,7 @@ void VisualShaderEditor::_update_nodes() {
}
}
List<Variant> keys;
added.get_key_list(&keys);
LocalVector<Variant> keys = added.get_key_list();
keys.sort_custom<StringLikeVariantOrder>();
for (const Variant &key : keys) {
@ -2466,6 +2469,13 @@ Size2 VisualShaderEditor::get_minimum_size() const {
return Size2(10, 200);
}
void VisualShaderEditor::update_toggle_files_button() {
ERR_FAIL_NULL(toggle_files_list);
bool forward = toggle_files_list->is_visible() == is_layout_rtl();
toggle_files_button->set_button_icon(get_editor_theme_icon(forward ? SNAME("Forward") : SNAME("Back")));
toggle_files_button->set_tooltip_text(vformat("%s (%s)", TTR("Toggle Files Panel"), ED_GET_SHORTCUT("script_editor/toggle_files_panel")->get_as_text()));
}
void VisualShaderEditor::_draw_color_over_button(Object *p_obj, Color p_color) {
Button *button = Object::cast_to<Button>(p_obj);
if (!button) {
@ -3305,7 +3315,7 @@ void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node,
popup_pref_size.width = 180;
break;
}
property_editor_popup->set_min_size(popup_pref_size);
property_editor_popup->set_min_size(popup_pref_size * EDSCALE);
property_editor->set_object_and_property(edited_property_holder.ptr(), "edited_property");
property_editor->update_property();
@ -4424,8 +4434,8 @@ void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) {
for (const VisualShader::Connection &E : conns) {
if (E.from_node == F || E.to_node == F) {
bool cancel = false;
for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) {
if (R->get().from_node == E.from_node && R->get().from_port == E.from_port && R->get().to_node == E.to_node && R->get().to_port == E.to_port) {
for (const VisualShader::Connection &R : used_conns) {
if (R.from_node == E.from_node && R.from_port == E.from_port && R.to_node == E.to_node && R.to_port == E.to_port) {
cancel = true; // to avoid ERR_ALREADY_EXISTS warning
break;
}
@ -5150,6 +5160,10 @@ void VisualShaderEditor::_param_unselected() {
_clear_preview_param();
}
void VisualShaderEditor::_help_open() {
OS::get_singleton()->shell_open(vformat("%s/tutorials/shaders/visual_shaders.html", GODOT_VERSION_DOCS_URL));
}
void VisualShaderEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_POSTINITIALIZE: {
@ -5191,6 +5205,7 @@ void VisualShaderEditor::_notification(int p_what) {
} break;
case NOTIFICATION_THEME_CHANGED: {
site_search->set_button_icon(get_editor_theme_icon(SNAME("ExternalLink")));
highend_label->set_modulate(get_theme_color(SNAME("highend_color"), EditorStringName(Editor)));
param_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search")));
@ -5254,6 +5269,11 @@ void VisualShaderEditor::_notification(int p_what) {
if (is_visible_in_tree()) {
_update_graph();
}
update_toggle_files_button();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
update_toggle_files_button();
} break;
case NOTIFICATION_DRAG_BEGIN: {
@ -6102,6 +6122,10 @@ void VisualShaderEditor::_connection_menu_id_pressed(int p_idx) {
}
Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return Variant();
}
if (p_from == members) {
TreeItem *it = members->get_item_at_position(p_point);
if (!it) {
@ -6127,6 +6151,10 @@ Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
}
bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
if (p_point == Vector2(Math::INF, Math::INF)) {
return false;
}
if (p_from == graph) {
Dictionary d = p_data;
@ -6142,6 +6170,10 @@ bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
}
void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return;
}
if (p_from == graph) {
Dictionary d = p_data;
@ -6357,6 +6389,16 @@ void VisualShaderEditor::_show_shader_preview() {
}
}
void VisualShaderEditor::set_toggle_list_control(Control *p_control) {
toggle_files_list = p_control;
}
void VisualShaderEditor::_toggle_files_pressed() {
ERR_FAIL_NULL(toggle_files_list);
toggle_files_list->set_visible(!toggle_files_list->is_visible());
update_toggle_files_button();
}
void VisualShaderEditor::_bind_methods() {
ClassDB::bind_method("_update_nodes", &VisualShaderEditor::_update_nodes);
ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
@ -6493,7 +6535,7 @@ VisualShaderEditor::VisualShaderEditor() {
toolbar_panel->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE, PRESET_MODE_MINSIZE, 10);
toolbar_panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
HFlowContainer *toolbar = memnew(HFlowContainer);
toolbar = memnew(HFlowContainer);
{
LocalVector<Node *> nodes;
for (int i = 0; i < graph->get_menu_hbox()->get_child_count(); i++) {
@ -6592,6 +6634,32 @@ VisualShaderEditor::VisualShaderEditor() {
toolbar->add_child(shader_preview_button);
shader_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_shader_preview));
Control *spacer = memnew(Control);
spacer->set_h_size_flags(Control::SIZE_EXPAND);
toolbar->add_child(spacer);
site_search = memnew(Button);
site_search->set_flat(true);
site_search->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_help_open));
site_search->set_text(TTR("Online Docs"));
site_search->set_tooltip_text(TTR("Open Godot online documentation."));
toolbar->add_child(site_search);
toolbar->add_child(memnew(VSeparator));
VSeparator *separator = memnew(VSeparator);
toolbar->add_child(separator);
toolbar->move_child(separator, 0);
separator = memnew(VSeparator);
toolbar->add_child(separator);
toolbar->move_child(separator, 0);
toggle_files_button = memnew(Button);
toggle_files_button->set_flat(true);
toggle_files_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_toggle_files_pressed));
toolbar->add_child(toggle_files_button);
toolbar->move_child(toggle_files_button, 0);
///////////////////////////////////////
// CODE PREVIEW
///////////////////////////////////////
@ -6691,6 +6759,7 @@ VisualShaderEditor::VisualShaderEditor() {
preview_tools = memnew(MenuButton);
filter_hbox->add_child(preview_tools);
preview_tools->set_tooltip_text(TTR("Options"));
preview_tools->set_accessibility_name(TTRC("Options"));
preview_tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_preview_tools_menu_option));
preview_tools->get_popup()->add_item(TTR("Copy Parameters From Material"), COPY_PARAMS_FROM_MATERIAL);
preview_tools->get_popup()->add_item(TTR("Paste Parameters To Material"), PASTE_PARAMS_TO_MATERIAL);
@ -6740,10 +6809,12 @@ VisualShaderEditor::VisualShaderEditor() {
node_filter->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_sbox_input));
node_filter->set_h_size_flags(SIZE_EXPAND_FILL);
node_filter->set_placeholder(TTR("Search"));
node_filter->set_accessibility_name(TTRC("Search"));
tools = memnew(MenuButton);
filter_hb->add_child(tools);
tools->set_tooltip_text(TTR("Options"));
tools->set_accessibility_name(TTRC("Options"));
tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_tools_menu_option));
tools->get_popup()->add_item(TTR("Expand All"), EXPAND_ALL);
tools->get_popup()->add_item(TTR("Collapse All"), COLLAPSE_ALL);
@ -6819,6 +6890,7 @@ VisualShaderEditor::VisualShaderEditor() {
varying_type->add_item("Vector4");
varying_type->add_item("Boolean");
varying_type->add_item("Transform");
varying_type->set_accessibility_name(TTRC("Varying Type"));
varying_type->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_type_changed));
varying_name = memnew(LineEdit);
@ -6832,6 +6904,7 @@ VisualShaderEditor::VisualShaderEditor() {
hb->add_child(varying_mode);
varying_mode->add_item("Vertex -> [Fragment, Light]");
varying_mode->add_item("Fragment -> Light");
varying_mode->set_accessibility_name(TTRC("Varying Mode"));
varying_mode->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_mode_changed));
varying_error_label = memnew(Label);
@ -7623,12 +7696,15 @@ public:
}
void _item_selected(int p_item) {
editor->call_deferred(SNAME("_input_select_item"), input, get_item_text(p_item));
editor->call_deferred(SNAME("_input_select_item"), input, get_item_metadata(p_item));
}
void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeInput> &p_input) {
set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
editor = p_editor;
input = p_input;
Ref<Texture2D> type_icon[] = {
EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
@ -7641,13 +7717,16 @@ public:
EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)),
};
add_item("[None]");
add_item(TTR("[None]"));
set_item_metadata(-1, "[None]");
int to_select = -1;
for (int i = 0; i < input->get_input_index_count(); i++) {
if (input->get_input_name() == input->get_input_index_name(i)) {
to_select = i + 1;
}
add_icon_item(type_icon[input->get_input_index_type(i)], input->get_input_index_name(i));
set_item_metadata(-1, input->get_input_index_name(i));
}
if (to_select >= 0) {
@ -7672,10 +7751,12 @@ public:
}
void _item_selected(int p_item) {
editor->call_deferred(SNAME("_varying_select_item"), varying, get_item_text(p_item));
editor->call_deferred(SNAME("_varying_select_item"), varying, get_item_metadata(p_item));
}
void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeVarying> &p_varying, VisualShader::Type p_type) {
set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
editor = p_editor;
varying = p_varying;
@ -7692,7 +7773,8 @@ public:
bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
add_item("[None]");
add_item(TTR("[None]"));
set_item_metadata(-1, "[None]");
int to_select = -1;
for (int i = 0, j = 0; i < varying->get_varyings_count(); i++) {
@ -7726,6 +7808,7 @@ public:
to_select = i - j + 1;
}
add_icon_item(type_icon[varying->get_varying_type_by_index(i)], varying->get_varying_name_by_index(i));
set_item_metadata(-1, varying->get_varying_name_by_index(i));
}
if (to_select >= 0) {
@ -7752,10 +7835,12 @@ public:
}
void _item_selected(int p_item) {
editor->call_deferred(SNAME("_parameter_ref_select_item"), parameter_ref, get_item_text(p_item));
editor->call_deferred(SNAME("_parameter_ref_select_item"), parameter_ref, get_item_metadata(p_item));
}
void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeParameterRef> &p_parameter_ref) {
set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
editor = p_editor;
parameter_ref = p_parameter_ref;
@ -7772,13 +7857,16 @@ public:
EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)),
};
add_item("[None]");
add_item(TTR("[None]"));
set_item_metadata(-1, "[None]");
int to_select = -1;
for (int i = 0; i < p_parameter_ref->get_parameters_count(); i++) {
if (p_parameter_ref->get_parameter_name() == p_parameter_ref->get_parameter_name_by_index(i)) {
to_select = i + 1;
}
add_icon_item(type_icon[p_parameter_ref->get_parameter_type_by_index(i)], p_parameter_ref->get_parameter_name_by_index(i));
set_item_metadata(-1, p_parameter_ref->get_parameter_name_by_index(i));
}
if (to_select >= 0) {
@ -7967,7 +8055,7 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par
}
Vector<StringName> properties = p_node->get_editable_properties();
if (properties.size() == 0) {
if (properties.is_empty()) {
return nullptr;
}
@ -7984,7 +8072,7 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par
}
}
if (pinfo.size() == 0) {
if (pinfo.is_empty()) {
return nullptr;
}
@ -8126,6 +8214,7 @@ void EditorPropertyVisualShaderMode::set_option_button_clip(bool p_enable) {
EditorPropertyVisualShaderMode::EditorPropertyVisualShaderMode() {
options = memnew(OptionButton);
options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
options->set_clip_text(true);
add_child(options);
add_focusable(options);