예제 #1
0
 private void GetHamburgerButton()
 {
     hamburgerButton = GameObject.Find("MenuButton"); // Fine (Object in hierarchy)
     if (hamburgerButton != null)
     {
         hamburgerButtonScript = hamburgerButton.GetComponent <HamburgerButton>();
     }
 }
예제 #2
0
        public HamburgerMenu()
        {
            DebugWrite();

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                InitializeComponent();
            }
            else
            {
                // hamburger menu property changes
                PropertyChangedHandlers.Add(nameof(IsFullScreen), e => FullScreenPropertyChanged((bool?)e.OldValue, (bool?)e.NewValue));
                PropertyChangedHandlers.Add(nameof(Selected), e => SelectedPropertyChanged(e.OldValue as HamburgerButtonInfo, e.NewValue as HamburgerButtonInfo));
                PropertyChangedHandlers.Add(nameof(DisplayMode), e => DisplayModePropertyChanged((SplitViewDisplayMode)e.OldValue, (SplitViewDisplayMode)e.NewValue));
                PropertyChangedHandlers.Add(nameof(HamburgerButtonVisibility), e => HamburgerButtonVisibilityPropertyChanged((Visibility)e.NewValue));
                PropertyChangedHandlers.Add(nameof(IsOpen), e => IsOpenPropertyChanged((bool)e.OldValue, (bool)e.NewValue));
                PropertyChangedHandlers.Add(nameof(NavigationService), e => NavigationServicePropertyChanged(e.OldValue as INavigationService, e.NewValue as INavigationService));
                PropertyChangedHandlers.Add(nameof(AccentColor), e => AccentColorPropertyChanged(e.OldValue as Color?, e.NewValue as Color?));
                PropertyChangedHandlers.Add(nameof(HeaderContent), e => HeaderContentPropertyChanged(e.OldValue, e.NewValue));

                // default values;
                PrimaryButtons   = new ObservableCollection <HamburgerButtonInfo>();
                SecondaryButtons = new ObservableCollection <HamburgerButtonInfo>();

                // calling this now, let's handlers wire up before styles apply
                InitializeComponent();

                // control event handlers
                Loaded        += HamburgerMenu_Loaded;
                LayoutUpdated += HamburgerMenu_LayoutUpdated;

                // xbox controller menu button support
                KeyboardService.Instance.AfterMenuGesture += () =>
                {
                    HamburgerCommand.Execute();
                    HamburgerButton.Focus(FocusState.Programmatic);
                };

                GotFocus += (s, e) =>
                {
                    var element = FocusManager.GetFocusedElement() as FrameworkElement;
                    var name    = element?.Name ?? "no-name";
                    var content = (((element as ContentControl)?.Content as StackPanel)?.Children[0] as SymbolIcon)?.Symbol.ToString();
                    if (content == null)
                    {
                        content = (element as ContentControl)?.Content?.ToString() ?? "no-content";
                    }
                    var value = $"{element?.ToString() ?? "null"} {name} {content}";
                    DebugWrite(value, caller: "GotFocus");
                };
            }
        }
예제 #3
0
        private async void GamePage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(GameViewModel.Progress))
            {
                AdjustTemp(((GameViewModel)BindingContext).Progress);
            }
            else if (e.PropertyName == nameof(GameViewModel.VictoryMode))
            {
                bool state = ((GameViewModel)BindingContext).VictoryMode;
                Shell.Current.FlyoutBehavior = state ? FlyoutBehavior.Disabled : FlyoutBehavior.Flyout;
                if (state)
                {
                    OldImage.Opacity = 1;
                    HamburgerButton.FadeTo(0, 800u, Easing.CubicOut);
                    await BottomSheet.TranslateTo(0, Height, 800u, Easing.CubicOut);

                    Darkener.FadeTo(0.4);
                    VictoryView.FadeTo(1);
                }
                else
                {
                    Darkener.FadeTo(0);
                    await VictoryView.FadeTo(0);

                    await OldImage.FadeTo(0, easing : Easing.CubicIn);

                    await Task.Delay(250);

                    HamburgerButton.FadeTo(0.85);
                    await BottomSheet.TranslateTo(0, positions[1], 350u, Easing.CubicOut);
                }
            }
            else if (e.PropertyName == nameof(GameViewModel.IsDone))
            {
                if (((GameViewModel)BindingContext).IsDone)
                {
                    TempFinisher.FadeTo(1);
                }
                else
                {
                    TempFinisher.FadeTo(0);
                }
            }
        }
