2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_plugin_settings.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 14:46:12 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2016-02-28 03:10:44 +01:00
|
|
|
#include "editor_plugin_settings.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "editor_node.h"
|
|
|
|
#include "global_config.h"
|
2016-02-28 03:10:44 +01:00
|
|
|
#include "io/config_file.h"
|
|
|
|
#include "os/file_access.h"
|
|
|
|
#include "os/main_loop.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/margin_container.h"
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
void EditorPluginSettings::_notification(int p_what) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) {
|
2016-02-28 03:10:44 +01:00
|
|
|
update_plugins();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPluginSettings::update_plugins() {
|
|
|
|
|
|
|
|
plugin_list->clear();
|
|
|
|
|
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
Error err = da->change_dir("res://addons");
|
2017-03-05 16:44:50 +01:00
|
|
|
if (err != OK) {
|
2016-02-28 03:10:44 +01:00
|
|
|
memdelete(da);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating = true;
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
TreeItem *root = plugin_list->create_item();
|
|
|
|
|
|
|
|
da->list_dir_begin();
|
|
|
|
|
|
|
|
String d = da->get_next();
|
|
|
|
|
|
|
|
Vector<String> plugins;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (d != String()) {
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
bool dir = da->current_is_dir();
|
2017-03-05 16:44:50 +01:00
|
|
|
String path = "res://addons/" + d + "/plugin.cfg";
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
if (dir && FileAccess::exists(path)) {
|
|
|
|
|
|
|
|
plugins.push_back(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
d = da->get_next();
|
|
|
|
}
|
|
|
|
|
|
|
|
da->list_dir_end();
|
|
|
|
memdelete(da);
|
|
|
|
|
|
|
|
plugins.sort();
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
Vector<String> active_plugins = GlobalConfig::get_singleton()->get("plugins/active");
|
2016-02-28 03:10:44 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < plugins.size(); i++) {
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
Ref<ConfigFile> cf;
|
|
|
|
cf.instance();
|
2017-03-05 16:44:50 +01:00
|
|
|
String path = "res://addons/" + plugins[i] + "/plugin.cfg";
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
Error err = cf->load(path);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (err != OK) {
|
|
|
|
WARN_PRINTS("Can't load plugin config: " + path);
|
|
|
|
} else if (!cf->has_section_key("plugin", "name")) {
|
|
|
|
WARN_PRINTS("Plugin misses plugin/name: " + path);
|
|
|
|
} else if (!cf->has_section_key("plugin", "author")) {
|
|
|
|
WARN_PRINTS("Plugin misses plugin/author: " + path);
|
|
|
|
} else if (!cf->has_section_key("plugin", "version")) {
|
|
|
|
WARN_PRINTS("Plugin misses plugin/version: " + path);
|
|
|
|
} else if (!cf->has_section_key("plugin", "description")) {
|
|
|
|
WARN_PRINTS("Plugin misses plugin/description: " + path);
|
|
|
|
} else if (!cf->has_section_key("plugin", "script")) {
|
|
|
|
WARN_PRINTS("Plugin misses plugin/script: " + path);
|
2016-02-28 03:10:44 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
String d = plugins[i];
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = cf->get_value("plugin", "name");
|
|
|
|
String author = cf->get_value("plugin", "author");
|
|
|
|
String version = cf->get_value("plugin", "version");
|
|
|
|
String description = cf->get_value("plugin", "description");
|
|
|
|
String script = cf->get_value("plugin", "script");
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
TreeItem *item = plugin_list->create_item(root);
|
2017-03-05 16:44:50 +01:00
|
|
|
item->set_text(0, name);
|
|
|
|
item->set_tooltip(0, "Name: " + name + "\nPath: " + path + "\nMain Script: " + script);
|
|
|
|
item->set_metadata(0, d);
|
|
|
|
item->set_text(1, version);
|
|
|
|
item->set_metadata(1, script);
|
|
|
|
item->set_text(2, author);
|
|
|
|
item->set_metadata(2, description);
|
|
|
|
item->set_cell_mode(3, TreeItem::CELL_MODE_RANGE);
|
|
|
|
item->set_range_config(3, 0, 1, 1);
|
|
|
|
item->set_text(3, "Inactive,Active");
|
|
|
|
item->set_editable(3, true);
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
if (EditorNode::get_singleton()->is_addon_plugin_enabled(d)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
item->set_custom_color(3, Color(0.2, 1, 0.2));
|
|
|
|
item->set_range(3, 1);
|
2016-02-28 03:10:44 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
item->set_custom_color(3, Color(1, 0.2, 0.2));
|
|
|
|
item->set_range(3, 0);
|
2016-02-28 03:10:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating = false;
|
2016-02-28 03:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPluginSettings::_plugin_activity_changed() {
|
|
|
|
|
|
|
|
if (updating)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
TreeItem *ti = plugin_list->get_edited();
|
2016-02-28 03:10:44 +01:00
|
|
|
ERR_FAIL_COND(!ti);
|
|
|
|
bool active = ti->get_range(3);
|
|
|
|
String name = ti->get_metadata(0);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
EditorNode::get_singleton()->set_addon_plugin_enabled(name, active);
|
2016-02-28 03:10:44 +01:00
|
|
|
|
|
|
|
bool is_active = EditorNode::get_singleton()->is_addon_plugin_enabled(name);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (is_active != active) {
|
|
|
|
updating = true;
|
|
|
|
ti->set_range(3, is_active ? 1 : 0);
|
|
|
|
updating = false;
|
2016-02-28 03:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_active)
|
2017-03-05 16:44:50 +01:00
|
|
|
ti->set_custom_color(3, Color(0.2, 1, 0.2));
|
2016-02-28 03:10:44 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
ti->set_custom_color(3, Color(1, 0.2, 0.2));
|
2016-02-28 03:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPluginSettings::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method("update_plugins", &EditorPluginSettings::update_plugins);
|
|
|
|
ClassDB::bind_method("_plugin_activity_changed", &EditorPluginSettings::_plugin_activity_changed);
|
2016-02-28 03:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorPluginSettings::EditorPluginSettings() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *title_hb = memnew(HBoxContainer);
|
|
|
|
title_hb->add_child(memnew(Label(TTR("Installed Plugins:"))));
|
2016-02-28 03:10:44 +01:00
|
|
|
title_hb->add_spacer();
|
2017-03-05 16:44:50 +01:00
|
|
|
update_list = memnew(Button(TTR("Update")));
|
|
|
|
update_list->connect("pressed", this, "update_plugins");
|
2016-02-28 03:10:44 +01:00
|
|
|
title_hb->add_child(update_list);
|
|
|
|
add_child(title_hb);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
plugin_list = memnew(Tree);
|
2016-02-28 03:10:44 +01:00
|
|
|
plugin_list->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
plugin_list->set_columns(4);
|
|
|
|
plugin_list->set_column_titles_visible(true);
|
2017-03-05 16:44:50 +01:00
|
|
|
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_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_min_width(1, 100);
|
|
|
|
plugin_list->set_column_min_width(2, 250);
|
|
|
|
plugin_list->set_column_min_width(3, 80);
|
2016-02-28 03:10:44 +01:00
|
|
|
plugin_list->set_hide_root(true);
|
2017-03-05 16:44:50 +01:00
|
|
|
plugin_list->connect("item_edited", this, "_plugin_activity_changed");
|
2016-02-28 03:10:44 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MarginContainer *mc = memnew(MarginContainer);
|
2016-02-28 03:10:44 +01:00
|
|
|
mc->add_child(plugin_list);
|
|
|
|
mc->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
|
|
|
add_child(mc);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating = false;
|
2016-02-28 03:10:44 +01:00
|
|
|
}
|