Exemple #1
0
    public void Init(Glyph glyph)
    {
        m_glyph = glyph;

        LetterBoxView lbv = GetComponent <LetterBoxView>();

        lbv.SetLetter(GlyphDictionary.UNKNOWN_GLYPH_CHAR);

        lbv.m_glyph.sprite = GlyphVisuals.Instance.GetVisual(glyph.VisualId);
    }
Exemple #2
0
    public void OnPointerUp()
    {
        LetterBoxView lbv    = GetComponent <LetterBoxView>();
        LetterBoxView letter = m_letterPanel.findLetterAtPos(lbv.m_glyph.transform.position);

        if (letter)
        {
            Game.Instance.setPlayerGlyph(letter.m_letter[0], m_glyph);
        }
        lbv.m_glyph.transform.position = m_startPosition;
    }
Exemple #3
0
    public void UpdateWithDictionary(GlyphDictionary dict)
    {
        LetterBoxView lbv = GetComponent <LetterBoxView>();

        if (dict.hasGlyph(m_glyph))
        {
            char letter = dict.getLetter(m_glyph);
            lbv.SetLetter(letter);
        }
        else
        {
            lbv.SetLetter(GlyphDictionary.UNKNOWN_GLYPH_CHAR);
        }
    }
Exemple #4
0
    void OnPuzzleChanged(Puzzle puzzle)
    {
        foreach (var glyph in m_glyphs)
        {
            Destroy(glyph.gameObject);
        }
        m_glyphs.Clear();

        m_prefab.gameObject.SetActive(true);

        m_question.text = puzzle.Definition.Question;

        float       itemWidth       = m_prefab.GetComponent <RectTransform>().rect.width;
        const float itemSeparationX = 8.0f;
        float       panelWidth      = m_panel.GetComponent <RectTransform>().rect.width;
        float       answerWidth     = puzzle.Glyphs.Count * itemWidth + (puzzle.Glyphs.Count - 1) * itemSeparationX;

        float offsetX = (panelWidth - answerWidth) * 0.5f;

        float currentX = -panelWidth / 2.0f + offsetX;
        float currentY = 0;
        int   count    = 0;

        foreach (var glyph in puzzle.Glyphs)
        {
            GameObject newObj = Instantiate(m_prefab.gameObject);

            newObj.name = "glyph_" + (count++).ToString();
            PuzzleLetterView plv = newObj.GetComponent <PuzzleLetterView>();
            LetterBoxView    lbv = newObj.GetComponent <LetterBoxView>();

            plv.Init(glyph);

            newObj.transform.SetParent(m_panel.transform);
            RectTransform newTransform = newObj.GetComponent <RectTransform>();
            newTransform.localPosition = new Vector2(currentX + itemWidth * 0.5f, currentY);

            currentX += itemWidth + itemSeparationX;

            m_glyphs.Add(plv);
        }

        m_prefab.gameObject.SetActive(false);

        m_prevPuzzle.gameObject.SetActive(Game.Instance.CurrentPuzzleIndex > 0);
        m_nextPuzzle.gameObject.SetActive(Game.Instance.CurrentPuzzleIndex < Game.Instance.PuzzleCount - 1);

        OnPlayerDictUpdated(Game.Instance.playerDict);
    }
Exemple #5
0
    void Start()
    {
        m_letters = new List <LetterBoxView>();

        Rect parentRect = m_panel.GetComponent <RectTransform>().rect;
        int  left       = (int)(-parentRect.width / 2);
        int  top        = (int)(parentRect.height / 2);

        float itemWidth  = m_prefab.GetComponent <RectTransform>().rect.width;
        float itemHeight = m_prefab.GetComponent <RectTransform>().rect.height;

        float itemSeparation = 8;

        int   itemsPerRow  = (int)(parentRect.width / (itemWidth + itemSeparation));
        float contentWidth = itemsPerRow * itemWidth + (itemsPerRow - 1) * itemSeparation;
        float offsetX      = (parentRect.width - contentWidth) * 0.5f;

        float currentX = left + offsetX;
        float currentY = top - itemSeparation;

        for (char c = 'a'; c <= 'z'; ++c)
        {
            GameObject newObj = Instantiate(m_prefab.gameObject);
            string     letter = c.ToString();
            newObj.name = "letterBox_" + letter;
            LetterBoxView lbv = newObj.GetComponent <LetterBoxView>();
            lbv.m_letter = letter;


            newObj.transform.SetParent(m_panel.transform);
            RectTransform newTransform = newObj.GetComponent <RectTransform>();
            newTransform.localPosition = new Vector2(currentX + itemWidth / 2, currentY - itemHeight / 2);

            currentX += itemWidth + itemSeparation;

            if (currentX + itemWidth > parentRect.width / 2)
            {
                currentX  = left + offsetX;
                currentY -= itemHeight + itemSeparation;
            }

            m_letters.Add(lbv);
        }
        m_prefab.gameObject.SetActive(false);

        Game.onPlayerDictUpdated += OnPlayerDictUpdated;
    }
Exemple #6
0
    public void OnDrag()
    {
        LetterBoxView lbv = GetComponent <LetterBoxView>();

        lbv.m_glyph.transform.position = Input.mousePosition;
    }