diff options
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r-- | editor/editor_properties.cpp | 191 |
1 files changed, 121 insertions, 70 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 3c3df6b8ef..3730807243 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); @@ -475,33 +477,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 +494,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; } } @@ -651,6 +643,7 @@ public: int h = bsize * 2 + 1; int vofs = (rect.size.height - h) / 2; + Color color = get_color("highlight_color", "Editor"); for (int i = 0; i < 2; i++) { Point2 ofs(4, vofs); @@ -667,7 +660,8 @@ public: uint32_t idx = i * 10 + j; bool on = value & (1 << idx); Rect2 rect = Rect2(o, Size2(bsize, bsize)); - draw_rect(rect, Color(0, 0, 0, on ? 0.8 : 0.3)); + color.a = on ? 0.6 : 0.2; + draw_rect(rect, color); flag_rects.push_back(rect); } } @@ -815,10 +809,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); } @@ -844,18 +838,11 @@ void EditorPropertyObjectID::update_property() { if (type == "") type = "Object"; - String icon_type = type; - if (has_icon(icon_type, "EditorIcons")) { - type = icon_type; - } else { - type = "Object"; - } - ObjectID id = get_edited_object()->get(get_edited_property()); if (id != 0) { edit->set_text(type + " ID: " + itos(id)); edit->set_disabled(false); - edit->set_icon(get_icon(icon_type, "EditorIcons")); + edit->set_icon(EditorNode::get_singleton()->get_class_icon(type)); } else { edit->set_text(TTR("[Empty]")); edit->set_disabled(true); @@ -1188,21 +1175,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) { @@ -1250,7 +1255,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; @@ -1331,7 +1336,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; @@ -1412,7 +1417,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; @@ -1797,8 +1802,13 @@ 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")) { - base_node = get_edited_object()->call("get_root_path"); + if (base_node == NULL) { + if (Object::cast_to<Resource>(get_edited_object())) { + Node *to_node = get_node(p_path); + path = get_tree()->get_edited_scene_root()->get_path_to(to_node); + } else if (get_edited_object()->has_method("get_root_path")) { + base_node = get_edited_object()->call("get_root_path"); + } } if (base_node) { // for AnimationTrackKeyEdit path = base_node->get_path().rel_path_to(p_path); @@ -1855,15 +1865,14 @@ void EditorPropertyNodePath::update_property() { Node *target_node = base_node->get_node(p); ERR_FAIL_COND(!target_node); - assign->set_text(target_node->get_name()); - - Ref<Texture> icon; - if (has_icon(target_node->get_class(), "EditorIcons")) - icon = get_icon(target_node->get_class(), "EditorIcons"); - else - icon = get_icon("Node", "EditorIcons"); + if (String(target_node->get_name()).find("@") != -1) { + assign->set_icon(Ref<Texture>()); + assign->set_text(p); + return; + } - assign->set_icon(icon); + assign->set_text(target_node->get_name()); + assign->set_icon(EditorNode::get_singleton()->get_object_icon(target_node, "Node")); } void EditorPropertyNodePath::setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types) { @@ -1903,7 +1912,7 @@ EditorPropertyNodePath::EditorPropertyNodePath() { clear->connect("pressed", this, "_node_clear"); hbc->add_child(clear); - scene_tree = NULL; //do not allocate unnecesarily + scene_tree = NULL; //do not allocate unnecessarily } ////////////// RESOURCE ////////////////////// @@ -2060,8 +2069,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"); @@ -2094,12 +2117,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); @@ -2116,7 +2145,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()); @@ -2206,7 +2236,7 @@ void EditorPropertyResource::_update_menu() { 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 { } @@ -2258,6 +2288,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(); @@ -2282,6 +2317,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()) { @@ -2361,18 +2410,12 @@ void EditorPropertyResource::update_property() { assign->set_text(TTR("[empty]")); } else { - Ref<Texture> icon; - if (has_icon(res->get_class(), "EditorIcons")) - icon = get_icon(res->get_class(), "EditorIcons"); - else - icon = get_icon("Node", "EditorIcons"); - - assign->set_icon(icon); + assign->set_icon(EditorNode::get_singleton()->get_object_icon(res.operator->(), "Node")); 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()); @@ -2575,6 +2618,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() { @@ -2601,6 +2645,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); @@ -2609,6 +2654,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; @@ -2654,7 +2700,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; @@ -2668,7 +2714,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ case PROPERTY_HINT_LAYERS_3D_PHYSICS: lt = EditorPropertyLayers::LAYER_PHYSICS_3D; break; - default: {} //compiler could be smarter here and realize this cant happen + default: {} //compiler could be smarter here and realize this can't happen } EditorPropertyLayers *editor = memnew(EditorPropertyLayers); editor->setup(lt); @@ -2681,14 +2727,19 @@ 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) { - greater = false; //if using ranged, asume false by default + greater = false; //if using ranged, assume false by default 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") { @@ -2700,7 +2751,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); } @@ -2733,7 +2784,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ bool greater = true, lesser = true; if ((p_hint == PROPERTY_HINT_RANGE || p_hint == PROPERTY_HINT_EXP_RANGE) && p_hint_text.get_slice_count(",") >= 2) { - greater = false; //if using ranged, asume false by default + greater = false; //if using ranged, assume false by default lesser = false; min = p_hint_text.get_slice(",", 0).to_double(); max = p_hint_text.get_slice(",", 1).to_double(); @@ -3066,7 +3117,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ default: {} } - return false; //can be overriden, although it will most likely be last anyway + return false; //can be overridden, although it will most likely be last anyway } void EditorInspectorDefaultPlugin::parse_end() { |