1 /*************************************************************************/
2 /*  resource_preloader_editor_plugin.h                                   */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 
31 #ifndef RESOURCE_PRELOADER_EDITOR_PLUGIN_H
32 #define RESOURCE_PRELOADER_EDITOR_PLUGIN_H
33 
34 #include "editor/editor_node.h"
35 #include "editor/editor_plugin.h"
36 #include "scene/gui/dialogs.h"
37 #include "scene/gui/file_dialog.h"
38 #include "scene/gui/tree.h"
39 #include "scene/main/resource_preloader.h"
40 
41 class ResourcePreloaderEditor : public PanelContainer {
42 
43 	GDCLASS(ResourcePreloaderEditor, PanelContainer);
44 
45 	enum {
46 		BUTTON_OPEN_SCENE,
47 		BUTTON_EDIT_RESOURCE,
48 		BUTTON_REMOVE
49 	};
50 
51 	Button *load;
52 	Button *paste;
53 	Tree *tree;
54 	bool loading_scene;
55 
56 	EditorFileDialog *file;
57 
58 	AcceptDialog *dialog;
59 
60 	ResourcePreloader *preloader;
61 
62 	void _load_pressed();
63 	void _load_scene_pressed();
64 	void _files_load_request(const Vector<String> &p_paths);
65 	void _paste_pressed();
66 	void _remove_resource(const String &p_to_remove);
67 	void _update_library();
68 	void _cell_button_pressed(Object *p_item, int p_column, int p_id);
69 	void _item_edited();
70 
71 	UndoRedo *undo_redo;
72 
73 	Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
74 	bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
75 	void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
76 
77 protected:
78 	void _notification(int p_what);
79 	void _gui_input(Ref<InputEvent> p_event);
80 	static void _bind_methods();
81 
82 public:
set_undo_redo(UndoRedo * p_undo_redo)83 	void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
84 
85 	void edit(ResourcePreloader *p_preloader);
86 	ResourcePreloaderEditor();
87 };
88 
89 class ResourcePreloaderEditorPlugin : public EditorPlugin {
90 
91 	GDCLASS(ResourcePreloaderEditorPlugin, EditorPlugin);
92 
93 	ResourcePreloaderEditor *preloader_editor;
94 	EditorNode *editor;
95 	Button *button;
96 
97 public:
get_name()98 	virtual String get_name() const { return "ResourcePreloader"; }
has_main_screen()99 	bool has_main_screen() const { return false; }
100 	virtual void edit(Object *p_object);
101 	virtual bool handles(Object *p_object) const;
102 	virtual void make_visible(bool p_visible);
103 
104 	ResourcePreloaderEditorPlugin(EditorNode *p_node);
105 	~ResourcePreloaderEditorPlugin();
106 };
107 
108 #endif // RESOURCE_PRELOADER_EDITOR_PLUGIN_H
109