Esempio n. 1
0
        public override void Update(GameTime gameTime)
        {
            if (isActive)
            {
                foreach (Button b in buttons)
                {
                    b.Update();

                    if (b.IsPressed)
                    {
                        if (b.Command == MenuCommand.OpenDijkstra || b.Command == MenuCommand.OpenAStar || b.Command == MenuCommand.OpenScentAlgorithm)
                        {
                            LoadMap();
                            if (b.Command == MenuCommand.OpenDijkstra)
                            {
                                LevelHandler.SetPathfindingAlgorithm(PathfinderAlgorithm.Dijkstra);
                            }
                            else if (b.Command == MenuCommand.OpenAStar)
                            {
                                LevelHandler.SetPathfindingAlgorithm(PathfinderAlgorithm.AStar);
                            }
                            else if (b.Command == MenuCommand.OpenScentAlgorithm)
                            {
                                LevelHandler.SetPathfindingAlgorithm(PathfinderAlgorithm.ScentMap);
                            }
                            else
                            {
                                Console.WriteLine("Menu.cs: Error, attempted to set unrecognized pathfinding algorithm. Defaulting to Dijkstra.");
                                LevelHandler.SetPathfindingAlgorithm(PathfinderAlgorithm.Dijkstra);
                            }
                            Main.SetState(typeof(LevelHandler));
                        }
                        else if (b.Command == MenuCommand.OpenMapFile)
                        {
                            OpenMap();
                        }
                        else if (b.Command == MenuCommand.OpenTestConfig)
                        {
                            if (LoadMap())
                            {
                                RunTestConfig();
                            }
                        }
                        else
                        {
                            Console.WriteLine("Unrecognized menu button command called.\n");
                        }
                    }
                }
            }
            else
            {
                testConfigBox.Activate(); // If not active, keep focus on the configuration box
            }
            base.Update(gameTime);
        }
        /// <summary>
        /// Update function for this component.
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            if (isActive)
            {
                foreach (Button b in buttons)
                {
                    b.Update();

                    if (b.IsPressed)
                    {
                        if (b.Command == MenuCommand.OpenDijkstra || b.Command == MenuCommand.OpenAStar || b.Command == MenuCommand.OpenScentMap)
                        {
                            if (LoadMap())
                            {
                                if (b.Command == MenuCommand.OpenDijkstra)
                                {
                                    LevelHandler.SetPathfindingAlgorithm(PathfinderAlgorithm.Dijkstra);
                                }
                                else if (b.Command == MenuCommand.OpenAStar)
                                {
                                    LevelHandler.SetPathfindingAlgorithm(PathfinderAlgorithm.AStar);
                                }
                                else if (b.Command == MenuCommand.OpenScentMap)
                                {
                                    LevelHandler.SetPathfindingAlgorithm(PathfinderAlgorithm.ScentMap);
                                }
                                else
                                {
                                    Console.WriteLine("Menu.cs: Error, attempted to set unrecognized pathfinding algorithm. Defaulting to Dijkstra.");
                                    LevelHandler.SetPathfindingAlgorithm(PathfinderAlgorithm.Dijkstra);
                                }
                                Main.SetState(typeof(LevelHandler));
                            }
                        }
                        else if (b.Command == MenuCommand.OpenMapFile)
                        {
                            OpenMap();
                        }
                        else if (b.Command == MenuCommand.OpenTestConfig)
                        {
                            if (LoadMap())
                            {
                                RunTestConfig();
                            }
                        }
                        else if (b.Command == MenuCommand.OpenGenerateMap)
                        {
                            RunGenerateMap();
                        }
                        else
                        {
                            Console.WriteLine("Unrecognized menu button command called.\n");
                        }
                    }
                }
            }
            else
            {
                if (InputHandler.IsMouseButtonPressed(MouseButton.LeftButton) && game.IsActive)
                {
                    if (mapGenActive)
                    {
                        if (Form.ActiveForm != mapGen)
                        {
                            mapGen.Activate();
                            SystemSounds.Exclamation.Play();
                        }
                    }
                    if (configTestActive && !testActive)
                    {
                        if (Form.ActiveForm != testConfigBox)
                        {
                            testConfigBox.Activate();
                            SystemSounds.Exclamation.Play();
                        }
                    }
                }
            }

            base.Update(gameTime);
        }