diff options
Diffstat (limited to 'editor/plugins')
19 files changed, 1854 insertions, 1776 deletions
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 43d6c22bcc..5b71f51b0f 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -367,10 +367,6 @@ void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resou int flg = 0; if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) flg |= ResourceSaver::FLAG_COMPRESS; - /* - if (EditorSettings::get_singleton()->get("filesystem/on_save/save_paths_as_relative")) - flg |= ResourceSaver::FLAG_RELATIVE_PATHS; - */ String path = ProjectSettings::get_singleton()->localize_path(p_path); Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); @@ -380,7 +376,6 @@ void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resou accept->popup_centered_minsize(); return; } - //EditorFileSystem::get_singleton()->update_file(path,p_resource->get_type()); ((Resource *)p_resource.ptr())->set_path(path); editor->emit_signal("resource_saved", p_resource); diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp new file mode 100644 index 0000000000..c01c2de6b7 --- /dev/null +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -0,0 +1,1486 @@ +/*************************************************************************/ +/* asset_library_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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 "asset_library_editor_plugin.h" + +#include "editor_node.h" +#include "editor_settings.h" +#include "io/json.h" + +void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost) { + + title->set_text(p_title); + asset_id = p_asset_id; + category->set_text(p_category); + category_id = p_category_id; + author->set_text(p_author); + author_id = p_author_id; + price->set_text(p_cost); + + for (int i = 0; i < 5; i++) { + if (i < p_rating) + stars[i]->set_texture(get_icon("RatingStar", "EditorIcons")); + else + stars[i]->set_texture(get_icon("RatingNoStar", "EditorIcons")); + } +} + +void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Texture> &p_image) { + + ERR_FAIL_COND(p_type != EditorAssetLibrary::IMAGE_QUEUE_ICON); + ERR_FAIL_COND(p_index != 0); + + icon->set_normal_texture(p_image); +} + +void EditorAssetLibraryItem::_notification(int p_what) { + + if (p_what == NOTIFICATION_ENTER_TREE) { + + icon->set_normal_texture(get_icon("GodotAssetDefault", "EditorIcons")); + category->add_color_override("font_color", Color(0.5, 0.5, 0.5)); + author->add_color_override("font_color", Color(0.5, 0.5, 0.5)); + } +} + +void EditorAssetLibraryItem::_asset_clicked() { + + emit_signal("asset_selected", asset_id); +} + +void EditorAssetLibraryItem::_category_clicked() { + + emit_signal("category_selected", category_id); +} +void EditorAssetLibraryItem::_author_clicked() { + + emit_signal("author_selected", author_id); +} + +void EditorAssetLibraryItem::_bind_methods() { + + ClassDB::bind_method("set_image", &EditorAssetLibraryItem::set_image); + ClassDB::bind_method("_asset_clicked", &EditorAssetLibraryItem::_asset_clicked); + ClassDB::bind_method("_category_clicked", &EditorAssetLibraryItem::_category_clicked); + ClassDB::bind_method("_author_clicked", &EditorAssetLibraryItem::_author_clicked); + ADD_SIGNAL(MethodInfo("asset_selected")); + ADD_SIGNAL(MethodInfo("category_selected")); + ADD_SIGNAL(MethodInfo("author_selected")); +} + +EditorAssetLibraryItem::EditorAssetLibraryItem() { + + Ref<StyleBoxEmpty> border; + border.instance(); + border->set_default_margin(MARGIN_LEFT, 5); + border->set_default_margin(MARGIN_RIGHT, 5); + border->set_default_margin(MARGIN_BOTTOM, 5); + border->set_default_margin(MARGIN_TOP, 5); + add_style_override("panel", border); + + HBoxContainer *hb = memnew(HBoxContainer); + add_child(hb); + + icon = memnew(TextureButton); + icon->set_default_cursor_shape(CURSOR_POINTING_HAND); + icon->connect("pressed", this, "_asset_clicked"); + + hb->add_child(icon); + + VBoxContainer *vb = memnew(VBoxContainer); + + hb->add_child(vb); + vb->set_h_size_flags(SIZE_EXPAND_FILL); + + title = memnew(LinkButton); + title->set_text("My Awesome Addon"); + title->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); + title->connect("pressed", this, "_asset_clicked"); + vb->add_child(title); + + category = memnew(LinkButton); + category->set_text("Editor Tools"); + category->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); + category->connect("pressed", this, "_category_clicked"); + vb->add_child(category); + + author = memnew(LinkButton); + author->set_text("Johny Tolengo"); + author->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); + author->connect("pressed", this, "_author_clicked"); + vb->add_child(author); + + HBoxContainer *rating_hb = memnew(HBoxContainer); + vb->add_child(rating_hb); + + for (int i = 0; i < 5; i++) { + stars[i] = memnew(TextureRect); + rating_hb->add_child(stars[i]); + } + price = memnew(Label); + price->set_text(TTR("Free")); + vb->add_child(price); + + set_custom_minimum_size(Size2(250, 100)); + set_h_size_flags(SIZE_EXPAND_FILL); + + set_mouse_filter(MOUSE_FILTER_PASS); +} + +////////////////////////////////////////////////////////////////////////////// + +void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const Ref<Texture> &p_image) { + + switch (p_type) { + + case EditorAssetLibrary::IMAGE_QUEUE_ICON: { + + item->call("set_image", p_type, p_index, p_image); + icon = p_image; + } break; + case EditorAssetLibrary::IMAGE_QUEUE_THUMBNAIL: { + + for (int i = 0; i < preview_images.size(); i++) { + if (preview_images[i].id == p_index) { + preview_images[i].button->set_icon(p_image); + break; + } + } + //item->call("set_image",p_type,p_index,p_image); + } break; + case EditorAssetLibrary::IMAGE_QUEUE_SCREENSHOT: { + + for (int i = 0; i < preview_images.size(); i++) { + if (preview_images[i].id == p_index) { + preview_images[i].image = p_image; + if (preview_images[i].button->is_pressed()) { + _preview_click(p_index); + } + break; + } + } + //item->call("set_image",p_type,p_index,p_image); + } break; + } +} +void EditorAssetLibraryItemDescription::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + previews_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); + desc_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); + } break; + } +} +void EditorAssetLibraryItemDescription::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_image"), &EditorAssetLibraryItemDescription::set_image); + ClassDB::bind_method(D_METHOD("_link_click"), &EditorAssetLibraryItemDescription::_link_click); + ClassDB::bind_method(D_METHOD("_preview_click"), &EditorAssetLibraryItemDescription::_preview_click); +} + +void EditorAssetLibraryItemDescription::_link_click(const String &p_url) { + ERR_FAIL_COND(!p_url.begins_with("http")); + OS::get_singleton()->shell_open(p_url); +} + +void EditorAssetLibraryItemDescription::_preview_click(int p_id) { + for (int i = 0; i < preview_images.size(); i++) { + if (preview_images[i].id == p_id) { + preview_images[i].button->set_pressed(true); + if (!preview_images[i].is_video) { + if (preview_images[i].image.is_valid()) { + preview->set_texture(preview_images[i].image); + } + } else { + _link_click(preview_images[i].video_link); + } + } else { + preview_images[i].button->set_pressed(false); + } + } +} + +void EditorAssetLibraryItemDescription::configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost, int p_version, const String &p_version_string, const String &p_description, const String &p_download_url, const String &p_browse_url, const String &p_sha256_hash) { + + asset_id = p_asset_id; + title = p_title; + download_url = p_download_url; + sha256 = p_sha256_hash; + item->configure(p_title, p_asset_id, p_category, p_category_id, p_author, p_author_id, p_rating, p_cost); + description->clear(); + description->add_text(TTR("Version:") + " " + p_version_string + "\n"); + description->add_text(TTR("Contents:") + " "); + description->push_meta(p_browse_url); + description->add_text(TTR("View Files")); + description->pop(); + description->add_text("\n" + TTR("Description:") + "\n\n"); + description->append_bbcode(p_description); + set_title(p_title); +} + +void EditorAssetLibraryItemDescription::add_preview(int p_id, bool p_video, const String &p_url) { + + Preview preview; + preview.id = p_id; + preview.video_link = p_url; + preview.is_video = p_video; + preview.button = memnew(Button); + preview.button->set_flat(true); + preview.button->set_icon(get_icon("ThumbnailWait", "EditorIcons")); + preview.button->set_toggle_mode(true); + preview.button->connect("pressed", this, "_preview_click", varray(p_id)); + preview_hb->add_child(preview.button); + if (!p_video) { + preview.image = get_icon("ThumbnailWait", "EditorIcons"); + } + if (preview_images.size() == 0 && !p_video) { + _preview_click(p_id); + } + preview_images.push_back(preview); +} + +EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { + + VBoxContainer *vbox = memnew(VBoxContainer); + add_child(vbox); + + HBoxContainer *hbox = memnew(HBoxContainer); + vbox->add_child(hbox); + vbox->add_constant_override("separation", 15); + VBoxContainer *desc_vbox = memnew(VBoxContainer); + hbox->add_child(desc_vbox); + hbox->add_constant_override("separation", 15); + + item = memnew(EditorAssetLibraryItem); + + desc_vbox->add_child(item); + desc_vbox->set_custom_minimum_size(Size2(300, 0)); + + desc_bg = memnew(PanelContainer); + desc_vbox->add_child(desc_bg); + desc_bg->set_v_size_flags(SIZE_EXPAND_FILL); + + description = memnew(RichTextLabel); + description->connect("meta_clicked", this, "_link_click"); + desc_bg->add_child(description); + + preview = memnew(TextureRect); + preview->set_custom_minimum_size(Size2(640, 345)); + hbox->add_child(preview); + + previews_bg = memnew(PanelContainer); + vbox->add_child(previews_bg); + previews_bg->set_custom_minimum_size(Size2(0, 85)); + + previews = memnew(ScrollContainer); + previews_bg->add_child(previews); + previews->set_enable_v_scroll(false); + previews->set_enable_h_scroll(true); + preview_hb = memnew(HBoxContainer); + preview_hb->set_v_size_flags(SIZE_EXPAND_FILL); + + previews->add_child(preview_hb); + get_ok()->set_text(TTR("Install")); + get_cancel()->set_text(TTR("Close")); +} +/////////////////////////////////////////////////////////////////////////////////// + +void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) { + + String error_text; + print_line("COMPLETED: " + itos(p_status) + " code: " + itos(p_code) + " data size: " + itos(p_data.size())); + + switch (p_status) { + + case HTTPRequest::RESULT_CANT_RESOLVE: { + error_text = TTR("Can't resolve hostname:") + " " + host; + status->set_text(TTR("Can't resolve.")); + } break; + case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: + case HTTPRequest::RESULT_CONNECTION_ERROR: + case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: { + error_text = TTR("Connection error, please try again."); + status->set_text(TTR("Can't connect.")); + } break; + case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: + case HTTPRequest::RESULT_CANT_CONNECT: { + error_text = TTR("Can't connect to host:") + " " + host; + status->set_text(TTR("Can't connect.")); + } break; + case HTTPRequest::RESULT_NO_RESPONSE: { + error_text = TTR("No response from host:") + " " + host; + status->set_text(TTR("No response.")); + } break; + case HTTPRequest::RESULT_REQUEST_FAILED: { + error_text = TTR("Request failed, return code:") + " " + itos(p_code); + status->set_text(TTR("Req. Failed.")); + } break; + case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { + error_text = TTR("Request failed, too many redirects"); + status->set_text(TTR("Redirect Loop.")); + } break; + default: { + if (p_code != 200) { + error_text = TTR("Request failed, return code:") + " " + itos(p_code); + status->set_text(TTR("Failed:") + " " + itos(p_code)); + } else if (sha256 != "") { + String download_sha256 = FileAccess::get_sha256(download->get_download_file()); + if (sha256 != download_sha256) { + error_text = TTR("Bad download hash, assuming file has been tampered with.") + "\n"; + error_text += TTR("Expected:") + " " + sha256 + "\n" + TTR("Got:") + " " + download_sha256; + status->set_text(TTR("Failed sha256 hash check")); + } + } + } break; + } + + if (error_text != String()) { + download_error->set_text(TTR("Asset Download Error:") + "\n" + error_text); + download_error->popup_centered_minsize(); + return; + } + + progress->set_max(download->get_body_size()); + progress->set_value(download->get_downloaded_bytes()); + + print_line("max: " + itos(download->get_body_size()) + " bytes: " + itos(download->get_downloaded_bytes())); + install->set_disabled(false); + + progress->set_value(download->get_downloaded_bytes()); + + status->set_text(TTR("Success!") + " (" + String::humanize_size(download->get_downloaded_bytes()) + ")"); + set_process(false); +} + +void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asset_id, const Ref<Texture> &p_preview, const String &p_download_url, const String &p_sha256_hash) { + + title->set_text(p_title); + icon->set_texture(p_preview); + asset_id = p_asset_id; + if (!p_preview.is_valid()) + icon->set_texture(get_icon("GodotAssetDefault", "EditorIcons")); + host = p_download_url; + sha256 = p_sha256_hash; + asset_installer->connect("confirmed", this, "_close"); + dismiss->set_normal_texture(get_icon("Close", "EditorIcons")); + _make_request(); +} + +void EditorAssetLibraryItemDownload::_notification(int p_what) { + + if (p_what == NOTIFICATION_PROCESS) { + + progress->set_max(download->get_body_size()); + progress->set_value(download->get_downloaded_bytes()); + + int cstatus = download->get_http_client_status(); + + if (cstatus == HTTPClient::STATUS_BODY) + status->set_text(TTR("Fetching:") + " " + String::humanize_size(download->get_downloaded_bytes())); + + if (cstatus != prev_status) { + switch (cstatus) { + + case HTTPClient::STATUS_RESOLVING: { + status->set_text(TTR("Resolving..")); + } break; + case HTTPClient::STATUS_CONNECTING: { + status->set_text(TTR("Connecting..")); + } break; + case HTTPClient::STATUS_REQUESTING: { + status->set_text(TTR("Requesting..")); + } break; + default: {} + } + prev_status = cstatus; + } + } +} +void EditorAssetLibraryItemDownload::_close() { + + DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + da->remove(download->get_download_file()); //clean up removed file + memdelete(da); + queue_delete(); +} + +void EditorAssetLibraryItemDownload::_install() { + + String file = download->get_download_file(); + + if (external_install) { + emit_signal("install_asset", file, title->get_text()); + return; + } + + asset_installer->open(file, 1); +} + +void EditorAssetLibraryItemDownload::_make_request() { + download->cancel_request(); + download->set_download_file(EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("tmp_asset_" + itos(asset_id)) + ".zip"); + + Error err = download->request(host); + if (err != OK) { + status->set_text(TTR("Error making request")); + } else { + set_process(true); + } +} + +void EditorAssetLibraryItemDownload::_bind_methods() { + + ClassDB::bind_method("_http_download_completed", &EditorAssetLibraryItemDownload::_http_download_completed); + ClassDB::bind_method("_install", &EditorAssetLibraryItemDownload::_install); + ClassDB::bind_method("_close", &EditorAssetLibraryItemDownload::_close); + ClassDB::bind_method("_make_request", &EditorAssetLibraryItemDownload::_make_request); + + ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name"))); +} + +EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { + + HBoxContainer *hb = memnew(HBoxContainer); + add_child(hb); + icon = memnew(TextureRect); + hb->add_child(icon); + + VBoxContainer *vb = memnew(VBoxContainer); + hb->add_child(vb); + vb->set_h_size_flags(SIZE_EXPAND_FILL); + + HBoxContainer *title_hb = memnew(HBoxContainer); + vb->add_child(title_hb); + title = memnew(Label); + title_hb->add_child(title); + title->set_h_size_flags(SIZE_EXPAND_FILL); + + dismiss = memnew(TextureButton); + dismiss->connect("pressed", this, "_close"); + title_hb->add_child(dismiss); + + title->set_clip_text(true); + + vb->add_spacer(); + + status = memnew(Label(TTR("Idle"))); + vb->add_child(status); + status->add_color_override("font_color", Color(0.5, 0.5, 0.5)); + progress = memnew(ProgressBar); + vb->add_child(progress); + + HBoxContainer *hb2 = memnew(HBoxContainer); + vb->add_child(hb2); + hb2->add_spacer(); + + install = memnew(Button); + install->set_text(TTR("Install")); + install->set_disabled(true); + install->connect("pressed", this, "_install"); + + retry = memnew(Button); + retry->set_text(TTR("Retry")); + retry->connect("pressed", this, "_make_request"); + + hb2->add_child(retry); + hb2->add_child(install); + set_custom_minimum_size(Size2(250, 0)); + + download = memnew(HTTPRequest); + add_child(download); + download->connect("request_completed", this, "_http_download_completed"); + + download_error = memnew(AcceptDialog); + add_child(download_error); + download_error->set_title(TTR("Download Error")); + + asset_installer = memnew(EditorAssetInstaller); + add_child(asset_installer); + + prev_status = -1; + + external_install = false; +} + +//////////////////////////////////////////////////////////////////////////////// +void EditorAssetLibrary::_notification(int p_what) { + + switch (p_what) { + case NOTIFICATION_READY: { + + TextureRect *tf = memnew(TextureRect); + tf->set_texture(get_icon("Error", "EditorIcons")); + reverse->set_icon(get_icon("Sort", "EditorIcons")); + + error_hb->add_child(tf); + error_label->raise(); + } break; + + case NOTIFICATION_VISIBILITY_CHANGED: { + + if (is_visible()) { + _repository_changed(0); // Update when shown for the first time + } + } break; + + case NOTIFICATION_PROCESS: { + + HTTPClient::Status s = request->get_http_client_status(); + bool visible = s != HTTPClient::STATUS_DISCONNECTED; + + if (visible != load_status->is_visible()) { + load_status->set_visible(visible); + } + + if (visible) { + switch (s) { + + case HTTPClient::STATUS_RESOLVING: { + load_status->set_value(0.1); + } break; + case HTTPClient::STATUS_CONNECTING: { + load_status->set_value(0.2); + } break; + case HTTPClient::STATUS_REQUESTING: { + load_status->set_value(0.3); + } break; + case HTTPClient::STATUS_BODY: { + load_status->set_value(0.4); + } break; + default: {} + } + } + + bool no_downloads = downloads_hb->get_child_count() == 0; + if (no_downloads == downloads_scroll->is_visible()) { + downloads_scroll->set_visible(!no_downloads); + } + + } break; + case NOTIFICATION_THEME_CHANGED: { + + library_scroll_bg->add_style_override("panel", get_stylebox("bg", "Tree")); + } break; + } +} + +void EditorAssetLibrary::_install_asset() { + + ERR_FAIL_COND(!description); + + for (int i = 0; i < downloads_hb->get_child_count(); i++) { + + EditorAssetLibraryItemDownload *d = Object::cast_to<EditorAssetLibraryItemDownload>(downloads_hb->get_child(i)); + if (d && d->get_asset_id() == description->get_asset_id()) { + + if (EditorNode::get_singleton() != NULL) + EditorNode::get_singleton()->show_warning(TTR("Download for this asset is already in progress!")); + return; + } + } + + EditorAssetLibraryItemDownload *download = memnew(EditorAssetLibraryItemDownload); + downloads_hb->add_child(download); + download->configure(description->get_title(), description->get_asset_id(), description->get_preview_icon(), description->get_download_url(), description->get_sha256()); + + if (templates_only) { + download->set_external_install(true); + download->connect("install_asset", this, "_install_external_asset"); + } +} + +const char *EditorAssetLibrary::sort_key[SORT_MAX] = { + "rating", + "downloads", + "name", + "cost", + "updated" +}; + +const char *EditorAssetLibrary::sort_text[SORT_MAX] = { + "Rating", + "Downloads", + "Name", + "Cost", + "Updated" +}; + +const char *EditorAssetLibrary::support_key[SUPPORT_MAX] = { + "official", + "community", + "testing" +}; + +void EditorAssetLibrary::_select_author(int p_id) { + + //opemn author window +} + +void EditorAssetLibrary::_select_category(int p_id) { + + for (int i = 0; i < categories->get_item_count(); i++) { + + if (i == 0) + continue; + int id = categories->get_item_metadata(i); + if (id == p_id) { + categories->select(i); + _search(); + break; + } + } +} +void EditorAssetLibrary::_select_asset(int p_id) { + + _api_request("asset/" + itos(p_id), REQUESTING_ASSET); + + /* + if (description) { + memdelete(description); + } + + + description = memnew( EditorAssetLibraryItemDescription ); + add_child(description); + description->popup_centered_minsize();*/ +} + +void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByteArray &p_data, int p_queue_id) { + Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target); + + if (obj) { + bool image_set = false; + PoolByteArray image_data = p_data; + + if (use_cache) { + String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text()); + + FileAccess *file = FileAccess::open(cache_filename_base + ".data", FileAccess::READ); + + if (file) { + PoolByteArray cached_data; + int len = file->get_32(); + cached_data.resize(len); + + PoolByteArray::Write w = cached_data.write(); + file->get_buffer(w.ptr(), len); + + image_data = cached_data; + file->close(); + } + } + + int len = image_data.size(); + PoolByteArray::Read r = image_data.read(); + Ref<Image> image = Ref<Image>(memnew(Image(r.ptr(), len))); + + if (!image->empty()) { + float max_height = 10000; + switch (image_queue[p_queue_id].image_type) { + case IMAGE_QUEUE_ICON: max_height = 80; break; + case IMAGE_QUEUE_THUMBNAIL: max_height = 80; break; + case IMAGE_QUEUE_SCREENSHOT: max_height = 345; break; + } + float scale_ratio = max_height / image->get_height(); + if (scale_ratio < 1) { + image->resize(image->get_width() * scale_ratio, image->get_height() * scale_ratio, Image::INTERPOLATE_CUBIC); + } + + Ref<ImageTexture> tex; + tex.instance(); + tex->create_from_image(image); + + obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, tex); + image_set = true; + } + + if (!image_set && final) { + obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("ErrorSign", "EditorIcons")); + } + } +} + +void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data, int p_queue_id) { + + ERR_FAIL_COND(!image_queue.has(p_queue_id)); + + if (p_status == HTTPRequest::RESULT_SUCCESS) { + + print_line("GOT IMAGE YAY!"); + + if (p_code != HTTPClient::RESPONSE_NOT_MODIFIED) { + for (int i = 0; i < headers.size(); i++) { + if (headers[i].findn("ETag:") == 0) { // Save etag + String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text()); + String new_etag = headers[i].substr(headers[i].find(":") + 1, headers[i].length()).strip_edges(); + FileAccess *file; + + file = FileAccess::open(cache_filename_base + ".etag", FileAccess::WRITE); + if (file) { + file->store_line(new_etag); + file->close(); + } + + int len = p_data.size(); + PoolByteArray::Read r = p_data.read(); + file = FileAccess::open(cache_filename_base + ".data", FileAccess::WRITE); + if (file) { + file->store_32(len); + file->store_buffer(r.ptr(), len); + file->close(); + } + + break; + } + } + } + _image_update(p_code == HTTPClient::RESPONSE_NOT_MODIFIED, true, p_data, p_queue_id); + + } else { + WARN_PRINTS("Error getting PNG file for asset id " + itos(image_queue[p_queue_id].asset_id)); + Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target); + if (obj) { + obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("ErrorSign", "EditorIcons")); + } + } + + image_queue[p_queue_id].request->queue_delete(); + image_queue.erase(p_queue_id); + + _update_image_queue(); +} + +void EditorAssetLibrary::_update_image_queue() { + + int max_images = 2; + int current_images = 0; + + List<int> to_delete; + for (Map<int, ImageQueue>::Element *E = image_queue.front(); E; E = E->next()) { + if (!E->get().active && current_images < max_images) { + + String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + E->get().image_url.md5_text()); + Vector<String> headers; + + if (FileAccess::exists(cache_filename_base + ".etag") && FileAccess::exists(cache_filename_base + ".data")) { + FileAccess *file = FileAccess::open(cache_filename_base + ".etag", FileAccess::READ); + if (file) { + headers.push_back("If-None-Match: " + file->get_line()); + file->close(); + } + } + + print_line("REQUEST ICON FOR: " + itos(E->get().asset_id)); + Error err = E->get().request->request(E->get().image_url, headers); + if (err != OK) { + to_delete.push_back(E->key()); + } else { + E->get().active = true; + } + current_images++; + } else if (E->get().active) { + current_images++; + } + } + + while (to_delete.size()) { + image_queue[to_delete.front()->get()].request->queue_delete(); + image_queue.erase(to_delete.front()->get()); + to_delete.pop_front(); + } +} + +void EditorAssetLibrary::_request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index) { + + ImageQueue iq; + iq.image_url = p_image_url; + iq.image_index = p_image_index; + iq.image_type = p_type; + iq.request = memnew(HTTPRequest); + + iq.target = p_for; + iq.queue_id = ++last_queue_id; + iq.active = false; + + iq.request->connect("request_completed", this, "_image_request_completed", varray(iq.queue_id)); + + image_queue[iq.queue_id] = iq; + + add_child(iq.request); + + _image_update(true, false, PoolByteArray(), iq.queue_id); + _update_image_queue(); +} + +void EditorAssetLibrary::_repository_changed(int p_repository_id) { + host = repository->get_item_metadata(p_repository_id); + print_line(".." + host); + if (templates_only) { + _api_request("configure", REQUESTING_CONFIG, "?type=project"); + } else { + _api_request("configure", REQUESTING_CONFIG); + } +} + +void EditorAssetLibrary::_support_toggled(int p_support) { + support->get_popup()->set_item_checked(p_support, !support->get_popup()->is_item_checked(p_support)); + _search(); +} + +void EditorAssetLibrary::_rerun_search(int p_ignore) { + _search(); +} + +void EditorAssetLibrary::_search(int p_page) { + + String args; + + if (templates_only) { + args += "?type=project&"; + } else { + args += "?"; + } + args += String() + "sort=" + sort_key[sort->get_selected()]; + + String support_list; + for (int i = 0; i < SUPPORT_MAX; i++) { + if (support->get_popup()->is_item_checked(i)) { + support_list += String(support_key[i]) + "+"; + } + } + if (support_list != String()) { + args += "&support=" + support_list.substr(0, support_list.length() - 1); + } + + if (categories->get_selected() > 0) { + + args += "&category=" + itos(categories->get_item_metadata(categories->get_selected())); + } + + if (reverse->is_pressed()) { + + args += "&reverse=true"; + } + + if (filter->get_text() != String()) { + args += "&filter=" + filter->get_text().http_escape(); + } + + if (p_page > 0) { + args += "&page=" + itos(p_page); + } + + _api_request("asset", REQUESTING_SEARCH, args); +} + +HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items) { + + HBoxContainer *hbc = memnew(HBoxContainer); + + //do the mario + int from = p_page - 5; + if (from < 0) + from = 0; + int to = from + 10; + if (to > p_page_count) + to = p_page_count; + + Color gray = Color(0.65, 0.65, 0.65); + + hbc->add_spacer(); + hbc->add_constant_override("separation", 10); + + if (p_page != 0) { + LinkButton *first = memnew(LinkButton); + first->set_text(TTR("first")); + first->add_color_override("font_color", gray); + first->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); + first->connect("pressed", this, "_search", varray(0)); + hbc->add_child(first); + } + + if (p_page > 0) { + LinkButton *prev = memnew(LinkButton); + prev->set_text(TTR("prev")); + prev->add_color_override("font_color", gray); + prev->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); + prev->connect("pressed", this, "_search", varray(p_page - 1)); + hbc->add_child(prev); + } + + for (int i = from; i < to; i++) { + + if (i == p_page) { + + Label *current = memnew(Label); + current->set_text(itos(i + 1)); + hbc->add_child(current); + } else { + + LinkButton *current = memnew(LinkButton); + current->add_color_override("font_color", gray); + current->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); + current->set_text(itos(i + 1)); + current->connect("pressed", this, "_search", varray(i)); + + hbc->add_child(current); + } + } + + if (p_page < p_page_count - 1) { + LinkButton *next = memnew(LinkButton); + next->set_text(TTR("next")); + next->add_color_override("font_color", gray); + next->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); + next->connect("pressed", this, "_search", varray(p_page + 1)); + + hbc->add_child(next); + } + + if (p_page != p_page_count - 1) { + LinkButton *last = memnew(LinkButton); + last->set_text(TTR("last")); + last->add_color_override("font_color", gray); + last->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); + hbc->add_child(last); + last->connect("pressed", this, "_search", varray(p_page_count - 1)); + } + + Label *totals = memnew(Label); + totals->set_text("( " + itos(from * p_page_len) + " - " + itos(from * p_page_len + p_current_items - 1) + " / " + itos(p_total_items) + " )"); + hbc->add_child(totals); + + hbc->add_spacer(); + + return hbc; +} + +void EditorAssetLibrary::_api_request(const String &p_request, RequestType p_request_type, const String &p_arguments) { + + if (requesting != REQUESTING_NONE) { + request->cancel_request(); + } + + requesting = p_request_type; + + error_hb->hide(); + request->request(host + "/" + p_request + p_arguments); +} + +void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) { + + String str; + + { + int datalen = p_data.size(); + PoolByteArray::Read r = p_data.read(); + str.parse_utf8((const char *)r.ptr(), datalen); + } + + bool error_abort = true; + + switch (p_status) { + + case HTTPRequest::RESULT_CANT_RESOLVE: { + error_label->set_text(TTR("Can't resolve hostname:") + " " + host); + } break; + case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: + case HTTPRequest::RESULT_CONNECTION_ERROR: + case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: { + error_label->set_text(TTR("Connection error, please try again.")); + } break; + case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: + case HTTPRequest::RESULT_CANT_CONNECT: { + error_label->set_text(TTR("Can't connect to host:") + " " + host); + } break; + case HTTPRequest::RESULT_NO_RESPONSE: { + error_label->set_text(TTR("No response from host:") + " " + host); + } break; + case HTTPRequest::RESULT_REQUEST_FAILED: { + error_label->set_text(TTR("Request failed, return code:") + " " + itos(p_code)); + } break; + case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { + error_label->set_text(TTR("Request failed, too many redirects")); + + } break; + default: { + if (p_code != 200) { + error_label->set_text(TTR("Request failed, return code:") + " " + itos(p_code)); + } else { + + error_abort = false; + } + } break; + } + + if (error_abort) { + error_hb->show(); + return; + } + + print_line("response: " + itos(p_status) + " code: " + itos(p_code)); + + Dictionary d; + { + Variant js; + String errs; + int errl; + JSON::parse(str, js, errs, errl); + d = js; + } + + print_line(Variant(d).get_construct_string()); + + RequestType requested = requesting; + requesting = REQUESTING_NONE; + + switch (requested) { + case REQUESTING_CONFIG: { + + categories->clear(); + categories->add_item(TTR("All")); + categories->set_item_metadata(0, 0); + if (d.has("categories")) { + Array clist = d["categories"]; + for (int i = 0; i < clist.size(); i++) { + Dictionary cat = clist[i]; + if (!cat.has("name") || !cat.has("id")) + continue; + String name = cat["name"]; + int id = cat["id"]; + categories->add_item(name); + categories->set_item_metadata(categories->get_item_count() - 1, id); + category_map[cat["id"]] = name; + } + } + + _search(); + } break; + case REQUESTING_SEARCH: { + if (asset_items) { + memdelete(asset_items); + } + + if (asset_top_page) { + memdelete(asset_top_page); + } + + if (asset_bottom_page) { + memdelete(asset_bottom_page); + } + + int page = 0; + int pages = 1; + int page_len = 10; + int total_items = 1; + Array result; + + if (d.has("page")) { + page = d["page"]; + } + if (d.has("pages")) { + pages = d["pages"]; + } + if (d.has("page_length")) { + page_len = d["page_length"]; + } + if (d.has("total")) { + total_items = d["total"]; + } + if (d.has("result")) { + result = d["result"]; + } + + asset_top_page = _make_pages(page, pages, page_len, total_items, result.size()); + library_vb->add_child(asset_top_page); + + asset_items = memnew(GridContainer); + asset_items->set_columns(2); + asset_items->add_constant_override("hseparation", 10); + asset_items->add_constant_override("vseparation", 10); + + library_vb->add_child(asset_items); + + asset_bottom_page = _make_pages(page, pages, page_len, total_items, result.size()); + library_vb->add_child(asset_bottom_page); + + for (int i = 0; i < result.size(); i++) { + + Dictionary r = result[i]; + + ERR_CONTINUE(!r.has("title")); + ERR_CONTINUE(!r.has("asset_id")); + ERR_CONTINUE(!r.has("author")); + ERR_CONTINUE(!r.has("author_id")); + ERR_CONTINUE(!r.has("category_id")); + ERR_FAIL_COND(!category_map.has(r["category_id"])); + ERR_CONTINUE(!r.has("rating")); + ERR_CONTINUE(!r.has("cost")); + + EditorAssetLibraryItem *item = memnew(EditorAssetLibraryItem); + asset_items->add_child(item); + item->configure(r["title"], r["asset_id"], category_map[r["category_id"]], r["category_id"], r["author"], r["author_id"], r["rating"], r["cost"]); + item->connect("asset_selected", this, "_select_asset"); + item->connect("author_selected", this, "_select_author"); + item->connect("category_selected", this, "_select_category"); + + if (r.has("icon_url") && r["icon_url"] != "") { + _request_image(item->get_instance_id(), r["icon_url"], IMAGE_QUEUE_ICON, 0); + } + } + } break; + case REQUESTING_ASSET: { + Dictionary r = d; + + ERR_FAIL_COND(!r.has("title")); + ERR_FAIL_COND(!r.has("asset_id")); + ERR_FAIL_COND(!r.has("author")); + ERR_FAIL_COND(!r.has("author_id")); + ERR_FAIL_COND(!r.has("version")); + ERR_FAIL_COND(!r.has("version_string")); + ERR_FAIL_COND(!r.has("category_id")); + ERR_FAIL_COND(!category_map.has(r["category_id"])); + ERR_FAIL_COND(!r.has("rating")); + ERR_FAIL_COND(!r.has("cost")); + ERR_FAIL_COND(!r.has("description")); + ERR_FAIL_COND(!r.has("download_url")); + ERR_FAIL_COND(!r.has("download_hash")); + ERR_FAIL_COND(!r.has("browse_url")); + + if (description) { + memdelete(description); + } + + description = memnew(EditorAssetLibraryItemDescription); + add_child(description); + description->popup_centered_minsize(); + description->connect("confirmed", this, "_install_asset"); + + description->configure(r["title"], r["asset_id"], category_map[r["category_id"]], r["category_id"], r["author"], r["author_id"], r["rating"], r["cost"], r["version"], r["version_string"], r["description"], r["download_url"], r["browse_url"], r["download_hash"]); + /*item->connect("asset_selected",this,"_select_asset"); + item->connect("author_selected",this,"_select_author"); + item->connect("category_selected",this,"_category_selected");*/ + + if (r.has("icon_url") && r["icon_url"] != "") { + _request_image(description->get_instance_id(), r["icon_url"], IMAGE_QUEUE_ICON, 0); + } + + if (d.has("previews")) { + Array previews = d["previews"]; + + for (int i = 0; i < previews.size(); i++) { + + Dictionary p = previews[i]; + + ERR_CONTINUE(!p.has("type")); + ERR_CONTINUE(!p.has("link")); + + bool is_video = p.has("type") && String(p["type"]) == "video"; + String video_url; + if (is_video && p.has("link")) { + video_url = p["link"]; + } + + description->add_preview(i, is_video, video_url); + + if (p.has("thumbnail")) { + _request_image(description->get_instance_id(), p["thumbnail"], IMAGE_QUEUE_THUMBNAIL, i); + } + if (is_video) { + //_request_image(description->get_instance_id(),p["link"],IMAGE_QUEUE_SCREENSHOT,i); + } else { + _request_image(description->get_instance_id(), p["link"], IMAGE_QUEUE_SCREENSHOT, i); + } + } + } + } break; + default: break; + } +} + +void EditorAssetLibrary::_asset_file_selected(const String &p_file) { + + if (asset_installer) { + memdelete(asset_installer); + asset_installer = NULL; + } + + asset_installer = memnew(EditorAssetInstaller); + add_child(asset_installer); + asset_installer->open(p_file); +} + +void EditorAssetLibrary::_asset_open() { + + asset_open->popup_centered_ratio(); +} + +void EditorAssetLibrary::_manage_plugins() { + + ProjectSettingsEditor::get_singleton()->popup_project_settings(); + ProjectSettingsEditor::get_singleton()->set_plugins_page(); +} + +void EditorAssetLibrary::_install_external_asset(String p_zip_path, String p_title) { + + emit_signal("install_asset", p_zip_path, p_title); +} + +void EditorAssetLibrary::_bind_methods() { + + ClassDB::bind_method("_http_request_completed", &EditorAssetLibrary::_http_request_completed); + ClassDB::bind_method("_select_asset", &EditorAssetLibrary::_select_asset); + ClassDB::bind_method("_select_author", &EditorAssetLibrary::_select_author); + ClassDB::bind_method("_select_category", &EditorAssetLibrary::_select_category); + ClassDB::bind_method("_image_request_completed", &EditorAssetLibrary::_image_request_completed); + ClassDB::bind_method("_search", &EditorAssetLibrary::_search, DEFVAL(0)); + ClassDB::bind_method("_install_asset", &EditorAssetLibrary::_install_asset); + ClassDB::bind_method("_manage_plugins", &EditorAssetLibrary::_manage_plugins); + ClassDB::bind_method("_asset_open", &EditorAssetLibrary::_asset_open); + ClassDB::bind_method("_asset_file_selected", &EditorAssetLibrary::_asset_file_selected); + ClassDB::bind_method("_repository_changed", &EditorAssetLibrary::_repository_changed); + ClassDB::bind_method("_support_toggled", &EditorAssetLibrary::_support_toggled); + ClassDB::bind_method("_rerun_search", &EditorAssetLibrary::_rerun_search); + ClassDB::bind_method("_install_external_asset", &EditorAssetLibrary::_install_external_asset); + + ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name"))); +} + +EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { + + templates_only = p_templates_only; + + VBoxContainer *library_main = memnew(VBoxContainer); + + add_child(library_main); + + HBoxContainer *search_hb = memnew(HBoxContainer); + + library_main->add_child(search_hb); + library_main->add_constant_override("separation", 10); + + search_hb->add_child(memnew(Label(TTR("Search:") + " "))); + filter = memnew(LineEdit); + search_hb->add_child(filter); + filter->set_h_size_flags(SIZE_EXPAND_FILL); + filter->connect("text_entered", this, "_search"); + search = memnew(Button(TTR("Search"))); + search->connect("pressed", this, "_search"); + search_hb->add_child(search); + + if (!p_templates_only) + search_hb->add_child(memnew(VSeparator)); + + Button *open_asset = memnew(Button); + open_asset->set_text(TTR("Import")); + search_hb->add_child(open_asset); + open_asset->connect("pressed", this, "_asset_open"); + + Button *plugins = memnew(Button); + plugins->set_text(TTR("Plugins")); + search_hb->add_child(plugins); + plugins->connect("pressed", this, "_manage_plugins"); + + if (p_templates_only) { + open_asset->hide(); + plugins->hide(); + } + + HBoxContainer *search_hb2 = memnew(HBoxContainer); + library_main->add_child(search_hb2); + + search_hb2->add_child(memnew(Label(TTR("Sort:") + " "))); + sort = memnew(OptionButton); + for (int i = 0; i < SORT_MAX; i++) { + sort->add_item(sort_text[i]); + } + + search_hb2->add_child(sort); + + sort->set_h_size_flags(SIZE_EXPAND_FILL); + sort->connect("item_selected", this, "_rerun_search"); + + reverse = memnew(ToolButton); + reverse->set_toggle_mode(true); + reverse->connect("toggled", this, "_rerun_search"); + //reverse->set_text(TTR("Reverse")); + search_hb2->add_child(reverse); + + search_hb2->add_child(memnew(VSeparator)); + + //search_hb2->add_spacer(); + + search_hb2->add_child(memnew(Label(TTR("Category:") + " "))); + categories = memnew(OptionButton); + categories->add_item(TTR("All")); + search_hb2->add_child(categories); + categories->set_h_size_flags(SIZE_EXPAND_FILL); + //search_hb2->add_spacer(); + categories->connect("item_selected", this, "_rerun_search"); + + search_hb2->add_child(memnew(VSeparator)); + + search_hb2->add_child(memnew(Label(TTR("Site:") + " "))); + repository = memnew(OptionButton); + + // FIXME: Reenable me once GH-7147 is fixed. + /* + repository->add_item("godotengine.org"); + repository->set_item_metadata(0, "https://godotengine.org/asset-library/api"); + */ + repository->add_item("localhost"); + repository->set_item_metadata(/*1*/ 0, "http://127.0.0.1/asset-library/api"); + repository->connect("item_selected", this, "_repository_changed"); + + search_hb2->add_child(repository); + repository->set_h_size_flags(SIZE_EXPAND_FILL); + + search_hb2->add_child(memnew(VSeparator)); + + support = memnew(MenuButton); + search_hb2->add_child(support); + support->set_text(TTR("Support..")); + support->get_popup()->add_check_item(TTR("Official"), SUPPORT_OFFICIAL); + support->get_popup()->add_check_item(TTR("Community"), SUPPORT_COMMUNITY); + support->get_popup()->add_check_item(TTR("Testing"), SUPPORT_TESTING); + support->get_popup()->set_item_checked(SUPPORT_OFFICIAL, true); + support->get_popup()->set_item_checked(SUPPORT_COMMUNITY, true); + support->get_popup()->connect("id_pressed", this, "_support_toggled"); + + ///////// + + library_scroll_bg = memnew(PanelContainer); + library_main->add_child(library_scroll_bg); + library_scroll_bg->set_v_size_flags(SIZE_EXPAND_FILL); + + library_scroll = memnew(ScrollContainer); + library_scroll->set_enable_v_scroll(true); + library_scroll->set_enable_h_scroll(false); + + library_scroll_bg->add_child(library_scroll); + + Ref<StyleBoxEmpty> border2; + border2.instance(); + border2->set_default_margin(MARGIN_LEFT, 15); + border2->set_default_margin(MARGIN_RIGHT, 35); + border2->set_default_margin(MARGIN_BOTTOM, 15); + border2->set_default_margin(MARGIN_TOP, 15); + + PanelContainer *library_vb_border = memnew(PanelContainer); + library_scroll->add_child(library_vb_border); + library_vb_border->add_style_override("panel", border2); + library_vb_border->set_h_size_flags(SIZE_EXPAND_FILL); + library_vb_border->set_mouse_filter(MOUSE_FILTER_PASS); + + library_vb = memnew(VBoxContainer); + library_vb->set_h_size_flags(SIZE_EXPAND_FILL); + + library_vb_border->add_child(library_vb); + //margin_panel->set_stop_mouse(false); + + asset_top_page = memnew(HBoxContainer); + library_vb->add_child(asset_top_page); + + asset_items = memnew(GridContainer); + asset_items->set_columns(2); + asset_items->add_constant_override("hseparation", 10); + asset_items->add_constant_override("vseparation", 10); + + library_vb->add_child(asset_items); + + asset_bottom_page = memnew(HBoxContainer); + library_vb->add_child(asset_bottom_page); + + request = memnew(HTTPRequest); + add_child(request); + request->set_use_threads(EDITOR_DEF("asset_library/use_threads", true)); + request->connect("request_completed", this, "_http_request_completed"); + + last_queue_id = 0; + + library_vb->add_constant_override("separation", 20); + + load_status = memnew(ProgressBar); + load_status->set_min(0); + load_status->set_max(1); + load_status->set_step(0.001); + library_main->add_child(load_status); + + error_hb = memnew(HBoxContainer); + library_main->add_child(error_hb); + error_label = memnew(Label); + error_label->add_color_override("color", Color(1, 0.4, 0.3)); + error_hb->add_child(error_label); + + description = NULL; + + set_process(true); + + downloads_scroll = memnew(ScrollContainer); + downloads_scroll->set_enable_h_scroll(true); + downloads_scroll->set_enable_v_scroll(false); + library_main->add_child(downloads_scroll); + downloads_hb = memnew(HBoxContainer); + downloads_scroll->add_child(downloads_hb); + + asset_open = memnew(EditorFileDialog); + + asset_open->set_access(EditorFileDialog::ACCESS_FILESYSTEM); + asset_open->add_filter("*.zip ; " + TTR("Assets ZIP File")); + asset_open->set_mode(EditorFileDialog::MODE_OPEN_FILE); + add_child(asset_open); + asset_open->connect("file_selected", this, "_asset_file_selected"); + + asset_installer = NULL; +} + +/////// + +void AssetLibraryEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + + addon_library->show(); + } else { + + addon_library->hide(); + } +} + +AssetLibraryEditorPlugin::AssetLibraryEditorPlugin(EditorNode *p_node) { + + editor = p_node; + addon_library = memnew(EditorAssetLibrary); + addon_library->set_v_size_flags(Control::SIZE_EXPAND_FILL); + editor->get_viewport()->add_child(addon_library); + addon_library->set_area_as_parent_rect(); + addon_library->hide(); +} + +AssetLibraryEditorPlugin::~AssetLibraryEditorPlugin() { +} diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h new file mode 100644 index 0000000000..fa768ec96a --- /dev/null +++ b/editor/plugins/asset_library_editor_plugin.h @@ -0,0 +1,328 @@ +/*************************************************************************/ +/* asset_library_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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 ASSET_LIBRARY_EDITOR_PLUGIN_H +#define ASSET_LIBRARY_EDITOR_PLUGIN_H + +#include "editor_plugin.h" +#include "scene/gui/box_container.h" +#include "scene/gui/check_box.h" +#include "scene/gui/line_edit.h" +#include "scene/gui/link_button.h" +#include "scene/gui/option_button.h" +#include "scene/gui/panel_container.h" +#include "scene/gui/progress_bar.h" +#include "scene/gui/separator.h" +#include "scene/gui/tab_container.h" + +#include "editor_plugin_settings.h" +#include "scene/gui/grid_container.h" +#include "scene/gui/rich_text_label.h" +#include "scene/gui/scroll_container.h" +#include "scene/gui/texture_button.h" + +#include "editor_asset_installer.h" +#include "scene/main/http_request.h" + +class EditorAssetLibraryItem : public PanelContainer { + + GDCLASS(EditorAssetLibraryItem, PanelContainer); + + TextureButton *icon; + LinkButton *title; + LinkButton *category; + LinkButton *author; + TextureRect *stars[5]; + Label *price; + + int asset_id; + int category_id; + int author_id; + + void _asset_clicked(); + void _category_clicked(); + void _author_clicked(); + + void set_image(int p_type, int p_index, const Ref<Texture> &p_image); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost); + + EditorAssetLibraryItem(); +}; + +class EditorAssetLibraryItemDescription : public ConfirmationDialog { + + GDCLASS(EditorAssetLibraryItemDescription, ConfirmationDialog); + + EditorAssetLibraryItem *item; + RichTextLabel *description; + ScrollContainer *previews; + HBoxContainer *preview_hb; + PanelContainer *previews_bg; + PanelContainer *desc_bg; + + struct Preview { + int id; + bool is_video; + String video_link; + Button *button; + Ref<Texture> image; + }; + + Vector<Preview> preview_images; + TextureRect *preview; + + void set_image(int p_type, int p_index, const Ref<Texture> &p_image); + + int asset_id; + String download_url; + String title; + String sha256; + Ref<Texture> icon; + + void _link_click(const String &p_url); + void _preview_click(int p_id); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost, int p_version, const String &p_version_string, const String &p_description, const String &p_download_url, const String &p_browse_url, const String &p_sha256_hash); + void add_preview(int p_id, bool p_video, const String &p_url); + + String get_title() { return title; } + Ref<Texture> get_preview_icon() { return icon; } + String get_download_url() { return download_url; } + int get_asset_id() { return asset_id; } + String get_sha256() { return sha256; } + EditorAssetLibraryItemDescription(); +}; + +class EditorAssetLibraryItemDownload : public PanelContainer { + + GDCLASS(EditorAssetLibraryItemDownload, PanelContainer); + + TextureRect *icon; + Label *title; + ProgressBar *progress; + Button *install; + Button *retry; + TextureButton *dismiss; + + AcceptDialog *download_error; + HTTPRequest *download; + String host; + String sha256; + Label *status; + + int prev_status; + + int asset_id; + + bool external_install; + + EditorAssetInstaller *asset_installer; + + void _close(); + void _install(); + void _make_request(); + void _http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void set_external_install(bool p_enable) { external_install = p_enable; } + int get_asset_id() { return asset_id; } + void configure(const String &p_title, int p_asset_id, const Ref<Texture> &p_preview, const String &p_download_url, const String &p_sha256_hash); + EditorAssetLibraryItemDownload(); +}; + +class EditorAssetLibrary : public PanelContainer { + GDCLASS(EditorAssetLibrary, PanelContainer); + + String host; + + EditorFileDialog *asset_open; + EditorAssetInstaller *asset_installer; + + void _asset_open(); + void _asset_file_selected(const String &p_file); + + PanelContainer *library_scroll_bg; + ScrollContainer *library_scroll; + VBoxContainer *library_vb; + LineEdit *filter; + OptionButton *categories; + OptionButton *repository; + OptionButton *sort; + ToolButton *reverse; + Button *search; + ProgressBar *load_status; + HBoxContainer *error_hb; + Label *error_label; + MenuButton *support; + + HBoxContainer *contents; + + HBoxContainer *asset_top_page; + GridContainer *asset_items; + HBoxContainer *asset_bottom_page; + + HTTPRequest *request; + + bool templates_only; + + enum Support { + SUPPORT_OFFICIAL, + SUPPORT_COMMUNITY, + SUPPORT_TESTING, + SUPPORT_MAX + }; + + enum SortOrder { + SORT_RATING, + SORT_DOWNLOADS, + SORT_NAME, + SORT_COST, + SORT_UPDATED, + SORT_MAX + }; + + static const char *sort_key[SORT_MAX]; + static const char *sort_text[SORT_MAX]; + static const char *support_key[SUPPORT_MAX]; + + ///MainListing + + enum ImageType { + IMAGE_QUEUE_ICON, + IMAGE_QUEUE_THUMBNAIL, + IMAGE_QUEUE_SCREENSHOT, + + }; + + struct ImageQueue { + + bool active; + int queue_id; + int asset_id; + ImageType image_type; + int image_index; + String image_url; + HTTPRequest *request; + ObjectID target; + }; + + int last_queue_id; + Map<int, ImageQueue> image_queue; + + void _image_update(bool use_cache, bool final, const PoolByteArray &p_data, int p_queue_id); + void _image_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data, int p_queue_id); + void _request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index); + void _update_image_queue(); + + HBoxContainer *_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items); + + // + EditorAssetLibraryItemDescription *description; + // + + enum RequestType { + REQUESTING_NONE, + REQUESTING_CONFIG, + REQUESTING_SEARCH, + REQUESTING_ASSET, + }; + + RequestType requesting; + Dictionary category_map; + + ScrollContainer *downloads_scroll; + HBoxContainer *downloads_hb; + + void _install_asset(); + + void _select_author(int p_id); + void _select_category(int p_id); + void _select_asset(int p_id); + + void _manage_plugins(); + + void _search(int p_page = 0); + void _rerun_search(int p_ignore); + void _api_request(const String &p_request, RequestType p_request_type, const String &p_arguments = ""); + void _http_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data); + void _http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data); + + void _repository_changed(int p_repository_id); + void _support_toggled(int p_support); + + void _install_external_asset(String p_zip_path, String p_title); + + friend class EditorAssetLibraryItemDescription; + friend class EditorAssetLibraryItem; + +protected: + static void _bind_methods(); + void _notification(int p_what); + +public: + EditorAssetLibrary(bool p_templates_only = false); +}; + +class AssetLibraryEditorPlugin : public EditorPlugin { + + GDCLASS(AssetLibraryEditorPlugin, EditorPlugin); + + EditorAssetLibrary *addon_library; + EditorNode *editor; + +public: + virtual String get_name() const { return "AssetLib"; } + bool has_main_screen() const { return true; } + virtual void edit(Object *p_object) {} + virtual bool handles(Object *p_object) const { return false; } + virtual void make_visible(bool p_visible); + //virtual bool get_remove_list(List<Node*> *p_list) { return canvas_item_editor->get_remove_list(p_list); } + //virtual Dictionary get_state() const; + //virtual void set_state(const Dictionary& p_state); + + AssetLibraryEditorPlugin(EditorNode *p_node); + ~AssetLibraryEditorPlugin(); +}; + +#endif // EDITORASSETLIBRARY_H diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index ce6eefd694..1842717cc0 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -29,14 +29,13 @@ /*************************************************************************/ #include "editor_preview_plugins.h" +#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "io/file_access_memory.h" #include "io/resource_loader.h" #include "os/os.h" -#include "scene/resources/material.h" -//#include "scene/resources/sample.h" -#include "editor/editor_scale.h" #include "scene/resources/bit_mask.h" +#include "scene/resources/material.h" #include "scene/resources/mesh.h" bool EditorTexturePreviewPlugin::handles(const String &p_type) const { @@ -239,7 +238,6 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) { VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid()); VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture - //print_line("queue capture!"); preview_done = false; VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); @@ -454,9 +452,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from) { while (_is_text_char(code[pos])) { pos++; } - ///print_line("from "+itos(i)+" to "+itos(pos)); String word = code.substr(i, pos - i); - //print_line("found word: "+word); if (keywords.has(word)) in_keyword = true; @@ -502,6 +498,8 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from) { EditorScriptPreviewPlugin::EditorScriptPreviewPlugin() { } /////////////////////////////////////////////////////////////////// + +// FIXME: Needs to be rewritten for AudioStream in Godot 3.0+ #if 0 bool EditorSamplePreviewPlugin::handles(const String& p_type) const { @@ -766,10 +764,9 @@ Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) { } EditorSamplePreviewPlugin::EditorSamplePreviewPlugin() { - - } #endif + /////////////////////////////////////////////////////////////////////////// void EditorMeshPreviewPlugin::_preview_done(const Variant &p_udata) { @@ -788,14 +785,12 @@ bool EditorMeshPreviewPlugin::handles(const String &p_type) const { Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) { - print_line("**Generating for mesh finally??"); Ref<Mesh> mesh = p_from; ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture>()); VS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid()); Rect3 aabb = mesh->get_aabb(); - print_line("mesh aabb: " + aabb); Vector3 ofs = aabb.position + aabb.size * 0.5; aabb.position -= ofs; Transform xform; @@ -807,14 +802,12 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) { return Ref<Texture>(); m = 1.0 / m; m *= 0.5; - //print_line("scale: "+rtos(m)); xform.basis.scale(Vector3(m, m, m)); xform.origin = -xform.basis.xform(ofs); //-ofs*m; xform.origin.z -= rot_aabb.size.z * 2; VS::get_singleton()->instance_set_transform(mesh_instance, xform); VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture - //print_line("queue capture!"); preview_done = false; VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); @@ -826,7 +819,6 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) { Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>()); - print_line("captured! " + itos(img->get_width()) + "x" + itos(img->get_height())); VS::get_singleton()->instance_set_base(mesh_instance, RID()); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h index 7e7d36eb1e..2ce35390a5 100644 --- a/editor/plugins/editor_preview_plugins.h +++ b/editor/plugins/editor_preview_plugins.h @@ -97,6 +97,7 @@ public: EditorScriptPreviewPlugin(); }; +// FIXME: Needs to be rewritten for AudioStream in Godot 3.0+ #if 0 class EditorSamplePreviewPlugin : public EditorResourcePreviewGenerator { public: @@ -106,8 +107,8 @@ public: EditorSamplePreviewPlugin(); }; - #endif + class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator { GDCLASS(EditorMeshPreviewPlugin, EditorResourcePreviewGenerator) diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 751f39e55d..2afcf6a341 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -27,12 +27,14 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + +// FIXME: Disabled as (according to reduz) users were complaining that it gets in the way +// Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored. +#if 0 #include "material_editor_plugin.h" #include "scene/main/viewport.h" -#if 0 - void MaterialEditor::_gui_input(InputEvent p_event) { diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index a0a91f53a6..218354a918 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -30,6 +30,10 @@ #ifndef MATERIAL_EDITOR_PLUGIN_H #define MATERIAL_EDITOR_PLUGIN_H +// FIXME: Disabled as (according to reduz) users were complaining that it gets in the way +// Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored. +#if 0 + #include "editor/editor_node.h" #include "editor/editor_plugin.h" #include "scene/3d/camera.h" @@ -37,7 +41,6 @@ #include "scene/3d/mesh_instance.h" #include "scene/resources/material.h" -#if 0 class MaterialEditor : public Control { GDCLASS(MaterialEditor, Control); @@ -97,5 +100,5 @@ public: }; -#endif // MATERIAL_EDITOR_PLUGIN_H #endif +#endif // MATERIAL_EDITOR_PLUGIN_H diff --git a/editor/plugins/rich_text_editor_plugin.cpp b/editor/plugins/rich_text_editor_plugin.cpp deleted file mode 100644 index 2a6474023c..0000000000 --- a/editor/plugins/rich_text_editor_plugin.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************/ -/* rich_text_editor_plugin.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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 "rich_text_editor_plugin.h" - -#include "canvas_item_editor_plugin.h" -#include "os/file_access.h" - -void RichTextEditor::_notification(int p_what) { - - switch (p_what) { - - case NOTIFICATION_FIXED_PROCESS: { - - } break; - } -} -void RichTextEditor::_node_removed(Node *p_node) { - - if (p_node == node) { - node = NULL; - hide(); - } -} - -void RichTextEditor::_file_selected(const String &p_path) { - - CharString cs; - FileAccess *fa = FileAccess::open(p_path, FileAccess::READ); - if (!fa) { - ERR_FAIL(); - } - - while (!fa->eof_reached()) - cs.push_back(fa->get_8()); - cs.push_back(0); - memdelete(fa); - - String bbcode; - bbcode.parse_utf8(&cs[0]); - node->parse_bbcode(bbcode); -} - -void RichTextEditor::_menu_option(int p_option) { - - switch (p_option) { - - case PARSE_BBCODE: { - - file_dialog->popup_centered_ratio(); - } break; - case CLEAR: { - - node->clear(); - - } break; - } -} - -void RichTextEditor::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_menu_option"), &RichTextEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_file_selected"), &RichTextEditor::_file_selected); -} - -void RichTextEditor::edit(Node *p_rich_text) { - - node = Object::cast_to<RichTextLabel>(p_rich_text); -} -RichTextEditor::RichTextEditor() { - - options = memnew(MenuButton); - //add_child(options); - CanvasItemEditor::get_singleton()->add_control_to_menu_panel(options); - options->set_area_as_parent_rect(); - - options->set_text("RichText"); - options->get_popup()->add_item(TTR("Parse BBCode"), PARSE_BBCODE); - options->get_popup()->add_item(TTR("Clear"), CLEAR); - - options->get_popup()->connect("id_pressed", this, "_menu_option"); - file_dialog = memnew(EditorFileDialog); - add_child(file_dialog); - file_dialog->add_filter("*.txt"); - file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); - file_dialog->connect("file_selected", this, "_file_selected"); -} - -void RichTextEditorPlugin::edit(Object *p_object) { - - rich_text_editor->edit(Object::cast_to<Node>(p_object)); -} - -bool RichTextEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("RichTextLabel"); -} - -void RichTextEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - rich_text_editor->options->show(); - } else { - - rich_text_editor->options->hide(); - rich_text_editor->edit(NULL); - } -} - -RichTextEditorPlugin::RichTextEditorPlugin(EditorNode *p_node) { - - editor = p_node; - rich_text_editor = memnew(RichTextEditor); - editor->get_viewport()->add_child(rich_text_editor); - - rich_text_editor->set_margin(MARGIN_LEFT, 184); - rich_text_editor->set_margin(MARGIN_RIGHT, 230); - rich_text_editor->set_margin(MARGIN_TOP, 0); - rich_text_editor->set_margin(MARGIN_BOTTOM, 10); - - rich_text_editor->options->hide(); -} - -RichTextEditorPlugin::~RichTextEditorPlugin() { -} diff --git a/editor/plugins/rich_text_editor_plugin.h b/editor/plugins/rich_text_editor_plugin.h deleted file mode 100644 index 2665db2993..0000000000 --- a/editor/plugins/rich_text_editor_plugin.h +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************/ -/* rich_text_editor_plugin.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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 RICH_TEXT_EDITOR_PLUGIN_H -#define RICH_TEXT_EDITOR_PLUGIN_H - -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "scene/gui/file_dialog.h" -#include "scene/gui/rich_text_label.h" - -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - -class RichTextEditor : public Control { - - GDCLASS(RichTextEditor, Control); - - friend class RichTextEditorPlugin; - - enum { - - PARSE_BBCODE, - CLEAR - }; - - Panel *panel; - MenuButton *options; - RichTextLabel *node; - EditorFileDialog *file_dialog; - - void _file_selected(const String &p_path); - void _menu_option(int p_option); - -protected: - void _notification(int p_what); - void _node_removed(Node *p_node); - static void _bind_methods(); - -public: - void edit(Node *p_rich_text); - RichTextEditor(); -}; - -class RichTextEditorPlugin : public EditorPlugin { - - GDCLASS(RichTextEditorPlugin, EditorPlugin); - - RichTextEditor *rich_text_editor; - EditorNode *editor; - -public: - virtual String get_name() const { return "RichText"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - - RichTextEditorPlugin(EditorNode *p_node); - ~RichTextEditorPlugin(); -}; - -#endif // RICH_TEXT_EDITOR_PLUGIN_H diff --git a/editor/plugins/sample_editor_plugin.cpp b/editor/plugins/sample_editor_plugin.cpp deleted file mode 100644 index f6f776f670..0000000000 --- a/editor/plugins/sample_editor_plugin.cpp +++ /dev/null @@ -1,452 +0,0 @@ -/*************************************************************************/ -/* sample_editor_plugin.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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 "sample_editor_plugin.h" - -#if 0 -#include "editor/editor_settings.h" -#include "io/resource_loader.h" -#include "project_settings.h" - - - - -void SampleEditor::_gui_input(InputEvent p_event) { - - -} - -void SampleEditor::_notification(int p_what) { - - if (p_what==NOTIFICATION_FIXED_PROCESS) { - - } - - if (p_what==NOTIFICATION_ENTER_TREE) { - play->set_icon( get_icon("Play","EditorIcons") ); - stop->set_icon( get_icon("Stop","EditorIcons") ); - } - - if (p_what==NOTIFICATION_READY) { - - //get_scene()->connect("node_removed",this,"_node_removed"); - - } - - if (p_what==NOTIFICATION_DRAW) { - - } -} - -void SampleEditor::_play_pressed() { - - player->play("default",true); - stop->set_pressed(false); - play->set_pressed(true); -} -void SampleEditor::_stop_pressed() { - - player->stop_all(); - play->set_pressed(false); -} - -void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<ImageTexture> &p_texture) { - - - PoolVector<uint8_t> data = p_sample->get_data(); - - PoolVector<uint8_t> img; - int w = p_texture->get_width(); - int h = p_texture->get_height(); - img.resize(w*h*3); - PoolVector<uint8_t>::Write imgdata = img.write(); - uint8_t * imgw = imgdata.ptr(); - PoolVector<uint8_t>::Read sampledata = data.read(); - const uint8_t *sdata=sampledata.ptr(); - - bool stereo = p_sample->is_stereo(); - bool _16=p_sample->get_format()==Sample::FORMAT_PCM16; - int len = p_sample->get_length(); - - if (len<1) - return; - - if (p_sample->get_format()==Sample::FORMAT_IMA_ADPCM) { - - - struct IMA_ADPCM_State { - - int16_t step_index; - int32_t predictor; - /* values at loop point */ - int16_t loop_step_index; - int32_t loop_predictor; - int32_t last_nibble; - int32_t loop_pos; - int32_t window_ofs; - const uint8_t *ptr; - } ima_adpcm; - - ima_adpcm.step_index=0; - ima_adpcm.predictor=0; - ima_adpcm.loop_step_index=0; - ima_adpcm.loop_predictor=0; - ima_adpcm.last_nibble=-1; - ima_adpcm.loop_pos=0x7FFFFFFF; - ima_adpcm.window_ofs=0; - ima_adpcm.ptr=NULL; - - - for(int i=0;i<w;i++) { - - float max[2]={-1e10,-1e10}; - float min[2]={1e10,1e10}; - int from = i*len/w; - int to = (i+1)*len/w; - if (to>=len) - to=len-1; - - for(int j=from;j<to;j++) { - - while(j>ima_adpcm.last_nibble) { - - static const int16_t _ima_adpcm_step_table[89] = { - 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, - 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, - 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, - 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, - 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, - 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, - 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, - 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, - 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 - }; - - static const int8_t _ima_adpcm_index_table[16] = { - -1, -1, -1, -1, 2, 4, 6, 8, - -1, -1, -1, -1, 2, 4, 6, 8 - }; - - int16_t nibble,diff,step; - - ima_adpcm.last_nibble++; - const uint8_t *src_ptr=sdata; - - int ofs = ima_adpcm.last_nibble>>1; - - if (stereo) - ofs*=2; - - nibble = (ima_adpcm.last_nibble&1)? - (src_ptr[ofs]>>4):(src_ptr[ofs]&0xF); - - step=_ima_adpcm_step_table[ima_adpcm.step_index]; - - ima_adpcm.step_index += _ima_adpcm_index_table[nibble]; - if (ima_adpcm.step_index<0) - ima_adpcm.step_index=0; - if (ima_adpcm.step_index>88) - ima_adpcm.step_index=88; - - diff = step >> 3 ; - if (nibble & 1) - diff += step >> 2 ; - if (nibble & 2) - diff += step >> 1 ; - if (nibble & 4) - diff += step ; - if (nibble & 8) - diff = -diff ; - - ima_adpcm.predictor+=diff; - if (ima_adpcm.predictor<-0x8000) - ima_adpcm.predictor=-0x8000; - else if (ima_adpcm.predictor>0x7FFF) - ima_adpcm.predictor=0x7FFF; - - - /* store loop if there */ - if (ima_adpcm.last_nibble==ima_adpcm.loop_pos) { - - ima_adpcm.loop_step_index = ima_adpcm.step_index; - ima_adpcm.loop_predictor = ima_adpcm.predictor; - } - - } - - float v=ima_adpcm.predictor/32767.0; - if (v>max[0]) - max[0]=v; - if (v<min[0]) - min[0]=v; - } - - for(int j=0;j<h;j++) { - float v = (j/(float)h) * 2.0 - 1.0; - uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3]; - if (v>min[0] && v<max[0]) { - imgofs[0]=255; - imgofs[1]=150; - imgofs[2]=80; - } else { - imgofs[0]=0; - imgofs[1]=0; - imgofs[2]=0; - } - } - } - } else { - for(int i=0;i<w;i++) { - // i trust gcc will optimize this loop - float max[2]={-1e10,-1e10}; - float min[2]={1e10,1e10}; - int c=stereo?2:1; - int from = uint64_t(i)*len/w; - int to = (uint64_t(i)+1)*len/w; - if (to>=len) - to=len-1; - - if (_16) { - const int16_t*src =(const int16_t*)sdata; - - for(int j=0;j<c;j++) { - - for(int k=from;k<=to;k++) { - - float v = src[uint64_t(k)*c+j]/32768.0; - if (v>max[j]) - max[j]=v; - if (v<min[j]) - min[j]=v; - } - - } - } else { - - const int8_t*src =(const int8_t*)sdata; - - for(int j=0;j<c;j++) { - - for(int k=from;k<=to;k++) { - - float v = src[uint64_t(k)*c+j]/128.0; - if (v>max[j]) - max[j]=v; - if (v<min[j]) - min[j]=v; - } - - } - } - - if (!stereo) { - for(int j=0;j<h;j++) { - float v = (j/(float)h) * 2.0 - 1.0; - uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3]; - if (v>min[0] && v<max[0]) { - imgofs[0]=255; - imgofs[1]=150; - imgofs[2]=80; - } else { - imgofs[0]=0; - imgofs[1]=0; - imgofs[2]=0; - } - } - } else { - - for(int j=0;j<h;j++) { - - int half; - float v; - if (j<(h/2)) { - half=0; - v = (j/(float)(h/2)) * 2.0 - 1.0; - } else { - half=1; - v = ((j-(h/2))/(float)(h/2)) * 2.0 - 1.0; - } - - uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3]; - if (v>min[half] && v<max[half]) { - imgofs[0]=255; - imgofs[1]=150; - imgofs[2]=80; - } else { - imgofs[0]=0; - imgofs[1]=0; - imgofs[2]=0; - } - } - - } - - } - } - - imgdata = PoolVector<uint8_t>::Write(); - - - p_texture->set_data(Image(w,h,0,Image::FORMAT_RGB8,img)); - -} - -void SampleEditor::_update_sample() { - - player->stop_all(); - - generate_preview_texture(sample,peakdisplay); - info_label->set_text(TTR("Length:")+" "+String::num(sample->get_length()/(float)sample->get_mix_rate(),2)+"s"); - - if (library->has_sample("default")) - library->remove_sample("default"); - - library->add_sample("default",sample); -} - - - -void SampleEditor::edit(Ref<Sample> p_sample) { - - sample=p_sample; - - if (!sample.is_null()) - _update_sample(); - else { - - hide(); - set_fixed_process(false); - } - -} - - - -void SampleEditor::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_gui_input"),&SampleEditor::_gui_input); - ClassDB::bind_method(D_METHOD("_play_pressed"),&SampleEditor::_play_pressed); - ClassDB::bind_method(D_METHOD("_stop_pressed"),&SampleEditor::_stop_pressed); - -} - -SampleEditor::SampleEditor() { - - player = memnew(SamplePlayer); - add_child(player); - add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel")); - library = Ref<SampleLibrary>(memnew(SampleLibrary)); - player->set_sample_library(library); - sample_texframe = memnew( TextureRect ); - add_child(sample_texframe); - sample_texframe->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5); - sample_texframe->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,-5); - sample_texframe->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,30); - sample_texframe->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,-5); - - info_label = memnew( Label ); - sample_texframe->add_child(info_label); - info_label->set_area_as_parent_rect(); - info_label->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,-15); - info_label->set_margin(MARGIN_BOTTOM,-4); - info_label->set_margin(MARGIN_RIGHT,-4); - info_label->set_align(Label::ALIGN_RIGHT); - - - play = memnew( Button ); - - play->set_position(Point2( 5, 5 )); - play->set_size( Size2(1,1 ) ); - play->set_toggle_mode(true); - add_child(play); - - stop = memnew( Button ); - - stop->set_position(Point2( 35, 5 )); - stop->set_size( Size2(1,1 ) ); - stop->set_toggle_mode(true); - add_child(stop); - - peakdisplay=Ref<ImageTexture>( memnew( ImageTexture) ); - peakdisplay->create( EDITOR_DEF("editors/sample_editor/preview_width",512),EDITOR_DEF("editors/sample_editor/preview_height",128),Image::FORMAT_RGB8); - sample_texframe->set_expand(true); - sample_texframe->set_texture(peakdisplay); - - play->connect("pressed", this,"_play_pressed"); - stop->connect("pressed", this,"_stop_pressed"); - - set_custom_minimum_size(Size2(1,150)*EDSCALE); - -} - - -void SampleEditorPlugin::edit(Object *p_object) { - - Sample * s = Object::cast_to<Sample>(p_object); - if (!s) - return; - - sample_editor->edit(Ref<Sample>(s)); -} - -bool SampleEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("Sample"); -} - -void SampleEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - sample_editor->show(); - //sample_editor->set_process(true); - } else { - - sample_editor->hide(); - //sample_editor->set_process(false); - } - -} - -SampleEditorPlugin::SampleEditorPlugin(EditorNode *p_node) { - - editor=p_node; - sample_editor = memnew( SampleEditor ); - add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,sample_editor); - sample_editor->hide(); - - - -} - - -SampleEditorPlugin::~SampleEditorPlugin() -{ -} - -#endif diff --git a/editor/plugins/sample_editor_plugin.h b/editor/plugins/sample_editor_plugin.h deleted file mode 100644 index 8f93026c92..0000000000 --- a/editor/plugins/sample_editor_plugin.h +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************************************/ -/* sample_editor_plugin.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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 SAMPLE_EDITOR_PLUGIN_H -#define SAMPLE_EDITOR_PLUGIN_H - -#if 0 -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "scene/audio/sample_player.h" -#include "scene/resources/sample.h" -#include "scene/resources/sample_library.h" - - -class SampleEditor : public Panel { - - GDCLASS(SampleEditor, Panel ); - - - SamplePlayer *player; - Label *info_label; - Ref<ImageTexture> peakdisplay; - Ref<Sample> sample; - Ref<SampleLibrary> library; - TextureRect *sample_texframe; - Button *stop; - Button *play; - - void _play_pressed(); - void _stop_pressed(); - void _update_sample(); - -protected: - void _notification(int p_what); - void _gui_input(InputEvent p_event); - static void _bind_methods(); -public: - - static void generate_preview_texture(const Ref<Sample>& p_sample,Ref<ImageTexture> &p_texture); - void edit(Ref<Sample> p_sample); - SampleEditor(); -}; - - -class SampleEditorPlugin : public EditorPlugin { - - GDCLASS( SampleEditorPlugin, EditorPlugin ); - - SampleEditor *sample_editor; - EditorNode *editor; - -public: - - virtual String get_name() const { return "Sample"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_node); - virtual bool handles(Object *p_node) const; - virtual void make_visible(bool p_visible); - - SampleEditorPlugin(EditorNode *p_node); - ~SampleEditorPlugin(); - -}; - -#endif - -#endif // SAMPLE_EDITOR_PLUGIN_H diff --git a/editor/plugins/sample_library_editor_plugin.cpp b/editor/plugins/sample_library_editor_plugin.cpp deleted file mode 100644 index 761301610e..0000000000 --- a/editor/plugins/sample_library_editor_plugin.cpp +++ /dev/null @@ -1,547 +0,0 @@ -/*************************************************************************/ -/* sample_library_editor_plugin.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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. */ -/*************************************************************************/ - -#if 0 -#include "sample_library_editor_plugin.h" - -#include "editor/editor_settings.h" -#include "io/resource_loader.h" -#include "project_settings.h" -#include "sample_editor_plugin.h" -#include "scene/main/viewport.h" - - -void SampleLibraryEditor::_gui_input(InputEvent p_event) { - - -} - -void SampleLibraryEditor::_notification(int p_what) { - - if (p_what==NOTIFICATION_PROCESS) { - if (is_playing && !player->is_active()) { - TreeItem *tl=Object::cast_to<TreeItem>(last_sample_playing); - tl->set_button(0,0,get_icon("Play","EditorIcons")); - is_playing = false; - set_process(false); - } - } - - if (p_what==NOTIFICATION_ENTER_TREE) { - load->set_icon( get_icon("Folder","EditorIcons") ); - load->set_tooltip(TTR("Open Sample File(s)")); - } - - if (p_what==NOTIFICATION_READY) { - - //NodePath("/root")->connect("node_removed", this,"_node_removed",Vector<Variant>(),true); - } - - if (p_what==NOTIFICATION_DRAW) { - - } -} - -void SampleLibraryEditor::_file_load_request(const PoolVector<String>& p_path) { - - - for(int i=0;i<p_path.size();i++) { - - String path = p_path[i]; - Ref<Sample> sample = ResourceLoader::load(path,"Sample"); - if (sample.is_null()) { - dialog->set_text(TTR("ERROR: Couldn't load sample!")); - dialog->set_title(TTR("Error!")); - //dialog->get_cancel()->set_text("Close"); - dialog->get_ok()->set_text(TTR("Close")); - dialog->popup_centered_minsize(); - return; ///beh should show an error i guess - } - String basename = path.get_file().get_basename(); - String name=basename; - int counter=0; - while(sample_library->has_sample(name)) { - counter++; - name=basename+"_"+itos(counter); - } - - undo_redo->create_action(TTR("Add Sample")); - undo_redo->add_do_method(sample_library.operator->(),"add_sample",name,sample); - undo_redo->add_undo_method(sample_library.operator->(),"remove_sample",name); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); - undo_redo->commit_action(); - } -} - -void SampleLibraryEditor::_load_pressed() { - - file->popup_centered_ratio(); - -} - -void SampleLibraryEditor::_button_pressed(Object *p_item,int p_column, int p_id) { - - TreeItem *ti=Object::cast_to<TreeItem>(p_item); - String name = ti->get_text(0); - - if (p_column==0) { // Play/Stop - - String btn_type; - if(!is_playing) { - is_playing = true; - btn_type = TTR("Stop"); - player->play(name,true); - last_sample_playing = p_item; - set_process(true); - } else { - player->stop_all(); - if(last_sample_playing != p_item){ - TreeItem *tl=Object::cast_to<TreeItem>(last_sample_playing); - tl->set_button(p_column,0,get_icon("Play","EditorIcons")); - btn_type = TTR("Stop"); - player->play(name,true); - last_sample_playing = p_item; - } else { - btn_type = TTR("Play"); - is_playing = false; - } - } - ti->set_button(p_column,0,get_icon(btn_type,"EditorIcons")); - } else if (p_column==1) { // Edit - - get_tree()->get_root()->get_child(0)->call("_resource_selected",sample_library->get_sample(name)); - } else if (p_column==5) { // Delete - - ti->select(0); - _delete_pressed(); - } - - -} - - - - - -void SampleLibraryEditor::_item_edited() { - - if (!tree->get_selected()) - return; - - TreeItem *s = tree->get_selected(); - - if (tree->get_selected_column()==0) { // Name - // renamed - String old_name=s->get_metadata(0); - String new_name=s->get_text(0); - if (old_name==new_name) - return; - - if (new_name=="" || new_name.find("\\")!=-1 || new_name.find("/")!=-1 || sample_library->has_sample(new_name)) { - - s->set_text(0,old_name); - return; - } - - Ref<Sample> samp = sample_library->get_sample(old_name); - undo_redo->create_action(TTR("Rename Sample")); - undo_redo->add_do_method(sample_library.operator->(),"remove_sample",old_name); - undo_redo->add_do_method(sample_library.operator->(),"add_sample",new_name,samp); - undo_redo->add_undo_method(sample_library.operator->(),"remove_sample",new_name); - undo_redo->add_undo_method(sample_library.operator->(),"add_sample",old_name,samp); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); - undo_redo->commit_action(); - - } else if (tree->get_selected_column()==3) { // Volume dB - - StringName n = s->get_text(0); - sample_library->sample_set_volume_db(n,s->get_range(3)); - - } else if (tree->get_selected_column()==4) { // Pitch scale - - StringName n = s->get_text(0); - sample_library->sample_set_pitch_scale(n,s->get_range(4)); - - } - - -} - -void SampleLibraryEditor::_delete_pressed() { - - if (!tree->get_selected()) - return; - - String to_remove = tree->get_selected()->get_text(0); - undo_redo->create_action(TTR("Delete Sample")); - undo_redo->add_do_method(sample_library.operator->(),"remove_sample",to_remove); - undo_redo->add_undo_method(sample_library.operator->(),"add_sample",to_remove,sample_library->get_sample(to_remove)); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); - undo_redo->commit_action(); -} - - -void SampleLibraryEditor::_update_library() { - - player->stop_all(); - - tree->clear(); - tree->set_hide_root(true); - TreeItem *root = tree->create_item(NULL); - - List<StringName> names; - sample_library->get_sample_list(&names); - names.sort_custom<StringName::AlphCompare>(); - - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - - TreeItem *ti = tree->create_item(root); - - // Name + Play/Stop - 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()); - ti->add_button(0,get_icon("Play","EditorIcons")); - - Ref<Sample> smp = sample_library->get_sample(E->get()); - - // Preview/edit - Ref<ImageTexture> preview( memnew( ImageTexture )); - preview->create(128,16,Image::FORMAT_RGB8); - SampleEditor::generate_preview_texture(smp,preview); - ti->set_cell_mode(1,TreeItem::CELL_MODE_ICON); - ti->set_selectable(1,false); - ti->set_editable(1,false); - ti->set_icon(1,preview); - ti->add_button(1,get_icon("Edit","EditorIcons")); - - // Format - ti->set_cell_mode(2,TreeItem::CELL_MODE_STRING); - ti->set_editable(2,false); - ti->set_selectable(2,false); - ti->set_text(2,String()+(smp->get_format()==Sample::FORMAT_PCM16?TTR("16 Bits")+", ":(smp->get_format()==Sample::FORMAT_PCM8?TTR("8 Bits")+", ":"IMA-ADPCM,"))+(smp->is_stereo()?TTR("Stereo"):TTR("Mono"))); - - // Volume dB - ti->set_cell_mode(3,TreeItem::CELL_MODE_RANGE); - ti->set_range_config(3,-60,24,0.01); - ti->set_selectable(3,true); - ti->set_editable(3,true); - ti->set_range(3,sample_library->sample_get_volume_db(E->get())); - - // Pitch scale - ti->set_cell_mode(4,TreeItem::CELL_MODE_RANGE); - ti->set_range_config(4,0.01,100,0.01); - ti->set_selectable(4,true); - ti->set_editable(4,true); - ti->set_range(4,sample_library->sample_get_pitch_scale(E->get())); - - // Delete - ti->set_cell_mode(5,TreeItem::CELL_MODE_STRING); - ti->add_button(5,get_icon("Remove","EditorIcons")); - - } - - //player->add_sample("default",sample); -} - - - -void SampleLibraryEditor::edit(Ref<SampleLibrary> p_sample_library) { - - sample_library=p_sample_library; - - - if (!sample_library.is_null()) { - player->set_sample_library(sample_library); - _update_library(); - } else { - - hide(); - } - -} - -Variant SampleLibraryEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) { - - TreeItem*ti =tree->get_item_at_pos(p_point); - if (!ti) - return Variant(); - - String name = ti->get_metadata(0); - - RES res = sample_library->get_sample(name); - if (!res.is_valid()) - return Variant(); - - return EditorNode::get_singleton()->drag_resource(res,p_from); - - -} - -bool SampleLibraryEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const { - - - - Dictionary d = p_data; - - if (!d.has("type")) - return false; - - if (d.has("from") && (Object*)(d["from"])==tree) - return false; - - if (String(d["type"])=="resource" && d.has("resource")) { - RES r=d["resource"]; - - Ref<Sample> sample = r; - - if (sample.is_valid()) { - - return true; - } - } - - - if (String(d["type"])=="files") { - - Vector<String> files = d["files"]; - - if (files.size()==0) - return false; - - for(int i=0;i<files.size();i++) { - String file = files[0]; - String ftype = EditorFileSystem::get_singleton()->get_file_type(file); - - if (ftype!="Sample") { - return false; - } - - } - - return true; - - } - return false; -} - -void SampleLibraryEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) { - - if (!can_drop_data_fw(p_point,p_data,p_from)) - return; - - Dictionary d = p_data; - - if (!d.has("type")) - return; - - - if (String(d["type"])=="resource" && d.has("resource")) { - RES r=d["resource"]; - - Ref<Sample> sample = r; - - if (sample.is_valid()) { - - String basename; - if (sample->get_name()!="") { - basename=sample->get_name(); - } else if (sample->get_path().is_resource_file()) { - basename = sample->get_path().get_basename(); - } else { - basename="Sample"; - } - - String name=basename; - int counter=0; - while(sample_library->has_sample(name)) { - counter++; - name=basename+"_"+itos(counter); - } - - undo_redo->create_action(TTR("Add Sample")); - undo_redo->add_do_method(sample_library.operator->(),"add_sample",name,sample); - undo_redo->add_undo_method(sample_library.operator->(),"remove_sample",name); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); - undo_redo->commit_action(); - } - } - - - if (String(d["type"])=="files") { - - PoolVector<String> files = d["files"]; - - _file_load_request(files); - - } - -} - - -void SampleLibraryEditor::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_gui_input"),&SampleLibraryEditor::_gui_input); - ClassDB::bind_method(D_METHOD("_load_pressed"),&SampleLibraryEditor::_load_pressed); - ClassDB::bind_method(D_METHOD("_item_edited"),&SampleLibraryEditor::_item_edited); - ClassDB::bind_method(D_METHOD("_delete_pressed"),&SampleLibraryEditor::_delete_pressed); - ClassDB::bind_method(D_METHOD("_file_load_request"),&SampleLibraryEditor::_file_load_request); - ClassDB::bind_method(D_METHOD("_update_library"),&SampleLibraryEditor::_update_library); - ClassDB::bind_method(D_METHOD("_button_pressed"),&SampleLibraryEditor::_button_pressed); - - ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SampleLibraryEditor::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SampleLibraryEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &SampleLibraryEditor::drop_data_fw); - -} - -SampleLibraryEditor::SampleLibraryEditor() { - - player = memnew(SamplePlayer); - add_child(player); - add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel")); - - - load = memnew( Button ); - load->set_position(Point2( 5, 5 )); - load->set_size( Size2(1,1 ) ); - add_child(load); - - file = memnew( EditorFileDialog ); - add_child(file); - List<String> extensions; - ResourceLoader::get_recognized_extensions_for_type("Sample",&extensions); - for(int i=0;i<extensions.size();i++) - file->add_filter("*."+extensions[i]); - file->set_mode(EditorFileDialog::MODE_OPEN_FILES); - - tree = memnew( Tree ); - tree->set_columns(6); - add_child(tree); - tree->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5); - tree->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,-5); - tree->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,30); - tree->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,-5); - tree->set_column_titles_visible(true); - tree->set_column_title(0,TTR("Name")); - tree->set_column_title(1,TTR("Preview")); - tree->set_column_title(2,TTR("Format")); - tree->set_column_title(3,"dB"); - tree->set_column_title(4,TTR("Pitch")); - tree->set_column_title(5,""); - - tree->set_column_min_width(1,150); - tree->set_column_min_width(2,100); - tree->set_column_min_width(3,50); - tree->set_column_min_width(4,50); - tree->set_column_min_width(5,32); - tree->set_column_expand(1,false); - tree->set_column_expand(2,false); - tree->set_column_expand(3,false); - tree->set_column_expand(4,false); - tree->set_column_expand(5,false); - - tree->set_drag_forwarding(this); - - dialog = memnew( ConfirmationDialog ); - add_child( dialog ); - - tree->connect("button_pressed",this,"_button_pressed"); - load->connect("pressed", this,"_load_pressed"); - file->connect("files_selected", this,"_file_load_request"); - tree->connect("item_edited", this,"_item_edited"); - - is_playing = false; -} - - -void SampleLibraryEditorPlugin::edit(Object *p_object) { - - sample_library_editor->set_undo_redo(&get_undo_redo()); - SampleLibrary * s = Object::cast_to<SampleLibrary>(p_object); - if (!s) - return; - - sample_library_editor->edit(Ref<SampleLibrary>(s)); -} - -bool SampleLibraryEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("SampleLibrary"); -} - -void SampleLibraryEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - //sample_library_editor->show(); - button->show(); - editor->make_bottom_panel_item_visible(sample_library_editor); - //sample_library_editor->set_process(true); - } else { - - if (sample_library_editor->is_visible_in_tree()) - editor->hide_bottom_panel(); - button->hide(); - - //sample_library_editor->set_process(false); - } - -} - -SampleLibraryEditorPlugin::SampleLibraryEditorPlugin(EditorNode *p_node) { - - editor=p_node; - sample_library_editor = memnew( SampleLibraryEditor ); - - //editor->get_viewport()->add_child(sample_library_editor); - sample_library_editor->set_custom_minimum_size(Size2(0,250)); - button=p_node->add_bottom_panel_item("SampleLibrary",sample_library_editor); - button->hide(); - - //sample_library_editor->set_area_as_parent_rect(); - //sample_library_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END); - //sample_library_editor->set_margin( MARGIN_TOP, 120 ); - //sample_library_editor->hide(); - - - -} - - -SampleLibraryEditorPlugin::~SampleLibraryEditorPlugin() -{ -} -#endif diff --git a/editor/plugins/sample_library_editor_plugin.h b/editor/plugins/sample_library_editor_plugin.h deleted file mode 100644 index 0244fa66ed..0000000000 --- a/editor/plugins/sample_library_editor_plugin.h +++ /dev/null @@ -1,108 +0,0 @@ -/*************************************************************************/ -/* sample_library_editor_plugin.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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 SAMPLE_LIBRARY_EDITOR_PLUGIN_H -#define SAMPLE_LIBRARY_EDITOR_PLUGIN_H - -#if 0 -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "scene/audio/sample_player.h" -#include "scene/gui/dialogs.h" -#include "scene/gui/file_dialog.h" -#include "scene/gui/tree.h" -#include "scene/resources/sample.h" - - -class SampleLibraryEditor : public Panel { - - GDCLASS(SampleLibraryEditor, Panel ); - - - - SamplePlayer *player; - Ref<SampleLibrary> sample_library; - Button *load; - Tree *tree; - bool is_playing; - Object *last_sample_playing; - - EditorFileDialog *file; - - ConfirmationDialog *dialog; - - - void _load_pressed(); - void _file_load_request(const PoolVector<String>& p_path); - void _delete_pressed(); - void _update_library(); - void _item_edited(); - - UndoRedo *undo_redo; - - void _button_pressed(Object *p_item,int p_column, int p_id); - - Variant get_drag_data_fw(const Point2& p_point,Control* p_from); - bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const; - void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from); - -protected: - void _notification(int p_what); - void _gui_input(InputEvent p_event); - static void _bind_methods(); -public: - - void set_undo_redo(UndoRedo *p_undo_redo) {undo_redo=p_undo_redo; } - void edit(Ref<SampleLibrary> p_sample); - SampleLibraryEditor(); -}; - -class SampleLibraryEditorPlugin : public EditorPlugin { - - GDCLASS( SampleLibraryEditorPlugin, EditorPlugin ); - - SampleLibraryEditor *sample_library_editor; - EditorNode *editor; - Button *button; - -public: - - virtual String get_name() const { return "SampleLibrary"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_node); - virtual bool handles(Object *p_node) const; - virtual void make_visible(bool p_visible); - - SampleLibraryEditorPlugin(EditorNode *p_node); - ~SampleLibraryEditorPlugin(); - -}; - -#endif -#endif // SAMPLE_LIBRARY_EDITOR_PLUGIN_H diff --git a/editor/plugins/sample_player_editor_plugin.cpp b/editor/plugins/sample_player_editor_plugin.cpp deleted file mode 100644 index 821c7ecc01..0000000000 --- a/editor/plugins/sample_player_editor_plugin.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/*************************************************************************/ -/* sample_player_editor_plugin.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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. */ -/*************************************************************************/ - -#if 0 -#include "sample_player_editor_plugin.h" - -#include "scene/resources/sample_library.h" - - -void SamplePlayerEditor::_notification(int p_what) { - - if (p_what==NOTIFICATION_ENTER_TREE) { - play->set_icon( get_icon("Play","EditorIcons") ); - stop->set_icon( get_icon("Stop","EditorIcons") ); - } - -} - -void SamplePlayerEditor::_node_removed(Node *p_node) { - - if(p_node==node) { - node=NULL; - hide(); - } - -} - -void SamplePlayerEditor::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_play"),&SamplePlayerEditor::_play); - ClassDB::bind_method(D_METHOD("_stop"),&SamplePlayerEditor::_stop); - -} - - -void SamplePlayerEditor::_play() { - - if (!node) - return; - if (samples->get_item_count()<=0) - return; - - node->call("play",samples->get_item_text( samples->get_selected() )); - stop->set_pressed(false); - play->set_pressed(true); -} - -void SamplePlayerEditor::_stop() { - - if (!node) - return; - if (samples->get_item_count()<=0) - return; - - node->call("stop_all"); - print_line("STOP ALL!!"); - stop->set_pressed(true); - play->set_pressed(false); - -} - - -void SamplePlayerEditor::_update_sample_library() { - - samples->clear(); - Ref<SampleLibrary> sl = node->call("get_sample_library"); - if (sl.is_null()) { - samples->add_item("<NO SAMPLE LIBRARY>"); - return; //no sample library; - } - - List<StringName> samplenames; - sl->get_sample_list(&samplenames); - samplenames.sort_custom<StringName::AlphCompare>(); - for(List<StringName>::Element *E=samplenames.front();E;E=E->next()) { - samples->add_item(E->get()); - } - -} - -void SamplePlayerEditor::edit(Node *p_sample_player) { - - node=p_sample_player; - if (node) { - _update_sample_library(); - } - -} -SamplePlayerEditor::SamplePlayerEditor() { - - - play = memnew( Button ); - - play->set_position(Point2( 5, 5 )); - play->set_toggle_mode(true); - play->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-250); - play->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-230); - play->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0); - play->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0); - - add_child(play); - - stop = memnew( Button ); - - stop->set_position(Point2( 35, 5 )); - stop->set_toggle_mode(true); - stop->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-220); - stop->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-200); - stop->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0); - stop->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0); - add_child(stop); - - samples = memnew( OptionButton ); - samples->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-190); - samples->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-5); - samples->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0); - samples->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0); - add_child(samples); - - play->connect("pressed", this,"_play"); - stop->connect("pressed", this,"_stop"); - -} - - -void SamplePlayerEditorPlugin::edit(Object *p_object) { - - sample_player_editor->edit(Object::cast_to<Node>(p_object)); -} - -bool SamplePlayerEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("SamplePlayer2D") || p_object->is_class("SamplePlayer") || p_object->is_class("SpatialSamplePlayer"); -} - -void SamplePlayerEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - sample_player_editor->show(); - sample_player_editor->set_fixed_process(true); - } else { - - sample_player_editor->hide(); - sample_player_editor->set_fixed_process(false); - sample_player_editor->edit(NULL); - } - -} - -SamplePlayerEditorPlugin::SamplePlayerEditorPlugin(EditorNode *p_node) { - - editor=p_node; - sample_player_editor = memnew( SamplePlayerEditor ); - editor->get_viewport()->add_child(sample_player_editor); - - sample_player_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END); - sample_player_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END); - sample_player_editor->set_margin(MARGIN_LEFT,-250); - sample_player_editor->set_margin(MARGIN_RIGHT,0); - sample_player_editor->set_margin(MARGIN_TOP,0); - sample_player_editor->set_margin(MARGIN_BOTTOM,10); - - - sample_player_editor->hide(); - - - -} - - -SamplePlayerEditorPlugin::~SamplePlayerEditorPlugin() -{ -} - -#endif diff --git a/editor/plugins/sample_player_editor_plugin.h b/editor/plugins/sample_player_editor_plugin.h deleted file mode 100644 index 5c1b25aaa2..0000000000 --- a/editor/plugins/sample_player_editor_plugin.h +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************/ -/* sample_player_editor_plugin.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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 SAMPLE_PLAYER_EDITOR_PLUGIN_H -#define SAMPLE_PLAYER_EDITOR_PLUGIN_H - -#if 0 - -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "scene/3d/spatial_sample_player.h" -#include "scene/audio/sample_player.h" -#include "scene/gui/option_button.h" - -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - -class SamplePlayerEditor : public Control { - - GDCLASS(SamplePlayerEditor, Control ); - - Panel *panel; - Button * play; - Button * stop; - OptionButton *samples; - Node *node; - - - void _update_sample_library(); - void _play(); - void _stop(); - -protected: - void _notification(int p_what); - void _node_removed(Node *p_node); - static void _bind_methods(); -public: - - void edit(Node *p_sample_player); - SamplePlayerEditor(); -}; - -class SamplePlayerEditorPlugin : public EditorPlugin { - - GDCLASS( SamplePlayerEditorPlugin, EditorPlugin ); - - SamplePlayerEditor *sample_player_editor; - EditorNode *editor; - -public: - - virtual String get_name() const { return "SamplePlayer"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_node); - virtual bool handles(Object *p_node) const; - virtual void make_visible(bool p_visible); - - SamplePlayerEditorPlugin(EditorNode *p_node); - ~SamplePlayerEditorPlugin(); - -}; - -#endif -#endif // SAMPLE_PLAYER_EDITOR_PLUGIN_H diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index a6db0f6e59..9b83d4e483 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -29,18 +29,19 @@ /*************************************************************************/ #include "script_editor_plugin.h" +#include "core/io/resource_loader.h" +#include "core/io/resource_saver.h" +#include "core/os/file_access.h" +#include "core/os/input.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" +#include "core/project_settings.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" +#include "editor/node_dock.h" #include "editor/script_editor_debugger.h" -#include "io/resource_loader.h" -#include "io/resource_saver.h" -#include "node_dock.h" -#include "os/file_access.h" -#include "os/input.h" -#include "os/keyboard.h" -#include "os/os.h" -#include "project_settings.h" #include "scene/main/viewport.h" + /*** SCRIPT EDITOR ****/ void ScriptEditorBase::_bind_methods() { diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 251416f853..5a57efd941 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -29,20 +29,17 @@ /*************************************************************************/ #include "shader_editor_plugin.h" +#include "core/io/resource_loader.h" +#include "core/io/resource_saver.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "editor/property_editor.h" -#include "io/resource_loader.h" -#include "io/resource_saver.h" -#include "os/keyboard.h" -#include "os/os.h" #include "scene/resources/shader_graph.h" #include "servers/visual/shader_types.h" -#include "spatial_editor_plugin.h" -/*** SETTINGS EDITOR ****/ - -/*** SCRIPT EDITOR ****/ +/*** SHADER SCRIPT EDITOR ****/ Ref<Shader> ShaderTextEditor::get_edited_shader() const { diff --git a/editor/plugins/shader_graph_editor_plugin.cpp b/editor/plugins/shader_graph_editor_plugin.cpp index 7ad32464af..3f8f2488dc 100644 --- a/editor/plugins/shader_graph_editor_plugin.cpp +++ b/editor/plugins/shader_graph_editor_plugin.cpp @@ -27,9 +27,11 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "shader_graph_editor_plugin.h" +// FIXME: Godot 3.0 broke compatibility with ShaderGraphEditorPlugin, +// it needs to be ported to the new shader language. #if 0 +#include "shader_graph_editor_plugin.h" #include "canvas_item_editor_plugin.h" #include "os/keyboard.h" diff --git a/editor/plugins/shader_graph_editor_plugin.h b/editor/plugins/shader_graph_editor_plugin.h index e7cab50d8d..159c752ee6 100644 --- a/editor/plugins/shader_graph_editor_plugin.h +++ b/editor/plugins/shader_graph_editor_plugin.h @@ -30,6 +30,10 @@ #ifndef SHADER_GRAPH_EDITOR_PLUGIN_H #define SHADER_GRAPH_EDITOR_PLUGIN_H +// FIXME: Godot 3.0 broke compatibility with ShaderGraphEditorPlugin, +// it needs to be ported to the new shader language. +#if 0 + #include "editor/editor_node.h" #include "editor/editor_plugin.h" #include "editor/property_editor.h" @@ -39,11 +43,11 @@ #include "scene/gui/tree.h" #include "scene/resources/shader.h" #include "scene/resources/shader_graph.h" + /** @author Juan Linietsky <reduzio@gmail.com> */ -#if 0 class GraphColorRampEdit : public Control { GDCLASS(GraphColorRampEdit,Control); @@ -238,5 +242,6 @@ public: ~ShaderGraphEditorPlugin(); }; + #endif -#endif +#endif // SHADER_GRAPH_EDITOR_PLUGIN_H |