Exemple #1
0
        private void NewGameMenuSelected(object sender, EventArgs e)
        {
            var worlds = Directory.GetFiles("Content/World", "*.vgs");

            if (worlds.Length == 1)
            {
                LoadingScreen.Load(ScreenManager, new Screen[] { new GameplayScreen(worlds[0]) });
            }
            else
            {
                ScreenManager.AddScreen(SelectorMenuScreen.Create("Select a world!", worlds, StartWorld));
            }
        }
Exemple #2
0
        public static SelectorMenuScreen Create(string title, string[] items, EventHandler <MenuItemSelectedEventArgs> menuItemSelectedEventHandler)
        {
            var titleWidth   = Assets.StandardFont.MeasureString(title).X;
            var maxItemWidth = (int)items.Max(item => Assets.StandardFont.MeasureString(item).X);
            var menuWidth    = Math.Max(titleWidth, maxItemWidth);
            var maxHeight    = (int)items.Max(item => Assets.StandardFont.MeasureString(item).Y);
            var menuHeight   = (items.Length + 2) * maxHeight;

            var screen = new SelectorMenuScreen()
            {
                MenuItems = items.Select(label => new MenuItem(label, "", menuItemSelectedEventHandler)).ToList(),
                title     = title,
                IsOverlay = true,
                BlockScreenUpdatesBelow = true,
                menuSize = new Vector2(menuWidth, menuHeight) * 1.1f
            };

            screen.SetupDefaultMenuItemPositions();
            return(screen);
        }