示例#1
0
        private static View CreateConfigurationControls(ITrackParameters trackParameters, IEnumerable <ILayerRenderer> layers)
        {
            var layersGroup = new VStack();

            foreach (ILayerRenderer layer in layers)
            {
                layersGroup.Add(new ToggleButton(layer.Name, layer.Enabled, () => layer.Enabled = !layer.Enabled));
            }
#pragma warning disable CA2000 // Dispose objects before losing scope
            layersGroup.Add(new VStack()
            {
                GetConfigurationControl(trackParameters, nameof(trackParameters.CellSize)),
                GetConfigurationControl(trackParameters, nameof(trackParameters.NumPlanks)),
                GetConfigurationControl(trackParameters, nameof(trackParameters.NumCornerPlanks)),
                GetConfigurationControl(trackParameters, nameof(trackParameters.PlankWidth)),
                GetConfigurationControl(trackParameters, nameof(trackParameters.PlankPadding)),
                GetConfigurationControl(trackParameters, nameof(trackParameters.TrackPadding)),
                GetConfigurationControl(trackParameters, nameof(trackParameters.TrackWidth)),
                GetConfigurationControl(trackParameters, nameof(trackParameters.CornerStepDegrees)),
                GetConfigurationControl(trackParameters, nameof(trackParameters.CornerEdgeOffsetDegrees))
            }.Margin(top: 50)
#pragma warning restore CA2000 // Dispose objects before losing scope
                            );
            return(layersGroup);
        }
 public TrackLayoutRenderer(IGameBoard gameBoard, ITrackRenderer trackRenderer, IPixelMapper pixelMapper, ITrackParameters parameters)
 {
     _gameBoard     = gameBoard;
     _trackRenderer = trackRenderer;
     _pixelMapper   = pixelMapper;
     _parameters    = parameters;
 }
示例#3
0
        public TrackRenderer(ITrackParameters trackParameters, ITrackPathBuilder trackPathBuilder)
        {
            _trackParameters = trackParameters;

            _cornerTrackPath       = trackPathBuilder.BuildCornerTrackPath();
            _cornerPlankPath       = trackPathBuilder.BuildCornerPlankPath();
            _cornerSinglePlankPath = trackPathBuilder.BuildCornerPlankPath(1);
            _horizontalTrackPath   = trackPathBuilder.BuildHorizontalTrackPath();
            _horizontalPlankPath   = trackPathBuilder.BuildHorizontalPlankPath();

            _plankPaint = new PaintBrush
            {
                Color       = Colors.Black,
                Style       = PaintStyle.Stroke,
                StrokeWidth = _trackParameters.PlankWidth,
                IsAntialias = true
            };
            _trackClear = new PaintBrush
            {
                Color       = Colors.White,
                Style       = PaintStyle.Stroke,
                StrokeWidth = _trackParameters.RailTopWidth,
                IsAntialias = true
            };
            _trackEdge = new PaintBrush
            {
                Color       = Colors.Black,
                Style       = PaintStyle.Stroke,
                StrokeWidth = _trackParameters.RailWidth,
                IsAntialias = true
            };
        }
示例#4
0
        public MainPage(IGame game,
                        IPixelMapper pixelMapper,
                        OrderedList <ITool> tools,
                        OrderedList <ILayerRenderer> layers,
                        OrderedList <ICommand> commands,
                        ITrainController trainControls,
                        ITrackParameters trackParameters,
                        ITrackLayout trackLayout,
                        IGameStorage gameStorage)
        {
            this.Title("Trains - " + ThisAssembly.AssemblyInformationalVersion);

            var controlDelegate = new TrainsDelegate(game, pixelMapper);

            _miniMapDelegate = new MiniMapDelegate(trackLayout, trackParameters, pixelMapper);

            this.Body = () =>
            {
                return(new HStack()
                {
                    new VStack()
                    {
                        new ToggleButton("Configuration", _configurationShown, () => _configurationShown.Value = !_configurationShown.Value),
                        new Spacer(),
                        _configurationShown ?
                        CreateConfigurationControls(layers) :
                        CreateToolsControls(tools, controlDelegate),
                        new Spacer(),
                        _configurationShown ? null :
                        CreateCommandControls(commands),
                        new Spacer(),
                        new DrawableControl(_miniMapDelegate).Frame(height: 100)
                    }.Frame(100, alignment: Alignment.Top),
                    new VStack()
                    {
                        new TrainControllerPanel(trainControls),
                        new DrawableControl(controlDelegate)
                    }
                }.FillHorizontal());
            };

            _timer          = new GameTimer();
            _timer.Interval = 16;
            _timer.Elapsed += (s, e) =>
            {
                game.AdjustViewPortIfNecessary();

                ThreadHelper.Run(async() =>
                {
                    await ThreadHelper.SwitchToMainThreadAsync();

                    controlDelegate.Invalidate();
                    _miniMapDelegate.Invalidate();
                });
            };
            _timer.Start();
            _trackLayout = trackLayout;
            _gameStorage = gameStorage;
        }
示例#5
0
 public TrainLookaheadRenderer(IGameBoard gameBoard, IPixelMapper pixelMapper, ITrackParameters parameters, ITrainPainter painter, ITimer gameTimer)
 {
     _gameBoard   = gameBoard;
     _pixelMapper = pixelMapper;
     _parameters  = parameters;
     _painter     = painter;
     _gameTimer   = gameTimer;
 }
示例#6
0
        public static void SetupCanvasToDrawTrain(ICanvas canvas, IMovable train, ITrackParameters trackParameters)
        {
            float x = trackParameters.CellSize * train.RelativeLeft;
            float y = trackParameters.CellSize * train.RelativeTop;

            canvas.Translate(x, y);
            canvas.RotateDegrees(train.Angle);
        }
        public TrackLayoutRenderer(ITrackLayout trackLayout, ITrackRenderer trackRenderer, IPixelMapper pixelMapper, ITrackParameters parameters)
        {
            _trackLayout   = trackLayout;
            _trackRenderer = trackRenderer;
            _pixelMapper   = pixelMapper;
            _parameters    = parameters;

            _trackLayout.TracksChanged += (s, e) => _dirty = true;
        }
示例#8
0
        public MiniMapDelegate(IGameBoard gameBoard, ITrackParameters trackParameters, IPixelMapper pixelMapper)
        {
            _gameBoard       = gameBoard;
            _trackParameters = trackParameters;
            _pixelMapper     = pixelMapper;

            _pixelMapper.ViewPortChanged += (s, e) => _redraw = true;
            _gameBoard.TracksChanged     += (s, e) => _redraw = true;
        }
示例#9
0
        public MiniMapDelegate(ITrackLayout trackLayout, ITrackParameters trackParameters, IPixelMapper pixelMapper)
        {
            _trackLayout     = trackLayout;
            _trackParameters = trackParameters;
            _pixelMapper     = pixelMapper;

            _pixelMapper.ViewPortChanged += (s, e) => _redraw = true;
            _trackLayout.TracksChanged   += (s, e) => _redraw = true;
        }
示例#10
0
        public TrackPathBuilder(ITrackParameters trackParameters, IPathFactory pathFactory)
        {
            _trackParameters = trackParameters;
            _pathFactory     = pathFactory;

            _innerTrackOffset = 50.0f - _trackParameters.TrackWidth / 2.0f;
            _outerTrackOffset = 50.0f + _trackParameters.TrackWidth / 2.0f;
            _innerPlankOffset = 50.0f - _trackParameters.PlankLength / 2.0f;
            _outerPlankOffset = 50.0f + _trackParameters.PlankLength / 2.0f;
        }
示例#11
0
        public TrackPathBuilder(ITrackParameters parameters, IPathFactory pathFactory)
        {
            _parameters  = parameters;
            _pathFactory = pathFactory;

            _innerTrackOffset = _parameters.CellSize / 2.0f - _parameters.TrackWidth / 2.0f;
            _outerTrackOffset = _parameters.CellSize / 2.0f + _parameters.TrackWidth / 2.0f;
            _innerPlankOffset = _parameters.CellSize / 2.0f - _parameters.PlankLength / 2.0f;
            _outerPlankOffset = _parameters.CellSize / 2.0f + _parameters.PlankLength / 2.0f;
        }
示例#12
0
        public TrackPathBuilder(IGameParameters gameParameters, ITrackParameters trackParameters, IPathFactory pathFactory)
        {
            _gameParameters  = gameParameters;
            _trackParameters = trackParameters;
            _pathFactory     = pathFactory;

            _innerTrackOffset = _gameParameters.CellSize / 2.0f - _trackParameters.TrackWidth / 2.0f;
            _outerTrackOffset = _gameParameters.CellSize / 2.0f + _trackParameters.TrackWidth / 2.0f;
            _innerPlankOffset = _gameParameters.CellSize / 2.0f - _trackParameters.PlankLength / 2.0f;
            _outerPlankOffset = _gameParameters.CellSize / 2.0f + _trackParameters.PlankLength / 2.0f;
        }
