summaryrefslogtreecommitdiff
path: root/editor/property_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/property_editor.cpp')
-rw-r--r--editor/property_editor.cpp91
1 files changed, 72 insertions, 19 deletions
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp
index 0777b6950e..0ec83d8a36 100644
--- a/editor/property_editor.cpp
+++ b/editor/property_editor.cpp
@@ -38,6 +38,7 @@
#include "editor_node.h"
#include "editor_settings.h"
#include "io/image_loader.h"
+#include "io/marshalls.h"
#include "io/resource_loader.h"
#include "multi_node_edit.h"
#include "os/input.h"
@@ -434,13 +435,13 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
} else if (hint == PROPERTY_HINT_EXP_EASING) {
easing_draw->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5 * EDSCALE);
- easing_draw->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 5 * EDSCALE);
+ easing_draw->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5 * EDSCALE);
easing_draw->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 5 * EDSCALE);
- easing_draw->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 30 * EDSCALE);
+ easing_draw->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -30 * EDSCALE);
type_button->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 3 * EDSCALE);
- type_button->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 3 * EDSCALE);
- type_button->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, 25 * EDSCALE);
- type_button->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 7 * EDSCALE);
+ type_button->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -3 * EDSCALE);
+ type_button->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -25 * EDSCALE);
+ type_button->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -7 * EDSCALE);
type_button->set_text(TTR("Preset.."));
type_button->get_popup()->clear();
type_button->get_popup()->add_item(TTR("Linear"), EASING_LINEAR);
@@ -523,8 +524,8 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
action_buttons[0]->set_anchor(MARGIN_TOP, ANCHOR_END);
action_buttons[0]->set_anchor(MARGIN_RIGHT, ANCHOR_END);
action_buttons[0]->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
- action_buttons[0]->set_begin(Point2(70 * EDSCALE, button_margin - 5 * EDSCALE));
- action_buttons[0]->set_end(Point2(margin, margin));
+ action_buttons[0]->set_begin(Point2(-70 * EDSCALE, -button_margin + 5 * EDSCALE));
+ action_buttons[0]->set_end(Point2(-margin, -margin));
action_buttons[0]->set_text(TTR("Close"));
action_buttons[0]->show();
@@ -862,6 +863,10 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
List<String> names;
names.push_back(TTR("Assign"));
names.push_back(TTR("Clear"));
+
+ if (owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && owner->cast_to<Node>()->has_node(v))
+ names.push_back(TTR("Select Node"));
+
config_action_buttons(names);
} break;
@@ -1269,7 +1274,18 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
v = NodePath();
emit_signal("variant_changed");
hide();
+ } else if (p_which == 2) {
+
+ if (owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && owner->cast_to<Node>()->has_node(v)) {
+
+ Node *target_node = owner->cast_to<Node>()->get_node(v);
+ EditorNode::get_singleton()->get_editor_selection()->clear();
+ EditorNode::get_singleton()->get_scene_tree_dock()->set_selected(target_node);
+ }
+
+ hide();
}
+
} break;
case Variant::OBJECT: {
@@ -2305,7 +2321,15 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p
} break;
case Variant::OBJECT: {
- if (obj->get(p_name).get_type() == Variant::NIL || obj->get(p_name).operator RefPtr().is_null()) {
+ Ref<EncodedObjectAsID> encoded = obj->get(p_name); //for debugger and remote tools
+
+ if (encoded.is_valid()) {
+
+ p_item->set_text(1, "Object: " + itos(encoded->get_object_id()));
+ p_item->set_icon(1, Ref<Texture>());
+ p_item->set_custom_as_button(1, true);
+
+ } else if (obj->get(p_name).get_type() == Variant::NIL || obj->get(p_name).operator RefPtr().is_null()) {
p_item->set_text(1, "<null>");
p_item->set_icon(1, Ref<Texture>());
p_item->set_custom_as_button(1, false);
@@ -2459,11 +2483,14 @@ bool PropertyEditor::_is_drop_valid(const Dictionary &p_drag_data, const Diction
String allowed_type = d["hint_text"];
+ print_line("allowed type " + allowed_type);
+
Dictionary drag_data = p_drag_data;
if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
Ref<Resource> res = drag_data["resource"];
for (int i = 0; i < allowed_type.get_slice_count(","); i++) {
String at = allowed_type.get_slice(",", i).strip_edges();
+ print_line("RES vs " + at);
if (res.is_valid() && ClassDB::is_parent_class(res->get_class(), at)) {
return true;
}
@@ -2474,13 +2501,18 @@ bool PropertyEditor::_is_drop_valid(const Dictionary &p_drag_data, const Diction
Vector<String> files = drag_data["files"];
+ print_line("fileS: " + String(Variant(files)));
if (files.size() == 1) {
String file = files[0];
String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
+
+ print_line("file: " + file);
+ print_line("type: " + ftype);
if (ftype != "") {
for (int i = 0; i < allowed_type.get_slice_count(","); i++) {
String at = allowed_type.get_slice(",", i).strip_edges();
+ print_line("FILE vs " + at);
if (ClassDB::is_parent_class(ftype, at)) {
return true;
}
@@ -3587,7 +3619,16 @@ void PropertyEditor::update_tree() {
RES res = obj->get(p.name).operator RefPtr();
- if (obj->get(p.name).get_type() == Variant::NIL || res.is_null()) {
+ Ref<EncodedObjectAsID> encoded = obj->get(p.name); //for debugger and remote tools
+
+ if (encoded.is_valid()) {
+
+ item->set_text(1, "Object: " + itos(encoded->get_object_id()));
+ item->set_icon(1, Ref<Texture>());
+ item->set_custom_as_button(1, true);
+ item->set_editable(1, true);
+
+ } else if (obj->get(p.name).get_type() == Variant::NIL || res.is_null()) {
item->set_text(1, "<null>");
item->set_icon(1, Ref<Texture>());
item->set_custom_as_button(1, false);
@@ -3736,6 +3777,10 @@ void PropertyEditor::_item_selected() {
selected_property = item->get_metadata(1);
}
+void PropertyEditor::_item_rmb_edited() {
+ _custom_editor_request(true);
+}
+
void PropertyEditor::_edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field) {
if (autoclear) {
@@ -3912,6 +3957,13 @@ void PropertyEditor::_item_edited() {
if (!item->is_custom_set_as_button(1))
break;
+ Ref<EncodedObjectAsID> encoded = obj->get(name); //for debugger and remote tools
+
+ if (encoded.is_valid()) {
+
+ emit_signal("object_id_selected", encoded->get_object_id());
+ }
+
RES res = obj->get(name);
if (res.is_valid()) {
emit_signal("resource_selected", res.get_ref_ptr(), name);
@@ -4164,9 +4216,9 @@ void PropertyEditor::set_keying(bool p_active) {
update_tree();
}
-void PropertyEditor::_draw_flags(Object *t, const Rect2 &p_rect) {
+void PropertyEditor::_draw_flags(Object *p_object, const Rect2 &p_rect) {
- TreeItem *ti = t->cast_to<TreeItem>();
+ TreeItem *ti = p_object->cast_to<TreeItem>();
if (!ti)
return;
@@ -4232,6 +4284,7 @@ void PropertyEditor::_bind_methods() {
ClassDB::bind_method("_item_edited", &PropertyEditor::_item_edited);
ClassDB::bind_method("_item_selected", &PropertyEditor::_item_selected);
+ ClassDB::bind_method("_item_rmb_edited", &PropertyEditor::_item_rmb_edited);
ClassDB::bind_method("_item_folded", &PropertyEditor::_item_folded);
ClassDB::bind_method("_custom_editor_request", &PropertyEditor::_custom_editor_request);
ClassDB::bind_method("_custom_editor_edited", &PropertyEditor::_custom_editor_edited);
@@ -4386,6 +4439,7 @@ PropertyEditor::PropertyEditor() {
add_child(tree);
tree->connect("item_edited", this, "_item_edited", varray(), CONNECT_DEFERRED);
+ tree->connect("item_rmb_edited", this, "_item_rmb_edited");
tree->connect("cell_selected", this, "_item_selected");
tree->connect("item_collapsed", this, "_item_folded");
@@ -4745,20 +4799,20 @@ double PropertyValueEvaluator::eval(const String &p_text) {
return _default_eval(p_text);
}
- ScriptInstance *script_instance = script->instance_create(this);
+ Object dummy;
+ ScriptInstance *script_instance = script->instance_create(&dummy);
if (!script_instance)
return _default_eval(p_text);
Variant::CallError call_err;
- script_instance->call("set_this", obj);
- double result = script_instance->call("e", NULL, 0, call_err);
+ Variant arg = obj;
+ const Variant *args[] = { &arg };
+ double result = script_instance->call("eval", args, 1, call_err);
if (call_err.error == Variant::CallError::CALL_OK) {
return result;
}
print_line("[PropertyValueEvaluator]: Error eval! Error code: " + itos(call_err.error));
- memdelete(script_instance);
-
return _default_eval(p_text);
}
@@ -4767,9 +4821,8 @@ void PropertyValueEvaluator::edit(Object *p_obj) {
}
String PropertyValueEvaluator::_build_script(const String &p_text) {
- String script_text = "tool\nvar this\nfunc set_this(p_this):\n\tthis=p_this\nfunc e():\n\treturn ";
- script_text += p_text.strip_edges();
- script_text += "\n";
+ String script_text =
+ "tool\nextends Object\nfunc eval(s):\n\tself = s\n\treturn " + p_text.strip_edges() + "\n";
return script_text;
}