diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 19 | ||||
-rw-r--r-- | editor/editor_node.h | 5 | ||||
-rw-r--r-- | editor/editor_plugin.cpp | 6 | ||||
-rw-r--r-- | editor/editor_plugin.h | 5 | ||||
-rw-r--r-- | editor/editor_plugin_settings.cpp | 36 | ||||
-rw-r--r-- | editor/editor_plugin_settings.h | 9 | ||||
-rw-r--r-- | editor/plugin_config_dialog.cpp | 230 | ||||
-rw-r--r-- | editor/plugin_config_dialog.h | 71 | ||||
-rw-r--r-- | editor/project_settings_editor.cpp | 4 | ||||
-rw-r--r-- | editor/project_settings_editor.h | 1 |
10 files changed, 385 insertions, 1 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 05fbf7aa76..c59882b677 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -408,6 +408,18 @@ void EditorNode::_notification(int p_what) { } } +void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_name) { + Ref<Script> script = Object::cast_to<Script>(p_script); + if (script.is_null()) + return; + if (p_activate_name.length()) { + set_addon_plugin_enabled(p_activate_name, true); + } + project_settings->update_plugins(); + project_settings->hide(); + push_item(script.operator->()); +} + void EditorNode::_fs_changed() { for (Set<FileDialog *>::Element *E = file_dialogs.front(); E; E = E->next()) { @@ -2540,6 +2552,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled) EditorPlugin *ep = memnew(EditorPlugin); ep->set_script(script.get_ref_ptr()); + ep->set_dir_cache(p_addon); plugin_addons[p_addon] = ep; add_editor_plugin(ep); @@ -4520,6 +4533,8 @@ void EditorNode::_bind_methods() { ClassDB::bind_method(D_METHOD("_resources_reimported"), &EditorNode::_resources_reimported); ClassDB::bind_method(D_METHOD("_bottom_panel_raise_toggled"), &EditorNode::_bottom_panel_raise_toggled); + ClassDB::bind_method(D_METHOD("_on_plugin_ready"), &EditorNode::_on_plugin_ready); + ClassDB::bind_method(D_METHOD("_video_driver_selected"), &EditorNode::_video_driver_selected); ADD_SIGNAL(MethodInfo("play_pressed")); @@ -5082,6 +5097,10 @@ EditorNode::EditorNode() { p->connect("id_pressed", this, "_menu_option"); p->add_item(TTR("Export"), FILE_EXPORT_PROJECT); + plugin_config_dialog = memnew(PluginConfigDialog); + plugin_config_dialog->connect("plugin_ready", this, "_on_plugin_ready"); + gui_base->add_child(plugin_config_dialog); + tool_menu = memnew(PopupMenu); tool_menu->set_name("Tools"); tool_menu->connect("index_pressed", this, "_tool_menu_option"); diff --git a/editor/editor_node.h b/editor/editor_node.h index b7224c9393..b6f1673d6a 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -56,6 +56,7 @@ #include "editor/inspector_dock.h" #include "editor/node_dock.h" #include "editor/pane_drag.h" +#include "editor/plugin_config_dialog.h" #include "editor/progress_dialog.h" #include "editor/project_export.h" #include "editor/project_settings_editor.h" @@ -256,6 +257,8 @@ private: ToolButton *search_button; TextureProgress *audio_vu; + PluginConfigDialog *plugin_config_dialog; + RichTextLabel *load_errors; AcceptDialog *load_error_dialog; @@ -415,6 +418,8 @@ private: void _tool_menu_option(int p_idx); void _update_debug_options(); + void _on_plugin_ready(Object *p_script, const String &p_activate_name); + void _fs_changed(); void _resources_reimported(const Vector<String> &p_resources); void _sources_changed(bool p_exist); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 843267d673..fcf56cdc09 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -309,6 +309,12 @@ void EditorPlugin::remove_autoload_singleton(const String &p_name) { EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_remove(p_name); } +Ref<ConfigFile> EditorPlugin::get_config() { + Ref<ConfigFile> cf = memnew(ConfigFile); + cf->load(_dir_cache.plus_file("plugin.cfg")); + return cf; +} + ToolButton *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) { ERR_FAIL_NULL_V(p_control, NULL); return EditorNode::get_singleton()->add_bottom_panel_item(p_title, p_control); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 72e21b2f7f..652a1c06da 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -115,6 +115,7 @@ class EditorPlugin : public Node { bool force_draw_over_forwarding_enabled; String last_main_screen_name; + String _dir_cache; protected: static void _bind_methods(); @@ -223,6 +224,10 @@ public: void add_autoload_singleton(const String &p_name, const String &p_path); void remove_autoload_singleton(const String &p_name); + void set_dir_cache(const String &p_dir) { _dir_cache = p_dir; } + String get_dir_cache() { return _dir_cache; } + Ref<ConfigFile> get_config(); + EditorPlugin(); virtual ~EditorPlugin(); }; diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index ea1e0fe99e..68f8ed6d94 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -41,6 +41,9 @@ void EditorPluginSettings::_notification(int p_what) { if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) { update_plugins(); + } else if (p_what == Node::NOTIFICATION_READY) { + plugin_config_dialog->connect("plugin_ready", EditorNode::get_singleton(), "_on_plugin_ready"); + plugin_list->connect("button_pressed", this, "_cell_button_pressed"); } } @@ -124,6 +127,7 @@ void EditorPluginSettings::update_plugins() { item->set_range_config(3, 0, 1, 1); item->set_text(3, "Inactive,Active"); item->set_editable(3, true); + item->add_button(4, get_icon("Edit", "EditorIcons"), BUTTON_PLUGIN_EDIT, false, TTR("Edit Plugin")); if (EditorNode::get_singleton()->is_addon_plugin_enabled(d)) { item->set_custom_color(3, get_color("success_color", "Editor")); @@ -164,17 +168,44 @@ void EditorPluginSettings::_plugin_activity_changed() { ti->set_custom_color(3, get_color("disabled_font_color", "Editor")); } +void EditorPluginSettings::_create_clicked() { + plugin_config_dialog->config(""); + plugin_config_dialog->popup_centered(); +} + +void EditorPluginSettings::_cell_button_pressed(Object *p_item, int p_column, int p_id) { + TreeItem *item = Object::cast_to<TreeItem>(p_item); + if (!item) + return; + if (p_id == BUTTON_PLUGIN_EDIT) { + if (p_column == 4) { + String dir = item->get_metadata(0); + plugin_config_dialog->config("res://addons/" + dir + "/plugin.cfg"); + plugin_config_dialog->popup_centered(); + } + } +} + void EditorPluginSettings::_bind_methods() { ClassDB::bind_method("update_plugins", &EditorPluginSettings::update_plugins); + ClassDB::bind_method("_create_clicked", &EditorPluginSettings::_create_clicked); ClassDB::bind_method("_plugin_activity_changed", &EditorPluginSettings::_plugin_activity_changed); + ClassDB::bind_method("_cell_button_pressed", &EditorPluginSettings::_cell_button_pressed); } EditorPluginSettings::EditorPluginSettings() { + plugin_config_dialog = memnew(PluginConfigDialog); + plugin_config_dialog->config(""); + add_child(plugin_config_dialog); + HBoxContainer *title_hb = memnew(HBoxContainer); title_hb->add_child(memnew(Label(TTR("Installed Plugins:")))); title_hb->add_spacer(); + create_plugin = memnew(Button(TTR("Create"))); + create_plugin->connect("pressed", this, "_create_clicked"); + title_hb->add_child(create_plugin); update_list = memnew(Button(TTR("Update"))); update_list->connect("pressed", this, "update_plugins"); title_hb->add_child(update_list); @@ -182,19 +213,22 @@ EditorPluginSettings::EditorPluginSettings() { plugin_list = memnew(Tree); plugin_list->set_v_size_flags(SIZE_EXPAND_FILL); - plugin_list->set_columns(4); + plugin_list->set_columns(5); plugin_list->set_column_titles_visible(true); plugin_list->set_column_title(0, TTR("Name:")); plugin_list->set_column_title(1, TTR("Version:")); plugin_list->set_column_title(2, TTR("Author:")); plugin_list->set_column_title(3, TTR("Status:")); + plugin_list->set_column_title(4, TTR("Edit:")); plugin_list->set_column_expand(0, true); plugin_list->set_column_expand(1, false); plugin_list->set_column_expand(2, false); plugin_list->set_column_expand(3, false); + plugin_list->set_column_expand(4, false); plugin_list->set_column_min_width(1, 100 * EDSCALE); plugin_list->set_column_min_width(2, 250 * EDSCALE); plugin_list->set_column_min_width(3, 80 * EDSCALE); + plugin_list->set_column_min_width(4, 40 * EDSCALE); plugin_list->set_hide_root(true); plugin_list->connect("item_edited", this, "_plugin_activity_changed"); diff --git a/editor/editor_plugin_settings.h b/editor/editor_plugin_settings.h index aacbd05dd4..310cab699f 100644 --- a/editor/editor_plugin_settings.h +++ b/editor/editor_plugin_settings.h @@ -31,6 +31,7 @@ #ifndef EDITORPLUGINSETTINGS_H #define EDITORPLUGINSETTINGS_H +#include "editor/plugin_config_dialog.h"; #include "editor_data.h" #include "property_editor.h" #include "scene/gui/dialogs.h" @@ -40,11 +41,19 @@ class EditorPluginSettings : public VBoxContainer { GDCLASS(EditorPluginSettings, VBoxContainer); + enum { + BUTTON_PLUGIN_EDIT + }; + + PluginConfigDialog *plugin_config_dialog; + Button *create_plugin; Button *update_list; Tree *plugin_list; bool updating; void _plugin_activity_changed(); + void _create_clicked(); + void _cell_button_pressed(Object *p_item, int p_column, int p_id); protected: void _notification(int p_what); diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp new file mode 100644 index 0000000000..418936ac9f --- /dev/null +++ b/editor/plugin_config_dialog.cpp @@ -0,0 +1,230 @@ +/*************************************************************************/ +/* plugin_config_dialog.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 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 "plugin_config_dialog.h" +#include "core/io/config_file.h" +#include "core/os/dir_access.h" +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "modules/gdscript/gdscript.h" +#include "scene/gui/grid_container.h" + +void PluginConfigDialog::_clear_fields() { + name_edit->set_text(""); + subfolder_edit->set_text(""); + desc_edit->set_text(""); + author_edit->set_text(""); + version_edit->set_text(""); + script_edit->set_text(""); +} + +void PluginConfigDialog::_on_confirmed() { + + String path = "res://addons/" + subfolder_edit->get_text(); + + if (!_edit_mode) { + DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); + if (!d || d->make_dir_recursive(path) != OK) + return; + } + + Ref<ConfigFile> cf = memnew(ConfigFile); + cf->set_value("plugin", "name", name_edit->get_text()); + cf->set_value("plugin", "description", desc_edit->get_text()); + cf->set_value("plugin", "author", author_edit->get_text()); + cf->set_value("plugin", "version", version_edit->get_text()); + cf->set_value("plugin", "script", script_edit->get_text()); + + cf->save(path.plus_file("plugin.cfg")); + + if (!_edit_mode) { + String type = script_option_edit->get_item_text(script_option_edit->get_selected()); + + Ref<Script> script; + + if (type == GDScriptLanguage::get_singleton()->get_name()) { + Ref<GDScript> gdscript = memnew(GDScript); + gdscript->set_source_code( + "tool\n" + "extends EditorPlugin\n" + "\n" + "func _enter_tree():\n" + "\tpass"); + String script_path = path.plus_file(script_edit->get_text()); + gdscript->set_path(script_path); + ResourceSaver::save(script_path, gdscript); + script = gdscript; + } + //TODO: other languages + + emit_signal("plugin_ready", script.operator->(), active_edit->is_pressed() ? name_edit->get_text() : ""); + } else { + EditorNode::get_singleton()->get_project_settings()->update_plugins(); + } + _clear_fields(); +} + +void PluginConfigDialog::_on_cancelled() { + _clear_fields(); +} + +void PluginConfigDialog::_on_required_text_changed(const String &p_text) { + String ext = script_option_edit->get_item_metadata(script_option_edit->get_selected()); + get_ok()->set_disabled(script_edit->get_text().get_basename().empty() || script_edit->get_text().get_extension() != ext || name_edit->get_text().empty()); +} + +void PluginConfigDialog::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_READY: { + connect("confirmed", this, "_on_confirmed"); + get_cancel()->connect("pressed", this, "_on_cancelled"); + } break; + } +} + +void PluginConfigDialog::config(const String &p_config_path) { + if (p_config_path.length()) { + Ref<ConfigFile> cf = memnew(ConfigFile); + print_line(p_config_path); + cf->load(p_config_path); + + name_edit->set_text(cf->get_value("plugin", "name", "")); + subfolder_edit->set_text(p_config_path.get_base_dir().get_basename().get_file()); + desc_edit->set_text(cf->get_value("plugin", "description", "")); + author_edit->set_text(cf->get_value("plugin", "author", "")); + version_edit->set_text(cf->get_value("plugin", "version", "")); + script_edit->set_text(cf->get_value("plugin", "script", "")); + + _edit_mode = true; + active_edit->hide(); + Object::cast_to<Label>(active_edit->get_parent()->get_child(active_edit->get_index() - 1))->hide(); + subfolder_edit->hide(); + Object::cast_to<Label>(subfolder_edit->get_parent()->get_child(subfolder_edit->get_index() - 1))->hide(); + set_title(TTR("Edit a Plugin")); + } else { + _clear_fields(); + _edit_mode = false; + active_edit->show(); + Object::cast_to<Label>(active_edit->get_parent()->get_child(active_edit->get_index() - 1))->show(); + subfolder_edit->show(); + Object::cast_to<Label>(subfolder_edit->get_parent()->get_child(subfolder_edit->get_index() - 1))->show(); + set_title(TTR("Create a Plugin")); + } + get_ok()->set_disabled(!_edit_mode); + get_ok()->set_text(_edit_mode ? TTR("Update") : TTR("Create")); +} + +void PluginConfigDialog::_bind_methods() { + ClassDB::bind_method("_on_required_text_changed", &PluginConfigDialog::_on_required_text_changed); + ClassDB::bind_method("_on_confirmed", &PluginConfigDialog::_on_confirmed); + ClassDB::bind_method("_on_cancelled", &PluginConfigDialog::_on_cancelled); + ADD_SIGNAL(MethodInfo("plugin_ready", PropertyInfo(Variant::STRING, "script_path", PROPERTY_HINT_NONE, ""), PropertyInfo(Variant::STRING, "activate_name"))); +} + +PluginConfigDialog::PluginConfigDialog() { + get_ok()->set_disabled(true); + set_hide_on_ok(true); + + GridContainer *grid = memnew(GridContainer); + grid->set_columns(2); + add_child(grid); + + Label *name_lb = memnew(Label); + name_lb->set_text(TTR("Plugin Name:")); + grid->add_child(name_lb); + + name_edit = memnew(LineEdit); + name_edit->connect("text_changed", this, "_on_required_text_changed"); + name_edit->set_placeholder("MyPlugin"); + grid->add_child(name_edit); + + Label *subfolder_lb = memnew(Label); + subfolder_lb->set_text(TTR("Subfolder:")); + grid->add_child(subfolder_lb); + + subfolder_edit = memnew(LineEdit); + subfolder_edit->set_placeholder("\"my_plugin\" -> res://addons/my_plugin"); + grid->add_child(subfolder_edit); + + Label *desc_lb = memnew(Label); + desc_lb->set_text(TTR("Description:")); + grid->add_child(desc_lb); + + desc_edit = memnew(TextEdit); + desc_edit->set_custom_minimum_size(Size2(400.0f, 50.0f)); + grid->add_child(desc_edit); + + Label *author_lb = memnew(Label); + author_lb->set_text(TTR("Author:")); + grid->add_child(author_lb); + + author_edit = memnew(LineEdit); + author_edit->set_placeholder("Godette"); + grid->add_child(author_edit); + + Label *version_lb = memnew(Label); + version_lb->set_text(TTR("Version:")); + grid->add_child(version_lb); + + version_edit = memnew(LineEdit); + version_edit->set_placeholder("1.0"); + grid->add_child(version_edit); + + Label *script_option_lb = memnew(Label); + script_option_lb->set_text(TTR("Language:")); + grid->add_child(script_option_lb); + + script_option_edit = memnew(OptionButton); + script_option_edit->add_item(GDScriptLanguage::get_singleton()->get_name()); + script_option_edit->set_item_metadata(0, GDScriptLanguage::get_singleton()->get_extension()); + script_option_edit->select(0); + //TODO: add other languages + grid->add_child(script_option_edit); + + Label *script_lb = memnew(Label); + script_lb->set_text(TTR("Script Name:")); + grid->add_child(script_lb); + + script_edit = memnew(LineEdit); + script_edit->connect("text_changed", this, "_on_required_text_changed"); + script_edit->set_placeholder("\"plugin.gd\" -> res://addons/my_plugin/plugin.gd"); + grid->add_child(script_edit); + + Label *active_lb = memnew(Label); + active_lb->set_text(TTR("Activate now?")); + grid->add_child(active_lb); + + active_edit = memnew(CheckBox); + active_edit->set_pressed(true); + grid->add_child(active_edit); +} + +PluginConfigDialog::~PluginConfigDialog() { +} diff --git a/editor/plugin_config_dialog.h b/editor/plugin_config_dialog.h new file mode 100644 index 0000000000..2d321a479d --- /dev/null +++ b/editor/plugin_config_dialog.h @@ -0,0 +1,71 @@ +/*************************************************************************/ +/* plugin_config_dialog.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 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 PLUGIN_CONFIG_DIALOG_H +#define PLUGIN_CONFIG_DIALOG_H + +#include "scene/gui/check_box.h" +#include "scene/gui/dialogs.h" +#include "scene/gui/line_edit.h" +#include "scene/gui/option_button.h" +#include "scene/gui/text_edit.h" + +class PluginConfigDialog : public ConfirmationDialog { + + GDCLASS(PluginConfigDialog, ConfirmationDialog); + + LineEdit *name_edit; + LineEdit *subfolder_edit; + TextEdit *desc_edit; + LineEdit *author_edit; + LineEdit *version_edit; + OptionButton *script_option_edit; + LineEdit *script_edit; + CheckBox *active_edit; + + bool _edit_mode; + + void _clear_fields(); + void _on_confirmed(); + void _on_cancelled(); + void _on_required_text_changed(const String &p_text); + +protected: + virtual void _notification(int p_what); + static void _bind_methods(); + +public: + void config(const String &p_plugin_dir_name); + + PluginConfigDialog(); + ~PluginConfigDialog(); +}; + +#endif // PLUGIN_CONFIG_DIALOG_H diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 2b2e03ce38..fb349961c8 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -806,6 +806,10 @@ void ProjectSettingsEditor::popup_project_settings() { plugin_settings->update_plugins(); } +void ProjectSettingsEditor::update_plugins() { + plugin_settings->update_plugins(); +} + void ProjectSettingsEditor::_item_selected(const String &p_path) { String selected_path = p_path; diff --git a/editor/project_settings_editor.h b/editor/project_settings_editor.h index 3b74ae1909..2f3d331a3e 100644 --- a/editor/project_settings_editor.h +++ b/editor/project_settings_editor.h @@ -188,6 +188,7 @@ public: static ProjectSettingsEditor *get_singleton() { return singleton; } void popup_project_settings(); void set_plugins_page(); + void update_plugins(); EditorAutoloadSettings *get_autoload_settings() { return autoload_settings; } |