Several improvements to inspector.

-Added optional horizontal/vertical modes for vector editing (default false for vec2, true for vec3)
-Some clean ups with fonts and styles
This commit is contained in:
Juan Linietsky 2018-08-07 12:19:19 -03:00
parent 6ffd2d3529
commit 254eb46de3
8 changed files with 151 additions and 55 deletions

View file

@ -43,6 +43,9 @@
Size2 EditorProperty::get_minimum_size() const { Size2 EditorProperty::get_minimum_size() const {
Size2 ms; Size2 ms;
Ref<Font> font = get_font("font", "Tree");
ms.height = font->get_height();
for (int i = 0; i < get_child_count(); i++) { for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i)); Control *c = Object::cast_to<Control>(get_child(i));
@ -70,12 +73,10 @@ Size2 EditorProperty::get_minimum_size() const {
ms.width += check->get_width() + get_constant("hseparator", "Tree"); ms.width += check->get_width() + get_constant("hseparator", "Tree");
} }
if (bottom_editor != NULL) { if (bottom_editor != NULL && bottom_editor->is_visible()) {
Ref<Font> font = get_font("font", "Tree");
ms.height += font->get_height();
ms.height += get_constant("vseparation", "Tree"); ms.height += get_constant("vseparation", "Tree");
Size2 bems = bottom_editor->get_combined_minimum_size(); Size2 bems = bottom_editor->get_combined_minimum_size();
bems.width += get_constant("item_margin", "Tree"); //bems.width += get_constant("item_margin", "Tree");
ms.height += bems.height; ms.height += bems.height;
ms.width = MAX(ms.width, bems.width); ms.width = MAX(ms.width, bems.width);
} }
@ -98,6 +99,7 @@ void EditorProperty::_notification(int p_what) {
int child_room = size.width * (1.0 - split_ratio); int child_room = size.width * (1.0 - split_ratio);
Ref<Font> font = get_font("font", "Tree"); Ref<Font> font = get_font("font", "Tree");
int height = font->get_height(); int height = font->get_height();
bool no_children = true;
//compute room needed //compute room needed
for (int i = 0; i < get_child_count(); i++) { for (int i = 0; i < get_child_count(); i++) {
@ -113,11 +115,16 @@ void EditorProperty::_notification(int p_what) {
Size2 minsize = c->get_combined_minimum_size(); Size2 minsize = c->get_combined_minimum_size();
child_room = MAX(child_room, minsize.width); child_room = MAX(child_room, minsize.width);
height = MAX(height, minsize.height); height = MAX(height, minsize.height);
no_children = false;
} }
text_size = MAX(0, size.width - child_room + 4 * EDSCALE); if (no_children) {
text_size = size.width;
rect = Rect2(text_size, 0, size.width - text_size, height); rect = Rect2(size.width - 1, 0, 1, height);
} else {
text_size = MAX(0, size.width - (child_room + 4 * EDSCALE));
rect = Rect2(size.width - child_room, 0, child_room, height);
}
if (bottom_editor) { if (bottom_editor) {
@ -178,7 +185,7 @@ void EditorProperty::_notification(int p_what) {
draw_style_box(sb, Rect2(Vector2(), size)); draw_style_box(sb, Rect2(Vector2(), size));
} }
if (right_child_rect != Rect2()) { if (draw_top_bg && right_child_rect != Rect2()) {
draw_rect(right_child_rect, dark_color); draw_rect(right_child_rect, dark_color);
} }
if (bottom_child_rect != Rect2()) { if (bottom_child_rect != Rect2()) {
@ -189,7 +196,7 @@ void EditorProperty::_notification(int p_what) {
if (draw_red) { if (draw_red) {
color = get_color("error_color", "Editor"); color = get_color("error_color", "Editor");
} else { } else {
color = get_color("font_color", "Tree"); color = get_color("property_color", "Editor");
} }
if (label.find(".") != -1) { if (label.find(".") != -1) {
color.a = 0.5; //this should be un-hacked honestly, as it's used for editor overrides color.a = 0.5; //this should be un-hacked honestly, as it's used for editor overrides
@ -787,6 +794,8 @@ void EditorProperty::_bind_methods() {
EditorProperty::EditorProperty() { EditorProperty::EditorProperty() {
draw_top_bg = true;
object = NULL;
split_ratio = 0.5; split_ratio = 0.5;
selectable = true; selectable = true;
text_size = 0; text_size = 0;
@ -1613,32 +1622,10 @@ void EditorInspector::update_tree() {
for (List<EditorInspectorPlugin::AddedEditor>::Element *F = editors.front(); F; F = F->next()) { for (List<EditorInspectorPlugin::AddedEditor>::Element *F = editors.front(); F; F = F->next()) {
EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor); EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor);
current_vbox->add_child(F->get().property_editor);
if (ep) { if (ep) {
//set all this before the control gets the ENTER_TREE notification
ep->object = object; ep->object = object;
ep->connect("property_changed", this, "_property_changed");
if (p.usage & PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED) {
ep->connect("property_changed", this, "_property_changed_update_all", varray(), CONNECT_DEFERRED);
}
ep->connect("property_keyed", this, "_property_keyed");
ep->connect("property_keyed_with_value", this, "_property_keyed_with_value");
ep->connect("property_checked", this, "_property_checked");
ep->connect("selected", this, "_property_selected");
ep->connect("multiple_properties_changed", this, "_multiple_properties_changed");
ep->connect("resource_selected", this, "_resource_selected", varray(), CONNECT_DEFERRED);
ep->connect("object_id_selected", this, "_object_id_selected", varray(), CONNECT_DEFERRED);
if (doc_hint != String()) {
ep->set_tooltip(property_prefix + p.name + "::" + doc_hint);
} else {
ep->set_tooltip(property_prefix + p.name);
}
ep->set_draw_red(draw_red);
ep->set_use_folding(use_folding);
ep->set_checkable(checkable);
ep->set_checked(checked);
ep->set_keying(keying);
if (F->get().properties.size()) { if (F->get().properties.size()) {
@ -1664,8 +1651,35 @@ void EditorInspector::update_tree() {
editor_property_map[prop].push_back(ep); editor_property_map[prop].push_back(ep);
} }
} }
ep->set_draw_red(draw_red);
ep->set_use_folding(use_folding);
ep->set_checkable(checkable);
ep->set_checked(checked);
ep->set_keying(keying);
ep->set_read_only(read_only); ep->set_read_only(read_only);
}
current_vbox->add_child(F->get().property_editor);
if (ep) {
ep->connect("property_changed", this, "_property_changed");
if (p.usage & PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED) {
ep->connect("property_changed", this, "_property_changed_update_all", varray(), CONNECT_DEFERRED);
}
ep->connect("property_keyed", this, "_property_keyed");
ep->connect("property_keyed_with_value", this, "_property_keyed_with_value");
ep->connect("property_checked", this, "_property_checked");
ep->connect("selected", this, "_property_selected");
ep->connect("multiple_properties_changed", this, "_multiple_properties_changed");
ep->connect("resource_selected", this, "_resource_selected", varray(), CONNECT_DEFERRED);
ep->connect("object_id_selected", this, "_object_id_selected", varray(), CONNECT_DEFERRED);
if (doc_hint != String()) {
ep->set_tooltip(property_prefix + p.name + "::" + doc_hint);
} else {
ep->set_tooltip(property_prefix + p.name);
}
ep->update_property(); ep->update_property();
ep->update_reload_status(); ep->update_reload_status();

View file

@ -68,6 +68,7 @@ private:
bool can_revert; bool can_revert;
bool use_folding; bool use_folding;
bool draw_top_bg;
bool _might_be_in_instance(); bool _might_be_in_instance();
bool _is_property_different(const Variant &p_current, const Variant &p_orig, int p_usage); bool _is_property_different(const Variant &p_current, const Variant &p_orig, int p_usage);
@ -149,6 +150,8 @@ public:
String get_tooltip_text() const; String get_tooltip_text() const;
void set_draw_top_bg(bool p_draw) { draw_top_bg = p_draw; }
EditorProperty(); EditorProperty();
}; };

View file

@ -4773,6 +4773,8 @@ EditorNode::EditorNode() {
EDITOR_DEF_RST("interface/scene_tabs/show_thumbnail_on_hover", true); EDITOR_DEF_RST("interface/scene_tabs/show_thumbnail_on_hover", true);
EDITOR_DEF_RST("interface/inspector/capitalize_properties", true); EDITOR_DEF_RST("interface/inspector/capitalize_properties", true);
EDITOR_DEF_RST("interface/inspector/disable_folding", false); EDITOR_DEF_RST("interface/inspector/disable_folding", false);
EDITOR_DEF("interface/inspector/horizontal_vector2_editing", false);
EDITOR_DEF("interface/inspector/horizontal_vector3_editing", true);
EDITOR_DEF("interface/inspector/open_resources_in_current_inspector", true); EDITOR_DEF("interface/inspector/open_resources_in_current_inspector", true);
EDITOR_DEF("interface/inspector/resources_types_to_open_in_new_inspector", "SpatialMaterial"); EDITOR_DEF("interface/inspector/resources_types_to_open_in_new_inspector", "SpatialMaterial");
EDITOR_DEF("run/auto_save/save_before_running", true); EDITOR_DEF("run/auto_save/save_before_running", true);

View file

@ -1069,18 +1069,35 @@ void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, boo
} }
EditorPropertyVector2::EditorPropertyVector2() { EditorPropertyVector2::EditorPropertyVector2() {
VBoxContainer *vb = memnew(VBoxContainer); bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector2_editing");
add_child(vb);
BoxContainer *bc;
if (horizontal) {
bc = memnew(HBoxContainer);
add_child(bc);
set_bottom_editor(bc);
} else {
bc = memnew(VBoxContainer);
add_child(bc);
}
static const char *desc[2] = { "x", "y" }; static const char *desc[2] = { "x", "y" };
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
spin[i] = memnew(EditorSpinSlider); spin[i] = memnew(EditorSpinSlider);
spin[i]->set_flat(true); spin[i]->set_flat(true);
spin[i]->set_label(desc[i]); spin[i]->set_label(desc[i]);
vb->add_child(spin[i]); bc->add_child(spin[i]);
add_focusable(spin[i]); add_focusable(spin[i]);
spin[i]->connect("value_changed", this, "_value_changed"); spin[i]->connect("value_changed", this, "_value_changed");
if (horizontal) {
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
}
}
if (!horizontal) {
set_label_reference(spin[0]); //show text and buttons around this
} }
set_label_reference(spin[0]); //show text and buttons around this
setting = false; setting = false;
} }
@ -1195,19 +1212,35 @@ void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, boo
} }
EditorPropertyVector3::EditorPropertyVector3() { EditorPropertyVector3::EditorPropertyVector3() {
VBoxContainer *vb = memnew(VBoxContainer); bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector3_editing");
add_child(vb);
BoxContainer *bc;
if (horizontal) {
bc = memnew(HBoxContainer);
add_child(bc);
set_bottom_editor(bc);
} else {
bc = memnew(VBoxContainer);
add_child(bc);
}
static const char *desc[3] = { "x", "y", "z" }; static const char *desc[3] = { "x", "y", "z" };
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
spin[i] = memnew(EditorSpinSlider); spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]);
spin[i]->set_flat(true); spin[i]->set_flat(true);
spin[i]->set_label(desc[i]);
vb->add_child(spin[i]); bc->add_child(spin[i]);
add_focusable(spin[i]); add_focusable(spin[i]);
spin[i]->connect("value_changed", this, "_value_changed"); spin[i]->connect("value_changed", this, "_value_changed");
if (horizontal) {
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
}
}
if (!horizontal) {
set_label_reference(spin[0]); //show text and buttons around this
} }
set_label_reference(spin[0]); //show text and buttons around this
setting = false; setting = false;
} }
///////////////////// PLANE ///////////////////////// ///////////////////// PLANE /////////////////////////
@ -1259,18 +1292,36 @@ void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool
} }
EditorPropertyPlane::EditorPropertyPlane() { EditorPropertyPlane::EditorPropertyPlane() {
VBoxContainer *vb = memnew(VBoxContainer);
add_child(vb); bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector3_editing");
BoxContainer *bc;
if (horizontal) {
bc = memnew(HBoxContainer);
add_child(bc);
set_bottom_editor(bc);
} else {
bc = memnew(VBoxContainer);
add_child(bc);
}
static const char *desc[4] = { "x", "y", "z", "d" }; static const char *desc[4] = { "x", "y", "z", "d" };
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
spin[i] = memnew(EditorSpinSlider); spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]);
spin[i]->set_flat(true); spin[i]->set_flat(true);
vb->add_child(spin[i]); spin[i]->set_label(desc[i]);
bc->add_child(spin[i]);
add_focusable(spin[i]); add_focusable(spin[i]);
spin[i]->connect("value_changed", this, "_value_changed"); spin[i]->connect("value_changed", this, "_value_changed");
if (horizontal) {
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
}
}
if (!horizontal) {
set_label_reference(spin[0]); //show text and buttons around this
} }
set_label_reference(spin[0]); //show text and buttons around this
setting = false; setting = false;
} }
@ -1323,19 +1374,35 @@ void EditorPropertyQuat::setup(double p_min, double p_max, double p_step, bool p
} }
EditorPropertyQuat::EditorPropertyQuat() { EditorPropertyQuat::EditorPropertyQuat() {
VBoxContainer *vb = memnew(VBoxContainer); bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector3_editing");
add_child(vb);
BoxContainer *bc;
if (horizontal) {
bc = memnew(HBoxContainer);
add_child(bc);
set_bottom_editor(bc);
} else {
bc = memnew(VBoxContainer);
add_child(bc);
}
static const char *desc[4] = { "x", "y", "z", "w" }; static const char *desc[4] = { "x", "y", "z", "w" };
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
spin[i] = memnew(EditorSpinSlider); spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]);
spin[i]->set_flat(true); spin[i]->set_flat(true);
spin[i]->set_label(desc[i]);
vb->add_child(spin[i]); bc->add_child(spin[i]);
add_focusable(spin[i]); add_focusable(spin[i]);
spin[i]->connect("value_changed", this, "_value_changed"); spin[i]->connect("value_changed", this, "_value_changed");
if (horizontal) {
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
}
}
if (!horizontal) {
set_label_reference(spin[0]); //show text and buttons around this
} }
set_label_reference(spin[0]); //show text and buttons around this
setting = false; setting = false;
} }

