mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-26 19:09:18 +01:00
Cleaned up PolygonEditor.
This commit is contained in:
parent
5eafb2fcd5
commit
efd6c7b333
@ -20,13 +20,14 @@ public:
|
|||||||
PolygonControlPoint();
|
PolygonControlPoint();
|
||||||
~PolygonControlPoint();
|
~PolygonControlPoint();
|
||||||
|
|
||||||
|
const Vector2 OFFSET = Vector2(3, 3);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
bool moving = false;
|
bool moving = false;
|
||||||
const Vector2 OFFSET = Vector2(3, 3);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,92 +1,81 @@
|
|||||||
|
|
||||||
#include "polygon_editor.h"
|
#include "polygon_editor.h"
|
||||||
|
|
||||||
|
#include "../../../nodes/bases/polygon_base.h"
|
||||||
|
#include "polygon_control_point.h"
|
||||||
|
|
||||||
|
void PolygonEditor::set_polygon(const Ref<PolygonBase> &p) {
|
||||||
//tool;
|
|
||||||
signal value_changed(value);
|
|
||||||
|
|
||||||
void PolygonEditor::_ready() {
|
|
||||||
update_controls();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PolygonEditor::set_polygon(const Variant &p) {
|
|
||||||
polygon = p;
|
polygon = p;
|
||||||
update();
|
update();
|
||||||
update_controls();
|
update_controls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PolygonEditor::update_controls() {
|
void PolygonEditor::update_controls() {
|
||||||
|
for (int i = 0; i < get_child_count(); ++i) {
|
||||||
for (c in get_children()) {
|
Node *c = get_child(i);
|
||||||
c.queue_free();
|
c->queue_delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!polygon.is_valid()) {
|
||||||
if (!polygon) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolVector2Array points = polygon->get_points();
|
||||||
|
|
||||||
|
for (int i = 0; i < points.size(); ++i) {
|
||||||
|
Vector2 p = points[i];
|
||||||
|
|
||||||
|
PolygonControlPoint *control_point = memnew(PolygonControlPoint);
|
||||||
|
|
||||||
for (i in polygon.points.size()) {
|
|
||||||
Variant = polygon.points[i];
|
|
||||||
//var control_point = preload("res://addons/mat_maker_gd/widgets/polygon_edit/control_point.tscn").instance();
|
|
||||||
add_child(control_point);
|
add_child(control_point);
|
||||||
control_point.initialize(p);
|
control_point->initialize(p);
|
||||||
control_point.rect_position = transform_point(p)-control_point.OFFSET;
|
control_point->set_position(transform_point(p) - control_point->OFFSET);
|
||||||
control_point.connect("moved", self, "_on_ControlPoint_moved");
|
control_point->connect("moved", this, "_on_ControlPoint_moved");
|
||||||
control_point.connect("removed", self, "_on_ControlPoint_removed");
|
control_point->connect("removed", this, "_on_ControlPoint_removed");
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_signal("value_changed", polygon);
|
emit_signal("value_changed", polygon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PolygonEditor::_on_ControlPoint_moved(const int index) {
|
||||||
|
PolygonControlPoint *control_point = Object::cast_to<PolygonControlPoint>(get_child(index));
|
||||||
|
|
||||||
|
PoolVector2Array points = polygon->get_points();
|
||||||
|
|
||||||
|
points.set(index, reverse_transform_point(control_point->get_position() + control_point->OFFSET));
|
||||||
|
|
||||||
|
polygon->set_points(points);
|
||||||
|
|
||||||
void PolygonEditor::_on_ControlPoint_moved(const Variant &index) {
|
|
||||||
Variant = get_child(index);
|
|
||||||
polygon.points[index] = reverse_transform_point(control_point.rect_position+control_point.OFFSET);
|
|
||||||
update();
|
update();
|
||||||
emit_signal("value_changed", polygon);
|
emit_signal("value_changed", polygon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PolygonEditor::_on_ControlPoint_removed(const int index) {
|
||||||
void PolygonEditor::_on_ControlPoint_removed(const Variant &index) {
|
if (polygon->remove_point(index)) {
|
||||||
|
|
||||||
if (polygon.remove_point(index)) {
|
|
||||||
update();
|
update();
|
||||||
update_controls();
|
update_controls();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PolygonEditor::_on_PolygonEditor_gui_input(const Ref<InputEvent> &event) {
|
||||||
void PolygonEditor::_on_PolygonEditor_gui_input(const Variant &event) {
|
if (!polygon.is_valid()) {
|
||||||
|
|
||||||
if (!polygon) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<InputEventMouseButton> iemb = event;
|
||||||
|
|
||||||
if (event is InputEventMouseButton) {
|
if (iemb.is_valid()) {
|
||||||
|
if (iemb->get_button_index() == BUTTON_LEFT && iemb->is_doubleclick()) {
|
||||||
if (event.button_index == BUTTON_LEFT && event.doubleclick) {
|
Vector2 new_point_position = reverse_transform_point(get_local_mouse_position());
|
||||||
Variant = reverse_transform_point(get_local_mouse_position());
|
polygon->add_point(new_point_position.x, new_point_position.y, closed);
|
||||||
polygon.add_point(new_point_position.x, new_point_position.y, closed);
|
|
||||||
update_controls();
|
update_controls();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PolygonEditor::_on_resize() {
|
void PolygonEditor::_on_resize() {
|
||||||
._on_resize();
|
PolygonView::_on_resize();
|
||||||
update_controls();
|
update_controls();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PolygonEditor::PolygonEditor() {
|
PolygonEditor::PolygonEditor() {
|
||||||
@ -95,17 +84,20 @@
|
|||||||
PolygonEditor::~PolygonEditor() {
|
PolygonEditor::~PolygonEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PolygonEditor::_notification(int p_what) {
|
||||||
|
if (p_what == NOTIFICATION_POSTINITIALIZE) {
|
||||||
|
update_controls();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolygonEditor::_bind_methods() {
|
||||||
|
ADD_SIGNAL(MethodInfo("value_changed", PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "PolygonBase")));
|
||||||
|
|
||||||
static void PolygonEditor::_bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("_ready"), &PolygonEditor::_ready);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_polygon", "p"), &PolygonEditor::set_polygon);
|
ClassDB::bind_method(D_METHOD("set_polygon", "p"), &PolygonEditor::set_polygon);
|
||||||
ClassDB::bind_method(D_METHOD("update_controls"), &PolygonEditor::update_controls);
|
ClassDB::bind_method(D_METHOD("update_controls"), &PolygonEditor::update_controls);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_on_ControlPoint_moved", "index"), &PolygonEditor::_on_ControlPoint_moved);
|
ClassDB::bind_method(D_METHOD("_on_ControlPoint_moved", "index"), &PolygonEditor::_on_ControlPoint_moved);
|
||||||
ClassDB::bind_method(D_METHOD("_on_ControlPoint_removed", "index"), &PolygonEditor::_on_ControlPoint_removed);
|
ClassDB::bind_method(D_METHOD("_on_ControlPoint_removed", "index"), &PolygonEditor::_on_ControlPoint_removed);
|
||||||
ClassDB::bind_method(D_METHOD("_on_PolygonEditor_gui_input", "event"), &PolygonEditor::_on_PolygonEditor_gui_input);
|
ClassDB::bind_method(D_METHOD("_on_PolygonEditor_gui_input", "event"), &PolygonEditor::_on_PolygonEditor_gui_input);
|
||||||
ClassDB::bind_method(D_METHOD("_on_resize"), &PolygonEditor::_on_resize);
|
ClassDB::bind_method(D_METHOD("_on_resize"), &PolygonEditor::_on_resize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
|
|
||||||
void construct() {
|
|
||||||
|
|
||||||
//Script: res://addons/mat_maker_gd/widgets/polygon_edit/polygon_editor.gd
|
|
||||||
Control *polygoneditor = memnew(Control);
|
|
||||||
polygoneditor->set_name("PolygonEditor");
|
|
||||||
|
|
||||||
polygoneditor->set_name("PolygonEditor");
|
|
||||||
//polygoneditor->set("name", PolygonEditor));
|
|
||||||
|
|
||||||
polygoneditor->set_filename("res://addons/mat_maker_gd/widgets/polygon_edit/polygon_editor.tscn");
|
|
||||||
//polygoneditor->set("filename", "res://addons/mat_maker_gd/widgets/polygon_edit/polygon_editor.tscn");
|
|
||||||
|
|
||||||
polygoneditor->set_anchor_right(1);
|
|
||||||
//polygoneditor->set("anchor_right", 1);
|
|
||||||
|
|
||||||
polygoneditor->set_anchor_bottom(1);
|
|
||||||
//polygoneditor->set("anchor_bottom", 1);
|
|
||||||
|
|
||||||
polygoneditor->set_margin_left(10);
|
|
||||||
//polygoneditor->set("margin_left", 10);
|
|
||||||
|
|
||||||
polygoneditor->set_margin_top(10);
|
|
||||||
//polygoneditor->set("margin_top", 10);
|
|
||||||
|
|
||||||
polygoneditor->set_margin_right(-10);
|
|
||||||
//polygoneditor->set("margin_right", -10);
|
|
||||||
|
|
||||||
polygoneditor->set_margin_bottom(-10);
|
|
||||||
//polygoneditor->set("margin_bottom", -10);
|
|
||||||
|
|
||||||
polygoneditor->set_rect_position(Vector2(10, 10));
|
|
||||||
//polygoneditor->set("rect_position", Vector2(10, 10));
|
|
||||||
|
|
||||||
polygoneditor->set_rect_global_position(Vector2(10, 10));
|
|
||||||
//polygoneditor->set("rect_global_position", Vector2(10, 10));
|
|
||||||
|
|
||||||
//polygoneditor property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +1,34 @@
|
|||||||
#ifndef POLYGON_EDITOR_H
|
#ifndef POLYGON_EDITOR_H
|
||||||
#define POLYGON_EDITOR_H
|
#define POLYGON_EDITOR_H
|
||||||
|
|
||||||
|
#include "core/os/input_event.h"
|
||||||
|
#include "core/reference.h"
|
||||||
|
|
||||||
class PolygonEditor : public "res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.gd" {
|
#include "polygon_view.h"
|
||||||
GDCLASS(PolygonEditor, "res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.gd");
|
|
||||||
|
class PolygonBase;
|
||||||
|
|
||||||
|
class PolygonEditor : public PolygonView {
|
||||||
|
GDCLASS(PolygonEditor, PolygonView);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void set_polygon(const Ref<PolygonBase> &p);
|
||||||
void _ready();
|
|
||||||
void set_polygon(const Variant &p);
|
|
||||||
void update_controls();
|
void update_controls();
|
||||||
void _on_ControlPoint_moved(const Variant &index);
|
|
||||||
void _on_ControlPoint_removed(const Variant &index);
|
void _on_ControlPoint_moved(const int index);
|
||||||
void _on_PolygonEditor_gui_input(const Variant &event);
|
void _on_ControlPoint_removed(const int index);
|
||||||
|
void _on_PolygonEditor_gui_input(const Ref<InputEvent> &event);
|
||||||
void _on_resize();
|
void _on_resize();
|
||||||
|
|
||||||
PolygonEditor();
|
PolygonEditor();
|
||||||
~PolygonEditor();
|
~PolygonEditor();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void _notification(int p_what);
|
||||||
|
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
//tool
|
Ref<PolygonBase> polygon;
|
||||||
signal value_changed(value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user