/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState input) { // Move to the previous menu entry? if (input.MenuUp) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } audioManager.PlayCue("menuMove"); } // Move to the next menu entry? if (input.MenuDown) { selectedEntry++; if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } audioManager.PlayCue("menuMove"); } // Accept or cancel the menu? if (input.MenuSelect) { OnSelectEntry(selectedEntry); audioManager.PlayCue("menuSelect"); } else if (input.MenuCancel) { OnCancel(); } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState input) { #if __IOS__ || __ANDROID__ var touch = input.CurrentTouchState; if (touch.Count > 0) { Viewport viewport = ScreenManager.GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 position = new Vector2(0f, viewportSize.Y * 0.55f); foreach (var t in touch) { // we have a touch event if (t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Pressed) { var pos = t.Position; for (int i = 0; i < menuEntries.Count; i++) { // Draw text, centered on the middle of each line. Vector2 size = ScreenManager.Font.MeasureString(menuEntries[i].Text); position.X = viewportSize.X / 2f - size.X / 2f; var rect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); if (rect.Contains(pos)) { selectedEntry = i; OnSelectEntry(selectedEntry); break; } position.Y += ScreenManager.Font.LineSpacing; } } } } #endif // Move to the previous menu entry? if (input.MenuUp) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } audioManager.PlayCue("menuMove"); } // Move to the next menu entry? if (input.MenuDown) { selectedEntry++; if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } audioManager.PlayCue("menuMove"); } // Accept or cancel the menu? if (input.MenuSelect) { OnSelectEntry(selectedEntry); audioManager.PlayCue("menuSelect"); } else if (input.MenuCancel) { OnCancel(); } }