feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/input/input.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "editor/editor_file_system.h"
|
||||
#include "editor/editor_properties.h"
|
||||
#include "editor/editor_properties_vector.h"
|
||||
#include "editor/editor_settings.h"
|
||||
|
|
@ -39,10 +40,8 @@
|
|||
#include "editor/gui/editor_spin_slider.h"
|
||||
#include "editor/inspector_dock.h"
|
||||
#include "editor/themes/editor_scale.h"
|
||||
#include "editor/themes/editor_theme_manager.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/margin_container.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
bool EditorPropertyArrayObject::_set(const StringName &p_name, const Variant &p_value) {
|
||||
String name = p_name;
|
||||
|
|
@ -146,6 +145,16 @@ bool EditorPropertyDictionaryObject::get_by_property_name(const String &p_name,
|
|||
return true;
|
||||
}
|
||||
|
||||
if (name == "new_item_key_name") {
|
||||
r_ret = TTR("New Key:");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "new_item_value_name") {
|
||||
r_ret = TTR("New Value:");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.begins_with("indices")) {
|
||||
int index = name.get_slicec('/', 1).to_int();
|
||||
Variant key = dict.get_key_at_index(index);
|
||||
|
|
@ -153,6 +162,13 @@ bool EditorPropertyDictionaryObject::get_by_property_name(const String &p_name,
|
|||
return true;
|
||||
}
|
||||
|
||||
if (name.begins_with("keys")) {
|
||||
int index = name.get_slicec('/', 1).to_int();
|
||||
Variant key = dict.get_key_at_index(index);
|
||||
r_ret = key;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -191,6 +207,17 @@ String EditorPropertyDictionaryObject::get_property_name_for_index(int p_index)
|
|||
}
|
||||
}
|
||||
|
||||
String EditorPropertyDictionaryObject::get_key_name_for_index(int p_index) {
|
||||
switch (p_index) {
|
||||
case NEW_KEY_INDEX:
|
||||
return "new_item_key_name";
|
||||
case NEW_VALUE_INDEX:
|
||||
return "new_item_value_name";
|
||||
default:
|
||||
return "keys/" + itos(p_index);
|
||||
}
|
||||
}
|
||||
|
||||
String EditorPropertyDictionaryObject::get_label_for_index(int p_index) {
|
||||
switch (p_index) {
|
||||
case NEW_KEY_INDEX:
|
||||
|
|
@ -283,7 +310,7 @@ void EditorPropertyArray::_create_new_property_slot() {
|
|||
HBoxContainer *hbox = memnew(HBoxContainer);
|
||||
|
||||
Button *reorder_button = memnew(Button);
|
||||
reorder_button->set_icon(get_editor_theme_icon(SNAME("TripleBar")));
|
||||
reorder_button->set_button_icon(get_editor_theme_icon(SNAME("TripleBar")));
|
||||
reorder_button->set_default_cursor_shape(Control::CURSOR_MOVE);
|
||||
reorder_button->set_disabled(is_read_only());
|
||||
reorder_button->connect(SceneStringName(gui_input), callable_mp(this, &EditorPropertyArray::_reorder_button_gui_input));
|
||||
|
|
@ -298,13 +325,13 @@ void EditorPropertyArray::_create_new_property_slot() {
|
|||
|
||||
if (is_untyped_array) {
|
||||
Button *edit_btn = memnew(Button);
|
||||
edit_btn->set_icon(get_editor_theme_icon(SNAME("Edit")));
|
||||
edit_btn->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
|
||||
edit_btn->set_disabled(is_read_only());
|
||||
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_change_type).bind(edit_btn, idx));
|
||||
hbox->add_child(edit_btn);
|
||||
} else {
|
||||
Button *remove_btn = memnew(Button);
|
||||
remove_btn->set_icon(get_editor_theme_icon(SNAME("Remove")));
|
||||
remove_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
|
||||
remove_btn->set_disabled(is_read_only());
|
||||
remove_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_remove_pressed).bind(idx));
|
||||
hbox->add_child(remove_btn);
|
||||
|
|
@ -320,10 +347,15 @@ void EditorPropertyArray::_create_new_property_slot() {
|
|||
slots.push_back(slot);
|
||||
}
|
||||
|
||||
void EditorPropertyArray::set_preview_value(bool p_preview_value) {
|
||||
preview_value = p_preview_value;
|
||||
}
|
||||
|
||||
void EditorPropertyArray::update_property() {
|
||||
Variant array = get_edited_property_value();
|
||||
|
||||
String array_type_name = Variant::get_type_name(array_type);
|
||||
String array_sub_type_name;
|
||||
if (array_type == Variant::ARRAY && subtype != Variant::NIL) {
|
||||
String type_name;
|
||||
if (subtype == Variant::OBJECT && (subtype_hint == PROPERTY_HINT_RESOURCE_TYPE || subtype_hint == PROPERTY_HINT_NODE_TYPE)) {
|
||||
|
|
@ -332,11 +364,23 @@ void EditorPropertyArray::update_property() {
|
|||
type_name = Variant::get_type_name(subtype);
|
||||
}
|
||||
|
||||
array_type_name = vformat("%s[%s]", array_type_name, type_name);
|
||||
if (preview_value) {
|
||||
array_sub_type_name = vformat("[%s] ", type_name);
|
||||
} else {
|
||||
array_type_name = vformat("%s[%s]", array_type_name, type_name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!array.is_array()) {
|
||||
edit->set_text(vformat(TTR("(Nil) %s"), array_type_name));
|
||||
if (preview_value) {
|
||||
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
|
||||
edit->set_button_icon(get_editor_theme_icon(SNAME("Nil")));
|
||||
edit->set_text(array_type_name);
|
||||
} else {
|
||||
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
||||
edit->set_button_icon(Ref<Texture2D>());
|
||||
edit->set_text(vformat(TTR("(Nil) %s"), array_type_name));
|
||||
}
|
||||
edit->set_pressed(false);
|
||||
if (container) {
|
||||
set_bottom_editor(nullptr);
|
||||
|
|
@ -356,7 +400,25 @@ void EditorPropertyArray::update_property() {
|
|||
_page_changed(max_page);
|
||||
}
|
||||
|
||||
edit->set_text(vformat(TTR("%s (size %s)"), array_type_name, itos(size)));
|
||||
if (preview_value) {
|
||||
String ctr_str = array.get_construct_string().trim_prefix(array_type_name + "(").trim_suffix(")").replace("\n", "");
|
||||
if (array_type == Variant::ARRAY && subtype != Variant::NIL) {
|
||||
int type_end = ctr_str.find("](");
|
||||
if (type_end > 0) {
|
||||
ctr_str = ctr_str.substr(type_end + 2);
|
||||
}
|
||||
}
|
||||
|
||||
edit->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
|
||||
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
|
||||
edit->set_button_icon(get_editor_theme_icon(array_type_name));
|
||||
edit->set_text(vformat("%s%s", array_sub_type_name, ctr_str));
|
||||
edit->set_tooltip_text(vformat(TTR("%s%s (size %d)"), array_type_name, array_sub_type_name, size));
|
||||
} else {
|
||||
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
||||
edit->set_button_icon(Ref<Texture2D>());
|
||||
edit->set_text(vformat(TTR("%s (size %d)"), array_type_name, size));
|
||||
}
|
||||
|
||||
bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
|
||||
if (edit->is_pressed() != unfolded) {
|
||||
|
|
@ -385,6 +447,7 @@ void EditorPropertyArray::update_property() {
|
|||
size_slider = memnew(EditorSpinSlider);
|
||||
size_slider->set_step(1);
|
||||
size_slider->set_max(INT32_MAX);
|
||||
size_slider->set_editing_integer(true);
|
||||
size_slider->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
size_slider->set_read_only(is_read_only());
|
||||
size_slider->connect(SceneStringName(value_changed), callable_mp(this, &EditorPropertyArray::_length_changed));
|
||||
|
|
@ -395,7 +458,7 @@ void EditorPropertyArray::update_property() {
|
|||
vbox->add_child(property_vbox);
|
||||
|
||||
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Element"));
|
||||
button_add_item->set_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_add_element));
|
||||
button_add_item->set_disabled(is_read_only());
|
||||
vbox->add_child(button_add_item);
|
||||
|
|
@ -644,6 +707,8 @@ void EditorPropertyArray::_notification(int p_what) {
|
|||
case NOTIFICATION_THEME_CHANGED:
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
change_type->clear();
|
||||
change_type->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Remove Item"), Variant::VARIANT_MAX);
|
||||
change_type->add_separator();
|
||||
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
||||
if (i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) {
|
||||
// These types can't be constructed or serialized properly, so skip them.
|
||||
|
|
@ -653,11 +718,9 @@ void EditorPropertyArray::_notification(int p_what) {
|
|||
String type = Variant::get_type_name(Variant::Type(i));
|
||||
change_type->add_icon_item(get_editor_theme_icon(type), type, i);
|
||||
}
|
||||
change_type->add_separator();
|
||||
change_type->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Remove Item"), Variant::VARIANT_MAX);
|
||||
|
||||
if (button_add_item) {
|
||||
button_add_item->set_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
}
|
||||
} break;
|
||||
|
||||
|
|
@ -740,10 +803,10 @@ void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint
|
|||
// The format of p_hint_string is:
|
||||
// subType/subTypeHint:nextSubtype ... etc.
|
||||
if (!p_hint_string.is_empty()) {
|
||||
int hint_subtype_separator = p_hint_string.find(":");
|
||||
int hint_subtype_separator = p_hint_string.find_char(':');
|
||||
if (hint_subtype_separator >= 0) {
|
||||
String subtype_string = p_hint_string.substr(0, hint_subtype_separator);
|
||||
int slash_pos = subtype_string.find("/");
|
||||
int slash_pos = subtype_string.find_char('/');
|
||||
if (slash_pos >= 0) {
|
||||
subtype_hint = PropertyHint(subtype_string.substr(slash_pos + 1, subtype_string.size() - slash_pos - 1).to_int());
|
||||
subtype_string = subtype_string.substr(0, slash_pos);
|
||||
|
|
@ -819,6 +882,7 @@ void EditorPropertyArray::_reorder_button_up() {
|
|||
array.call("remove_at", reorder_slot.index);
|
||||
array.call("insert", reorder_to_index, value_to_move);
|
||||
|
||||
slots[reorder_to_index % page_length].reorder_button->grab_focus();
|
||||
emit_changed(get_edited_property(), array);
|
||||
}
|
||||
|
||||
|
|
@ -836,9 +900,6 @@ bool EditorPropertyArray::is_colored(ColorationMode p_mode) {
|
|||
return p_mode == COLORATION_CONTAINER_RESOURCE;
|
||||
}
|
||||
|
||||
void EditorPropertyArray::_bind_methods() {
|
||||
}
|
||||
|
||||
EditorPropertyArray::EditorPropertyArray() {
|
||||
object.instantiate();
|
||||
page_length = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page"));
|
||||
|
|
@ -866,13 +927,37 @@ EditorPropertyArray::EditorPropertyArray() {
|
|||
|
||||
///////////////////// DICTIONARY ///////////////////////////
|
||||
|
||||
void EditorPropertyDictionary::initialize_dictionary(Variant &p_dictionary) {
|
||||
if (key_subtype != Variant::NIL || value_subtype != Variant::NIL) {
|
||||
Dictionary dict;
|
||||
StringName key_subtype_class;
|
||||
Ref<Script> key_subtype_script;
|
||||
if (key_subtype == Variant::OBJECT && !key_subtype_hint_string.is_empty() && ClassDB::class_exists(key_subtype_hint_string)) {
|
||||
key_subtype_class = key_subtype_hint_string;
|
||||
}
|
||||
StringName value_subtype_class;
|
||||
Ref<Script> value_subtype_script;
|
||||
if (value_subtype == Variant::OBJECT && !value_subtype_hint_string.is_empty() && ClassDB::class_exists(value_subtype_hint_string)) {
|
||||
value_subtype_class = value_subtype_hint_string;
|
||||
}
|
||||
dict.set_typed(key_subtype, key_subtype_class, key_subtype_script, value_subtype, value_subtype_class, value_subtype_script);
|
||||
p_dictionary = dict;
|
||||
} else {
|
||||
VariantInternal::initialize(&p_dictionary, Variant::DICTIONARY);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorPropertyDictionary::_property_changed(const String &p_property, Variant p_value, const String &p_name, bool p_changing) {
|
||||
if (p_value.get_type() == Variant::OBJECT && p_value.is_null()) {
|
||||
p_value = Variant(); // `EditorResourcePicker` resets to `Ref<Resource>()`. See GH-82716.
|
||||
}
|
||||
|
||||
object->set(p_property, p_value);
|
||||
emit_changed(get_edited_property(), object->get_dict(), p_name, p_changing);
|
||||
bool new_item_or_key = !p_property.begins_with("indices");
|
||||
emit_changed(get_edited_property(), object->get_dict(), p_name, p_changing || new_item_or_key);
|
||||
if (new_item_or_key) {
|
||||
update_property();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorPropertyDictionary::_change_type(Object *p_button, int p_slot_index) {
|
||||
|
|
@ -914,21 +999,46 @@ void EditorPropertyDictionary::_add_key_value() {
|
|||
|
||||
void EditorPropertyDictionary::_create_new_property_slot(int p_idx) {
|
||||
HBoxContainer *hbox = memnew(HBoxContainer);
|
||||
|
||||
EditorProperty *prop_key = nullptr;
|
||||
if (p_idx != EditorPropertyDictionaryObject::NEW_KEY_INDEX && p_idx != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
|
||||
prop_key = memnew(EditorPropertyNil);
|
||||
hbox->add_child(prop_key);
|
||||
}
|
||||
|
||||
EditorProperty *prop = memnew(EditorPropertyNil);
|
||||
prop->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
if (p_idx != EditorPropertyDictionaryObject::NEW_KEY_INDEX && p_idx != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
|
||||
prop->set_draw_label(false);
|
||||
}
|
||||
hbox->add_child(prop);
|
||||
|
||||
Button *edit_btn = memnew(Button);
|
||||
edit_btn->set_icon(get_editor_theme_icon(SNAME("Edit")));
|
||||
edit_btn->set_disabled(is_read_only());
|
||||
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_change_type).bind(edit_btn, slots.size()));
|
||||
hbox->add_child(edit_btn);
|
||||
bool use_key = p_idx == EditorPropertyDictionaryObject::NEW_KEY_INDEX;
|
||||
bool is_untyped_dict = (use_key ? key_subtype : value_subtype) == Variant::NIL;
|
||||
|
||||
if (is_untyped_dict) {
|
||||
Button *edit_btn = memnew(Button);
|
||||
edit_btn->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
|
||||
edit_btn->set_disabled(is_read_only());
|
||||
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_change_type).bind(edit_btn, slots.size()));
|
||||
hbox->add_child(edit_btn);
|
||||
} else if (p_idx >= 0) {
|
||||
Button *remove_btn = memnew(Button);
|
||||
remove_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
|
||||
remove_btn->set_disabled(is_read_only());
|
||||
remove_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_remove_pressed).bind(slots.size()));
|
||||
hbox->add_child(remove_btn);
|
||||
}
|
||||
|
||||
if (add_panel) {
|
||||
add_panel->get_child(0)->add_child(hbox);
|
||||
} else {
|
||||
property_vbox->add_child(hbox);
|
||||
}
|
||||
|
||||
Slot slot;
|
||||
slot.prop = prop;
|
||||
slot.prop_key = prop_key;
|
||||
slot.object = object;
|
||||
slot.container = hbox;
|
||||
int index = p_idx + (p_idx >= 0 ? page_index * page_length : 0);
|
||||
|
|
@ -972,15 +1082,87 @@ void EditorPropertyDictionary::_change_type_menu(int p_index) {
|
|||
}
|
||||
}
|
||||
|
||||
void EditorPropertyDictionary::setup(PropertyHint p_hint) {
|
||||
property_hint = p_hint;
|
||||
void EditorPropertyDictionary::setup(PropertyHint p_hint, const String &p_hint_string) {
|
||||
PackedStringArray types = p_hint_string.split(";");
|
||||
if (types.size() > 0 && !types[0].is_empty()) {
|
||||
String key = types[0];
|
||||
int hint_key_subtype_separator = key.find_char(':');
|
||||
if (hint_key_subtype_separator >= 0) {
|
||||
String key_subtype_string = key.substr(0, hint_key_subtype_separator);
|
||||
int slash_pos = key_subtype_string.find_char('/');
|
||||
if (slash_pos >= 0) {
|
||||
key_subtype_hint = PropertyHint(key_subtype_string.substr(slash_pos + 1, key_subtype_string.size() - slash_pos - 1).to_int());
|
||||
key_subtype_string = key_subtype_string.substr(0, slash_pos);
|
||||
}
|
||||
|
||||
key_subtype_hint_string = key.substr(hint_key_subtype_separator + 1, key.size() - hint_key_subtype_separator - 1);
|
||||
key_subtype = Variant::Type(key_subtype_string.to_int());
|
||||
|
||||
Variant new_key = object->get_new_item_key();
|
||||
VariantInternal::initialize(&new_key, key_subtype);
|
||||
object->set_new_item_key(new_key);
|
||||
}
|
||||
}
|
||||
if (types.size() > 1 && !types[1].is_empty()) {
|
||||
String value = types[1];
|
||||
int hint_value_subtype_separator = value.find_char(':');
|
||||
if (hint_value_subtype_separator >= 0) {
|
||||
String value_subtype_string = value.substr(0, hint_value_subtype_separator);
|
||||
int slash_pos = value_subtype_string.find_char('/');
|
||||
if (slash_pos >= 0) {
|
||||
value_subtype_hint = PropertyHint(value_subtype_string.substr(slash_pos + 1, value_subtype_string.size() - slash_pos - 1).to_int());
|
||||
value_subtype_string = value_subtype_string.substr(0, slash_pos);
|
||||
}
|
||||
|
||||
value_subtype_hint_string = value.substr(hint_value_subtype_separator + 1, value.size() - hint_value_subtype_separator - 1);
|
||||
value_subtype = Variant::Type(value_subtype_string.to_int());
|
||||
|
||||
Variant new_value = object->get_new_item_value();
|
||||
VariantInternal::initialize(&new_value, value_subtype);
|
||||
object->set_new_item_value(new_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorPropertyDictionary::set_preview_value(bool p_preview_value) {
|
||||
preview_value = p_preview_value;
|
||||
}
|
||||
|
||||
void EditorPropertyDictionary::update_property() {
|
||||
Variant updated_val = get_edited_property_value();
|
||||
|
||||
String dict_type_name = "Dictionary";
|
||||
String dict_sub_type_name;
|
||||
if (key_subtype != Variant::NIL || value_subtype != Variant::NIL) {
|
||||
String key_subtype_name = "Variant";
|
||||
if (key_subtype == Variant::OBJECT && (key_subtype_hint == PROPERTY_HINT_RESOURCE_TYPE || key_subtype_hint == PROPERTY_HINT_NODE_TYPE)) {
|
||||
key_subtype_name = key_subtype_hint_string;
|
||||
} else if (key_subtype != Variant::NIL) {
|
||||
key_subtype_name = Variant::get_type_name(key_subtype);
|
||||
}
|
||||
String value_subtype_name = "Variant";
|
||||
if (value_subtype == Variant::OBJECT && (value_subtype_hint == PROPERTY_HINT_RESOURCE_TYPE || value_subtype_hint == PROPERTY_HINT_NODE_TYPE)) {
|
||||
value_subtype_name = value_subtype_hint_string;
|
||||
} else if (value_subtype != Variant::NIL) {
|
||||
value_subtype_name = Variant::get_type_name(value_subtype);
|
||||
}
|
||||
if (preview_value) {
|
||||
dict_sub_type_name = vformat("[%s, %s] ", key_subtype_name, value_subtype_name);
|
||||
} else {
|
||||
dict_type_name += vformat("[%s, %s]", key_subtype_name, value_subtype_name);
|
||||
}
|
||||
}
|
||||
|
||||
if (updated_val.get_type() != Variant::DICTIONARY) {
|
||||
edit->set_text(TTR("Dictionary (Nil)")); // This provides symmetry with the array property.
|
||||
if (preview_value) {
|
||||
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
|
||||
edit->set_button_icon(get_editor_theme_icon(SNAME("Nil")));
|
||||
edit->set_text(dict_type_name);
|
||||
} else {
|
||||
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
||||
edit->set_button_icon(Ref<Texture2D>());
|
||||
edit->set_text(vformat(TTR("(Nil) %s"), dict_type_name));
|
||||
}
|
||||
edit->set_pressed(false);
|
||||
if (container) {
|
||||
set_bottom_editor(nullptr);
|
||||
|
|
@ -996,7 +1178,25 @@ void EditorPropertyDictionary::update_property() {
|
|||
Dictionary dict = updated_val;
|
||||
object->set_dict(updated_val);
|
||||
|
||||
edit->set_text(vformat(TTR("Dictionary (size %d)"), dict.size()));
|
||||
if (preview_value) {
|
||||
String ctr_str = updated_val.get_construct_string().replace("\n", "");
|
||||
if (key_subtype != Variant::NIL || value_subtype != Variant::NIL) {
|
||||
int type_end = ctr_str.find("](");
|
||||
if (type_end > 0) {
|
||||
ctr_str = ctr_str.substr(type_end + 2).trim_suffix(")");
|
||||
}
|
||||
}
|
||||
|
||||
edit->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
|
||||
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
|
||||
edit->set_button_icon(get_editor_theme_icon(dict_type_name));
|
||||
edit->set_text(vformat("%s%s", dict_sub_type_name, ctr_str));
|
||||
edit->set_tooltip_text(vformat(TTR("%s%s (size %d)"), dict_type_name, dict_sub_type_name, dict.size()));
|
||||
} else {
|
||||
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
||||
edit->set_button_icon(Ref<Texture2D>());
|
||||
edit->set_text(vformat(TTR("%s (size %d)"), dict_type_name, dict.size()));
|
||||
}
|
||||
|
||||
bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
|
||||
if (edit->is_pressed() != unfolded) {
|
||||
|
|
@ -1037,7 +1237,7 @@ void EditorPropertyDictionary::update_property() {
|
|||
_create_new_property_slot(EditorPropertyDictionaryObject::NEW_VALUE_INDEX);
|
||||
|
||||
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Key/Value Pair"));
|
||||
button_add_item->set_icon(get_theme_icon(SNAME("Add"), EditorStringName(EditorIcons)));
|
||||
button_add_item->set_button_icon(get_theme_icon(SNAME("Add"), EditorStringName(EditorIcons)));
|
||||
button_add_item->set_disabled(is_read_only());
|
||||
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_add_key_value));
|
||||
add_vbox->add_child(button_add_item);
|
||||
|
|
@ -1062,6 +1262,44 @@ void EditorPropertyDictionary::update_property() {
|
|||
if (!slot_visible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the editor property key needs to be updated.
|
||||
if (slot.prop_key) {
|
||||
Variant key;
|
||||
object->get_by_property_name(slot.key_name, key);
|
||||
Variant::Type key_type = key.get_type();
|
||||
|
||||
bool key_as_id = Object::cast_to<EncodedObjectAsID>(key);
|
||||
if (key_type != slot.key_type || (key_type == Variant::OBJECT && key_as_id != slot.key_as_id)) {
|
||||
slot.key_as_id = key_as_id;
|
||||
slot.key_type = key_type;
|
||||
EditorProperty *new_prop = nullptr;
|
||||
if (key_type == Variant::OBJECT && key_as_id) {
|
||||
EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID);
|
||||
editor->setup("Object");
|
||||
new_prop = editor;
|
||||
} else {
|
||||
new_prop = EditorInspector::instantiate_property_editor(this, key_type, "", key_subtype_hint, key_subtype_hint_string, PROPERTY_USAGE_NONE);
|
||||
}
|
||||
new_prop->set_read_only(true);
|
||||
new_prop->set_selectable(false);
|
||||
new_prop->set_focus_mode(Control::FOCUS_NONE);
|
||||
new_prop->set_draw_background(false);
|
||||
new_prop->set_use_folding(is_using_folding());
|
||||
new_prop->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
new_prop->set_draw_label(false);
|
||||
EditorPropertyArray *arr_prop = Object::cast_to<EditorPropertyArray>(new_prop);
|
||||
if (arr_prop) {
|
||||
arr_prop->set_preview_value(true);
|
||||
}
|
||||
EditorPropertyDictionary *dict_prop = Object::cast_to<EditorPropertyDictionary>(new_prop);
|
||||
if (dict_prop) {
|
||||
dict_prop->set_preview_value(true);
|
||||
}
|
||||
slot.set_key_prop(new_prop);
|
||||
}
|
||||
}
|
||||
|
||||
Variant value;
|
||||
object->get_by_property_name(slot.prop_name, value);
|
||||
Variant::Type value_type = value.get_type();
|
||||
|
|
@ -1077,15 +1315,24 @@ void EditorPropertyDictionary::update_property() {
|
|||
editor->setup("Object");
|
||||
new_prop = editor;
|
||||
} else {
|
||||
new_prop = EditorInspector::instantiate_property_editor(this, value_type, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE);
|
||||
bool use_key = slot.index == EditorPropertyDictionaryObject::NEW_KEY_INDEX;
|
||||
new_prop = EditorInspector::instantiate_property_editor(this, value_type, "", use_key ? key_subtype_hint : value_subtype_hint,
|
||||
use_key ? key_subtype_hint_string : value_subtype_hint_string, PROPERTY_USAGE_NONE);
|
||||
}
|
||||
new_prop->set_selectable(false);
|
||||
new_prop->set_use_folding(is_using_folding());
|
||||
new_prop->connect(SNAME("property_changed"), callable_mp(this, &EditorPropertyDictionary::_property_changed));
|
||||
new_prop->connect(SNAME("object_id_selected"), callable_mp(this, &EditorPropertyDictionary::_object_id_selected));
|
||||
new_prop->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
if (slot.index != EditorPropertyDictionaryObject::NEW_KEY_INDEX && slot.index != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
|
||||
new_prop->set_draw_label(false);
|
||||
}
|
||||
new_prop->set_read_only(is_read_only());
|
||||
slot.set_prop(new_prop);
|
||||
} else if (slot.index != EditorPropertyDictionaryObject::NEW_KEY_INDEX && slot.index != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
|
||||
Variant key = dict.get_key_at_index(slot.index);
|
||||
String cs = key.get_construct_string();
|
||||
slot.prop->set_tooltip_text(cs);
|
||||
}
|
||||
|
||||
// We need to grab the focus of the property that is being changed, even if the type didn't actually changed.
|
||||
|
|
@ -1096,6 +1343,9 @@ void EditorPropertyDictionary::update_property() {
|
|||
}
|
||||
|
||||
slot.prop->update_property();
|
||||
if (slot.prop_key) {
|
||||
slot.prop_key->update_property();
|
||||
}
|
||||
}
|
||||
updating = false;
|
||||
|
||||
|
|
@ -1111,6 +1361,14 @@ void EditorPropertyDictionary::update_property() {
|
|||
}
|
||||
}
|
||||
|
||||
void EditorPropertyDictionary::_remove_pressed(int p_slot_index) {
|
||||
Dictionary dict = object->get_dict().duplicate();
|
||||
int index = slots[p_slot_index].index;
|
||||
dict.erase(dict.get_key_at_index(index));
|
||||
|
||||
emit_changed(get_edited_property(), dict);
|
||||
}
|
||||
|
||||
void EditorPropertyDictionary::_object_id_selected(const StringName &p_property, ObjectID p_id) {
|
||||
emit_signal(SNAME("object_id_selected"), p_property, p_id);
|
||||
}
|
||||
|
|
@ -1120,6 +1378,8 @@ void EditorPropertyDictionary::_notification(int p_what) {
|
|||
case NOTIFICATION_THEME_CHANGED:
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
change_type->clear();
|
||||
change_type->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Remove Item"), Variant::VARIANT_MAX);
|
||||
change_type->add_separator();
|
||||
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
||||
if (i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) {
|
||||
// These types can't be constructed or serialized properly, so skip them.
|
||||
|
|
@ -1129,11 +1389,9 @@ void EditorPropertyDictionary::_notification(int p_what) {
|
|||
String type = Variant::get_type_name(Variant::Type(i));
|
||||
change_type->add_icon_item(get_editor_theme_icon(type), type, i);
|
||||
}
|
||||
change_type->add_separator();
|
||||
change_type->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Remove Item"), Variant::VARIANT_MAX);
|
||||
|
||||
if (button_add_item) {
|
||||
button_add_item->set_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
add_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("DictionaryAddItem")));
|
||||
}
|
||||
} break;
|
||||
|
|
@ -1143,7 +1401,7 @@ void EditorPropertyDictionary::_notification(int p_what) {
|
|||
void EditorPropertyDictionary::_edit_pressed() {
|
||||
Variant prop_val = get_edited_property_value();
|
||||
if (prop_val.get_type() == Variant::NIL && edit->is_pressed()) {
|
||||
VariantInternal::initialize(&prop_val, Variant::DICTIONARY);
|
||||
initialize_dictionary(prop_val);
|
||||
emit_changed(get_edited_property(), prop_val);
|
||||
}
|
||||
|
||||
|
|
@ -1166,9 +1424,6 @@ void EditorPropertyDictionary::_page_changed(int p_page) {
|
|||
update_property();
|
||||
}
|
||||
|
||||
void EditorPropertyDictionary::_bind_methods() {
|
||||
}
|
||||
|
||||
bool EditorPropertyDictionary::is_colored(ColorationMode p_mode) {
|
||||
return p_mode == COLORATION_CONTAINER_RESOURCE;
|
||||
}
|
||||
|
|
@ -1191,8 +1446,16 @@ EditorPropertyDictionary::EditorPropertyDictionary() {
|
|||
change_type = memnew(PopupMenu);
|
||||
add_child(change_type);
|
||||
change_type->connect(SceneStringName(id_pressed), callable_mp(this, &EditorPropertyDictionary::_change_type_menu));
|
||||
changing_type_index = -1;
|
||||
changing_type_index = EditorPropertyDictionaryObject::NOT_CHANGING_TYPE;
|
||||
has_borders = true;
|
||||
|
||||
key_subtype = Variant::NIL;
|
||||
key_subtype_hint = PROPERTY_HINT_NONE;
|
||||
key_subtype_hint_string = "";
|
||||
|
||||
value_subtype = Variant::NIL;
|
||||
value_subtype_hint = PROPERTY_HINT_NONE;
|
||||
value_subtype_hint_string = "";
|
||||
}
|
||||
|
||||
///////////////////// LOCALIZABLE STRING ///////////////////////////
|
||||
|
|
@ -1325,7 +1588,7 @@ void EditorPropertyLocalizableString::update_property() {
|
|||
hbox->add_child(prop);
|
||||
prop->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
Button *edit_btn = memnew(Button);
|
||||
edit_btn->set_icon(get_editor_theme_icon(SNAME("Remove")));
|
||||
edit_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
|
||||
hbox->add_child(edit_btn);
|
||||
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyLocalizableString::_remove_item).bind(edit_btn, remove_index));
|
||||
|
||||
|
|
@ -1334,7 +1597,7 @@ void EditorPropertyLocalizableString::update_property() {
|
|||
|
||||
if (page_index == max_page) {
|
||||
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Translation"));
|
||||
button_add_item->set_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyLocalizableString::_add_locale_popup));
|
||||
property_vbox->add_child(button_add_item);
|
||||
}
|
||||
|
|
@ -1360,7 +1623,7 @@ void EditorPropertyLocalizableString::_notification(int p_what) {
|
|||
case NOTIFICATION_THEME_CHANGED:
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
if (button_add_item) {
|
||||
button_add_item->set_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
|
@ -1385,9 +1648,6 @@ void EditorPropertyLocalizableString::_page_changed(int p_page) {
|
|||
update_property();
|
||||
}
|
||||
|
||||
void EditorPropertyLocalizableString::_bind_methods() {
|
||||
}
|
||||
|
||||
EditorPropertyLocalizableString::EditorPropertyLocalizableString() {
|
||||
object.instantiate();
|
||||
page_length = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue