Example #1
0
    void Start()
    {
        HappinessGameInfo.PuzzleInit();

        RectTransform rt = (RectTransform)transform;

        float cellWidth  = rt.rect.width / HappinessGameInfo.PuzzleSize;
        float cellHeight = rt.rect.height / HappinessGameInfo.PuzzleSize;
        float largeSize  = Mathf.Min(cellHeight, cellWidth);

        int topRowCount = HappinessGameInfo.PuzzleSize >> 1;
        int botRowCount = HappinessGameInfo.PuzzleSize - topRowCount;

        // Make sure bottom row is the smaller of the two
        while (topRowCount < botRowCount)
        {
            topRowCount++;
            botRowCount--;
        }
        float smallSize  = Mathf.Min(cellWidth / topRowCount, cellHeight / 2);
        int   halfTopRow = topRowCount >> 1;
        float topRowLeft = (smallSize * halfTopRow);

        if ((topRowCount & 1) == 0)
        {
            topRowLeft -= (smallSize / 2);
        }
        int   halfBotRow = botRowCount >> 1;
        float botRowLeft = (smallSize * halfBotRow);

        if ((botRowCount & 1) == 0)
        {
            botRowLeft -= (smallSize / 2);
        }


        Cells = new GameCell[HappinessGameInfo.PuzzleSize, HappinessGameInfo.PuzzleSize];
        for (int y = 0; y < HappinessGameInfo.PuzzleSize; y++)
        {
            for (int x = 0; x < HappinessGameInfo.PuzzleSize; x++)
            {
                // Create the cell
                string   cellName = string.Format("Cell_{0}_{1}", x, y);
                GameCell gc       = new GameObject(cellName, typeof(RectTransform), typeof(GameCell)).GetComponent <GameCell>();
                gc.transform.SetParent(transform);
                gc.GetComponent <RectTransform>().SetAnchorAndPivot(AnchorPresets.TopLeft, PivotPresets.TopLeft);
                gc.Setup(x, y, cellWidth, cellHeight, largeSize, smallSize, topRowCount, botRowCount, topRowLeft, botRowLeft);

                // Add the frame
                Instantiate(FramePrefab, gc.transform, false);
                Cells[x, y]   = gc;
                gc.CellDialog = CellDialog;
            }
        }

        CellDialog.Init();
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        HappinessGameInfo.PuzzleInit();

        foreach (Clue c in HappinessGameInfo.Puzzle.VerticalClues)
        {
            GameObject vc = Instantiate(VCPrefab, transform);

            GameObject top    = vc.transform.Find("Top").gameObject;
            GameObject center = vc.transform.Find("Center").gameObject;
            GameObject bottom = vc.transform.Find("Bottom").gameObject;

            int[] iIcons   = new int[3];
            int[] iRows    = c.GetRows();
            int   numIcons = c.GetIcons(HappinessGameInfo.Puzzle, iIcons);

            top.GetComponent <Image>().sprite    = HappinessGameInfo.GetIcon(iRows[0], iIcons[0]);
            center.GetComponent <Image>().sprite = HappinessGameInfo.GetIcon(iRows[1], iIcons[1]);
            if (numIcons == 3)
            {
                bottom.GetComponent <Image>().sprite = HappinessGameInfo.GetIcon(iRows[2], iIcons[2]);
            }
            else
            {
                bottom.gameObject.SetActive(false);
            }

            switch (c.m_VerticalType)
            {
            case eVerticalType.Two:
            case eVerticalType.Three:
                break;

            case eVerticalType.EitherOr:
                CreateEitherOrOverlay(vc.transform);
                break;

            case eVerticalType.TwoNot:
                Image not = CreateNotOverlay(center, vc.transform);
                not.rectTransform.anchoredPosition = new Vector2(0, 30);
                break;

            case eVerticalType.ThreeTopNot:
                CreateNotOverlay(top, vc.transform);
                break;

            case eVerticalType.ThreeMidNot:
                CreateNotOverlay(center, vc.transform);
                break;

            case eVerticalType.ThreeBotNot:
                CreateNotOverlay(bottom, vc.transform);
                break;
            }
        }
    }
