Add Delete All button to ItemList editor
This commit is contained in:
parent
fb4fadfd1e
commit
f7e152b001
|
@ -244,6 +244,7 @@ void ItemListEditor::_node_removed(Node *p_node) {
|
||||||
void ItemListEditor::_notification(int p_notification) {
|
void ItemListEditor::_notification(int p_notification) {
|
||||||
if (p_notification == NOTIFICATION_ENTER_TREE || p_notification == NOTIFICATION_THEME_CHANGED) {
|
if (p_notification == NOTIFICATION_ENTER_TREE || p_notification == NOTIFICATION_THEME_CHANGED) {
|
||||||
add_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
|
add_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
|
||||||
|
clear_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
|
||||||
del_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
|
del_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
|
||||||
} else if (p_notification == NOTIFICATION_READY) {
|
} else if (p_notification == NOTIFICATION_READY) {
|
||||||
get_tree()->connect("node_removed", callable_mp(this, &ItemListEditor::_node_removed));
|
get_tree()->connect("node_removed", callable_mp(this, &ItemListEditor::_node_removed));
|
||||||
|
@ -258,6 +259,12 @@ void ItemListEditor::_add_pressed() {
|
||||||
item_plugins[selected_idx]->add_item();
|
item_plugins[selected_idx]->add_item();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemListEditor::_clear_pressed() {
|
||||||
|
for (int i = item_plugins[selected_idx]->get_item_count() - 1; i >= 0; i--) {
|
||||||
|
item_plugins[selected_idx]->erase(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ItemListEditor::_delete_pressed() {
|
void ItemListEditor::_delete_pressed() {
|
||||||
if (selected_idx == -1) {
|
if (selected_idx == -1) {
|
||||||
return;
|
return;
|
||||||
|
@ -350,6 +357,11 @@ ItemListEditor::ItemListEditor() {
|
||||||
|
|
||||||
hbc->add_spacer();
|
hbc->add_spacer();
|
||||||
|
|
||||||
|
clear_button = memnew(Button);
|
||||||
|
clear_button->set_text(TTR("Delete All"));
|
||||||
|
hbc->add_child(clear_button);
|
||||||
|
clear_button->connect("pressed", callable_mp(this, &ItemListEditor::_clear_pressed));
|
||||||
|
|
||||||
del_button = memnew(Button);
|
del_button = memnew(Button);
|
||||||
del_button->set_text(TTR("Delete"));
|
del_button->set_text(TTR("Delete"));
|
||||||
hbc->add_child(del_button);
|
hbc->add_child(del_button);
|
||||||
|
|
|
@ -204,6 +204,7 @@ class ItemListEditor : public HBoxContainer {
|
||||||
Tree *tree;
|
Tree *tree;
|
||||||
Button *add_button;
|
Button *add_button;
|
||||||
Button *del_button;
|
Button *del_button;
|
||||||
|
Button *clear_button;
|
||||||
|
|
||||||
int selected_idx;
|
int selected_idx;
|
||||||
|
|
||||||
|
@ -213,6 +214,7 @@ class ItemListEditor : public HBoxContainer {
|
||||||
|
|
||||||
void _add_pressed();
|
void _add_pressed();
|
||||||
void _delete_pressed();
|
void _delete_pressed();
|
||||||
|
void _clear_pressed();
|
||||||
|
|
||||||
void _node_removed(Node *p_node);
|
void _node_removed(Node *p_node);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue