/// <summary> /// Gets the full text of the item and its selected option to show on the menu page. /// </summary> /// <param name="isSelected">Specifies if the current menu item is selected.</param> /// <returns>A <see cref="string"/> representation of this item.</returns> public string ToString(bool isSelected) { MenuItemOption selectedOption = SelectedOption; string text; if (string.IsNullOrEmpty(Name)) { text = selectedOption != null ? selectedOption.Text : string.Empty; } else if (selectedOption == null || string.IsNullOrEmpty(selectedOption.Text)) { text = Name; } else { text = string.Format("{0}: {1}", Name, selectedOption.Text); } if (isSelected) { if (Options.Count > 1) { text = string.Format("<{0}>", text); } else { text = string.Format("[{0}]", text); } } return(text); }
/// <summary> /// Manages option selection and invocation when specific keys are pressed. /// </summary> /// <param name="inputManager">The input manager to use when retrieving the key states.</param> public virtual void Update(InputManager inputManager) { if (inputManager.IsNewKeyDown(Keys.A) || inputManager.IsNewKeyDown(Keys.Left)) { if (--_selectedOptionIndex < 0) { if (Options.Count > 0) { _selectedOptionIndex = Options.Count - 1; } else { _selectedOptionIndex = 0; } } } else if (inputManager.IsNewKeyDown(Keys.D) || inputManager.IsNewKeyDown(Keys.Right)) { if (++_selectedOptionIndex >= Options.Count) { _selectedOptionIndex = 0; } } else if (inputManager.IsNewKeyDown(Keys.Enter)) { MenuItemOption selectedOption = SelectedOption; if (selectedOption != null) { SelectedOption.InvokeAction(); } } }