예제 #4
0
 private void ContentFrameOnNavigated(object sender, NavigationEventArgs args)
 {
     if (ContentFrame.BackStackDepth > 0)
     {
         HamburgerButton.ShowBack();
         if (ContentFrame.Content is SongsCollectionPage)
         {
             AppTitleTextBlock.Foreground = HamburgerButton.Foreground = new SolidColorBrush(Colors.White);
         }
     }
     else
     {
         AppTitleTextBlock.Text = App.ResourceLoader.GetString("Text_Title_App");
         HamburgerButton.ShowMenu();
         AppTitleTextBlock.Foreground = HamburgerButton.Foreground = App.Current.Resources["TitleBarForegroundBrush"] as SolidColorBrush;
         Spotlight.Show(true);
         App.ResetTitleBarToAccentColor();
     }
 }
예제 #5
0
        public HamburgerMenu()
        {
            DebugWrite();

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                InitializeComponent();
            }
            else
            {
                // default values;
                PrimaryButtons   = new ObservableCollection <HamburgerButtonInfo>();
                SecondaryButtons = new ObservableCollection <HamburgerButtonInfo>();

                // calling this now, let's handlers wire up before styles apply
                InitializeComponent();

                // control event handlers
                Loaded        += HamburgerMenu_Loaded;
                LayoutUpdated += HamburgerMenu_LayoutUpdated;

                // xbox controller menu button support
                KeyboardService.Instance.AfterMenuGesture += () =>
                {
                    HamburgerCommand.Execute();
                    HamburgerButton.Focus(FocusState.Programmatic);
                };

                GotFocus += (s, e) =>
                {
                    var element    = FocusManager.GetFocusedElement() as FrameworkElement;
                    var name       = element?.Name ?? "no-name";
                    var stackpanel = (element as ContentControl)?.Content as StackPanel;
                    var symbolicon = stackpanel?.Children[0] as SymbolIcon;
                    var symbol     = symbolicon?.Symbol.ToString();
                    symbol = symbol ?? (element as ContentControl)?.Content?.ToString() ?? "no-content";
                    var value = $"{element?.ToString() ?? "null"} name:{name} symbol:{symbol}";
                    DebugWrite(value, caller: "GotFocus");
                };
            }
        }
예제 #6
0
        private void OnHamburgerButtonClick(object sender, RoutedEventArgs e)
        {
            if (isAnimating)
            {
                return;
            }

            isAnimating = true;

            var storyboardName     = isPaneOpened ? "CloseMenu" : "OpenMenu";
            var storyboard         = (Storyboard)HamburgerButton.FindResource(storyboardName);
            var storyboardAccessor = new StoryboardAccessor(storyboard);

            storyboardAccessor.HandleCompleted(() =>
            {
                storyboardAccessor.UnhandleCompleted();
                isAnimating  = false;
                isPaneOpened = !isPaneOpened;

                var visibility = isPaneOpened ? ScrollBarVisibility.Auto : ScrollBarVisibility.Hidden;
                ListView1.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, visibility);
            });
            storyboard.Begin();
        }
