/// <summary>
        /// Stores all the navigations stacks with the given name into local storage.
        /// </summary>
        /// <param name="navigation">The navigation service.</param>
        /// <param name="name">The name that will represents this navigation.</param>
        /// <param name="name">The base identifier of the stack.</param>
        public static void Store(this INavigation navigation, string name)
        {
            var states = new NavigationStates()
            {
                Date       = DateTime.Now,
                Navigation = ConvertPages(navigation.NavigationStack),
                Modal      = ConvertPages(navigation.ModalStack),
            };

            Application.Current.Properties[$"{StoreKeyPrefix}{name}"] = states;
        }
        /// <summary>
        /// Stores all the navigations stacks with the given name into local storage.
        /// </summary>
        /// <param name="navigation">The navigation service.</param>
        public static void Store(this INavigation navigation)
        {
            var states = new NavigationStates()
            {
                Date       = DateTime.Now,
                Navigation = ConvertPages(navigation.NavigationStack),
                Modal      = ConvertPages(navigation.ModalStack),
            };

            try
            {
                SaveNavigationHistory(states);
            }
            catch { }
        }
Example #3
0
        public static object NavigateToPage(App.Apps app, NavigationStates navState = NavigationStates.Normal)
        {
            Windows.Graphics.Display.DisplayInformation.AutoRotationPreferences =
                Windows.Graphics.Display.DisplayOrientations.Landscape |
                Windows.Graphics.Display.DisplayOrientations.LandscapeFlipped |
                Windows.Graphics.Display.DisplayOrientations.Portrait |
                Windows.Graphics.Display.DisplayOrientations.PortraitFlipped;

            App    curApp     = Application.Current as App;
            string searchArgs = curApp.SearchArguments;

            curApp.lastNavState = navState;

            //check the navigation type for share/search/normal
            Frame rootFrame;
            bool  newFrame = false;

            try
            {
                rootFrame = (curApp.CurrentPage as Page).Frame;
                if (rootFrame == null)
                {
                    throw new Exception(); //passes it to the catch block which initializes the frame
                }
            }
            catch
            {
                rootFrame = new Frame();
                newFrame  = true;
            }

            Calculator.Calc_MainPage calcPageMain;
            Utilities.Apps.UnitConverter.UnitConverter uc;
            switch (app)
            {
            case Apps.MainPage:
                rootFrame.Navigate(typeof(MainPage));
                MainPage mainPage = rootFrame.Content as MainPage;
                mainPage.SetNavigationState(navState);
                break;

            case App.Apps.Calculator:
                if (navState == NavigationStates.Search)
                {
                    rootFrame.Navigate(typeof(Calculator.Calc_MainPage));
                    calcPageMain = rootFrame.Content as Calculator.Calc_MainPage;

                    calcPageMain.Initialize(Apps.Scientific);

                    //Do any work to set up Search on Calculator here
                    calcPageMain.insertToWindow(searchArgs);

                    PrevCalcSearch = true;
                }
                else if (PrevCalcSearch == true)
                {
                    PrevCalcSearch = false;
                }
                else
                {
                    rootFrame.Navigate(typeof(Calculator.Calc_LandingPage));
                    Calculator.Calc_LandingPage calcPageLand = rootFrame.Content as Calculator.Calc_LandingPage;
                }

                break;

            case App.Apps.Scientific:
                rootFrame.Navigate(typeof(Calculator.Calc_MainPage));
                calcPageMain = rootFrame.Content as Calculator.Calc_MainPage;

                calcPageMain.Initialize(Apps.Scientific);
                break;

            case App.Apps.Programmer:
                rootFrame.Navigate(typeof(Calculator.Calc_MainPage));
                calcPageMain = rootFrame.Content as Calculator.Calc_MainPage;

                calcPageMain.Initialize(Apps.Programmer);
                break;

            case App.Apps.Statistics:
                rootFrame.Navigate(typeof(Calculator.Calc_MainPage));
                calcPageMain = rootFrame.Content as Calculator.Calc_MainPage;

                calcPageMain.Initialize(Apps.Statistics);
                break;

            case App.Apps.Notepad:
                rootFrame.Navigate(typeof(Notepad.Notepad_MainPage));
                Notepad.Notepad_MainPage notepadPage = rootFrame.Content as Notepad.Notepad_MainPage;

                if (navState != NavigationStates.Share)
                {
                    notepadPage.recentFilesTimer.Start();
                }
                else
                {
                    notepadPage.displaySharingText(curApp.ShareArguments);
                }
                break;

            //case App.Apps.ToDo:
            //    rootFrame.Navigate(typeof(Utilities.Apps.ToDo.ToDo_MainPage));
            //    break;

            case App.Apps.PCalendar:
                rootFrame.Navigate(typeof(PCalender.PCal_MainPage));
                //PCalender.PCal_MainPage pCalPage = rootFrame.Content as PCalender.PCal_MainPage;

                break;

            case App.Apps.UnitConverter:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter_LandingPage));
                break;

            //case App.Apps.Stopwatch:
            //    rootFrame.Navigate(typeof(Utilities.Apps.Stopwatch.Stopwatch_MainPage));
            //    break;

            //case App.Apps.Timer:
            //    rootFrame.Navigate(typeof(Utilities.Apps.Timer.Timer_MainPage));
            //    break;

            case App.Apps.Area:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter));
                uc = rootFrame.Content as Utilities.Apps.UnitConverter.UnitConverter;
                uc.Init(Utilities.Apps.UnitConverter.UnitConverter.ConversionTypes.area, "Area", Apps.Area);
                break;

            case Apps.Distance:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter));
                uc = rootFrame.Content as Utilities.Apps.UnitConverter.UnitConverter;
                uc.Init(Utilities.Apps.UnitConverter.UnitConverter.ConversionTypes.distance, "Distance", Apps.Distance);
                break;

            case Apps.Mass:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter));
                uc = rootFrame.Content as Utilities.Apps.UnitConverter.UnitConverter;
                uc.Init(Utilities.Apps.UnitConverter.UnitConverter.ConversionTypes.mass, "Mass", Apps.Mass);
                break;

            case Apps.Speed:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter));
                uc = rootFrame.Content as Utilities.Apps.UnitConverter.UnitConverter;
                uc.Init(Utilities.Apps.UnitConverter.UnitConverter.ConversionTypes.speed, "Speed", Apps.Speed);
                break;

            case Apps.Volume:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter));
                uc = rootFrame.Content as Utilities.Apps.UnitConverter.UnitConverter;
                uc.Init(Utilities.Apps.UnitConverter.UnitConverter.ConversionTypes.volume, "Volume", Apps.Volume);
                break;

            case Apps.Acceleration:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter));
                uc = rootFrame.Content as Utilities.Apps.UnitConverter.UnitConverter;
                uc.Init(Utilities.Apps.UnitConverter.UnitConverter.ConversionTypes.acceleration, "Acceleration", Apps.Acceleration);
                break;

            case Apps.Angles:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter));
                uc = rootFrame.Content as Utilities.Apps.UnitConverter.UnitConverter;
                uc.Init(Utilities.Apps.UnitConverter.UnitConverter.ConversionTypes.angles, "Angles", Apps.Angles);
                break;

            case Apps.Current:
                rootFrame.Navigate(typeof(Utilities.Apps.UnitConverter.UnitConverter));
                uc = rootFrame.Content as Utilities.Apps.UnitConverter.UnitConverter;
                uc.Init(Utilities.Apps.UnitConverter.UnitConverter.ConversionTypes.current, "Current", Apps.Current);
                break;

            //case Apps.About:
            //    rootFrame.Navigate(typeof(Utilities.Apps._About.AboutPage));
            //    break;

            default:
                break;
            }

            if (newFrame)
            {
                Window.Current.Content = rootFrame;
                Window.Current.Activate();
            }

            // remember the current app
            ((App)Application.Current).CurrentApp = app;

            // static variable that holds the current page
            ((App)Application.Current).CurrentPage = rootFrame.Content;
            return(((App)Application.Current).CurrentPage);
        }
        private static void SaveNavigationHistory(NavigationStates states)
        {
            var history = JsonConvert.SerializeObject(states);

            CrossSettings.Current.AddOrUpdateValue <string>(NavigationHistory, history);
        }
        void UpdateNavigation(float timeSinceLastUpdate)
        {
            if (steering == null || EnemySubmarine == null)
            {
                return;
            }

            float distanceSquaredEnemy = Vector2.DistanceSquared(CommandedSubmarine.WorldPosition, EnemySubmarine.WorldPosition);

            if (NavigationState != NavigationStates.Aggressive)
            {
                if (WithinRange(7000f, distanceSquaredEnemy))
                {
#if DEBUG
                    ShipCommandLog("Ship " + CommandedSubmarine + " was within the aggro range of " + EnemySubmarine);
#endif
                    NavigationState = NavigationStates.Aggressive;
                }
                else if (WithinRange(40000f, distanceSquaredEnemy))
                {
                    NavigationState = NavigationStates.Patrol;
                }
            }

            if (NavigationState == NavigationStates.Aggressive)
            {
                steering.AITacticalTarget = EnemySubmarine.WorldPosition;
                if (WithinRange(8500f, distanceSquaredEnemy) && !WithinRange(1500f, distanceSquaredEnemy)) // if we are within enemy ship's range for ramTimerMax, try to ram them instead (if we're not already very close)
                {
                    if (steering.AIRamTimer > 0f)
                    {
#if DEBUG
                        ShipCommandLog("Ship " + CommandedSubmarine + " was still ramming, " + steering.AIRamTimer + " left");
#endif
                    }
                    else
                    {
                        timeUntilRam -= timeSinceLastUpdate;
#if DEBUG
                        ShipCommandLog("Ship " + CommandedSubmarine + " was close enough to ram, " + timeUntilRam + " left until ramming");
#endif

                        if (timeUntilRam <= 0f)
                        {
#if DEBUG
                            ShipCommandLog("Ship " + CommandedSubmarine + " is attempting to ram!");
#endif
                            steering.AIRamTimer = 50f;
                            timeUntilRam        = RamTimerMax * Rand.Range(0.9f, 1.1f);
                        }
                    }
                }
                else
                {
                    steering.AIRamTimer = 0f;
                    timeUntilRam        = RamTimerMax * Rand.Range(0.9f, 1.1f);
                }
            }
            else if (patrolPositions.Any())
            {
                float distanceSquaredPatrol = Vector2.DistanceSquared(CommandedSubmarine.WorldPosition, patrolPositions.First());

                if (WithinRange(7000f, distanceSquaredPatrol))
                {
                    Vector2 lastPosition = patrolPositions.First();
                    patrolPositions.RemoveAt(0);
                    patrolPositions.Add(lastPosition);
                }
                steering.AITacticalTarget = patrolPositions.First();
            }
        }
