Example #1
0
 public virtual void OnBackKeyPress(System.Windows.Navigation.NavigationCacheMode navigationCacheMode, System.Windows.Navigation.NavigationContext navigationContext, System.Windows.Navigation.NavigationService navigationService, System.ComponentModel.CancelEventArgs e)
 {
 }
Example #2
0
 public virtual void OnNavigatingFrom(System.Windows.Navigation.NavigationCacheMode navigationCacheMode, System.Windows.Navigation.NavigationContext navigationContext, System.Windows.Navigation.NavigationService navigationService, System.Windows.Navigation.NavigatingCancelEventArgs e)
 {
 }
        protected override void InitFromNavigation(NavigationInfo nav)
        {
            System.Windows.Navigation.NavigationContext navCtx = nav.NavigationContext;
            bool shouldCancel = false;

            // Shows a progress bar.
            IsProgressBarVisible  = true;
            ProgressBarStatusText = null;

            // Parses the cartridge guid parameter and tries to get its tag.
            string filenameParam;
            string cidParam;
            string fileTokenParam;

            if (navCtx.QueryString.TryGetValue(CartridgeFilenameKey, out filenameParam) &&
                navCtx.QueryString.TryGetValue(CartridgeIdKey, out cidParam))
            {
                // Opens a cartridge from filename.
                CartridgeTag = Model.CartridgeStore.GetCartridgeTag(filenameParam, cidParam);
            }
            else if (navCtx.QueryString.TryGetValue(FileTokenKey, out fileTokenParam))
            {
                // Opens a cartridge from file association token.

                CartridgeTag = Model.CartridgeStore.GetCartridgeTagFromFileAssociation(fileTokenParam);
            }

            // Quits if the tag is null.
            if (CartridgeTag == null)
            {
                shouldCancel = true;
                MessageBox.Show("Sorry, Geowigo cannot open this cartridge.", "Error", MessageBoxButton.OK);
            }

            // Leave now if we need to cancel.
            if (shouldCancel)
            {
                App.Current.ViewModel.NavigationManager.NavigateBack();
                return;
            }

            // The progress bar is not needed anymore.
            IsProgressBarVisible = false;

            // Inits the data context.
            Cartridge     = CartridgeTag.Cartridge;
            WherigoObject = CartridgeTag.Cartridge;

            // Refreshes content.
            RefreshAppBar();
            RefreshStaticContent();
            RefreshLocatedContent();
            RefreshSavegames();

            // Adds a listener for cartridge tag changes.
            CartridgeTag.PropertyChanged -= OnCartridgeTagPropertyChanged;
            CartridgeTag.PropertyChanged += OnCartridgeTagPropertyChanged;

            // Resumes if needed.
            if (nav.ContinuationOperation == ExportSavegameOperationValue)
            {
                ExportSaveGameContinue(nav.ContinuationEventArgs);
            }
        }
Example #4
0
 public virtual void OnNavigatedTo(System.Windows.Navigation.NavigationCacheMode navigationCacheMode, System.Windows.Navigation.NavigationContext navigationContext, System.Windows.Navigation.NavigationService navigationService, System.Windows.Navigation.NavigationEventArgs e)
 {
 }
Example #5
0
        protected override void InitFromNavigation(NavigationInfo nav)
        {
            base.InitFromNavigation(nav);

            // We probably have a lot of things to do.
            // Let's block the UI and show some progress bar.
            RefreshProgressBar(Model.Core.GameState);

            System.Windows.Navigation.NavigationContext navCtx = nav.NavigationContext;

            // Tries to get a particular section to display.
            string section;

            if (navCtx.QueryString.TryGetValue(SectionKey, out section))
            {
                ShowSection(section);
            }

            // Refreshes the application bar.
            RefreshAppBar();

            // Nothing more to do if a cartridge exists already.
            if (Cartridge != null)
            {
                return;
            }

            // Makes sure the screen lock is disabled.
            App.Current.ViewModel.IsScreenLockEnabled = false;

            // Resets the custom status text.
            App.Current.ViewModel.SystemTrayManager.StatusText = null;

            // Tries to get the filename to query for.
            string filename;

            if (navCtx.QueryString.TryGetValue(CartridgeFilenameKey, out filename))
            {
                // Gets the cartridge tag for this cartridge.
                CartridgeTag = Model.CartridgeStore.GetCartridgeTag(filename);

                string gwsFilename;

                // Restores the cartridge or starts a new game?
                if (navCtx.QueryString.TryGetValue(SavegameFilenameKey, out gwsFilename))
                {
                    // Starts restoring the game.
                    RunOrDeferIfNotReady(
                        new Action(() =>
                    {
                        // Starts logging.
                        if (Model.Settings.CanGenerateCartridgeLog)
                        {
                            Model.Core.StartLogging(CartridgeTag.CreateLogFile());
                        }

                        // Restores the game.
                        Model.Core.InitAndRestoreCartridgeAsync(filename, gwsFilename)
                        .ContinueWith(t =>
                        {
                            // Keeps the cartridge.
                            try
                            {
                                Cartridge = t.Result;
                            }
                            catch (AggregateException ex)
                            {
                                FailInit(ex, CartridgeTag, true);
                            }

                            // Registers a history entry.
                            CartridgeSavegame savegame = CartridgeTag.Savegames.FirstOrDefault(cs => cs.SavegameFile == gwsFilename);
                            Model.History.AddRestoredGame(CartridgeTag, savegame);

                            // Lets the view model know we started the game.
                            App.Current.ViewModel.HandleGameStarted(CartridgeTag, savegame);
                        }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
                    }));
                }
                else
                {
                    // Starts a new game.
                    RunOrDeferIfNotReady(
                        new Action(() =>
                    {
                        // Starts logging.
                        if (Model.Settings.CanGenerateCartridgeLog)
                        {
                            Model.Core.StartLogging(CartridgeTag.CreateLogFile());
                        }

                        // Starts the game.
                        Model.Core.InitAndStartCartridgeAsync(filename)
                        .ContinueWith(t =>
                        {
                            // Stores the result of the cartridge.
                            try
                            {
                                Cartridge = t.Result;
                            }
                            catch (AggregateException ex)
                            {
                                FailInit(ex, CartridgeTag);
                            }

                            // Registers a history entry.
                            Model.History.AddStartedGame(CartridgeTag);

                            // Lets the view model know we started the game.
                            App.Current.ViewModel.HandleGameStarted(CartridgeTag);
                        }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
                    }));
                }
            }

            // TODO: Cancel nav if no cartridge in parameter?
        }