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.cpp75
1 files changed, 36 insertions, 39 deletions
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp
index 847af0f2c2..07312e42b4 100644
--- a/editor/property_editor.cpp
+++ b/editor/property_editor.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -251,7 +251,7 @@ void CustomPropertyEditor::_menu_option(int p_which) {
emit_signal("variant_changed");
break;
}
- ERR_FAIL_COND(inheritors_array.empty());
+ ERR_FAIL_COND(inheritors_array.is_empty());
String intype = inheritors_array[p_which - TYPE_BASE_ID];
@@ -262,7 +262,7 @@ void CustomPropertyEditor::_menu_option(int p_which) {
return;
}
- Object *obj = ClassDB::instance(intype);
+ Variant obj = ClassDB::instance(intype);
if (!obj) {
if (ScriptServer::is_global_class(intype)) {
@@ -280,7 +280,7 @@ void CustomPropertyEditor::_menu_option(int p_which) {
res->call("set_instance_base_type", owner->get_class());
}
- v = res;
+ v = obj;
emit_signal("variant_changed");
} break;
@@ -367,18 +367,18 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
int c = hint_text.get_slice_count(",");
float min = 0, max = 100, step = type == Variant::FLOAT ? .01 : 1;
if (c >= 1) {
- if (!hint_text.get_slice(",", 0).empty()) {
+ if (!hint_text.get_slice(",", 0).is_empty()) {
min = hint_text.get_slice(",", 0).to_float();
}
}
if (c >= 2) {
- if (!hint_text.get_slice(",", 1).empty()) {
+ if (!hint_text.get_slice(",", 1).is_empty()) {
max = hint_text.get_slice(",", 1).to_float();
}
}
if (c >= 3) {
- if (!hint_text.get_slice(",", 2).empty()) {
+ if (!hint_text.get_slice(",", 2).is_empty()) {
step = hint_text.get_slice(",", 2).to_float();
}
}
@@ -456,14 +456,14 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
set_size(Vector2(4, 4) * EDSCALE + checks20gc->get_position() + checks20gc->get_size());
} else if (hint == PROPERTY_HINT_EXP_EASING) {
- easing_draw->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, 5 * EDSCALE);
- easing_draw->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -5 * EDSCALE);
- easing_draw->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 5 * EDSCALE);
- easing_draw->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -30 * EDSCALE);
- type_button->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, 3 * EDSCALE);
- type_button->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -3 * EDSCALE);
- type_button->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_END, -25 * EDSCALE);
- type_button->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -7 * EDSCALE);
+ easing_draw->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 5 * EDSCALE);
+ easing_draw->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -5 * EDSCALE);
+ easing_draw->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_BEGIN, 5 * EDSCALE);
+ easing_draw->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -30 * EDSCALE);
+ type_button->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 3 * EDSCALE);
+ type_button->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -3 * EDSCALE);
+ type_button->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_END, -25 * EDSCALE);
+ type_button->set_anchor_and_offset(SIDE_BOTTOM, Control::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);
@@ -536,10 +536,10 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
int button_margin = text_edit->get_theme_constant("button_margin", "Dialogs");
int margin = text_edit->get_theme_constant("margin", "Dialogs");
- action_buttons[0]->set_anchor(MARGIN_LEFT, Control::ANCHOR_END);
- action_buttons[0]->set_anchor(MARGIN_TOP, Control::ANCHOR_END);
- action_buttons[0]->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
- action_buttons[0]->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_END);
+ action_buttons[0]->set_anchor(SIDE_LEFT, Control::ANCHOR_END);
+ action_buttons[0]->set_anchor(SIDE_TOP, Control::ANCHOR_END);
+ action_buttons[0]->set_anchor(SIDE_RIGHT, Control::ANCHOR_END);
+ action_buttons[0]->set_anchor(SIDE_BOTTOM, Control::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_text(TTR("Close"));
@@ -882,7 +882,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
bool is_custom_resource = false;
Ref<Texture2D> icon;
- if (!custom_resources.empty()) {
+ if (!custom_resources.is_empty()) {
for (int k = 0; k < custom_resources.size(); k++) {
if (custom_resources[k].name == t) {
is_custom_resource = true;
@@ -1064,7 +1064,7 @@ void CustomPropertyEditor::_type_create_selected(int p_idx) {
String intype = inheritors_array[p_idx];
- Object *obj = ClassDB::instance(intype);
+ Variant obj = ClassDB::instance(intype);
if (!obj) {
if (ScriptServer::is_global_class(intype)) {
@@ -1075,11 +1075,9 @@ void CustomPropertyEditor::_type_create_selected(int p_idx) {
}
ERR_FAIL_COND(!obj);
+ ERR_FAIL_COND(!Object::cast_to<Resource>(obj));
- Resource *res = Object::cast_to<Resource>(obj);
- ERR_FAIL_COND(!res);
-
- v = res;
+ v = obj;
emit_signal("variant_changed");
hide();
}
@@ -1246,12 +1244,12 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
} break;
case Variant::OBJECT: {
if (p_which == 0) {
- ERR_FAIL_COND(inheritors_array.empty());
+ ERR_FAIL_COND(inheritors_array.is_empty());
String intype = inheritors_array[0];
if (hint == PROPERTY_HINT_RESOURCE_TYPE) {
- Object *obj = ClassDB::instance(intype);
+ Variant obj = ClassDB::instance(intype);
if (!obj) {
if (ScriptServer::is_global_class(intype)) {
@@ -1262,10 +1260,9 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
}
ERR_BREAK(!obj);
- Resource *res = Object::cast_to<Resource>(obj);
- ERR_BREAK(!res);
+ ERR_BREAK(!Object::cast_to<Resource>(obj));
- v = res;
+ v = obj;
emit_signal("variant_changed");
hide();
}
@@ -1661,10 +1658,10 @@ void CustomPropertyEditor::_focus_exit() {
void CustomPropertyEditor::config_action_buttons(const List<String> &p_strings) {
Ref<StyleBox> sb = action_buttons[0]->get_theme_stylebox("panel");
- int margin_top = sb->get_margin(MARGIN_TOP);
- int margin_left = sb->get_margin(MARGIN_LEFT);
- int margin_bottom = sb->get_margin(MARGIN_BOTTOM);
- int margin_right = sb->get_margin(MARGIN_RIGHT);
+ int margin_top = sb->get_margin(SIDE_TOP);
+ int margin_left = sb->get_margin(SIDE_LEFT);
+ int margin_bottom = sb->get_margin(SIDE_BOTTOM);
+ int margin_right = sb->get_margin(SIDE_RIGHT);
int max_width = 0;
int height = 0;
@@ -1794,8 +1791,8 @@ CustomPropertyEditor::CustomPropertyEditor() {
text_edit = memnew(TextEdit);
add_child(text_edit);
- text_edit->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
- text_edit->set_margin(MARGIN_BOTTOM, -30);
+ text_edit->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
+ text_edit->set_offset(SIDE_BOTTOM, -30);
text_edit->hide();
text_edit->connect("text_changed", callable_mp(this, &CustomPropertyEditor::_text_edit_changed));
@@ -1853,12 +1850,12 @@ CustomPropertyEditor::CustomPropertyEditor() {
spinbox = memnew(SpinBox);
add_child(spinbox);
- spinbox->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
+ spinbox->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
spinbox->connect("value_changed", callable_mp(this, &CustomPropertyEditor::_range_modified));
slider = memnew(HSlider);
add_child(slider);
- slider->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
+ slider->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
slider->connect("value_changed", callable_mp(this, &CustomPropertyEditor::_range_modified));
create_dialog = nullptr;