예제 #7
0
        private void HamburgerMenu_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            var currentItem = FocusManager.GetFocusedElement() as FrameworkElement;
            var firstItem   = LoadedNavButtons.FirstOrDefault(x => x.HamburgerButtonInfo == (PrimaryButtons.Any() ? PrimaryButtons.FirstOrDefault() : SecondaryButtons.FirstOrDefault()));
            var lastItem    = LoadedNavButtons.FirstOrDefault(x => x.HamburgerButtonInfo == (SecondaryButtons.Any() ? SecondaryButtons.LastOrDefault() : PrimaryButtons.LastOrDefault()));

            var focus = new Func <FocusNavigationDirection, bool>(d =>
            {
                if (d == FocusNavigationDirection.Next)
                {
                    return(FocusManager.TryMoveFocus(d));
                }
                else if (d == FocusNavigationDirection.Previous)
                {
                    return(FocusManager.TryMoveFocus(d));
                }
                else
                {
                    var control = FocusManager.FindNextFocusableElement(d) as Control;
                    return(control?.Focus(FocusState.Programmatic) ?? false);
                }
            });

            var escape = new Func <bool>(() =>
            {
                if (DisplayMode == SplitViewDisplayMode.CompactOverlay ||
                    DisplayMode == SplitViewDisplayMode.Overlay)
                {
                    IsOpen = false;
                }
                if (Equals(ShellSplitView.PanePlacement, SplitViewPanePlacement.Left))
                {
                    ShellSplitView.Content.RenderTransform = new TranslateTransform {
                        X = 48 + ShellSplitView.OpenPaneLength
                    };
                    focus(FocusNavigationDirection.Right);
                    ShellSplitView.Content.RenderTransform = null;
                }
                else
                {
                    ShellSplitView.Content.RenderTransform = new TranslateTransform {
                        X = -48 - ShellSplitView.OpenPaneLength
                    };
                    focus(FocusNavigationDirection.Left);
                    ShellSplitView.Content.RenderTransform = null;
                }
                return(true);
            });

            var previous = new Func <bool>(() =>
            {
                if (Equals(currentItem, HamburgerButton))
                {
                    return(true);
                }
                else if (Equals(currentItem, firstItem.FrameworkElement))
                {
                    return(HamburgerButton.Focus(FocusState.Programmatic));
                }
                else if (focus(FocusNavigationDirection.Previous) || focus(FocusNavigationDirection.Up))
                {
                    return(true);
                }
                else
                {
                    return(escape());
                }
            });

            var next = new Func <bool>(() =>
            {
                if (Equals(currentItem, HamburgerButton))
                {
                    return(focus(FocusNavigationDirection.Down));
                }
                else if (Equals(currentItem, lastItem.FrameworkElement))
                {
                    return(escape());
                }
                else if (focus(FocusNavigationDirection.Next) || focus(FocusNavigationDirection.Down))
                {
                    return(true);
                }
                else
                {
                    return(escape());
                }
            });

            switch (e.Key)
            {
            case VirtualKey.Up:
            case VirtualKey.GamepadDPadUp:

                if (!(e.Handled = previous()))
                {
                    Debugger.Break();
                }
                break;

            case VirtualKey.Down:
            case VirtualKey.GamepadDPadDown:

                if (!(e.Handled = next()))
                {
                    Debugger.Break();
                }
                break;

            case VirtualKey.Right:
            case VirtualKey.GamepadDPadRight:

                if (SecondaryButtonContainer.Items.Contains(currentItem?.DataContext) &&
                    SecondaryButtonOrientation == Orientation.Horizontal)
                {
                    if (Equals(lastItem.FrameworkElement, currentItem))
                    {
                        if (!(e.Handled = escape()))
                        {
                            Debugger.Break();
                        }
                    }
                    else
                    {
                        if (!(e.Handled = next()))
                        {
                            Debugger.Break();
                        }
                    }
                }
                else
                {
                    if (!(e.Handled = escape()))
                    {
                        Debugger.Break();
                    }
                }
                break;

            case VirtualKey.Left:
            case VirtualKey.GamepadDPadLeft:

                if (SecondaryButtonContainer.Items.Contains(currentItem?.DataContext) &&
                    SecondaryButtonOrientation == Orientation.Horizontal)
                {
                    if (Equals(lastItem.FrameworkElement, currentItem))
                    {
                        if (!(e.Handled = escape()))
                        {
                            Debugger.Break();
                        }
                    }
                    else
                    {
                        if (!(e.Handled = previous()))
                        {
                            Debugger.Break();
                        }
                    }
                }
                else
                {
                    if (!(e.Handled = escape()))
                    {
                        Debugger.Break();
                    }
                }
                break;

            case VirtualKey.Space:
            case VirtualKey.Enter:
            case VirtualKey.GamepadA:

                var info = new InfoElement(currentItem);
                NavCommand.Execute(info?.HamburgerButtonInfo);
                break;

            case VirtualKey.Escape:
            case VirtualKey.GamepadB:

                if (!(e.Handled = escape()))
                {
                    Debugger.Break();
                }
                break;
            }
        }