Ejemplo n.º 1
0
        private void btnSaveGame_Click(object sender, RoutedEventArgs e)
        {
            Boolean gameworkerPaused = GameObjectWorker.GetInstance().isPaused();

            GameObjectWorker.GetInstance().cancel();

            string name = txtName.Text.Trim();

            Boolean doSave = true;


            if (SerializedLoadSaveHelpers.SaveGameExists(name))
            {
                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1007"), Translator.GetInstance().GetString("MessageBox", "1007", "message"), WPFMessageBoxButtons.YesNo);

                doSave = result == WPFMessageBoxResult.Yes;

                if (doSave)
                {
                    SerializedLoadSaveHelpers.DeleteSavedGame(name);
                }
            }

            if (doSave)
            {
                SplashControl scSaving = UIHelpers.FindChild <SplashControl>(this, "scSaving");

                scSaving.Visibility = System.Windows.Visibility.Visible;

                BackgroundWorker bgWorker = new BackgroundWorker();
                bgWorker.DoWork += (s, x) =>
                {
                    GameObject.GetInstance().Name = name;

                    SerializedLoadSaveHelpers.SaveGame(name);
                };
                bgWorker.RunWorkerCompleted += (s, x) =>
                {
                    if (!gameworkerPaused)
                    {
                        GameObjectWorker.GetInstance().start();
                    }

                    scSaving.Visibility = System.Windows.Visibility.Collapsed;
                };
                bgWorker.RunWorkerAsync();
            }
        }
        private void lnkSaveGame_Click(object sender, RoutedEventArgs e)
        {
            Boolean gameworkerPaused = GameObjectWorker.GetInstance().isPaused();

            GameObjectWorker.GetInstance().cancel();

            Popup popUpSplash = new Popup();

            popUpSplash.Child           = createSplashWindow("Saving......");
            popUpSplash.Placement       = PlacementMode.Center;
            popUpSplash.PlacementTarget = PageNavigator.MainWindow;
            popUpSplash.IsOpen          = false;


            String name = (String)PopUpSave.ShowPopUp();

            Boolean doSave = name != null;

            if (doSave)
            {
                if (SerializedLoadSaveHelpers.SaveGameExists(name))
                {
                    WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "1007"), Translator.GetInstance().GetString("MessageBox", "1007", "message"), WPFMessageBoxButtons.YesNo);

                    doSave = result == WPFMessageBoxResult.Yes;
                }
                if (doSave)
                {
                    popUpSplash.IsOpen = true;
                    DoEvents();

                    GameObject.GetInstance().Name = name;

                    /*
                     * string fileName;
                     *
                     * var saves = LoadSaveHelpers.GetSavedGames();
                     *
                     *
                     * KeyValuePair<string,string>? f = LoadSaveHelpers.GetSavedGames().Find(fs=>fs.Key == name);
                     *
                     * if (!f.HasValue || f.Value.Key == null)
                     * {
                     *  Guid file = Guid.NewGuid();
                     *
                     *  fileName = file.ToString();
                     *
                     *  LoadSaveHelpers.AppendSavedFile(name, fileName);
                     *
                     * }
                     * else
                     * {
                     *  fileName = f.Value.Value;
                     * }
                     */
                    //LoadSaveHelpers.SaveGame(fileName);
                    SerializedLoadSaveHelpers.SaveGame(name);

                    popUpSplash.IsOpen = false;
                }
            }


            if (!gameworkerPaused)
            {
                GameObjectWorker.GetInstance().start();
            }
        }