示例#13
0
        public TerrainRenderer(ITerrainMap terrainMap, IPixelMapper pixelMapper, ITrackParameters trackParameters)
        {
            _terrainMap      = terrainMap;
            _pixelMapper     = pixelMapper;
            _trackParameters = trackParameters;

            _paintBrush = new PaintBrush
            {
                Color       = Colors.LightGray,
                StrokeWidth = 1,
                Style       = PaintStyle.Stroke
            };
        }
示例#14
0
        private static View GetConfigurationControl(ITrackParameters trackParameters, string parameter)
        {
            PropertyInfo prop = trackParameters.GetType().GetProperty(parameter, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            return(new VStack()
            {
                new Text(parameter + ":"),
                new HStack()
                {
                    new Button("-", () => AdjustProperty(trackParameters, prop, -1)),
                    new Text($"{prop.GetValue(trackParameters)}"),
                    new Button("+", () => AdjustProperty(trackParameters, prop, 1))
                }
            });
        }
示例#15
0
        public MainPage(IGame game,
                        IPixelMapper pixelMapper,
                        ITrackParameters trackParameters,
                        OrderedList <ITool> tools,
                        OrderedList <ILayerRenderer> layers,
                        OrderedList <ICommand> commands,
                        ITrainController trainControls)
        {
            this.Title("Train.NET - " + ThisAssembly.AssemblyInformationalVersion);

            var controlDelegate = new TrainsDelegate(game, pixelMapper);

            this.Body = () =>
            {
                return(new HStack()
                {
                    new VStack()
                    {
                        new ToggleButton("Configuration", _configurationShown, () => _configurationShown.Value = !_configurationShown.Value),
                        new Spacer(),
                        _configurationShown ?
                        CreateConfigurationControls(trackParameters, layers) :
                        CreateToolsControls(tools, controlDelegate),
                        new Spacer(),
                        _configurationShown ? null :
                        CreateCommandControls(commands),
                        new Spacer()
                    }.Frame(100, alignment: Alignment.Top),
                    new VStack()
                    {
                        new TrainControllerPanel(trainControls),
                        new DrawableControl(controlDelegate).FillVertical()
                    }
                }.FillHorizontal());
            };

            _timer = new Timer((state) =>
            {
                ThreadHelper.Run(async() =>
                {
                    await ThreadHelper.SwitchToMainThreadAsync();

                    controlDelegate.Invalidate();
                });
            }, null, 0, 16);
        }
示例#16
0
 public TreeRenderer(IBitmapFactory bitmapFactory, ITrackParameters trackParameters)
 {
     _cellSize      = trackParameters.CellSize;
     _centerOffset  = _cellSize / 2.0f;
     _baseRadius    = _cellSize / 4.0f;
     _minTreeSize   = _baseRadius;
     _maxTreeSize   = _baseRadius * 1.25f;
     _baseTreeBrush = new PaintBrush
     {
         Color = new Color("#1B633A"),
         Style = PaintStyle.Fill
     };
     _topTreeBrush = new PaintBrush
     {
         Color       = new Color("#236A42"),
         Style       = PaintStyle.Fill,
         IsAntialias = true
     };
     _bitmapFactory = bitmapFactory;
 }
示例#17
0
        public TrackRenderer(ITrackParameters parameters)
        {
            _parameters = parameters;

            _plankPaint = new SKPaint
            {
                Color       = SKColors.Black,
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = _parameters.PlankWidth,
                IsAntialias = true
            };
            _arcTrackClear = new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = _parameters.TrackWidth,
                Color       = SKColors.White,
                IsAntialias = true
            };
            _arcTrackPaint = new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 1,
                Color       = SKColors.Black,
                IsAntialias = true
            };
            _straightTrackPaint = new SKPaint
            {
                Color       = SKColors.Black,
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 1,
                IsAntialias = false
            };
            _straightTrackClear = new SKPaint
            {
                Color       = SKColors.White,
                Style       = SKPaintStyle.Fill,
                StrokeWidth = 0
            };
        }
示例#18
0
 public TrackRenderer(ITrackParameters parameters, IPathFactory pathFactory)
 {
     _parameters  = parameters;
     _pathFactory = pathFactory;
     _plankPaint  = new PaintBrush
     {
         Color       = Colors.Black,
         Style       = PaintStyle.Stroke,
         IsAntialias = true
     };
     _arcTrackClear = new PaintBrush()
     {
         Style       = PaintStyle.Stroke,
         Color       = Colors.White,
         IsAntialias = true
     };
     _arcTrackPaint = new PaintBrush()
     {
         Style       = PaintStyle.Stroke,
         StrokeWidth = 1,
         Color       = Colors.Black,
         IsAntialias = true
     };
     _straightTrackPaint = new PaintBrush
     {
         Color       = Colors.Black,
         Style       = PaintStyle.Stroke,
         StrokeWidth = 1,
         IsAntialias = false
     };
     _straightTrackClear = new PaintBrush
     {
         Color       = Colors.White,
         Style       = PaintStyle.Fill,
         StrokeWidth = 0
     };
 }
