Esempio n. 1
0
        public void Show()
        {
            if (_useAnimation)
            {
                var inAnimation = new PopInThemeAnimation();
                var storyboard  = UIHelper.CreateStoryboard(inAnimation);
                Storyboard.SetTarget(inAnimation, Popup);
                storyboard.Begin();
            }

            Popup.IsOpen = true;
            _opening?.Invoke(_content);
            RearrangePopup(App.AppViewModel.GetDpiAwareAppWindowSize());
        }
Esempio n. 2
0
 private void VisualStateGroup_CurrentStateChanged(object sender, VisualStateChangedEventArgs e)
 {
     if (SettingHelper.DeviceType == DeviceType.PC)
     {
         // 之前有Right而之后没有,补充动画
         if (e.OldState != Left && e.NewState == Left)
         {
             var animation = new PopInThemeAnimation
             {
                 FromHorizontalOffset = 0,
                 FromVerticalOffset   = 100,
                 SpeedRatio           = 0.5
             };
             Storyboard.SetTarget(animation, Lframe);
             Storyboard storyboard = new Storyboard();
             storyboard.Children.Add(animation);
             storyboard.Begin();
         }
     }
 }
Esempio n. 3
0
 private void VisualStateGroup_OnCurrentStateChanged(object sender, VisualStateChangedEventArgs e)
 {
     if (DeviceInfoHelper.DeviceType == DeviceType.Desktop)
     {
         //从RightFrame返回MainShellView,加动画
         if (e.OldState == Show123 || e.OldState == Show3)
         {
             if (e.NewState == Show12 || e.NewState == Show2)
             {
                 var animation = new PopInThemeAnimation
                 {
                     FromHorizontalOffset = 0,
                     FromVerticalOffset   = 100,
                     SpeedRatio           = 0.5,
                 };
                 Storyboard.SetTarget(animation, centerPanel);
                 var sb = new Storyboard();
                 sb.Children.Add(animation);
                 sb.Begin();
             }
         }
     }
 }
Esempio n. 4
0
        private void PerformPlacement(double horizontalOffset, double verticalOffset)
        {
            double           x         = 0.0;
            double           y         = 0.0;
            PlacementMode    placement = this.Placement;
            FrameworkElement element   = this.PlacementTarget as FrameworkElement;
            bool             isRTL     = (element != null) ? (element.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft) : false;

            if ((element != null) && !element.IsHitTestVisible)
            {
                return;
            }

            switch (placement)
            {
            case PlacementMode.Bottom:
            case PlacementMode.Left:
            case PlacementMode.Right:
            case PlacementMode.Top:
                Point[] target = GetTransformedPoints(element, isRTL, element);
                Point[] menu   = GetTransformedPoints((FrameworkElement)_hostPopup.Child, isRTL, element);
                if (menu[0].X > menu[1].X)
                {
                    return;
                }
                Point p2 = PlacePopup(_windowBounds, target, menu, placement);
                x = p2.X;
                if (isRTL)
                {
                    // TODO: Handle RTL - PerformPlacement
                    //x = _windowBounds.Width - x;
                    //this._hostPopup.VerticalOffset = y;
                    //this._hostPopup.HorizontalOffset = x;
                    //return;
                }
                y = p2.Y;
                break;

            case PlacementMode.Mouse:
                throw new NotImplementedException("Mouse PlacementMode is not implemented.");
            }

            if (x < 0.0)
            {
                x = 0.0;
            }

            if (y < 0.0)
            {
                y = 0.0;
            }


            var calcH = this.CalculateHorizontalCenterOffset(x, ((FrameworkElement)_hostPopup.Child).ActualWidth, element.ActualWidth);
            var calcY = this.CalculateVerticalCenterOffset(y, ((FrameworkElement)_hostPopup.Child).ActualHeight, element.ActualHeight);

            if (calcH < 0)
            {
                calcH = GUTTER_BUFFER;
            }
            else
            {
                // TODO: Correct right nudge positioning as it is incorrect
                if ((calcH > _windowBounds.Width) || (calcH + ((FrameworkElement)_hostPopup.Child).ActualWidth) > _windowBounds.Width)
                {
                    calcH = _windowBounds.Width - ((FrameworkElement)_hostPopup.Child).ActualWidth - GUTTER_BUFFER;
                }
            }

            _hostPopup.HorizontalOffset = calcH;
            _hostPopup.VerticalOffset   = calcY;
            _hostPopup.IsHitTestVisible = true;
            _hostPopup.Opacity          = 1;

            // for entrance animation
            // UX guidelines show a PopIn animation
            Storyboard          inAnimation = new Storyboard();
            PopInThemeAnimation popin       = new PopInThemeAnimation();

            // TODO: Switch statement begs of refactoring
            switch (this.Placement)
            {
            case PlacementMode.Bottom:
                popin.FromVerticalOffset   = -10;
                popin.FromHorizontalOffset = 0;
                break;

            case PlacementMode.Left:
                popin.FromVerticalOffset   = 0;
                popin.FromHorizontalOffset = 10;
                break;

            case PlacementMode.Right:
                popin.FromVerticalOffset   = 0;
                popin.FromHorizontalOffset = -10;
                break;

            case PlacementMode.Top:
                popin.FromVerticalOffset   = 10;
                popin.FromHorizontalOffset = 0;
                break;
            }
            Storyboard.SetTarget(popin, _hostPopup);
            inAnimation.Children.Add(popin);
            inAnimation.Begin();
        }
Esempio n. 5
0
        private void PrepareAndAddCurrencyStats(string ticker, string displayName, ref ScrollViewer scrollViewer)
        {
            TextBlock        currencyLabel, usdLabel, btcLabel, userAmountLabel, userUSDValueLabel;
            CustomStackPanel stackPanelToUpdate;

            string
                stackPanelStr               = ticker + "StackPanel",
                labelStr                    = ticker + "Label",
                labelContentStr             = displayName + " Stats:",
                labelUSDStr                 = ticker + "USD",
                labelUSDContentStr          = "USD Price: $" + result.price_usd,
                labelBTCStr                 = ticker + "BTC",
                labelBTCContentStr          = "BTC Price: " + result.price_btc,
                labelUserAmountStr          = ticker + "UserAmount",
                labelUserAmountContentStr   = "Amount you own: ",
                labelUserUSDValueStr        = ticker + "UserUSDVal",
                labelUserUSDValueContentStr = "Your estimated USD value: ";

            // add label if currency not already displayed
            stackPanelToUpdate = GetChildOfStackPanel(rightStackPanelRef, stackPanelStr) as CustomStackPanel;

            if (stackPanelToUpdate == null)
            {
                // create new StackPanel to hold labels
                stackPanelToUpdate = new CustomStackPanel
                {
                    Name   = stackPanelStr,
                    Margin = new Thickness(5, 0, 5, 5)
                };

                stackPanelToUpdate.PointerEntered += PointerEnteredStackPanel;
                stackPanelToUpdate.PointerExited  += PointerExitedStackPanel;

                ColumnDefinition currencyLabelColumnDefinitionLeft = new ColumnDefinition
                {
                    Width = new GridLength(8, GridUnitType.Star)
                };
                ColumnDefinition currencyLabelColumnDefinitionRight = new ColumnDefinition
                {
                    Width = new GridLength(2, GridUnitType.Star)
                };

                // create and add currency grid
                Grid currencyGrid = new Grid
                {
                    HorizontalAlignment = HorizontalAlignment.Left
                };

                currencyGrid.ColumnDefinitions.Add(currencyLabelColumnDefinitionLeft);
                currencyGrid.ColumnDefinitions.Add(currencyLabelColumnDefinitionRight);

                currencyLabel = new TextBlock
                {
                    FontWeight = FontWeights.Bold,
                    FontSize   = 40,
                    Text       = labelContentStr,
                    Name       = labelStr
                };
                currencyGrid.Children.Add(currencyLabel);
                Grid.SetColumn(currencyLabel, 0);

                //Button deleteCurrencyButton = new Button
                stackPanelToUpdate.RemoveButton = new Button
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Content             = new SymbolIcon(Symbol.Clear),
                    Tag        = stackPanelStr,
                    Background = new SolidColorBrush {
                        Opacity = 0
                    },
                    Opacity   = 0,
                    IsEnabled = false
                };

                stackPanelToUpdate.RemoveButton.Click += RemoveCurrencyStatsForCurrency;

                currencyGrid.Children.Add(stackPanelToUpdate.RemoveButton);
                Grid.SetColumn(stackPanelToUpdate.RemoveButton, 1);

                //stackPanelToUpdate.Children.Add(currencyLabel);
                stackPanelToUpdate.Children.Add(currencyGrid);

                // create and add usdLabel
                usdLabel = new TextBlock
                {
                    Name     = labelUSDStr,
                    FontSize = 22,
                    Text     = labelUSDContentStr
                };
                stackPanelToUpdate.Children.Add(usdLabel);

                // create and add btcLabel
                btcLabel = new TextBlock
                {
                    Name     = labelBTCStr,
                    FontSize = 22,
                    Text     = labelBTCContentStr
                };
                stackPanelToUpdate.Children.Add(btcLabel);

                // create and add user holding amount label
                userAmountLabel = new TextBlock
                {
                    Name     = labelUserAmountStr,
                    FontSize = 22,
                    Text     = labelUserAmountContentStr + addedAmount.ToString()
                };
                stackPanelToUpdate.Children.Add(userAmountLabel);

                // create and add userUSDValue label
                userUSDValueLabel = new TextBlock
                {
                    Name       = labelUserUSDValueStr,
                    FontSize   = 22,
                    Text       = UpdateUserUSDValueContentStr(ref stackPanelToUpdate, this.result.price_usd, labelUserUSDValueContentStr),
                    Foreground = new SolidColorBrush(Colors.ForestGreen)
                };
                stackPanelToUpdate.Children.Add(userUSDValueLabel);

                rightStackPanelRef.Children.Add(stackPanelToUpdate);

                PopInThemeAnimation popInAnimation = new PopInThemeAnimation
                {
                    Duration             = new Duration(TimeSpan.FromSeconds(1)),
                    FromHorizontalOffset = 300,
                    TargetName           = stackPanelToUpdate.Name
                };

                Storyboard.SetTarget(popInAnimation, stackPanelToUpdate);

                Storyboard popInAnimationStoryboard = new Storyboard();
                popInAnimationStoryboard.Children.Add(popInAnimation);
                popInAnimationStoryboard.Begin();
            }
            else
            {
                // update user value
                stackPanelToUpdate.UserValue = addedAmount * Convert.ToDouble(this.result.price_usd);

                // update price labels
                usdLabel               = GetChildOfStackPanel(stackPanelToUpdate, labelUSDStr) as TextBlock;
                usdLabel.Text          = labelUSDContentStr;
                btcLabel               = GetChildOfStackPanel(stackPanelToUpdate, labelBTCStr) as TextBlock;
                btcLabel.Text          = labelBTCContentStr;
                userUSDValueLabel      = GetChildOfStackPanel(stackPanelToUpdate, labelUserUSDValueStr) as TextBlock;
                userUSDValueLabel.Text = UpdateUserUSDValueContentStr(ref stackPanelToUpdate, this.result.price_usd, labelUserUSDValueContentStr);
                userAmountLabel        = GetChildOfStackPanel(stackPanelToUpdate, labelUserAmountStr) as TextBlock;
                userAmountLabel.Text   = labelUserAmountContentStr + addedAmount.ToString();

                PopInThemeAnimation popInAnimation = new PopInThemeAnimation
                {
                    Duration             = new Duration(TimeSpan.FromSeconds(1)),
                    FromHorizontalOffset = 300,
                    TargetName           = userUSDValueLabel.Name
                };

                Storyboard.SetTarget(popInAnimation, userUSDValueLabel);

                Storyboard popInAnimationStoryboard = new Storyboard();
                popInAnimationStoryboard.Children.Add(popInAnimation);
                popInAnimationStoryboard.Begin();
            }

            UIHelperClass.ScrollToElement(scrollViewer, stackPanelToUpdate);
        }
