summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-02-15 15:44:55 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-02-15 15:44:55 +0100
commit09df8f4a560b69d44e676ec8ec1f6b8fd866cd5e (patch)
treed8613fcfe320e3b95af942bd8ebb59b25b812425
parent17944bbb3a96ed8ef2a963aa0269d80cbcd40af0 (diff)
parent9fa2355ceffefe3991e16ef4c3957f433fadd881 (diff)
downloadredot-engine-09df8f4a560b69d44e676ec8ec1f6b8fd866cd5e.tar.gz
Merge pull request #87952 from paulloz/dotnet/byebye-signal-callback-generation
Disable signal callback generation in C#
-rw-r--r--core/object/script_language.h1
-rw-r--r--core/object/script_language_extension.cpp1
-rw-r--r--core/object/script_language_extension.h1
-rw-r--r--doc/classes/ScriptLanguageExtension.xml5
-rw-r--r--editor/connections_dialog.cpp23
-rw-r--r--editor/connections_dialog.h2
-rw-r--r--editor/plugins/script_editor_plugin.cpp4
-rw-r--r--editor/plugins/script_text_editor.cpp9
-rw-r--r--modules/mono/csharp_script.cpp21
-rw-r--r--modules/mono/csharp_script.h1
10 files changed, 50 insertions, 18 deletions
diff --git a/core/object/script_language.h b/core/object/script_language.h
index 4075c6d593..4217bc9f96 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -257,6 +257,7 @@ public:
virtual bool can_inherit_from_file() const { return false; }
virtual int find_function(const String &p_function, const String &p_code) const = 0;
virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const = 0;
+ virtual bool can_make_function() const { return true; }
virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; }
virtual bool overrides_external_editor() { return false; }
diff --git a/core/object/script_language_extension.cpp b/core/object/script_language_extension.cpp
index be62cabe25..3a9b171f28 100644
--- a/core/object/script_language_extension.cpp
+++ b/core/object/script_language_extension.cpp
@@ -109,6 +109,7 @@ void ScriptLanguageExtension::_bind_methods() {
GDVIRTUAL_BIND(_can_inherit_from_file);
GDVIRTUAL_BIND(_find_function, "function", "code");
GDVIRTUAL_BIND(_make_function, "class_name", "function_name", "function_args");
+ GDVIRTUAL_BIND(_can_make_function);
GDVIRTUAL_BIND(_open_in_external_editor, "script", "line", "column");
GDVIRTUAL_BIND(_overrides_external_editor);
diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h
index cae2dd3f80..b7222a159a 100644
--- a/core/object/script_language_extension.h
+++ b/core/object/script_language_extension.h
@@ -373,6 +373,7 @@ public:
EXBIND2RC(int, find_function, const String &, const String &)
EXBIND3RC(String, make_function, const String &, const String &, const PackedStringArray &)
+ EXBIND0RC(bool, can_make_function)
EXBIND3R(Error, open_in_external_editor, const Ref<Script> &, int, int)
EXBIND0R(bool, overrides_external_editor)
diff --git a/doc/classes/ScriptLanguageExtension.xml b/doc/classes/ScriptLanguageExtension.xml
index e2ad1ca3e4..778e456646 100644
--- a/doc/classes/ScriptLanguageExtension.xml
+++ b/doc/classes/ScriptLanguageExtension.xml
@@ -34,6 +34,11 @@
<description>
</description>
</method>
+ <method name="_can_make_function" qualifiers="virtual const">
+ <return type="bool" />
+ <description>
+ </description>
+ </method>
<method name="_complete_code" qualifiers="virtual const">
<return type="Dictionary" />
<param index="0" name="code" type="String" />
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp
index e022294277..6ad8dae3b4 100644
--- a/editor/connections_dialog.cpp
+++ b/editor/connections_dialog.cpp
@@ -178,6 +178,7 @@ void ConnectDialog::_tree_node_selected() {
set_dst_method(generate_method_callback_name(source, signal, current));
}
_update_method_tree();
+ _update_warning_label();
_update_ok_enabled();
}
@@ -433,6 +434,23 @@ void ConnectDialog::_update_ok_enabled() {
get_ok_button()->set_disabled(false);
}
+void ConnectDialog::_update_warning_label() {
+ Ref<Script> scr = source->get_node(dst_path)->get_script();
+ if (scr.is_null()) {
+ warning_label->set_visible(false);
+ return;
+ }
+
+ ScriptLanguage *language = scr->get_language();
+ if (language->can_make_function()) {
+ warning_label->set_visible(false);
+ return;
+ }
+
+ warning_label->set_text(vformat(TTR("%s: Callback code won't be generated, please add it manually."), language->get_name()));
+ warning_label->set_visible(true);
+}
+
void ConnectDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -617,6 +635,7 @@ void ConnectDialog::init(const ConnectionData &p_cd, const PackedStringArray &p_
void ConnectDialog::popup_dialog(const String p_for_signal) {
from_signal->set_text(p_for_signal);
+ warning_label->add_theme_color_override("font_color", warning_label->get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
error_label->add_theme_color_override("font_color", error_label->get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
filter_nodes->clear();
@@ -694,6 +713,10 @@ ConnectDialog::ConnectDialog() {
connect_to_label = Object::cast_to<Label>(vbc_left->get_child(mc->get_index() - 1));
vbc_left->add_child(tree);
+ warning_label = memnew(Label);
+ vbc_left->add_child(warning_label);
+ warning_label->hide();
+
error_label = memnew(Label);
error_label->set_text(TTR("Scene does not contain any script."));
vbc_left->add_child(error_label);
diff --git a/editor/connections_dialog.h b/editor/connections_dialog.h
index a99f0dd0fe..4f628d5685 100644
--- a/editor/connections_dialog.h
+++ b/editor/connections_dialog.h
@@ -134,6 +134,7 @@ private:
CheckButton *advanced = nullptr;
Vector<Control *> bind_controls;
+ Label *warning_label = nullptr;
Label *error_label = nullptr;
void ok_pressed() override;
@@ -155,6 +156,7 @@ private:
void _remove_bind();
void _advanced_pressed();
void _update_ok_enabled();
+ void _update_warning_label();
protected:
void _notification(int p_what);
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index c8e65e98a7..335aa33c4a 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -2726,6 +2726,10 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const
Ref<Script> scr = p_obj->get_script();
ERR_FAIL_COND(!scr.is_valid());
+ if (!scr->get_language()->can_make_function()) {
+ return;
+ }
+
EditorNode::get_singleton()->push_item(scr.ptr());
for (int i = 0; i < tab_container->get_tab_count(); i++) {
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 06aedecd0e..9fbeab494e 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -345,14 +345,19 @@ void ScriptTextEditor::reload_text() {
}
void ScriptTextEditor::add_callback(const String &p_function, PackedStringArray p_args) {
+ ScriptLanguage *language = script->get_language();
+ if (!language->can_make_function()) {
+ return;
+ }
+
String code = code_editor->get_text_editor()->get_text();
- int pos = script->get_language()->find_function(p_function, code);
+ int pos = language->find_function(p_function, code);
code_editor->get_text_editor()->remove_secondary_carets();
if (pos == -1) {
//does not exist
code_editor->get_text_editor()->deselect();
pos = code_editor->get_text_editor()->get_line_count() + 2;
- String func = script->get_language()->make_function("", p_function, p_args);
+ String func = language->make_function("", p_function, p_args);
//code=code+func;
code_editor->get_text_editor()->set_caret_line(pos + 1);
code_editor->get_text_editor()->set_caret_column(1000000); //none shall be that big
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 6f234a31fa..0345eebef6 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -516,22 +516,11 @@ static String variant_type_to_managed_name(const String &p_var_type_name) {
}
String CSharpLanguage::make_function(const String &, const String &p_name, const PackedStringArray &p_args) const {
- // FIXME
- // - Due to Godot's API limitation this just appends the function to the end of the file
- // - Use fully qualified name if there is ambiguity
- String s = "private void " + p_name + "(";
- for (int i = 0; i < p_args.size(); i++) {
- const String &arg = p_args[i];
-
- if (i > 0) {
- s += ", ";
- }
-
- s += variant_type_to_managed_name(arg.get_slice(":", 1)) + " " + escape_csharp_keyword(arg.get_slice(":", 0));
- }
- s += ")\n{\n // Replace with function body.\n}\n";
-
- return s;
+ // The make_function() API does not work for C# scripts.
+ // It will always append the generated function at the very end of the script. In C#, it will break compilation by
+ // appending code after the final closing bracket (either the class' or the namespace's).
+ // To prevent issues, we have can_make_function() returning false, and make_function() is never implemented.
+ return String();
}
#else
String CSharpLanguage::make_function(const String &, const String &, const PackedStringArray &) const {
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index ae0111bd50..99e6ebf2e3 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -514,6 +514,7 @@ public:
return -1;
}
String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override;
+ virtual bool can_make_function() const override { return false; }
virtual String _get_indentation() const;
/* TODO? */ void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override {}
/* TODO */ void add_global_constant(const StringName &p_variable, const Variant &p_value) override {}