123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- /// Description Pending
- using Godot;
- // Description pending.
- [Tool]
- /// Descriptpepepl
- public partial class CurvedPolygon2D: Path2D {
- [Export(PropertyHint.Range, "1,10")]
- public int MaxStages {
- get { return _maxStages; }
- set { _maxStages = value; QueueRedraw(); }
- }
- private int _maxStages = 5;
-
- [Export(PropertyHint.Range, "1.0,30.0,0.1,degrees")]
- public float ToleranceDegrees {
- get { return _toleranceDegrees; }
- set { _toleranceDegrees = value; QueueRedraw(); }
- }
- private float _toleranceDegrees = 4.0f;
- [Export]
- private NodePath _collisionPolygon = null;
-
- [ExportGroup("Texture")]
-
- [Export]
- private Texture2D Texture {
- get { return _texture; }
- set {
- _texture = value;
- if(Engine.IsEditorHint() && Polygon != null) {
- Polygon.Texture = value;
- }
- }
- }
- private Texture2D _texture = null;
- [Export(PropertyHint.Link)]
- private Vector2 TextureScale {
- get { return _scale; }
- set {
- _scale = value;
- if(Engine.IsEditorHint() && Polygon != null) {
- Polygon.TextureScale = _scale.Inverse();
- }
- }
- }
- private Vector2 _scale = new Vector2(1.0f, 1.0f);
-
- [Export(PropertyHint.Range, "-360.0,360.0,0.1,or_less,or_greater,radians")]
- private float TextureRotation {
- get { return _rotation; }
- set {
- _rotation = value;
- if(Engine.IsEditorHint() && Polygon != null) {
- Polygon.TextureRotation = value;
- }
- }
- }
- private float _rotation = 0.0f;
- private Polygon2D _polygon = null;
- public Polygon2D Polygon {
- get {
- if(_polygon == null) {
- _polygon = (Polygon2D)FindChild("Polygon", false, false);
- }
- return _polygon;
- }
- }
- public Vector2[] RawVertices {
- get {
- return Curve.Tessellate(1, ToleranceDegrees);
- }
- }
- public override void _Ready() {
- if(Curve == null) {
- Curve = new Curve2D();
- }
- _polygon = (Polygon2D)FindChild("Polygon", false, true);
- if(_polygon == null) {
- _polygon = new Polygon2D();
- _polygon.Texture = Texture;
- _polygon.TextureScale = TextureScale.Inverse();
- _polygon.TextureFilter = TextureFilter;
- _polygon.UseParentMaterial = true;
- _polygon.Name = "Polygon";
- AddChild(_polygon);
- }
- }
-
- public override void _Draw() {
- if(Curve != null) {
- Vector2[] points = Curve.Tessellate(MaxStages, ToleranceDegrees);
- if(Polygon == null) {
- QueueRedraw();
- } else {
- Polygon.Polygon = points;
- if(_collisionPolygon != null) {
- try {
- GetNode<CollisionPolygon2D>(_collisionPolygon).Polygon = points;
- } catch(System.InvalidCastException) {
- GD.PushError("Collision Polygon attribute has to be a CollisionPolygon2D.");
- } catch(System.NullReferenceException) {
- GD.PushError("Invalid reference to the Collision Polygon.");
- }
- }
- }
- }
- }
- }
|