Path: blob/master/editor/inspector/editor_resource_picker.h
9898 views
/**************************************************************************/1/* editor_resource_picker.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/gui/box_container.h"3334class Button;35class ConfirmationDialog;36class EditorFileDialog;37class PopupMenu;38class TextureRect;39class Tree;40class TreeItem;4142class EditorResourcePicker : public HBoxContainer {43GDCLASS(EditorResourcePicker, HBoxContainer);4445String base_type;46Ref<Resource> edited_resource;4748bool editable = true;49bool dropping = false;5051Vector<String> inheritors_array;52mutable HashSet<StringName> allowed_types_without_convert;53mutable HashSet<StringName> allowed_types_with_convert;5455Button *assign_button = nullptr;56TextureRect *preview_rect = nullptr;57Button *edit_button = nullptr;58Button *quick_load_button = nullptr;59EditorFileDialog *file_dialog = nullptr;6061ConfirmationDialog *duplicate_resources_dialog = nullptr;62Tree *duplicate_resources_tree = nullptr;6364Size2i assign_button_min_size = Size2i(1, 1);6566enum MenuOption {67OBJ_MENU_LOAD,68OBJ_MENU_QUICKLOAD,69OBJ_MENU_INSPECT,70OBJ_MENU_CLEAR,71OBJ_MENU_MAKE_UNIQUE,72OBJ_MENU_MAKE_UNIQUE_RECURSIVE,73OBJ_MENU_SAVE,74OBJ_MENU_SAVE_AS,75OBJ_MENU_COPY,76OBJ_MENU_PASTE,77OBJ_MENU_PASTE_AS_UNIQUE,78OBJ_MENU_SHOW_IN_FILE_SYSTEM,7980TYPE_BASE_ID = 100,81CONVERT_BASE_ID = 1000,82};8384Object *resource_owner = nullptr;8586PopupMenu *edit_menu = nullptr;8788void _update_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj);8990void _resource_selected();91void _resource_changed();92void _file_selected(const String &p_path);9394void _resource_saved(Object *p_resource);9596void _update_menu();97void _update_menu_items();98void _edit_menu_cbk(int p_which);99100void _button_draw();101void _button_input(const Ref<InputEvent> &p_event);102103String _get_owner_path() const;104String _get_resource_type(const Ref<Resource> &p_resource) const;105void _ensure_allowed_types() const;106bool _is_drop_valid(const Dictionary &p_drag_data) const;107bool _is_type_valid(const String &p_type_name, const HashSet<StringName> &p_allowed_types) const;108bool _is_custom_type_script() const;109110Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);111bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;112void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);113114void _ensure_resource_menu();115void _gather_resources_to_duplicate(const Ref<Resource> p_resource, TreeItem *p_item, const String &p_property_name = "") const;116void _duplicate_selected_resources();117118protected:119virtual void _update_resource();120121Button *get_assign_button() { return assign_button; }122static void _bind_methods();123void _notification(int p_what);124125void set_assign_button_min_size(const Size2i &p_size);126127GDVIRTUAL1(_set_create_options, Object *)128GDVIRTUAL1R(bool, _handle_menu_selected, int)129130public:131void set_base_type(const String &p_base_type);132String get_base_type() const;133Vector<String> get_allowed_types() const;134135void set_edited_resource(Ref<Resource> p_resource);136void set_edited_resource_no_check(Ref<Resource> p_resource);137Ref<Resource> get_edited_resource();138139void set_toggle_mode(bool p_enable);140bool is_toggle_mode() const;141void set_toggle_pressed(bool p_pressed);142bool is_toggle_pressed() const;143144void set_resource_owner(Object *p_object);145146void set_editable(bool p_editable);147bool is_editable() const;148149virtual void set_create_options(Object *p_menu_node);150virtual bool handle_menu_selected(int p_which);151152EditorResourcePicker(bool p_hide_assign_button_controls = false);153};154155class EditorScriptPicker : public EditorResourcePicker {156GDCLASS(EditorScriptPicker, EditorResourcePicker);157158enum ExtraMenuOption {159OBJ_MENU_NEW_SCRIPT = 50,160OBJ_MENU_EXTEND_SCRIPT = 51161};162163Node *script_owner = nullptr;164165protected:166static void _bind_methods();167168public:169virtual void set_create_options(Object *p_menu_node) override;170virtual bool handle_menu_selected(int p_which) override;171172void set_script_owner(Node *p_owner);173Node *get_script_owner() const;174};175176class EditorShaderPicker : public EditorResourcePicker {177GDCLASS(EditorShaderPicker, EditorResourcePicker);178179enum ExtraMenuOption {180OBJ_MENU_NEW_SHADER = 50,181};182183ShaderMaterial *edited_material = nullptr;184int preferred_mode = -1;185186public:187virtual void set_create_options(Object *p_menu_node) override;188virtual bool handle_menu_selected(int p_which) override;189190void set_edited_material(ShaderMaterial *p_material);191ShaderMaterial *get_edited_material() const;192void set_preferred_mode(int p_preferred_mode);193};194195class EditorAudioStreamPicker : public EditorResourcePicker {196GDCLASS(EditorAudioStreamPicker, EditorResourcePicker);197198uint64_t last_preview_version = 0;199Control *stream_preview_rect = nullptr;200201enum {202MAX_TAGGED_FRAMES = 8203};204float tagged_frame_offsets[MAX_TAGGED_FRAMES];205uint32_t tagged_frame_offset_count = 0;206207void _preview_draw();208virtual void _update_resource() override;209210protected:211void _notification(int p_what);212213public:214EditorAudioStreamPicker();215};216217218