Beispiel #1
0
        private void CreateTitle()
        {
            TextBox       titleTxt = new TextBox(go.transform, TextRef.Create(title), (int)(fontSize * 1.2f), TextAnchor.MiddleCenter);
            LayoutElement LayEl    = titleTxt.gameObject.AddComponent <LayoutElement>();

            LayEl.minHeight       = fontSize * 1.2f;
            LayEl.preferredHeight = fontSize * 2 * 1.2f;
            LayEl.flexibleWidth   = 1;
            LayEl.flexibleHeight  = 0;
        }
Beispiel #2
0
 protected void BaseRedraw(List <List <TextRef> > info, int numberOfCol)
 {
     for (int i = go.transform.childCount - 1; i >= 0; i--)      // Kill all previous lines
     {
         UnityEngine.Object.Destroy(go.transform.GetChild(i).gameObject);
         go.transform.GetChild(i).SetParent(null);
     }
     if (title != null)
     {
         CreateTitle();
     }
     if (info.Count == 0)        // no data - place a dummy line
     {
         GameObject line = CreateLine();
         for (int i = 0; i < numberOfCol; i++)
         {
             GameObject dataCont = new GameObject("Data Container", typeof(RectTransform));
             dataCont.transform.SetParent(line.transform);
             TextBox data = new TextBox(dataCont.transform, TextRef.Create("#####", false), fontSize, i == 0 ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight);
             if (i == 0)
             {
                 dataCont.AddComponent <LayoutElement>().flexibleWidth = 1;
             }
         }
     }
     else
     {
         for (int i = 0; i < info.Count; i++)
         {
             GameObject line = CreateLine();
             for (int j = 0; j < numberOfCol; j++)
             {
                 GameObject dataCont = new GameObject("Data Container", typeof(RectTransform));
                 dataCont.transform.SetParent(line.transform);
                 dataCont.AddComponent <LayoutElement>();
                 if (widths == null)
                 {
                     ((RectTransform)dataCont.transform).sizeDelta = new Vector2(((RectTransform)line.transform.parent).rect.width / numberOfCol, 50);
                 }
                 else
                 {
                     ((RectTransform)dataCont.transform).sizeDelta          = new Vector2(widths[j], fontSize + 4);
                     dataCont.GetComponent <LayoutElement>().preferredWidth = widths[j];
                 }
                 TextBox data = new TextBox(dataCont.transform, info[i][j], fontSize, j == 0 ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight);
                 if (j == 0)
                 {
                     dataCont.GetComponent <LayoutElement>().flexibleWidth = 1;
                 }
             }
         }
     }
 }
Beispiel #3
0
 private void AddHeaders()
 {
     if (headers != null && headers.Count == colms)
     {
         List <TextRef> blank = new List <TextRef>()
         {
             TextRef.Create("")
         };
         info.Insert(0, blank.Concat(headers).ToList());
     }
     else if (headers != null && headers.Count == colms + 1)
     {
         info.Insert(0, headers);
     }
     else if (headers != null)
     {
         throw new ArgumentException("The headers of this infotable do not have a valid count. Use 'number of colums' or 'number of colums + 1'");
     }
 }
Beispiel #4
0
        public TabbedWindow(Transform parent, Vector2 size, List <Tuple <TextRef, GameObject> > tabs, int tabFontSize = 12, bool canBeMinimised = true)
        {
            go = new GameObject("TabWindow", typeof(RectTransform));
            go.transform.SetParent(parent, false);
            this.size           = size;
            this.canBeMinimised = canBeMinimised;
            this.tabFontSize    = tabFontSize;
            ((RectTransform)go.transform).sizeDelta = size;
            var VLayGr = go.AddComponent <VerticalLayoutGroup>();

            VLayGr.childForceExpandHeight = false;
            VLayGr.childForceExpandWidth  = false;
            GameObject buttonLine = new GameObject("Tab Line", typeof(RectTransform));

            buttonLine.transform.SetParent(go.transform, false);
            var LayEl = buttonLine.AddComponent <LayoutElement>();

            LayEl.minHeight      = tabFontSize * 3 / 2 + 5;
            LayEl.flexibleHeight = 0;
            LayEl.flexibleWidth  = 1;
            var HLayGr = buttonLine.AddComponent <HorizontalLayoutGroup>();

            HLayGr.childForceExpandHeight = false;
            HLayGr.childForceExpandWidth  = false;
            HLayGr.padding = new RectOffset(5, 0, 3, 2);
            GameObject mainWindow = new GameObject("Main Window", typeof(RectTransform));

            mainWindow.transform.SetParent(go.transform, false);
            mainWindow.AddComponent <LayoutElement>().flexibleHeight = 1;
            mainWindow.AddComponent <HorizontalLayoutGroup>();   // used to strech the underlying windows

            windows = new List <Tuple <GameObject, GameObject> >();
            for (int i = 0; i < tabs.Count; i++)
            {
                GameObject tab = new GameObject("Tab", typeof(RectTransform));
                tab.transform.SetParent(buttonLine.transform);
                Image img = tab.AddComponent <Image>();
                img.sprite        = Graphics.GetSprite("tab_image_low");
                img.raycastTarget = true;
                img.type          = Image.Type.Sliced;
                img.fillCenter    = true;

                TextBox text = new TextBox(tab.transform, tabs[i].Item1, tabFontSize);
                text.transform.anchoredPosition += new Vector2(5, 0);

                tab.AddComponent <LayoutElement>().flexibleHeight = 1;
                tab.GetComponent <LayoutElement>().preferredWidth = text.Width + tabFontSize;

                int j = i;
                if (canBeMinimised)
                {
                    tab.AddComponent <Button>().onClick.AddListener(() => { MaximiseWindow(); SetTab(j); });
                }
                else
                {
                    tab.AddComponent <Button>().onClick.AddListener(() => SetTab(j));
                }

                GameObject window = tabs[i].Item2;
                window.transform.SetParent(mainWindow.transform);
                window.SetActive(false);
                windows.Add(new Tuple <GameObject, GameObject>(tab, window));
            }
            if (canBeMinimised)
            {
                GameObject tab = new GameObject("Tab", typeof(RectTransform));
                tab.transform.SetParent(buttonLine.transform);
                Image img = tab.AddComponent <Image>();
                img.sprite        = Graphics.GetSprite("tab_image_low");
                img.raycastTarget = true;
                img.type          = Image.Type.Sliced;
                img.fillCenter    = true;

                TextBox text = new TextBox(tab.transform, TextRef.Create("X", false), tabFontSize);
                ((RectTransform)text.gameObject.transform).anchoredPosition += new Vector2(5, 0);

                tab.AddComponent <LayoutElement>().flexibleHeight = 1;
                tab.GetComponent <LayoutElement>().preferredWidth = text.gameObject.GetComponent <Text>().preferredWidth + tabFontSize;
                int a = windows.Count;
                tab.AddComponent <Button>().onClick.AddListener(() => { SetTab(a); MinimiseWindow(); });

                GameObject window = new GameObject("Null Window", typeof(RectTransform));
                window.transform.SetParent(mainWindow.transform);
                window.SetActive(false);
                windows.Add(new Tuple <GameObject, GameObject>(tab, window));
            }
            if (canBeMinimised)
            {
                MinimiseWindow();
            }
            else
            {
                SetTab(0);
            }
        }