Skip to content
Snippets Groups Projects
DisplayScrolls.cs 1.63 KiB
Newer Older
  • Learn to ignore specific revisions
  • MaZiFAU's avatar
    MaZiFAU committed
    using System.Collections.Generic;
    
    using System.Linq;
    
    using TMPro;
    
    BenniHome's avatar
    BenniHome committed
    
    public class DisplayScrolls : MonoBehaviour
    {
    
        static public List<REST_JSON_API.Scroll> AllowedScrolls;
    
        public GameObject[] ScrollButtons;
    
        public GameObject ScrollPrefab;
    
        public GameObject DetailScreen;
    
        public Transform scrollscreenContent;
    
    BenniHome's avatar
    BenniHome committed
    
    
    MaZiFAU's avatar
    MaZiFAU committed
            BuildScrollGUI();
    
    MaZiFAU's avatar
    MaZiFAU committed
        void BuildScrollGUI()
    
    Richard Marcus's avatar
    Richard Marcus committed
        {
    
            while (GlobalBehaviour.InitiateScrolls.MoveNext()) ; // active wait for server, should be rare
    
            AllowedScrolls = StageStatic.stage?.AllowedScrolls == null
                ? GlobalBehaviour.AvailableScrolls
                : GlobalBehaviour.AvailableScrolls
                    .Where(s => StageStatic.stage.AllowedScrolls.Contains(s.ScrollReference))
                    .ToList();
    
    Richard Marcus's avatar
    Richard Marcus committed
            //Build Selection-GUI of Scrolls
    
    MaZiFAU's avatar
    MaZiFAU committed
            ScrollButtons = new GameObject[AllowedScrolls.Count()];
    
            for (int i = 0; i < AllowedScrolls.Count; i++)
    
    MaZiFAU's avatar
    MaZiFAU committed
            {
                var obj = Instantiate(ScrollPrefab, scrollscreenContent);
    
                obj.GetComponent<ScrollClickedScript>().scroll = AllowedScrolls[i];
    
    Richard Marcus's avatar
    Richard Marcus committed
                obj.GetComponent<ScrollClickedScript>().DetailScreen = this.DetailScreen;
    
                obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = AllowedScrolls[i].label;
    
    Richard Marcus's avatar
    Richard Marcus committed
                ScrollButtons[i] = obj;
            }
    
            REST_JSON_API.Scroll preferredStartScroll = AllowedScrolls.Find(x => x.label.Equals(preferredStartScrollName));
    
            if (preferredStartScroll != null)
    
                ScrollDetails.Instance?.SetScroll(preferredStartScroll);
    
    Richard Marcus's avatar
    Richard Marcus committed
        }
    
    BenniHome's avatar
    BenniHome committed
    }