Exemple #1
0
            public bool IsEmptyDirection(AnchorableGump host, AnchorDirection direction)
            {
                Point?hostDirection = GetControlCoordinates(host);

                if (hostDirection.HasValue)
                {
                    var targetX = hostDirection.Value.X + _anchorDirectionMatrix[(int)direction].X;
                    var targetY = hostDirection.Value.Y + _anchorDirectionMatrix[(int)direction].Y;

                    return(IsEmptyDirection(targetX, targetY));
                }

                return(false);
            }
Exemple #2
0
        private AnchorDirection GetAnchorDirection(AnchorableGump host, int x, int y)
        {
            var anchorPoint = new Vector2((float)x / host.Width, (float)y / host.Height);

            for (AnchorDirection anchorDirection = AnchorDirection.Left; anchorDirection <= AnchorDirection.Bottom; anchorDirection++)
            {
                if (IsPointInPolygon(_anchorTriangles[(int)anchorDirection], anchorPoint))
                {
                    return(anchorDirection);
                }
            }

            return(AnchorDirection.Left);
        }
Exemple #3
0
        public Point GetCandidateDropLocation(AnchorableGump draggedControl, AnchorableGump host, int x, int y)
        {
            if (host.AnchorGroupName == draggedControl.AnchorGroupName && this[draggedControl] == null)
            {
                AnchorDirection direction = GetAnchorDirection(host, x, y);

                if (this[host] == null || this[host].IsEmptyDirection(host, direction))
                {
                    var offset = _anchorDirectionMatrix[(int)direction] * new Point(draggedControl.Width, draggedControl.Height);
                    return(new Point(host.X + offset.X, host.Y + offset.Y));
                }
            }

            return(draggedControl.Location);
        }
Exemple #4
0
 /// <summary>
 /// Calculates hold position based on holder controller's past move position (NEEDS REDO FOR CLONE)
 /// </summary>
 private void CalculateHoldPosition()
 {
     // Different behavior for clones
     if (this.CompareTag("TimeClone"))
     {
         Clone clone = GetComponent <Clone>();
         currentOffset   = clone.cloneXDirection == Clone.CloneXDirection.left ? holdOffsetLeft : holdOffsetRight;
         anchorDirection = clone.cloneXDirection == Clone.CloneXDirection.left ? AnchorDirection.left : AnchorDirection.right;
     }
     else
     {
         float sign = Mathf.Sign(holderController.moveAmountPast.x);
         currentOffset   = sign == -1 ? holdOffsetLeft : holdOffsetRight;
         anchorDirection = sign == -1 ? AnchorDirection.left : AnchorDirection.right;
     }
 }
Exemple #5
0
        public void DropControl(AnchorableGump draggedControl, AnchorableGump host, int x, int y)
        {
            if (host.AnchorGroupName == draggedControl.AnchorGroupName && this[draggedControl] == null)
            {
                AnchorDirection direction = GetAnchorDirection(host, x, y);

                if (this[host] == null)
                {
                    this[host] = new AnchorGroup(host);
                }

                if (this[host].IsEmptyDirection(host, direction))
                {
                    this[host].AnchorControlAt(draggedControl, host, direction);
                    this[draggedControl] = this[host];
                }
            }
        }
Exemple #6
0
            public void AnchorControlAt(AnchorableGump control, AnchorableGump host, AnchorDirection direction)
            {
                Point?hostDirection = GetControlCoordinates(host);

                if (hostDirection.HasValue)
                {
                    var targetX = hostDirection.Value.X + _anchorDirectionMatrix[(int)direction].X;
                    var targetY = hostDirection.Value.Y + _anchorDirectionMatrix[(int)direction].Y;

                    if (IsEmptyDirection(targetX, targetY))
                    {
                        if (targetX < 0) // Create new column left
                        {
                            ResizeMatrix(controlMatrix.GetLength(0) + 1, controlMatrix.GetLength(1), 1, 0);
                        }
                        else if (targetX > controlMatrix.GetLength(0) - 1) // Create new column right
                        {
                            ResizeMatrix(controlMatrix.GetLength(0) + 1, controlMatrix.GetLength(1), 0, 0);
                        }

                        if (targetY < 0) //Create new row top
                        {
                            ResizeMatrix(controlMatrix.GetLength(0), controlMatrix.GetLength(1) + 1, 0, 1);
                        }
                        else if (targetY > controlMatrix.GetLength(1) - 1) // Create new row bottom
                        {
                            ResizeMatrix(controlMatrix.GetLength(0), controlMatrix.GetLength(1) + 1, 0, 0);
                        }


                        hostDirection = GetControlCoordinates(host);

                        if (hostDirection.HasValue)
                        {
                            targetX = hostDirection.Value.X + _anchorDirectionMatrix[(int)direction].X;
                            targetY = hostDirection.Value.Y + _anchorDirectionMatrix[(int)direction].Y;
                            controlMatrix[targetX, targetY] = control;
                        }
                    }
                }
            }
Exemple #7
0
    public Transform GetAnchorFromPositionAndNormal(Vector3 position, Vector3 normal)
    {
        //Find which direction to use to look for our anchor
        int index = 0;

        normal = transform.worldToLocalMatrix * normal; // Work in local space

        Vector3 closestCartesian = Utils.GetClosestCartesianFromVector(normal);

        if (closestCartesian == Vector3.right)
        {
            index = (int)Anchor.Right;
        }
        else if (closestCartesian == -Vector3.right)
        {
            index = (int)Anchor.Left;
        }
        else if (closestCartesian == Vector3.forward)
        {
            index = (int)Anchor.Front;
        }
        else if (closestCartesian == -Vector3.forward)
        {
            index = (int)Anchor.Back;
        }
        else if (closestCartesian == Vector3.up)
        {
            index = (int)Anchor.Up;
        }
        else if (-closestCartesian == Vector3.up)
        {
            index = (int)Anchor.Down;
        }
        else
        {
            return(null);
        }

        // Now find in which unit we are and if an anchor exists here

        AnchorDirection ad = anchorsDirection[index];

        if (ad.Anchors.Length <= 0)
        {
            return(null);
        }

        int index2 = -1;

        for (int i = 0; i < ad.Anchors.Length; i++)
        {
            if (ad.Anchors[i] == null)
            {
                continue;
            }
            Vector3 localPos = ad.Anchors[i].worldToLocalMatrix.MultiplyPoint3x4(position);
            if ((localPos.x < (unitSize / 2.0f) + 0.1f && localPos.x > -unitSize / 2.0f - 0.1f) && (localPos.y < unitSize / 2.0f + 0.1f && localPos.y > -unitSize / 2.0f - 0.1f))
            {
                index2 = i;
                break;
            }
        }

        if (index2 == -1)
        {
            return(null);
        }

        return(anchorsDirection[index].Anchors[index2]); //Returns null if no anchor has been set at this index;
    }
Exemple #8
0
 private void AnchorBR_Checked(object sender, RoutedEventArgs e)
 {
     UncheckAllBoxes();
     Anchor             = AnchorDirection.BR;
     AnchorBR.IsChecked = true;
 }
Exemple #9
0
 public KaiTool_UIAnchor()
 {
     m_anchorDirection = AnchorDirection.Center;
     m_relativePositon = Vector3.zero;
 }
Exemple #10
0
 private void Awake()
 {
     holderController = GetComponent <Controller2D>();
     CalculateHoldPosition();
     anchorDirection = AnchorDirection.noDirection;
 }