示例#19
0
 public PixelMapper(ITrackParameters parameters)
 {
     _parameters = parameters;
 }
示例#20
0
 public TrainRenderer(ITrackParameters trackParameters, ITrainParameters trainParameters, OrderedList <ITrainPalette> trainPalettes)
 {
     _trackParameters = trackParameters;
     _trainParameters = trainParameters;
     _trainPalettes   = trainPalettes;
 }
示例#21
0
 public GridRenderer(ITrackParameters parameters, IPixelMapper pixelMapper)
 {
     _parameters  = parameters;
     _pixelMapper = pixelMapper;
     _pixelMapper.ViewPortChanged += (s, e) => _dirty = true;
 }
示例#22
0
        public MainPage(IGame game,
                        IPixelMapper pixelMapper,
                        OrderedList <ITool> tools,
                        OrderedList <ILayerRenderer> layers,
                        OrderedList <ICommand> commands,
                        ITrainController trainControls,
                        ITrackParameters trackParameters,
                        ITrackLayout trackLayout,
                        IGameStorage gameStorage,
                        ITimer gameTimer,
                        Factory <IToolPreviewer> previewerFactory)
        {
            this.Title("Trains - " + ThisAssembly.AssemblyInformationalVersion);

            var controlDelegate = new TrainsDelegate(game, pixelMapper, previewerFactory);

            _miniMapDelegate = new MiniMapDelegate(trackLayout, trackParameters, pixelMapper);

            this.Body = () =>
            {
                return(new HStack()
                {
                    new VStack()
                    {
                        _configurationShown?null:
                        new Button(trainControls.BuildMode ? "Building" : "Playing", () => SwitchGameMode()),
                        new Spacer(),
                        _configurationShown ?
                        CreateConfigurationControls(layers) :
                        CreateToolsControls(tools, controlDelegate, trainControls.BuildMode.Value),
                        new Spacer(),
                        _configurationShown || !trainControls.BuildMode ? null :
                        CreateCommandControls(commands),
                        new Spacer(),
                        new Button("Configuration", () => _configurationShown.Value = !_configurationShown.Value),
                        new DrawableControl(_miniMapDelegate).Frame(height: 100)
                    }.Frame(100, alignment: Alignment.Top),
                    new VStack()
                    {
                        new TrainControllerPanel(trainControls),
                        new DrawableControl(controlDelegate)
                    }
                }.FillHorizontal());
            };

            _gameTimer          = gameTimer;
            _gameTimer.Elapsed += (s, e) =>
            {
                game.AdjustViewPortIfNecessary();

                controlDelegate.FlagDraw();
                _miniMapDelegate.FlagDraw();

                ThreadHelper.Run(async() =>
                {
                    await ThreadHelper.SwitchToMainThreadAsync();

                    controlDelegate.Invalidate();
                    _miniMapDelegate.Invalidate();
                });
            };
            _trackLayout = trackLayout;
            _gameStorage = gameStorage;

            void SwitchGameMode()
            {
                trainControls.ToggleBuildMode();

                if (controlDelegate == null)
                {
                    return;
                }

                controlDelegate.CurrentTool.Value = tools.FirstOrDefault(t => ShouldShowTool(trainControls.BuildMode, t));
            }
        }
示例#23
0
 public HappinessRenderer(IGameBoard gameBoard, IPixelMapper pixelMapper, ITrackParameters parameters)
 {
     _gameBoard   = gameBoard;
     _pixelMapper = pixelMapper;
     _parameters  = parameters;
 }
示例#24
0
 private static void AdjustProperty(ITrackParameters trackParameters, PropertyInfo prop, int adjustment)
 {
     prop.SetValue(trackParameters, (int)prop.GetValue(trackParameters) + adjustment);
 }
示例#25
0
 public TrainRenderer(IPixelMapper pixelMapper, ITrackParameters trackParameters)
 {
     _pixelMapper     = pixelMapper;
     _trackParameters = trackParameters;
 }
示例#26
0
 public TrackRenderer(ITrackParameters parameters)
 {
     _parameters = parameters;
 }
 public TrainLookaheadRenderer(IGameBoard gameBoard, IPixelMapper pixelMapper, ITrackParameters parameters)
 {
     _gameBoard   = gameBoard;
     _pixelMapper = pixelMapper;
     _parameters  = parameters;
 }
