Path: blob/master/editor/inspector/editor_properties.h
21345 views
/**************************************************************************/1/* editor_properties.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 "editor/inspector/editor_inspector.h"3334class CheckBox;35class ColorPickerButton;36class ConfirmationDialog;37class CreateDialog;38class EditorFileDialog;39class EditorLocaleDialog;40class EditorResourcePicker;41class EditorSpinSlider;42class EditorVariantTypePopupMenu;43class MenuButton;44class SceneTreeDialog;45class TextEdit;46class TextureButton;4748struct EditorPropertyRangeHint {49bool or_greater = true;50bool or_less = true;51double min = 0.0;52double max = 0.0;53double step = 1.0;54String suffix;55bool exp_range = false;56bool prefer_slider = false;57bool hide_control = true;58bool radians_as_degrees = false;59};6061class EditorPropertyNil : public EditorProperty {62GDCLASS(EditorPropertyNil, EditorProperty);63LineEdit *text = nullptr;6465public:66virtual void update_property() override;67EditorPropertyNil();68};6970class EditorPropertyVariant : public EditorProperty {71GDCLASS(EditorPropertyVariant, EditorProperty);7273HBoxContainer *content = nullptr;74EditorProperty *sub_property = nullptr;75Button *edit_button = nullptr;76EditorVariantTypePopupMenu *change_type = nullptr;7778Variant::Type current_type = Variant::VARIANT_MAX;79Variant::Type new_type = Variant::VARIANT_MAX;8081void _change_type(int p_to_type);82void _popup_edit_menu();8384protected:85virtual void _set_read_only(bool p_read_only) override;86void _notification(int p_what);8788public:89virtual void update_property() override;90EditorPropertyVariant();91};9293class EditorPropertyText : public EditorProperty {94GDCLASS(EditorPropertyText, EditorProperty);95LineEdit *text = nullptr;9697bool monospaced = false;98bool updating = false;99bool string_name = false;100void _text_changed(const String &p_string);101void _text_submitted(const String &p_string);102void _update_theme();103104protected:105void _notification(int p_what);106107virtual void _set_read_only(bool p_read_only) override;108109public:110void set_string_name(bool p_enabled);111virtual void update_property() override;112void set_placeholder(const String &p_string);113void set_secret(bool p_enabled);114void set_monospaced(bool p_monospaced);115EditorPropertyText();116};117118class EditorPropertyMultilineText : public EditorProperty {119GDCLASS(EditorPropertyMultilineText, EditorProperty);120121TextEdit *text = nullptr;122123AcceptDialog *big_text_dialog = nullptr;124TextEdit *big_text = nullptr;125Button *open_big_text = nullptr;126127bool expression = false;128bool monospaced = false;129bool wrap_lines = true;130131void _big_text_changed();132void _text_changed();133void _open_big_text();134void _update_theme();135136protected:137virtual void _set_read_only(bool p_read_only) override;138void _notification(int p_what);139140public:141virtual void update_property() override;142143void set_monospaced(bool p_monospaced);144bool get_monospaced();145146void set_wrap_lines(bool p_wrap_lines);147bool get_wrap_lines();148149EditorPropertyMultilineText(bool p_expression = false);150};151152class EditorPropertyTextEnum : public EditorProperty {153GDCLASS(EditorPropertyTextEnum, EditorProperty);154155HBoxContainer *default_layout = nullptr;156HBoxContainer *edit_custom_layout = nullptr;157158OptionButton *option_button = nullptr;159Button *edit_button = nullptr;160161LineEdit *custom_value_edit = nullptr;162Button *accept_button = nullptr;163Button *cancel_button = nullptr;164165Vector<String> options;166Vector<String> option_names;167bool string_name = false;168bool loose_mode = false;169170void _emit_changed_value(const String &p_string);171void _option_selected(int p_which);172173void _edit_custom_value();174void _custom_value_submitted(const String &p_value);175void _custom_value_accepted();176void _custom_value_canceled();177178protected:179virtual void _set_read_only(bool p_read_only) override;180void _notification(int p_what);181182public:183void setup(const Vector<String> &p_options, const Vector<String> &p_option_names = {}, bool p_string_name = false, bool p_loose_mode = false);184virtual void update_property() override;185EditorPropertyTextEnum();186};187188class EditorPropertyPath : public EditorProperty {189GDCLASS(EditorPropertyPath, EditorProperty);190Vector<String> extensions;191bool folder = false;192bool global = false;193bool save_mode = false;194bool enable_uid = false;195bool display_uid = false;196197EditorFileDialog *dialog = nullptr;198LineEdit *path = nullptr;199Button *toggle_uid = nullptr;200Button *path_edit = nullptr;201202String _get_path_text(bool p_allow_uid = false);203204void _path_selected(const String &p_path);205void _path_pressed();206void _path_focus_exited();207void _toggle_uid_display();208void _update_uid_icon();209void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);210bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;211212protected:213virtual void _set_read_only(bool p_read_only) override;214void _notification(int p_what);215216public:217LineEdit *get_path_edit() const { return path; }218219void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global, bool p_enable_uid);220void set_save_mode();221virtual void update_property() override;222EditorPropertyPath();223};224225class EditorPropertyLocale : public EditorProperty {226GDCLASS(EditorPropertyLocale, EditorProperty);227EditorLocaleDialog *dialog = nullptr;228LineEdit *locale = nullptr;229Button *locale_edit = nullptr;230231void _locale_selected(const String &p_locale);232void _locale_pressed();233void _locale_focus_exited();234235protected:236void _notification(int p_what);237238public:239void setup(const String &p_hit_string);240virtual void update_property() override;241EditorPropertyLocale();242};243244class EditorPropertyClassName : public EditorProperty {245GDCLASS(EditorPropertyClassName, EditorProperty);246247private:248CreateDialog *dialog = nullptr;249Button *property = nullptr;250String selected_type;251String base_type;252void _property_selected();253void _dialog_created();254255protected:256virtual void _set_read_only(bool p_read_only) override;257258public:259void setup(const String &p_base_type, const String &p_selected_type);260virtual void update_property() override;261EditorPropertyClassName();262};263264class EditorPropertyCheck : public EditorProperty {265GDCLASS(EditorPropertyCheck, EditorProperty);266CheckBox *checkbox = nullptr;267268void _checkbox_pressed();269270protected:271virtual void _set_read_only(bool p_read_only) override;272273public:274virtual void update_property() override;275EditorPropertyCheck();276};277278class EditorPropertyEnum : public EditorProperty {279GDCLASS(EditorPropertyEnum, EditorProperty);280OptionButton *options = nullptr;281282void _option_selected(int p_which);283284protected:285virtual void _set_read_only(bool p_read_only) override;286287public:288void setup(const Vector<String> &p_options);289virtual void update_property() override;290void set_option_button_clip(bool p_enable);291OptionButton *get_option_button(); // Hack to allow setting icons.292EditorPropertyEnum();293};294295class EditorPropertyFlags : public EditorProperty {296GDCLASS(EditorPropertyFlags, EditorProperty);297VBoxContainer *vbox = nullptr;298Vector<CheckBox *> flags;299Vector<uint32_t> flag_values;300301void _flag_toggled(int p_index);302303protected:304virtual void _set_read_only(bool p_read_only) override;305306public:307void setup(const Vector<String> &p_options);308virtual void update_property() override;309EditorPropertyFlags();310};311312///////////////////// LAYERS /////////////////////////313314class EditorPropertyLayersGrid : public Control {315GDCLASS(EditorPropertyLayersGrid, Control);316317private:318Vector<Rect2> flag_rects;319Rect2 expand_rect;320bool expand_hovered = false;321bool expanded = false;322int expansion_rows = 0;323const uint32_t HOVERED_INDEX_NONE = UINT32_MAX;324uint32_t hovered_index = HOVERED_INDEX_NONE;325bool dragging = false;326bool dragging_value_to_set = false;327bool read_only = false;328int renamed_layer_index = -1;329PopupMenu *layer_rename = nullptr;330ConfirmationDialog *rename_dialog = nullptr;331LineEdit *rename_dialog_text = nullptr;332333void _rename_pressed(int p_menu);334void _rename_operation_confirm();335void _update_hovered(const Vector2 &p_position);336void _on_hover_exit();337void _update_flag(bool p_replace);338Size2 get_grid_size() const;339340protected:341void _notification(int p_what);342static void _bind_methods();343344public:345uint32_t value = 0;346int layer_group_size = 0;347uint32_t layer_count = 0;348Vector<String> names;349Vector<String> tooltips;350351void set_read_only(bool p_read_only);352virtual Size2 get_minimum_size() const override;353virtual String get_tooltip(const Point2 &p_pos) const override;354void gui_input(const Ref<InputEvent> &p_ev) override;355void set_flag(uint32_t p_flag);356EditorPropertyLayersGrid();357};358359class EditorPropertyLayers : public EditorProperty {360GDCLASS(EditorPropertyLayers, EditorProperty);361362public:363enum LayerType {364LAYER_PHYSICS_2D,365LAYER_RENDER_2D,366LAYER_NAVIGATION_2D,367LAYER_PHYSICS_3D,368LAYER_RENDER_3D,369LAYER_NAVIGATION_3D,370LAYER_AVOIDANCE,371};372373private:374EditorPropertyLayersGrid *grid = nullptr;375void _grid_changed(uint32_t p_grid);376String basename;377LayerType layer_type;378PopupMenu *layers = nullptr;379TextureButton *button = nullptr;380381void _button_pressed();382void _menu_pressed(int p_menu);383void _refresh_names();384385protected:386void _notification(int p_what);387virtual void _set_read_only(bool p_read_only) override;388389public:390void setup(LayerType p_layer_type);391void set_layer_name(int p_index, const String &p_name);392String get_layer_name(int p_index) const;393virtual void update_property() override;394EditorPropertyLayers();395};396397class EditorPropertyInteger : public EditorProperty {398GDCLASS(EditorPropertyInteger, EditorProperty);399EditorSpinSlider *spin = nullptr;400void _value_changed(int64_t p_val);401402protected:403virtual void _set_read_only(bool p_read_only) override;404405public:406virtual void update_property() override;407void setup(const EditorPropertyRangeHint &p_range_hint);408EditorPropertyInteger();409};410411class EditorPropertyObjectID : public EditorProperty {412GDCLASS(EditorPropertyObjectID, EditorProperty);413Button *edit = nullptr;414String base_type;415void _edit_pressed();416417protected:418virtual void _set_read_only(bool p_read_only) override;419420public:421virtual void update_property() override;422void setup(const String &p_base_type);423EditorPropertyObjectID();424};425426class EditorPropertySignal : public EditorProperty {427GDCLASS(EditorPropertySignal, EditorProperty);428Button *edit = nullptr;429String base_type;430void _edit_pressed();431432public:433virtual void update_property() override;434EditorPropertySignal();435};436437class EditorPropertyCallable : public EditorProperty {438GDCLASS(EditorPropertyCallable, EditorProperty);439Button *edit = nullptr;440String base_type;441442public:443virtual void update_property() override;444EditorPropertyCallable();445};446447class EditorPropertyFloat : public EditorProperty {448GDCLASS(EditorPropertyFloat, EditorProperty);449EditorSpinSlider *spin = nullptr;450bool radians_as_degrees = false;451void _value_changed(double p_val);452453protected:454virtual void _set_read_only(bool p_read_only) override;455456public:457virtual void update_property() override;458void setup(const EditorPropertyRangeHint &p_range_hint);459EditorPropertyFloat();460};461462class EditorPropertyEasing : public EditorProperty {463GDCLASS(EditorPropertyEasing, EditorProperty);464Control *easing_draw = nullptr;465PopupMenu *preset = nullptr;466EditorSpinSlider *spin = nullptr;467468bool dragging = false;469bool full = false;470bool flip = false;471bool positive_only = false;472473enum {474EASING_ZERO,475EASING_LINEAR,476EASING_IN,477EASING_OUT,478EASING_IN_OUT,479EASING_OUT_IN,480EASING_MAX481482};483484void _drag_easing(const Ref<InputEvent> &p_ev);485void _draw_easing();486void _set_preset(int);487488void _setup_spin();489void _spin_value_changed(double p_value);490void _spin_focus_exited();491492void _notification(int p_what);493494protected:495virtual void _set_read_only(bool p_read_only) override;496497public:498virtual void update_property() override;499void setup(bool p_positive_only, bool p_flip);500EditorPropertyEasing();501};502503class EditorPropertyRect2 : public EditorProperty {504GDCLASS(EditorPropertyRect2, EditorProperty);505EditorSpinSlider *spin[4];506void _value_changed(double p_val, const String &p_name);507508protected:509virtual void _set_read_only(bool p_read_only) override;510void _notification(int p_what);511512public:513virtual void update_property() override;514void setup(const EditorPropertyRangeHint &p_range_hint);515EditorPropertyRect2(bool p_force_wide = false);516};517518class EditorPropertyRect2i : public EditorProperty {519GDCLASS(EditorPropertyRect2i, EditorProperty);520EditorSpinSlider *spin[4];521void _value_changed(double p_val, const String &p_name);522523protected:524virtual void _set_read_only(bool p_read_only) override;525void _notification(int p_what);526527public:528virtual void update_property() override;529void setup(const EditorPropertyRangeHint &p_range_hint);530EditorPropertyRect2i(bool p_force_wide = false);531};532533class EditorPropertyPlane : public EditorProperty {534GDCLASS(EditorPropertyPlane, EditorProperty);535EditorSpinSlider *spin[4];536void _value_changed(double p_val, const String &p_name);537538protected:539virtual void _set_read_only(bool p_read_only) override;540void _notification(int p_what);541542public:543virtual void update_property() override;544void setup(const EditorPropertyRangeHint &p_range_hint);545EditorPropertyPlane(bool p_force_wide = false);546};547548class EditorPropertyQuaternion : public EditorProperty {549GDCLASS(EditorPropertyQuaternion, EditorProperty);550BoxContainer *default_layout = nullptr;551EditorSpinSlider *spin[4];552553Button *warning = nullptr;554AcceptDialog *warning_dialog = nullptr;555556Label *euler_label = nullptr;557VBoxContainer *edit_custom_bc = nullptr;558EditorSpinSlider *euler[3];559Button *edit_button = nullptr;560561Vector3 edit_euler;562563void _value_changed(double p_val, const String &p_name);564void _edit_custom_value();565void _custom_value_changed(double p_val);566void _warning_pressed();567568bool is_grabbing_euler();569570protected:571virtual void _set_read_only(bool p_read_only) override;572void _notification(int p_what);573574public:575virtual void update_property() override;576void setup(const EditorPropertyRangeHint &p_range_hint, bool p_hide_editor = false);577EditorPropertyQuaternion();578};579580class EditorPropertyAABB : public EditorProperty {581GDCLASS(EditorPropertyAABB, EditorProperty);582EditorSpinSlider *spin[6];583void _value_changed(double p_val, const String &p_name);584585protected:586virtual void _set_read_only(bool p_read_only) override;587void _notification(int p_what);588589public:590virtual void update_property() override;591void setup(const EditorPropertyRangeHint &p_range_hint);592EditorPropertyAABB();593};594595class EditorPropertyTransform2D : public EditorProperty {596GDCLASS(EditorPropertyTransform2D, EditorProperty);597EditorSpinSlider *spin[6];598void _value_changed(double p_val, const String &p_name);599600protected:601virtual void _set_read_only(bool p_read_only) override;602void _notification(int p_what);603604public:605virtual void update_property() override;606void setup(const EditorPropertyRangeHint &p_range_hint);607EditorPropertyTransform2D(bool p_include_origin = true);608};609610class EditorPropertyBasis : public EditorProperty {611GDCLASS(EditorPropertyBasis, EditorProperty);612EditorSpinSlider *spin[9];613void _value_changed(double p_val, const String &p_name);614615protected:616virtual void _set_read_only(bool p_read_only) override;617void _notification(int p_what);618619public:620virtual void update_property() override;621void setup(const EditorPropertyRangeHint &p_range_hint);622EditorPropertyBasis();623};624625class EditorPropertyTransform3D : public EditorProperty {626GDCLASS(EditorPropertyTransform3D, EditorProperty);627EditorSpinSlider *spin[12];628void _value_changed(double p_val, const String &p_name);629630protected:631virtual void _set_read_only(bool p_read_only) override;632void _notification(int p_what);633634public:635virtual void update_property() override;636virtual void update_using_transform(Transform3D p_transform);637void setup(const EditorPropertyRangeHint &p_range_hint);638EditorPropertyTransform3D();639};640641class EditorPropertyProjection : public EditorProperty {642GDCLASS(EditorPropertyProjection, EditorProperty);643EditorSpinSlider *spin[16];644void _value_changed(double p_val, const String &p_name);645646protected:647virtual void _set_read_only(bool p_read_only) override;648void _notification(int p_what);649650public:651virtual void update_property() override;652virtual void update_using_transform(Projection p_transform);653void setup(const EditorPropertyRangeHint &p_range_hint);654EditorPropertyProjection();655};656657class EditorPropertyColor : public EditorProperty {658GDCLASS(EditorPropertyColor, EditorProperty);659ColorPickerButton *picker = nullptr;660void _color_changed(const Color &p_color);661void _picker_created();662void _popup_opening();663void _popup_closed();664665Color last_color;666bool live_changes_enabled = true;667bool was_checked = false;668669protected:670virtual void _set_read_only(bool p_read_only) override;671672public:673virtual void update_property() override;674void setup(bool p_show_alpha);675void set_live_changes_enabled(bool p_enabled);676EditorPropertyColor();677};678679class EditorPropertyNodePath : public EditorProperty {680GDCLASS(EditorPropertyNodePath, EditorProperty);681682enum {683ACTION_CLEAR,684ACTION_COPY,685ACTION_EDIT,686ACTION_SELECT,687};688689Button *assign = nullptr;690MenuButton *menu = nullptr;691LineEdit *edit = nullptr;692693SceneTreeDialog *scene_tree = nullptr;694bool use_path_from_scene_root = false;695bool editing_node = false;696bool dropping = false;697698Vector<StringName> valid_types;699void _node_selected(const NodePath &p_path, bool p_absolute = true);700void _node_assign();701void _assign_draw();702Node *get_base_node();703void _update_menu();704void _menu_option(int p_idx);705void _accept_text();706void _text_submitted(const String &p_text);707const NodePath _get_node_path() const;708709bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;710void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);711bool is_drop_valid(const Dictionary &p_drag_data) const;712713virtual Variant _get_cache_value(const StringName &p_prop, bool &r_valid) const override;714715protected:716virtual void _set_read_only(bool p_read_only) override;717void _notification(int p_what);718719public:720virtual void update_property() override;721void setup(const Vector<StringName> &p_valid_types, bool p_use_path_from_scene_root = true, bool p_editing_node = false);722EditorPropertyNodePath();723};724725class EditorPropertyRID : public EditorProperty {726GDCLASS(EditorPropertyRID, EditorProperty);727Label *label = nullptr;728729public:730virtual void update_property() override;731EditorPropertyRID();732};733734class EditorPropertyResource : public EditorProperty {735GDCLASS(EditorPropertyResource, EditorProperty);736737EditorResourcePicker *resource_picker = nullptr;738SceneTreeDialog *scene_tree = nullptr;739740bool use_sub_inspector = false;741EditorInspector *sub_inspector = nullptr;742bool opened_editor = false;743bool use_filter = false;744745void _resource_selected(const Ref<Resource> &p_resource, bool p_inspect);746void _resource_changed(const Ref<Resource> &p_resource);747748Node *_get_base_node();749void _viewport_selected(const NodePath &p_path);750751void _sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool p_advance);752void _sub_inspector_resource_selected(const Ref<Resource> &p_resource, const String &p_property);753void _sub_inspector_object_id_selected(int p_id);754755void _open_editor_pressed();756void _update_preferred_shader();757bool _should_stop_editing() const;758759protected:760virtual void _set_read_only(bool p_read_only) override;761void _notification(int p_what);762static void _bind_methods();763764public:765virtual void update_property() override;766void setup(Object *p_object, const String &p_path, const String &p_base_type);767EditorResourcePicker *get_resource_picker() const { return resource_picker; }768769void collapse_all_folding() override;770void expand_all_folding() override;771void expand_revertable() override;772773void set_use_sub_inspector(bool p_enable);774void set_use_filter(bool p_use);775void fold_resource();776777virtual bool is_colored(ColorationMode p_mode) override;778779EditorPropertyResource();780};781782///////////////////////////////////////////////////783/// \brief The EditorInspectorDefaultPlugin class784///785class EditorInspectorDefaultPlugin : public EditorInspectorPlugin {786GDCLASS(EditorInspectorDefaultPlugin, EditorInspectorPlugin);787788public:789virtual bool can_handle(Object *p_object) override;790virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;791792static EditorProperty *get_editor_for_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false);793};794795796