2023-01-05 12:25:55 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_resource_picker.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2021-05-17 12:25:38 +00:00
|
|
|
|
|
|
|
#ifndef EDITOR_RESOURCE_PICKER_H
|
|
|
|
#define EDITOR_RESOURCE_PICKER_H
|
|
|
|
|
|
|
|
#include "scene/gui/box_container.h"
|
|
|
|
|
2023-06-04 21:59:03 +00:00
|
|
|
class Button;
|
|
|
|
class ConfirmationDialog;
|
2022-02-12 01:46:22 +00:00
|
|
|
class EditorFileDialog;
|
2022-02-14 13:00:03 +00:00
|
|
|
class EditorQuickOpen;
|
2023-06-04 21:59:03 +00:00
|
|
|
class PopupMenu;
|
|
|
|
class TextureRect;
|
|
|
|
class Tree;
|
|
|
|
class TreeItem;
|
2022-02-12 01:46:22 +00:00
|
|
|
|
2021-05-17 12:25:38 +00:00
|
|
|
class EditorResourcePicker : public HBoxContainer {
|
|
|
|
GDCLASS(EditorResourcePicker, HBoxContainer);
|
|
|
|
|
|
|
|
String base_type;
|
2022-05-02 23:43:50 +00:00
|
|
|
Ref<Resource> edited_resource;
|
2021-05-17 12:25:38 +00:00
|
|
|
|
|
|
|
bool editable = true;
|
|
|
|
bool dropping = false;
|
|
|
|
|
|
|
|
Vector<String> inheritors_array;
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
Button *assign_button = nullptr;
|
|
|
|
TextureRect *preview_rect = nullptr;
|
|
|
|
Button *edit_button = nullptr;
|
2021-05-25 15:38:19 +00:00
|
|
|
EditorFileDialog *file_dialog = nullptr;
|
2020-03-22 13:31:46 +00:00
|
|
|
EditorQuickOpen *quick_open = nullptr;
|
2021-05-17 12:25:38 +00:00
|
|
|
|
2023-06-04 21:59:03 +00:00
|
|
|
ConfirmationDialog *duplicate_resources_dialog = nullptr;
|
|
|
|
Tree *duplicate_resources_tree = nullptr;
|
|
|
|
|
2022-07-20 23:00:58 +00:00
|
|
|
Size2i assign_button_min_size = Size2i(1, 1);
|
|
|
|
|
2021-05-17 12:25:38 +00:00
|
|
|
enum MenuOption {
|
|
|
|
OBJ_MENU_LOAD,
|
2020-03-22 13:31:46 +00:00
|
|
|
OBJ_MENU_QUICKLOAD,
|
2022-04-29 06:06:48 +00:00
|
|
|
OBJ_MENU_INSPECT,
|
2021-05-17 12:25:38 +00:00
|
|
|
OBJ_MENU_CLEAR,
|
|
|
|
OBJ_MENU_MAKE_UNIQUE,
|
2022-04-28 00:24:13 +00:00
|
|
|
OBJ_MENU_MAKE_UNIQUE_RECURSIVE,
|
2021-05-17 12:25:38 +00:00
|
|
|
OBJ_MENU_SAVE,
|
2023-11-20 20:05:17 +00:00
|
|
|
OBJ_MENU_SAVE_AS,
|
2021-05-17 12:25:38 +00:00
|
|
|
OBJ_MENU_COPY,
|
|
|
|
OBJ_MENU_PASTE,
|
|
|
|
OBJ_MENU_SHOW_IN_FILE_SYSTEM,
|
|
|
|
|
|
|
|
TYPE_BASE_ID = 100,
|
|
|
|
CONVERT_BASE_ID = 1000,
|
|
|
|
};
|
|
|
|
|
2021-07-16 21:36:05 +00:00
|
|
|
PopupMenu *edit_menu = nullptr;
|
2021-05-17 12:25:38 +00:00
|
|
|
|
|
|
|
void _update_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj);
|
|
|
|
|
|
|
|
void _resource_selected();
|
2020-03-22 13:31:46 +00:00
|
|
|
void _file_quick_selected();
|
2021-05-17 12:25:38 +00:00
|
|
|
void _file_selected(const String &p_path);
|
|
|
|
|
|
|
|
void _update_menu();
|
|
|
|
void _update_menu_items();
|
|
|
|
void _edit_menu_cbk(int p_which);
|
|
|
|
|
|
|
|
void _button_draw();
|
|
|
|
void _button_input(const Ref<InputEvent> &p_event);
|
|
|
|
|
2022-04-26 05:55:51 +00:00
|
|
|
String _get_resource_type(const Ref<Resource> &p_resource) const;
|
2023-01-19 15:47:01 +00:00
|
|
|
void _get_allowed_types(bool p_with_convert, HashSet<StringName> *p_vector) const;
|
2021-05-17 12:25:38 +00:00
|
|
|
bool _is_drop_valid(const Dictionary &p_drag_data) const;
|
2024-02-15 16:25:58 +00:00
|
|
|
bool _is_type_valid(const String &p_type_name, const HashSet<StringName> &p_allowed_types) const;
|
2021-05-17 12:25:38 +00:00
|
|
|
|
|
|
|
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
|
|
|
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
|
|
|
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
|
|
|
|
2021-07-16 21:36:05 +00:00
|
|
|
void _ensure_resource_menu();
|
2023-06-04 21:59:03 +00:00
|
|
|
void _gather_resources_to_duplicate(const Ref<Resource> p_resource, TreeItem *p_item, const String &p_property_name = "") const;
|
|
|
|
void _duplicate_selected_resources();
|
2021-07-16 21:36:05 +00:00
|
|
|
|
2021-05-17 12:25:38 +00:00
|
|
|
protected:
|
2022-07-20 23:00:58 +00:00
|
|
|
virtual void _update_resource();
|
|
|
|
|
|
|
|
Button *get_assign_button() { return assign_button; }
|
2021-05-17 12:25:38 +00:00
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
2023-06-04 21:59:03 +00:00
|
|
|
void set_assign_button_min_size(const Size2i &p_size);
|
2022-07-20 23:00:58 +00:00
|
|
|
|
2021-12-29 17:27:44 +00:00
|
|
|
GDVIRTUAL1(_set_create_options, Object *)
|
|
|
|
GDVIRTUAL1R(bool, _handle_menu_selected, int)
|
|
|
|
|
2021-05-17 12:25:38 +00:00
|
|
|
public:
|
|
|
|
void set_base_type(const String &p_base_type);
|
|
|
|
String get_base_type() const;
|
|
|
|
Vector<String> get_allowed_types() const;
|
2021-05-19 12:19:07 +00:00
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
void set_edited_resource(Ref<Resource> p_resource);
|
|
|
|
Ref<Resource> get_edited_resource();
|
2021-05-17 12:25:38 +00:00
|
|
|
|
2021-05-19 12:19:07 +00:00
|
|
|
void set_toggle_mode(bool p_enable);
|
|
|
|
bool is_toggle_mode() const;
|
|
|
|
void set_toggle_pressed(bool p_pressed);
|
|
|
|
|
2021-05-17 12:25:38 +00:00
|
|
|
void set_editable(bool p_editable);
|
|
|
|
bool is_editable() const;
|
|
|
|
|
2021-05-19 12:19:07 +00:00
|
|
|
virtual void set_create_options(Object *p_menu_node);
|
|
|
|
virtual bool handle_menu_selected(int p_which);
|
|
|
|
|
2022-07-20 23:00:58 +00:00
|
|
|
EditorResourcePicker(bool p_hide_assign_button_controls = false);
|
2021-05-17 12:25:38 +00:00
|
|
|
};
|
|
|
|
|
2021-05-19 12:19:07 +00:00
|
|
|
class EditorScriptPicker : public EditorResourcePicker {
|
|
|
|
GDCLASS(EditorScriptPicker, EditorResourcePicker);
|
|
|
|
|
|
|
|
enum ExtraMenuOption {
|
2023-11-22 16:28:40 +00:00
|
|
|
OBJ_MENU_NEW_SCRIPT = 50,
|
|
|
|
OBJ_MENU_EXTEND_SCRIPT = 51
|
2021-05-19 12:19:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Node *script_owner = nullptr;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void set_create_options(Object *p_menu_node) override;
|
|
|
|
virtual bool handle_menu_selected(int p_which) override;
|
|
|
|
|
|
|
|
void set_script_owner(Node *p_owner);
|
|
|
|
Node *get_script_owner() const;
|
|
|
|
|
|
|
|
EditorScriptPicker();
|
|
|
|
};
|
|
|
|
|
2021-06-04 09:24:08 +00:00
|
|
|
class EditorShaderPicker : public EditorResourcePicker {
|
|
|
|
GDCLASS(EditorShaderPicker, EditorResourcePicker);
|
|
|
|
|
|
|
|
enum ExtraMenuOption {
|
2023-11-22 16:28:40 +00:00
|
|
|
OBJ_MENU_NEW_SHADER = 50,
|
2021-06-04 09:24:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ShaderMaterial *edited_material = nullptr;
|
2021-09-17 14:35:24 +00:00
|
|
|
int preferred_mode = -1;
|
2021-06-04 09:24:08 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void set_create_options(Object *p_menu_node) override;
|
|
|
|
virtual bool handle_menu_selected(int p_which) override;
|
|
|
|
|
|
|
|
void set_edited_material(ShaderMaterial *p_material);
|
|
|
|
ShaderMaterial *get_edited_material() const;
|
2021-09-17 14:35:24 +00:00
|
|
|
void set_preferred_mode(int p_preferred_mode);
|
2021-06-04 09:24:08 +00:00
|
|
|
|
|
|
|
EditorShaderPicker();
|
|
|
|
};
|
|
|
|
|
2022-07-20 23:00:58 +00:00
|
|
|
class EditorAudioStreamPicker : public EditorResourcePicker {
|
|
|
|
GDCLASS(EditorAudioStreamPicker, EditorResourcePicker);
|
|
|
|
|
|
|
|
uint64_t last_preview_version = 0;
|
|
|
|
Control *stream_preview_rect = nullptr;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MAX_TAGGED_FRAMES = 8
|
|
|
|
};
|
|
|
|
float tagged_frame_offsets[MAX_TAGGED_FRAMES];
|
|
|
|
uint32_t tagged_frame_offset_count = 0;
|
|
|
|
|
|
|
|
void _preview_draw();
|
|
|
|
virtual void _update_resource() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
|
|
|
EditorAudioStreamPicker();
|
|
|
|
};
|
|
|
|
|
2021-05-17 12:25:38 +00:00
|
|
|
#endif // EDITOR_RESOURCE_PICKER_H
|