2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* resource_preloader_editor_plugin.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) */
|
2014-02-10 02:10:30 +01: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "resource_preloader_editor_plugin.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2017-03-05 14:21:25 +01:00
|
|
|
#include "editor/editor_settings.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "io/resource_loader.h"
|
2017-07-30 22:53:40 +02:00
|
|
|
#include "project_settings.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
void ResourcePreloaderEditor::_gui_input(Ref<InputEvent> p_event) {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditor::_notification(int p_what) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == NOTIFICATION_FIXED_PROCESS) {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
|
|
|
load->set_icon(get_icon("Folder", "EditorIcons"));
|
|
|
|
_delete->set_icon(get_icon("Del", "EditorIcons"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == NOTIFICATION_READY) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//NodePath("/root")->connect("node_removed", this,"_node_removed",Vector<Variant>(),true);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ResourcePreloaderEditor::_files_load_request(const Vector<String> &p_paths) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_paths.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-18 11:26:02 +01:00
|
|
|
String path = p_paths[i];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-17 05:30:13 +01:00
|
|
|
RES resource;
|
|
|
|
resource = ResourceLoader::load(path);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-17 05:30:13 +01:00
|
|
|
if (resource.is_null()) {
|
2016-05-04 03:25:37 +02:00
|
|
|
dialog->set_text(TTR("ERROR: Couldn't load resource!"));
|
|
|
|
dialog->set_title(TTR("Error!"));
|
2016-05-21 01:18:35 +02:00
|
|
|
//dialog->get_cancel()->set_text("Close");
|
2016-05-04 03:25:37 +02:00
|
|
|
dialog->get_ok()->set_text(TTR("Close"));
|
2016-03-17 05:30:13 +01:00
|
|
|
dialog->popup_centered_minsize();
|
|
|
|
return; ///beh should show an error i guess
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 04:51:09 +01:00
|
|
|
String basename = path.get_file().get_basename();
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = basename;
|
|
|
|
int counter = 1;
|
|
|
|
while (preloader->has_resource(name)) {
|
2016-03-17 05:30:13 +01:00
|
|
|
counter++;
|
2017-03-05 16:44:50 +01:00
|
|
|
name = basename + " " + itos(counter);
|
2016-03-17 05:30:13 +01:00
|
|
|
}
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Add Resource"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(preloader, "add_resource", name, resource);
|
|
|
|
undo_redo->add_undo_method(preloader, "remove_resource", name);
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2016-03-17 05:30:13 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditor::_load_pressed() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
loading_scene = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
file->clear_filters();
|
|
|
|
List<String> extensions;
|
2017-03-05 16:44:50 +01:00
|
|
|
ResourceLoader::get_recognized_extensions_for_type("", &extensions);
|
|
|
|
for (int i = 0; i < extensions.size(); i++)
|
|
|
|
file->add_filter("*." + extensions[i]);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-17 05:30:13 +01:00
|
|
|
file->set_mode(EditorFileDialog::MODE_OPEN_FILES);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
file->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditor::_item_edited() {
|
|
|
|
|
|
|
|
if (!tree->get_selected())
|
|
|
|
return;
|
|
|
|
|
|
|
|
TreeItem *s = tree->get_selected();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tree->get_selected_column() == 0) {
|
2014-02-10 02:10:30 +01:00
|
|
|
// renamed
|
2017-03-05 16:44:50 +01:00
|
|
|
String old_name = s->get_metadata(0);
|
|
|
|
String new_name = s->get_text(0);
|
|
|
|
if (old_name == new_name)
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (new_name == "" || new_name.find("\\") != -1 || new_name.find("/") != -1 || preloader->has_resource(new_name)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
s->set_text(0, old_name);
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RES samp = preloader->get_resource(old_name);
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Rename Resource"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(preloader, "remove_resource", old_name);
|
|
|
|
undo_redo->add_do_method(preloader, "add_resource", new_name, samp);
|
|
|
|
undo_redo->add_undo_method(preloader, "remove_resource", new_name);
|
|
|
|
undo_redo->add_undo_method(preloader, "add_resource", old_name, samp);
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditor::_delete_confirm_pressed() {
|
|
|
|
|
|
|
|
if (!tree->get_selected())
|
|
|
|
return;
|
|
|
|
|
|
|
|
String to_remove = tree->get_selected()->get_text(0);
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Delete Resource"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(preloader, "remove_resource", to_remove);
|
|
|
|
undo_redo->add_undo_method(preloader, "add_resource", to_remove, preloader->get_resource(to_remove));
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditor::_paste_pressed() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RES r = EditorSettings::get_singleton()->get_resource_clipboard();
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!r.is_valid()) {
|
2016-05-04 03:25:37 +02:00
|
|
|
dialog->set_text(TTR("Resource clipboard is empty!"));
|
|
|
|
dialog->set_title(TTR("Error!"));
|
2016-05-21 01:18:35 +02:00
|
|
|
//dialog->get_cancel()->set_text("Close");
|
2016-05-04 03:25:37 +02:00
|
|
|
dialog->get_ok()->set_text(TTR("Close"));
|
2015-04-08 19:02:13 +02:00
|
|
|
dialog->popup_centered_minsize();
|
2014-02-10 02:10:30 +01:00
|
|
|
return; ///beh should show an error i guess
|
|
|
|
}
|
|
|
|
|
|
|
|
String name = r->get_name();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (name == "")
|
|
|
|
name = r->get_path().get_file();
|
|
|
|
if (name == "")
|
|
|
|
name = r->get_class();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String basename = name;
|
2017-03-05 16:44:50 +01:00
|
|
|
int counter = 1;
|
|
|
|
while (preloader->has_resource(name)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
counter++;
|
2017-03-05 16:44:50 +01:00
|
|
|
name = basename + " " + itos(counter);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Paste Resource"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(preloader, "add_resource", name, r);
|
|
|
|
undo_redo->add_undo_method(preloader, "remove_resource", name);
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditor::_delete_pressed() {
|
|
|
|
|
|
|
|
if (!tree->get_selected())
|
|
|
|
return;
|
|
|
|
|
|
|
|
_delete_confirm_pressed(); //it has undo.. why bother with a dialog..
|
|
|
|
/*
|
2016-05-19 00:08:12 +02:00
|
|
|
dialog->set_title("Confirm...");
|
|
|
|
dialog->set_text("Remove Resource '"+tree->get_selected()->get_text(0)+"' ?");
|
|
|
|
//dialog->get_cancel()->set_text("Cancel");
|
2014-02-10 02:10:30 +01:00
|
|
|
//dialog->get_ok()->show();
|
2016-05-19 00:08:12 +02:00
|
|
|
dialog->get_ok()->set_text("Remove");
|
2014-02-10 02:10:30 +01:00
|
|
|
dialog->popup_centered(Size2(300,60));*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditor::_update_library() {
|
|
|
|
|
|
|
|
tree->clear();
|
|
|
|
tree->set_hide_root(true);
|
|
|
|
TreeItem *root = tree->create_item(NULL);
|
|
|
|
|
|
|
|
List<StringName> rnames;
|
|
|
|
preloader->get_resource_list(&rnames);
|
|
|
|
|
|
|
|
List<String> names;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<StringName>::Element *E = rnames.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
names.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
names.sort();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<String>::Element *E = names.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
TreeItem *ti = tree->create_item(root);
|
2017-03-05 16:44:50 +01:00
|
|
|
ti->set_cell_mode(0, TreeItem::CELL_MODE_STRING);
|
|
|
|
ti->set_editable(0, true);
|
|
|
|
ti->set_selectable(0, true);
|
|
|
|
ti->set_text(0, E->get());
|
|
|
|
ti->set_metadata(0, E->get());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
RES r = preloader->get_resource(E->get());
|
|
|
|
|
|
|
|
ERR_CONTINUE(r.is_null());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ti->set_tooltip(0, r->get_path());
|
2017-01-03 03:03:46 +01:00
|
|
|
String type = r->get_class();
|
2017-03-05 16:44:50 +01:00
|
|
|
ti->set_text(1, type);
|
|
|
|
ti->set_selectable(1, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (has_icon(type, "EditorIcons"))
|
|
|
|
ti->set_icon(1, get_icon(type, "EditorIcons"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//player->add_resource("default",resource);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ResourcePreloaderEditor::edit(ResourcePreloader *p_preloader) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
preloader = p_preloader;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (p_preloader) {
|
|
|
|
_update_library();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
hide();
|
|
|
|
set_fixed_process(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
TreeItem *ti = tree->get_item_at_pos(p_point);
|
2016-05-15 04:48:23 +02:00
|
|
|
if (!ti)
|
|
|
|
return Variant();
|
|
|
|
|
|
|
|
String name = ti->get_metadata(0);
|
|
|
|
|
|
|
|
RES res = preloader->get_resource(name);
|
|
|
|
if (!res.is_valid())
|
|
|
|
return Variant();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return EditorNode::get_singleton()->drag_resource(res, p_from);
|
2016-05-15 04:48:23 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ResourcePreloaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
|
2016-05-15 04:48:23 +02:00
|
|
|
|
|
|
|
Dictionary d = p_data;
|
|
|
|
|
|
|
|
if (!d.has("type"))
|
|
|
|
return false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (d.has("from") && (Object *)(d["from"]) == tree)
|
2016-05-15 04:48:23 +02:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (String(d["type"]) == "resource" && d.has("resource")) {
|
|
|
|
RES r = d["resource"];
|
2016-05-15 04:48:23 +02:00
|
|
|
|
|
|
|
return r.is_valid();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (String(d["type"]) == "files") {
|
2016-05-15 04:48:23 +02:00
|
|
|
|
|
|
|
Vector<String> files = d["files"];
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (files.size() == 0)
|
2016-05-15 04:48:23 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ResourcePreloaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
|
2016-05-15 04:48:23 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!can_drop_data_fw(p_point, p_data, p_from))
|
2016-05-15 04:48:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
Dictionary d = p_data;
|
|
|
|
|
|
|
|
if (!d.has("type"))
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (String(d["type"]) == "resource" && d.has("resource")) {
|
|
|
|
RES r = d["resource"];
|
2016-05-15 04:48:23 +02:00
|
|
|
|
|
|
|
if (r.is_valid()) {
|
|
|
|
|
|
|
|
String basename;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (r->get_name() != "") {
|
|
|
|
basename = r->get_name();
|
2016-05-15 04:48:23 +02:00
|
|
|
} else if (r->get_path().is_resource_file()) {
|
2017-01-14 04:51:09 +01:00
|
|
|
basename = r->get_path().get_basename();
|
2016-05-15 04:48:23 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
basename = "Resource";
|
2016-05-15 04:48:23 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = basename;
|
|
|
|
int counter = 0;
|
|
|
|
while (preloader->has_resource(name)) {
|
2016-05-15 04:48:23 +02:00
|
|
|
counter++;
|
2017-03-05 16:44:50 +01:00
|
|
|
name = basename + "_" + itos(counter);
|
2016-05-15 04:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Add Resource"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(preloader, "add_resource", name, r);
|
|
|
|
undo_redo->add_undo_method(preloader, "remove_resource", name);
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2016-05-15 04:48:23 +02:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (String(d["type"]) == "files") {
|
2016-05-15 04:48:23 +02:00
|
|
|
|
|
|
|
Vector<String> files = d["files"];
|
|
|
|
|
|
|
|
_files_load_request(files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ResourcePreloaderEditor::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_gui_input"), &ResourcePreloaderEditor::_gui_input);
|
|
|
|
ClassDB::bind_method(D_METHOD("_load_pressed"), &ResourcePreloaderEditor::_load_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_item_edited"), &ResourcePreloaderEditor::_item_edited);
|
|
|
|
ClassDB::bind_method(D_METHOD("_delete_pressed"), &ResourcePreloaderEditor::_delete_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_paste_pressed"), &ResourcePreloaderEditor::_paste_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_delete_confirm_pressed"), &ResourcePreloaderEditor::_delete_confirm_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_files_load_request"), &ResourcePreloaderEditor::_files_load_request);
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_library"), &ResourcePreloaderEditor::_update_library);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ResourcePreloaderEditor::get_drag_data_fw);
|
|
|
|
ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ResourcePreloaderEditor::can_drop_data_fw);
|
|
|
|
ClassDB::bind_method(D_METHOD("drop_data_fw"), &ResourcePreloaderEditor::drop_data_fw);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourcePreloaderEditor::ResourcePreloaderEditor() {
|
|
|
|
|
2017-08-04 21:41:31 +02:00
|
|
|
//add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(vbc);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
vbc->add_child(hbc);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
load = memnew(Button);
|
2016-05-04 03:25:37 +02:00
|
|
|
load->set_tooltip(TTR("Load Resource"));
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(load);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_delete = memnew(Button);
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(_delete);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
paste = memnew(Button);
|
2016-05-04 03:25:37 +02:00
|
|
|
paste->set_text(TTR("Paste"));
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(paste);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
file = memnew(EditorFileDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(file);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
tree = memnew(Tree);
|
2014-02-10 02:10:30 +01:00
|
|
|
tree->set_columns(2);
|
2017-03-05 16:44:50 +01:00
|
|
|
tree->set_column_min_width(0, 3);
|
|
|
|
tree->set_column_min_width(1, 1);
|
|
|
|
tree->set_column_expand(0, true);
|
|
|
|
tree->set_column_expand(1, true);
|
2014-02-10 02:10:30 +01:00
|
|
|
tree->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2016-05-15 04:48:23 +02:00
|
|
|
tree->set_drag_forwarding(this);
|
2014-02-10 02:10:30 +01:00
|
|
|
vbc->add_child(tree);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
dialog = memnew(AcceptDialog);
|
|
|
|
add_child(dialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
load->connect("pressed", this, "_load_pressed");
|
|
|
|
_delete->connect("pressed", this, "_delete_pressed");
|
|
|
|
paste->connect("pressed", this, "_paste_pressed");
|
|
|
|
file->connect("files_selected", this, "_files_load_request");
|
2014-02-10 02:10:30 +01:00
|
|
|
//dialog->connect("confirmed", this,"_delete_confirm_pressed");
|
2017-03-05 16:44:50 +01:00
|
|
|
tree->connect("item_edited", this, "_item_edited");
|
|
|
|
loading_scene = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
|
|
|
preloader_editor->set_undo_redo(&get_undo_redo());
|
2017-08-24 22:58:51 +02:00
|
|
|
ResourcePreloader *s = Object::cast_to<ResourcePreloader>(p_object);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
preloader_editor->edit(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResourcePreloaderEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
return p_object->is_class("ResourcePreloader");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcePreloaderEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
|
|
|
|
if (p_visible) {
|
2016-01-18 00:03:57 +01:00
|
|
|
//preloader_editor->show();
|
|
|
|
button->show();
|
|
|
|
editor->make_bottom_panel_item_visible(preloader_editor);
|
2017-01-14 12:26:56 +01:00
|
|
|
//preloader_editor->set_process(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
|
|
|
|
2017-01-13 14:45:50 +01:00
|
|
|
if (preloader_editor->is_visible_in_tree())
|
2016-01-18 00:03:57 +01:00
|
|
|
editor->hide_bottom_panel();
|
|
|
|
button->hide();
|
|
|
|
//preloader_editor->hide();
|
2017-01-14 12:26:56 +01:00
|
|
|
//preloader_editor->set_process(false);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourcePreloaderEditorPlugin::ResourcePreloaderEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
editor = p_node;
|
|
|
|
preloader_editor = memnew(ResourcePreloaderEditor);
|
|
|
|
preloader_editor->set_custom_minimum_size(Size2(0, 250));
|
2016-01-18 00:03:57 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
button = editor->add_bottom_panel_item("ResourcePreloader", preloader_editor);
|
2016-01-18 00:03:57 +01:00
|
|
|
button->hide();
|
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//preloader_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END);
|
|
|
|
//preloader_editor->set_margin( MARGIN_TOP, 120 );
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ResourcePreloaderEditorPlugin::~ResourcePreloaderEditorPlugin() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|