diff options
Diffstat (limited to 'editor/plugin_config_dialog.cpp')
-rw-r--r-- | editor/plugin_config_dialog.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 971e746509..4e3333f528 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* 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 */ @@ -33,9 +33,15 @@ #include "core/os/dir_access.h" #include "editor/editor_node.h" #include "editor/editor_plugin.h" -#include "modules/gdscript/gdscript.h" +#include "editor/editor_scale.h" +#include "editor/project_settings_editor.h" #include "scene/gui/grid_container.h" +#include "modules/modules_enabled.gen.h" +#ifdef MODULE_GDSCRIPT_ENABLED +#include "modules/gdscript/gdscript.h" +#endif + void PluginConfigDialog::_clear_fields() { name_edit->set_text(""); subfolder_edit->set_text(""); @@ -73,29 +79,38 @@ void PluginConfigDialog::_on_confirmed() { // TODO Use script templates. Right now, this code won't add the 'tool' annotation to other languages. // TODO Better support script languages with named classes (has_named_classes). + // FIXME: It's hacky to have hardcoded access to the GDScript module here. + // The editor code should not have to know what languages are enabled. +#ifdef MODULE_GDSCRIPT_ENABLED if (lang_name == GDScriptLanguage::get_singleton()->get_name()) { // Hard-coded GDScript template to keep usability until we use script templates. - Ref<GDScript> gdscript = memnew(GDScript); + Ref<Script> gdscript = memnew(GDScript); gdscript->set_source_code( "tool\n" "extends EditorPlugin\n" "\n" - "func _enter_tree():\n" - "\tpass\n" "\n" - "func _exit_tree():\n" - "\tpass\n"); + "func _enter_tree()%VOID_RETURN%:\n" + "%TS%pass\n" + "\n" + "\n" + "func _exit_tree()%VOID_RETURN%:\n" + "%TS%pass\n"); + GDScriptLanguage::get_singleton()->make_template("", "", gdscript); String script_path = path.plus_file(script_edit->get_text()); gdscript->set_path(script_path); ResourceSaver::save(script_path, gdscript); script = gdscript; } else { +#endif String script_path = path.plus_file(script_edit->get_text()); String class_name = script_path.get_file().get_basename(); script = ScriptServer::get_language(lang_idx)->get_template(class_name, "EditorPlugin"); script->set_path(script_path); ResourceSaver::save(script_path, script); +#ifdef MODULE_GDSCRIPT_ENABLED } +#endif emit_signal("plugin_ready", script.operator->(), active_edit->is_pressed() ? subfolder_edit->get_text() : ""); } else { @@ -117,8 +132,8 @@ void PluginConfigDialog::_on_required_text_changed(const String &) { void PluginConfigDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - connect("confirmed", this, "_on_confirmed"); - get_cancel()->connect("pressed", this, "_on_cancelled"); + connect_compat("confirmed", this, "_on_confirmed"); + get_cancel()->connect_compat("pressed", this, "_on_cancelled"); } break; case NOTIFICATION_POST_POPUP: { @@ -179,7 +194,7 @@ PluginConfigDialog::PluginConfigDialog() { grid->add_child(name_lb); name_edit = memnew(LineEdit); - name_edit->connect("text_changed", this, "_on_required_text_changed"); + name_edit->connect_compat("text_changed", this, "_on_required_text_changed"); name_edit->set_placeholder("MyPlugin"); grid->add_child(name_edit); @@ -224,9 +239,11 @@ PluginConfigDialog::PluginConfigDialog() { for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptLanguage *lang = ScriptServer::get_language(i); script_option_edit->add_item(lang->get_name()); +#ifdef MODULE_GDSCRIPT_ENABLED if (lang == GDScriptLanguage::get_singleton()) { default_lang = i; } +#endif } script_option_edit->select(default_lang); grid->add_child(script_option_edit); @@ -236,7 +253,7 @@ PluginConfigDialog::PluginConfigDialog() { grid->add_child(script_lb); script_edit = memnew(LineEdit); - script_edit->connect("text_changed", this, "_on_required_text_changed"); + script_edit->connect_compat("text_changed", this, "_on_required_text_changed"); script_edit->set_placeholder("\"plugin.gd\" -> res://addons/my_plugin/plugin.gd"); grid->add_child(script_edit); |