editor_properties.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*************************************************************************/
  2. /* editor_properties.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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_file_system.h"
  34. #include "editor/editor_inspector.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. class EditorPropertyNil : public EditorProperty {
  40. GDCLASS(EditorPropertyNil, EditorProperty)
  41. LineEdit *text;
  42. public:
  43. virtual void update_property();
  44. EditorPropertyNil();
  45. };
  46. class EditorPropertyText : public EditorProperty {
  47. GDCLASS(EditorPropertyText, EditorProperty)
  48. LineEdit *text;
  49. bool updating;
  50. void _text_changed(const String &p_string);
  51. void _text_entered(const String &p_string);
  52. protected:
  53. static void _bind_methods();
  54. public:
  55. virtual void update_property();
  56. void set_placeholder(const String &p_string);
  57. EditorPropertyText();
  58. };
  59. class EditorPropertyMultilineText : public EditorProperty {
  60. GDCLASS(EditorPropertyMultilineText, EditorProperty)
  61. TextEdit *text;
  62. AcceptDialog *big_text_dialog;
  63. TextEdit *big_text;
  64. Button *open_big_text;
  65. void _big_text_changed();
  66. void _text_changed();
  67. void _open_big_text();
  68. protected:
  69. void _notification(int p_what);
  70. static void _bind_methods();
  71. public:
  72. virtual void update_property();
  73. EditorPropertyMultilineText();
  74. };
  75. class EditorPropertyTextEnum : public EditorProperty {
  76. GDCLASS(EditorPropertyTextEnum, EditorProperty)
  77. OptionButton *options;
  78. void _option_selected(int p_which);
  79. protected:
  80. static void _bind_methods();
  81. public:
  82. void setup(const Vector<String> &p_options);
  83. virtual void update_property();
  84. EditorPropertyTextEnum();
  85. };
  86. class EditorPropertyPath : public EditorProperty {
  87. GDCLASS(EditorPropertyPath, EditorProperty)
  88. Vector<String> extensions;
  89. bool folder;
  90. bool global;
  91. bool save_mode;
  92. EditorFileDialog *dialog;
  93. LineEdit *path;
  94. Button *path_edit;
  95. void _path_selected(const String &p_path);
  96. void _path_pressed();
  97. void _path_focus_exited();
  98. protected:
  99. static void _bind_methods();
  100. void _notification(int p_what);
  101. public:
  102. void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global);
  103. void set_save_mode();
  104. virtual void update_property();
  105. EditorPropertyPath();
  106. };
  107. class EditorPropertyClassName : public EditorProperty {
  108. GDCLASS(EditorPropertyClassName, EditorProperty)
  109. private:
  110. CreateDialog *dialog;
  111. Button *property;
  112. String selected_type;
  113. String base_type;
  114. void _property_selected();
  115. void _dialog_created();
  116. protected:
  117. static void _bind_methods();
  118. public:
  119. void setup(const String &p_base_type, const String &p_selected_type);
  120. virtual void update_property();
  121. EditorPropertyClassName();
  122. };
  123. class EditorPropertyMember : public EditorProperty {
  124. GDCLASS(EditorPropertyMember, EditorProperty)
  125. public:
  126. enum Type {
  127. MEMBER_METHOD_OF_VARIANT_TYPE, ///< a method of a type
  128. MEMBER_METHOD_OF_BASE_TYPE, ///< a method of a base type
  129. MEMBER_METHOD_OF_INSTANCE, ///< a method of an instance
  130. MEMBER_METHOD_OF_SCRIPT, ///< a method of a script & base
  131. MEMBER_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type
  132. MEMBER_PROPERTY_OF_BASE_TYPE, ///< a property of a base type
  133. MEMBER_PROPERTY_OF_INSTANCE, ///< a property of an instance
  134. MEMBER_PROPERTY_OF_SCRIPT, ///< a property of a script & base
  135. };
  136. private:
  137. Type hint;
  138. PropertySelector *selector;
  139. Button *property;
  140. String hint_text;
  141. void _property_selected(const String &p_selected);
  142. void _property_select();
  143. protected:
  144. static void _bind_methods();
  145. public:
  146. void setup(Type p_hint, const String &p_hint_text);
  147. virtual void update_property();
  148. EditorPropertyMember();
  149. };
  150. class EditorPropertyCheck : public EditorProperty {
  151. GDCLASS(EditorPropertyCheck, EditorProperty)
  152. CheckBox *checkbox;
  153. void _checkbox_pressed();
  154. protected:
  155. static void _bind_methods();
  156. public:
  157. virtual void update_property();
  158. EditorPropertyCheck();
  159. };
  160. class EditorPropertyEnum : public EditorProperty {
  161. GDCLASS(EditorPropertyEnum, EditorProperty)
  162. OptionButton *options;
  163. void _option_selected(int p_which);
  164. protected:
  165. static void _bind_methods();
  166. public:
  167. void setup(const Vector<String> &p_options);
  168. virtual void update_property();
  169. void set_option_button_clip(bool p_enable);
  170. EditorPropertyEnum();
  171. };
  172. class EditorPropertyFlags : public EditorProperty {
  173. GDCLASS(EditorPropertyFlags, EditorProperty)
  174. VBoxContainer *vbox;
  175. Vector<CheckBox *> flags;
  176. Vector<int> flag_indices;
  177. void _flag_toggled();
  178. protected:
  179. static void _bind_methods();
  180. public:
  181. void setup(const Vector<String> &p_options);
  182. virtual void update_property();
  183. EditorPropertyFlags();
  184. };
  185. class EditorPropertyLayersGrid;
  186. class EditorPropertyLayers : public EditorProperty {
  187. GDCLASS(EditorPropertyLayers, EditorProperty)
  188. public:
  189. enum LayerType {
  190. LAYER_PHYSICS_2D,
  191. LAYER_RENDER_2D,
  192. LAYER_PHYSICS_3D,
  193. LAYER_RENDER_3D,
  194. };
  195. private:
  196. EditorPropertyLayersGrid *grid;
  197. void _grid_changed(uint32_t p_grid);
  198. LayerType layer_type;
  199. PopupMenu *layers;
  200. Button *button;
  201. void _button_pressed();
  202. void _menu_pressed(int p_menu);
  203. protected:
  204. static void _bind_methods();
  205. public:
  206. void setup(LayerType p_layer_type);
  207. virtual void update_property();
  208. EditorPropertyLayers();
  209. };
  210. class EditorPropertyInteger : public EditorProperty {
  211. GDCLASS(EditorPropertyInteger, EditorProperty)
  212. EditorSpinSlider *spin;
  213. bool setting;
  214. void _value_changed(double p_val);
  215. protected:
  216. static void _bind_methods();
  217. public:
  218. virtual void update_property();
  219. void setup(int p_min, int p_max, int p_step, bool p_allow_greater, bool p_allow_lesser);
  220. EditorPropertyInteger();
  221. };
  222. class EditorPropertyObjectID : public EditorProperty {
  223. GDCLASS(EditorPropertyObjectID, EditorProperty)
  224. Button *edit;
  225. String base_type;
  226. void _edit_pressed();
  227. protected:
  228. static void _bind_methods();
  229. public:
  230. virtual void update_property();
  231. void setup(const String &p_base_type);
  232. EditorPropertyObjectID();
  233. };
  234. class EditorPropertyFloat : public EditorProperty {
  235. GDCLASS(EditorPropertyFloat, EditorProperty)
  236. EditorSpinSlider *spin;
  237. bool setting;
  238. void _value_changed(double p_val);
  239. protected:
  240. static void _bind_methods();
  241. public:
  242. virtual void update_property();
  243. 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);
  244. EditorPropertyFloat();
  245. };
  246. class EditorPropertyEasing : public EditorProperty {
  247. GDCLASS(EditorPropertyEasing, EditorProperty)
  248. Control *easing_draw;
  249. PopupMenu *preset;
  250. bool full;
  251. enum {
  252. EASING_ZERO,
  253. EASING_LINEAR,
  254. EASING_IN,
  255. EASING_OUT,
  256. EASING_IN_OUT,
  257. EASING_OUT_IN,
  258. EASING_MAX
  259. };
  260. bool flip;
  261. void _drag_easing(const Ref<InputEvent> &p_ev);
  262. void _draw_easing();
  263. void _notification(int p_what);
  264. void _set_preset(int);
  265. protected:
  266. static void _bind_methods();
  267. public:
  268. virtual void update_property();
  269. void setup(bool p_full, bool p_flip);
  270. EditorPropertyEasing();
  271. };
  272. class EditorPropertyVector2 : public EditorProperty {
  273. GDCLASS(EditorPropertyVector2, EditorProperty)
  274. EditorSpinSlider *spin[2];
  275. bool setting;
  276. void _value_changed(double p_val);
  277. protected:
  278. void _notification(int p_what);
  279. static void _bind_methods();
  280. public:
  281. virtual void update_property();
  282. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  283. EditorPropertyVector2();
  284. };
  285. class EditorPropertyRect2 : public EditorProperty {
  286. GDCLASS(EditorPropertyRect2, EditorProperty)
  287. EditorSpinSlider *spin[4];
  288. bool setting;
  289. void _value_changed(double p_val);
  290. protected:
  291. void _notification(int p_what);
  292. static void _bind_methods();
  293. public:
  294. virtual void update_property();
  295. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  296. EditorPropertyRect2();
  297. };
  298. class EditorPropertyVector3 : public EditorProperty {
  299. GDCLASS(EditorPropertyVector3, EditorProperty)
  300. EditorSpinSlider *spin[3];
  301. bool setting;
  302. void _value_changed(double p_val);
  303. protected:
  304. void _notification(int p_what);
  305. static void _bind_methods();
  306. public:
  307. virtual void update_property();
  308. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  309. EditorPropertyVector3();
  310. };
  311. class EditorPropertyPlane : public EditorProperty {
  312. GDCLASS(EditorPropertyPlane, EditorProperty)
  313. EditorSpinSlider *spin[4];
  314. bool setting;
  315. void _value_changed(double p_val);
  316. protected:
  317. void _notification(int p_what);
  318. static void _bind_methods();
  319. public:
  320. virtual void update_property();
  321. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  322. EditorPropertyPlane();
  323. };
  324. class EditorPropertyQuat : public EditorProperty {
  325. GDCLASS(EditorPropertyQuat, EditorProperty)
  326. EditorSpinSlider *spin[4];
  327. bool setting;
  328. void _value_changed(double p_val);
  329. protected:
  330. void _notification(int p_what);
  331. static void _bind_methods();
  332. public:
  333. virtual void update_property();
  334. void setup(double p_min, double p_max, double p_step, bool p_no_slider);
  335. EditorPropertyQuat();
  336. };
  337. class EditorPropertyAABB : public EditorProperty {
  338. GDCLASS(EditorPropertyAABB, EditorProperty)
  339. EditorSpinSlider *spin[6];
  340. bool setting;
  341. void _value_changed(double p_val);
  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);
  348. EditorPropertyAABB();
  349. };
  350. class EditorPropertyTransform2D : public EditorProperty {
  351. GDCLASS(EditorPropertyTransform2D, EditorProperty)
  352. EditorSpinSlider *spin[6];
  353. bool setting;
  354. void _value_changed(double p_val);
  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. EditorPropertyTransform2D();
  362. };
  363. class EditorPropertyBasis : public EditorProperty {
  364. GDCLASS(EditorPropertyBasis, EditorProperty)
  365. EditorSpinSlider *spin[9];
  366. bool setting;
  367. void _value_changed(double p_val);
  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. EditorPropertyBasis();
  375. };
  376. class EditorPropertyTransform : public EditorProperty {
  377. GDCLASS(EditorPropertyTransform, EditorProperty)
  378. EditorSpinSlider *spin[12];
  379. bool setting;
  380. void _value_changed(double p_val);
  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. EditorPropertyTransform();
  388. };
  389. class EditorPropertyColor : public EditorProperty {
  390. GDCLASS(EditorPropertyColor, EditorProperty)
  391. ColorPickerButton *picker;
  392. void _color_changed(const Color &p_color);
  393. void _popup_closed();
  394. protected:
  395. static void _bind_methods();
  396. public:
  397. virtual void update_property();
  398. void setup(bool p_show_alpha);
  399. EditorPropertyColor();
  400. };
  401. class EditorPropertyNodePath : public EditorProperty {
  402. GDCLASS(EditorPropertyNodePath, EditorProperty)
  403. Button *assign;
  404. Button *clear;
  405. SceneTreeDialog *scene_tree;
  406. NodePath base_hint;
  407. Vector<StringName> valid_types;
  408. void _node_selected(const NodePath &p_path);
  409. void _node_assign();
  410. void _node_clear();
  411. protected:
  412. static void _bind_methods();
  413. void _notification(int p_what);
  414. public:
  415. virtual void update_property();
  416. void setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types);
  417. EditorPropertyNodePath();
  418. };
  419. class EditorPropertyResource : public EditorProperty {
  420. GDCLASS(EditorPropertyResource, EditorProperty)
  421. enum MenuOption {
  422. OBJ_MENU_LOAD = 0,
  423. OBJ_MENU_EDIT = 1,
  424. OBJ_MENU_CLEAR = 2,
  425. OBJ_MENU_MAKE_UNIQUE = 3,
  426. OBJ_MENU_SAVE = 4,
  427. OBJ_MENU_COPY = 5,
  428. OBJ_MENU_PASTE = 6,
  429. OBJ_MENU_NEW_SCRIPT = 7,
  430. OBJ_MENU_SHOW_IN_FILE_SYSTEM = 8,
  431. TYPE_BASE_ID = 100,
  432. CONVERT_BASE_ID = 1000
  433. };
  434. Button *assign;
  435. TextureRect *preview;
  436. Button *edit;
  437. PopupMenu *menu;
  438. EditorFileDialog *file;
  439. Vector<String> inheritors_array;
  440. EditorInspector *sub_inspector;
  441. VBoxContainer *sub_inspector_vbox;
  442. bool use_sub_inspector;
  443. bool dropping;
  444. String base_type;
  445. SceneTreeDialog *scene_tree;
  446. void _file_selected(const String &p_path);
  447. void _menu_option(int p_which);
  448. void _resource_preview(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, ObjectID p_obj);
  449. void _resource_selected();
  450. void _viewport_selected(const NodePath &p_path);
  451. void _update_menu_items();
  452. void _update_menu();
  453. void _sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool);
  454. void _sub_inspector_resource_selected(const RES &p_resource, const String &p_property);
  455. void _sub_inspector_object_id_selected(int p_id);
  456. void _button_draw();
  457. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  458. bool _is_drop_valid(const Dictionary &p_drag_data) const;
  459. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  460. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  461. void _button_input(const Ref<InputEvent> &p_event);
  462. void _open_editor_pressed();
  463. protected:
  464. static void _bind_methods();
  465. void _notification(int p_what);
  466. public:
  467. virtual void update_property();
  468. void setup(const String &p_base_type);
  469. void collapse_all_folding();
  470. void expand_all_folding();
  471. void set_use_sub_inspector(bool p_enable);
  472. EditorPropertyResource();
  473. };
  474. ///////////////////////////////////////////////////
  475. /// \brief The EditorInspectorDefaultPlugin class
  476. ///
  477. class EditorInspectorDefaultPlugin : public EditorInspectorPlugin {
  478. GDCLASS(EditorInspectorDefaultPlugin, EditorInspectorPlugin)
  479. public:
  480. virtual bool can_handle(Object *p_object);
  481. virtual void parse_begin(Object *p_object);
  482. 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);
  483. virtual void parse_end();
  484. };
  485. #endif // EDITOR_PROPERTIES_H