Esempio n. 6
0
        private async void PunchEffect(PunchingEllipse punchingEllipse)
        {
            //do some cool effect stuff
            try
            {
                //print predicate
                BitmapImage effectSource = new BitmapImage();

                string imagePath = "";
                string sfxPath   = "";
                switch (punchingEllipse.ellipseStatus)
                {
                case PunchingEllipse.EllipseFlags.miss:
                    imagePath = "ms-appx:///Assets/Effect/missEffect.png";
                    sfxPath   = "ms-appx:///Assets/SFX/missSFX.wav";
                    break;

                case PunchingEllipse.EllipseFlags.bad:
                    imagePath = "ms-appx:///Assets/Effect/badEffect.png";
                    sfxPath   = "ms-appx:///Assets/SFX/badSFX.wav";
                    break;

                case PunchingEllipse.EllipseFlags.cool:
                    imagePath = "ms-appx:///Assets/Effect/coolEffect.png";
                    sfxPath   = "ms-appx:///Assets/SFX/coolSFX.wav";
                    break;

                case PunchingEllipse.EllipseFlags.great:
                    imagePath = "ms-appx:///Assets/Effect/greatEffect.png";
                    sfxPath   = "ms-appx:///Assets/SFX/greatSFX.wav";
                    break;

                case PunchingEllipse.EllipseFlags.perfect:
                    imagePath = "ms-appx:///Assets/Effect/perfectEffect.png";
                    sfxPath   = "ms-appx:///Assets/SFX/perfectSFX.wav";
                    break;
                }

                SFXPlayer.Source = new Uri(sfxPath);
                effectSource     = new BitmapImage(new Uri(imagePath));

                //apply audio effect
                SFXPlayer.Play();

                //apply visual evect
                Image effectImage = new Image();
                effectImage.Source = effectSource;
                effectImage.Width  = Definitions.effectPredicateWidth;
                effectImage.Height = Definitions.effectPredicateHeight;
                Canvas.SetLeft(effectImage, punchingEllipse.ellipseSpawnPoint.X - effectImage.Width / 2);
                Canvas.SetTop(effectImage, punchingEllipse.ellipseSpawnPoint.Y - effectImage.Height / 2);
                gameCanvas.Children.Add(effectImage);
                PopInThemeAnimation predicateEffectAnim = new PopInThemeAnimation();
                await Task.Delay(Definitions.punchEffectDuration);

                gameCanvas.Children.Remove(effectImage);
                effectImage = null;
            }
            catch (Exception exc)
            {
                Debug.WriteLine("rendering effect fail >" + exc.InnerException.Message);
            }
        }