Added editor properties for Vector2i, Vector3i, and Rect2i.

This commit is contained in:
Relintai 2022-03-22 01:34:43 +01:00
parent 6c91c3f9d5
commit 68c0469aa5
2 changed files with 322 additions and 7 deletions

View File

@ -1550,6 +1550,86 @@ EditorPropertyVector2::EditorPropertyVector2() {
setting = false;
}
///////////////////// VECTOR2I /////////////////////////
void EditorPropertyVector2i::_value_changed(double val, const String &p_name) {
if (setting) {
return;
}
Vector2i v2;
v2.x = spin[0]->get_value();
v2.y = spin[1]->get_value();
emit_changed(get_edited_property(), v2, p_name);
}
void EditorPropertyVector2i::update_property() {
Vector2i val = get_edited_object()->get(get_edited_property());
setting = true;
spin[0]->set_value(val.x);
spin[1]->set_value(val.y);
setting = false;
}
void EditorPropertyVector2i::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_color("accent_color", "Editor");
for (int i = 0; i < 2; i++) {
Color c = base;
c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
}
}
}
void EditorPropertyVector2i::_bind_methods() {
ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector2i::_value_changed);
}
void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider) {
for (int i = 0; i < 2; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(1);
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
}
}
EditorPropertyVector2i::EditorPropertyVector2i() {
bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector2_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[2] = { "x", "y" };
for (int i = 0; i < 2; i++) {
spin[i] = memnew(EditorSpinSlider);
spin[i]->set_flat(true);
spin[i]->set_label(desc[i]);
bc->add_child(spin[i]);
add_focusable(spin[i]);
spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
if (horizontal) {
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
}
}
if (!horizontal) {
set_label_reference(spin[0]); //show text and buttons around this
}
setting = false;
}
///////////////////// RECT2 /////////////////////////
void EditorPropertyRect2::_value_changed(double val, const String &p_name) {
@ -1632,6 +1712,88 @@ EditorPropertyRect2::EditorPropertyRect2() {
setting = false;
}
///////////////////// RECT2I /////////////////////////
void EditorPropertyRect2i::_value_changed(double val, const String &p_name) {
if (setting) {
return;
}
Rect2i r2;
r2.position.x = spin[0]->get_value();
r2.position.y = spin[1]->get_value();
r2.size.x = spin[2]->get_value();
r2.size.y = spin[3]->get_value();
emit_changed(get_edited_property(), r2, p_name);
}
void EditorPropertyRect2i::update_property() {
Rect2i val = get_edited_object()->get(get_edited_property());
setting = true;
spin[0]->set_value(val.position.x);
spin[1]->set_value(val.position.y);
spin[2]->set_value(val.size.x);
spin[3]->set_value(val.size.y);
setting = false;
}
void EditorPropertyRect2i::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_color("accent_color", "Editor");
for (int i = 0; i < 4; i++) {
Color c = base;
c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
}
}
}
void EditorPropertyRect2i::_bind_methods() {
ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyRect2i::_value_changed);
}
void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider) {
for (int i = 0; i < 4; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(1);
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
}
}
EditorPropertyRect2i::EditorPropertyRect2i() {
bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_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", "w", "h" };
for (int i = 0; i < 4; i++) {
spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]);
spin[i]->set_flat(true);
bc->add_child(spin[i]);
add_focusable(spin[i]);
spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
if (horizontal) {
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
}
}
if (!horizontal) {
set_label_reference(spin[0]); //show text and buttons around this
}
setting = false;
}
///////////////////// VECTOR3 /////////////////////////
void EditorPropertyVector3::_value_changed(double val, const String &p_name) {
@ -1711,6 +1873,87 @@ EditorPropertyVector3::EditorPropertyVector3() {
}
setting = false;
}
///////////////////// VECTOR3I /////////////////////////
void EditorPropertyVector3i::_value_changed(double val, const String &p_name) {
if (setting) {
return;
}
Vector3i v3;
v3.x = spin[0]->get_value();
v3.y = spin[1]->get_value();
v3.z = spin[2]->get_value();
emit_changed(get_edited_property(), v3, p_name);
}
void EditorPropertyVector3i::update_property() {
Vector3i val = get_edited_object()->get(get_edited_property());
setting = true;
spin[0]->set_value(val.x);
spin[1]->set_value(val.y);
spin[2]->set_value(val.z);
setting = false;
}
void EditorPropertyVector3i::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_color("accent_color", "Editor");
for (int i = 0; i < 3; i++) {
Color c = base;
c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
}
}
}
void EditorPropertyVector3i::_bind_methods() {
ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector3i::_value_changed);
}
void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider) {
for (int i = 0; i < 3; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(1);
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
}
}
EditorPropertyVector3i::EditorPropertyVector3i() {
bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_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[3] = { "x", "y", "z" };
for (int i = 0; i < 3; i++) {
spin[i] = memnew(EditorSpinSlider);
spin[i]->set_flat(true);
spin[i]->set_label(desc[i]);
bc->add_child(spin[i]);
add_focusable(spin[i]);
spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
if (horizontal) {
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
}
}
if (!horizontal) {
set_label_reference(spin[0]); //show text and buttons around this
}
setting = false;
}
///////////////////// PLANE /////////////////////////
void EditorPropertyPlane::_value_changed(double val, const String &p_name) {
@ -2996,26 +3239,21 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
add_property_editor(p_path, editor);
} break; // 5
/* TODO
case Variant::VECTOR2I: {
EditorPropertyVector2i *editor = memnew(EditorPropertyVector2i);
int min = -65535, max = 65535, step = default_float_step;
int min = -65535, max = 65535;
bool hide_slider = true;
if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
min = p_hint_text.get_slice(",", 0).to_int();
max = p_hint_text.get_slice(",", 1).to_int();
if (p_hint_text.get_slice_count(",") >= 3) {
step = p_hint_text.get_slice(",", 2).to_int();
}
hide_slider = false;
}
editor->setup(min, max, step, hide_slider);
editor->setup(min, max, hide_slider);
add_property_editor(p_path, editor);
} break;
*/
case Variant::RECT2: {
EditorPropertyRect2 *editor = memnew(EditorPropertyRect2);
double min = -65535, max = 65535, step = default_float_step;
@ -3033,6 +3271,20 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
} break;
case Variant::RECT2I: {
EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i);
double min = -65535, max = 65535;
bool hide_slider = true;
if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
min = p_hint_text.get_slice(",", 0).to_double();
max = p_hint_text.get_slice(",", 1).to_double();
hide_slider = false;
}
editor->setup(min, max, hide_slider);
add_property_editor(p_path, editor);
} break;
case Variant::VECTOR3: {
EditorPropertyVector3 *editor = memnew(EditorPropertyVector3);
double min = -65535, max = 65535, step = default_float_step;
@ -3050,6 +3302,21 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
} break;
case Variant::VECTOR3I: {
EditorPropertyVector3i *editor = memnew(EditorPropertyVector3i);
double min = -65535, max = 65535;
bool hide_slider = true;
if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
min = p_hint_text.get_slice(",", 0).to_double();
max = p_hint_text.get_slice(",", 1).to_double();
hide_slider = false;
}
editor->setup(min, max, hide_slider);
add_property_editor(p_path, editor);
} break;
case Variant::TRANSFORM2D: {
EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D);

