Ejemplo n.º 1
0
    public void UpdateChain()
    {
        SetReconstructButton(cursorScript.parts.Count > DroneUtilities.GetPartLimit(currentData.type) ?
                             ReconstructButtonStatus.PastPartLimit : ReconstructButtonStatus.Valid);
        var shellRect = ShipBuilder.GetRect(shellImage.rectTransform);

        shellRect.Expand(10);
        foreach (ShipBuilderPart shipPart in cursorScript.parts)
        {
            shipPart.isInChain = false;
            var partBounds = ShipBuilder.GetRect(shipPart.rectTransform);
            shipPart.isInChain = partBounds.Intersects(shellRect);
        }
        foreach (ShipBuilderPart shipPart in cursorScript.parts)
        {
            if (shipPart.isInChain)
            {
                UpdateChainHelper(shipPart);
            }
        }

        foreach (ShipBuilderPart shipPart in cursorScript.parts)
        {
            if (!shipPart.isInChain || !shipPart.validPos)
            {
                SetReconstructButton(ReconstructButtonStatus.PartInvalidPosition);
                return;
            }
        }
    }
Ejemplo n.º 2
0
    bool IsTooClose(ShipBuilderPart otherPart)
    {
        var closeConstant = mode == BuilderMode.Workshop ? -1.2F : -1F;
        var rect1         = ShipBuilder.GetRect(rectTransform);
        var rect2         = ShipBuilder.GetRect(otherPart.rectTransform);

        rect1.Expand(closeConstant * rect1.extents);
        rect2.Expand(closeConstant * rect2.extents);
        return(rect1.Intersects(rect2));
    }
Ejemplo n.º 3
0
    bool PartIsTooClose(ShipBuilderPart part, ShipBuilderPart otherPart)
    {
        var closeConstant = mode == BuilderMode.Workshop ? -1.2F : -1F;
        var rect1         = ShipBuilder.GetRect(part.rectTransform);
        var rect2         = ShipBuilder.GetRect(otherPart.rectTransform);

        // add small number (0.005) to deal with floating point issues
        rect1.Expand((closeConstant - 0.005F) * rect1.extents);
        rect2.Expand((closeConstant - 0.005F) * rect2.extents);
        return(rect1.Intersects(rect2));
    }
Ejemplo n.º 4
0
    void UpdateChainHelper(ShipBuilderPart part)
    {
        var x = ShipBuilder.GetRect(part.rectTransform);

        foreach (ShipBuilderPart shipPart in cursorScript.parts)
        {
            if (!shipPart.isInChain)
            {
                var y = ShipBuilder.GetRect(shipPart.rectTransform);
                if (x.Intersects(y))
                {
                    shipPart.isInChain = true;
                    UpdateChainHelper(shipPart);
                }
            }
        }
    }
Ejemplo n.º 5
0
 // Finds the part which contains the passed vector point
 // symmetry mode enables checks based on symmetryPart - same part ID, ability ID, different mirrored
 private ShipBuilderPart FindPart(Vector2 vector, ShipBuilderPart symmetryPart)
 {
     for (int i = parts.Count - 1; i >= 0; i--)
     {
         Bounds bound = ShipBuilder.GetRect(parts[i].rectTransform);
         bound.extents /= 1.5F;
         var origPos = transform.position;
         transform.position = Input.mousePosition;
         if (bound.Contains(vector) && (!symmetryPart || (parts[i].info.partID == symmetryPart.info.partID &&
                                                          (symmetryMode != SymmetryMode.X || parts[i].info.mirrored != symmetryPart.info.mirrored))))
         {
             transform.position = origPos;
             return(parts[i]);
         }
         transform.position = origPos;
     }
     return(null);
 }
Ejemplo n.º 6
0
    // Finds the part which contains the passed vector point
    // symmetry mode enables checks based on symmetryPart - same part ID, ability ID, different mirrored
    public ShipBuilderPart FindPart(Vector2 vector, ShipBuilderPart symmetryPart, bool useBounds = false)
    {
        if (!isMouseOnGrid)
        {
            return(null);
        }

        for (int i = parts.Count - 1; i >= 0; i--)
        {
            var origPos = transform.position;
            if (!useBounds && !PositionsCloseEnough(parts[i].rectTransform.anchoredPosition, vector))
            {
                continue;
            }
            else if (useBounds)
            {
                Bounds bound = ShipBuilder.GetRect(parts[i].rectTransform);
                bound.extents /= 1.5F;

                transform.position = Input.mousePosition;
                if (!bound.Contains(vector))
                {
                    transform.position = origPos;
                    continue;
                }
            }
            if ((!symmetryPart || (parts[i].info.partID == symmetryPart.info.partID &&
                                   (symmetryMode != SymmetryMode.X ||
                                    CheckOrientationCompatibility(parts[i].info, symmetryPart.info)))))
            {
                transform.position = origPos;
                return(parts[i]);
            }

            transform.position = origPos;
        }

        return(null);
    }
