示例#1
0
文件: MainMenu.cs 项目: ylyking/Myre
        public MainMenu(TestGame game, CommandConsole console, GraphicsDevice device, ContentManager content, IServiceProvider services)
        {
            this.game = game;
            this.player = game.Player;

            ui = new UserInterface(device);
            ui.Actors.Add(player);

            var tests = from type in Assembly.GetExecutingAssembly().GetTypes()
                        where typeof(TestScreen).IsAssignableFrom(type)
                        where !type.IsAbstract
                        select type;

            this.menu = new Menu(ui.Root);
            menu.SetPoint(Points.BottomLeft, 50, -50);

            int index = 0;
            foreach (var test in tests)
            {
                index++;

                var testKernel = new StandardKernel();
                testKernel.Bind<GraphicsDevice>().ToConstant(device);
                testKernel.Bind<ContentManager>().ToConstant(new ContentManager(services));
                testKernel.Bind<Game>().ToConstant(game);
                testKernel.Bind<TestGame>().ToConstant(game);
                testKernel.Bind<CommandConsole>().ToConstant(console);
                testKernel.Bind<IServiceProvider>().ToConstant(game.Services);
                //testKernel.Bind<InputActor>().ToConstant(player);

                var instance = testKernel.Get(test) as TestScreen;

                var menuOption = new TextButton(menu, content.Load<SpriteFont>("Consolas"), instance.Name);
                menuOption.Highlight = Color.Red;
                menuOption.Gestures.Bind((gesture, time, input) => Manager.Push(instance), new MouseReleased(MouseButtons.Left), new KeyReleased(Keys.Enter));
            }

            var quit = new TextButton(menu, content.Load<SpriteFont>("Consolas"), "Exit");
            quit.Highlight = Color.Red;
            quit.Gestures.Bind((gesture, time, input) => game.Exit(), new MouseReleased(MouseButtons.Left), new KeyReleased(Keys.Enter));

            menu.Arrange(Justification.Left);
        }
示例#2
0
 public ConsoleWriter(CommandConsole commandConsole)
 {
     _commandConsole = commandConsole;
 }
示例#3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            _ui = new UserInterface(GraphicsDevice);

            Player = new InputActor(1, new MouseDevice(), new KeyboardDevice(PlayerIndex.One, Window.Handle));
            //Kernel.Bind<InputActor>().ToConstant(player);
            Components.Add(Player);
            _ui.Actors.Add(Player);

            var statLog = new StatisticTextLog(_ui.Root, Content.Load<SpriteFont>("Consolas"), true);
            statLog.SetPoint(Points.TopLeft, 10, 10);

            _frameTime = Statistic.Create("Misc.Time", "{0:00.00}ms");
            _fps = new FrequencyTracker("Misc.FPS");

            var console = new CommandConsole(this, Content.Load<SpriteFont>("Consolas"), _ui.Root);
            Kernel.Bind<CommandConsole>().ToConstant(console);

            _screens = new ScreenManager();
            _screens.Push(Kernel.Get<MainMenu>());

            base.Initialize();
        }