summaryrefslogtreecommitdiff
path: root/editor/editor_properties.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r--editor/editor_properties.cpp179
1 files changed, 137 insertions, 42 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 3439133809..de948acc71 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -108,6 +108,7 @@ void EditorPropertyMultilineText::_open_big_text() {
if (!big_text_dialog) {
big_text = memnew(TextEdit);
big_text->connect("text_changed", this, "_big_text_changed");
+ big_text->set_wrap_enabled(true);
big_text_dialog = memnew(AcceptDialog);
big_text_dialog->add_child(big_text);
big_text_dialog->set_title("Edit Text:");
@@ -152,6 +153,7 @@ EditorPropertyMultilineText::EditorPropertyMultilineText() {
set_bottom_editor(hb);
text = memnew(TextEdit);
text->connect("text_changed", this, "_text_changed");
+ text->set_wrap_enabled(true);
add_focusable(text);
hb->add_child(text);
text->set_h_size_flags(SIZE_EXPAND_FILL);
@@ -231,7 +233,7 @@ void EditorPropertyPath::_path_pressed() {
dialog->set_mode(EditorFileDialog::MODE_OPEN_DIR);
dialog->set_current_dir(full_path);
} else {
- dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
+ dialog->set_mode(save_mode ? EditorFileDialog::MODE_SAVE_FILE : EditorFileDialog::MODE_OPEN_FILE);
for (int i = 0; i < extensions.size(); i++) {
String e = extensions[i].strip_edges();
if (e != String()) {
@@ -258,6 +260,11 @@ void EditorPropertyPath::setup(const Vector<String> &p_extensions, bool p_folder
global = p_global;
}
+void EditorPropertyPath::set_save_mode() {
+
+ save_mode = true;
+}
+
void EditorPropertyPath::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
@@ -294,6 +301,7 @@ EditorPropertyPath::EditorPropertyPath() {
path_edit->connect("pressed", this, "_path_pressed");
folder = false;
global = false;
+ save_mode = false;
}
///////////////////// CLASS NAME /////////////////////////
@@ -475,33 +483,16 @@ EditorPropertyCheck::EditorPropertyCheck() {
void EditorPropertyEnum::_option_selected(int p_which) {
- String text = options->get_item_text(p_which);
- Vector<String> text_split = text.split(":");
- if (text_split.size() == 1) {
- emit_signal("property_changed", get_edited_property(), p_which);
- return;
- }
- String name = text_split[1];
- emit_signal("property_changed", get_edited_property(), name.to_int());
+ int val = options->get_item_metadata(p_which);
+ emit_signal("property_changed", get_edited_property(), val);
}
void EditorPropertyEnum::update_property() {
int which = get_edited_object()->get(get_edited_property());
- if (which == 0) {
- options->select(which);
- return;
- }
for (int i = 0; i < options->get_item_count(); i++) {
- String text = options->get_item_text(i);
- Vector<String> text_split = text.split(":");
- if (text_split.size() == 1) {
- options->select(which);
- return;
- }
- String name = text_split[1];
- if (itos(which) == name) {
+ if (which == (int)options->get_item_metadata(i)) {
options->select(i);
return;
}
@@ -509,8 +500,15 @@ void EditorPropertyEnum::update_property() {
}
void EditorPropertyEnum::setup(const Vector<String> &p_options) {
+
+ int current_val = 0;
for (int i = 0; i < p_options.size(); i++) {
- options->add_item(p_options[i], i);
+ Vector<String> text_split = p_options[i].split(":");
+ if (text_split.size() != 1)
+ current_val = text_split[1].to_int();
+ options->add_item(text_split[0]);
+ options->set_item_metadata(i, current_val);
+ current_val += 1;
}
}
@@ -817,10 +815,10 @@ void EditorPropertyInteger::_bind_methods() {
ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyInteger::_value_changed);
}
-void EditorPropertyInteger::setup(int p_min, int p_max, bool p_allow_greater, bool p_allow_lesser) {
+void EditorPropertyInteger::setup(int p_min, int p_max, int p_step, bool p_allow_greater, bool p_allow_lesser) {
spin->set_min(p_min);
spin->set_max(p_max);
- spin->set_step(1);
+ spin->set_step(p_step);
spin->set_allow_greater(p_allow_greater);
spin->set_allow_lesser(p_allow_lesser);
}
@@ -1183,21 +1181,39 @@ void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool
}
EditorPropertyRect2::EditorPropertyRect2() {
- VBoxContainer *vb = memnew(VBoxContainer);
- add_child(vb);
+
+ bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
+
+ BoxContainer *bc;
+
+ if (horizontal) {
+ bc = memnew(HBoxContainer);
+ add_child(bc);
+ set_bottom_editor(bc);
+ } else {
+ bc = memnew(VBoxContainer);
+ add_child(bc);
+ }
+
static const char *desc[4] = { "x", "y", "w", "h" };
for (int i = 0; i < 4; i++) {
spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]);
spin[i]->set_flat(true);
-
- vb->add_child(spin[i]);
+ bc->add_child(spin[i]);
add_focusable(spin[i]);
spin[i]->connect("value_changed", this, "_value_changed");
+ if (horizontal) {
+ spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
+ }
+ }
+
+ if (!horizontal) {
+ set_label_reference(spin[0]); //show text and buttons around this
}
- set_label_reference(spin[0]); //show text and buttons around this
setting = false;
}
+
///////////////////// VECTOR3 /////////////////////////
void EditorPropertyVector3::_value_changed(double val) {
@@ -1245,7 +1261,7 @@ void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, boo
}
EditorPropertyVector3::EditorPropertyVector3() {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector3_editing");
+ bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
BoxContainer *bc;
@@ -1326,7 +1342,7 @@ void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool
EditorPropertyPlane::EditorPropertyPlane() {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector3_editing");
+ bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
BoxContainer *bc;
@@ -1407,7 +1423,7 @@ void EditorPropertyQuat::setup(double p_min, double p_max, double p_step, bool p
}
EditorPropertyQuat::EditorPropertyQuat() {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector3_editing");
+ bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
BoxContainer *bc;
@@ -1792,9 +1808,26 @@ void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {
NodePath path = p_path;
Node *base_node = Object::cast_to<Node>(get_edited_object());
- if (base_node == NULL && get_edited_object()->has_method("get_root_path")) {
+ if (!base_node) {
+ //try a base node within history
+ if (EditorNode::get_singleton()->get_editor_history()->get_path_size() > 0) {
+ Object *base = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_path_object(0));
+ if (base) {
+ base_node = Object::cast_to<Node>(base);
+ }
+ }
+ }
+
+ if (!base_node && get_edited_object()->has_method("get_root_path")) {
base_node = get_edited_object()->call("get_root_path");
}
+
+ if (!base_node && Object::cast_to<Reference>(get_edited_object())) {
+ Node *to_node = get_node(p_path);
+ ERR_FAIL_COND(!to_node);
+ path = get_tree()->get_edited_scene_root()->get_path_to(to_node);
+ }
+
if (base_node) { // for AnimationTrackKeyEdit
path = base_node->get_path().rel_path_to(p_path);
}
@@ -1850,6 +1883,12 @@ void EditorPropertyNodePath::update_property() {
Node *target_node = base_node->get_node(p);
ERR_FAIL_COND(!target_node);
+ if (String(target_node->get_name()).find("@") != -1) {
+ assign->set_icon(Ref<Texture>());
+ assign->set_text(p);
+ return;
+ }
+
assign->set_text(target_node->get_name());
assign->set_icon(EditorNode::get_singleton()->get_object_icon(target_node, "Node"));
}
@@ -1995,6 +2034,13 @@ void EditorPropertyResource::_menu_option(int p_which) {
} break;
+ case OBJ_MENU_SAVE: {
+ RES res = get_edited_object()->get(get_edited_property());
+ if (res.is_null())
+ return;
+ EditorNode::get_singleton()->save_resource(res);
+ } break;
+
case OBJ_MENU_COPY: {
RES res = get_edited_object()->get(get_edited_property());
@@ -2048,8 +2094,22 @@ void EditorPropertyResource::_menu_option(int p_which) {
if (intype == "ViewportTexture") {
+ Resource *r = Object::cast_to<Resource>(get_edited_object());
+ if (r && r->get_path().is_resource_file()) {
+ EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on resources saved as a file.\nResource needs to belong to a scene."));
+ return;
+ }
+
+ if (r && !r->is_local_to_scene()) {
+ EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on this resource because it's not set as local to scene.\nPlease switch on the 'local to scene' property on it (and all resources containing it up to a node)."));
+ return;
+ }
+
if (!scene_tree) {
scene_tree = memnew(SceneTreeDialog);
+ Vector<StringName> valid_types;
+ valid_types.push_back("Viewport");
+ scene_tree->get_scene_tree()->set_valid_types(valid_types);
scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
add_child(scene_tree);
scene_tree->connect("selected", this, "_viewport_selected");
@@ -2082,12 +2142,18 @@ void EditorPropertyResource::_menu_option(int p_which) {
}
}
-void EditorPropertyResource::_resource_preview(const String &p_path, const Ref<Texture> &p_preview, ObjectID p_obj) {
+void EditorPropertyResource::_resource_preview(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, ObjectID p_obj) {
RES p = get_edited_object()->get(get_edited_property());
if (p.is_valid() && p->get_instance_id() == p_obj) {
+ String type = p->get_class_name();
+
+ if (ClassDB::is_parent_class(type, "Script")) {
+ assign->set_text(p->get_path().get_file());
+ return;
+ }
+
if (p_preview.is_valid()) {
- String type = p->get_class_name();
preview->set_margin(MARGIN_LEFT, assign->get_icon()->get_width() + assign->get_stylebox("normal")->get_default_margin(MARGIN_LEFT) + get_constant("hseparation", "Button"));
if (type == "GradientTexture") {
preview->set_stretch_mode(TextureRect::STRETCH_SCALE);
@@ -2104,7 +2170,8 @@ void EditorPropertyResource::_resource_preview(const String &p_path, const Ref<T
}
}
-void EditorPropertyResource::_update_menu() {
+void EditorPropertyResource::_update_menu_items() {
+
//////////////////// UPDATE MENU //////////////////////////
RES res = get_edited_object()->get(get_edited_property());
@@ -2191,10 +2258,11 @@ void EditorPropertyResource::_update_menu() {
menu->add_icon_item(get_icon("Edit", "EditorIcons"), TTR("Edit"), OBJ_MENU_EDIT);
menu->add_icon_item(get_icon("Clear", "EditorIcons"), TTR("Clear"), OBJ_MENU_CLEAR);
menu->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
+ menu->add_icon_item(get_icon("Save", "EditorIcons"), TTR("Save"), OBJ_MENU_SAVE);
RES r = res;
if (r.is_valid() && r->get_path().is_resource_file()) {
menu->add_separator();
- menu->add_item(TTR("Show in File System"), OBJ_MENU_SHOW_IN_FILE_SYSTEM);
+ menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM);
}
} else {
}
@@ -2246,6 +2314,11 @@ void EditorPropertyResource::_update_menu() {
menu->add_icon_item(icon, vformat(TTR("Convert To %s"), what), CONVERT_BASE_ID + i);
}
}
+}
+
+void EditorPropertyResource::_update_menu() {
+
+ _update_menu_items();
Rect2 gt = edit->get_global_rect();
menu->set_as_minsize();
@@ -2270,6 +2343,20 @@ void EditorPropertyResource::_sub_inspector_object_id_selected(int p_id) {
emit_signal("object_id_selected", get_edited_property(), p_id);
}
+void EditorPropertyResource::_button_input(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_valid()) {
+ if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
+ _update_menu_items();
+ Vector2 pos = mb->get_global_position();
+ //pos = assign->get_global_transform().xform(pos);
+ menu->set_as_minsize();
+ menu->set_global_position(pos);
+ menu->popup();
+ }
+ }
+}
+
void EditorPropertyResource::_open_editor_pressed() {
RES res = get_edited_object()->get(get_edited_property());
if (res.is_valid()) {
@@ -2354,7 +2441,7 @@ void EditorPropertyResource::update_property() {
if (res->get_name() != String()) {
assign->set_text(res->get_name());
} else if (res->get_path().is_resource_file()) {
- assign->set_text(res->get_name());
+ assign->set_text(res->get_path().get_file());
assign->set_tooltip(res->get_path());
} else {
assign->set_text(res->get_class());
@@ -2557,6 +2644,7 @@ void EditorPropertyResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("drop_data_fw"), &EditorPropertyResource::drop_data_fw);
ClassDB::bind_method(D_METHOD("_button_draw"), &EditorPropertyResource::_button_draw);
ClassDB::bind_method(D_METHOD("_open_editor_pressed"), &EditorPropertyResource::_open_editor_pressed);
+ ClassDB::bind_method(D_METHOD("_button_input"), &EditorPropertyResource::_button_input);
}
EditorPropertyResource::EditorPropertyResource() {
@@ -2583,6 +2671,7 @@ EditorPropertyResource::EditorPropertyResource() {
preview->set_margin(MARGIN_BOTTOM, -1);
preview->set_margin(MARGIN_RIGHT, -1);
assign->add_child(preview);
+ assign->connect("gui_input", this, "_button_input");
menu = memnew(PopupMenu);
add_child(menu);
@@ -2591,6 +2680,7 @@ EditorPropertyResource::EditorPropertyResource() {
menu->connect("id_pressed", this, "_menu_option");
edit->connect("pressed", this, "_update_menu");
hbc->add_child(edit);
+ edit->connect("gui_input", this, "_button_input");
file = NULL;
scene_tree = NULL;
@@ -2636,7 +2726,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} else if (p_hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || p_hint == PROPERTY_HINT_LAYERS_2D_RENDER || p_hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || p_hint == PROPERTY_HINT_LAYERS_3D_RENDER) {
- EditorPropertyLayers::LayerType lt;
+ EditorPropertyLayers::LayerType lt = EditorPropertyLayers::LAYER_RENDER_2D;
switch (p_hint) {
case PROPERTY_HINT_LAYERS_2D_RENDER:
lt = EditorPropertyLayers::LAYER_RENDER_2D;
@@ -2663,7 +2753,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} else {
EditorPropertyInteger *editor = memnew(EditorPropertyInteger);
- int min = 0, max = 65535;
+ int min = 0, max = 65535, step = 1;
bool greater = true, lesser = true;
if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
@@ -2671,6 +2761,11 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
lesser = false;
min = p_hint_text.get_slice(",", 0).to_int();
max = p_hint_text.get_slice(",", 1).to_int();
+
+ if (p_hint_text.get_slice_count(",") >= 3) {
+ step = p_hint_text.get_slice(",", 2).to_int();
+ }
+
for (int i = 2; i < p_hint_text.get_slice_count(","); i++) {
String slice = p_hint_text.get_slice(",", i).strip_edges();
if (slice == "or_greater") {
@@ -2682,7 +2777,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
}
- editor->setup(min, max, greater, lesser);
+ editor->setup(min, max, step, greater, lesser);
add_property_editor(p_path, editor);
}
@@ -3007,7 +3102,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break;
case Variant::ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
- editor->setup(Variant::ARRAY);
+ editor->setup(Variant::ARRAY, p_hint_text);
add_property_editor(p_path, editor);
} break;
case Variant::POOL_BYTE_ARRAY: {