Merge pull request #67867 from timothyqiu/named-layer-3.x

[3.x] Only show named layers in layer menu
This commit is contained in:
Rémi Verschelde 2022-10-31 14:00:30 +01:00
commit 0e19672656
No known key found for this signature in database
GPG key ID: C3336907360768E1
5 changed files with 54 additions and 27 deletions

View file

@ -32,6 +32,7 @@
#include "editor/editor_resource_preview.h"
#include "editor/filesystem_dock.h"
#include "editor/project_settings_editor.h"
#include "editor_node.h"
#include "editor_properties_array_dict.h"
#include "editor_scale.h"
@ -1015,7 +1016,6 @@ void EditorPropertyLayers::update_property() {
void EditorPropertyLayers::setup(LayerType p_layer_type) {
layer_type = p_layer_type;
String basename;
int layer_group_size = 0;
int layer_count = 0;
switch (p_layer_type) {
@ -1059,13 +1059,8 @@ void EditorPropertyLayers::setup(LayerType p_layer_type) {
Vector<String> names;
Vector<String> tooltips;
for (int i = 0; i < layer_count; i++) {
String name;
if (ProjectSettings::get_singleton()->has_setting(basename + "/layer_" + itos(i + 1))) {
name = ProjectSettings::get_singleton()->get(basename + "/layer_" + itos(i + 1));
}
if (name == "") {
String name = _get_layer_name(i);
if (name.empty()) {
name = TTR("Layer") + " " + itos(i + 1);
}
@ -1081,18 +1076,25 @@ void EditorPropertyLayers::setup(LayerType p_layer_type) {
void EditorPropertyLayers::_button_pressed() {
int layer_count = grid->layer_count;
int layer_group_size = grid->layer_group_size;
layers->clear();
for (int i = 0; i < layer_count; i++) {
if ((i != 0) && ((i % layer_group_size) == 0)) {
layers->add_separator();
const String name = _get_layer_name(i);
if (name.empty()) {
continue;
}
layers->add_check_item(grid->names[i], i);
layers->add_check_item(name, i);
int idx = layers->get_item_index(i);
layers->set_item_checked(idx, grid->value & (1 << i));
}
if (layers->get_item_count() == 0) {
layers->add_item(TTR("No Named Layers"));
layers->set_item_disabled(0, true);
}
layers->add_separator();
layers->add_icon_item(get_icon("Edit", "EditorIcons"), TTR("Edit Layer Names"), grid->layer_count);
Rect2 gp = button->get_global_rect();
layers->set_as_minsize();
Vector2 popup_pos = gp.position - Vector2(layers->get_combined_minimum_size().x, 0);
@ -1101,20 +1103,33 @@ void EditorPropertyLayers::_button_pressed() {
}
void EditorPropertyLayers::_menu_pressed(int p_menu) {
if (grid->value & (1 << p_menu)) {
grid->value &= ~(1 << p_menu);
if (p_menu == grid->layer_count) {
ProjectSettingsEditor::get_singleton()->popup_project_settings();
ProjectSettingsEditor::get_singleton()->set_general_page(basename);
} else {
grid->value |= (1 << p_menu);
if (grid->value & (1 << p_menu)) {
grid->value &= ~(1 << p_menu);
} else {
grid->value |= (1 << p_menu);
}
grid->update();
layers->set_item_checked(layers->get_item_index(p_menu), grid->value & (1 << p_menu));
_grid_changed(grid->value);
}
grid->update();
layers->set_item_checked(layers->get_item_index(p_menu), grid->value & (1 << p_menu));
_grid_changed(grid->value);
}
void EditorPropertyLayers::_refresh_names() {
setup(layer_type);
}
String EditorPropertyLayers::_get_layer_name(int p_index) const {
const String property_name = basename + vformat("/layer_%d", p_index + 1);
if (ProjectSettings::get_singleton()->has_setting(property_name)) {
return ProjectSettings::get_singleton()->get(property_name);
}
return String();
}
void EditorPropertyLayers::_bind_methods() {
ClassDB::bind_method(D_METHOD("_grid_changed"), &EditorPropertyLayers::_grid_changed);
ClassDB::bind_method(D_METHOD("_button_pressed"), &EditorPropertyLayers::_button_pressed);

View file

@ -269,11 +269,14 @@ private:
LayerType layer_type;
PopupMenu *layers;
Button *button;
String basename;
void _button_pressed();
void _menu_pressed(int p_menu);
void _refresh_names();
String _get_layer_name(int p_index) const;
protected:
static void _bind_methods();

View file

@ -164,7 +164,9 @@ void SectionedInspector::_section_selected() {
void SectionedInspector::set_current_section(const String &p_section) {
if (section_map.has(p_section)) {
section_map[p_section]->select(0);
TreeItem *item = section_map[p_section];
item->select(0);
sections->scroll_to_item(item);
}
}

View file

@ -1555,6 +1555,11 @@ void ProjectSettingsEditor::set_plugins_page() {
tab_container->set_current_tab(plugin_settings->get_index());
}
void ProjectSettingsEditor::set_general_page(const String &p_category) {
tab_container->set_current_tab(general_editor->get_index());
globals_editor->set_current_section(p_category);
}
TabContainer *ProjectSettingsEditor::get_tabs() {
return tab_container;
}
@ -1651,15 +1656,15 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
tab_container->set_use_hidden_tabs_for_min_size(true);
add_child(tab_container);
VBoxContainer *props_base = memnew(VBoxContainer);
props_base->set_alignment(BoxContainer::ALIGN_BEGIN);
props_base->set_v_size_flags(Control::SIZE_EXPAND_FILL);
tab_container->add_child(props_base);
props_base->set_name(TTR("General"));
general_editor = memnew(VBoxContainer);
general_editor->set_alignment(BoxContainer::ALIGN_BEGIN);
general_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
tab_container->add_child(general_editor);
general_editor->set_name(TTR("General"));
HBoxContainer *hbc = memnew(HBoxContainer);
hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
props_base->add_child(hbc);
general_editor->add_child(hbc);
search_button = memnew(Button);
search_button->set_toggle_mode(true);
@ -1707,7 +1712,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
search_bar->add_child(search_box);
globals_editor = memnew(SectionedInspector);
props_base->add_child(globals_editor);
general_editor->add_child(globals_editor);
globals_editor->get_inspector()->set_undo_redo(EditorNode::get_singleton()->get_undo_redo());
globals_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
globals_editor->register_search_box(search_box);
@ -1734,7 +1739,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
set_hide_on_ok(true);
restart_container = memnew(PanelContainer);
props_base->add_child(restart_container);
general_editor->add_child(restart_container);
HBoxContainer *restart_hb = memnew(HBoxContainer);
restart_container->add_child(restart_hb);
restart_icon = memnew(TextureRect);

View file

@ -53,6 +53,7 @@ class ProjectSettingsEditor : public AcceptDialog {
};
TabContainer *tab_container;
VBoxContainer *general_editor;
Timer *timer;
InputType add_type;
@ -185,6 +186,7 @@ public:
static ProjectSettingsEditor *get_singleton() { return singleton; }
void popup_project_settings();
void set_plugins_page();
void set_general_page(const String &p_category);
void update_plugins();
EditorAutoloadSettings *get_autoload_settings() { return autoload_settings; }