Ejemplo n.º 1
0
    private void SetBelow(SpatialControl reference, SpatialControl actual)
    {
        //Size is positive, but we want to go down so we subtract.
        var y = reference.Translation.y - reference.Size.y;

        actual.Translation = new Vector3(actual.Translation.x, y, actual.Translation.z);
    }
Ejemplo n.º 2
0
 float AnchorSX(SpatialControl reference)
 {
     if (Right)
     {
         return(AnchorRight * reference.Size.x + MarginRight - owner.Translation.x);
     }
     return(owner.Size.x);
 }
Ejemplo n.º 3
0
 float AnchorSY(SpatialControl reference)
 {
     if (Bottom)
     {
         return(AnchorBottom * reference.Size.y + MarginRight + owner.Translation.y);
     }
     return(owner.Size.y);
 }
Ejemplo n.º 4
0
 float AnchorX(SpatialControl reference)
 {
     if (Left)
     {
         return(AnchorLeft * reference.Size.x + MarginLeft);
     }
     return(owner.Translation.x);
 }
Ejemplo n.º 5
0
 float AnchorY(SpatialControl reference)
 {
     if (Top)
     {
         return(AnchorTop * reference.Size.y + MarginTop);
     }
     return(owner.Translation.y);
 }
Ejemplo n.º 6
0
 //This is necessary because something else is referencing this object
 //and we dont know what.
 public void OnOwnerDelete()
 {
     if (!(parent is null))
     {
         parent.Disconnect(nameof(SpatialControl.SizeChanged), this, nameof(OnReferenceSizeChanged));
     }
     parent = null;
     owner  = null;
 }
Ejemplo n.º 7
0
    public override void _Ready()
    {
        SpatialControl parent = (SpatialControl)GetParent();

        parent.Connect(nameof(SpatialControl.SizeChanged), this, nameof(OnSizeChanged),
                       new Godot.Collections.Array {
            parent
        });

        shape = GetNode <CollisionShape>("CollisionShape");
    }
Ejemplo n.º 8
0
 //NOT an override of Godot.Object._init
 //That doesn't take arguments and this thing needs a reference to its owner.
 public void Init(SpatialControl o)
 {
     owner = o;
     owner.Connect(nameof(SpatialControl.OnPredelete), this, nameof(OnOwnerDelete));
     // p.GetTree().GetEditedSceneRoot();
     if (owner.GetParent() is SpatialControl p)
     {
         parent = p;
         parent.Connect(nameof(SpatialControl.SizeChanged), this, nameof(OnReferenceSizeChanged),
                        new Godot.Collections.Array {
             parent
         });
         OnReferenceSizeChanged(parent.Size, parent);
     }
 }
Ejemplo n.º 9
0
 public void OnChildSizeChanged(Vector2 oldSize, SpatialControl child)
 {
     if (Math.Abs(oldSize.y - child.Size.y) < 1e-7)
     {
         return; //we don't actually care about changes that don't affect vertical size.
     }
     GD.Print(child.Name, "; ", child.Translation, "; ", oldSize, " -> ", child.Size);
     for (int i = child.GetIndex() + 1; i < GetChildCount(); i++)
     {
         var nextChild = (SpatialControl)GetChild(i);
         SetBelow(child, nextChild);
         child = nextChild;
     }
     Size = new Vector2(Size.x, -child.Translation.y + child.Size.y);
     GD.Print(GetPath() + "size set to: ", Size);
 }
Ejemplo n.º 10
0
 private void RegisterChild(SpatialControl child)
 {
     GD.Print("Registering: ", child.Name, "; ", child.GetIndex());
     if (child.GetIndex() == 0)
     {
         child.Translation = new Vector3(child.Translation.x, 0, child.Translation.z);
     }
     else
     {
         var previousSC = (SpatialControl)GetChild(child.GetIndex() - 1);
         SetBelow(previousSC, child);
     }
     child.Connect(nameof(SizeChanged), this, nameof(OnChildSizeChanged),
                   new Godot.Collections.Array {
         child
     });
     OnChildSizeChanged(Vector2.Zero, child);
 }
Ejemplo n.º 11
0
 public void InsertSpatialControl(SpatialControl child, int index)
 {
     AddChildBelowNode(GetChild(index), child);
     RegisterChild(child);
 }
Ejemplo n.º 12
0
 public void AddSpatialControl(SpatialControl child)
 {
     AddChild(child);
     RegisterChild(child);
 }
Ejemplo n.º 13
0
 public virtual void OnReferenceSizeChanged(Vector2 oldSize, SpatialControl reference)
 {
     owner.Translation = new Vector3(AnchorX(reference), AnchorY(reference), owner.Translation.z);
     owner.Size        = new Vector2(AnchorSX(reference), AnchorSY(reference));
 }
Ejemplo n.º 14
0
 public void OnSizeChanged(Vector2 oldSize, SpatialControl parent)
 {
     shape.Translation = new Vector3(parent.Size.x / 2, -parent.Size.y / 2, 0);
     ((BoxShape)shape.Shape).Extents = new Vector3(parent.Size.x / 2, parent.Size.y / 2, Thiccness);
 }