editor_properties.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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_locale_dialog.h"
  35. #include "editor/editor_resource_picker.h"
  36. #include "editor/editor_spin_slider.h"
  37. #include "editor/property_selector.h"
  38. #include "editor/scene_tree_editor.h"
  39. #include "scene/gui/color_picker.h"
  40. #include "scene/gui/line_edit.h"
  41. class EditorPropertyNil : public EditorProperty {
  42. GDCLASS(EditorPropertyNil, EditorProperty);
  43. LineEdit *text;
  44. public:
  45. virtual void update_property();
  46. EditorPropertyNil();
  47. };
  48. class EditorPropertyText : public EditorProperty {
  49. GDCLASS(EditorPropertyText, EditorProperty);
  50. LineEdit *text;
  51. bool updating;
  52. void _text_changed(const String &p_string);
  53. void _text_entered(const String &p_string);
  54. protected:
  55. static void _bind_methods();
  56. public:
  57. virtual void update_property();
  58. void set_placeholder(const String &p_string);
  59. EditorPropertyText();
  60. };
  61. class EditorPropertyMultilineText : public EditorProperty {
  62. GDCLASS(EditorPropertyMultilineText, EditorProperty);
  63. TextEdit *text;
  64. AcceptDialog *big_text_dialog;
  65. TextEdit *big_text;
  66. Button *open_big_text;
  67. void _big_text_changed();
  68. void _text_changed();
  69. void _open_big_text();
  70. protected:
  71. void _notification(int p_what);
  72. static void _bind_methods();
  73. public:
  74. virtual void update_property();
  75. EditorPropertyMultilineText();
  76. };
  77. class EditorPropertyTextEnum : public EditorProperty {
  78. GDCLASS(EditorPropertyTextEnum, EditorProperty);
  79. HBoxContainer *default_layout;
  80. HBoxContainer *edit_custom_layout;
  81. OptionButton *option_button;
  82. Button *edit_button;
  83. LineEdit *custom_value_edit;
  84. Button *accept_button;
  85. Button *cancel_button;
  86. Vector<String> options;
  87. bool loose_mode = false;
  88. void _emit_changed_value(String p_string);
  89. void _option_selected(int p_which);
  90. void _edit_custom_value();
  91. void _custom_value_submitted(String p_value);
  92. void _custom_value_accepted();
  93. void _custom_value_cancelled();
  94. protected:
  95. static void _bind_methods();
  96. void _notification(int p_what);
  97. public:
  98. void setup(const Vector<String> &p_options, bool p_loose_mode = false);
  99. virtual void update_property();
  100. EditorPropertyTextEnum();
  101. };
  102. class EditorPropertyPath : public EditorProperty {
  103. GDCLASS(EditorPropertyPath, EditorProperty);
  104. Vector<String> extensions;
  105. bool folder;
  106. bool global;
  107. bool save_mode;
  108. EditorFileDialog *dialog;
  109. LineEdit *path;
  110. Button *path_edit;
  111. void _path_selected(const String &p_path);
  112. void _path_pressed();
  113. void _path_focus_exited();
  114. protected:
  115. static void _bind_methods();
  116. void _notification(int p_what);
  117. public:
  118. void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global);
  119. void set_save_mode();
  120. virtual void update_property();
  121. EditorPropertyPath();
  122. };
  123. class EditorPropertyClassName : public EditorProperty {
  124. GDCLASS(EditorPropertyClassName, EditorProperty);
  125. private:
  126. CreateDialog *dialog;
  127. Button *property;
  128. String selected_type;
  129. String base_type;
  130. void _property_selected();
  131. void _dialog_created();
  132. protected:
  133. static void _bind_methods();
  134. public:
  135. void setup(const String &p_base_type, const String &p_selected_type);
  136. virtual void update_property();
  137. EditorPropertyClassName();
  138. };
  139. class EditorPropertyMember : public EditorProperty {
  140. GDCLASS(EditorPropertyMember, EditorProperty);
  141. public:
  142. enum Type {
  143. MEMBER_METHOD_OF_VARIANT_TYPE, ///< a method of a type
  144. MEMBER_METHOD_OF_BASE_TYPE, ///< a method of a base type
  145. MEMBER_METHOD_OF_INSTANCE, ///< a method of an instance
  146. MEMBER_METHOD_OF_SCRIPT, ///< a method of a script & base
  147. MEMBER_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type
  148. MEMBER_PROPERTY_OF_BASE_TYPE, ///< a property of a base type
  149. MEMBER_PROPERTY_OF_INSTANCE, ///< a property of an instance
  150. MEMBER_PROPERTY_OF_SCRIPT, ///< a property of a script & base
  151. };
  152. private:
  153. Type hint;
  154. PropertySelector *selector;
  155. Button *property;
  156. String hint_text;
  157. void _property_selected(const String &p_selected);
  158. void _property_select();
  159. protected:
  160. static void _bind_methods();
  161. public:
  162. void setup(Type p_hint, const String &p_hint_text);
  163. virtual void update_property();
  164. EditorPropertyMember();
  165. };
  166. class EditorPropertyCheck : public EditorProperty {
  167. GDCLASS(EditorPropertyCheck, EditorProperty);
  168. CheckBox *checkbox;
  169. void _checkbox_pressed();
  170. protected:
  171. static void _bind_methods();
  172. public:
  173. virtual void update_property();
  174. EditorPropertyCheck();
  175. };
  176. class EditorPropertyEnum : public EditorProperty {
  177. GDCLASS(EditorPropertyEnum, EditorProperty);
  178. OptionButton *options;
  179. void _option_selected(int p_which);
  180. protected:
  181. static void _bind_methods();
  182. public:
  183. void setup(const Vector<String> &p_options);
  184. virtual void update_property();
  185. void set_option_button_clip(bool p_enable);
  186. EditorPropertyEnum();
  187. };
  188. class EditorPropertyFlags : public EditorProperty {
  189. GDCLASS(EditorPropertyFlags, EditorProperty);
  190. VBoxContainer *vbox;
  191. Vector<CheckBox *> flags;
  192. Vector<uint32_t> flag_values;
  193. void _flag_toggled(int p_index);
  194. protected:
  195. static void _bind_methods();
  196. public:
  197. void setup(const Vector<String> &p_options);
  198. virtual void update_property();
  199. EditorPropertyFlags();
  200. };
  201. class EditorPropertyLayersGrid;
  202. class EditorPropertyLayers : public EditorProperty {
  203. GDCLASS(EditorPropertyLayers, EditorProperty);
  204. public:
  205. enum LayerType {
  206. LAYER_PHYSICS_2D,
  207. LAYER_RENDER_2D,
  208. LAYER_NAVIGATION_2D,
  209. LAYER_PHYSICS_3D,
  210. LAYER_RENDER_3D,
  211. LAYER_NAVIGATION_3D,
  212. };
  213. private:
  214. EditorPropertyLayersGrid *grid;
  215. void _grid_changed(uint32_t p_grid);
  216. LayerType layer_type;
  217. PopupMenu *layers;
  218. Button *button;
  219. String basename;
  220. void _button_pressed();
  221. void _menu_pressed(int p_menu);
  222. void _refresh_names();
  223. String _get_layer_name(int p_index) const;
  224. protected:
  225. static void _bind_methods();
  226. public:
  227. void setup(LayerType p_layer_type);
  228. virtual void update_property();
  229. EditorPropertyLayers();
  230. };
  231. class EditorPropertyInteger : public EditorProperty {
  232. GDCLASS(EditorPropertyInteger, EditorProperty);
  233. EditorSpinSlider *spin;
  234. bool setting;
  235. void _value_changed(int64_t p_val);
  236. protected:
  237. static void _bind_methods();
  238. public:
  239. virtual void update_property();
  240. void setup(int64_t p_min, int64_t p_max, int64_t p_step, bool p_allow_greater, bool p_allow_lesser);
  241. EditorPropertyInteger();
  242. };
  243. class EditorPropertyObjectID : public EditorProperty {
  244. GDCLASS(EditorPropertyObjectID, EditorProperty);
  245. Button *edit;
  246. String base_type;
  247. void _edit_pressed();
  248. protected:
  249. static void _bind_methods();
  250. public:
  251. virtual void update_property();
  252. void setup(const String &p_base_type);
  253. EditorPropertyObjectID();
  254. };
  255. class EditorPropertyFloat : public EditorProperty {
  256. GDCLASS(EditorPropertyFloat, EditorProperty);
  257. EditorSpinSlider *spin;
  258. bool setting;
  259. void _value_changed(double p_val);
  260. protected:
  261. static void _bind_methods();
  262. public:
  263. virtual void update_property();
  264. 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);
  265. EditorPropertyFloat();
  266. };
  267. class EditorPropertyEasing : public EditorProperty {
  268. GDCLASS(EditorPropertyEasing, EditorProperty);
  269. Control *easing_draw;
  270. PopupMenu *preset;
  271. EditorSpinSlider *spin;
  272. bool setting;
  273. bool dragging;
  274. bool full;
  275. bool flip;
  276. enum {
  277. EASING_ZERO,
  278. EASING_LINEAR,
  279. EASING_IN,
  280. EASING_OUT,
  281. EASING_IN_OUT,
  282. EASING_OUT_IN,
  283. EASING_MAX
  284. };
  285. void _drag_easing(const Ref<InputEvent> &p_ev);
  286. void _draw_easing();
  287. void _set_preset(int);
  288. void _setup_spin();
  289. void _spin_value_changed(double p_value);
  290. void _spin_focus_exited();
  291. void _notification(int p_what);
  292. protected:
  293. static void _bind_methods();
  294. public:
  295. virtual void update_property();
  296. void setup(bool p_full, bool p_flip);
  297. EditorPropertyEasing();
  298. };
  299. class EditorPropertyVector2 : public EditorProperty {
  300. GDCLASS(EditorPropertyVector2, EditorProperty);
  301. EditorSpinSlider *spin[2];
  302. bool setting;
  303. double ratio_xy = 1.0;
  304. double ratio_yx = 1.0;
  305. TextureButton *linked = nullptr;
  306. void _update_ratio();
  307. void _value_changed(double p_val, const String &p_name);
  308. protected:
  309. void _notification(int p_what);
  310. static void _bind_methods();
  311. public:
  312. virtual void update_property();
  313. void setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link = false);
  314. EditorPropertyVector2();
  315. };
  316. class EditorPropertyRect2 : public EditorProperty {
  317. GDCLASS(EditorPropertyRect2, EditorProperty);
  318. EditorSpinSlider *spin[4];
  319. bool setting;
  320. void _value_changed(double p_val, const String &p_name);
  321. protected:
  322. void _notification(int p_what);
  323. static void _bind_methods();
  324. public:
  325. virtual void update_property();
  326. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  327. EditorPropertyRect2();
  328. };
  329. class EditorPropertyVector3 : public EditorProperty {
  330. GDCLASS(EditorPropertyVector3, EditorProperty);
  331. EditorSpinSlider *spin[3];
  332. bool setting;
  333. double ratio_yx = 1.0;
  334. double ratio_zx = 1.0;
  335. double ratio_xy = 1.0;
  336. double ratio_zy = 1.0;
  337. double ratio_xz = 1.0;
  338. double ratio_yz = 1.0;
  339. TextureButton *linked = nullptr;
  340. void _update_ratio();
  341. void _value_changed(double p_val, const String &p_name);
  342. protected:
  343. void _notification(int p_what);
  344. static void _bind_methods();
  345. public:
  346. virtual void update_property();
  347. void setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link = false);
  348. EditorPropertyVector3();
  349. };
  350. class EditorPropertyPlane : public EditorProperty {
  351. GDCLASS(EditorPropertyPlane, EditorProperty);
  352. EditorSpinSlider *spin[4];
  353. bool setting;
  354. void _value_changed(double p_val, const String &p_name);
  355. protected:
  356. void _notification(int p_what);
  357. static void _bind_methods();
  358. public:
  359. virtual void update_property();
  360. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  361. EditorPropertyPlane();
  362. };
  363. class EditorPropertyQuat : public EditorProperty {
  364. GDCLASS(EditorPropertyQuat, EditorProperty);
  365. EditorSpinSlider *spin[4];
  366. bool setting;
  367. void _value_changed(double p_val, const String &p_name);
  368. protected:
  369. void _notification(int p_what);
  370. static void _bind_methods();
  371. public:
  372. virtual void update_property();
  373. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  374. EditorPropertyQuat();
  375. };
  376. class EditorPropertyAABB : public EditorProperty {
  377. GDCLASS(EditorPropertyAABB, EditorProperty);
  378. EditorSpinSlider *spin[6];
  379. bool setting;
  380. void _value_changed(double p_val, const String &p_name);
  381. protected:
  382. void _notification(int p_what);
  383. static void _bind_methods();
  384. public:
  385. virtual void update_property();
  386. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  387. EditorPropertyAABB();
  388. };
  389. class EditorPropertyTransform2D : public EditorProperty {
  390. GDCLASS(EditorPropertyTransform2D, EditorProperty);
  391. EditorSpinSlider *spin[6];
  392. bool setting;
  393. void _value_changed(double p_val, const String &p_name);
  394. protected:
  395. void _notification(int p_what);
  396. static void _bind_methods();
  397. public:
  398. virtual void update_property();
  399. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  400. EditorPropertyTransform2D();
  401. };
  402. class EditorPropertyBasis : public EditorProperty {
  403. GDCLASS(EditorPropertyBasis, EditorProperty);
  404. EditorSpinSlider *spin[9];
  405. bool setting;
  406. void _value_changed(double p_val, const String &p_name);
  407. protected:
  408. void _notification(int p_what);
  409. static void _bind_methods();
  410. public:
  411. virtual void update_property();
  412. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  413. EditorPropertyBasis();
  414. };
  415. class EditorPropertyTransform : public EditorProperty {
  416. GDCLASS(EditorPropertyTransform, EditorProperty);
  417. EditorSpinSlider *spin[12];
  418. bool setting;
  419. void _value_changed(double p_val, const String &p_name);
  420. protected:
  421. void _notification(int p_what);
  422. static void _bind_methods();
  423. public:
  424. virtual void update_property();
  425. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  426. EditorPropertyTransform();
  427. };
  428. class EditorPropertyColor : public EditorProperty {
  429. GDCLASS(EditorPropertyColor, EditorProperty);
  430. ColorPickerButton *picker;
  431. void _color_changed(const Color &p_color);
  432. void _popup_closed();
  433. void _picker_created();
  434. void _picker_opening();
  435. Color last_color;
  436. protected:
  437. static void _bind_methods();
  438. public:
  439. virtual void update_property();
  440. void setup(bool p_show_alpha);
  441. EditorPropertyColor();
  442. };
  443. class EditorPropertyNodePath : public EditorProperty {
  444. GDCLASS(EditorPropertyNodePath, EditorProperty);
  445. Button *assign;
  446. Button *clear;
  447. SceneTreeDialog *scene_tree;
  448. NodePath base_hint;
  449. bool use_path_from_scene_root;
  450. Vector<StringName> valid_types;
  451. void _node_selected(const NodePath &p_path);
  452. void _node_assign();
  453. void _node_clear();
  454. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  455. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  456. bool is_drop_valid(const Dictionary &p_drag_data) const;
  457. protected:
  458. static void _bind_methods();
  459. void _notification(int p_what);
  460. public:
  461. virtual void update_property();
  462. void setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root = true);
  463. EditorPropertyNodePath();
  464. };
  465. class EditorPropertyLocale : public EditorProperty {
  466. GDCLASS(EditorPropertyLocale, EditorProperty);
  467. EditorLocaleDialog *dialog;
  468. LineEdit *locale;
  469. Button *locale_edit;
  470. void _locale_selected(const String &p_locale);
  471. void _locale_pressed();
  472. void _locale_focus_exited();
  473. protected:
  474. static void _bind_methods();
  475. void _notification(int p_what);
  476. public:
  477. void setup(const String &p_hit_string);
  478. virtual void update_property();
  479. EditorPropertyLocale();
  480. };
  481. class EditorPropertyRID : public EditorProperty {
  482. GDCLASS(EditorPropertyRID, EditorProperty);
  483. Label *label;
  484. public:
  485. virtual void update_property();
  486. EditorPropertyRID();
  487. };
  488. class EditorPropertyResource : public EditorProperty {
  489. GDCLASS(EditorPropertyResource, EditorProperty);
  490. EditorResourcePicker *resource_picker = nullptr;
  491. SceneTreeDialog *scene_tree = nullptr;
  492. bool use_sub_inspector = false;
  493. EditorInspector *sub_inspector = nullptr;
  494. VBoxContainer *sub_inspector_vbox = nullptr;
  495. bool updating_theme = false;
  496. bool opened_editor = false;
  497. void _resource_selected(const RES &p_resource, bool p_edit);
  498. void _resource_changed(const RES &p_resource);
  499. void _viewport_selected(const NodePath &p_path);
  500. void _sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool);
  501. void _sub_inspector_resource_selected(const RES &p_resource, const String &p_property);
  502. void _sub_inspector_object_id_selected(int p_id);
  503. bool _can_use_sub_inspector(const RES &p_resource);
  504. void _open_editor_pressed();
  505. void _fold_other_editors(Object *p_self);
  506. void _update_property_bg();
  507. protected:
  508. static void _bind_methods();
  509. void _notification(int p_what);
  510. public:
  511. virtual void update_property();
  512. void setup(Object *p_object, const String &p_path, const String &p_base_type);
  513. void collapse_all_folding();
  514. void expand_all_folding();
  515. void set_use_sub_inspector(bool p_enable);
  516. EditorPropertyResource();
  517. };
  518. ///////////////////////////////////////////////////
  519. /// \brief The EditorInspectorDefaultPlugin class
  520. ///
  521. class EditorInspectorDefaultPlugin : public EditorInspectorPlugin {
  522. GDCLASS(EditorInspectorDefaultPlugin, EditorInspectorPlugin);
  523. public:
  524. virtual bool can_handle(Object *p_object);
  525. virtual void parse_begin(Object *p_object);
  526. 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);
  527. virtual void parse_end();
  528. };
  529. #endif // EDITOR_PROPERTIES_H