Ejemplo n.º 1
0
    private void UpdateTileList()
    {
        // -- TEXTS --
        if_setName.text = currSet.name; // update header

        // -- TILES --
        List <string> termGs = currSet.allTermGs;
        // Destroy any extras.
        int count = 0;

        while (termTiles.Count > termGs.Count)
        {
            TermEditableTile tile = termTiles[termTiles.Count - 1];
            termTiles.Remove(tile);
            Destroy(tile.gameObject);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }
        // Add any missing.
        count = 0;
        while (termTiles.Count < termGs.Count)
        {
            TermEditableTile newTile = Instantiate(ResourcesHandler.Instance.TermEditableTile).GetComponent <TermEditableTile>();
            newTile.Initialize(true, rt_tilesContent);
            termTiles.Add(newTile);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }

        // Now update all the existing tiles!
        for (int i = 0; i < termGs.Count; i++)
        {
            Term             term = dm.library.GetTerm(termGs[i]);
            TermEditableTile tile = termTiles[i];
            if (term == null)
            {
                Debug.LogError("Whoa, can't find a term in the library for this set.");
            }

            tile.SetMyTerm(i, term);
        }
    }
Ejemplo n.º 2
0
    public void RefreshTermTiles()
    {
        // Update resultTerms!
        string searchStr = if_search.text.ToUpperInvariant();

        resultTerms = new List <Term>();
        if (searchStr.Length > 0)
        {
            foreach (Term term in allTerms)
            {
                if (term.native.ToUpperInvariant().Contains(searchStr) ||
                    term.foreign.ToUpperInvariant().Contains(searchStr) ||
                    term.phonetic.ToUpperInvariant().Contains(searchStr))
                {
                    resultTerms.Add(term);
                }
            }
        }

        // Update t_andMore.
        int numHiddenResults = resultTerms.Count - MaxResultsToShow;

        t_andMore.gameObject.SetActive(numHiddenResults > 0);
        if (numHiddenResults > 0)
        {
            t_andMore.text = "...and " + numHiddenResults + " more";
        }

        // Update t_numResults
        t_numResults.text = searchStr.Length == 0 ? "" : resultTerms.Count + " results";


        // Destroy any extras.
        int count = 0;

        while (termTiles.Count > resultTerms.Count)
        {
            TermEditableTile tile = termTiles[termTiles.Count - 1];
            termTiles.Remove(tile);
            Destroy(tile.gameObject);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }
        // Add any missing.
        count = 0;
        while (termTiles.Count < resultTerms.Count && termTiles.Count < MaxResultsToShow)
        {
            TermEditableTile newTile = Instantiate(ResourcesHandler.Instance.TermEditableTile).GetComponent <TermEditableTile>();
            newTile.Initialize(false, rt_tilesContent);
            termTiles.Add(newTile);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }

        // Now update all the tiles!
        for (int i = 0; i < resultTerms.Count && i < MaxResultsToShow; i++)
        {
            TermEditableTile tile = termTiles[i];
            tile.SetMyTerm(i, resultTerms[i]);
        }

        // Update the parent content RT height!
        const float tileHeight    = 130;
        float       tileSpacing   = rt_tilesContent.GetComponent <VerticalLayoutGroup>().spacing;
        float       contentHeight = termTiles.Count * (tileHeight + tileSpacing) + 450;

        rt_scrollContent.sizeDelta = new Vector2(rt_scrollContent.sizeDelta.x, contentHeight);
    }