summaryrefslogtreecommitdiff
path: root/editor/editor_inspector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r--editor/editor_inspector.cpp292
1 files changed, 195 insertions, 97 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index cbfd6ae6de..d94f1d80e5 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -1181,6 +1181,15 @@ void EditorInspectorSection::_notification(int p_what) {
header_height += get_theme_constant(SNAME("vseparation"), SNAME("Tree"));
int inspector_margin = get_theme_constant(SNAME("inspector_margin"), SNAME("Editor"));
+ int section_indent_size = get_theme_constant(SNAME("indent_size"), SNAME("EditorInspectorSection"));
+ if (indent_depth > 0 && section_indent_size > 0) {
+ inspector_margin += indent_depth * section_indent_size;
+ }
+ Ref<StyleBoxFlat> section_indent_style = get_theme_stylebox(SNAME("indent_box"), SNAME("EditorInspectorSection"));
+ if (indent_depth > 0 && section_indent_style.is_valid()) {
+ inspector_margin += section_indent_style->get_margin(SIDE_LEFT) + section_indent_style->get_margin(SIDE_RIGHT);
+ }
+
Size2 size = get_size() - Vector2(inspector_margin, 0);
Vector2 offset = Vector2(is_layout_rtl() ? 0 : inspector_margin, header_height);
for (int i = 0; i < get_child_count(); i++) {
@@ -1216,14 +1225,31 @@ void EditorInspectorSection::_notification(int p_what) {
bool rtl = is_layout_rtl();
- // Compute the height of the section header.
+ // Compute the height and width of the section header.
int header_height = font->get_height(font_size);
if (arrow.is_valid()) {
header_height = MAX(header_height, arrow->get_height());
}
header_height += get_theme_constant(SNAME("vseparation"), SNAME("Tree"));
- Rect2 header_rect = Rect2(Vector2(), Vector2(get_size().width, header_height));
+ int section_indent = 0;
+ int section_indent_size = get_theme_constant(SNAME("indent_size"), SNAME("EditorInspectorSection"));
+ if (indent_depth > 0 && section_indent_size > 0) {
+ section_indent = indent_depth * section_indent_size;
+ }
+ Ref<StyleBoxFlat> section_indent_style = get_theme_stylebox(SNAME("indent_box"), SNAME("EditorInspectorSection"));
+ if (indent_depth > 0 && section_indent_style.is_valid()) {
+ section_indent += section_indent_style->get_margin(SIDE_LEFT) + section_indent_style->get_margin(SIDE_RIGHT);
+ }
+
+ int header_width = get_size().width - section_indent;
+ int header_offset_x = 0.0;
+ if (!rtl) {
+ header_offset_x += section_indent;
+ }
+
+ // Draw header area.
+ Rect2 header_rect = Rect2(Vector2(header_offset_x, 0.0), Vector2(header_width, header_height));
Color c = bg_color;
c.a *= 0.4;
if (foldable && header_rect.has_point(get_local_mouse_position())) {
@@ -1231,24 +1257,46 @@ void EditorInspectorSection::_notification(int p_what) {
}
draw_rect(header_rect, c);
+ // Draw header title and folding arrow.
const int arrow_margin = 2;
const int arrow_width = arrow.is_valid() ? arrow->get_width() : 0;
Color color = get_theme_color(SNAME("font_color"));
- float text_width = get_size().width - Math::round(arrow_width + arrow_margin * EDSCALE);
- draw_string(font, Point2(rtl ? 0 : Math::round(arrow_width + arrow_margin * EDSCALE), font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2).floor(), label, rtl ? HORIZONTAL_ALIGNMENT_RIGHT : HORIZONTAL_ALIGNMENT_LEFT, text_width, font_size, color);
+ float text_width = get_size().width - Math::round(arrow_width + arrow_margin * EDSCALE) - section_indent;
+ Point2 text_offset = Point2(0, font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2);
+ HorizontalAlignment text_align = HORIZONTAL_ALIGNMENT_LEFT;
+ if (rtl) {
+ text_align = HORIZONTAL_ALIGNMENT_RIGHT;
+ } else {
+ text_offset.x = section_indent + Math::round(arrow_width + arrow_margin * EDSCALE);
+ }
+ draw_string(font, text_offset.floor(), label, text_align, text_width, font_size, color);
if (arrow.is_valid()) {
+ Point2 arrow_position = Point2(0, (header_height - arrow->get_height()) / 2);
if (rtl) {
- draw_texture(arrow, Point2(get_size().width - arrow->get_width() - Math::round(arrow_margin * EDSCALE), (header_height - arrow->get_height()) / 2).floor());
+ arrow_position.x = get_size().width - section_indent - arrow->get_width() - Math::round(arrow_margin * EDSCALE);
} else {
- draw_texture(arrow, Point2(Math::round(arrow_margin * EDSCALE), (header_height - arrow->get_height()) / 2).floor());
+ arrow_position.x = section_indent + Math::round(arrow_margin * EDSCALE);
}
+ draw_texture(arrow, arrow_position.floor());
}
+ // Draw dropping highlight.
if (dropping && !vbox->is_visible_in_tree()) {
Color accent_color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
draw_rect(Rect2(Point2(), get_size()), accent_color, false);
}
+
+ // Draw section indentation.
+ if (section_indent_style.is_valid() && section_indent > 0) {
+ Rect2 indent_rect = Rect2(Vector2(), Vector2(indent_depth * section_indent_size, get_size().height));
+ if (rtl) {
+ indent_rect.position.x = get_size().width - section_indent + section_indent_style->get_margin(SIDE_RIGHT);
+ } else {
+ indent_rect.position.x = section_indent_style->get_margin(SIDE_LEFT);
+ }
+ draw_style_box(section_indent_style, indent_rect);
+ }
} break;
case NOTIFICATION_DRAG_BEGIN: {
Dictionary dd = get_viewport()->gui_get_drag_data();
@@ -1311,15 +1359,25 @@ Size2 EditorInspectorSection::get_minimum_size() const {
ms.height += font->get_height(font_size) + get_theme_constant(SNAME("vseparation"), SNAME("Tree"));
ms.width += get_theme_constant(SNAME("inspector_margin"), SNAME("Editor"));
+ int section_indent_size = get_theme_constant(SNAME("indent_size"), SNAME("EditorInspectorSection"));
+ if (indent_depth > 0 && section_indent_size > 0) {
+ ms.width += indent_depth * section_indent_size;
+ }
+ Ref<StyleBoxFlat> section_indent_style = get_theme_stylebox(SNAME("indent_box"), SNAME("EditorInspectorSection"));
+ if (indent_depth > 0 && section_indent_style.is_valid()) {
+ ms.width += section_indent_style->get_margin(SIDE_LEFT) + section_indent_style->get_margin(SIDE_RIGHT);
+ }
+
return ms;
}
-void EditorInspectorSection::setup(const String &p_section, const String &p_label, Object *p_object, const Color &p_bg_color, bool p_foldable) {
+void EditorInspectorSection::setup(const String &p_section, const String &p_label, Object *p_object, const Color &p_bg_color, bool p_foldable, int p_indent_depth) {
section = p_section;
label = p_label;
object = p_object;
bg_color = p_bg_color;
foldable = p_foldable;
+ indent_depth = p_indent_depth;
if (!foldable && !vbox_added) {
add_child(vbox);
@@ -1401,12 +1459,8 @@ void EditorInspectorSection::_bind_methods() {
}
EditorInspectorSection::EditorInspectorSection() {
- object = nullptr;
- foldable = false;
vbox = memnew(VBoxContainer);
- vbox_added = false;
- dropping = false;
dropping_unfold_timer = memnew(Timer);
dropping_unfold_timer->set_wait_time(0.6);
dropping_unfold_timer->set_one_shot(true);
@@ -1422,6 +1476,7 @@ EditorInspectorSection::~EditorInspectorSection() {
////////////////////////////////////////////////
////////////////////////////////////////////////
+
int EditorInspectorArray::_get_array_count() {
if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {
List<PropertyInfo> object_property_list;
@@ -1440,31 +1495,8 @@ void EditorInspectorArray::_add_button_pressed() {
_move_element(-1, -1);
}
-void EditorInspectorArray::_first_page_button_pressed() {
- emit_signal(SNAME("page_change_request"), 0);
-}
-
-void EditorInspectorArray::_prev_page_button_pressed() {
- emit_signal(SNAME("page_change_request"), MAX(0, page - 1));
-}
-
-void EditorInspectorArray::_page_line_edit_text_submitted(String p_text) {
- if (p_text.is_valid_int()) {
- int new_page = p_text.to_int() - 1;
- new_page = MIN(MAX(0, new_page), max_page);
- page_line_edit->set_text(Variant(new_page));
- emit_signal(SNAME("page_change_request"), new_page);
- } else {
- page_line_edit->set_text(Variant(page));
- }
-}
-
-void EditorInspectorArray::_next_page_button_pressed() {
- emit_signal(SNAME("page_change_request"), MIN(max_page, page + 1));
-}
-
-void EditorInspectorArray::_last_page_button_pressed() {
- emit_signal(SNAME("page_change_request"), max_page);
+void EditorInspectorArray::_paginator_page_changed(int p_page) {
+ emit_signal("page_change_request", p_page);
}
void EditorInspectorArray::_rmb_popup_id_pressed(int p_id) {
@@ -1636,17 +1668,17 @@ void EditorInspectorArray::_move_element(int p_element_index, int p_to_pos) {
// Handle page change and update counts.
if (p_element_index < 0) {
int added_index = p_to_pos < 0 ? count : p_to_pos;
- emit_signal(SNAME("page_change_request"), added_index / page_lenght);
+ emit_signal(SNAME("page_change_request"), added_index / page_length);
count += 1;
} else if (p_to_pos < 0) {
count -= 1;
- if (page == max_page && (MAX(0, count - 1) / page_lenght != max_page)) {
+ if (page == max_page && (MAX(0, count - 1) / page_length != max_page)) {
emit_signal(SNAME("page_change_request"), max_page - 1);
}
}
- begin_array_index = page * page_lenght;
- end_array_index = MIN(count, (page + 1) * page_lenght);
- max_page = MAX(0, count - 1) / page_lenght;
+ begin_array_index = page * page_length;
+ end_array_index = MIN(count, (page + 1) * page_length);
+ max_page = MAX(0, count - 1) / page_length;
}
void EditorInspectorArray::_clear_array() {
@@ -1860,9 +1892,9 @@ void EditorInspectorArray::_resize_dialog_confirmed() {
void EditorInspectorArray::_setup() {
// Setup counts.
count = _get_array_count();
- begin_array_index = page * page_lenght;
- end_array_index = MIN(count, (page + 1) * page_lenght);
- max_page = MAX(0, count - 1) / page_lenght;
+ begin_array_index = page * page_length;
+ end_array_index = MIN(count, (page + 1) * page_length);
+ max_page = MAX(0, count - 1) / page_length;
array_elements.resize(MAX(0, end_array_index - begin_array_index));
if (page < 0 || page > max_page) {
WARN_PRINT(vformat("Invalid page number %d", page));
@@ -1920,18 +1952,12 @@ void EditorInspectorArray::_setup() {
// Hide/show the add button.
add_button->set_visible(page == max_page);
- if (max_page == 0) {
- hbox_pagination->hide();
- } else {
- // Update buttons.
- first_page_button->set_disabled(page == 0);
- prev_page_button->set_disabled(page == 0);
- next_page_button->set_disabled(page == max_page);
- last_page_button->set_disabled(page == max_page);
-
- // Update page number and page count.
- page_line_edit->set_text(vformat("%d", page + 1));
- page_count_label->set_text(vformat("/ %d", max_page + 1));
+ // Add paginator if there's more than 1 page.
+ if (max_page > 0) {
+ EditorPaginator *paginator = memnew(EditorPaginator);
+ paginator->update(page, max_page);
+ paginator->connect("page_changed", callable_mp(this, &EditorInspectorArray::_paginator_page_changed));
+ vbox->add_child(paginator);
}
}
@@ -1996,10 +2022,6 @@ void EditorInspectorArray::_notification(int p_what) {
}
add_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
- first_page_button->set_icon(get_theme_icon(SNAME("PageFirst"), SNAME("EditorIcons")));
- prev_page_button->set_icon(get_theme_icon(SNAME("PagePrevious"), SNAME("EditorIcons")));
- next_page_button->set_icon(get_theme_icon(SNAME("PageNext"), SNAME("EditorIcons")));
- last_page_button->set_icon(get_theme_icon(SNAME("PageLast"), SNAME("EditorIcons")));
update_minimum_size();
} break;
case NOTIFICATION_DRAG_BEGIN: {
@@ -2036,7 +2058,7 @@ void EditorInspectorArray::setup_with_move_element_function(Object *p_object, St
array_element_prefix = p_array_element_prefix;
page = p_page;
- EditorInspectorSection::setup(String(p_array_element_prefix) + "_array", p_label, p_object, p_bg_color, p_foldable);
+ EditorInspectorSection::setup(String(p_array_element_prefix) + "_array", p_label, p_object, p_bg_color, p_foldable, 0);
_setup();
}
@@ -2047,7 +2069,7 @@ void EditorInspectorArray::setup_with_count_property(Object *p_object, String p_
array_element_prefix = p_array_element_prefix;
page = p_page;
- EditorInspectorSection::setup(String(count_property) + "_array", p_label, p_object, p_bg_color, p_foldable);
+ EditorInspectorSection::setup(String(count_property) + "_array", p_label, p_object, p_bg_color, p_foldable, 0);
_setup();
}
@@ -2092,38 +2114,6 @@ EditorInspectorArray::EditorInspectorArray() {
add_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_add_button_pressed));
vbox->add_child(add_button);
- hbox_pagination = memnew(HBoxContainer);
- hbox_pagination->set_h_size_flags(SIZE_EXPAND_FILL);
- hbox_pagination->set_alignment(BoxContainer::ALIGNMENT_CENTER);
- vbox->add_child(hbox_pagination);
-
- first_page_button = memnew(Button);
- first_page_button->set_flat(true);
- first_page_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_first_page_button_pressed));
- hbox_pagination->add_child(first_page_button);
-
- prev_page_button = memnew(Button);
- prev_page_button->set_flat(true);
- prev_page_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_prev_page_button_pressed));
- hbox_pagination->add_child(prev_page_button);
-
- page_line_edit = memnew(LineEdit);
- page_line_edit->connect("text_submitted", callable_mp(this, &EditorInspectorArray::_page_line_edit_text_submitted));
- page_line_edit->add_theme_constant_override("minimum_character_width", 2);
- hbox_pagination->add_child(page_line_edit);
-
- page_count_label = memnew(Label);
- hbox_pagination->add_child(page_count_label);
- next_page_button = memnew(Button);
- next_page_button->set_flat(true);
- next_page_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_next_page_button_pressed));
- hbox_pagination->add_child(next_page_button);
-
- last_page_button = memnew(Button);
- last_page_button->set_flat(true);
- last_page_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_last_page_button_pressed));
- hbox_pagination->add_child(last_page_button);
-
control_dropping = memnew(Control);
control_dropping->connect("draw", callable_mp(this, &EditorInspectorArray::_control_dropping_draw));
control_dropping->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
@@ -2149,6 +2139,97 @@ EditorInspectorArray::EditorInspectorArray() {
////////////////////////////////////////////////
////////////////////////////////////////////////
+void EditorPaginator::_first_page_button_pressed() {
+ emit_signal("page_changed", 0);
+}
+
+void EditorPaginator::_prev_page_button_pressed() {
+ emit_signal("page_changed", MAX(0, page - 1));
+}
+
+void EditorPaginator::_page_line_edit_text_submitted(String p_text) {
+ if (p_text.is_valid_int()) {
+ int new_page = p_text.to_int() - 1;
+ new_page = MIN(MAX(0, new_page), max_page);
+ page_line_edit->set_text(Variant(new_page));
+ emit_signal("page_changed", new_page);
+ } else {
+ page_line_edit->set_text(Variant(page));
+ }
+}
+
+void EditorPaginator::_next_page_button_pressed() {
+ emit_signal("page_changed", MIN(max_page, page + 1));
+}
+
+void EditorPaginator::_last_page_button_pressed() {
+ emit_signal("page_changed", max_page);
+}
+
+void EditorPaginator::update(int p_page, int p_max_page) {
+ page = p_page;
+ max_page = p_max_page;
+
+ // Update buttons.
+ first_page_button->set_disabled(page == 0);
+ prev_page_button->set_disabled(page == 0);
+ next_page_button->set_disabled(page == max_page);
+ last_page_button->set_disabled(page == max_page);
+
+ // Update page number and page count.
+ page_line_edit->set_text(vformat("%d", page + 1));
+ page_count_label->set_text(vformat("/ %d", max_page + 1));
+}
+
+void EditorPaginator::_notification(int p_what) {
+ if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
+ first_page_button->set_icon(get_theme_icon(SNAME("PageFirst"), SNAME("EditorIcons")));
+ prev_page_button->set_icon(get_theme_icon(SNAME("PagePrevious"), SNAME("EditorIcons")));
+ next_page_button->set_icon(get_theme_icon(SNAME("PageNext"), SNAME("EditorIcons")));
+ last_page_button->set_icon(get_theme_icon(SNAME("PageLast"), SNAME("EditorIcons")));
+ }
+}
+
+void EditorPaginator::_bind_methods() {
+ ADD_SIGNAL(MethodInfo("page_changed", PropertyInfo(Variant::INT, "page")));
+}
+
+EditorPaginator::EditorPaginator() {
+ set_h_size_flags(SIZE_EXPAND_FILL);
+ set_alignment(ALIGNMENT_CENTER);
+
+ first_page_button = memnew(Button);
+ first_page_button->set_flat(true);
+ first_page_button->connect("pressed", callable_mp(this, &EditorPaginator::_first_page_button_pressed));
+ add_child(first_page_button);
+
+ prev_page_button = memnew(Button);
+ prev_page_button->set_flat(true);
+ prev_page_button->connect("pressed", callable_mp(this, &EditorPaginator::_prev_page_button_pressed));
+ add_child(prev_page_button);
+
+ page_line_edit = memnew(LineEdit);
+ page_line_edit->connect("text_submitted", callable_mp(this, &EditorPaginator::_page_line_edit_text_submitted));
+ page_line_edit->add_theme_constant_override("minimum_character_width", 2);
+ add_child(page_line_edit);
+
+ page_count_label = memnew(Label);
+ add_child(page_count_label);
+
+ next_page_button = memnew(Button);
+ next_page_button->set_flat(true);
+ next_page_button->connect("pressed", callable_mp(this, &EditorPaginator::_next_page_button_pressed));
+ add_child(next_page_button);
+
+ last_page_button = memnew(Button);
+ last_page_button->set_flat(true);
+ last_page_button->connect("pressed", callable_mp(this, &EditorPaginator::_last_page_button_pressed));
+ add_child(last_page_button);
+}
+
+////////////////////////////////////////////////
+////////////////////////////////////////////////
+
Ref<EditorInspectorPlugin> EditorInspector::inspector_plugins[MAX_PLUGINS];
int EditorInspector::inspector_plugin_count = 0;
@@ -2349,6 +2430,7 @@ void EditorInspector::update_tree() {
String group_base;
String subgroup;
String subgroup_base;
+ int section_depth = 0;
VBoxContainer *category_vbox = nullptr;
List<PropertyInfo> plist;
@@ -2373,14 +2455,29 @@ void EditorInspector::update_tree() {
if (p.usage & PROPERTY_USAGE_SUBGROUP) {
// Setup a property sub-group.
subgroup = p.name;
- subgroup_base = p.hint_string;
+
+ Vector<String> hint_parts = p.hint_string.split(",");
+ subgroup_base = hint_parts[0];
+ if (hint_parts.size() > 1) {
+ section_depth = hint_parts[1].to_int();
+ } else {
+ section_depth = 0;
+ }
continue;
} else if (p.usage & PROPERTY_USAGE_GROUP) {
// Setup a property group.
group = p.name;
- group_base = p.hint_string;
+
+ Vector<String> hint_parts = p.hint_string.split(",");
+ group_base = hint_parts[0];
+ if (hint_parts.size() > 1) {
+ section_depth = hint_parts[1].to_int();
+ } else {
+ section_depth = 0;
+ }
+
subgroup = "";
subgroup_base = "";
@@ -2392,6 +2489,7 @@ void EditorInspector::update_tree() {
group_base = "";
subgroup = "";
subgroup_base = "";
+ section_depth = 0;
if (!show_categories) {
continue;
@@ -2633,7 +2731,7 @@ void EditorInspector::update_tree() {
Color c = sscolor;
c.a /= level;
- section->setup(acc_path, component, object, c, use_folding);
+ section->setup(acc_path, component, object, c, use_folding, section_depth);
// Add editors at the start of a group.
for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {