Backport editor type icons

Co-authored-by: FireForge <isaacr.7.2005@gmail.com>
This commit is contained in:
Haoyu Qiu 2022-02-16 22:29:11 +08:00
parent 2dd545b512
commit 5688ca688c
4 changed files with 71 additions and 36 deletions

View File

@ -501,20 +501,33 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d
}
void EditorPropertyArray::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAG_BEGIN) {
if (is_visible_in_tree()) {
if (_is_drop_valid(get_viewport()->gui_get_drag_data())) {
dropping = true;
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
change_type->clear();
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
String type = Variant::get_type_name(Variant::Type(i));
change_type->add_icon_item(get_icon(type, "EditorIcons"), type, i);
}
change_type->add_separator();
change_type->add_icon_item(get_icon("Remove", "EditorIcons"), TTR("Remove Item"), Variant::VARIANT_MAX);
} break;
case NOTIFICATION_DRAG_BEGIN: {
if (is_visible_in_tree()) {
if (_is_drop_valid(get_viewport()->gui_get_drag_data())) {
dropping = true;
edit->update();
}
}
} break;
case NOTIFICATION_DRAG_END: {
if (dropping) {
dropping = false;
edit->update();
}
}
}
if (p_what == NOTIFICATION_DRAG_END) {
if (dropping) {
dropping = false;
edit->update();
}
} break;
}
}
@ -1092,10 +1105,11 @@ void EditorPropertyDictionary::update_property() {
prop->update_property();
if (i == amount + 1) {
Button *butt_add_item = memnew(Button);
butt_add_item->set_text(TTR("Add Key/Value Pair"));
butt_add_item->connect("pressed", this, "_add_key_value");
add_vbox->add_child(butt_add_item);
button_add_item = memnew(Button);
button_add_item->set_text(TTR("Add Key/Value Pair"));
button_add_item->set_icon(get_icon("Add", "EditorIcons"));
button_add_item->connect("pressed", this, "_add_key_value");
add_vbox->add_child(button_add_item);
}
}
@ -1115,6 +1129,22 @@ void EditorPropertyDictionary::_object_id_selected(const String &p_property, Obj
}
void EditorPropertyDictionary::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
change_type->clear();
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
String type = Variant::get_type_name(Variant::Type(i));
change_type->add_icon_item(get_icon(type, "EditorIcons"), type, i);
}
change_type->add_separator();
change_type->add_icon_item(get_icon("Remove", "EditorIcons"), TTR("Remove Item"), Variant::VARIANT_MAX);
if (Object::cast_to<Button>(button_add_item)) {
button_add_item->set_icon(get_icon("Add", "EditorIcons"));
}
} break;
}
}
void EditorPropertyDictionary::_edit_pressed() {
@ -1160,16 +1190,10 @@ EditorPropertyDictionary::EditorPropertyDictionary() {
add_focusable(edit);
vbox = nullptr;
page_slider = nullptr;
button_add_item = nullptr;
updating = false;
change_type = memnew(PopupMenu);
add_child(change_type);
change_type->connect("id_pressed", this, "_change_type_menu");
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
String type = Variant::get_type_name(Variant::Type(i));
change_type->add_item(type, i);
}
change_type->add_separator();
change_type->add_item(TTR("Remove Item"), Variant::VARIANT_MAX);
changing_type_index = -1;
}

View File

@ -147,6 +147,7 @@ class EditorPropertyDictionary : public EditorProperty {
EditorSpinSlider *size_slider;
EditorSpinSlider *page_slider;
HBoxContainer *page_hbox;
Button *button_add_item;
void _page_changed(double p_page);
void _edit_pressed();

View File

@ -169,6 +169,10 @@ void ProjectSettingsEditor::_notification(int p_what) {
popup_add->set_item_icon(popup_add->get_item_index(INPUT_MOUSE_BUTTON), get_icon("Mouse", "EditorIcons"));
_update_actions();
} break;
case NOTIFICATION_THEME_CHANGED: {
_update_theme();
} break;
}
}
@ -880,7 +884,7 @@ void ProjectSettingsEditor::_item_adds(String) {
void ProjectSettingsEditor::_item_add() {
// Initialize the property with the default value for the given type.
Variant::CallError ce;
const Variant value = Variant::construct(Variant::Type(type->get_selected_id()), nullptr, 0, ce);
const Variant value = Variant::construct(Variant::Type(type_box->get_selected_id()), nullptr, 0, ce);
String name = property->get_text().strip_edges();
@ -1734,6 +1738,18 @@ void ProjectSettingsEditor::_editor_restart_close() {
restart_container->hide();
}
void ProjectSettingsEditor::_update_theme() {
type_box->clear();
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
// There's no point in adding Nil types, and Object types
// can't be serialized correctly in the project settings.
if (i != Variant::NIL && i != Variant::OBJECT) {
const String type = Variant::get_type_name(Variant::Type(i));
type_box->add_icon_item(get_icon(type, "EditorIcons"), type, i);
}
}
}
void ProjectSettingsEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_input"), &ProjectSettingsEditor::_unhandled_input);
ClassDB::bind_method(D_METHOD("_item_selected"), &ProjectSettingsEditor::_item_selected);
@ -1837,17 +1853,9 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
add_prop_bar->add_child(l);
l->set_text(TTR("Type:"));
type = memnew(OptionButton);
type->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
add_prop_bar->add_child(type);
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
// There's no point in adding Nil types, and Object types
// can't be serialized correctly in the project settings.
if (i != Variant::NIL && i != Variant::OBJECT) {
type->add_item(Variant::get_type_name(Variant::Type(i)), i);
}
}
type_box = memnew(OptionButton);
type_box->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
add_prop_bar->add_child(type_box);
Button *add = memnew(Button);
add_prop_bar->add_child(add);

View File

@ -74,7 +74,7 @@ class ProjectSettingsEditor : public AcceptDialog {
HBoxContainer *add_prop_bar;
AcceptDialog *message;
LineEdit *property;
OptionButton *type;
OptionButton *type_box;
PopupMenu *popup_add;
ConfirmationDialog *press_a_key;
bool press_a_key_physical;
@ -178,6 +178,8 @@ class ProjectSettingsEditor : public AcceptDialog {
void _editor_restart();
void _editor_restart_close();
void _update_theme();
protected:
void _unhandled_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);