Interaction logic for AchievementNotificationBox.xaml
Inheritance: System.Windows.Window
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args) 
        {
            ObjectFactory.Configure(a =>
            {
                a.For<IAchievementRepository>()
                 .Singleton()
                 .Use<AppDataXmlCompletedAchievementsRepository>()
                 .Ctor<string>("storageFile")
                 .Is("AchievementStorage_ConsoleTest.xml");
                
                a.For<IAchievementService>()
                 .Singleton()
                 .Use<SerialStrokesAchievementService>();
            });

            var achievementService = ObjectFactory.GetInstance<IAchievementService>();
            achievementService.LoadAchievementsFrom(typeof(ArrayLengthPropertyAchievement).Assembly);

            notificationBox = new AchievementNotificationBox(achievementService);

            var cultureToTest = "ru-RU"; // Set to "ru-RU" to enable russian. Set to "nl" for dutch

            // Comment the following line to use operating system default culture.
            //Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureToTest);

            achievementService.AchievementsUnlocked += AchievementContext_AchievementsUnlocked;
            achievementService.ResetAchievementProgress();

            achievementService.StaticAnalysisCompleted += DetectionDispatcher_DetectionCompleted;
            var file = System.IO.Path.GetFullPath("TestFile.cs");

            achievementService.PerformStaticAnalysis(new StaticAnalysisManifest()
            {
                ActiveFile = file,
                ChangedFiles = new string[] { file },
                CodeFiles = new string[] { file }
            }, true);

            System.Console.Read();
        }