View File

@ -408,6 +408,22 @@ public:
EditorPropertyVector2();
};
class EditorPropertyVector2i : public EditorProperty {
GDCLASS(EditorPropertyVector2i, EditorProperty);
EditorSpinSlider *spin[2];
bool setting;
void _value_changed(double p_val, const String &p_name);
protected:
void _notification(int p_what);
static void _bind_methods();
public:
virtual void update_property();
void setup(int p_min, int p_max, bool p_no_slider);
EditorPropertyVector2i();
};
class EditorPropertyRect2 : public EditorProperty {
GDCLASS(EditorPropertyRect2, EditorProperty);
EditorSpinSlider *spin[4];
@ -424,6 +440,22 @@ public:
EditorPropertyRect2();
};
class EditorPropertyRect2i : public EditorProperty {
GDCLASS(EditorPropertyRect2i, EditorProperty);
EditorSpinSlider *spin[4];
bool setting;
void _value_changed(double p_val, const String &p_name);
protected:
void _notification(int p_what);
static void _bind_methods();
public:
virtual void update_property();
void setup(int p_min, int p_max, bool p_no_slider);
EditorPropertyRect2i();
};
class EditorPropertyVector3 : public EditorProperty {
GDCLASS(EditorPropertyVector3, EditorProperty);
EditorSpinSlider *spin[3];
@ -440,6 +472,22 @@ public:
EditorPropertyVector3();
};
class EditorPropertyVector3i : public EditorProperty {
GDCLASS(EditorPropertyVector3i, EditorProperty);
EditorSpinSlider *spin[3];
bool setting;
void _value_changed(double p_val, const String &p_name);
protected:
void _notification(int p_what);
static void _bind_methods();
public:
virtual void update_property();
void setup(int p_min, int p_max, bool p_no_slider);
EditorPropertyVector3i();
};
class EditorPropertyPlane : public EditorProperty {
GDCLASS(EditorPropertyPlane, EditorProperty);
EditorSpinSlider *spin[4];