Fix duplicate methods and binds in CurveEditor.

This commit is contained in:
Relintai 2022-06-16 12:15:10 +02:00
parent 025713f94f
commit 034aed2b73
3 changed files with 10 additions and 12 deletions

View File

@ -6,7 +6,7 @@
#include "core/object.h" #include "core/object.h"
#include "slope_point.h" #include "slope_point.h"
void MMCurveEditor::set_curve(const Variant &c) { void MMCurveEditor::set_curve(const Ref<CurveBase> &c) {
curve = c; curve = c;
update(); update();
update_controls(); update_controls();
@ -52,7 +52,7 @@ void MMCurveEditor::update_controls() {
emit_signal("value_changed", curve); emit_signal("value_changed", curve);
} }
void MMCurveEditor::_on_ControlPoint_moved(const Variant &index) { void MMCurveEditor::_on_ControlPoint_moved(const int index) {
Vector<CurveBase::Point> points = curve->get_points(); Vector<CurveBase::Point> points = curve->get_points();
ControlPoint *control_point = Object::cast_to<ControlPoint>(get_child(index)); ControlPoint *control_point = Object::cast_to<ControlPoint>(get_child(index));
points.write[index].p = reverse_transform_point(control_point->get_position() + control_point->OFFSET); points.write[index].p = reverse_transform_point(control_point->get_position() + control_point->OFFSET);
@ -78,14 +78,14 @@ void MMCurveEditor::_on_ControlPoint_moved(const Variant &index) {
emit_signal("value_changed", curve); emit_signal("value_changed", curve);
} }
void MMCurveEditor::_on_ControlPoint_removed(const Variant &index) { void MMCurveEditor::_on_ControlPoint_removed(const int index) {
if (curve->remove_point(index)) { if (curve->remove_point(index)) {
update(); update();
update_controls(); update_controls();
} }
} }
void MMCurveEditor::_on_MMCurveEditor_gui_input(const Variant &event) { void MMCurveEditor::_on_MMCurveEditor_gui_input(const Ref<InputEvent> &event) {
Ref<InputEventMouseButton> iemb = event; Ref<InputEventMouseButton> iemb = event;
if (iemb.is_valid()) { if (iemb.is_valid()) {
@ -122,11 +122,9 @@ void MMCurveEditor::_notification(int p_what) {
void MMCurveEditor::_bind_methods() { void MMCurveEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("value_changed", PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "CurveBase"))); ADD_SIGNAL(MethodInfo("value_changed", PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "CurveBase")));
ClassDB::bind_method(D_METHOD("set_curve", "c"), &MMCurveEditor::set_curve);
ClassDB::bind_method(D_METHOD("update_controls"), &MMCurveEditor::update_controls); ClassDB::bind_method(D_METHOD("update_controls"), &MMCurveEditor::update_controls);
ClassDB::bind_method(D_METHOD("_on_ControlPoint_moved", "index"), &MMCurveEditor::_on_ControlPoint_moved); ClassDB::bind_method(D_METHOD("_on_ControlPoint_moved", "index"), &MMCurveEditor::_on_ControlPoint_moved);
ClassDB::bind_method(D_METHOD("_on_ControlPoint_removed", "index"), &MMCurveEditor::_on_ControlPoint_removed); ClassDB::bind_method(D_METHOD("_on_ControlPoint_removed", "index"), &MMCurveEditor::_on_ControlPoint_removed);
ClassDB::bind_method(D_METHOD("_on_MMCurveEditor_gui_input", "event"), &MMCurveEditor::_on_MMCurveEditor_gui_input); ClassDB::bind_method(D_METHOD("_on_MMCurveEditor_gui_input", "event"), &MMCurveEditor::_on_MMCurveEditor_gui_input);
ClassDB::bind_method(D_METHOD("_on_resize"), &MMCurveEditor::_on_resize);
} }

View File

@ -7,12 +7,12 @@ class MMCurveEditor : public CurveView {
GDCLASS(MMCurveEditor, CurveView); GDCLASS(MMCurveEditor, CurveView);
public: public:
void set_curve(const Variant &c); void set_curve(const Ref<CurveBase> &c);
void update_controls(); void update_controls();
void _on_ControlPoint_moved(const Variant &index); void _on_ControlPoint_moved(const int index);
void _on_ControlPoint_removed(const Variant &index); void _on_ControlPoint_removed(const int index);
void _on_MMCurveEditor_gui_input(const Variant &event); void _on_MMCurveEditor_gui_input(const Ref<InputEvent> &event);
void _on_resize(); void _on_resize();
MMCurveEditor(); MMCurveEditor();

View File

@ -15,13 +15,13 @@ public:
void set_show_axes(const bool val); void set_show_axes(const bool val);
Ref<CurveBase> get_curve(); Ref<CurveBase> get_curve();
void set_curve(const Ref<CurveBase> &val); virtual void set_curve(const Ref<CurveBase> &val);
Vector2 transform_point(const Vector2 &p); Vector2 transform_point(const Vector2 &p);
Vector2 reverse_transform_point(const Vector2 &p); Vector2 reverse_transform_point(const Vector2 &p);
void _draw(); void _draw();
void _on_resize(); virtual void _on_resize();
CurveView(); CurveView();
~CurveView(); ~CurveView();