mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 05:19:50 +01:00
Implement addon discovering for the plugin refresher module.
This commit is contained in:
parent
60a2fcf304
commit
91387222ce
@ -1,5 +1,8 @@
|
||||
|
||||
#include "plugin_refresher.h"
|
||||
#include "core/io/config_file.h"
|
||||
#include "core/os/dir_access.h"
|
||||
#include "core/os/file_access.h"
|
||||
#include "core/os/input_event.h"
|
||||
|
||||
#include "editor/project_settings_editor.h"
|
||||
@ -32,6 +35,82 @@ void PluginRefresher::_popup() {
|
||||
_selector_dialog->popup_centered();
|
||||
}
|
||||
void PluginRefresher::_refresh() {
|
||||
String selected_plugin;
|
||||
|
||||
if (_currently_selected_addon != -1) {
|
||||
selected_plugin = _plugins[_currently_selected_addon].folder;
|
||||
} else {
|
||||
selected_plugin = EditorSettings::get_singleton()->get_project_metadata("plugin_refresher", "plugin", "");
|
||||
}
|
||||
|
||||
_currently_selected_addon = -1;
|
||||
|
||||
_option_button->clear();
|
||||
_plugins.clear();
|
||||
|
||||
DirAccess *dir = DirAccess::open("res://addons/");
|
||||
|
||||
if (!dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<String> addon_dirs;
|
||||
|
||||
dir->list_dir_begin();
|
||||
|
||||
String file = dir->get_next();
|
||||
while (file != "") {
|
||||
if (file == "." || file == "..") {
|
||||
file = dir->get_next();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dir->current_is_dir()) {
|
||||
addon_dirs.push_back(file);
|
||||
}
|
||||
|
||||
file = dir->get_next();
|
||||
}
|
||||
|
||||
dir->list_dir_end();
|
||||
|
||||
memdelete(dir);
|
||||
|
||||
addon_dirs.sort();
|
||||
|
||||
for (int i = 0; i < addon_dirs.size(); ++i) {
|
||||
String addon_dir = addon_dirs[i];
|
||||
|
||||
String cp = "res://addons/";
|
||||
cp += addon_dir;
|
||||
cp += "/plugin.cfg";
|
||||
|
||||
Ref<ConfigFile> cf;
|
||||
cf.instance();
|
||||
if (cf->load(cp) != OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!cf->has_section("plugin")) {
|
||||
continue;
|
||||
}
|
||||
String addon_name = cf->get_value("plugin", "name", addon_dir);
|
||||
|
||||
PluginEntry p;
|
||||
p.name = addon_name;
|
||||
p.folder = addon_dir;
|
||||
|
||||
_plugins.push_back(p);
|
||||
_option_button->add_item(addon_name, i);
|
||||
|
||||
if (addon_dir == selected_plugin) {
|
||||
_currently_selected_addon = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (_currently_selected_addon != -1) {
|
||||
_option_button->select(_currently_selected_addon);
|
||||
}
|
||||
}
|
||||
|
||||
void PluginRefresher::_set_enabled(const bool p_enabled) {
|
||||
@ -54,11 +133,21 @@ void PluginRefresher::_on_disable_button_pressed() {
|
||||
set_enabled(false);
|
||||
}
|
||||
|
||||
void PluginRefresher::_on_popup_confirmed() {
|
||||
void PluginRefresher::_on_option_selected(const int id) {
|
||||
_currently_selected_addon = id;
|
||||
|
||||
String selected_plugin = _plugins[_currently_selected_addon].folder;
|
||||
|
||||
EditorSettings::get_singleton()->set_project_metadata("plugin_refresher", "plugin", selected_plugin);
|
||||
}
|
||||
|
||||
void PluginRefresher::_refresh_selected() {
|
||||
//if addon got deleted do popup
|
||||
}
|
||||
|
||||
void PluginRefresher::pressed() {
|
||||
if (_button == BUTTON_LEFT) {
|
||||
_refresh_selected();
|
||||
} else if (_button == BUTTON_RIGHT) {
|
||||
_popup();
|
||||
}
|
||||
@ -74,6 +163,7 @@ void PluginRefresher::_gui_input(Ref<InputEvent> p_event) {
|
||||
}
|
||||
|
||||
PluginRefresher::PluginRefresher() {
|
||||
_currently_selected_addon = -1;
|
||||
_button = 0;
|
||||
set_button_mask(BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT);
|
||||
set_enabled_focus_mode(FOCUS_NONE);
|
||||
@ -83,7 +173,6 @@ PluginRefresher::PluginRefresher() {
|
||||
add_child(_selector_dialog);
|
||||
_selector_dialog->set_title("Plugin refresher");
|
||||
_selector_dialog->set_custom_minimum_size(Size2(300, 0));
|
||||
_selector_dialog->connect("confirmed", this, "_on_popup_confirmed");
|
||||
|
||||
VBoxContainer *main_container = memnew(VBoxContainer);
|
||||
_selector_dialog->add_child(main_container);
|
||||
@ -110,6 +199,7 @@ PluginRefresher::PluginRefresher() {
|
||||
|
||||
_option_button = memnew(OptionButton);
|
||||
main_container->add_child(_option_button);
|
||||
_option_button->connect("item_selected", this, "_on_option_selected");
|
||||
}
|
||||
|
||||
PluginRefresher::~PluginRefresher() {
|
||||
@ -119,5 +209,5 @@ void PluginRefresher::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_set_enabled", "enabled"), &PluginRefresher::_set_enabled);
|
||||
ClassDB::bind_method(D_METHOD("_on_plugins_button_pressed"), &PluginRefresher::_on_plugins_button_pressed);
|
||||
ClassDB::bind_method(D_METHOD("_on_disable_button_pressed"), &PluginRefresher::_on_disable_button_pressed);
|
||||
ClassDB::bind_method(D_METHOD("_on_popup_confirmed"), &PluginRefresher::_on_popup_confirmed);
|
||||
ClassDB::bind_method(D_METHOD("_on_option_selected", "id"), &PluginRefresher::_on_option_selected);
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ protected:
|
||||
void _set_enabled(const bool p_enabled);
|
||||
void _on_plugins_button_pressed();
|
||||
void _on_disable_button_pressed();
|
||||
void _on_popup_confirmed();
|
||||
void _on_option_selected(const int id);
|
||||
void _refresh_selected();
|
||||
|
||||
void pressed();
|
||||
void _gui_input(Ref<InputEvent> p_event);
|
||||
@ -40,6 +41,14 @@ protected:
|
||||
CheckBox *_enabler_check_box;
|
||||
AcceptDialog *_selector_dialog;
|
||||
OptionButton *_option_button;
|
||||
int _currently_selected_addon;
|
||||
|
||||
struct PluginEntry {
|
||||
String name;
|
||||
String folder;
|
||||
};
|
||||
|
||||
Vector<PluginEntry> _plugins;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user