Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the <see cref="Control"/> class.
        /// </summary>
        /// <param name="parent">The user interface to add this control to.</param>
        public Control(UserInterface parent)
            : base(parent.Device, parent.Root)
        {
            if (parent == null)
                throw new ArgumentNullException("parent");

            UserInterface = parent;
            Initialise();
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private static Control CreateUserInterface(Game game)
        {
            UserInterface ui = new UserInterface(game.GraphicsDevice) { DrawOrder = int.MaxValue };
            game.Components.Add(ui);

            var player = new InputActor(1) { new KeyboardDevice(PlayerIndex.One) };
            game.Components.Add(player);
            ui.Actors.Add(player);

            return ui.Root;
        }
Exemplo n.º 4
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();
        }