Path: blob/master/editor/inspector/editor_properties.h
9896 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 CreateDialog;37class EditorFileDialog;38class EditorLocaleDialog;39class EditorResourcePicker;40class EditorSpinSlider;41class EditorVariantTypePopupMenu;42class MenuButton;43class PropertySelector;44class SceneTreeDialog;45class TextEdit;46class TextureButton;4748class EditorPropertyNil : public EditorProperty {49GDCLASS(EditorPropertyNil, EditorProperty);50LineEdit *text = nullptr;5152public:53virtual void update_property() override;54EditorPropertyNil();55};5657class EditorPropertyVariant : public EditorProperty {58GDCLASS(EditorPropertyVariant, EditorProperty);5960HBoxContainer *content = nullptr;61EditorProperty *sub_property = nullptr;62Button *edit_button = nullptr;63EditorVariantTypePopupMenu *change_type = nullptr;6465Variant::Type current_type = Variant::VARIANT_MAX;66Variant::Type new_type = Variant::VARIANT_MAX;6768void _change_type(int p_to_type);69void _popup_edit_menu();7071protected:72virtual void _set_read_only(bool p_read_only) override;73void _notification(int p_what);7475public:76virtual void update_property() override;77EditorPropertyVariant();78};7980class EditorPropertyText : public EditorProperty {81GDCLASS(EditorPropertyText, EditorProperty);82LineEdit *text = nullptr;8384bool updating = false;85bool string_name = false;86void _text_changed(const String &p_string);87void _text_submitted(const String &p_string);8889protected:90virtual void _set_read_only(bool p_read_only) override;9192public:93void set_string_name(bool p_enabled);94virtual void update_property() override;95void set_placeholder(const String &p_string);96void set_secret(bool p_enabled);97EditorPropertyText();98};99100class EditorPropertyMultilineText : public EditorProperty {101GDCLASS(EditorPropertyMultilineText, EditorProperty);102TextEdit *text = nullptr;103104AcceptDialog *big_text_dialog = nullptr;105TextEdit *big_text = nullptr;106Button *open_big_text = nullptr;107108void _big_text_changed();109void _text_changed();110void _open_big_text();111bool expression = false;112113protected:114virtual void _set_read_only(bool p_read_only) override;115void _notification(int p_what);116117public:118virtual void update_property() override;119EditorPropertyMultilineText(bool p_expression = false);120};121122class EditorPropertyTextEnum : public EditorProperty {123GDCLASS(EditorPropertyTextEnum, EditorProperty);124125HBoxContainer *default_layout = nullptr;126HBoxContainer *edit_custom_layout = nullptr;127128OptionButton *option_button = nullptr;129Button *edit_button = nullptr;130131LineEdit *custom_value_edit = nullptr;132Button *accept_button = nullptr;133Button *cancel_button = nullptr;134135Vector<String> options;136bool string_name = false;137bool loose_mode = false;138139void _emit_changed_value(const String &p_string);140void _option_selected(int p_which);141142void _edit_custom_value();143void _custom_value_submitted(const String &p_value);144void _custom_value_accepted();145void _custom_value_canceled();146147protected:148virtual void _set_read_only(bool p_read_only) override;149void _notification(int p_what);150151public:152void setup(const Vector<String> &p_options, bool p_string_name = false, bool p_loose_mode = false);153virtual void update_property() override;154EditorPropertyTextEnum();155};156157class EditorPropertyPath : public EditorProperty {158GDCLASS(EditorPropertyPath, EditorProperty);159Vector<String> extensions;160bool folder = false;161bool global = false;162bool save_mode = false;163bool enable_uid = false;164bool display_uid = false;165166EditorFileDialog *dialog = nullptr;167LineEdit *path = nullptr;168Button *toggle_uid = nullptr;169Button *path_edit = nullptr;170171String _get_path_text(bool p_allow_uid = false);172173void _path_selected(const String &p_path);174void _path_pressed();175void _path_focus_exited();176void _toggle_uid_display();177void _update_uid_icon();178void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);179bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;180181protected:182virtual void _set_read_only(bool p_read_only) override;183void _notification(int p_what);184185public:186LineEdit *get_path_edit() const { return path; }187188void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global, bool p_enable_uid);189void set_save_mode();190virtual void update_property() override;191EditorPropertyPath();192};193194class EditorPropertyLocale : public EditorProperty {195GDCLASS(EditorPropertyLocale, EditorProperty);196EditorLocaleDialog *dialog = nullptr;197LineEdit *locale = nullptr;198Button *locale_edit = nullptr;199200void _locale_selected(const String &p_locale);201void _locale_pressed();202void _locale_focus_exited();203204protected:205void _notification(int p_what);206207public:208void setup(const String &p_hit_string);209virtual void update_property() override;210EditorPropertyLocale();211};212213class EditorPropertyClassName : public EditorProperty {214GDCLASS(EditorPropertyClassName, EditorProperty);215216private:217CreateDialog *dialog = nullptr;218Button *property = nullptr;219String selected_type;220String base_type;221void _property_selected();222void _dialog_created();223224protected:225virtual void _set_read_only(bool p_read_only) override;226227public:228void setup(const String &p_base_type, const String &p_selected_type);229virtual void update_property() override;230EditorPropertyClassName();231};232233class EditorPropertyCheck : public EditorProperty {234GDCLASS(EditorPropertyCheck, EditorProperty);235CheckBox *checkbox = nullptr;236237void _checkbox_pressed();238239protected:240virtual void _set_read_only(bool p_read_only) override;241242public:243virtual void update_property() override;244EditorPropertyCheck();245};246247class EditorPropertyEnum : public EditorProperty {248GDCLASS(EditorPropertyEnum, EditorProperty);249OptionButton *options = nullptr;250251void _option_selected(int p_which);252253protected:254virtual void _set_read_only(bool p_read_only) override;255256public:257void setup(const Vector<String> &p_options);258virtual void update_property() override;259void set_option_button_clip(bool p_enable);260EditorPropertyEnum();261};262263class EditorPropertyFlags : public EditorProperty {264GDCLASS(EditorPropertyFlags, EditorProperty);265VBoxContainer *vbox = nullptr;266Vector<CheckBox *> flags;267Vector<uint32_t> flag_values;268269void _flag_toggled(int p_index);270271protected:272virtual void _set_read_only(bool p_read_only) override;273274public:275void setup(const Vector<String> &p_options);276virtual void update_property() override;277EditorPropertyFlags();278};279280///////////////////// LAYERS /////////////////////////281282class EditorPropertyLayersGrid : public Control {283GDCLASS(EditorPropertyLayersGrid, Control);284285private:286Vector<Rect2> flag_rects;287Rect2 expand_rect;288bool expand_hovered = false;289bool expanded = false;290int expansion_rows = 0;291uint32_t hovered_index = INT32_MAX; // Nothing is hovered.292bool read_only = false;293int renamed_layer_index = -1;294PopupMenu *layer_rename = nullptr;295ConfirmationDialog *rename_dialog = nullptr;296LineEdit *rename_dialog_text = nullptr;297298void _rename_pressed(int p_menu);299void _rename_operation_confirm();300void _update_hovered(const Vector2 &p_position);301void _on_hover_exit();302void _update_flag(bool p_replace);303Size2 get_grid_size() const;304305protected:306void _notification(int p_what);307static void _bind_methods();308309public:310uint32_t value = 0;311int layer_group_size = 0;312uint32_t layer_count = 0;313Vector<String> names;314Vector<String> tooltips;315316void set_read_only(bool p_read_only);317virtual Size2 get_minimum_size() const override;318virtual String get_tooltip(const Point2 &p_pos) const override;319void gui_input(const Ref<InputEvent> &p_ev) override;320void set_flag(uint32_t p_flag);321EditorPropertyLayersGrid();322};323324class EditorPropertyLayers : public EditorProperty {325GDCLASS(EditorPropertyLayers, EditorProperty);326327public:328enum LayerType {329LAYER_PHYSICS_2D,330LAYER_RENDER_2D,331LAYER_NAVIGATION_2D,332LAYER_PHYSICS_3D,333LAYER_RENDER_3D,334LAYER_NAVIGATION_3D,335LAYER_AVOIDANCE,336};337338private:339EditorPropertyLayersGrid *grid = nullptr;340void _grid_changed(uint32_t p_grid);341String basename;342LayerType layer_type;343PopupMenu *layers = nullptr;344TextureButton *button = nullptr;345346void _button_pressed();347void _menu_pressed(int p_menu);348void _refresh_names();349350protected:351void _notification(int p_what);352virtual void _set_read_only(bool p_read_only) override;353354public:355void setup(LayerType p_layer_type);356void set_layer_name(int p_index, const String &p_name);357String get_layer_name(int p_index) const;358virtual void update_property() override;359EditorPropertyLayers();360};361362class EditorPropertyInteger : public EditorProperty {363GDCLASS(EditorPropertyInteger, EditorProperty);364EditorSpinSlider *spin = nullptr;365void _value_changed(int64_t p_val);366367protected:368virtual void _set_read_only(bool p_read_only) override;369370public:371virtual void update_property() override;372void setup(int64_t p_min, int64_t p_max, int64_t p_step, bool p_hide_slider, bool p_allow_greater, bool p_allow_lesser, const String &p_suffix = String());373EditorPropertyInteger();374};375376class EditorPropertyObjectID : public EditorProperty {377GDCLASS(EditorPropertyObjectID, EditorProperty);378Button *edit = nullptr;379String base_type;380void _edit_pressed();381382protected:383virtual void _set_read_only(bool p_read_only) override;384385public:386virtual void update_property() override;387void setup(const String &p_base_type);388EditorPropertyObjectID();389};390391class EditorPropertySignal : public EditorProperty {392GDCLASS(EditorPropertySignal, EditorProperty);393Button *edit = nullptr;394String base_type;395void _edit_pressed();396397public:398virtual void update_property() override;399EditorPropertySignal();400};401402class EditorPropertyCallable : public EditorProperty {403GDCLASS(EditorPropertyCallable, EditorProperty);404Button *edit = nullptr;405String base_type;406407public:408virtual void update_property() override;409EditorPropertyCallable();410};411412class EditorPropertyFloat : public EditorProperty {413GDCLASS(EditorPropertyFloat, EditorProperty);414EditorSpinSlider *spin = nullptr;415bool radians_as_degrees = false;416void _value_changed(double p_val);417418protected:419virtual void _set_read_only(bool p_read_only) override;420421public:422virtual void update_property() override;423void setup(double p_min, double p_max, double p_step, bool p_hide_slider, bool p_exp_range, bool p_greater, bool p_lesser, const String &p_suffix = String(), bool p_radians_as_degrees = false);424EditorPropertyFloat();425};426427class EditorPropertyEasing : public EditorProperty {428GDCLASS(EditorPropertyEasing, EditorProperty);429Control *easing_draw = nullptr;430PopupMenu *preset = nullptr;431EditorSpinSlider *spin = nullptr;432433bool dragging = false;434bool full = false;435bool flip = false;436bool positive_only = false;437438enum {439EASING_ZERO,440EASING_LINEAR,441EASING_IN,442EASING_OUT,443EASING_IN_OUT,444EASING_OUT_IN,445EASING_MAX446447};448449void _drag_easing(const Ref<InputEvent> &p_ev);450void _draw_easing();451void _set_preset(int);452453void _setup_spin();454void _spin_value_changed(double p_value);455void _spin_focus_exited();456457void _notification(int p_what);458459protected:460virtual void _set_read_only(bool p_read_only) override;461462public:463virtual void update_property() override;464void setup(bool p_positive_only, bool p_flip);465EditorPropertyEasing();466};467468class EditorPropertyRect2 : public EditorProperty {469GDCLASS(EditorPropertyRect2, EditorProperty);470EditorSpinSlider *spin[4];471void _value_changed(double p_val, const String &p_name);472473protected:474virtual void _set_read_only(bool p_read_only) override;475void _notification(int p_what);476477public:478virtual void update_property() override;479void setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix = String());480EditorPropertyRect2(bool p_force_wide = false);481};482483class EditorPropertyRect2i : public EditorProperty {484GDCLASS(EditorPropertyRect2i, EditorProperty);485EditorSpinSlider *spin[4];486void _value_changed(double p_val, const String &p_name);487488protected:489virtual void _set_read_only(bool p_read_only) override;490void _notification(int p_what);491492public:493virtual void update_property() override;494void setup(int p_min, int p_max, const String &p_suffix = String());495EditorPropertyRect2i(bool p_force_wide = false);496};497498class EditorPropertyPlane : public EditorProperty {499GDCLASS(EditorPropertyPlane, EditorProperty);500EditorSpinSlider *spin[4];501void _value_changed(double p_val, const String &p_name);502503protected:504virtual void _set_read_only(bool p_read_only) override;505void _notification(int p_what);506507public:508virtual void update_property() override;509void setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix = String());510EditorPropertyPlane(bool p_force_wide = false);511};512513class EditorPropertyQuaternion : public EditorProperty {514GDCLASS(EditorPropertyQuaternion, EditorProperty);515BoxContainer *default_layout = nullptr;516EditorSpinSlider *spin[4];517518Button *warning = nullptr;519AcceptDialog *warning_dialog = nullptr;520521Label *euler_label = nullptr;522VBoxContainer *edit_custom_bc = nullptr;523EditorSpinSlider *euler[3];524Button *edit_button = nullptr;525526Vector3 edit_euler;527528void _value_changed(double p_val, const String &p_name);529void _edit_custom_value();530void _custom_value_changed(double p_val);531void _warning_pressed();532533bool is_grabbing_euler();534535protected:536virtual void _set_read_only(bool p_read_only) override;537void _notification(int p_what);538539public:540virtual void update_property() override;541void setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix = String(), bool p_hide_editor = false);542EditorPropertyQuaternion();543};544545class EditorPropertyAABB : public EditorProperty {546GDCLASS(EditorPropertyAABB, EditorProperty);547EditorSpinSlider *spin[6];548void _value_changed(double p_val, const String &p_name);549550protected:551virtual void _set_read_only(bool p_read_only) override;552void _notification(int p_what);553554public:555virtual void update_property() override;556void setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix = String());557EditorPropertyAABB();558};559560class EditorPropertyTransform2D : public EditorProperty {561GDCLASS(EditorPropertyTransform2D, EditorProperty);562EditorSpinSlider *spin[6];563void _value_changed(double p_val, const String &p_name);564565protected:566virtual void _set_read_only(bool p_read_only) override;567void _notification(int p_what);568569public:570virtual void update_property() override;571void setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix = String());572EditorPropertyTransform2D(bool p_include_origin = true);573};574575class EditorPropertyBasis : public EditorProperty {576GDCLASS(EditorPropertyBasis, EditorProperty);577EditorSpinSlider *spin[9];578void _value_changed(double p_val, const String &p_name);579580protected:581virtual void _set_read_only(bool p_read_only) override;582void _notification(int p_what);583584public:585virtual void update_property() override;586void setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix = String());587EditorPropertyBasis();588};589590class EditorPropertyTransform3D : public EditorProperty {591GDCLASS(EditorPropertyTransform3D, EditorProperty);592EditorSpinSlider *spin[12];593void _value_changed(double p_val, const String &p_name);594595protected:596virtual void _set_read_only(bool p_read_only) override;597void _notification(int p_what);598599public:600virtual void update_property() override;601virtual void update_using_transform(Transform3D p_transform);602void setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix = String());603EditorPropertyTransform3D();604};605606class EditorPropertyProjection : public EditorProperty {607GDCLASS(EditorPropertyProjection, EditorProperty);608EditorSpinSlider *spin[16];609void _value_changed(double p_val, const String &p_name);610611protected:612virtual void _set_read_only(bool p_read_only) override;613void _notification(int p_what);614615public:616virtual void update_property() override;617virtual void update_using_transform(Projection p_transform);618void setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix = String());619EditorPropertyProjection();620};621622class EditorPropertyColor : public EditorProperty {623GDCLASS(EditorPropertyColor, EditorProperty);624ColorPickerButton *picker = nullptr;625void _color_changed(const Color &p_color);626void _picker_created();627void _popup_opening();628void _popup_closed();629630Color last_color;631bool live_changes_enabled = true;632bool was_checked = false;633634protected:635virtual void _set_read_only(bool p_read_only) override;636void _notification(int p_what);637638public:639virtual void update_property() override;640void setup(bool p_show_alpha);641void set_live_changes_enabled(bool p_enabled);642EditorPropertyColor();643};644645class EditorPropertyNodePath : public EditorProperty {646GDCLASS(EditorPropertyNodePath, EditorProperty);647648enum {649ACTION_CLEAR,650ACTION_COPY,651ACTION_EDIT,652ACTION_SELECT,653};654655Button *assign = nullptr;656MenuButton *menu = nullptr;657LineEdit *edit = nullptr;658659SceneTreeDialog *scene_tree = nullptr;660bool use_path_from_scene_root = false;661bool editing_node = false;662bool dropping = false;663664Vector<StringName> valid_types;665void _node_selected(const NodePath &p_path, bool p_absolute = true);666void _node_assign();667void _assign_draw();668Node *get_base_node();669void _update_menu();670void _menu_option(int p_idx);671void _accept_text();672void _text_submitted(const String &p_text);673const NodePath _get_node_path() const;674675bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;676void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);677bool is_drop_valid(const Dictionary &p_drag_data) const;678679virtual Variant _get_cache_value(const StringName &p_prop, bool &r_valid) const override;680681protected:682virtual void _set_read_only(bool p_read_only) override;683void _notification(int p_what);684685public:686virtual void update_property() override;687void setup(const Vector<StringName> &p_valid_types, bool p_use_path_from_scene_root = true, bool p_editing_node = false);688EditorPropertyNodePath();689};690691class EditorPropertyRID : public EditorProperty {692GDCLASS(EditorPropertyRID, EditorProperty);693Label *label = nullptr;694695public:696virtual void update_property() override;697EditorPropertyRID();698};699700class EditorPropertyResource : public EditorProperty {701GDCLASS(EditorPropertyResource, EditorProperty);702703EditorResourcePicker *resource_picker = nullptr;704SceneTreeDialog *scene_tree = nullptr;705706bool use_sub_inspector = false;707EditorInspector *sub_inspector = nullptr;708bool opened_editor = false;709bool use_filter = false;710711void _resource_selected(const Ref<Resource> &p_resource, bool p_inspect);712void _resource_changed(const Ref<Resource> &p_resource);713714void _viewport_selected(const NodePath &p_path);715716void _sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool p_advance);717void _sub_inspector_resource_selected(const Ref<Resource> &p_resource, const String &p_property);718void _sub_inspector_object_id_selected(int p_id);719720void _open_editor_pressed();721void _update_preferred_shader();722bool _should_stop_editing() const;723724protected:725virtual void _set_read_only(bool p_read_only) override;726void _notification(int p_what);727static void _bind_methods();728729public:730virtual void update_property() override;731void setup(Object *p_object, const String &p_path, const String &p_base_type);732733void collapse_all_folding() override;734void expand_all_folding() override;735void expand_revertable() override;736737void set_use_sub_inspector(bool p_enable);738void set_use_filter(bool p_use);739void fold_resource();740741virtual bool is_colored(ColorationMode p_mode) override;742743EditorPropertyResource();744};745746///////////////////////////////////////////////////747/// \brief The EditorInspectorDefaultPlugin class748///749class EditorInspectorDefaultPlugin : public EditorInspectorPlugin {750GDCLASS(EditorInspectorDefaultPlugin, EditorInspectorPlugin);751752public:753virtual bool can_handle(Object *p_object) override;754virtual 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;755756static 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);757};758759760