Example #3
0
    void CreateSmallIcon(int row, int i, float smallSize, float x, float y)
    {
        GameObject smallIcon = new GameObject("SmallIcon_" + i, typeof(Image));

        smallIcon.transform.SetParent(transform);
        Image ri = smallIcon.GetComponent <Image>();

        //ri.color = new Color(0.125f * i, 0, 0);
        ri.rectTransform.sizeDelta        = new Vector2(smallSize, smallSize);
        ri.rectTransform.localScale       = Vector3.one;
        ri.rectTransform.anchoredPosition = new Vector2(x, y);
        ri.raycastTarget = false;
        ri.sprite        = HappinessGameInfo.GetIcon(row, i);
        ri.raycastTarget = false;
        SmallIcons.Add(ri);
    }
Example #4
0
    protected void UpdateIcons(int row, int col)
    {
        Row = row;
        Col = col;
        int iFinal = GetFinalIcon();

        if (iFinal >= 0)
        {
            if (!FinalIcon.gameObject.activeInHierarchy)
            {
                FinalIcon.gameObject.SetActive(true);
                foreach (Image img in SmallIcons)
                {
                    img.gameObject.SetActive(false);
                }
            }

            FinalIcon.sprite = HappinessGameInfo.GetIcon(row, iFinal);
        }
        else
        {
            FinalIcon.gameObject.SetActive(false);
            bool[] values = GetSmallIconValues();
            for (int i = 0; i < HappinessGameInfo.PuzzleSize; i++)
            {
                SmallIcons[i].sprite = HappinessGameInfo.GetIcon(Row, i);
                if (GreyOutEliminated)
                {
                    SmallIcons[i].gameObject.SetActive(true);
                    SmallIcons[i].color = values[i] ? Vector4.one : new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
                }
                else
                {
                    SmallIcons[i].gameObject.SetActive(values[i]);
                }
            }
        }
    }
Example #5
0
    // Use this for initialization
    void Start()
    {
        HappinessGameInfo.PuzzleInit();

        foreach (Clue c in HappinessGameInfo.Puzzle.HorizontalClues)
        {
            GameObject hc = Instantiate(HCPrefab, transform);

            GameObject left   = hc.transform.Find("Left").gameObject;
            GameObject center = hc.transform.Find("Center").gameObject;
            GameObject right  = hc.transform.Find("Right").gameObject;

            int[] iIcons    = new int[3];
            int[] iRows     = c.GetRows();
            int   iNumIcons = c.GetIcons(HappinessGameInfo.Puzzle, iIcons);

            left.GetComponent <Image>().sprite = HappinessGameInfo.GetIcon(iRows[0], iIcons[0]);

            if (c.m_HorizontalType == eHorizontalType.LeftOf || c.m_HorizontalType == eHorizontalType.NotLeftOf)
            {
                center.GetComponent <Image>().sprite = NextTo;
                right.GetComponent <Image>().sprite  = HappinessGameInfo.GetIcon(iRows[1], iIcons[1]);

                if (c.m_HorizontalType == eHorizontalType.NotLeftOf)
                {
                    CreateNotOverlay(center, hc.transform);
                }
            }
            else
            {
                center.GetComponent <Image>().sprite = HappinessGameInfo.GetIcon(iRows[1], iIcons[1]);
                if (iNumIcons == 3)
                {
                    right.GetComponent <Image>().sprite = HappinessGameInfo.GetIcon(iRows[2], iIcons[2]);

                    switch (c.m_HorizontalType)
                    {
                    case eHorizontalType.NextTo:
                    case eHorizontalType.LeftOf:
                    case eHorizontalType.NotLeftOf:
                        break;

                    case eHorizontalType.NotNextTo:
                        CreateNotOverlay(center, hc.transform);
                        break;

                    case eHorizontalType.Span:
                        CreateSpanOverlay(hc.transform);
                        break;

                    case eHorizontalType.SpanNotLeft:
                        CreateSpanOverlay(hc.transform);
                        CreateNotOverlay(left, hc.transform);
                        break;

                    case eHorizontalType.SpanNotMid:
                        CreateSpanOverlay(hc.transform);
                        CreateNotOverlay(center, hc.transform);
                        break;

                    case eHorizontalType.SpanNotRight:
                        CreateSpanOverlay(hc.transform);
                        CreateNotOverlay(right, hc.transform);
                        break;
                    }
                }
                else
                {
                    right.gameObject.SetActive(false);
                }
            }
        }
    }