View file

@ -31,6 +31,11 @@
#include "editor_spin_slider.h" #include "editor_spin_slider.h"
#include "editor_scale.h" #include "editor_scale.h"
#include "os/input.h" #include "os/input.h"
String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const {
return rtos(get_value());
}
String EditorSpinSlider::get_text_value() const { String EditorSpinSlider::get_text_value() const {
int zeros = Math::step_decimals(get_step()); int zeros = Math::step_decimals(get_step());
return String::num(get_value(), zeros); return String::num(get_value(), zeros);

View file

@ -82,6 +82,8 @@ protected:
void _focus_entered(); void _focus_entered();
public: public:
String get_tooltip(const Point2 &p_pos) const;
String get_text_value() const; String get_text_value() const;
void set_label(const String &p_label); void set_label(const String &p_label);
String get_label() const; String get_label() const;

View file

@ -367,6 +367,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
Color success_color = accent_color.linear_interpolate(Color(0.2, 1, 0.2), 0.6) * 1.2; Color success_color = accent_color.linear_interpolate(Color(0.2, 1, 0.2), 0.6) * 1.2;
Color warning_color = accent_color.linear_interpolate(Color(1, 1, 0), 0.7) * 1.2; Color warning_color = accent_color.linear_interpolate(Color(1, 1, 0), 0.7) * 1.2;
Color error_color = accent_color.linear_interpolate(Color(1, 0, 0), 0.8) * 1.7; Color error_color = accent_color.linear_interpolate(Color(1, 0, 0), 0.8) * 1.7;
Color property_color = font_color.linear_interpolate(Color(0.5, 0.5, 0.5), 0.5);
if (!dark_theme) { if (!dark_theme) {
// yellow on white themes is a P.I.T.A. // yellow on white themes is a P.I.T.A.
warning_color = accent_color.linear_interpolate(Color(1, 0.8, 0), 0.9); warning_color = accent_color.linear_interpolate(Color(1, 0.8, 0), 0.9);
@ -377,6 +379,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_color("success_color", "Editor", success_color); theme->set_color("success_color", "Editor", success_color);
theme->set_color("warning_color", "Editor", warning_color); theme->set_color("warning_color", "Editor", warning_color);
theme->set_color("error_color", "Editor", error_color); theme->set_color("error_color", "Editor", error_color);
theme->set_color("property_color", "Editor", property_color);
// 2d grid color // 2d grid color
const Color grid_minor_color = mono_color * Color(1.0, 1.0, 1.0, 0.07); const Color grid_minor_color = mono_color * Color(1.0, 1.0, 1.0, 0.07);

View file

@ -793,13 +793,13 @@ void Spatial::_bind_methods() {
//ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM,"transform/global",PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR ), "set_global_transform", "get_global_transform") ; //ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM,"transform/global",PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR ), "set_global_transform", "get_global_transform") ;
ADD_GROUP("Transform", ""); ADD_GROUP("Transform", "");
ADD_PROPERTYNZ(PropertyInfo(Variant::TRANSFORM, "transform", PROPERTY_HINT_NONE, ""), "set_transform", "get_transform");
ADD_PROPERTYNZ(PropertyInfo(Variant::TRANSFORM, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform"); ADD_PROPERTYNZ(PropertyInfo(Variant::TRANSFORM, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_translation", "get_translation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_translation", "get_translation");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_NONE, "", 0), "set_rotation", "get_rotation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_NONE, "", 0), "set_rotation", "get_rotation");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale");
ADD_GROUP("Matrix", "");
ADD_PROPERTYNZ(PropertyInfo(Variant::TRANSFORM, "transform", PROPERTY_HINT_NONE, ""), "set_transform", "get_transform");
ADD_GROUP("Visibility", ""); ADD_GROUP("Visibility", "");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "SpatialGizmo", 0), "set_gizmo", "get_gizmo"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "SpatialGizmo", 0), "set_gizmo", "get_gizmo");