示例#28
0
 public HappinessRenderer(ITrackLayout trackLayout, IPixelMapper pixelMapper, ITrackParameters parameters)
 {
     _trackLayout = trackLayout;
     _pixelMapper = pixelMapper;
     _parameters  = parameters;
 }
示例#29
0
        public MainForm(IGame game, IEnumerable <IBoardRenderer> renderers, ITrackParameters parameters)
        {
            _game              = game;
            _parameters        = parameters;
            this.Text          = "Trains.NET";
            this.AutoScaleMode = AutoScaleMode.Font;
            this.StartPosition = FormStartPosition.Manual;
            this.Location      = new Point(1086, 559);
            this.ClientSize    = new Size(1547, 897);

            var splitContainer = new SplitContainer()
            {
                FixedPanel       = FixedPanel.Panel1,
                SplitterDistance = 400,
                Dock             = DockStyle.Fill,
                IsSplitterFixed  = true
            };

            var buttonPanel = new Panel()
            {
                Dock     = DockStyle.Top,
                Padding  = new Padding(5),
                AutoSize = true
            };

            var rendererPanel = new Panel()
            {
                Dock     = DockStyle.Top,
                Padding  = new Padding(5),
                AutoSize = true
            };

            foreach (Tool tool in ((Tool[])Enum.GetValues(typeof(Tool))).Reverse())
            {
                buttonPanel.Controls.Add(CreateButton(tool));
            }

            var button = new CheckBox
            {
                Text       = "Configure",
                Height     = 30,
                TextAlign  = ContentAlignment.MiddleCenter,
                Dock       = DockStyle.Top,
                Appearance = Appearance.Button
            };

            buttonPanel.Controls.Add(button);

            button.CheckedChanged += (s, e) =>
            {
                if (_debugForm == null)
                {
                    _debugForm = CreateDebugForm();
                }

                if (button.Checked)
                {
                    _debugForm.Show();
                }
                else
                {
                    _debugForm.Hide();
                }
            };

            _skiaView = new SKControl()
            {
                Dock = DockStyle.Fill
            };

            _skiaView.MouseDown    += DoMouseClick;
            _skiaView.MouseMove    += DoMouseClick;
            _skiaView.Resize       += (s, e) => _game.SetSize(_skiaView.Width, _skiaView.Height);
            _skiaView.PaintSurface += (s, e) => _game.Render(e.Surface);

            foreach (IBoardRenderer renderer in renderers)
            {
                rendererPanel.Controls.Add(CreateRendererCheckbox(renderer));
            }

            splitContainer.Panel1.Controls.Add(rendererPanel);
            splitContainer.Panel1.Controls.Add(buttonPanel);
            splitContainer.Panel2.Controls.Add(_skiaView);
            splitContainer.Panel2.Padding = new Padding(5);

            this.Controls.Add(splitContainer);

            void DoMouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.None)
                {
                    return;
                }
                if ((e.Button & MouseButtons.Middle) == MouseButtons.Middle)
                {
                    return;
                }

                bool isRightMouseButton = (e.Button & MouseButtons.Right) == MouseButtons.Right;

                _game.OnMouseDown(e.X, e.Y, isRightMouseButton);

                _skiaView.Refresh();
            }

            RadioButton CreateButton(Tool tool)
            {
                var button = new RadioButton()
                {
                    Text       = tool.ToString(),
                    Dock       = DockStyle.Top,
                    Height     = 50,
                    Appearance = Appearance.Button,
                    TextAlign  = ContentAlignment.MiddleCenter,
                    Checked    = tool == (Tool)0
                };

                button.Click += (s, e) => _game.CurrentTool = tool;

                return(button);
            }

            Control CreateRendererCheckbox(IBoardRenderer renderer)
            {
                var checkbox = new CheckBox
                {
                    Text       = renderer.Name,
                    Dock       = DockStyle.Top,
                    Height     = 50,
                    Appearance = Appearance.Button,
                    TextAlign  = ContentAlignment.MiddleCenter,
                    Checked    = renderer.Enabled
                };

                checkbox.CheckedChanged += (s, e) =>
                {
                    renderer.Enabled = checkbox.Checked;
                    _skiaView.Refresh();
                };

                return(checkbox);
            }
        }
示例#30
0
 public TrainRenderer(ITrackParameters trackParameters, ITrainParameters trainParameters, ITrainPainter trainPainter)
 {
     _trackParameters = trackParameters;
     _trainParameters = trainParameters;
     _trainPainter    = trainPainter;
 }