Esempio n. 1
0
        public InputStateManager(SAMViewportAdapter gameAdap, SAMViewportAdapter hudAdap, float mapOffsetX, float mapOffsetY)
        {
            adapterGame = gameAdap;
            adapterHUD  = hudAdap;

            stateCache = InputState.GetInitialState(mapOffsetX, mapOffsetY);
        }
Esempio n. 2
0
		private InputState(SAMViewportAdapter adapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs, InputState prev)
		{
			Mouse = ms;
			Keyboard = ks;
			TouchPanel = ts;
			GamePad = gs;

			if (Mouse.LeftButton == ButtonState.Pressed)
			{
				IsDown = true;
				PointerPosition = adapter.PointToScreen(Mouse.Position);
			}
			else if (TouchPanel.Count > 0)
			{
				IsDown = true;
				PointerPosition = adapter.PointToScreen(TouchPanel[0].Position.ToPoint());
			}
			else
			{
				IsDown = false;
				PointerPosition = prev.PointerPosition;
			}

			IsJustDown = IsDown && !prev.IsDown;
			IsJustUp = !IsDown && prev.IsDown;

			lastKeyState = prev.currentKeyState;
			currentKeyState = lastKeyState.ToDictionary(p => p.Key, p => ks.IsKeyDown(p.Key));
		}
Esempio n. 3
0
		public InputState(SAMViewportAdapter adapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs)
		{
			Mouse = ms;
			Keyboard = ks;
			TouchPanel = ts;
			GamePad = gs;

			if (Mouse.LeftButton == ButtonState.Pressed)
			{
				IsDown = true;
				PointerPosition = adapter.PointToScreen(Mouse.Position);
			}
			else if (TouchPanel.Count > 0)
			{
				IsDown = true;
				PointerPosition = adapter.PointToScreen(TouchPanel[0].Position.ToPoint());
			}
			else
			{
				IsDown = false;
				PointerPosition = FPoint.Zero;
			}

			currentKeyState = new Dictionary<Keys, bool>(0);
		}
Esempio n. 4
0
        protected override void OnInit(GDWorldMapScreen screen)
        {
            vp = screen.VAdapterGame;

            rectStart = screen.GuaranteedMapViewport;
            rectFinal = screen.Graph.BoundingViewport;
        }
Esempio n. 5
0
        private void Initialize()
        {
            MapFullBounds = CreateMapFullBounds();
            VAdapterGame  = CreateViewport();
            VAdapterHUD   = CreateViewport();           // later perhaps diff adapters

            InternalBatch   = new SpriteBatch(Graphics.GraphicsDevice);
            FixedBatch      = new SpriteBatchWrapper(InternalBatch);
            TranslatedBatch = new SpriteBatchWrapper(InternalBatch);

            InputStateMan = new InputStateManager(VAdapterGame, VAdapterHUD, MapOffsetX, MapOffsetY);
            GameHUD       = CreateHUD();
            Background    = CreateBackground();

            Entities = CreateEntityManager();

            DebugDisp = new DummyDebugTextDisplay();

            GameHUD.Validate();

#if DEBUG
            FPSCounter = new RealtimeAPSCounter();
            UPSCounter = new RealtimeAPSCounter();
            GCMonitor  = new GCMonitor();

            DebugMap = CreateDebugMinimap();
#endif
        }
Esempio n. 6
0
        protected override void OnInit(GDWorldMapScreen screen)
        {
            vp = screen.VAdapterGame;

            rectStart = screen.GuaranteedMapViewport;

            rectFinal = _node.DrawingBoundingRect.AsResized(0.5f, 0.5f);
        }
Esempio n. 7
0
        protected override void OnInit(GDWorldMapScreen screen)
        {
            vp = screen.VAdapterGame;

            rectStart = screen.GuaranteedMapViewport;

            rectFinal = FRectangle.CreateByCenter(centerPos, GDConstants.VIEW_WIDTH, GDConstants.VIEW_HEIGHT);
        }
Esempio n. 8
0
		public static InputState GetState(SAMViewportAdapter adapter, InputState previous)
		{
			var ks = Microsoft.Xna.Framework.Input.Keyboard.GetState();
			var ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
			var ts = Microsoft.Xna.Framework.Input.Touch.TouchPanel.GetState();
			var gs = Microsoft.Xna.Framework.Input.GamePad.GetState(PlayerIndex.One);

			return new InputState(adapter, ks, ms, ts, gs, previous);
		}
Esempio n. 9
0
        protected override void OnInit(GDOverworldScreen screen)
        {
            vp = screen.VAdapterGame;

            rectStart = screen.GuaranteedMapViewport;

            rectFinal = FRectangle.CreateByCenter(_gdNode.Position, new FSize(1.8f * GDConstants.TILE_WIDTH, 1.8f * GDConstants.TILE_WIDTH))
                        .SetRatioUnderfitKeepCenter(GDConstants.VIEW_WIDTH * 1f / GDConstants.VIEW_HEIGHT);
        }
Esempio n. 10
0
        public LeaveTransitionOverworldAgent(GDWorldMapScreen scrn, bool faster) : base(scrn, faster ? DURATION_FAST : DURATION)
        {
            _gdScreen = scrn;
            vp        = scrn.VAdapterGame;

            rectStart = scrn.GuaranteedMapViewport;

            rectFinal = scrn.Graph.BoundingViewport;
        }
Esempio n. 11
0
        public ZoomInAgent(GDWorldMapScreen scrn, FPoint pos) : base(scrn, DURATION)
        {
            _gdScreen = scrn;
            vp        = scrn.VAdapterGame;

            rectStart = scrn.GuaranteedMapViewport;

            rectFinal = FRectangle.CreateByCenter(pos, GDConstants.VIEW_WIDTH, GDConstants.VIEW_HEIGHT);
        }
Esempio n. 12
0
        public static InputState GetState(SAMViewportAdapter gameAdapter, SAMViewportAdapter hudAdapter, InputState previous, float mox, float moy)
        {
            var ks = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            var ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
            var ts = Microsoft.Xna.Framework.Input.Touch.TouchPanel.GetState();
            var gs = Microsoft.Xna.Framework.Input.GamePad.GetState(PlayerIndex.One);

            return(new InputState(gameAdapter, hudAdapter, ks, ms, ts, gs, previous, mox, moy));
        }
Esempio n. 13
0
        public ZoomOutAgent(GDWorldMapScreen scrn) : base(scrn, DURATION)
        {
            _gdScreen = scrn;
            vp        = scrn.VAdapterGame;

            rectStart = scrn.GuaranteedMapViewport;

            rectFinal = scrn.Graph.BoundingViewport;
        }
        protected override void OnInit(GDOverworldScreen screen)
        {
            _gdNode = screen.GetEntities <OverworldNode>().First(n => n.ContentID == _focus.ID);
            vp      = screen.VAdapterGame;

            rectStart = FRectangle.CreateByCenter(_gdNode.Position, new FSize(1.8f * GDConstants.TILE_WIDTH, 1.8f * GDConstants.TILE_WIDTH))
                        .SetRatioUnderfitKeepCenter(GDConstants.VIEW_WIDTH * 1f / GDConstants.VIEW_HEIGHT);

            rectFinal = screen.GuaranteedMapViewport;
        }
        public ReappearTransitionAgent(GDOverworldScreen scrn, GraphBlueprint g) : base(scrn, DURATION)
        {
            _gdNode = scrn.GetEntities <OverworldNode>().First(n => n.ContentID == g.ID);
            vp      = scrn.VAdapterGame;

            rectStart = FRectangle.CreateByCenter(_gdNode.Position, new FSize(1.8f * GDConstants.TILE_WIDTH, 1.8f * GDConstants.TILE_WIDTH))
                        .SetRatioUnderfitKeepCenter(GDConstants.VIEW_WIDTH * 1f / GDConstants.VIEW_HEIGHT);

            rectFinal = scrn.GuaranteedMapViewport;
        }
Esempio n. 16
0
        public TransitionZoomInToTutorialAgent(GDOverworldScreen scrn, OverworldNode_Tutorial node) : base(scrn, DURATION)
        {
            _gdNode = node;
            vp      = scrn.VAdapterGame;

            rectStart = scrn.GuaranteedMapViewport;

            rectFinal = FRectangle.CreateByCenter(node.Position, new FSize(1.8f * GDConstants.TILE_WIDTH, 1.8f * GDConstants.TILE_WIDTH))
                        .SetRatioUnderfitKeepCenter(GDConstants.VIEW_WIDTH * 1f / GDConstants.VIEW_HEIGHT);
        }
        protected override void OnInit(GDWorldMapScreen screen)
        {
            vp = screen.VAdapterGame;

            rectStart = screen.Graph.BoundingViewport;

            var pos = screen.GetInitialNode().Position;

            rectFinal = FRectangle.CreateByCenter(pos, GDConstants.VIEW_WIDTH, GDConstants.VIEW_HEIGHT);
        }
