Exemple #1
0
        public void SinglePLayerControllerFactoryTest()
        {
            StaticServiceLocator.AddService <IControllerSettings>(new ControllerSettings());
            var controller = new SinglePlayerControllerFactory();

            controller.CreateEntityController(new BaseMovable(), new EightWayPossibleMovement(new CrowDistance()),
                                              new MoverManager());
            const Buttons buttons = Buttons.A;

            controller.AddGamePadButton(new List <IButtonAble>(), buttons);
            controller.AddKeyBoardButton(new List <IButtonAble>(), Keys.A);

            var button = new KeyButton(Keys.A);


            var smart = new SmartController();

            smart.AddButton(new BaseSmartButton(button));
            smart.Update(new GameTime());
        }
Exemple #2
0
        protected MenuScreen(ViewportAdapter viewPort, IServiceProvider serviceProvider)
        {
            _camera = new Camera2D(viewPort)
            {
                Zoom = 1.0f
            };
            _serviceProvider = serviceProvider;
            MenuItems        = new List <MenuItem>();

            _clickController = new ClickController();
            _clickController.MouseControl.OnPressedEvent += (state, mouseState) =>
            {
                CheckClick(mouseState.Position.ToVector2());
            };
            var moveGesture = new SmartGesture(GestureType.Tap);

            moveGesture.GestureEvent += gesture =>
            {
                CheckClick(gesture.Position);
            };
            _clickController.TouchScreenControl.AddSmartGesture(moveGesture);
            var upButtons = new List <IButtonAble>
            {
                new DirectionGamePadButton(Buttons.DPadUp),
                new KeyButton(Keys.W),
                new KeyButton(Keys.Up)
            };
            var downButtons = new List <IButtonAble>
            {
                new DirectionGamePadButton(Buttons.DPadDown),
                new KeyButton(Keys.S),
                new KeyButton(Keys.Down)
            };
            var actionButtons = new List <IButtonAble>
            {
                new GamePadButton(Buttons.A),
                new KeyButton(Keys.E)
            };
            var upAction = new CompositeSmartButton(upButtons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    Selected--;
                }
            };
            var downAction = new CompositeSmartButton(downButtons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    Selected++;
                }
            };
            var action = new CompositeSmartButton(actionButtons)
            {
                OnButtonReleased = (sender, args) =>
                {
                    MenuItems[Selected].Action.Invoke();
                }
            };

            _controller = new SmartController();
            _controller.AddButton(upAction);
            _controller.AddButton(downAction);
            _controller.AddButton(action);
        }
        public void AddInteractionController()
        {
            var controller     = new SmartController();
            var buttonsCreated = StaticServiceLocator.ContainsService <List <IButtonAble> >();

            if (!buttonsCreated)
            {
                var interactButton = new List <IButtonAble>
                {
                    new KeyButton(Keys.E),
                    new GamePadButton(Buttons.A)
                };
                StaticServiceLocator.AddService(interactButton);
            }
            var buttons     = StaticServiceLocator.GetService <List <IButtonAble> >();
            var smartButton = new CompositeSmartButton(buttons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    if (!DialogBox.Interact())
                    {
                        InteractEvent?.Invoke(this, null);
                    }
                }
            };

            controller.AddButton(smartButton);
            var upButton = new List <IButtonAble> {
                new DirectionGamePadButton(Buttons.DPadUp, PlayerIndex.One, false)
            };
            var smartUpButton = new CompositeSmartButton(upButton)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    DialogBox.Up();
                }
            };

            controller.AddButton(smartUpButton);
            var downButton = new List <IButtonAble> {
                new DirectionGamePadButton(Buttons.DPadDown, PlayerIndex.One, false)
            };
            var smartDownButton = new CompositeSmartButton(downButton)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    DialogBox.Down();
                }
            };

            controller.AddButton(smartDownButton);
            var optionsButtons = new List <IButtonAble>
            {
                new KeyButton(Keys.Escape),
                new GamePadButton(Buttons.Start)
            };
            var optionsAction = new CompositeSmartButton(optionsButtons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    _backButtonClickEvent.Invoke(this, null);
                }
            };

            controller.AddButton(optionsAction);
            UpdateList.Add(controller);
        }