Ejemplo n.º 7
0
    // TODO: Test this when the Drone Workshop is added into the game
    public bool CheckPartIntersectsWithShell(ShipBuilderPart shipPart)
    {
        var shellRect = ShipBuilder.GetRect(shellImage.rectTransform);

        var partBounds = ShipBuilder.GetRect(shipPart.rectTransform);

        if (partBounds.Intersects(shellRect))
        {
            /*
             * bool z = Mathf.Abs(shipPart.rectTransform.anchoredPosition.x - shellImage.rectTransform.anchoredPosition.x) <=
             * 0.18F*(shipPart.rectTransform.sizeDelta.x + shellImage.rectTransform.sizeDelta.x) &&
             * Mathf.Abs(shipPart.rectTransform.anchoredPosition.y - shellImage.rectTransform.anchoredPosition.y) <=
             * 0.18F*(shipPart.rectTransform.sizeDelta.y + shellImage.rectTransform.sizeDelta.y);
             */
            shipPart.isInChain = true; //!z;

            // reset sprite

            //return true;
            return(true); //z;
        }

        return(false);
    }
Ejemplo n.º 8
0
    void Update()
    {
        UpdateCompact();

        if (clickedOnce)
        {
            if (timer > 0.2F)
            {
                clickedOnce = false;
            }
            else
            {
                timer += Time.deltaTime;
            }
        }

        int baseMoveSize = cursorMode == BuilderMode.Yard ? 4 : 5;

        builder.UpdateChain();
        if (Input.GetKeyDown(KeyCode.C) && (!searchField.isFocused && !jsonField.isFocused && !WCWorldIO.active))
        {
            if (builder as ShipBuilder == null || (builder as ShipBuilder).Equals(null) || !(builder as ShipBuilder).editorMode)
            {
                ClearAllParts();
            }
        }
        foreach (var part in parts)
        {
            part.boundImage.enabled = Input.GetKey(KeyCode.LeftShift);
        }

        System.Func <Vector3, int, int, Vector3> roundToRatios = (x, y, z) => new Vector3(y * ((int)x.x / (int)y), z * ((int)x.y / (int)z), 0);
        var newOffset = roundToRatios(grid.position, baseMoveSize, baseMoveSize) - grid.position;

        transform.position = roundToRatios(Input.mousePosition, baseMoveSize, baseMoveSize) - newOffset;
        var oldPos = GetComponent <RectTransform>().anchoredPosition;

        GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Round(oldPos.x / 10) * 10, Mathf.Round(oldPos.y / 10) * 10);
        // round to nearest 0.1
        // TODO: Make this stuff less messy. Regardless, consistency achieved!
        if (rotateMode)
        {
            RotateLastPart();
            return;
        }
        if (flipped)
        {
            grid2mousePos = Input.mousePosition;
            flipped       = false;
            return;
        }

        if (currentPart)
        {
            currentPart.SetMaskable(false);
            currentPart.info.location = (GetComponent <RectTransform>().anchoredPosition + offset) / 100;
            if (Input.GetMouseButtonUp(0))
            {
                PlaceCurrentPart();
            }
        }
        else if (Input.GetMouseButtonDown(0))
        {
            grid2lastPos  = grid.anchoredPosition;
            grid2mousePos = Input.mousePosition;
            lastPart      = null;
            for (int i = parts.Count - 1; i >= 0; i--)
            {
                Bounds bound = ShipBuilder.GetRect(parts[i].rectTransform);
                bound.extents /= 1.5F;
                var origPos = transform.position;
                transform.position = Input.mousePosition;
                if (bound.Contains(GetComponent <RectTransform>().anchoredPosition))
                {
                    transform.position = origPos;
                    GrabPart(parts[i]);
                    break;
                }
                transform.position = origPos;
            }
            if (clickedOnce && !rotateMode && !flipped && !currentPart)
            {
                grid2lastPos = grid.anchoredPosition = Vector2.zero;
            }
            else
            {
                timer       = 0;
                clickedOnce = true;
            }
        }

        // drag grid
        Vector2 bounds = grid.sizeDelta / 2 - grid2mask.sizeDelta / 2;

        if (grid.GetComponent <DragDetector>().dragging &&
            Input.GetMouseButton(0) && !rotateMode && !flipped && !currentPart)
        {
            grid.anchoredPosition = grid2lastPos + ((Vector2)Input.mousePosition - grid2mousePos) * 2;
            grid.anchoredPosition = new Vector2(Mathf.Max(-bounds.x, Mathf.Min(bounds.x, grid.anchoredPosition.x)),
                                                Mathf.Max(-bounds.y, Mathf.Min(bounds.y, grid.anchoredPosition.y))
                                                );
        }
    }