Example #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (!this.IsActive)
            {
                lostFocus = true;
                return;
            }

            TVUserInput.Update();
            if (lostFocus)
            {
                // if the previous call was in inactive mode, we do want TVUserInput to be updated, but we will only
                // act on it the next round. To make sure moving the mouse to other locations and back is influencing
                // the location visible in trackviewer.
                lostFocus = false;
                return;
            }

            fontManager.Update(GraphicsDevice);
            if (DrawTrackDB != null)
            {   // when update is called, we are not searching via menu
                DrawTrackDB.ClearHighlightOverrides();
            }

            // First check all the buttons that can be kept down.

            if (this.drawPathChart.IsActived)
            {
                if (TVUserInput.IsDown(TVUserCommands.ShiftLeft))
                {
                    drawPathChart.Shift(-1); skipDrawAmount = 0;
                }
                if (TVUserInput.IsDown(TVUserCommands.ShiftRight))
                {
                    drawPathChart.Shift(1); skipDrawAmount = 0;
                }
                if (TVUserInput.IsDown(TVUserCommands.ZoomIn))
                {
                    drawPathChart.Zoom(-1); skipDrawAmount = 0;
                }
                if (TVUserInput.IsDown(TVUserCommands.ZoomOut))
                {
                    drawPathChart.Zoom(1); skipDrawAmount = 0;
                }
            }
            else
            {
                if (TVUserInput.IsDown(TVUserCommands.ShiftLeft))
                {
                    DrawArea.ShiftLeft(); skipDrawAmount = 0;
                }
                if (TVUserInput.IsDown(TVUserCommands.ShiftRight))
                {
                    DrawArea.ShiftRight(); skipDrawAmount = 0;
                }
                if (TVUserInput.IsDown(TVUserCommands.ShiftUp))
                {
                    DrawArea.ShiftUp(); skipDrawAmount = 0;
                }
                if (TVUserInput.IsDown(TVUserCommands.ShiftDown))
                {
                    DrawArea.ShiftDown(); skipDrawAmount = 0;
                }

                if (TVUserInput.IsDown(TVUserCommands.ZoomIn))
                {
                    DrawArea.Zoom(-1); skipDrawAmount = 0;
                }
                if (TVUserInput.IsDown(TVUserCommands.ZoomOut))
                {
                    DrawArea.Zoom(1); skipDrawAmount = 0;
                }
            }

            if (TVUserInput.Changed)
            {
                skipDrawAmount = 0;
            }

            if (TVUserInput.IsPressed(TVUserCommands.Quit))
            {
                this.Quit();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ReloadRoute))
            {
                this.ReloadRoute();
            }

            if (TVUserInput.IsPressed(TVUserCommands.ShiftToMouseLocation))
            {
                DrawArea.ShiftToLocation(DrawArea.MouseLocation);
            }
            if (TVUserInput.IsPressed(TVUserCommands.ZoomInSlow))
            {
                DrawArea.Zoom(-1);
            }
            if (TVUserInput.IsPressed(TVUserCommands.ZoomOutSlow))
            {
                DrawArea.Zoom(1);
            }
            if (TVUserInput.IsPressed(TVUserCommands.ZoomToTile))
            {
                DrawArea.ZoomToTile();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ZoomReset))
            {
                DrawArea.ZoomReset(DrawTrackDB);
                drawAreaInset.ZoomReset(DrawTrackDB);  // needed in case window was resized
            }

            if (DrawPATfile != null && Properties.Settings.Default.showPATfile)
            {
                if (TVUserInput.IsPressed(TVUserCommands.ExtendPath))
                {
                    DrawPATfile.ExtendPath();
                }
                if (TVUserInput.IsPressed(TVUserCommands.ExtendPathFull))
                {
                    DrawPATfile.ExtendPathFull();
                }
                if (TVUserInput.IsPressed(TVUserCommands.ReducePath))
                {
                    DrawPATfile.ReducePath();
                }
                if (TVUserInput.IsPressed(TVUserCommands.ReducePathFull))
                {
                    DrawPATfile.ReducePathFull();
                }
                if (TVUserInput.IsDown(TVUserCommands.ShiftToPathLocation))
                {
                    DrawArea.ShiftToLocation(DrawPATfile.CurrentLocation);
                }
            }

            if (PathEditor != null && Properties.Settings.Default.showTrainpath)
            {
                if (TVUserInput.IsPressed(TVUserCommands.ExtendPath))
                {
                    PathEditor.ExtendPath();
                }
                if (TVUserInput.IsPressed(TVUserCommands.ExtendPathFull))
                {
                    PathEditor.ExtendPathFull();
                }
                if (TVUserInput.IsPressed(TVUserCommands.ReducePath))
                {
                    PathEditor.ReducePath();
                }
                if (TVUserInput.IsPressed(TVUserCommands.ReducePathFull))
                {
                    PathEditor.ReducePathFull();
                }
                if (TVUserInput.IsDown(TVUserCommands.ShiftToPathLocation))
                {
                    DrawArea.ShiftToLocation(PathEditor.CurrentLocation);
                }

                if (TVUserInput.IsPressed(TVUserCommands.EditorUndo))
                {
                    PathEditor.Undo();
                }
                if (TVUserInput.IsPressed(TVUserCommands.EditorRedo))
                {
                    PathEditor.Redo();
                }
                if (TVUserInput.IsMouseXButton1Pressed())
                {
                    PathEditor.Undo();
                }
                if (TVUserInput.IsMouseXButton2Pressed())
                {
                    PathEditor.Redo();
                }
            }

            if (PathEditor != null && PathEditor.EditingIsActive)
            {
                if (TVUserInput.IsMouseRightButtonPressed())
                {
                    PathEditor.OnLeftMouseRelease(); // any action done with left mouse is cancelled now
                    PathEditor.PopupContextMenu(TVUserInput.MouseLocationX, TVUserInput.MouseLocationY);
                }

                if (TVUserInput.IsDown(TVUserCommands.EditorTakesMouseClick))
                {
                    if (TVUserInput.IsMouseLeftButtonPressed())
                    {
                        PathEditor.OnLeftMouseClick(TVUserInput.MouseLocationX, TVUserInput.MouseLocationY);
                    }
                    if (TVUserInput.IsMouseLeftButtonDown())
                    {
                        PathEditor.OnLeftMouseMoved(); // to make sure it is reactive enough, don't even care if mouse is really moved
                    }
                    if (TVUserInput.IsMouseLeftButtonReleased())
                    {
                        PathEditor.OnLeftMouseRelease();
                    }
                }

                if (TVUserInput.IsReleased(TVUserCommands.EditorTakesMouseClick))
                {
                    PathEditor.OnLeftMouseCancel();
                }
                drawPathChart.DrawDynamics();
            }

            if (!TVUserInput.IsDown(TVUserCommands.EditorTakesMouseClick) && !this.MenuHasMouse && !this.drawPathChart.IsActived)
            {
                if (TVUserInput.IsMouseMoved() && TVUserInput.IsMouseLeftButtonDown())
                {
                    DrawArea.ShiftArea(TVUserInput.MouseMoveX(), TVUserInput.MouseMoveY());
                }
            }

            if (TVUserInput.IsMouseWheelChanged())
            {
                int mouseWheelChange = TVUserInput.MouseWheelChange();
                if (!this.drawPathChart.IsActived)
                {
                    if (TVUserInput.IsDown(TVUserCommands.MouseZoomSlow))
                    {
                        DrawArea.Zoom(mouseWheelChange > 0 ? -1 : 1);
                    }
                    else
                    {
                        DrawArea.Zoom(-mouseWheelChange / 40);
                    }
                }
            }


            DrawArea.Update();
            drawAreaInset.Update();
            drawAreaInset.Follow(DrawArea, 10f);

            if (TVUserInput.IsPressed(TVUserCommands.ToggleZoomAroundMouse))
            {
                menuControl.MenuToggleZoomingAroundMouse();
            }

            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowTerrain))
            {
                menuControl.MenuToggleShowTerrain();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowDMTerrain))
            {
                menuControl.MenuToggleShowDMTerrain();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowPatchLines))
            {
                menuControl.MenuToggleShowPatchLines();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowSignals))
            {
                menuControl.MenuToggleShowSignals();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowSidings))
            {
                menuControl.MenuToggleShowSidings();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowSidingNames))
            {
                menuControl.MenuToggleShowSidingNames();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowPlatforms))
            {
                menuControl.MenuToggleShowPlatforms();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowPlatformNames))
            {
                menuControl.MenuCirculatePlatformStationNames();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowSpeedLimits))
            {
                menuControl.MenuToggleShowSpeedLimits();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowMilePosts))
            {
                menuControl.MenuToggleShowMilePosts();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowTrainpath))
            {
                menuControl.MenuToggleShowTrainpath();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleShowPatFile))
            {
                menuControl.MenuToggleShowPatFile();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleHighlightTracks))
            {
                menuControl.MenuToggleHighlightTracks();
            }
            if (TVUserInput.IsPressed(TVUserCommands.ToggleHighlightItems))
            {
                menuControl.MenuToggleHighlightItems();
            }


            if (TVUserInput.IsPressed(TVUserCommands.Debug))
            {
                runDebug();
            }

            base.Update(gameTime);
        }