From de79e014ad283a7f42109f6c2c2bcf44fd132113 Mon Sep 17 00:00:00 2001 From: "nathan@daedalus" Date: Sat, 28 Apr 2012 22:00:15 -0500 Subject: [PATCH] Final commits for new GSM. --HG-- branch : axios-newgsm extra : close : 1 --- axios.suo | Bin 211968 -> 211968 bytes axios/Axios_Windows.csproj.user | 2 +- axios/ScreenSystem/GameScreen.cs | 2 +- axios/ScreenSystem/InputState.cs | 34 ++++++++++++++++ axios/ScreenSystem/MenuScreen.cs | 58 +++++++++++++++++++++++++++- axios/ScreenSystem/ScreenManager.cs | 6 ++- 6 files changed, 98 insertions(+), 4 deletions(-) diff --git a/axios.suo b/axios.suo index e10df79c3a996b302b7fca0fd2927db744f8ba6f..3ca7ae9c5b43c380e09c32ed09545207ae13cf19 100644 GIT binary patch delta 255 zcmZqp!PD@AXG0DP+XcC126dIqMJ$1A%nTe1)9ZT}MW-h$VU(Qwg)4v~f`Ne{7>K6_ zE@9NzT*7^xg_$u5NzvvK0Rbh>ML-pcf%so@uhI5iBgW0yj8&5vH4~;UIL^c|JzzJZ zkcp1I(vrq}l{icU{h!YDcU3s(RKD+2>VFc41< zT*9caxrF;X%jCl>hMP+S1e7LM81qal;AoyF!=$CNIQ_T{m4ZomH?Irn7-{_ I6q$LX0DQkTM*si- diff --git a/axios/Axios_Windows.csproj.user b/axios/Axios_Windows.csproj.user index 566c009..76fe5a5 100644 --- a/axios/Axios_Windows.csproj.user +++ b/axios/Axios_Windows.csproj.user @@ -1,6 +1,6 @@  - ShowAllFiles + ProjectFiles \ No newline at end of file diff --git a/axios/ScreenSystem/GameScreen.cs b/axios/ScreenSystem/GameScreen.cs index 654b6ff..9d58f55 100644 --- a/axios/ScreenSystem/GameScreen.cs +++ b/axios/ScreenSystem/GameScreen.cs @@ -41,7 +41,7 @@ namespace GameStateManagement HasVirtualStick = false; HasCursor = false; } - protected bool HasCursor = false; + public bool HasCursor = false; /// /// Normally when one screen is brought up over the top of another, /// the first screen will transition off to make room for the new diff --git a/axios/ScreenSystem/InputState.cs b/axios/ScreenSystem/InputState.cs index a553459..06ab122 100644 --- a/axios/ScreenSystem/InputState.cs +++ b/axios/ScreenSystem/InputState.cs @@ -14,6 +14,7 @@ using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input.Touch; using FarseerPhysics.SamplesFramework; using Microsoft.Xna.Framework.Graphics; +using System; namespace GameStateManagement { @@ -244,11 +245,32 @@ namespace GameStateManagement return new GamePadState(_stick, Vector2.Zero, 0f, 0f, _buttons.ToArray()); } + public void Draw() + { + if (_cursorIsVisible && _cursorIsValid) + { + _manager.SpriteBatch.Begin(); + _manager.SpriteBatch.Draw(_cursorSprite.Texture, _cursor, null, Color.White, 0f, _cursorSprite.Origin, 1f, SpriteEffects.None, 0f); + _manager.SpriteBatch.End(); + } +#if WINDOWS_PHONE + if (_handleVirtualStick) + { + _manager.SpriteBatch.Begin(); + _phoneA.Draw(_manager.SpriteBatch); + _phoneB.Draw(_manager.SpriteBatch); + _phoneStick.Draw(_manager.SpriteBatch); + _manager.SpriteBatch.End(); + } +#endif + } + /// /// Reads the latest state user input. /// public void Update(GameTime gameTime) { + PlayerIndex p; _lastMouseState = _currentMouseState; if (_handleVirtualStick) { @@ -297,8 +319,10 @@ namespace GameStateManagement Gestures.Clear(); while (TouchPanel.IsGestureAvailable) { + //System.Diagnostics.Debugger.Break(); Gestures.Add(TouchPanel.ReadGesture()); } + //System.Diagnostics.Debugger.Break(); // Update cursor Vector2 oldCursor = _cursor; @@ -314,9 +338,16 @@ namespace GameStateManagement _cursor.X = _currentMouseState.X; _cursor.Y = _currentMouseState.Y; } + + if (this.IsNewKeyPress(Keys.P, PlayerIndex.One, out p)) + Console.WriteLine(_cursor.ToString()); + _cursor.X = MathHelper.Clamp(_cursor.X, 0f, _viewport.Width); _cursor.Y = MathHelper.Clamp(_cursor.Y, 0f, _viewport.Height); + if (this.IsNewKeyPress(Keys.P, PlayerIndex.One, out p)) + Console.WriteLine(_cursor.ToString()); + if (_cursorIsValid && oldCursor != _cursor) { _cursorMoved = true; @@ -345,6 +376,9 @@ namespace GameStateManagement _cursorIsValid = false; } #endif + + if (this.IsNewKeyPress(Keys.P, PlayerIndex.One, out p)) + Console.WriteLine(_viewport.ToString()); } diff --git a/axios/ScreenSystem/MenuScreen.cs b/axios/ScreenSystem/MenuScreen.cs index 771e77d..bc578d8 100644 --- a/axios/ScreenSystem/MenuScreen.cs +++ b/axios/ScreenSystem/MenuScreen.cs @@ -27,6 +27,9 @@ namespace GameStateManagement { #region Fields + // the number of pixels to pad above and below menu entries for touch input + const int menuEntryPadding = 10; + private List menuEntries = new List(); int selectedEntry = 0; string menuTitle; @@ -62,6 +65,8 @@ namespace GameStateManagement public MenuScreen(string menuTitle) { this.menuTitle = menuTitle; + // menus generally only need Tap for menu selection + EnabledGestures = GestureType.Tap; TransitionOnTime = TimeSpan.FromSeconds(0.5); TransitionOffTime = TimeSpan.FromSeconds(0.5); @@ -95,6 +100,19 @@ namespace GameStateManagement #region Handle Input + /// + /// Allows the screen to create the hit bounds for a particular menu entry. + /// + protected virtual Rectangle GetMenuEntryHitBounds(MenuEntry entry) + { + // the hit bounds are the entire width of the screen, and the height of the entry + // with some additional padding above and below. + return new Rectangle( + 0, + (int)entry.Position.Y - menuEntryPadding, + ScreenManager.GraphicsDevice.Viewport.Width, + entry.GetHeight(this) + (menuEntryPadding * 2)); + } /// /// Responds to user input, changing the selected entry and accepting @@ -107,8 +125,10 @@ namespace GameStateManagement // If we pass a null controlling player, the InputState helper returns to // us which player actually provided the input. We pass that through to // OnSelectEntry and OnCancel, so they can tell which player triggered them. - PlayerIndex playerIndex; + +#if WINDOWS || XBOX360 + PlayerIndex playerIndex; // Move to the previous menu entry? if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex)) { @@ -135,6 +155,42 @@ namespace GameStateManagement { OnCancel(playerIndex); } +#endif + +#if WINDOWS_PHONE + //selectedEntry = 1; + + PlayerIndex player; + if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player)) + { + OnCancel(player); + } + + // look for any taps that occurred and select any entries that were tapped + foreach (GestureSample gesture in input.Gestures) + { + //System.Diagnostics.Debugger.Break(); + if (gesture.GestureType == GestureType.Tap) + { + // convert the position to a Point that we can test against a Rectangle + Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y); + + // iterate the entries to see if any were tapped + for (int i = 0; i < menuEntries.Count; i++) + { + MenuEntry menuEntry = menuEntries[i]; + + if (GetMenuEntryHitBounds(menuEntry).Contains(tapLocation)) + { + // select the entry. since gestures are only available on Windows Phone, + // we can safely pass PlayerIndex.One to all entries since there is only + // one player on Windows Phone. + OnSelectEntry(i, PlayerIndex.One); + } + } + } + } +#endif } diff --git a/axios/ScreenSystem/ScreenManager.cs b/axios/ScreenSystem/ScreenManager.cs index 6912ebe..dcd2545 100644 --- a/axios/ScreenSystem/ScreenManager.cs +++ b/axios/ScreenSystem/ScreenManager.cs @@ -144,7 +144,7 @@ namespace GameStateManagement spriteBatch = new SpriteBatch(GraphicsDevice); font = content.Load("menufont"); blankTexture = Game.Content.Load("Materials/blank"); - + input.LoadContent(); // Tell each of the screens to load their content. foreach (GameScreen screen in screens) { @@ -207,6 +207,8 @@ namespace GameStateManagement // give it a chance to handle input. if (!otherScreenHasFocus) { + input.ShowCursor = screen.HasCursor; + input.EnableVirtualStick = screen.HasVirtualStick; screen.HandleInput(gameTime, input); otherScreenHasFocus = true; @@ -244,6 +246,7 @@ namespace GameStateManagement /// public override void Draw(GameTime gameTime) { + foreach (GameScreen screen in screens) { if (screen.ScreenState == ScreenState.Hidden) @@ -251,6 +254,7 @@ namespace GameStateManagement screen.Draw(gameTime); } + input.Draw(); }