示例#1
0
        /// <summary>
        /// Once a path has been selected, do the necessary loading.
        /// </summary>
        /// <param name="path">Path (with FilePath) that has to be loaded</param>
        internal void SetPath(Path path)
        {
            if (!CanDiscardModifiedPath())
            {
                return;
            }

            if (path == null)
            {
                DrawPATfile = null;
                PathEditor  = null;
                drawPathChart.Close();
            }
            else
            {
                DrawLoadingMessage(catalog.GetString("Loading .pat file ..."));
                DrawPATfile = new DrawPATfile(path);

                DrawLoadingMessage(catalog.GetString("Processing .pat file ..."));
                PathEditor = new PathEditor(this.RouteData, this.DrawTrackDB, path);
                drawPathChart.SetPathEditor(this.RouteData, this.PathEditor);

                DrawLoadingMessage(" ...");
            }
        }
示例#2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            // Even if there is nothing new to draw for main window, we might still need to draw for the shadow textures.
            if (DrawTrackDB != null && Properties.Settings.Default.showInset)
            {
                drawAreaInset.DrawShadowTextures(DrawTrackDB.DrawTracks, DrawColors.colorsNormal.ClearWindowInset);
            }

            // if there is nothing to draw, be done.
            if (--skipDrawAmount > 0)
            {
                return;
            }

            GraphicsDevice.Clear(DrawColors.colorsNormal.ClearWindow);
            if (DrawTrackDB == null)
            {
                return;
            }

            spriteBatch.Begin();
            if (drawTerrain != null)
            {
                drawTerrain.Draw(DrawArea);
            }
            drawWorldTiles.Draw(DrawArea);
            DrawArea.DrawTileGrid();
            if (drawTerrain != null)
            {
                drawTerrain.DrawPatchLines(DrawArea);
            }

            DrawTrackDB.DrawRoads(DrawArea);
            DrawTrackDB.DrawTracks(DrawArea);
            DrawTrackDB.DrawTrackHighlights(DrawArea, true);

            DrawTrackDB.DrawJunctionAndEndNodes(DrawArea);

            if (Properties.Settings.Default.showInset)
            {
                drawAreaInset.DrawBackground(DrawColors.colorsNormal.ClearWindowInset);
                //drawTrackDB.DrawTracks(drawAreaInset); //replaced by next line
                drawAreaInset.DrawShadowedTextures();
                DrawTrackDB.DrawTrackHighlights(drawAreaInset, false);
                drawAreaInset.DrawBorder(Color.Red, DrawArea);
                drawAreaInset.DrawBorder(Color.Black);
            }

            if (DrawMultiplePaths != null)
            {
                DrawMultiplePaths.Draw(DrawArea);
            }
            if (DrawPATfile != null && Properties.Settings.Default.showPATfile)
            {
                DrawPATfile.Draw(DrawArea);
            }
            if (PathEditor != null && Properties.Settings.Default.showTrainpath)
            {
                PathEditor.Draw(DrawArea);
            }

            DrawTrackDB.DrawRoadTrackItems(DrawArea);
            DrawTrackDB.DrawTrackItems(DrawArea);
            DrawTrackDB.DrawItemHighlights(DrawArea);

            CalculateFPS(gameTime);

            statusBarControl.Update(this, DrawArea.MouseLocation);

            drawScaleRuler.Draw();
            drawLongitudeLatitude.Draw(DrawArea.MouseLocation);

            DebugWindow.DrawAll();

            spriteBatch.End();

            base.Draw(gameTime);
            skipDrawAmount = maxSkipDrawAmount;
        }
示例#3
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);
        }