editor_properties.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /**************************************************************************/
  2. /* editor_properties.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef EDITOR_PROPERTIES_H
  31. #define EDITOR_PROPERTIES_H
  32. #include "editor/create_dialog.h"
  33. #include "editor/editor_inspector.h"
  34. #include "editor/editor_resource_picker.h"
  35. #include "editor/editor_spin_slider.h"
  36. #include "editor/property_selector.h"
  37. #include "editor/scene_tree_editor.h"
  38. #include "scene/gui/color_picker.h"
  39. #include "scene/gui/line_edit.h"
  40. class EditorPropertyNil : public EditorProperty {
  41. GDCLASS(EditorPropertyNil, EditorProperty);
  42. LineEdit *text;
  43. public:
  44. virtual void update_property();
  45. EditorPropertyNil();
  46. };
  47. class EditorPropertyText : public EditorProperty {
  48. GDCLASS(EditorPropertyText, EditorProperty);
  49. LineEdit *text;
  50. bool updating;
  51. void _text_changed(const String &p_string);
  52. void _text_entered(const String &p_string);
  53. protected:
  54. static void _bind_methods();
  55. public:
  56. virtual void update_property();
  57. void set_placeholder(const String &p_string);
  58. EditorPropertyText();
  59. };
  60. class EditorPropertyMultilineText : public EditorProperty {
  61. GDCLASS(EditorPropertyMultilineText, EditorProperty);
  62. TextEdit *text;
  63. AcceptDialog *big_text_dialog;
  64. TextEdit *big_text;
  65. Button *open_big_text;
  66. void _big_text_changed();
  67. void _text_changed();
  68. void _open_big_text();
  69. protected:
  70. void _notification(int p_what);
  71. static void _bind_methods();
  72. public:
  73. virtual void update_property();
  74. EditorPropertyMultilineText();
  75. };
  76. class EditorPropertyTextEnum : public EditorProperty {
  77. GDCLASS(EditorPropertyTextEnum, EditorProperty);
  78. HBoxContainer *default_layout;
  79. HBoxContainer *edit_custom_layout;
  80. OptionButton *option_button;
  81. Button *edit_button;
  82. LineEdit *custom_value_edit;
  83. Button *accept_button;
  84. Button *cancel_button;
  85. Vector<String> options;
  86. bool loose_mode = false;
  87. void _emit_changed_value(String p_string);
  88. void _option_selected(int p_which);
  89. void _edit_custom_value();
  90. void _custom_value_submitted(String p_value);
  91. void _custom_value_accepted();
  92. void _custom_value_cancelled();
  93. protected:
  94. static void _bind_methods();
  95. void _notification(int p_what);
  96. public:
  97. void setup(const Vector<String> &p_options, bool p_loose_mode = false);
  98. virtual void update_property();
  99. EditorPropertyTextEnum();
  100. };
  101. class EditorPropertyPath : public EditorProperty {
  102. GDCLASS(EditorPropertyPath, EditorProperty);
  103. Vector<String> extensions;
  104. bool folder;
  105. bool global;
  106. bool save_mode;
  107. EditorFileDialog *dialog;
  108. LineEdit *path;
  109. Button *path_edit;
  110. void _path_selected(const String &p_path);
  111. void _path_pressed();
  112. void _path_focus_exited();
  113. protected:
  114. static void _bind_methods();
  115. void _notification(int p_what);
  116. public:
  117. void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global);
  118. void set_save_mode();
  119. virtual void update_property();
  120. EditorPropertyPath();
  121. };
  122. class EditorPropertyClassName : public EditorProperty {
  123. GDCLASS(EditorPropertyClassName, EditorProperty);
  124. private:
  125. CreateDialog *dialog;
  126. Button *property;
  127. String selected_type;
  128. String base_type;
  129. void _property_selected();
  130. void _dialog_created();
  131. protected:
  132. static void _bind_methods();
  133. public:
  134. void setup(const String &p_base_type, const String &p_selected_type);
  135. virtual void update_property();
  136. EditorPropertyClassName();
  137. };
  138. class EditorPropertyMember : public EditorProperty {
  139. GDCLASS(EditorPropertyMember, EditorProperty);
  140. public:
  141. enum Type {
  142. MEMBER_METHOD_OF_VARIANT_TYPE, ///< a method of a type
  143. MEMBER_METHOD_OF_BASE_TYPE, ///< a method of a base type
  144. MEMBER_METHOD_OF_INSTANCE, ///< a method of an instance
  145. MEMBER_METHOD_OF_SCRIPT, ///< a method of a script & base
  146. MEMBER_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type
  147. MEMBER_PROPERTY_OF_BASE_TYPE, ///< a property of a base type
  148. MEMBER_PROPERTY_OF_INSTANCE, ///< a property of an instance
  149. MEMBER_PROPERTY_OF_SCRIPT, ///< a property of a script & base
  150. };
  151. private:
  152. Type hint;
  153. PropertySelector *selector;
  154. Button *property;
  155. String hint_text;
  156. void _property_selected(const String &p_selected);
  157. void _property_select();
  158. protected:
  159. static void _bind_methods();
  160. public:
  161. void setup(Type p_hint, const String &p_hint_text);
  162. virtual void update_property();
  163. EditorPropertyMember();
  164. };
  165. class EditorPropertyCheck : public EditorProperty {
  166. GDCLASS(EditorPropertyCheck, EditorProperty);
  167. CheckBox *checkbox;
  168. void _checkbox_pressed();
  169. protected:
  170. static void _bind_methods();
  171. public:
  172. virtual void update_property();
  173. EditorPropertyCheck();
  174. };
  175. class EditorPropertyEnum : public EditorProperty {
  176. GDCLASS(EditorPropertyEnum, EditorProperty);
  177. OptionButton *options;
  178. void _option_selected(int p_which);
  179. protected:
  180. static void _bind_methods();
  181. public:
  182. void setup(const Vector<String> &p_options);
  183. virtual void update_property();
  184. void set_option_button_clip(bool p_enable);
  185. EditorPropertyEnum();
  186. };
  187. class EditorPropertyFlags : public EditorProperty {
  188. GDCLASS(EditorPropertyFlags, EditorProperty);
  189. VBoxContainer *vbox;
  190. Vector<CheckBox *> flags;
  191. Vector<int> flag_indices;
  192. void _flag_toggled();
  193. protected:
  194. static void _bind_methods();
  195. public:
  196. void setup(const Vector<String> &p_options);
  197. virtual void update_property();
  198. EditorPropertyFlags();
  199. };
  200. class EditorPropertyLayersGrid;
  201. class EditorPropertyLayers : public EditorProperty {
  202. GDCLASS(EditorPropertyLayers, EditorProperty);
  203. public:
  204. enum LayerType {
  205. LAYER_PHYSICS_2D,
  206. LAYER_RENDER_2D,
  207. LAYER_NAVIGATION_2D,
  208. LAYER_PHYSICS_3D,
  209. LAYER_RENDER_3D,
  210. LAYER_NAVIGATION_3D,
  211. };
  212. private:
  213. EditorPropertyLayersGrid *grid;
  214. void _grid_changed(uint32_t p_grid);
  215. LayerType layer_type;
  216. PopupMenu *layers;
  217. Button *button;
  218. void _button_pressed();
  219. void _menu_pressed(int p_menu);
  220. void _refresh_names();
  221. protected:
  222. static void _bind_methods();
  223. public:
  224. void setup(LayerType p_layer_type);
  225. virtual void update_property();
  226. EditorPropertyLayers();
  227. };
  228. class EditorPropertyInteger : public EditorProperty {
  229. GDCLASS(EditorPropertyInteger, EditorProperty);
  230. EditorSpinSlider *spin;
  231. bool setting;
  232. void _value_changed(int64_t p_val);
  233. protected:
  234. static void _bind_methods();
  235. public:
  236. virtual void update_property();
  237. void setup(int64_t p_min, int64_t p_max, int64_t p_step, bool p_allow_greater, bool p_allow_lesser);
  238. EditorPropertyInteger();
  239. };
  240. class EditorPropertyObjectID : public EditorProperty {
  241. GDCLASS(EditorPropertyObjectID, EditorProperty);
  242. Button *edit;
  243. String base_type;
  244. void _edit_pressed();
  245. protected:
  246. static void _bind_methods();
  247. public:
  248. virtual void update_property();
  249. void setup(const String &p_base_type);
  250. EditorPropertyObjectID();
  251. };
  252. class EditorPropertyFloat : public EditorProperty {
  253. GDCLASS(EditorPropertyFloat, EditorProperty);
  254. EditorSpinSlider *spin;
  255. bool setting;
  256. void _value_changed(double p_val);
  257. protected:
  258. static void _bind_methods();
  259. public:
  260. virtual void update_property();
  261. void setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_exp_range, bool p_greater, bool p_lesser);
  262. EditorPropertyFloat();
  263. };
  264. class EditorPropertyEasing : public EditorProperty {
  265. GDCLASS(EditorPropertyEasing, EditorProperty);
  266. Control *easing_draw;
  267. PopupMenu *preset;
  268. EditorSpinSlider *spin;
  269. bool setting;
  270. bool dragging;
  271. bool full;
  272. bool flip;
  273. enum {
  274. EASING_ZERO,
  275. EASING_LINEAR,
  276. EASING_IN,
  277. EASING_OUT,
  278. EASING_IN_OUT,
  279. EASING_OUT_IN,
  280. EASING_MAX
  281. };
  282. void _drag_easing(const Ref<InputEvent> &p_ev);
  283. void _draw_easing();
  284. void _set_preset(int);
  285. void _setup_spin();
  286. void _spin_value_changed(double p_value);
  287. void _spin_focus_exited();
  288. void _notification(int p_what);
  289. protected:
  290. static void _bind_methods();
  291. public:
  292. virtual void update_property();
  293. void setup(bool p_full, bool p_flip);
  294. EditorPropertyEasing();
  295. };
  296. class EditorPropertyVector2 : public EditorProperty {
  297. GDCLASS(EditorPropertyVector2, EditorProperty);
  298. EditorSpinSlider *spin[2];
  299. bool setting;
  300. void _value_changed(double p_val, const String &p_name);
  301. protected:
  302. void _notification(int p_what);
  303. static void _bind_methods();
  304. public:
  305. virtual void update_property();
  306. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  307. EditorPropertyVector2();
  308. };
  309. class EditorPropertyRect2 : public EditorProperty {
  310. GDCLASS(EditorPropertyRect2, EditorProperty);
  311. EditorSpinSlider *spin[4];
  312. bool setting;
  313. void _value_changed(double p_val, const String &p_name);
  314. protected:
  315. void _notification(int p_what);
  316. static void _bind_methods();
  317. public:
  318. virtual void update_property();
  319. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  320. EditorPropertyRect2();
  321. };
  322. class EditorPropertyVector3 : public EditorProperty {
  323. GDCLASS(EditorPropertyVector3, EditorProperty);
  324. EditorSpinSlider *spin[3];
  325. bool setting;
  326. void _value_changed(double p_val, const String &p_name);
  327. protected:
  328. void _notification(int p_what);
  329. static void _bind_methods();
  330. public:
  331. virtual void update_property();
  332. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  333. EditorPropertyVector3();
  334. };
  335. class EditorPropertyPlane : public EditorProperty {
  336. GDCLASS(EditorPropertyPlane, EditorProperty);
  337. EditorSpinSlider *spin[4];
  338. bool setting;
  339. void _value_changed(double p_val, const String &p_name);
  340. protected:
  341. void _notification(int p_what);
  342. static void _bind_methods();
  343. public:
  344. virtual void update_property();
  345. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  346. EditorPropertyPlane();
  347. };
  348. class EditorPropertyQuat : public EditorProperty {
  349. GDCLASS(EditorPropertyQuat, EditorProperty);
  350. EditorSpinSlider *spin[4];
  351. bool setting;
  352. void _value_changed(double p_val, const String &p_name);
  353. protected:
  354. void _notification(int p_what);
  355. static void _bind_methods();
  356. public:
  357. virtual void update_property();
  358. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  359. EditorPropertyQuat();
  360. };
  361. class EditorPropertyAABB : public EditorProperty {
  362. GDCLASS(EditorPropertyAABB, EditorProperty);
  363. EditorSpinSlider *spin[6];
  364. bool setting;
  365. void _value_changed(double p_val, const String &p_name);
  366. protected:
  367. void _notification(int p_what);
  368. static void _bind_methods();
  369. public:
  370. virtual void update_property();
  371. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  372. EditorPropertyAABB();
  373. };
  374. class EditorPropertyTransform2D : public EditorProperty {
  375. GDCLASS(EditorPropertyTransform2D, EditorProperty);
  376. EditorSpinSlider *spin[6];
  377. bool setting;
  378. void _value_changed(double p_val, const String &p_name);
  379. protected:
  380. void _notification(int p_what);
  381. static void _bind_methods();
  382. public:
  383. virtual void update_property();
  384. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  385. EditorPropertyTransform2D();
  386. };
  387. class EditorPropertyBasis : public EditorProperty {
  388. GDCLASS(EditorPropertyBasis, EditorProperty);
  389. EditorSpinSlider *spin[9];
  390. bool setting;
  391. void _value_changed(double p_val, const String &p_name);
  392. protected:
  393. void _notification(int p_what);
  394. static void _bind_methods();
  395. public:
  396. virtual void update_property();
  397. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  398. EditorPropertyBasis();
  399. };
  400. class EditorPropertyTransform : public EditorProperty {
  401. GDCLASS(EditorPropertyTransform, EditorProperty);
  402. EditorSpinSlider *spin[12];
  403. bool setting;
  404. void _value_changed(double p_val, const String &p_name);
  405. protected:
  406. void _notification(int p_what);
  407. static void _bind_methods();
  408. public:
  409. virtual void update_property();
  410. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  411. EditorPropertyTransform();
  412. };
  413. class EditorPropertyColor : public EditorProperty {
  414. GDCLASS(EditorPropertyColor, EditorProperty);
  415. ColorPickerButton *picker;
  416. void _color_changed(const Color &p_color);
  417. void _popup_closed();
  418. void _picker_created();
  419. void _picker_opening();
  420. Color last_color;
  421. protected:
  422. static void _bind_methods();
  423. public:
  424. virtual void update_property();
  425. void setup(bool p_show_alpha);
  426. EditorPropertyColor();
  427. };
  428. class EditorPropertyNodePath : public EditorProperty {
  429. GDCLASS(EditorPropertyNodePath, EditorProperty);
  430. Button *assign;
  431. Button *clear;
  432. SceneTreeDialog *scene_tree;
  433. NodePath base_hint;
  434. bool use_path_from_scene_root;
  435. Vector<StringName> valid_types;
  436. void _node_selected(const NodePath &p_path);
  437. void _node_assign();
  438. void _node_clear();
  439. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  440. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  441. bool is_drop_valid(const Dictionary &p_drag_data) const;
  442. protected:
  443. static void _bind_methods();
  444. void _notification(int p_what);
  445. public:
  446. virtual void update_property();
  447. void setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root = true);
  448. EditorPropertyNodePath();
  449. };
  450. class EditorPropertyRID : public EditorProperty {
  451. GDCLASS(EditorPropertyRID, EditorProperty);
  452. Label *label;
  453. public:
  454. virtual void update_property();
  455. EditorPropertyRID();
  456. };
  457. class EditorPropertyResource : public EditorProperty {
  458. GDCLASS(EditorPropertyResource, EditorProperty);
  459. EditorResourcePicker *resource_picker = nullptr;
  460. SceneTreeDialog *scene_tree = nullptr;
  461. bool use_sub_inspector = false;
  462. EditorInspector *sub_inspector = nullptr;
  463. VBoxContainer *sub_inspector_vbox = nullptr;
  464. bool updating_theme = false;
  465. bool opened_editor = false;
  466. void _resource_selected(const RES &p_resource, bool p_edit);
  467. void _resource_changed(const RES &p_resource);
  468. void _viewport_selected(const NodePath &p_path);
  469. void _sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool);
  470. void _sub_inspector_resource_selected(const RES &p_resource, const String &p_property);
  471. void _sub_inspector_object_id_selected(int p_id);
  472. bool _can_use_sub_inspector(const RES &p_resource);
  473. void _open_editor_pressed();
  474. void _fold_other_editors(Object *p_self);
  475. void _update_property_bg();
  476. protected:
  477. static void _bind_methods();
  478. void _notification(int p_what);
  479. public:
  480. virtual void update_property();
  481. void setup(Object *p_object, const String &p_path, const String &p_base_type);
  482. void collapse_all_folding();
  483. void expand_all_folding();
  484. void set_use_sub_inspector(bool p_enable);
  485. EditorPropertyResource();
  486. };
  487. ///////////////////////////////////////////////////
  488. /// \brief The EditorInspectorDefaultPlugin class
  489. ///
  490. class EditorInspectorDefaultPlugin : public EditorInspectorPlugin {
  491. GDCLASS(EditorInspectorDefaultPlugin, EditorInspectorPlugin);
  492. public:
  493. virtual bool can_handle(Object *p_object);
  494. virtual void parse_begin(Object *p_object);
  495. virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage);
  496. virtual void parse_end();
  497. };
  498. #endif // EDITOR_PROPERTIES_H