AddAchievements() protected method

protected AddAchievements ( IEnumerable achievementDescriptors ) : void
achievementDescriptors IEnumerable
return void
Beispiel #1
0
        public static void ShowAchievements(IEnumerable <Achievement> achievementDescriptors)
        {
            if (achievementDescriptors.Any() == false)
            {
                return;
            }

            var instance = new AchievementNotificationBox();

            instance.AddAchievements(achievementDescriptors);

            // This is only to support the Strokes.Console-project
            if (Application.Current != null)
            {
                const int rightMargin  = 5;
                const int bottomMargin = 5;

                instance.Owner = Application.Current.MainWindow != instance ? Application.Current.MainWindow : instance.Owner;
                instance.Show();
                if (instance.Owner != null)
                {
                    System.Drawing.Rectangle windowRectangle;

                    if (instance.Owner.WindowState == System.Windows.WindowState.Maximized)
                    {
                        /* Here is the magic:
                         * Use Winforms code to find the Available space on the
                         * screen that contained the window
                         * just before it was maximized
                         * (Left, Top have their values from Normal WindowState)
                         */
                        windowRectangle = System.Windows.Forms.Screen.GetWorkingArea(
                            new System.Drawing.Point((int)instance.Owner.Left, (int)instance.Owner.Top));
                    }
                    else
                    {
                        windowRectangle = new System.Drawing.Rectangle((int)instance.Owner.Left, (int)instance.Owner.Top, (int)instance.Owner.ActualWidth, (int)instance.Owner.ActualHeight);
                    }

                    instance.Left = windowRectangle.Left + windowRectangle.Width - instance.Width - rightMargin;
                    instance.Top  = windowRectangle.Top + windowRectangle.Height - instance.Height - bottomMargin;
                }
            }
            else
            {
                // When activated from a console-app, this is called.
                new Application().Run(instance);
            }
        }
        public static void ShowAchievements(IEnumerable<Achievement> achievementDescriptors)
        {
            if (achievementDescriptors.Any() == false)
            {
                return;
            }

            var instance = new AchievementNotificationBox();
            instance.AddAchievements(achievementDescriptors);

            // This is only to support the Strokes.Console-project
            if (Application.Current != null)
            {
                const int rightMargin = 5;
                const int bottomMargin = 5;

                instance.Owner = Application.Current.MainWindow != instance ? Application.Current.MainWindow : instance.Owner;
                instance.Show();
                if(instance.Owner != null)
                {
                    System.Drawing.Rectangle windowRectangle;

                    if (instance.Owner.WindowState == System.Windows.WindowState.Maximized)
                    {
                        /* Here is the magic:
                         * Use Winforms code to find the Available space on the
                         * screen that contained the window
                         * just before it was maximized
                         * (Left, Top have their values from Normal WindowState)
                         */
                        windowRectangle = System.Windows.Forms.Screen.GetWorkingArea(
                            new System.Drawing.Point((int)instance.Owner.Left, (int)instance.Owner.Top));
                    }
                    else
                    {
                        windowRectangle = new System.Drawing.Rectangle((int)instance.Owner.Left, (int)instance.Owner.Top, (int)instance.Owner.ActualWidth, (int)instance.Owner.ActualHeight);
                    }

                    instance.Left = windowRectangle.Left + windowRectangle.Width - instance.Width - rightMargin;
                    instance.Top = windowRectangle.Top + windowRectangle.Height - instance.Height - bottomMargin;
                }
            }
            else
            {
                // When activated from a console-app, this is called.
                new Application().Run(instance);
            }
        }