Utilize space better with BBParam property editor
For types that need more space, the bottom editor will be used instead. In effect also for string parameters with @export_multiline.
This commit is contained in:
parent
c63785b5bc
commit
17a480ed19
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
#include "editor_property_bb_param.h"
|
#include "editor_property_bb_param.h"
|
||||||
|
|
||||||
#include "core/variant/variant.h"
|
|
||||||
#include "modules/limboai/blackboard/bb_param/bb_param.h"
|
#include "modules/limboai/blackboard/bb_param/bb_param.h"
|
||||||
#include "modules/limboai/blackboard/bb_param/bb_variant.h"
|
#include "modules/limboai/blackboard/bb_param/bb_variant.h"
|
||||||
#include "modules/limboai/editor/mode_switch_button.h"
|
#include "modules/limboai/editor/mode_switch_button.h"
|
||||||
|
@ -23,9 +22,11 @@
|
||||||
#include "core/error/error_macros.h"
|
#include "core/error/error_macros.h"
|
||||||
#include "core/io/marshalls.h"
|
#include "core/io/marshalls.h"
|
||||||
#include "core/object/class_db.h"
|
#include "core/object/class_db.h"
|
||||||
|
#include "core/object/object.h"
|
||||||
#include "core/object/ref_counted.h"
|
#include "core/object/ref_counted.h"
|
||||||
#include "core/os/memory.h"
|
#include "core/os/memory.h"
|
||||||
#include "core/string/print_string.h"
|
#include "core/string/print_string.h"
|
||||||
|
#include "core/variant/variant.h"
|
||||||
#include "editor/editor_inspector.h"
|
#include "editor/editor_inspector.h"
|
||||||
#include "editor/editor_properties.h"
|
#include "editor/editor_properties.h"
|
||||||
#include "editor/editor_properties_array_dict.h"
|
#include "editor/editor_properties_array_dict.h"
|
||||||
|
@ -55,6 +56,8 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) {
|
||||||
_remove_value_editor();
|
_remove_value_editor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_bottom = false;
|
||||||
|
|
||||||
switch (p_type) {
|
switch (p_type) {
|
||||||
case Variant::NIL: {
|
case Variant::NIL: {
|
||||||
value_editor = memnew(EditorPropertyNil);
|
value_editor = memnew(EditorPropertyNil);
|
||||||
|
@ -78,6 +81,7 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) {
|
||||||
} else {
|
} else {
|
||||||
value_editor = memnew(EditorPropertyText);
|
value_editor = memnew(EditorPropertyText);
|
||||||
}
|
}
|
||||||
|
is_bottom = (property_hint == PROPERTY_HINT_MULTILINE_TEXT);
|
||||||
} break;
|
} break;
|
||||||
case Variant::VECTOR2: {
|
case Variant::VECTOR2: {
|
||||||
EditorPropertyVector2 *editor = memnew(EditorPropertyVector2);
|
EditorPropertyVector2 *editor = memnew(EditorPropertyVector2);
|
||||||
|
@ -93,66 +97,79 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) {
|
||||||
EditorPropertyRect2 *editor = memnew(EditorPropertyRect2);
|
EditorPropertyRect2 *editor = memnew(EditorPropertyRect2);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::RECT2I: {
|
case Variant::RECT2I: {
|
||||||
EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i);
|
EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i);
|
||||||
editor->setup(-100000, 100000);
|
editor->setup(-100000, 100000);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::VECTOR3: {
|
case Variant::VECTOR3: {
|
||||||
EditorPropertyVector3 *editor = memnew(EditorPropertyVector3);
|
EditorPropertyVector3 *editor = memnew(EditorPropertyVector3);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::VECTOR3I: {
|
case Variant::VECTOR3I: {
|
||||||
EditorPropertyVector3i *editor = memnew(EditorPropertyVector3i);
|
EditorPropertyVector3i *editor = memnew(EditorPropertyVector3i);
|
||||||
editor->setup(-100000, 100000);
|
editor->setup(-100000, 100000);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::VECTOR4: {
|
case Variant::VECTOR4: {
|
||||||
EditorPropertyVector4 *editor = memnew(EditorPropertyVector4);
|
EditorPropertyVector4 *editor = memnew(EditorPropertyVector4);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::VECTOR4I: {
|
case Variant::VECTOR4I: {
|
||||||
EditorPropertyVector4i *editor = memnew(EditorPropertyVector4i);
|
EditorPropertyVector4i *editor = memnew(EditorPropertyVector4i);
|
||||||
editor->setup(-100000, 100000);
|
editor->setup(-100000, 100000);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::TRANSFORM2D: {
|
case Variant::TRANSFORM2D: {
|
||||||
EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D);
|
EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::PLANE: {
|
case Variant::PLANE: {
|
||||||
EditorPropertyPlane *editor = memnew(EditorPropertyPlane);
|
EditorPropertyPlane *editor = memnew(EditorPropertyPlane);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::QUATERNION: {
|
case Variant::QUATERNION: {
|
||||||
EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
|
EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::AABB: {
|
case Variant::AABB: {
|
||||||
EditorPropertyAABB *editor = memnew(EditorPropertyAABB);
|
EditorPropertyAABB *editor = memnew(EditorPropertyAABB);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::BASIS: {
|
case Variant::BASIS: {
|
||||||
EditorPropertyBasis *editor = memnew(EditorPropertyBasis);
|
EditorPropertyBasis *editor = memnew(EditorPropertyBasis);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::TRANSFORM3D: {
|
case Variant::TRANSFORM3D: {
|
||||||
EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D);
|
EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::PROJECTION: {
|
case Variant::PROJECTION: {
|
||||||
EditorPropertyProjection *editor = memnew(EditorPropertyProjection);
|
EditorPropertyProjection *editor = memnew(EditorPropertyProjection);
|
||||||
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::COLOR: {
|
case Variant::COLOR: {
|
||||||
value_editor = memnew(EditorPropertyColor);
|
value_editor = memnew(EditorPropertyColor);
|
||||||
|
@ -161,6 +178,7 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) {
|
||||||
EditorPropertyText *editor = memnew(EditorPropertyText);
|
EditorPropertyText *editor = memnew(EditorPropertyText);
|
||||||
editor->set_string_name(true);
|
editor->set_string_name(true);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = (property_hint == PROPERTY_HINT_MULTILINE_TEXT);
|
||||||
} break;
|
} break;
|
||||||
case Variant::NODE_PATH: {
|
case Variant::NODE_PATH: {
|
||||||
value_editor = memnew(EditorPropertyNodePath);
|
value_editor = memnew(EditorPropertyNodePath);
|
||||||
|
@ -176,9 +194,11 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) {
|
||||||
EditorPropertyResource *editor = memnew(EditorPropertyResource);
|
EditorPropertyResource *editor = memnew(EditorPropertyResource);
|
||||||
editor->setup(_get_edited_param().ptr(), SNAME("saved_value"), "Resource");
|
editor->setup(_get_edited_param().ptr(), SNAME("saved_value"), "Resource");
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
case Variant::DICTIONARY: {
|
case Variant::DICTIONARY: {
|
||||||
value_editor = memnew(EditorPropertyDictionary);
|
value_editor = memnew(EditorPropertyDictionary);
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Variant::ARRAY:
|
case Variant::ARRAY:
|
||||||
|
@ -194,6 +214,7 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) {
|
||||||
EditorPropertyArray *editor = memnew(EditorPropertyArray);
|
EditorPropertyArray *editor = memnew(EditorPropertyArray);
|
||||||
editor->setup(p_type);
|
editor->setup(p_type);
|
||||||
value_editor = editor;
|
value_editor = editor;
|
||||||
|
is_bottom = true;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
@ -202,15 +223,25 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value_editor->set_name_split_ratio(0.0);
|
value_editor->set_name_split_ratio(0.0);
|
||||||
editor_hbox->add_child(value_editor);
|
value_editor->set_use_folding(is_using_folding());
|
||||||
|
value_editor->set_selectable(false);
|
||||||
value_editor->set_h_size_flags(SIZE_EXPAND_FILL);
|
value_editor->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||||
value_editor->set_meta(SNAME("_param_type"), p_type);
|
value_editor->set_meta(SNAME("_param_type"), p_type);
|
||||||
value_editor->connect(SNAME("property_changed"), callable_mp(this, &EditorPropertyBBParam::_value_edited));
|
value_editor->connect(SNAME("property_changed"), callable_mp(this, &EditorPropertyBBParam::_value_edited));
|
||||||
|
if (is_bottom) {
|
||||||
|
bottom_container->add_child(value_editor);
|
||||||
|
set_bottom_editor(bottom_container);
|
||||||
|
bottom_container->show();
|
||||||
|
} else {
|
||||||
|
set_bottom_editor(nullptr);
|
||||||
|
editor_hbox->add_child(value_editor);
|
||||||
|
bottom_container->hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorPropertyBBParam::_remove_value_editor() {
|
void EditorPropertyBBParam::_remove_value_editor() {
|
||||||
if (value_editor) {
|
if (value_editor) {
|
||||||
editor_hbox->remove_child(value_editor);
|
value_editor->get_parent()->remove_child(value_editor);
|
||||||
value_editor->queue_free();
|
value_editor->queue_free();
|
||||||
value_editor = nullptr;
|
value_editor = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -245,15 +276,15 @@ void EditorPropertyBBParam::update_property() {
|
||||||
variable_edit->set_text(param->get_variable());
|
variable_edit->set_text(param->get_variable());
|
||||||
variable_edit->set_editable(true);
|
variable_edit->set_editable(true);
|
||||||
variable_edit->show();
|
variable_edit->show();
|
||||||
mode_button->set_mode(Mode::BIND_VAR, true);
|
mode_button->call_deferred(SNAME("set_mode"), Mode::BIND_VAR, true);
|
||||||
type_choice->hide();
|
type_choice->hide();
|
||||||
} else {
|
} else {
|
||||||
variable_edit->hide();
|
|
||||||
_create_value_editor(param->get_type());
|
_create_value_editor(param->get_type());
|
||||||
|
variable_edit->hide();
|
||||||
value_editor->show();
|
value_editor->show();
|
||||||
value_editor->set_object_and_property(param.ptr(), SNAME("saved_value"));
|
value_editor->set_object_and_property(param.ptr(), SNAME("saved_value"));
|
||||||
mode_button->set_mode(Mode::SPECIFY_VALUE, true);
|
|
||||||
value_editor->update_property();
|
value_editor->update_property();
|
||||||
|
mode_button->call_deferred(SNAME("set_mode"), Mode::SPECIFY_VALUE, true);
|
||||||
type_choice->set_visible(is_variant_param);
|
type_choice->set_visible(is_variant_param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,6 +339,10 @@ EditorPropertyBBParam::EditorPropertyBBParam() {
|
||||||
add_child(hbox);
|
add_child(hbox);
|
||||||
hbox->add_theme_constant_override(SNAME("separation"), 0);
|
hbox->add_theme_constant_override(SNAME("separation"), 0);
|
||||||
|
|
||||||
|
bottom_container = memnew(MarginContainer);
|
||||||
|
bottom_container->set_theme_type_variation("MarginContainer4px");
|
||||||
|
add_child(bottom_container);
|
||||||
|
|
||||||
mode_button = memnew(ModeSwitchButton);
|
mode_button = memnew(ModeSwitchButton);
|
||||||
hbox->add_child(mode_button);
|
hbox->add_child(mode_button);
|
||||||
mode_button->set_focus_mode(FOCUS_NONE);
|
mode_button->set_focus_mode(FOCUS_NONE);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "modules/limboai/editor/mode_switch_button.h"
|
#include "modules/limboai/editor/mode_switch_button.h"
|
||||||
|
|
||||||
#include "scene/gui/box_container.h"
|
#include "scene/gui/box_container.h"
|
||||||
|
#include "scene/gui/margin_container.h"
|
||||||
#include "scene/gui/menu_button.h"
|
#include "scene/gui/menu_button.h"
|
||||||
|
|
||||||
class EditorPropertyBBParam : public EditorProperty {
|
class EditorPropertyBBParam : public EditorProperty {
|
||||||
|
@ -38,6 +39,7 @@ private:
|
||||||
Mode mode = Mode::SPECIFY_VALUE;
|
Mode mode = Mode::SPECIFY_VALUE;
|
||||||
|
|
||||||
HBoxContainer *hbox = nullptr;
|
HBoxContainer *hbox = nullptr;
|
||||||
|
MarginContainer *bottom_container = nullptr;
|
||||||
HBoxContainer *editor_hbox = nullptr;
|
HBoxContainer *editor_hbox = nullptr;
|
||||||
ModeSwitchButton *mode_button = nullptr;
|
ModeSwitchButton *mode_button = nullptr;
|
||||||
EditorProperty *value_editor = nullptr;
|
EditorProperty *value_editor = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue