summaryrefslogtreecommitdiff
path: root/editor/editor_properties.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r--editor/editor_properties.cpp673
1 files changed, 385 insertions, 288 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 6bb4b5e81b..68a3fabe1e 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -30,11 +30,13 @@
#include "editor_properties.h"
+#include "core/config/project_settings.h"
+#include "editor/editor_file_dialog.h"
+#include "editor/editor_node.h"
+#include "editor/editor_properties_array_dict.h"
#include "editor/editor_resource_preview.h"
+#include "editor/editor_scale.h"
#include "editor/filesystem_dock.h"
-#include "editor_node.h"
-#include "editor_properties_array_dict.h"
-#include "editor_scale.h"
#include "scene/2d/gpu_particles_2d.h"
#include "scene/3d/fog_volume.h"
#include "scene/3d/gpu_particles_3d.h"
@@ -164,7 +166,6 @@ void EditorPropertyMultilineText::_notification(int p_what) {
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
text->set_custom_minimum_size(Vector2(0, font->get_height(font_size) * 6));
-
} break;
}
}
@@ -292,11 +293,11 @@ void EditorPropertyTextEnum::_bind_methods() {
void EditorPropertyTextEnum::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
- case NOTIFICATION_THEME_CHANGED:
+ case NOTIFICATION_THEME_CHANGED: {
edit_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
accept_button->set_icon(get_theme_icon(SNAME("ImportCheck"), SNAME("EditorIcons")));
cancel_button->set_icon(get_theme_icon(SNAME("ImportFail"), SNAME("EditorIcons")));
- break;
+ } break;
}
}
@@ -372,8 +373,11 @@ void EditorPropertyLocale::setup(const String &p_hint_text) {
}
void EditorPropertyLocale::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- locale_edit->set_icon(get_theme_icon(SNAME("Translation"), SNAME("EditorIcons")));
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ locale_edit->set_icon(get_theme_icon(SNAME("Translation"), SNAME("EditorIcons")));
+ } break;
}
}
@@ -465,8 +469,11 @@ void EditorPropertyPath::set_save_mode() {
}
void EditorPropertyPath::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- path_edit->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")));
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ path_edit->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")));
+ } break;
}
}
@@ -592,7 +599,7 @@ void EditorPropertyMember::_property_select() {
} else if (hint == MEMBER_PROPERTY_OF_VARIANT_TYPE) {
Variant::Type type = Variant::NIL;
String tname = hint_text;
- if (tname.find(".") != -1) {
+ if (tname.contains(".")) {
tname = tname.get_slice(".", 0);
}
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
@@ -791,261 +798,290 @@ EditorPropertyFlags::EditorPropertyFlags() {
///////////////////// LAYERS /////////////////////////
-class EditorPropertyLayersGrid : public Control {
- GDCLASS(EditorPropertyLayersGrid, Control);
-
-private:
- Vector<Rect2> flag_rects;
- Rect2 expand_rect;
- bool expand_hovered = false;
- bool expanded = false;
- int expansion_rows = 0;
- int hovered_index = -1;
- bool read_only = false;
+void EditorPropertyLayersGrid::_rename_pressed(int p_menu) {
+ // Show rename popup for active layer.
+ if (renamed_layer_index == -1) {
+ return;
+ }
+ String name = names[renamed_layer_index];
+ rename_dialog->set_title(vformat(TTR("Renaming layer %d:"), renamed_layer_index + 1));
+ rename_dialog_text->set_text(name);
+ rename_dialog_text->select(0, name.length());
+ rename_dialog->popup_centered(Size2(300, 80) * EDSCALE);
+ rename_dialog_text->grab_focus();
+}
- Size2 get_grid_size() const {
- Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
- int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
- return Vector2(0, font->get_height(font_size) * 3);
+void EditorPropertyLayersGrid::_rename_operation_confirm() {
+ String new_name = rename_dialog_text->get_text().strip_edges();
+ if (new_name.length() == 0) {
+ EditorNode::get_singleton()->show_warning(TTR("No name provided."));
+ return;
+ } else if (new_name.contains("/") || new_name.contains("\\") || new_name.contains(":")) {
+ EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
+ return;
}
+ names.set(renamed_layer_index, new_name);
+ tooltips.set(renamed_layer_index, new_name + "\n" + vformat(TTR("Bit %d, value %d"), renamed_layer_index, 1 << renamed_layer_index));
+ emit_signal(SNAME("rename_confirmed"), renamed_layer_index, new_name);
+}
+
+EditorPropertyLayersGrid::EditorPropertyLayersGrid() {
+ rename_dialog = memnew(ConfirmationDialog);
+ VBoxContainer *rename_dialog_vb = memnew(VBoxContainer);
+ rename_dialog->add_child(rename_dialog_vb);
+ rename_dialog_text = memnew(LineEdit);
+ rename_dialog_vb->add_margin_child(TTR("Name:"), rename_dialog_text);
+ rename_dialog->get_ok_button()->set_text(TTR("Rename"));
+ add_child(rename_dialog);
+ rename_dialog->register_text_enter(rename_dialog_text);
+ rename_dialog->connect("confirmed", callable_mp(this, &EditorPropertyLayersGrid::_rename_operation_confirm));
+ layer_rename = memnew(PopupMenu);
+ layer_rename->add_item(TTR("Rename layer"), 0);
+ add_child(layer_rename);
+ layer_rename->connect("id_pressed", callable_mp(this, &EditorPropertyLayersGrid::_rename_pressed));
+}
+
+Size2 EditorPropertyLayersGrid::get_grid_size() const {
+ Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
+ int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
+ return Vector2(0, font->get_height(font_size) * 3);
+}
-public:
- uint32_t value = 0;
- int layer_group_size = 0;
- int layer_count = 0;
- Vector<String> names;
- Vector<String> tooltips;
+void EditorPropertyLayersGrid::set_read_only(bool p_read_only) {
+ read_only = p_read_only;
+}
- void set_read_only(bool p_read_only) {
- read_only = p_read_only;
+Size2 EditorPropertyLayersGrid::get_minimum_size() const {
+ Size2 min_size = get_grid_size();
+
+ // Add extra rows when expanded.
+ if (expanded) {
+ const int bsize = (min_size.height * 80 / 100) / 2;
+ for (int i = 0; i < expansion_rows; ++i) {
+ min_size.y += 2 * (bsize + 1) + 3;
+ }
}
- virtual Size2 get_minimum_size() const override {
- Size2 min_size = get_grid_size();
+ return min_size;
+}
- // Add extra rows when expanded.
- if (expanded) {
- const int bsize = (min_size.height * 80 / 100) / 2;
- for (int i = 0; i < expansion_rows; ++i) {
- min_size.y += 2 * (bsize + 1) + 3;
- }
+String EditorPropertyLayersGrid::get_tooltip(const Point2 &p_pos) const {
+ for (int i = 0; i < flag_rects.size(); i++) {
+ if (i < tooltips.size() && flag_rects[i].has_point(p_pos)) {
+ return tooltips[i];
}
-
- return min_size;
}
+ return String();
+}
- virtual String get_tooltip(const Point2 &p_pos) const override {
- for (int i = 0; i < flag_rects.size(); i++) {
- if (i < tooltips.size() && flag_rects[i].has_point(p_pos)) {
- return tooltips[i];
+void EditorPropertyLayersGrid::gui_input(const Ref<InputEvent> &p_ev) {
+ if (read_only) {
+ return;
+ }
+ const Ref<InputEventMouseMotion> mm = p_ev;
+ if (mm.is_valid()) {
+ bool expand_was_hovered = expand_hovered;
+ expand_hovered = expand_rect.has_point(mm->get_position());
+ if (expand_hovered != expand_was_hovered) {
+ update();
+ }
+
+ if (!expand_hovered) {
+ for (int i = 0; i < flag_rects.size(); i++) {
+ if (flag_rects[i].has_point(mm->get_position())) {
+ // Used to highlight the hovered flag in the layers grid.
+ hovered_index = i;
+ update();
+ return;
+ }
}
}
- return String();
- }
- void gui_input(const Ref<InputEvent> &p_ev) override {
- if (read_only) {
- return;
+ // Remove highlight when no square is hovered.
+ if (hovered_index != -1) {
+ hovered_index = -1;
+ update();
}
- const Ref<InputEventMouseMotion> mm = p_ev;
- if (mm.is_valid()) {
- bool expand_was_hovered = expand_hovered;
- expand_hovered = expand_rect.has_point(mm->get_position());
- if (expand_hovered != expand_was_hovered) {
- update();
- }
- if (!expand_hovered) {
- for (int i = 0; i < flag_rects.size(); i++) {
- if (flag_rects[i].has_point(mm->get_position())) {
- // Used to highlight the hovered flag in the layers grid.
- hovered_index = i;
- update();
- return;
- }
- }
- }
+ return;
+ }
- // Remove highlight when no square is hovered.
- if (hovered_index != -1) {
- hovered_index = -1;
- update();
+ const Ref<InputEventMouseButton> mb = p_ev;
+ if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
+ if (hovered_index >= 0) {
+ // Toggle the flag.
+ // We base our choice on the hovered flag, so that it always matches the hovered flag.
+ if (value & (1 << hovered_index)) {
+ value &= ~(1 << hovered_index);
+ } else {
+ value |= (1 << hovered_index);
}
- return;
+ emit_signal(SNAME("flag_changed"), value);
+ update();
+ } else if (expand_hovered) {
+ expanded = !expanded;
+ update_minimum_size();
+ update();
}
-
- const Ref<InputEventMouseButton> mb = p_ev;
- if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
- if (hovered_index >= 0) {
- // Toggle the flag.
- // We base our choice on the hovered flag, so that it always matches the hovered flag.
- if (value & (1 << hovered_index)) {
- value &= ~(1 << hovered_index);
- } else {
- value |= (1 << hovered_index);
- }
-
- emit_signal(SNAME("flag_changed"), value);
- update();
- } else if (expand_hovered) {
- expanded = !expanded;
- update_minimum_size();
- update();
- }
+ }
+ if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
+ if (hovered_index >= 0) {
+ renamed_layer_index = hovered_index;
+ layer_rename->set_position(get_screen_position() + mb->get_position());
+ layer_rename->reset_size();
+ layer_rename->popup();
}
}
+}
- void _notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_DRAW: {
- Size2 grid_size = get_grid_size();
- grid_size.x = get_size().x;
-
- flag_rects.clear();
+void EditorPropertyLayersGrid::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ Size2 grid_size = get_grid_size();
+ grid_size.x = get_size().x;
- int prev_expansion_rows = expansion_rows;
- expansion_rows = 0;
+ flag_rects.clear();
- const int bsize = (grid_size.height * 80 / 100) / 2;
- const int h = bsize * 2 + 1;
+ int prev_expansion_rows = expansion_rows;
+ expansion_rows = 0;
- Color color = get_theme_color(read_only ? SNAME("disabled_highlight_color") : SNAME("highlight_color"), SNAME("Editor"));
+ const int bsize = (grid_size.height * 80 / 100) / 2;
+ const int h = bsize * 2 + 1;
- Color text_color = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_color"), SNAME("Editor"));
- text_color.a *= 0.5;
+ Color color = get_theme_color(read_only ? SNAME("disabled_highlight_color") : SNAME("highlight_color"), SNAME("Editor"));
- Color text_color_on = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_hover_color"), SNAME("Editor"));
- text_color_on.a *= 0.7;
+ Color text_color = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_color"), SNAME("Editor"));
+ text_color.a *= 0.5;
- const int vofs = (grid_size.height - h) / 2;
+ Color text_color_on = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_hover_color"), SNAME("Editor"));
+ text_color_on.a *= 0.7;
- int layer_index = 0;
- int block_index = 0;
+ const int vofs = (grid_size.height - h) / 2;
- Point2 arrow_pos;
+ int layer_index = 0;
+ int block_index = 0;
- Point2 block_ofs(4, vofs);
+ Point2 arrow_pos;
- while (true) {
- Point2 ofs = block_ofs;
+ Point2 block_ofs(4, vofs);
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < layer_group_size; j++) {
- const bool on = value & (1 << layer_index);
- Rect2 rect2 = Rect2(ofs, Size2(bsize, bsize));
+ while (true) {
+ Point2 ofs = block_ofs;
- color.a = on ? 0.6 : 0.2;
- if (layer_index == hovered_index) {
- // Add visual feedback when hovering a flag.
- color.a += 0.15;
- }
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < layer_group_size; j++) {
+ const bool on = value & (1 << layer_index);
+ Rect2 rect2 = Rect2(ofs, Size2(bsize, bsize));
- draw_rect(rect2, color);
- flag_rects.push_back(rect2);
+ color.a = on ? 0.6 : 0.2;
+ if (layer_index == hovered_index) {
+ // Add visual feedback when hovering a flag.
+ color.a += 0.15;
+ }
- Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
- int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
- Vector2 offset;
- offset.y = rect2.size.y * 0.75;
+ draw_rect(rect2, color);
+ flag_rects.push_back(rect2);
- draw_string(font, rect2.position + offset, itos(layer_index + 1), HORIZONTAL_ALIGNMENT_CENTER, rect2.size.x, font_size, on ? text_color_on : text_color);
+ Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
+ int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
+ Vector2 offset;
+ offset.y = rect2.size.y * 0.75;
- ofs.x += bsize + 1;
+ draw_string(font, rect2.position + offset, itos(layer_index + 1), HORIZONTAL_ALIGNMENT_CENTER, rect2.size.x, font_size, on ? text_color_on : text_color);
- ++layer_index;
- }
+ ofs.x += bsize + 1;
- ofs.x = block_ofs.x;
- ofs.y += bsize + 1;
+ ++layer_index;
}
- if (layer_index >= layer_count) {
- if (!flag_rects.is_empty() && (expansion_rows == 0)) {
- const Rect2 &last_rect = flag_rects[flag_rects.size() - 1];
- arrow_pos = last_rect.get_end();
- }
- break;
+ ofs.x = block_ofs.x;
+ ofs.y += bsize + 1;
+ }
+
+ if (layer_index >= layer_count) {
+ if (!flag_rects.is_empty() && (expansion_rows == 0)) {
+ const Rect2 &last_rect = flag_rects[flag_rects.size() - 1];
+ arrow_pos = last_rect.get_end();
}
+ break;
+ }
- int block_size_x = layer_group_size * (bsize + 1);
- block_ofs.x += block_size_x + 3;
+ int block_size_x = layer_group_size * (bsize + 1);
+ block_ofs.x += block_size_x + 3;
- if (block_ofs.x + block_size_x + 12 > grid_size.width) {
- // Keep last valid cell position for the expansion icon.
- if (!flag_rects.is_empty() && (expansion_rows == 0)) {
- const Rect2 &last_rect = flag_rects[flag_rects.size() - 1];
- arrow_pos = last_rect.get_end();
- }
- ++expansion_rows;
-
- if (expanded) {
- // Expand grid to next line.
- block_ofs.x = 4;
- block_ofs.y += 2 * (bsize + 1) + 3;
- } else {
- // Skip remaining blocks.
- break;
- }
+ if (block_ofs.x + block_size_x + 12 > grid_size.width) {
+ // Keep last valid cell position for the expansion icon.
+ if (!flag_rects.is_empty() && (expansion_rows == 0)) {
+ const Rect2 &last_rect = flag_rects[flag_rects.size() - 1];
+ arrow_pos = last_rect.get_end();
+ }
+ ++expansion_rows;
+
+ if (expanded) {
+ // Expand grid to next line.
+ block_ofs.x = 4;
+ block_ofs.y += 2 * (bsize + 1) + 3;
+ } else {
+ // Skip remaining blocks.
+ break;
}
-
- ++block_index;
}
- if ((expansion_rows != prev_expansion_rows) && expanded) {
- update_minimum_size();
- }
+ ++block_index;
+ }
- if ((expansion_rows == 0) && (layer_index == layer_count)) {
- // Whole grid was drawn, no need for expansion icon.
- break;
- }
+ if ((expansion_rows != prev_expansion_rows) && expanded) {
+ update_minimum_size();
+ }
- Ref<Texture2D> arrow = get_theme_icon(SNAME("arrow"), SNAME("Tree"));
- ERR_FAIL_COND(arrow.is_null());
+ if ((expansion_rows == 0) && (layer_index == layer_count)) {
+ // Whole grid was drawn, no need for expansion icon.
+ break;
+ }
- Color arrow_color = get_theme_color(SNAME("highlight_color"), SNAME("Editor"));
- arrow_color.a = expand_hovered ? 1.0 : 0.6;
+ Ref<Texture2D> arrow = get_theme_icon(SNAME("arrow"), SNAME("Tree"));
+ ERR_FAIL_COND(arrow.is_null());
- arrow_pos.x += 2.0;
- arrow_pos.y -= arrow->get_height();
+ Color arrow_color = get_theme_color(SNAME("highlight_color"), SNAME("Editor"));
+ arrow_color.a = expand_hovered ? 1.0 : 0.6;
- Rect2 arrow_draw_rect(arrow_pos, arrow->get_size());
- expand_rect = arrow_draw_rect;
- if (expanded) {
- arrow_draw_rect.size.y *= -1.0; // Flip arrow vertically when expanded.
- }
+ arrow_pos.x += 2.0;
+ arrow_pos.y -= arrow->get_height();
- RID ci = get_canvas_item();
- arrow->draw_rect(ci, arrow_draw_rect, false, arrow_color);
+ Rect2 arrow_draw_rect(arrow_pos, arrow->get_size());
+ expand_rect = arrow_draw_rect;
+ if (expanded) {
+ arrow_draw_rect.size.y *= -1.0; // Flip arrow vertically when expanded.
+ }
- } break;
+ RID ci = get_canvas_item();
+ arrow->draw_rect(ci, arrow_draw_rect, false, arrow_color);
- case NOTIFICATION_MOUSE_EXIT: {
- if (expand_hovered) {
- expand_hovered = false;
- update();
- }
- if (hovered_index != -1) {
- hovered_index = -1;
- update();
- }
- } break;
+ } break;
- default:
- break;
- }
+ case NOTIFICATION_MOUSE_EXIT: {
+ if (expand_hovered) {
+ expand_hovered = false;
+ update();
+ }
+ if (hovered_index != -1) {
+ hovered_index = -1;
+ update();
+ }
+ } break;
}
+}
- void set_flag(uint32_t p_flag) {
- value = p_flag;
- update();
- }
+void EditorPropertyLayersGrid::set_flag(uint32_t p_flag) {
+ value = p_flag;
+ update();
+}
- static void _bind_methods() {
- ADD_SIGNAL(MethodInfo("flag_changed", PropertyInfo(Variant::INT, "flag")));
- }
-};
+void EditorPropertyLayersGrid::_bind_methods() {
+ ADD_SIGNAL(MethodInfo("flag_changed", PropertyInfo(Variant::INT, "flag")));
+ ADD_SIGNAL(MethodInfo("rename_confirmed", PropertyInfo(Variant::INT, "layer_id"), PropertyInfo(Variant::STRING, "new_name")));
+}
void EditorPropertyLayers::_set_read_only(bool p_read_only) {
button->set_disabled(p_read_only);
@@ -1063,7 +1099,7 @@ void EditorPropertyLayers::update_property() {
}
void EditorPropertyLayers::setup(LayerType p_layer_type) {
- String basename;
+ layer_type = p_layer_type;
int layer_group_size = 0;
int layer_count = 0;
switch (p_layer_type) {
@@ -1127,6 +1163,13 @@ void EditorPropertyLayers::setup(LayerType p_layer_type) {
grid->layer_count = layer_count;
}
+void EditorPropertyLayers::set_layer_name(int p_index, const String &p_name) {
+ if (ProjectSettings::get_singleton()->has_setting(basename + vformat("/layer_%d", p_index + 1))) {
+ ProjectSettings::get_singleton()->set(basename + vformat("/layer_%d", p_index + 1), p_name);
+ ProjectSettings::get_singleton()->save();
+ }
+}
+
void EditorPropertyLayers::_button_pressed() {
int layer_count = grid->layer_count;
int layer_group_size = grid->layer_group_size;
@@ -1159,6 +1202,10 @@ void EditorPropertyLayers::_menu_pressed(int p_menu) {
_grid_changed(grid->value);
}
+void EditorPropertyLayers::_refresh_names() {
+ setup(layer_type);
+}
+
void EditorPropertyLayers::_bind_methods() {
}
@@ -1168,6 +1215,7 @@ EditorPropertyLayers::EditorPropertyLayers() {
add_child(hb);
grid = memnew(EditorPropertyLayersGrid);
grid->connect("flag_changed", callable_mp(this, &EditorPropertyLayers::_grid_changed));
+ grid->connect("rename_confirmed", callable_mp(this, &EditorPropertyLayers::set_layer_name));
grid->set_h_size_flags(SIZE_EXPAND_FILL);
hb->add_child(grid);
@@ -1184,6 +1232,7 @@ EditorPropertyLayers::EditorPropertyLayers() {
layers->set_hide_on_checkable_item_selection(false);
layers->connect("id_pressed", callable_mp(this, &EditorPropertyLayers::_menu_pressed));
layers->connect("popup_hide", callable_mp((BaseButton *)button, &BaseButton::set_pressed), varray(false));
+ EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &EditorPropertyLayers::_refresh_names));
}
///////////////////// INT /////////////////////////
@@ -1572,11 +1621,14 @@ void EditorPropertyVector2::update_property() {
}
void EditorPropertyVector2::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 2; i++) {
- spin[i]->set_custom_label_color(true, colors[i]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 2; i++) {
+ spin[i]->set_custom_label_color(true, colors[i]);
+ }
+ } break;
}
}
@@ -1663,11 +1715,14 @@ void EditorPropertyRect2::update_property() {
}
void EditorPropertyRect2::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 4; i++) {
- spin[i]->set_custom_label_color(true, colors[i % 2]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 4; i++) {
+ spin[i]->set_custom_label_color(true, colors[i % 2]);
+ }
+ } break;
}
}
@@ -1789,11 +1844,14 @@ Vector3 EditorPropertyVector3::get_vector() {
}
void EditorPropertyVector3::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 3; i++) {
- spin[i]->set_custom_label_color(true, colors[i]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 3; i++) {
+ spin[i]->set_custom_label_color(true, colors[i]);
+ }
+ } break;
}
}
@@ -1876,11 +1934,14 @@ void EditorPropertyVector2i::update_property() {
}
void EditorPropertyVector2i::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 2; i++) {
- spin[i]->set_custom_label_color(true, colors[i]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 2; i++) {
+ spin[i]->set_custom_label_color(true, colors[i]);
+ }
+ } break;
}
}
@@ -1967,11 +2028,14 @@ void EditorPropertyRect2i::update_property() {
}
void EditorPropertyRect2i::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 4; i++) {
- spin[i]->set_custom_label_color(true, colors[i % 2]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 4; i++) {
+ spin[i]->set_custom_label_color(true, colors[i % 2]);
+ }
+ } break;
}
}
@@ -2066,11 +2130,14 @@ void EditorPropertyVector3i::update_property() {
}
void EditorPropertyVector3i::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 3; i++) {
- spin[i]->set_custom_label_color(true, colors[i]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 3; i++) {
+ spin[i]->set_custom_label_color(true, colors[i]);
+ }
+ } break;
}
}
@@ -2156,11 +2223,14 @@ void EditorPropertyPlane::update_property() {
}
void EditorPropertyPlane::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 4; i++) {
- spin[i]->set_custom_label_color(true, colors[i]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 4; i++) {
+ spin[i]->set_custom_label_color(true, colors[i]);
+ }
+ } break;
}
}
@@ -2247,11 +2317,14 @@ void EditorPropertyQuaternion::update_property() {
}
void EditorPropertyQuaternion::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 4; i++) {
- spin[i]->set_custom_label_color(true, colors[i]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 4; i++) {
+ spin[i]->set_custom_label_color(true, colors[i]);
+ }
+ } break;
}
}
@@ -2341,11 +2414,14 @@ void EditorPropertyAABB::update_property() {
}
void EditorPropertyAABB::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 6; i++) {
- spin[i]->set_custom_label_color(true, colors[i % 3]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 6; i++) {
+ spin[i]->set_custom_label_color(true, colors[i % 3]);
+ }
+ } break;
}
}
@@ -2422,16 +2498,19 @@ void EditorPropertyTransform2D::update_property() {
}
void EditorPropertyTransform2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 6; i++) {
- // For Transform2D, use the 4th color (cyan) for the origin vector.
- if (i % 3 == 2) {
- spin[i]->set_custom_label_color(true, colors[3]);
- } else {
- spin[i]->set_custom_label_color(true, colors[i % 3]);
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 6; i++) {
+ // For Transform2D, use the 4th color (cyan) for the origin vector.
+ if (i % 3 == 2) {
+ spin[i]->set_custom_label_color(true, colors[3]);
+ } else {
+ spin[i]->set_custom_label_color(true, colors[i % 3]);
+ }
}
- }
+ } break;
}
}
@@ -2515,11 +2594,14 @@ void EditorPropertyBasis::update_property() {
}
void EditorPropertyBasis::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 9; i++) {
- spin[i]->set_custom_label_color(true, colors[i % 3]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 9; i++) {
+ spin[i]->set_custom_label_color(true, colors[i % 3]);
+ }
+ } break;
}
}
@@ -2609,11 +2691,14 @@ void EditorPropertyTransform3D::update_using_transform(Transform3D p_transform)
}
void EditorPropertyTransform3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- const Color *colors = _get_property_colors();
- for (int i = 0; i < 12; i++) {
- spin[i]->set_custom_label_color(true, colors[i % 4]);
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ const Color *colors = _get_property_colors();
+ for (int i = 0; i < 12; i++) {
+ spin[i]->set_custom_label_color(true, colors[i % 4]);
+ }
+ } break;
}
}
@@ -2753,7 +2838,7 @@ void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {
}
if (!base_node && get_edited_object()->has_method("get_root_path")) {
- base_node = get_edited_object()->call("get_root_path");
+ base_node = Object::cast_to<Node>(get_edited_object()->call("get_root_path"));
}
if (!base_node && Object::cast_to<RefCounted>(get_edited_object())) {
@@ -2838,7 +2923,7 @@ void EditorPropertyNodePath::update_property() {
Node *target_node = base_node->get_node(p);
ERR_FAIL_COND(!target_node);
- if (String(target_node->get_name()).find("@") != -1) {
+ if (String(target_node->get_name()).contains("@")) {
assign->set_icon(Ref<Texture2D>());
assign->set_text(p);
return;
@@ -2855,9 +2940,12 @@ void EditorPropertyNodePath::setup(const NodePath &p_base_hint, Vector<StringNam
}
void EditorPropertyNodePath::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- Ref<Texture2D> t = get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"));
- clear->set_icon(t);
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ Ref<Texture2D> t = get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"));
+ clear->set_icon(t);
+ } break;
}
}
@@ -3273,9 +3361,9 @@ struct EditorPropertyRangeHint {
bool angle_in_degrees = false;
bool greater = true;
bool lesser = true;
- double min = -99999;
- double max = 99999;
- double step = 0;
+ double min = -99999.0;
+ double max = 99999.0;
+ double step = 1.0;
String suffix;
bool exp_range = false;
bool hide_slider = true;
@@ -3286,18 +3374,25 @@ static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const Stri
EditorPropertyRangeHint hint;
hint.step = p_default_step;
bool degrees = false;
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- hint.greater = false; //if using ranged, assume false by default
+
+ if (p_hint == PROPERTY_HINT_RANGE) {
+ Vector<String> slices = p_hint_text.split(",");
+ ERR_FAIL_COND_V_MSG(slices.size() < 2, hint,
+ vformat("Invalid PROPERTY_HINT_RANGE with hint \"%s\": Missing required min and/or max values.", p_hint_text));
+
+ hint.greater = false; // If using ranged, assume false by default.
hint.lesser = false;
- hint.min = p_hint_text.get_slice(",", 0).to_float();
- hint.max = p_hint_text.get_slice(",", 1).to_float();
- if (p_hint_text.get_slice_count(",") >= 3) {
- hint.step = p_hint_text.get_slice(",", 2).to_float();
+ hint.min = slices[0].to_float();
+ hint.max = slices[1].to_float();
+
+ if (slices.size() >= 3 && slices[2].is_valid_float()) {
+ // Step is optional, could be something else if not a number.
+ hint.step = slices[2].to_float();
}
hint.hide_slider = false;
- for (int i = 2; i < p_hint_text.get_slice_count(","); i++) {
- String slice = p_hint_text.get_slice(",", i).strip_edges();
+ for (int i = 2; i < slices.size(); i++) {
+ String slice = slices[i].strip_edges();
if (slice == "radians") {
hint.radians = true;
} else if (slice == "degrees") {
@@ -3320,6 +3415,9 @@ static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const Stri
hint.suffix = U"\u00B0";
}
+ ERR_FAIL_COND_V_MSG(hint.step == 0, hint,
+ vformat("Invalid PROPERTY_HINT_RANGE with hint \"%s\": Step cannot be 0.", p_hint_text));
+
return hint;
}
@@ -3390,7 +3488,6 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
EditorPropertyInteger *editor = memnew(EditorPropertyInteger);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
-
editor->setup(hint.min, hint.max, hint.step, hint.greater, hint.lesser);
return editor;