| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  asset_library_editor_plugin.cpp                                      */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                    http://www.godotengine.org                         */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2017-01-01 22:01:57 +01:00
										 |  |  | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							| 
									
										
										
										
											2017-04-08 00:11:42 +02:00
										 |  |  | /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md)    */ | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | #include "asset_library_editor_plugin.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-16 08:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | #include "editor_node.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | #include "editor_settings.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-08 22:40:00 -03:00
										 |  |  | #include "io/json.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 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) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	title->set_text(p_title); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_id = p_asset_id; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	category->set_text(p_category); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	category_id = p_category_id; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	author->set_text(p_author); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	author_id = p_author_id; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	price->set_text(p_cost); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < 5; i++) { | 
					
						
							|  |  |  | 		if (i < p_rating) | 
					
						
							|  |  |  | 			stars[i]->set_texture(get_icon("RatingStar", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			stars[i]->set_texture(get_icon("RatingNoStar", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Texture> &p_image) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND(p_type != EditorAssetLibrary::IMAGE_QUEUE_ICON); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_index != 0); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	icon->set_normal_texture(p_image); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAssetLibraryItem::_notification(int p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_ENTER_TREE) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		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)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAssetLibraryItem::_asset_clicked() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	emit_signal("asset_selected", asset_id); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibraryItem::_category_clicked() { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	emit_signal("category_selected", category_id); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibraryItem::_author_clicked() { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	emit_signal("author_selected", author_id); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAssetLibraryItem::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EditorAssetLibraryItem::EditorAssetLibraryItem() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<StyleBoxEmpty> border; | 
					
						
							|  |  |  | 	border.instance(); | 
					
						
							| 
									
										
										
										
											2017-07-14 23:40:17 -05:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	add_style_override("panel", border); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	add_child(hb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	icon = memnew(TextureButton); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	icon->set_default_cursor_shape(CURSOR_POINTING_HAND); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	icon->connect("pressed", this, "_asset_clicked"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hb->add_child(icon); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *vb = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hb->add_child(vb); | 
					
						
							|  |  |  | 	vb->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	title = memnew(LinkButton); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	title->set_text("My Awesome Addon"); | 
					
						
							|  |  |  | 	title->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	title->connect("pressed", this, "_asset_clicked"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	vb->add_child(title); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	category = memnew(LinkButton); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	category->set_text("Editor Tools"); | 
					
						
							|  |  |  | 	category->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	category->connect("pressed", this, "_category_clicked"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	vb->add_child(category); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	author = memnew(LinkButton); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	author->set_text("Johny Tolengo"); | 
					
						
							|  |  |  | 	author->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	author->connect("pressed", this, "_author_clicked"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	vb->add_child(author); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *rating_hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	vb->add_child(rating_hb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < 5; i++) { | 
					
						
							|  |  |  | 		stars[i] = memnew(TextureRect); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 		rating_hb->add_child(stars[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	price = memnew(Label); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	price->set_text(TTR("Free")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	vb->add_child(price); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	set_custom_minimum_size(Size2(250, 100)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 19:54:19 -03:00
										 |  |  | 	set_mouse_filter(MOUSE_FILTER_PASS); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const Ref<Texture> &p_image) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_type) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | 		case EditorAssetLibrary::IMAGE_QUEUE_ICON: { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			item->call("set_image", p_type, p_index, p_image); | 
					
						
							|  |  |  | 			icon = p_image; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | 		case EditorAssetLibrary::IMAGE_QUEUE_THUMBNAIL: { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (int i = 0; i < preview_images.size(); i++) { | 
					
						
							|  |  |  | 				if (preview_images[i].id == p_index) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 					preview_images[i].button->set_icon(p_image); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			//item->call("set_image",p_type,p_index,p_image);
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | 		case EditorAssetLibrary::IMAGE_QUEUE_SCREENSHOT: { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (int i = 0; i < preview_images.size(); i++) { | 
					
						
							|  |  |  | 				if (preview_images[i].id == p_index) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					preview_images[i].image = p_image; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (preview_images[i].button->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 						_preview_click(p_index); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			//item->call("set_image",p_type,p_index,p_image);
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibraryItemDescription::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibraryItemDescription::_link_click(const String &p_url) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	ERR_FAIL_COND(!p_url.begins_with("http")); | 
					
						
							|  |  |  | 	OS::get_singleton()->shell_open(p_url); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibraryItemDescription::_preview_click(int p_id) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < preview_images.size(); i++) { | 
					
						
							|  |  |  | 		if (preview_images[i].id == p_id) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			preview_images[i].button->set_pressed(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (!preview_images[i].is_video) { | 
					
						
							|  |  |  | 				if (preview_images[i].image.is_valid()) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					preview->set_texture(preview_images[i].image); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				_link_click(preview_images[i].video_link); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			preview_images[i].button->set_pressed(false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 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) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	description->clear(); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	description->add_text(TTR("Version:") + " " + p_version_string + "\n"); | 
					
						
							|  |  |  | 	description->add_text(TTR("Contents:") + " "); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	description->push_meta(p_browse_url); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	description->add_text(TTR("View Files")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	description->pop(); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	description->add_text("\n" + TTR("Description:") + "\n\n"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	description->append_bbcode(p_description); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	set_title(p_title); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibraryItemDescription::add_preview(int p_id, bool p_video, const String &p_url) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Preview preview; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	preview.id = p_id; | 
					
						
							|  |  |  | 	preview.video_link = p_url; | 
					
						
							|  |  |  | 	preview.is_video = p_video; | 
					
						
							|  |  |  | 	preview.button = memnew(Button); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	preview.button->set_flat(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	preview.button->set_icon(get_icon("ThumbnailWait", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	preview.button->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	preview.button->connect("pressed", this, "_preview_click", varray(p_id)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	preview_hb->add_child(preview.button); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (!p_video) { | 
					
						
							|  |  |  | 		preview.image = get_icon("ThumbnailWait", "EditorIcons"); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (preview_images.size() == 0 && !p_video) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		_preview_click(p_id); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	preview_images.push_back(preview); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *vbox = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	add_child(vbox); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hbox = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	vbox->add_child(hbox); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	vbox->add_constant_override("separation", 15); | 
					
						
							|  |  |  | 	VBoxContainer *desc_vbox = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	hbox->add_child(desc_vbox); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	hbox->add_constant_override("separation", 15); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	item = memnew(EditorAssetLibraryItem); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	desc_vbox->add_child(item); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	desc_vbox->set_custom_minimum_size(Size2(300, 0)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	PanelContainer *desc_bg = memnew(PanelContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	desc_vbox->add_child(desc_bg); | 
					
						
							|  |  |  | 	desc_bg->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	description = memnew(RichTextLabel); | 
					
						
							|  |  |  | 	description->connect("meta_clicked", this, "_link_click"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	desc_bg->add_child(description); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	desc_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	preview = memnew(TextureRect); | 
					
						
							|  |  |  | 	preview->set_custom_minimum_size(Size2(640, 345)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	hbox->add_child(preview); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	PanelContainer *previews_bg = memnew(PanelContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	vbox->add_child(previews_bg); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	previews_bg->set_custom_minimum_size(Size2(0, 85)); | 
					
						
							|  |  |  | 	previews_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	previews = memnew(ScrollContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	previews_bg->add_child(previews); | 
					
						
							|  |  |  | 	previews->set_enable_v_scroll(false); | 
					
						
							|  |  |  | 	previews->set_enable_h_scroll(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	preview_hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	preview_hb->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	previews->add_child(preview_hb); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	get_ok()->set_text(TTR("Install")); | 
					
						
							|  |  |  | 	get_cancel()->set_text(TTR("Close")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String error_text; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	print_line("COMPLETED: " + itos(p_status) + " code: " + itos(p_code) + " data size: " + itos(p_data.size())); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_status) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_CANT_RESOLVE: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_text = TTR("Can't resolve hostname:") + " " + host; | 
					
						
							|  |  |  | 			status->set_text(TTR("Can't resolve.")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_CONNECTION_ERROR: | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_text = TTR("Connection error, please try again."); | 
					
						
							|  |  |  | 			status->set_text(TTR("Can't connect.")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_CANT_CONNECT: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_text = TTR("Can't connect to host:") + " " + host; | 
					
						
							|  |  |  | 			status->set_text(TTR("Can't connect.")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_NO_RESPONSE: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_text = TTR("No response from host:") + " " + host; | 
					
						
							|  |  |  | 			status->set_text(TTR("No response.")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_REQUEST_FAILED: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_text = TTR("Request failed, return code:") + " " + itos(p_code); | 
					
						
							|  |  |  | 			status->set_text(TTR("Req. Failed.")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_text = TTR("Request failed, too many redirects"); | 
					
						
							|  |  |  | 			status->set_text(TTR("Redirect Loop.")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		default: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (p_code != 200) { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 				error_text = TTR("Request failed, return code:") + " " + itos(p_code); | 
					
						
							|  |  |  | 				status->set_text(TTR("Failed:") + " " + itos(p_code)); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			} else if (sha256 != "") { | 
					
						
							| 
									
										
										
										
											2016-06-21 15:38:29 +03:00
										 |  |  | 				String download_sha256 = FileAccess::get_sha256(download->get_download_file()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (sha256 != download_sha256) { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 					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")); | 
					
						
							| 
									
										
										
										
											2016-06-21 15:38:29 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (error_text != String()) { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 		download_error->set_text(TTR("Asset Download Error:") + "\n" + error_text); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		download_error->popup_centered_minsize(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	progress->set_max(download->get_body_size()); | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 	progress->set_value(download->get_downloaded_bytes()); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	print_line("max: " + itos(download->get_body_size()) + " bytes: " + itos(download->get_downloaded_bytes())); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	install->set_disabled(false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 	progress->set_value(download->get_downloaded_bytes()); | 
					
						
							| 
									
										
										
										
											2016-07-24 14:37:26 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	status->set_text(TTR("Success!") + " (" + String::humanize_size(download->get_downloaded_bytes()) + ")"); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	set_process(false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 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) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	title->set_text(p_title); | 
					
						
							|  |  |  | 	icon->set_texture(p_preview); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_id = p_asset_id; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	if (!p_preview.is_valid()) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		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")); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	_make_request(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibraryItemDownload::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_PROCESS) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		progress->set_max(download->get_body_size()); | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 		progress->set_value(download->get_downloaded_bytes()); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		int cstatus = download->get_http_client_status(); | 
					
						
							| 
									
										
										
										
											2016-07-24 14:37:26 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (cstatus == HTTPClient::STATUS_BODY) | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			status->set_text(TTR("Fetching:") + " " + String::humanize_size(download->get_downloaded_bytes())); | 
					
						
							| 
									
										
										
										
											2016-07-24 14:37:26 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (cstatus != prev_status) { | 
					
						
							|  |  |  | 			switch (cstatus) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				case HTTPClient::STATUS_RESOLVING: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 					status->set_text(TTR("Resolving..")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case HTTPClient::STATUS_CONNECTING: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 					status->set_text(TTR("Connecting..")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case HTTPClient::STATUS_REQUESTING: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 					status->set_text(TTR("Requesting..")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				default: {} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			prev_status = cstatus; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibraryItemDownload::_close() { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); | 
					
						
							|  |  |  | 	da->remove(download->get_download_file()); //clean up removed file
 | 
					
						
							|  |  |  | 	memdelete(da); | 
					
						
							|  |  |  | 	queue_delete(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibraryItemDownload::_install() { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String file = download->get_download_file(); | 
					
						
							| 
									
										
										
										
											2016-07-11 21:34:02 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (external_install) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		emit_signal("install_asset", file, title->get_text()); | 
					
						
							| 
									
										
										
										
											2016-07-11 21:34:02 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_installer->open(file, 1); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibraryItemDownload::_make_request() { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	download->cancel_request(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	download->set_download_file(EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("tmp_asset_" + itos(asset_id)) + ".zip"); | 
					
						
							| 
									
										
										
										
											2016-07-24 16:09:43 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	Error err = download->request(host); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (err != OK) { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 		status->set_text(TTR("Error making request")); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		set_process(true); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibraryItemDownload::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2016-07-11 21:34:02 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name"))); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	add_child(hb); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	icon = memnew(TextureRect); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	hb->add_child(icon); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *vb = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	hb->add_child(vb); | 
					
						
							|  |  |  | 	vb->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *title_hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	vb->add_child(title_hb); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	title = memnew(Label); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	title_hb->add_child(title); | 
					
						
							|  |  |  | 	title->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	dismiss = memnew(TextureButton); | 
					
						
							|  |  |  | 	dismiss->connect("pressed", this, "_close"); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	title_hb->add_child(dismiss); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	title->set_clip_text(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	vb->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	status = memnew(Label(TTR("Idle"))); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	vb->add_child(status); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	status->add_color_override("font_color", Color(0.5, 0.5, 0.5)); | 
					
						
							|  |  |  | 	progress = memnew(ProgressBar); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	vb->add_child(progress); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hb2 = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	vb->add_child(hb2); | 
					
						
							|  |  |  | 	hb2->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	install = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	install->set_text(TTR("Install")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	install->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	install->connect("pressed", this, "_install"); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	retry = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	retry->set_text(TTR("Retry")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	retry->connect("pressed", this, "_make_request"); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hb2->add_child(retry); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	hb2->add_child(install); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	set_custom_minimum_size(Size2(250, 0)); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	download = memnew(HTTPRequest); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	add_child(download); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	download->connect("request_completed", this, "_http_download_completed"); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	download_error = memnew(AcceptDialog); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	add_child(download_error); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	download_error->set_title(TTR("Download Error")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_installer = memnew(EditorAssetInstaller); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	add_child(asset_installer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	prev_status = -1; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	external_install = false; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | ////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_READY) { | 
					
						
							| 
									
										
										
										
											2017-01-12 18:27:27 -03:00
										 |  |  | 		TextureRect *tf = memnew(TextureRect); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		tf->set_texture(get_icon("Error", "EditorIcons")); | 
					
						
							|  |  |  | 		reverse->set_icon(get_icon("Updown", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2016-06-08 10:17:16 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 		error_hb->add_child(tf); | 
					
						
							|  |  |  | 		error_label->raise(); | 
					
						
							| 
									
										
										
										
											2016-06-09 23:08:45 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { | 
					
						
							|  |  |  | 		if (is_visible()) { | 
					
						
							| 
									
										
										
										
											2016-06-09 23:08:45 +03:00
										 |  |  | 			_repository_changed(0); // Update when shown for the first time
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_PROCESS) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 		HTTPClient::Status s = request->get_http_client_status(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		bool visible = s != HTTPClient::STATUS_DISCONNECTED; | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 		if (visible != load_status->is_visible()) { | 
					
						
							|  |  |  | 			load_status->set_visible(visible); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (visible) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			switch (s) { | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				case HTTPClient::STATUS_RESOLVING: { | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 					load_status->set_value(0.1); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case HTTPClient::STATUS_CONNECTING: { | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 					load_status->set_value(0.2); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case HTTPClient::STATUS_REQUESTING: { | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 					load_status->set_value(0.3); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case HTTPClient::STATUS_BODY: { | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 					load_status->set_value(0.4); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 				default: {} | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		bool no_downloads = downloads_hb->get_child_count() == 0; | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 		if (no_downloads == downloads_scroll->is_visible()) { | 
					
						
							|  |  |  | 			downloads_scroll->set_visible(!no_downloads); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_install_asset() { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!description); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < downloads_hb->get_child_count(); i++) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		EditorAssetLibraryItemDownload *d = downloads_hb->get_child(i)->cast_to<EditorAssetLibraryItemDownload>(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 		if (d && d->get_asset_id() == description->get_asset_id()) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 17:19:19 -03:00
										 |  |  | 			if (EditorNode::get_singleton() != NULL) | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 				EditorNode::get_singleton()->show_warning(TTR("Download for this asset is already in progress!")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	EditorAssetLibraryItemDownload *download = memnew(EditorAssetLibraryItemDownload); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	downloads_hb->add_child(download); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	download->configure(description->get_title(), description->get_asset_id(), description->get_preview_icon(), description->get_download_url(), description->get_sha256()); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 21:34:02 -03:00
										 |  |  | 	if (templates_only) { | 
					
						
							|  |  |  | 		download->set_external_install(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		download->connect("install_asset", this, "_install_external_asset"); | 
					
						
							| 
									
										
										
										
											2016-07-11 21:34:02 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | const char *EditorAssetLibrary::sort_key[SORT_MAX] = { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	"rating", | 
					
						
							|  |  |  | 	"downloads", | 
					
						
							|  |  |  | 	"name", | 
					
						
							|  |  |  | 	"cost", | 
					
						
							|  |  |  | 	"updated" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | const char *EditorAssetLibrary::sort_text[SORT_MAX] = { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	"Rating", | 
					
						
							|  |  |  | 	"Downloads", | 
					
						
							|  |  |  | 	"Name", | 
					
						
							|  |  |  | 	"Cost", | 
					
						
							|  |  |  | 	"Updated" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | const char *EditorAssetLibrary::support_key[SUPPORT_MAX] = { | 
					
						
							| 
									
										
										
										
											2016-06-21 16:29:49 +03:00
										 |  |  | 	"official", | 
					
						
							|  |  |  | 	"community", | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_select_author(int p_id) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//opemn author window
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibrary::_select_category(int p_id) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < categories->get_item_count(); i++) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (i == 0) | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		int id = categories->get_item_metadata(i); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (id == p_id) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 			categories->select(i); | 
					
						
							|  |  |  | 			_search(); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibrary::_select_asset(int p_id) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	_api_request("asset/" + itos(p_id), REQUESTING_ASSET); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	if (description) { | 
					
						
							|  |  |  | 		memdelete(description); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | 	description = memnew( EditorAssetLibraryItemDescription ); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	add_child(description); | 
					
						
							|  |  |  | 	description->popup_centered_minsize();*/ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByteArray &p_data, int p_queue_id) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (obj) { | 
					
						
							|  |  |  | 		bool image_set = false; | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | 		PoolByteArray image_data = p_data; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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) { | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | 				PoolByteArray cached_data; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				int len = file->get_32(); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 				cached_data.resize(len); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				PoolByteArray::Write w = cached_data.write(); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 				file->get_buffer(w.ptr(), len); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 				image_data = cached_data; | 
					
						
							|  |  |  | 				file->close(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		int len = image_data.size(); | 
					
						
							|  |  |  | 		PoolByteArray::Read r = image_data.read(); | 
					
						
							| 
									
										
										
										
											2017-05-17 07:36:47 -03:00
										 |  |  | 		Ref<Image> image = Ref<Image>(memnew(Image(r.ptr(), len))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!image->empty()) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			float max_height = 10000; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			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; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-05-17 07:36:47 -03:00
										 |  |  | 			float scale_ratio = max_height / image->get_height(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (scale_ratio < 1) { | 
					
						
							| 
									
										
										
										
											2017-05-17 07:36:47 -03:00
										 |  |  | 				image->resize(image->get_width() * scale_ratio, image->get_height() * scale_ratio, Image::INTERPOLATE_CUBIC); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Ref<ImageTexture> tex; | 
					
						
							|  |  |  | 			tex.instance(); | 
					
						
							|  |  |  | 			tex->create_from_image(image); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, tex); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			image_set = true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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")); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 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)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_status == HTTPRequest::RESULT_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		print_line("GOT IMAGE YAY!"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 						file->store_line(new_etag); | 
					
						
							|  |  |  | 						file->close(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					int len = p_data.size(); | 
					
						
							|  |  |  | 					PoolByteArray::Read r = p_data.read(); | 
					
						
							|  |  |  | 					file = FileAccess::open(cache_filename_base + ".data", FileAccess::WRITE); | 
					
						
							|  |  |  | 					if (file) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 						file->store_32(len); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						file->store_buffer(r.ptr(), len); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 						file->close(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		_image_update(p_code == HTTPClient::RESPONSE_NOT_MODIFIED, true, p_data, p_queue_id); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		WARN_PRINTS("Error getting PNG file for asset id " + itos(image_queue[p_queue_id].asset_id)); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target); | 
					
						
							|  |  |  | 		if (obj) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("ErrorSign", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 18:03:38 +01:00
										 |  |  | 	image_queue[p_queue_id].request->queue_delete(); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	image_queue.erase(p_queue_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_update_image_queue(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_update_image_queue() { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int max_images = 2; | 
					
						
							|  |  |  | 	int current_images = 0; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	List<int> to_delete; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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()); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			Vector<String> headers; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (FileAccess::exists(cache_filename_base + ".etag") && FileAccess::exists(cache_filename_base + ".data")) { | 
					
						
							|  |  |  | 				FileAccess *file = FileAccess::open(cache_filename_base + ".etag", FileAccess::READ); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 				if (file) { | 
					
						
							|  |  |  | 					headers.push_back("If-None-Match: " + file->get_line()); | 
					
						
							|  |  |  | 					file->close(); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			print_line("REQUEST ICON FOR: " + itos(E->get().asset_id)); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			Error err = E->get().request->request(E->get().image_url, headers); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (err != OK) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 				to_delete.push_back(E->key()); | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				E->get().active = true; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			current_images++; | 
					
						
							|  |  |  | 		} else if (E->get().active) { | 
					
						
							|  |  |  | 			current_images++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	while (to_delete.size()) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 		image_queue[to_delete.front()->get()].request->queue_delete(); | 
					
						
							|  |  |  | 		image_queue.erase(to_delete.front()->get()); | 
					
						
							|  |  |  | 		to_delete.pop_front(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibrary::_request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ImageQueue iq; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	iq.image_url = p_image_url; | 
					
						
							|  |  |  | 	iq.image_index = p_image_index; | 
					
						
							|  |  |  | 	iq.image_type = p_type; | 
					
						
							|  |  |  | 	iq.request = memnew(HTTPRequest); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	iq.target = p_for; | 
					
						
							|  |  |  | 	iq.queue_id = ++last_queue_id; | 
					
						
							|  |  |  | 	iq.active = false; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	iq.request->connect("request_completed", this, "_image_request_completed", varray(iq.queue_id)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	image_queue[iq.queue_id] = iq; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	add_child(iq.request); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | 	_image_update(true, false, PoolByteArray(), iq.queue_id); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	_update_image_queue(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_repository_changed(int p_repository_id) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	host = repository->get_item_metadata(p_repository_id); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	print_line(".." + host); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (templates_only) { | 
					
						
							| 
									
										
										
										
											2016-06-21 17:10:02 +03:00
										 |  |  | 		_api_request("configure", REQUESTING_CONFIG, "?type=project"); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		_api_request("configure", REQUESTING_CONFIG); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 16:29:49 +03:00
										 |  |  | void EditorAssetLibrary::_support_toggled(int p_support) { | 
					
						
							|  |  |  | 	support->get_popup()->set_item_checked(p_support, !support->get_popup()->is_item_checked(p_support)); | 
					
						
							| 
									
										
										
										
											2016-06-21 17:10:02 +03:00
										 |  |  | 	_search(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAssetLibrary::_rerun_search(int p_ignore) { | 
					
						
							|  |  |  | 	_search(); | 
					
						
							| 
									
										
										
										
											2016-06-21 16:29:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_search(int p_page) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String args; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (templates_only) { | 
					
						
							| 
									
										
										
										
											2016-06-21 17:10:02 +03:00
										 |  |  | 		args += "?type=project&"; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		args += "?"; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	args += String() + "sort=" + sort_key[sort->get_selected()]; | 
					
						
							| 
									
										
										
										
											2016-06-21 17:10:02 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 16:29:49 +03:00
										 |  |  | 	String support_list; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < SUPPORT_MAX; i++) { | 
					
						
							|  |  |  | 		if (support->get_popup()->is_item_checked(i)) { | 
					
						
							| 
									
										
										
										
											2016-06-21 16:29:49 +03:00
										 |  |  | 			support_list += String(support_key[i]) + "+"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (support_list != String()) { | 
					
						
							| 
									
										
										
										
											2016-06-21 16:29:49 +03:00
										 |  |  | 		args += "&support=" + support_list.substr(0, support_list.length() - 1); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (categories->get_selected() > 0) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		args += "&category=" + itos(categories->get_item_metadata(categories->get_selected())); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	if (reverse->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		args += "&reverse=true"; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (filter->get_text() != String()) { | 
					
						
							|  |  |  | 		args += "&filter=" + filter->get_text().http_escape(); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_page > 0) { | 
					
						
							|  |  |  | 		args += "&page=" + itos(p_page); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	_api_request("asset", REQUESTING_SEARCH, args); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hbc = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//do the mario
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int from = p_page - 5; | 
					
						
							|  |  |  | 	if (from < 0) | 
					
						
							|  |  |  | 		from = 0; | 
					
						
							|  |  |  | 	int to = from + 10; | 
					
						
							|  |  |  | 	if (to > p_page_count) | 
					
						
							|  |  |  | 		to = p_page_count; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Color gray = Color(0.65, 0.65, 0.65); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hbc->add_spacer(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	hbc->add_constant_override("separation", 10); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_page != 0) { | 
					
						
							|  |  |  | 		LinkButton *first = memnew(LinkButton); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 		first->set_text(TTR("first")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		first->add_color_override("font_color", gray); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		first->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		first->connect("pressed", this, "_search", varray(0)); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		hbc->add_child(first); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_page > 0) { | 
					
						
							|  |  |  | 		LinkButton *prev = memnew(LinkButton); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 		prev->set_text(TTR("prev")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		prev->add_color_override("font_color", gray); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 		prev->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		prev->connect("pressed", this, "_search", varray(p_page - 1)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 		hbc->add_child(prev); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = from; i < to; i++) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (i == p_page) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			Label *current = memnew(Label); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			current->set_text(itos(i + 1)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 			hbc->add_child(current); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			LinkButton *current = memnew(LinkButton); | 
					
						
							|  |  |  | 			current->add_color_override("font_color", gray); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 			current->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			current->set_text(itos(i + 1)); | 
					
						
							|  |  |  | 			current->connect("pressed", this, "_search", varray(i)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			hbc->add_child(current); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_page < p_page_count - 1) { | 
					
						
							|  |  |  | 		LinkButton *next = memnew(LinkButton); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 		next->set_text(TTR("next")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		next->add_color_override("font_color", gray); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 		next->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		next->connect("pressed", this, "_search", varray(p_page + 1)); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		hbc->add_child(next); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_page != p_page_count - 1) { | 
					
						
							|  |  |  | 		LinkButton *last = memnew(LinkButton); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 		last->set_text(TTR("last")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		last->add_color_override("font_color", gray); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		last->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); | 
					
						
							|  |  |  | 		hbc->add_child(last); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		last->connect("pressed", this, "_search", varray(p_page_count - 1)); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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) + " )"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	hbc->add_child(totals); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hbc->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return hbc; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibrary::_api_request(const String &p_request, RequestType p_request_type, const String &p_arguments) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (requesting != REQUESTING_NONE) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 		request->cancel_request(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-24 16:09:43 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	requesting = p_request_type; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 	error_hb->hide(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	request->request(host + "/" + p_request + p_arguments); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String str; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int datalen = p_data.size(); | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | 		PoolByteArray::Read r = p_data.read(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		str.parse_utf8((const char *)r.ptr(), datalen); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	bool error_abort = true; | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_status) { | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_CANT_RESOLVE: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_label->set_text(TTR("Can't resolve hostname:") + " " + host); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_CONNECTION_ERROR: | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_label->set_text(TTR("Connection error, please try again.")); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_CANT_CONNECT: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_label->set_text(TTR("Can't connect to host:") + " " + host); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_NO_RESPONSE: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_label->set_text(TTR("No response from host:") + " " + host); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_REQUEST_FAILED: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_label->set_text(TTR("Request failed, return code:") + " " + itos(p_code)); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			error_label->set_text(TTR("Request failed, too many redirects")); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		default: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (p_code != 200) { | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 				error_label->set_text(TTR("Request failed, return code:") + " " + itos(p_code)); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				error_abort = false; | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (error_abort) { | 
					
						
							|  |  |  | 		error_hb->show(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	print_line("response: " + itos(p_status) + " code: " + itos(p_code)); | 
					
						
							| 
									
										
										
										
											2017-01-08 22:40:00 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	Dictionary d; | 
					
						
							| 
									
										
										
										
											2017-01-08 22:40:00 -03:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		Variant js; | 
					
						
							|  |  |  | 		String errs; | 
					
						
							|  |  |  | 		int errl; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		JSON::parse(str, js, errs, errl); | 
					
						
							|  |  |  | 		d = js; | 
					
						
							| 
									
										
										
										
											2017-01-08 22:40:00 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	print_line(Variant(d).get_construct_string()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 	RequestType requested = requesting; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	requesting = REQUESTING_NONE; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (requested) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		case REQUESTING_CONFIG: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			categories->clear(); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 			categories->add_item(TTR("All")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			categories->set_item_metadata(0, 0); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			if (d.has("categories")) { | 
					
						
							|  |  |  | 				Array clist = d["categories"]; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				for (int i = 0; i < clist.size(); i++) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					Dictionary cat = clist[i]; | 
					
						
							|  |  |  | 					if (!cat.has("name") || !cat.has("id")) | 
					
						
							|  |  |  | 						continue; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					String name = cat["name"]; | 
					
						
							|  |  |  | 					int id = cat["id"]; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					categories->add_item(name); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					categories->set_item_metadata(categories->get_item_count() - 1, id); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					category_map[cat["id"]] = name; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			_search(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case REQUESTING_SEARCH: { | 
					
						
							|  |  |  | 			if (asset_items) { | 
					
						
							|  |  |  | 				memdelete(asset_items); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			if (asset_top_page) { | 
					
						
							|  |  |  | 				memdelete(asset_top_page); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			if (asset_bottom_page) { | 
					
						
							|  |  |  | 				memdelete(asset_bottom_page); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			int page = 0; | 
					
						
							|  |  |  | 			int pages = 1; | 
					
						
							|  |  |  | 			int page_len = 10; | 
					
						
							|  |  |  | 			int total_items = 1; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			Array result; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			if (d.has("page")) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				page = d["page"]; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (d.has("pages")) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				pages = d["pages"]; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (d.has("page_length")) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				page_len = d["page_length"]; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (d.has("total")) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				total_items = d["total"]; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (d.has("result")) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				result = d["result"]; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			asset_top_page = _make_pages(page, pages, page_len, total_items, result.size()); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			library_vb->add_child(asset_top_page); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			asset_items = memnew(GridContainer); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			asset_items->set_columns(2); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			asset_items->add_constant_override("hseparation", 10); | 
					
						
							|  |  |  | 			asset_items->add_constant_override("vseparation", 10); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			library_vb->add_child(asset_items); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			asset_bottom_page = _make_pages(page, pages, page_len, total_items, result.size()); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			library_vb->add_child(asset_bottom_page); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (int i = 0; i < result.size(); i++) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 				Dictionary r = result[i]; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 				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")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				EditorAssetLibraryItem *item = memnew(EditorAssetLibraryItem); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 				asset_items->add_child(item); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				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"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (r.has("icon_url") && r["icon_url"] != "") { | 
					
						
							|  |  |  | 					_request_image(item->get_instance_ID(), r["icon_url"], IMAGE_QUEUE_ICON, 0); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} 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")); | 
					
						
							| 
									
										
										
										
											2016-06-21 15:38:29 +03:00
										 |  |  | 			ERR_FAIL_COND(!r.has("download_hash")); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			ERR_FAIL_COND(!r.has("browse_url")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (description) { | 
					
						
							|  |  |  | 				memdelete(description); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			description = memnew(EditorAssetLibraryItemDescription); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			add_child(description); | 
					
						
							|  |  |  | 			description->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			description->connect("confirmed", this, "_install_asset"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			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"]); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			/*item->connect("asset_selected",this,"_select_asset");
 | 
					
						
							|  |  |  | 			item->connect("author_selected",this,"_select_author"); | 
					
						
							|  |  |  | 			item->connect("category_selected",this,"_category_selected");*/ | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (r.has("icon_url") && r["icon_url"] != "") { | 
					
						
							|  |  |  | 				_request_image(description->get_instance_ID(), r["icon_url"], IMAGE_QUEUE_ICON, 0); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 			if (d.has("previews")) { | 
					
						
							|  |  |  | 				Array previews = d["previews"]; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				for (int i = 0; i < previews.size(); i++) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					Dictionary p = previews[i]; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					ERR_CONTINUE(!p.has("type")); | 
					
						
							|  |  |  | 					ERR_CONTINUE(!p.has("link")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					bool is_video = p.has("type") && String(p["type"]) == "video"; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					String video_url; | 
					
						
							|  |  |  | 					if (is_video && p.has("link")) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						video_url = p["link"]; | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					description->add_preview(i, is_video, video_url); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (p.has("thumbnail")) { | 
					
						
							|  |  |  | 						_request_image(description->get_instance_ID(), p["thumbnail"], IMAGE_QUEUE_THUMBNAIL, i); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (is_video) { | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 						//_request_image(description->get_instance_ID(),p["link"],IMAGE_QUEUE_SCREENSHOT,i);
 | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						_request_image(description->get_instance_ID(), p["link"], IMAGE_QUEUE_SCREENSHOT, i); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		default: break; | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibrary::_asset_file_selected(const String &p_file) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (asset_installer) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		memdelete(asset_installer); | 
					
						
							|  |  |  | 		asset_installer = NULL; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_installer = memnew(EditorAssetInstaller); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	add_child(asset_installer); | 
					
						
							|  |  |  | 	asset_installer->open(p_file); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_asset_open() { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	asset_open->popup_centered_ratio(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_manage_plugins() { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-19 17:00:46 -03:00
										 |  |  | 	ProjectSettingsEditor::get_singleton()->popup_project_settings(); | 
					
						
							|  |  |  | 	ProjectSettingsEditor::get_singleton()->set_plugins_page(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorAssetLibrary::_install_external_asset(String p_zip_path, String p_title) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	emit_signal("install_asset", p_zip_path, p_title); | 
					
						
							| 
									
										
										
										
											2016-07-11 21:34:02 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | void EditorAssetLibrary::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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"))); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	templates_only = p_templates_only; | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *library_main = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	add_child(library_main); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *search_hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_main->add_child(search_hb); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	library_main->add_constant_override("separation", 10); | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	search_hb->add_child(memnew(Label(TTR("Search:") + " "))); | 
					
						
							|  |  |  | 	filter = memnew(LineEdit); | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 	search_hb->add_child(filter); | 
					
						
							|  |  |  | 	filter->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	filter->connect("text_entered", this, "_search"); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	search = memnew(Button(TTR("Search"))); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	search->connect("pressed", this, "_search"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	search_hb->add_child(search); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | 	if (!p_templates_only) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		search_hb->add_child(memnew(VSeparator)); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Button *open_asset = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	open_asset->set_text(TTR("Import")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	search_hb->add_child(open_asset); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	open_asset->connect("pressed", this, "_asset_open"); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Button *plugins = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	plugins->set_text(TTR("Plugins")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	search_hb->add_child(plugins); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	plugins->connect("pressed", this, "_manage_plugins"); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 09:25:47 -03:00
										 |  |  | 	if (p_templates_only) { | 
					
						
							|  |  |  | 		open_asset->hide(); | 
					
						
							|  |  |  | 		plugins->hide(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *search_hb2 = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_main->add_child(search_hb2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	search_hb2->add_child(memnew(Label(TTR("Sort:") + " "))); | 
					
						
							|  |  |  | 	sort = memnew(OptionButton); | 
					
						
							|  |  |  | 	for (int i = 0; i < SORT_MAX; i++) { | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 		sort->add_item(sort_text[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	search_hb2->add_child(sort); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sort->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2016-06-21 17:10:02 +03:00
										 |  |  | 	sort->connect("item_selected", this, "_rerun_search"); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	reverse = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-06-08 10:17:16 -03:00
										 |  |  | 	reverse->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2016-06-21 17:10:02 +03:00
										 |  |  | 	reverse->connect("toggled", this, "_rerun_search"); | 
					
						
							| 
									
										
										
										
											2016-06-08 10:17:16 -03:00
										 |  |  | 	//reverse->set_text(TTR("Reverse"));
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	search_hb2->add_child(reverse); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	search_hb2->add_child(memnew(VSeparator)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//search_hb2->add_spacer();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	search_hb2->add_child(memnew(Label(TTR("Category:") + " "))); | 
					
						
							|  |  |  | 	categories = memnew(OptionButton); | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	categories->add_item(TTR("All")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	search_hb2->add_child(categories); | 
					
						
							|  |  |  | 	categories->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	//search_hb2->add_spacer();
 | 
					
						
							| 
									
										
										
										
											2016-06-21 17:10:02 +03:00
										 |  |  | 	categories->connect("item_selected", this, "_rerun_search"); | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	search_hb2->add_child(memnew(VSeparator)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	search_hb2->add_child(memnew(Label(TTR("Site:") + " "))); | 
					
						
							|  |  |  | 	repository = memnew(OptionButton); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 22:29:42 +02:00
										 |  |  | 	// FIXME: Reenable me once GH-7147 is fixed.
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2017-04-20 14:42:35 +02:00
										 |  |  | 	repository->add_item("godotengine.org"); | 
					
						
							| 
									
										
										
										
											2016-06-29 19:16:20 +02:00
										 |  |  | 	repository->set_item_metadata(0, "https://godotengine.org/asset-library/api"); | 
					
						
							| 
									
										
										
										
											2017-07-25 22:29:42 +02:00
										 |  |  | 	*/ | 
					
						
							|  |  |  | 	repository->add_item("localhost"); | 
					
						
							|  |  |  | 	repository->set_item_metadata(/*1*/ 0, "http://127.0.0.1/asset-library/api"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	repository->connect("item_selected", this, "_repository_changed"); | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	search_hb2->add_child(repository); | 
					
						
							|  |  |  | 	repository->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 10:17:16 -03:00
										 |  |  | 	search_hb2->add_child(memnew(VSeparator)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	support = memnew(MenuButton); | 
					
						
							| 
									
										
										
										
											2016-06-08 10:17:16 -03:00
										 |  |  | 	search_hb2->add_child(support); | 
					
						
							|  |  |  | 	support->set_text(TTR("Support..")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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"); | 
					
						
							| 
									
										
										
										
											2016-06-08 10:17:16 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	/////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	PanelContainer *library_scroll_bg = memnew(PanelContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_main->add_child(library_scroll_bg); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	library_scroll_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_scroll_bg->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	library_scroll = memnew(ScrollContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	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(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	PanelContainer *library_vb_border = memnew(PanelContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_scroll->add_child(library_vb_border); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	library_vb_border->add_style_override("panel", border2); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_vb_border->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-01-08 19:54:19 -03:00
										 |  |  | 	library_vb_border->set_mouse_filter(MOUSE_FILTER_PASS); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	library_vb = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_vb->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	library_vb_border->add_child(library_vb); | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 	//margin_panel->set_stop_mouse(false);
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_top_page = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_vb->add_child(asset_top_page); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_items = memnew(GridContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	asset_items->set_columns(2); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_items->add_constant_override("hseparation", 10); | 
					
						
							|  |  |  | 	asset_items->add_constant_override("vseparation", 10); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	library_vb->add_child(asset_items); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_bottom_page = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	library_vb->add_child(asset_bottom_page); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	request = memnew(HTTPRequest); | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	add_child(request); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	request->set_use_threads(EDITOR_DEF("asset_library/use_threads", true)); | 
					
						
							|  |  |  | 	request->connect("request_completed", this, "_http_request_completed"); | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	last_queue_id = 0; | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	library_vb->add_constant_override("separation", 20); | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	load_status = memnew(ProgressBar); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 	load_status->set_min(0); | 
					
						
							|  |  |  | 	load_status->set_max(1); | 
					
						
							|  |  |  | 	load_status->set_step(0.001); | 
					
						
							|  |  |  | 	library_main->add_child(load_status); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	error_hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 	library_main->add_child(error_hb); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	error_label = memnew(Label); | 
					
						
							|  |  |  | 	error_label->add_color_override("color", Color(1, 0.4, 0.3)); | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 	error_hb->add_child(error_label); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 11:09:45 -03:00
										 |  |  | 	description = NULL; | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 12:24:12 -03:00
										 |  |  | 	set_process(true); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	downloads_scroll = memnew(ScrollContainer); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	downloads_scroll->set_enable_h_scroll(true); | 
					
						
							|  |  |  | 	downloads_scroll->set_enable_v_scroll(false); | 
					
						
							|  |  |  | 	library_main->add_child(downloads_scroll); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	downloads_hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	downloads_scroll->add_child(downloads_hb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_open = memnew(EditorFileDialog); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	asset_open->set_access(EditorFileDialog::ACCESS_FILESYSTEM); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_open->add_filter("*.zip ; " + TTR("Assets ZIP File")); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 	asset_open->set_mode(EditorFileDialog::MODE_OPEN_FILE); | 
					
						
							|  |  |  | 	add_child(asset_open); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_open->connect("file_selected", this, "_asset_file_selected"); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:44:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	asset_installer = NULL; | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | void AssetLibraryEditorPlugin::make_visible(bool p_visible) { | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_visible) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		addon_library->show(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		addon_library->hide(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | AssetLibraryEditorPlugin::AssetLibraryEditorPlugin(EditorNode *p_node) { | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	editor = p_node; | 
					
						
							|  |  |  | 	addon_library = memnew(EditorAssetLibrary); | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | 	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(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 21:29:15 +03:00
										 |  |  | AssetLibraryEditorPlugin::~AssetLibraryEditorPlugin() { | 
					
						
							| 
									
										
										
										
											2016-02-29 09:56:36 -03:00
										 |  |  | } |