Esempio n. 18
0
        public LeaveTransitionGameEndAgent(GDWorldMapScreen scrn, bool slower, WarpGameEndNode node) : base(scrn, slower ? DURATION_SLOW : DURATION)
        {
            _gdScreen = scrn;
            _node     = node;
            vp        = scrn.VAdapterGame;

            rectStart = scrn.GuaranteedMapViewport;

            rectFinal = node.DrawingBoundingRect.AsResized(0.5f, 0.5f);
        }
        public InitialTransitionAgent(GDWorldMapScreen scrn) : base(scrn, DURATION)
        {
            _gdScreen = scrn;
            vp        = scrn.VAdapterGame;

            rectStart = scrn.Graph.BoundingViewport;

            var pos = scrn.GetInitialNode().Position;

            rectFinal = FRectangle.CreateByCenter(pos, GDConstants.VIEW_WIDTH, GDConstants.VIEW_HEIGHT);
        }
Esempio n. 20
0
		public InputStateManager(SAMViewportAdapter vadap)
		{
			adapter = vadap;

			stateCache = InputState.GetInitialState(vadap);
		}
Esempio n. 21
0
		protected GameBackground(GameScreen scrn)
		{
			Owner = scrn;
			VAdapter = Owner.VAdapter;
		}
Esempio n. 22
0
        public readonly float LastPinchPower        = 0f;  // squared

        private InputState(SAMViewportAdapter gameAdapter, SAMViewportAdapter hudAdapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs, InputState prev, float mox, float moy)
        {
            Mouse      = ms;
            Keyboard   = ks;
            TouchPanel = ts;
            GamePad    = gs;


            AllGamePointerPositions = new FPoint[TouchPanel.Count];
            float sumX = 0;
            float sumY = 0;

            for (int i = 0; i < TouchPanel.Count; i++)
            {
                AllGamePointerPositions[i] = gameAdapter.PointToScreen(TouchPanel[i].Position.ToPoint());
                sumX += TouchPanel[i].Position.X;
                sumY += TouchPanel[i].Position.Y;
            }

            if (Mouse.LeftButton == ButtonState.Pressed)
            {
                isDown = true;
                GamePointerPosition = gameAdapter.PointToScreen(Mouse.Position);
                HUDPointerPosition  = hudAdapter.PointToScreen(Mouse.Position);
            }
            else if (TouchPanel.Count == 1)
            {
                isDown = true;
                GamePointerPosition = AllGamePointerPositions[0];
                HUDPointerPosition  = hudAdapter.PointToScreen(TouchPanel[0].Position.ToPoint());
            }
            else if (TouchPanel.Count == 0)
            {
                isDown = false;
                GamePointerPosition = prev.GamePointerPosition;
                HUDPointerPosition  = prev.HUDPointerPosition;
            }
            else                // if (TouchPanel.Count > 1)
            {
                isDown = false; // this is correct - down onl when one finger
                GamePointerPosition = gameAdapter.PointToScreen(sumX / TouchPanel.Count, sumY / TouchPanel.Count);
                HUDPointerPosition  = hudAdapter.PointToScreen(sumX / TouchPanel.Count, sumY / TouchPanel.Count);
            }

            GamePointerPositionOnMap = GamePointerPosition.RelativeTo(mox, moy);

            isJustDown = isDown && !prev.isDown;
            isJustUp   = !isDown && prev.isDown;

            lastKeyState    = prev.currentKeyState;
            currentKeyState = lastKeyState.ToDictionary(p => p.Key, p => IsKeyDown(p.Key, ks, gs));


            LastPinchPower = prev.LastPinchPower;
            if (TouchPanel.Count == 2)
            {
                if (prev.IsGesturePinching)
                {
                    IsGesturePinching   = true;
                    _pinchStartDistance = prev._pinchStartDistance;
                }

                var p1 = hudAdapter.PointToScreen(TouchPanel[0].Position.ToPoint());                 // hud positions cause HUD will (?) not be resized
                var p2 = hudAdapter.PointToScreen(TouchPanel[1].Position.ToPoint());

                while (Microsoft.Xna.Framework.Input.Touch.TouchPanel.IsGestureAvailable)
                {
                    var g = Microsoft.Xna.Framework.Input.Touch.TouchPanel.ReadGesture();

                    if (g.GestureType == GestureType.Pinch)
                    {
                        IsGesturePinching   = true;
                        _pinchStartDistance = prev._pinchStartDistance ?? (p1 - p2).LengthSquared();
                    }
                    else if (g.GestureType == GestureType.PinchComplete && prev._pinchStartDistance != null)
                    {
                        IsGesturePinchComplete = true;
                        LastPinchPower         = ((p1 - p2).LengthSquared() - prev._pinchStartDistance.Value) / 5000;
                    }
                }
            }
        }
Esempio n. 23
0
 protected GameBackground(GameScreen scrn)
 {
     Owner    = scrn;
     VAdapter = Owner.VAdapterGame;
 }