Exemplo n.º 1
0
    // Methods
    public virtual new void OnPointerDown(PointerEventData _eventData)
    {
        //Check for null Transform
        if (_eventData.button == PointerEventData.InputButton.Left)
        {
            if (m_rectTransform == null || m_canvas == null || m_visualGate == null || m_visualGridManager == null || m_gameplayManager == null || m_wireManager == null || m_infoPopup == null)
            {
                m_rectTransform     = GetComponent <RectTransform>();
                m_visualGate        = GetComponent <VisualGate>();
                m_canvas            = FindObjectOfType <Canvas>();
                m_visualGridManager = FindObjectOfType <VisualGridManager>();
                m_gameplayManager   = FindObjectOfType <GameplayManager>();
                m_wireManager       = FindObjectOfType <WireManager>();
                m_infoPopup         = FindObjectOfType <InfoPopup>();
            }
            if (m_rectTransform != null && m_canvas != null && m_visualGate != null && m_visualGridManager != null && m_gameplayManager != null && m_wireManager != null)
            {
                if (!m_wireManager.IsInWireEditMode())
                {
                    DoStateTransition(SelectionState.Pressed, false);
                    m_isBeingDragged = true;
                    m_rectTransform.SetParent(m_gameplayManager.gridParent);

                    StartCoroutine(OnDrag());
                }
            }
        }
    }
Exemplo n.º 2
0
    public Vector2 GetSnapPoint(Vector2 _position, VisualGate _visualGate = null)
    {
        Vector2 actualPos = uiCanvasFixer.ScreenPosToCanvas(_position);

        if (actualPos.x > startPos.x && actualPos.y > startPos.y && actualPos.x < endPos.x && actualPos.y < endPos.y)
        {
            if (_visualGate != null)
            {
                //Check that this gridObject won't overlap anything
                if (!IsGridObjectValid(actualPos, _visualGate, false))
                {
                    if (_visualGate != null)
                    {
                        _visualGate.localScale = 1.0f;
                    }
                    return(actualPos);
                }
            }

            Vector2 gridSize   = new Vector2(endPos.x - startPos.x, endPos.y - startPos.y);
            Vector2 squareSize = new Vector2(gridSize.x / gridWidth, gridSize.y / gridHeight);

            Vector2 closestSnapPoint = ((actualPos - startPos) / squareSize);
            Vector2 flooredSnapPoint = new Vector2(Mathf.Floor(closestSnapPoint.x), Mathf.Floor(closestSnapPoint.y));
            flooredSnapPoint *= squareSize;

            flooredSnapPoint += (squareSize * 0.5f);

            //Resize
            if (_visualGate != null)
            {
                _visualGate.localScale = 5.0f / (Mathf.Min(gridWidth, gridHeight));
            }

            return(flooredSnapPoint + startPos);
        }

        if (_visualGate != null)
        {
            _visualGate.localScale = 1.0f;
        }
        return(actualPos);
    }
Exemplo n.º 3
0
    public override void OnPointerEnter(PointerEventData eventData)
    {
        base.OnPointerEnter(eventData);

        if (m_infoPopup == null || m_visualGridManager == null || m_visualGate == null)
        {
            m_infoPopup         = FindObjectOfType <InfoPopup>();
            m_visualGridManager = FindObjectOfType <VisualGridManager>();
            m_visualGate        = GetComponent <VisualGate>();
        }

        if (m_infoPopup != null)
        {
            if (m_infoPopup.SetText(m_visualGate.titleText, m_visualGate.descriptionText))
            {
                m_isHighlighted = true;
                StartCoroutine(OnHighlight());
            }
        }
    }
Exemplo n.º 4
0
    private IEnumerator OnDrag()
    {
        while (m_isBeingDragged)
        {
            //Drag Logic

            Vector2 mousePosition = m_visualGridManager.GetSnapPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y), m_visualGate);
            m_rectTransform.anchoredPosition = mousePosition;

            if (Input.GetMouseButtonUp(1))
            {
                VisualGate visualGate = GetComponent <VisualGate>();
                if (visualGate != null)
                {
                    visualGate.Rotate(true);
                }
            }

            yield return(null);
        }
    }
