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; }
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 }; }
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; }
public TrainLookaheadRenderer(IGameBoard gameBoard, IPixelMapper pixelMapper, ITrackParameters parameters, ITrainPainter painter, ITimer gameTimer) { _gameBoard = gameBoard; _pixelMapper = pixelMapper; _parameters = parameters; _painter = painter; _gameTimer = gameTimer; }
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; }
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; }
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; }
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; }
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; }
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; }
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 }; }
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)) } }); }
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); }
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; }
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 }; }
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 }; }
public PixelMapper(ITrackParameters parameters) { _parameters = parameters; }
public TrainRenderer(ITrackParameters trackParameters, ITrainParameters trainParameters, OrderedList <ITrainPalette> trainPalettes) { _trackParameters = trackParameters; _trainParameters = trainParameters; _trainPalettes = trainPalettes; }
public GridRenderer(ITrackParameters parameters, IPixelMapper pixelMapper) { _parameters = parameters; _pixelMapper = pixelMapper; _pixelMapper.ViewPortChanged += (s, e) => _dirty = true; }
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)); } }
public HappinessRenderer(IGameBoard gameBoard, IPixelMapper pixelMapper, ITrackParameters parameters) { _gameBoard = gameBoard; _pixelMapper = pixelMapper; _parameters = parameters; }
private static void AdjustProperty(ITrackParameters trackParameters, PropertyInfo prop, int adjustment) { prop.SetValue(trackParameters, (int)prop.GetValue(trackParameters) + adjustment); }
public TrainRenderer(IPixelMapper pixelMapper, ITrackParameters trackParameters) { _pixelMapper = pixelMapper; _trackParameters = trackParameters; }
public TrackRenderer(ITrackParameters parameters) { _parameters = parameters; }
public TrainLookaheadRenderer(IGameBoard gameBoard, IPixelMapper pixelMapper, ITrackParameters parameters) { _gameBoard = gameBoard; _pixelMapper = pixelMapper; _parameters = parameters; }
public HappinessRenderer(ITrackLayout trackLayout, IPixelMapper pixelMapper, ITrackParameters parameters) { _trackLayout = trackLayout; _pixelMapper = pixelMapper; _parameters = parameters; }
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); } }
public TrainRenderer(ITrackParameters trackParameters, ITrainParameters trainParameters, ITrainPainter trainPainter) { _trackParameters = trackParameters; _trainParameters = trainParameters; _trainPainter = trainPainter; }