Пример #1
0
        // -----------------------------------------------------------------------------------
        int SortFunc_ByArtist(CharacterIcon a, CharacterIcon b)
        {
            int compare = string.Compare(a.characterFile.artist, b.characterFile.artist);

            // sort by creation date if they're all from the same artist
            if (compare == 0)
            {
                compare = SortFunc_ByDateCreated(a, b);
            }

            return(compare);
        }
Пример #2
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Scrolls the character icon pages to the left (-1) or right (+1)
        /// </summary>
        IEnumerator ScrollPage(int offset)
        {
            const float ScrollTime = 0.45f;

            // can't scroll
            int next = currentPage + offset;

            if (next >= pageCount || next < 0 || isScrolling)
            {
                yield break;
            }

            isScrolling = true;

            // just move the current and next pages
            RectTransform oldPage = pagesRoot.GetChild(currentPage).GetComponent <RectTransform>();
            RectTransform newPage = pagesRoot.GetChild(next).GetComponent <RectTransform>();

            // by this much (page width). offset here gives us direction
            float dx = widthController.minWidth * offset;

            float elapsed = 0;

            while (elapsed < ScrollTime)
            {
                elapsed += Time.deltaTime;
                float t = Mathf.Clamp01(elapsed / ScrollTime);
                t = IllogicGate.Tweener.EaseOut(t);

                // move one page in and the other out
                oldPage.anchoredPosition = new Vector2(-dx * t, 0);
                newPage.anchoredPosition = new Vector2(dx * (1 - t), 0);
                yield return(null);
            }

            // update the navigation for the random button
            SetRandomButtonNavigation(newPage);

            // "lastHover" is now in the old page.
            // reselect the same position (or the last one int the page, if unavailable)
            int idx = lastHover.transform.GetSiblingIndex();

            if (idx >= newPage.childCount)
            {
                idx = newPage.childCount - 1;
            }
            lastHover = newPage.GetChild(idx).GetComponent <CharacterIcon>();

            currentPage = next;
            isScrolling = false;
        }
Пример #3
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Add an icon to the character grid
        /// </summary>
        public CharacterIcon AddCharacter(CharacterFile.File file)
        {
            CharacterIcon newIcon = Instantiate(sampleIcon, pagesRoot, true);

            newIcon.name          = file.guid;
            newIcon.characterFile = file;
            newIcon.gameObject.SetActive(true);
            newIcon.selected    += OnCharacterSelected;
            newIcon.highlighted += OnCharacterHighlighted;

            availableCharacters.Add(newIcon);

            return(newIcon);
        }
Пример #4
0
 // -----------------------------------------------------------------------------------
 /// <summary>
 /// Callback from the character icon, when a character gets selected.
 /// </summary>
 private void OnCharacterSelected(CharacterIcon icon)
 {
     if (icon == randomButton)
     {
         selected = null;
         avatar.SetCharacter(null);
         roundImages.Reset();
     }
     else
     {
         selected = icon.characterFile;
         avatar.SetCharacter(selected);
         roundImages.SetCharacter(selected);
     }
 }
Пример #5
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Selects the first icon in the grid. You usually
        /// call this right after the menu screen opens
        /// </summary>
        public void SelectFirst()
        {
            Transform     firstPage = pagesRoot.GetChild(0);
            CharacterIcon icon      = random;

            // change to first icon on first page if there are
            // any pages (ie: not empty)
            if (firstPage != null && firstPage.childCount > 0)
            {
                Transform first = firstPage.GetChild(0);
                icon = first.GetComponent <CharacterIcon>();
            }

            icon.Select();
            icon.OnSubmit(null);
        }
Пример #6
0
 // -----------------------------------------------------------------------------------
 int SortFunc_ByDateUpdated(CharacterIcon a, CharacterIcon b)
 {
     System.TimeSpan diff = a.characterFile.updatedDate - b.characterFile.updatedDate;
     if (diff.TotalSeconds > 0)
     {
         return(1);
     }
     else if (diff.TotalSeconds < 0)
     {
         return(-1);
     }
     else
     {
         return(0);
     }
 }
Пример #7
0
        // -----------------------------------------------------------------------------------
        int SortFunc_ByUnplayed(CharacterIcon a, CharacterIcon b)
        {
            Data.CharacterStats stats_a = Data.SaveFile.instance.GetCharacterStats(a.characterFile.guid);
            Data.CharacterStats stats_b = Data.SaveFile.instance.GetCharacterStats(b.characterFile.guid);

            // if both are either played, or unplayed; sort by creation date
            if (stats_a.played == stats_b.played)
            {
                return(SortFunc_ByDateCreated(a, b));
            }

            // else, unplayed comes first
            if (!stats_a.played)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
Пример #8
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Loads all character sheets and sets up icons
        /// </summary>
        /// <returns></returns>
        IEnumerator LoadCharacterSheets()
        {
            Debug.Log("Loading character files");
            string[] files = System.IO.Directory.GetFiles(CharacterFile.File.dataPath, "*.chr");

            foreach (string file in files)
            {
                CharacterFile.File charFile = new CharacterFile.File(file);
                CharacterIcon      icon     = characterGrid.AddCharacter(charFile);
                icon.selected += OnCharacterSelected;
                yield return(null);
            }

            // wait until the charcter grid finishes initializing
            while (!characterGrid.isReady)
            {
                yield return(null);
            }

            characterGrid.Paginate();
            characterGrid.SelectFirst();
        }
Пример #9
0
 // -----------------------------------------------------------------------------------
 private void OnCharacterSelected(CharacterIcon sender)
 {
     selected = sender;
 }
Пример #10
0
 // -----------------------------------------------------------------------------------
 private void OnCharacterHighlighted(CharacterIcon sender)
 {
     lastHover = sender;
 }
Пример #11
0
 // -----------------------------------------------------------------------------------
 int SortFunc_ByCharacterName(CharacterIcon a, CharacterIcon b)
 {
     return(string.Compare(a.characterFile.characterName, b.characterFile.characterName));
 }