Exemplo n.º 5
0
    public bool IsGridObjectValid(Vector2 _position, VisualGate _gate, bool _convertToCanvas)
    {
        GridObject gridObject = null;
        Vector2Int oGrid      = Vector2Int.zero;

        if (GetGridCoordinates(_position, ref oGrid, _convertToCanvas))
        {
            CellCoordinates cell = new CellCoordinates((uint)oGrid.x, (uint)oGrid.y);

            switch (_gate.gateType)
            {
            case GateType.Add:
            {
                gridObject = new AddGate(cell, _gate.objectOrientation);
                break;
            }

            case GateType.Subtract:
            {
                gridObject = new SubtractGate(cell, _gate.objectOrientation);
                break;
            }

            case GateType.Multiply:
            {
                gridObject = new MultiplyGate(cell, _gate.objectOrientation);
                break;
            }

            case GateType.Divide:
            {
                gridObject = new DivideGate(cell, _gate.objectOrientation);
                break;
            }

            case GateType.IncrementDecrement:
            {
                gridObject = new IncrementDecrementGate(cell, _gate.objectOrientation);
                break;
            }

            case GateType.Cross:
            {
                gridObject = new CrossGate(cell, _gate.objectOrientation);
                break;
            }

            case GateType.Replicate:
            {
                gridObject = new ReplicateGate(cell, _gate.objectOrientation);
                break;
            }
            }

            foreach (CellCoordinates coordinates in gridObject.Coordinates)
            {
                if (coordinates.X < 1 || coordinates.Y < 1 || coordinates.X > gridWidth || coordinates.Y > gridHeight)
                {
                    return(false);
                }
            }

            return(true);
        }

        return(false);
    }
    // Update is called once per frame
    public void RegenerateButtons(List <GateType> _gates, List <int> _incDecValues)
    {
        //Delete old GameObjects
        if (levelObjects != null)
        {
            foreach (GameObject menuObject in levelObjects)
            {
                Destroy(menuObject);
            }
        }

        levelObjects = new List <GameObject>();

        float gateSize = 80;

        foreach (GateType gateType in _gates)
        {
            int numToCreate = 1;
            if (gateType == GateType.IncrementDecrement)
            {
                numToCreate = _incDecValues.Count;
            }

            for (int i = 0; i < numToCreate; ++i)
            {
                RectTransform rect = iconPrefabs[(int)gateType].GetComponent <RectTransform>();
                gateSize += rect.sizeDelta.y + 40;
            }
        }
        gateSize += 40;

        scrollView.GetComponent <RectTransform>().sizeDelta = new Vector2(scrollView.GetComponent <RectTransform>().sizeDelta.x, gateSize);

        //Make Buttons
        int   buttonCount = 0;
        float gateHeight  = gateSize - 100.0f;

        foreach (GateType gateType in _gates)
        {
            int numToCreate = 1;
            if (gateType == GateType.IncrementDecrement)
            {
                numToCreate = _incDecValues.Count;
            }

            for (int i = 0; i < numToCreate; ++i)
            {
                GameObject gateButton = Instantiate(iconPrefabs[(int)gateType], scrollView.transform);
                levelObjects.Add(gateButton);

                RectTransform rect = gateButton.GetComponent <RectTransform>();
                rect.anchoredPosition = new Vector2(94.0f, gateHeight);
                gateHeight           -= rect.sizeDelta.y + 50.0f;

                if (gateType == GateType.IncrementDecrement)
                {
                    int        value  = _incDecValues[i];
                    VisualGate incDec = gateButton.GetComponent <VisualGate>();
                    incDec.value = value;

                    gateButton.transform.Find("Text").GetComponent <Text>().text = (value <= 0 ? "" : "+") + value;
                }

                buttonCount++;
            }
        }
    }
Exemplo n.º 7
0
    public virtual new void OnPointerUp(PointerEventData _eventData)
    {
        if (_eventData.button == PointerEventData.InputButton.Left)
        {
            if (!m_wireManager.IsInWireEditMode())
            {
                DoStateTransition(currentSelectionState, false);
                m_isBeingDragged = false;

                if (m_infoPopup != null && m_isHighlighted)
                {
                    m_isHighlighted = false;
                    m_infoPopup.PopText();
                }

                Vector2Int      oGrid          = Vector2Int.zero;
                CellCoordinates oldCoordinates = m_cellCoordinates;

                if (m_visualGridManager.GetGridCoordinates(m_rectTransform.anchoredPosition, ref oGrid, false) &&
                    m_visualGridManager.IsGridObjectValid(m_rectTransform.anchoredPosition, m_visualGate, false))
                {
                    CellCoordinates cell = new CellCoordinates((uint)oGrid.x, (uint)oGrid.y);
                    m_cellCoordinates = cell;

                    if (m_isPlaced)
                    {
                        if (m_cellCoordinates != oldCoordinates)
                        {
                            m_gameplayManager.ClearCell(oldCoordinates, true);
                        }
                    }

                    if (m_visualGate != null)
                    {
                        VisualGate visualGate = GetComponent <VisualGate>();
                        if (visualGate != null)
                        {
                            if (visualGate.gateType != GateType.IncrementDecrement)
                            {
                                m_gameplayManager.AddGate(visualGate.gateType, cell, visualGate.objectOrientation, gameObject, 0, m_isPlaced);
                            }
                            else
                            {
                                m_gameplayManager.AddGate(visualGate.gateType, cell, visualGate.objectOrientation, gameObject, visualGate.value, m_isPlaced);
                            }

                            if (!m_isPlaced)
                            {
                                GameObject copy = Instantiate(gameObject, m_gameplayManager.scrollViewParent);
                                copy.GetComponent <VisualBase>().ResetBase();
                                copy.GetComponent <RectTransform>().anchoredPosition = visualGate.GetSpawnLocation();
                            }
                        }
                    }

                    //If we were on a space clear it
                    if (m_isPlaced)
                    {
                        m_gameplayManager.UpdateGiblets(m_cellCoordinates, true);
                    }

                    m_isPlaced = true;
                }
                else
                {
                    if (!m_isPlaced)
                    {
                        if (m_visualGate != null)
                        {
                            GetComponent <RectTransform>().SetParent(m_gameplayManager.scrollViewParent);
                            GetComponent <RectTransform>().anchoredPosition = m_visualGate.GetSpawnLocation();
                            GetComponent <VisualBase>().ResetBase();
                        }
                    }
                    else
                    {
                        //If we have already been placed. Kill yourself
                        m_gameplayManager.ClearCell(oldCoordinates, true);
                        Destroy(gameObject);
                    }
                }
            }
        }
    }