Path: blob/master/editor/inspector/editor_resource_picker.h
21436 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"33#include "scene/resources/material.h"3435class Button;36class ConfirmationDialog;37class EditorFileDialog;38class PopupMenu;39class TextureRect;40class Tree;41class TreeItem;4243class EditorResourcePicker : public HBoxContainer {44GDCLASS(EditorResourcePicker, HBoxContainer);4546String base_type;47Ref<Resource> edited_resource;4849bool editable = true;50bool dropping = false;51bool force_allow_unique = false;5253Vector<String> inheritors_array;54mutable HashSet<StringName> allowed_types_without_convert;55mutable HashSet<StringName> allowed_types_with_convert;5657Button *assign_button = nullptr;58Button *make_unique_button = nullptr;59TextureRect *preview_rect = nullptr;60Button *edit_button = nullptr;61Button *quick_load_button = nullptr;62EditorFileDialog *file_dialog = nullptr;6364ConfirmationDialog *duplicate_resources_dialog = nullptr;65Tree *duplicate_resources_tree = nullptr;6667Size2i assign_button_min_size = Size2i(1, 1);6869enum MenuOption {70OBJ_MENU_LOAD,71OBJ_MENU_QUICKLOAD,72OBJ_MENU_INSPECT,73OBJ_MENU_CLEAR,74OBJ_MENU_MAKE_UNIQUE,75OBJ_MENU_MAKE_UNIQUE_RECURSIVE,76OBJ_MENU_SAVE,77OBJ_MENU_SAVE_AS,78OBJ_MENU_COPY,79OBJ_MENU_PASTE,80OBJ_MENU_PASTE_AS_UNIQUE,81OBJ_MENU_SHOW_IN_FILE_SYSTEM,8283TYPE_BASE_ID = 100,84CONVERT_BASE_ID = 1000,85};8687Object *resource_owner = nullptr;88StringName property_path;8990PopupMenu *edit_menu = nullptr;9192void _update_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj);9394void _resource_selected();95void _resource_changed();96void _file_selected(const String &p_path);9798void _resource_saved(Object *p_resource);99100void _update_menu();101void _update_menu_items();102void _edit_menu_cbk(int p_which);103104void _button_draw();105void _button_input(const Ref<InputEvent> &p_event);106void _on_unique_button_pressed();107108String _get_owner_path() const;109String _get_resource_type(const Ref<Resource> &p_resource) const;110void _ensure_allowed_types() const;111bool _is_drop_valid(const Dictionary &p_drag_data) const;112bool _is_type_valid(const String &p_type_name, const HashSet<StringName> &p_allowed_types) const;113bool _is_custom_type_script() const;114Ref<Resource> _get_dropped_resource(const Variant &p_data) const;115116Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);117bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;118void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);119120void _ensure_resource_menu();121void _gather_resources_to_duplicate(const Ref<Resource> p_resource, TreeItem *p_item, const String &p_property_name = "") const;122void _duplicate_selected_resources();123bool _is_uniqueness_enabled(bool p_check_recursive = false);124Ref<Resource> _has_parent_resource();125126protected:127virtual void _update_resource();128129Button *get_assign_button() { return assign_button; }130static void _bind_methods();131void _notification(int p_what);132133void set_assign_button_min_size(const Size2i &p_size);134135GDVIRTUAL1(_set_create_options, Object *)136GDVIRTUAL1R(bool, _handle_menu_selected, int)137138public:139void set_base_type(const String &p_base_type);140String get_base_type() const;141Vector<String> get_allowed_types() const;142143bool is_resource_allowed(const Ref<Resource> &p_resource);144void set_edited_resource(Ref<Resource> p_resource);145void set_edited_resource_no_check(Ref<Resource> p_resource);146Ref<Resource> get_edited_resource();147void set_force_allow_unique(bool p_force) { force_allow_unique = p_force; }148149void set_toggle_mode(bool p_enable);150bool is_toggle_mode() const;151void set_toggle_pressed(bool p_pressed);152bool is_toggle_pressed() const;153154void set_resource_owner(Object *p_object);155void set_property_path(const StringName &p_path) { property_path = p_path; }156157void set_editable(bool p_editable);158bool is_editable() const;159160virtual void set_create_options(Object *p_menu_node);161virtual bool handle_menu_selected(int p_which);162163EditorResourcePicker(bool p_hide_assign_button_controls = false);164};165166class EditorScriptPicker : public EditorResourcePicker {167GDCLASS(EditorScriptPicker, EditorResourcePicker);168169enum ExtraMenuOption {170OBJ_MENU_NEW_SCRIPT = 50,171OBJ_MENU_EXTEND_SCRIPT = 51172};173174Node *script_owner = nullptr;175176protected:177static void _bind_methods();178179public:180virtual void set_create_options(Object *p_menu_node) override;181virtual bool handle_menu_selected(int p_which) override;182183void set_script_owner(Node *p_owner);184Node *get_script_owner() const;185};186187class EditorShaderPicker : public EditorResourcePicker {188GDCLASS(EditorShaderPicker, EditorResourcePicker);189190enum ExtraMenuOption {191OBJ_MENU_NEW_SHADER = 50,192};193194ShaderMaterial *edited_material = nullptr;195int preferred_mode = -1;196197public:198virtual void set_create_options(Object *p_menu_node) override;199virtual bool handle_menu_selected(int p_which) override;200201void set_edited_material(ShaderMaterial *p_material);202ShaderMaterial *get_edited_material() const;203void set_preferred_mode(int p_preferred_mode);204};205206class EditorAudioStreamPicker : public EditorResourcePicker {207GDCLASS(EditorAudioStreamPicker, EditorResourcePicker);208209uint64_t last_preview_version = 0;210Control *stream_preview_rect = nullptr;211212enum {213MAX_TAGGED_FRAMES = 8214};215float tagged_frame_offsets[MAX_TAGGED_FRAMES];216uint32_t tagged_frame_offset_count = 0;217218void _preview_draw();219virtual void _update_resource() override;220221protected:222void _notification(int p_what);223224public:225EditorAudioStreamPicker();226};227228229