/// <summary> /// Change the center button using a CenterButtonShim object, which is used to store the current state of a /// CenterButton in a leightweight way. /// </summary> /// <remarks>This method is used to facilitate transitions between submenus.</remarks> /// <param name="s">Sending object</param> /// <param name="newButton">CenterButtonShim object to take properties for the new button from</param> /// <param name="storePrevious">Should we store the previous center button (for back navigation?)</param> public void ChangeCenterButton(object s, CenterButtonShim newButton, bool storePrevious) { // Store the current button if (storePrevious) { var backupButton = new CenterButtonShim { BorderBrush = CenterButtonBorder, Background = CenterButtonBackgroundFill, Content = CenterButtonIcon, FontSize = CenterButtonFontSize, Top = CenterButtonTop, Left = CenterButtonLeft, CenterButtonTappedHandler = CenterButtonTapped, Opacity = CenterButtonOpacity }; PreviousButtons.Push(backupButton); } // Decorate the current button with new props // Center button style defaults to current style unless overridden CenterButtonBorder = newButton?.BorderBrush ?? CenterButtonBorder; CenterButtonBackgroundFill = newButton?.Background ?? CenterButtonBackgroundFill; CenterButtonIcon = (string)newButton?.Content ?? CenterButtonIcon; CenterButtonFontSize = newButton?.FontSize ?? CenterButtonFontSize; CenterButtonTapped = newButton?.CenterButtonTappedHandler ?? null; CenterButtonOpacity = newButton?.Opacity ?? CenterButtonOpacity; if (newButton != null && !double.IsNaN(newButton.Top ?? 0) && !double.IsNaN(newButton.Left ?? 0)) { CenterButtonTop = newButton.Top ?? CenterButtonTop; CenterButtonLeft = newButton.Left ?? CenterButtonTop; } }
/// <summary> /// Event Handler for a center button tap, calling user-registered events and handling navigation (if enabled) /// </summary> /// <param name="s">Sending object</param> /// <param name="e">Event information</param> private void OnCenterButtonTapped(object s, TappedRoutedEventArgs e) { // If an event has been registered with the center button tap, call it CenterButtonTapped?.Invoke(this, e); if (PreviousPies.Count == 0) { TogglePie(); } if (PreviousPies.Count <= 0 || !IsCenterButtonNavigationEnabled) { return; } // a custom menu may have changed dragability. Ensure we are draggable, of using Floating var floatingParent = FindParent <Floating>(this); if (floatingParent != null) { floatingParent.ShouldManipulateChild = true; } // If we have a previous pie, we're going back to it ChangePie(this, PreviousPies[PreviousPies.Count - 1], false); PreviousPies.RemoveAt(PreviousPies.Count - 1); // We don't necessarily have the same amount of pies and center buttons. // Users can create submenues that don't bring their own center button if (PreviousButtons.Count <= 0) { return; } ChangeCenterButton(this, PreviousButtons.Pop(), false); }
public List <ICommand> GetCommand(int playerIndex) { List <ICommand> pressed = new List <ICommand>(); if (GamePad.GetState(playerIndex).Buttons.Start == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.Start)) { pressed.Add(ButtonsMap[Buttons.Start]); } if (GamePad.GetState(playerIndex).Buttons.A == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.A)) { pressed.Add(ButtonsMap[Buttons.A]); } if (GamePad.GetState(playerIndex).Buttons.B == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.B)) { pressed.Add(ButtonsMap[Buttons.B]); } if (GamePad.GetState(playerIndex).Buttons.X == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.X)) { pressed.Add(ButtonsMap[Buttons.X]); } if (GamePad.GetState(playerIndex).Buttons.Y == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.Y)) { pressed.Add(ButtonsMap[Buttons.Y]); } if (GamePad.GetState(playerIndex).Buttons.Back == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.Back)) { pressed.Add(ButtonsMap[Buttons.Back]); } if (GamePad.GetState(playerIndex).DPad.Up == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.DPadUp)) { pressed.Add(ButtonsMap[Buttons.DPadUp]); } if (GamePad.GetState(playerIndex).DPad.Right == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.DPadRight)) { pressed.Add(ButtonsMap[Buttons.DPadRight]); } if (GamePad.GetState(playerIndex).DPad.Left == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.DPadLeft)) { pressed.Add(ButtonsMap[Buttons.DPadLeft]); } if (GamePad.GetState(playerIndex).DPad.Down == ButtonState.Pressed && !PreviousButtons.IsButtonDown(Buttons.DPadDown)) { pressed.Add(ButtonsMap[Buttons.DPadDown]); } return(pressed); }