| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/box_container.h" |
| 34 |
#include "scene/resources/material.h" |
| 35 |
|
| 36 |
class Button; |
| 37 |
class ConfirmationDialog; |
| 38 |
class EditorFileDialog; |
| 39 |
class PopupMenu; |
| 40 |
class TextureRect; |
| 41 |
class Tree; |
| 42 |
class TreeItem; |
| 43 |
|
| 44 |
class EditorResourcePicker : public HBoxContainer { |
| 45 |
GDCLASS(EditorResourcePicker, HBoxContainer); |
| 46 |
|
| 47 |
String base_type; |
| 48 |
Ref<Resource> edited_resource; |
| 49 |
|
| 50 |
bool editable = true; |
| 51 |
bool dropping = false; |
| 52 |
bool force_allow_unique = false; |
| 53 |
|
| 54 |
Vector<String> inheritors_array; |
| 55 |
mutable HashSet<StringName> allowed_types_without_convert; |
| 56 |
mutable HashSet<StringName> allowed_types_with_convert; |
| 57 |
|
| 58 |
Button *assign_button = nullptr; |
| 59 |
Button *make_unique_button = nullptr; |
| 60 |
TextureRect *preview_rect = nullptr; |
| 61 |
Button *edit_button = nullptr; |
| 62 |
Button *quick_load_button = nullptr; |
| 63 |
EditorFileDialog *file_dialog = nullptr; |
| 64 |
|
| 65 |
ConfirmationDialog *duplicate_resources_dialog = nullptr; |
| 66 |
Tree *duplicate_resources_tree = nullptr; |
| 67 |
|
| 68 |
Size2i assign_button_min_size = Size2i(1, 1); |
| 69 |
|
| 70 |
enum MenuOption { |
| 71 |
OBJ_MENU_LOAD, |
| 72 |
OBJ_MENU_QUICKLOAD, |
| 73 |
OBJ_MENU_INSPECT, |
| 74 |
OBJ_MENU_CLEAR, |
| 75 |
OBJ_MENU_MAKE_UNIQUE, |
| 76 |
OBJ_MENU_MAKE_UNIQUE_RECURSIVE, |
| 77 |
OBJ_MENU_SAVE, |
| 78 |
OBJ_MENU_SAVE_AS, |
| 79 |
OBJ_MENU_COPY, |
| 80 |
OBJ_MENU_PASTE, |
| 81 |
OBJ_MENU_PASTE_AS_UNIQUE, |
| 82 |
OBJ_MENU_SHOW_IN_FILE_SYSTEM, |
| 83 |
|
| 84 |
TYPE_BASE_ID = 100, |
| 85 |
CONVERT_BASE_ID = 1000, |
| 86 |
}; |
| 87 |
|
| 88 |
Object *resource_owner = nullptr; |
| 89 |
StringName property_path; |
| 90 |
|
| 91 |
PopupMenu *edit_menu = nullptr; |
| 92 |
|
| 93 |
void _update_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj); |
| 94 |
|
| 95 |
void _resource_selected(); |
| 96 |
void _resource_changed(); |
| 97 |
void _file_selected(const String &p_path); |
| 98 |
|
| 99 |
void _resource_saved(Object *p_resource); |
| 100 |
|
| 101 |
void _update_menu(); |
| 102 |
void _update_menu_items(); |
| 103 |
void _edit_menu_cbk(int p_which); |
| 104 |
|
| 105 |
void _button_draw(); |
| 106 |
void _button_input(const Ref<InputEvent> &p_event); |
| 107 |
void _on_unique_button_pressed(); |
| 108 |
|
| 109 |
String _get_owner_path() const; |
| 110 |
String _get_resource_type(const Ref<Resource> &p_resource) const; |
| 111 |
void _ensure_allowed_types() const; |
| 112 |
bool _is_drop_valid(const Dictionary &p_drag_data) const; |
| 113 |
bool _is_type_valid(const String &p_type_name, const HashSet<StringName> &p_allowed_types) const; |
| 114 |
bool _is_custom_type_script() const; |
| 115 |
|
| 116 |
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); |
| 117 |
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; |
| 118 |
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); |
| 119 |
|
| 120 |
void _ensure_resource_menu(); |
| 121 |
void _gather_resources_to_duplicate(const Ref<Resource> p_resource, TreeItem *p_item, const String &p_property_name = "") const; |
| 122 |
void _duplicate_selected_resources(); |
| 123 |
bool _is_uniqueness_enabled(bool p_check_recursive = false); |
| 124 |
Ref<Resource> _has_parent_resource(); |
| 125 |
|
| 126 |
protected: |
| 127 |
virtual void _update_resource(); |
| 128 |
|
| 129 |
Button *get_assign_button() { return assign_button; } |
| 130 |
static void _bind_methods(); |
| 131 |
void _notification(int p_what); |
| 132 |
|
| 133 |
void set_assign_button_min_size(const Size2i &p_size); |
| 134 |
|
| 135 |
GDVIRTUAL1(_set_create_options, Object *) |
| 136 |
GDVIRTUAL1R(bool, _handle_menu_selected, int) |
| 137 |
|
| 138 |
public: |
| 139 |
void set_base_type(const String &p_base_type); |
| 140 |
String get_base_type() const; |
| 141 |
Vector<String> get_allowed_types() const; |
| 142 |
|
| 143 |
bool is_resource_allowed(const Ref<Resource> &p_resource); |
| 144 |
void set_edited_resource(Ref<Resource> p_resource); |
| 145 |
void set_edited_resource_no_check(Ref<Resource> p_resource); |
| 146 |
Ref<Resource> get_edited_resource(); |
| 147 |
void set_force_allow_unique(bool p_force) { force_allow_unique = p_force; } |
| 148 |
|
| 149 |
void set_toggle_mode(bool p_enable); |
| 150 |
bool is_toggle_mode() const; |
| 151 |
void set_toggle_pressed(bool p_pressed); |
| 152 |
bool is_toggle_pressed() const; |
| 153 |
|
| 154 |
void set_resource_owner(Object *p_object); |
| 155 |
void set_property_path(const StringName &p_path) { property_path = p_path; } |
| 156 |
|
| 157 |
void set_editable(bool p_editable); |
| 158 |
bool is_editable() const; |
| 159 |
|
| 160 |
virtual void set_create_options(Object *p_menu_node); |
| 161 |
virtual bool handle_menu_selected(int p_which); |
| 162 |
|
| 163 |
EditorResourcePicker(bool p_hide_assign_button_controls = false); |
| 164 |
}; |
| 165 |
|
| 166 |
class EditorScriptPicker : public EditorResourcePicker { |
| 167 |
GDCLASS(EditorScriptPicker, EditorResourcePicker); |
| 168 |
|
| 169 |
enum ExtraMenuOption { |
| 170 |
OBJ_MENU_NEW_SCRIPT = 50, |
| 171 |
OBJ_MENU_EXTEND_SCRIPT = 51 |
| 172 |
}; |
| 173 |
|
| 174 |
Node *script_owner = nullptr; |
| 175 |
|
| 176 |
protected: |
| 177 |
static void _bind_methods(); |
| 178 |
|
| 179 |
public: |
| 180 |
virtual void set_create_options(Object *p_menu_node) override; |
| 181 |
virtual bool handle_menu_selected(int p_which) override; |
| 182 |
|
| 183 |
void set_script_owner(Node *p_owner); |
| 184 |
Node *get_script_owner() const; |
| 185 |
}; |
| 186 |
|
| 187 |
class EditorShaderPicker : public EditorResourcePicker { |
| 188 |
GDCLASS(EditorShaderPicker, EditorResourcePicker); |
| 189 |
|
| 190 |
enum ExtraMenuOption { |
| 191 |
OBJ_MENU_NEW_SHADER = 50, |
| 192 |
}; |
| 193 |
|
| 194 |
ShaderMaterial *edited_material = nullptr; |
| 195 |
int preferred_mode = -1; |
| 196 |
|
| 197 |
public: |
| 198 |
virtual void set_create_options(Object *p_menu_node) override; |
| 199 |
virtual bool handle_menu_selected(int p_which) override; |
| 200 |
|
| 201 |
void set_edited_material(ShaderMaterial *p_material); |
| 202 |
ShaderMaterial *get_edited_material() const; |
| 203 |
void set_preferred_mode(int p_preferred_mode); |
| 204 |
}; |
| 205 |
|
| 206 |
class EditorAudioStreamPicker : public EditorResourcePicker { |
| 207 |
GDCLASS(EditorAudioStreamPicker, EditorResourcePicker); |
| 208 |
|
| 209 |
uint64_t last_preview_version = 0; |
| 210 |
Control *stream_preview_rect = nullptr; |
| 211 |
|
| 212 |
enum { |
| 213 |
MAX_TAGGED_FRAMES = 8 |
| 214 |
}; |
| 215 |
float tagged_frame_offsets[MAX_TAGGED_FRAMES]; |
| 216 |
uint32_t tagged_frame_offset_count = 0; |
| 217 |
|
| 218 |
void _preview_draw(); |
| 219 |
virtual void _update_resource() override; |
| 220 |
|
| 221 |
protected: |
| 222 |
void _notification(int p_what); |
| 223 |
|
| 224 |
public: |
| 225 |
EditorAudioStreamPicker(); |
| 226 |
}; |