1 /*************************************************************************/
2 /*  property_editor.h                                                    */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 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 
31 #ifndef PROPERTY_EDITOR_H
32 #define PROPERTY_EDITOR_H
33 
34 #include "editor/editor_file_dialog.h"
35 #include "editor/scene_tree_editor.h"
36 #include "scene/gui/button.h"
37 #include "scene/gui/check_box.h"
38 #include "scene/gui/check_button.h"
39 #include "scene/gui/color_picker.h"
40 #include "scene/gui/dialogs.h"
41 #include "scene/gui/grid_container.h"
42 #include "scene/gui/label.h"
43 #include "scene/gui/menu_button.h"
44 #include "scene/gui/split_container.h"
45 #include "scene/gui/text_edit.h"
46 #include "scene/gui/texture_rect.h"
47 #include "scene/gui/tree.h"
48 
49 class PropertyValueEvaluator;
50 class CreateDialog;
51 class PropertySelector;
52 
53 class EditorResourceConversionPlugin : public Reference {
54 
55 	GDCLASS(EditorResourceConversionPlugin, Reference);
56 
57 protected:
58 	static void _bind_methods();
59 
60 public:
61 	virtual String converts_to() const;
62 	virtual bool handles(const Ref<Resource> &p_resource) const;
63 	virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const;
64 };
65 
66 class CustomPropertyEditor : public Popup {
67 
68 	GDCLASS(CustomPropertyEditor, Popup);
69 
70 	enum {
71 		MAX_VALUE_EDITORS = 12,
72 		MAX_ACTION_BUTTONS = 5,
73 		OBJ_MENU_LOAD = 0,
74 		OBJ_MENU_EDIT = 1,
75 		OBJ_MENU_CLEAR = 2,
76 		OBJ_MENU_MAKE_UNIQUE = 3,
77 		OBJ_MENU_COPY = 4,
78 		OBJ_MENU_PASTE = 5,
79 		OBJ_MENU_NEW_SCRIPT = 6,
80 		OBJ_MENU_EXTEND_SCRIPT = 7,
81 		OBJ_MENU_SHOW_IN_FILE_SYSTEM = 8,
82 		TYPE_BASE_ID = 100,
83 		CONVERT_BASE_ID = 1000
84 	};
85 
86 	enum {
87 		EASING_LINEAR,
88 		EASING_EASE_IN,
89 		EASING_EASE_OUT,
90 		EASING_ZERO,
91 		EASING_IN_OUT,
92 		EASING_OUT_IN
93 	};
94 
95 	PopupMenu *menu;
96 	SceneTreeDialog *scene_tree;
97 	EditorFileDialog *file;
98 	ConfirmationDialog *error;
99 	String name;
100 	Variant::Type type;
101 	Variant v;
102 	List<String> field_names;
103 	int hint;
104 	String hint_text;
105 	LineEdit *value_editor[MAX_VALUE_EDITORS];
106 	int focused_value_editor;
107 	Label *value_label[MAX_VALUE_EDITORS];
108 	HScrollBar *scroll[4];
109 	Button *action_buttons[MAX_ACTION_BUTTONS];
110 	MenuButton *type_button;
111 	Vector<String> inheritors_array;
112 	TextureRect *texture_preview;
113 	ColorPicker *color_picker;
114 	TextEdit *text_edit;
115 	bool read_only;
116 	bool picking_viewport;
117 	GridContainer *checks20gc;
118 	CheckBox *checks20[20];
119 	SpinBox *spinbox;
120 	HSlider *slider;
121 
122 	Control *easing_draw;
123 	CreateDialog *create_dialog;
124 	PropertySelector *property_select;
125 
126 	Object *owner;
127 
128 	bool updating;
129 
130 	PropertyValueEvaluator *evaluator;
131 
132 	void _text_edit_changed();
133 	void _file_selected(String p_file);
134 	void _modified(String p_string);
135 
136 	real_t _parse_real_expression(String text);
137 
138 	void _range_modified(double p_value);
139 	void _focus_enter();
140 	void _focus_exit();
141 	void _action_pressed(int p_which);
142 	void _type_create_selected(int p_idx);
143 	void _create_dialog_callback();
144 	void _create_selected_property(const String &p_prop);
145 
146 	void _color_changed(const Color &p_color);
147 	void _draw_easing();
148 	void _menu_option(int p_which);
149 
150 	void _drag_easing(const Ref<InputEvent> &p_ev);
151 
152 	void _node_path_selected(NodePath p_path);
153 	void show_value_editors(int p_amount);
154 	void config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings);
155 	void config_action_buttons(const List<String> &p_strings);
156 
157 	void _emit_changed_whole_or_field();
158 
159 protected:
160 	void _notification(int p_what);
161 	static void _bind_methods();
162 
163 public:
164 	void hide_menu();
165 
166 	Variant get_variant() const;
167 	String get_name() const;
168 
set_read_only(bool p_read_only)169 	void set_read_only(bool p_read_only) { read_only = p_read_only; }
170 
171 	bool edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text);
172 
173 	CustomPropertyEditor();
174 };
175 
176 #endif
177