Example #6
0
        private void ChangeNavigationState(NavigationStates newState)
        {
            if (stateHistory.Contains(newState))
            {
                if (this.CurrentNavigationState != newState)
                {
                    // Navigate back to this state
                    var destIndex = stateHistory.IndexOf(newState) + 1;
                    for (int i = stateHistory.Count - 1; i >= destIndex; i--)
                    {
                        var isDestState = i == destIndex;
                        this.NavigateBack(doTransition: isDestState);
                        stateHistory.RemoveAt(i);
                    }
                }
            }
            else
            {
                switch (newState)
                {
                case NavigationStates.Exit:
                    WaveServices.Platform.Exit();
                    break;

                case NavigationStates.MainMenu:
                    this.PreloadAndNavigateFoward(new MainMenu());
                    break;

                case NavigationStates.ExitConfirmation:
                    this.PreloadAndNavigateFoward(new ExitConfirmation(), isModal: true);
                    break;

                case NavigationStates.Finish:
                    this.PreloadAndNavigateFoward(new Finish(), isModal: true);
                    break;

                case NavigationStates.LevelSelection:
                    this.PreloadAndNavigateFoward(new LevelSelection());
                    break;

                case NavigationStates.Loading:
                    this.PreloadAndNavigateFoward(new Loading());
                    break;

                case NavigationStates.Gameplay:
                    this.PreloadAndNavigateFoward(new Gameplay());
                    break;

                case NavigationStates.Pause:
                    this.PreloadAndNavigateFoward(new Pause(), isModal: true);
                    break;

                default:
                    throw new InvalidOperationException("Not spected state");
                }

                this.stateHistory.Add(newState);
            }

            Labels.Add("CurrentNavigationState", this.CurrentNavigationState);
        }