Ejemplo n.º 1
0
        public static TabRecord DrawTabs(Rect baseRect, List <TabRecord> tabs, float maxTabWidth = 200f)
        {
            TabRecord tabRecord  = null;
            TabRecord tabRecord2 = tabs.Find((TabRecord t) => t.Selected);
            float     num        = baseRect.width + (float)(tabs.Count - 1) * 10f;
            float     tabWidth   = num / (float)tabs.Count;

            if (tabWidth > maxTabWidth)
            {
                tabWidth = maxTabWidth;
            }
            Rect position = new Rect(baseRect);

            position.y     -= 32f;
            position.height = 9999f;
            GUI.BeginGroup(position);
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;
            Func <TabRecord, Rect> func = (TabRecord tab) => new Rect((float)tabs.IndexOf(tab) * (tabWidth - 10f), 1f, tabWidth, 32f);
            List <TabRecord>       list = tabs.ListFullCopy();

            if (tabRecord2 != null)
            {
                list.Remove(tabRecord2);
                list.Add(tabRecord2);
            }
            TabRecord        tabRecord3 = null;
            List <TabRecord> list2      = list.ListFullCopy();

            list2.Reverse();
            for (int i = 0; i < list2.Count; i++)
            {
                TabRecord tabRecord4 = list2[i];
                Rect      rect       = func(tabRecord4);
                if (tabRecord3 == null && Mouse.IsOver(rect))
                {
                    tabRecord3 = tabRecord4;
                }
                MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Tab);
                if (Widgets.ButtonInvisible(rect))
                {
                    tabRecord = tabRecord4;
                }
            }
            foreach (TabRecord item in list)
            {
                Rect rect2 = func(item);
                item.Draw(rect2);
            }
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
            if (tabRecord != null && tabRecord != tabRecord2)
            {
                SoundDefOf.RowTabSelect.PlayOneShotOnCamera();
                if (tabRecord.clickedAction != null)
                {
                    tabRecord.clickedAction();
                }
            }
            return(tabRecord);
        }
Ejemplo n.º 2
0
        public static TabRecord DrawTabs(Rect baseRect, IEnumerable <TabRecord> tabsEnum)
        {
            TabDrawer.tabList.Clear();
            foreach (TabRecord item in tabsEnum)
            {
                TabDrawer.tabList.Add(item);
            }
            TabRecord tabRecord  = null;
            TabRecord tabRecord2 = (from t in TabDrawer.tabList
                                    where t.selected
                                    select t).FirstOrDefault();

            if (tabRecord2 == null)
            {
                Log.ErrorOnce("Drew tabs without any being selected.", 5509712);
                return(TabDrawer.tabList[0]);
            }
            float num      = (float)(baseRect.width + (float)(TabDrawer.tabList.Count - 1) * 10.0);
            float tabWidth = num / (float)TabDrawer.tabList.Count;

            if (tabWidth > 200.0)
            {
                tabWidth = 200f;
            }
            Rect position = new Rect(baseRect);

            position.y     -= 32f;
            position.height = 9999f;
            GUI.BeginGroup(position);
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;
            Func <TabRecord, Rect> func = delegate(TabRecord tab)
            {
                int   num2 = TabDrawer.tabList.IndexOf(tab);
                float x    = (float)((float)num2 * (tabWidth - 10.0));
                return(new Rect(x, 1f, tabWidth, 32f));
            };
            List <TabRecord> list = TabDrawer.tabList.ListFullCopy();

            list.Remove(tabRecord2);
            list.Add(tabRecord2);
            TabRecord        tabRecord3 = null;
            List <TabRecord> list2      = list.ListFullCopy();

            list2.Reverse();
            for (int i = 0; i < list2.Count; i++)
            {
                TabRecord tabRecord4 = list2[i];
                Rect      rect       = func(tabRecord4);
                if (tabRecord3 == null && Mouse.IsOver(rect))
                {
                    tabRecord3 = tabRecord4;
                }
                MouseoverSounds.DoRegion(rect, SoundDefOf.MouseoverTab);
                if (Widgets.ButtonInvisible(rect, false))
                {
                    tabRecord = tabRecord4;
                }
            }
            foreach (TabRecord item2 in list)
            {
                Rect rect2 = func(item2);
                item2.Draw(rect2);
            }
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
            if (tabRecord != null && tabRecord != tabRecord2)
            {
                SoundDefOf.RowTabSelect.PlayOneShotOnCamera(null);
                if (tabRecord.clickedAction != null)
                {
                    tabRecord.clickedAction();
                }
            }
            return(tabRecord);
        }