Add generated Win2D sprites

This commit is contained in:
2026-05-09 02:17:47 +02:00
parent fd5564e444
commit 6e8766db3f
22 changed files with 260 additions and 112 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

View File

@@ -29,7 +29,20 @@
<ScrollViewer Grid.Column="0" Background="#1C2126"> <ScrollViewer Grid.Column="0" Background="#1C2126">
<StackPanel Padding="12" Spacing="10"> <StackPanel Padding="12" Spacing="10">
<TextBlock Text="Tools" FontSize="18" FontWeight="SemiBold" Foreground="#F4F1E8" /> <TextBlock Text="Tools" FontSize="18" FontWeight="SemiBold" Foreground="#F4F1E8" />
<ComboBox x:Name="ToolPicker" SelectionChanged="ToolPicker_SelectionChanged" /> <ComboBox x:Name="ToolPicker" SelectionChanged="ToolPicker_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="28" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Width="24" Height="24" Source="{Binding Icon}" />
<TextBlock Grid.Column="1" Text="{Binding Label}" />
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock Text="Brush applies to the selected cell." Foreground="#9EA7AE" TextWrapping="Wrap" /> <TextBlock Text="Brush applies to the selected cell." Foreground="#9EA7AE" TextWrapping="Wrap" />
<TextBlock Text="Left click paints. Use Robot to set the start position." Foreground="#9EA7AE" <TextBlock Text="Left click paints. Use Robot to set the start position." Foreground="#9EA7AE"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
@@ -78,7 +91,15 @@
<DataTemplate> <DataTemplate>
<Border BorderBrush="#46515A" BorderThickness="1" Padding="8" Margin="0,0,0,8" <Border BorderBrush="#46515A" BorderThickness="1" Padding="8" Margin="0,0,0,8"
CornerRadius="3"> CornerRadius="3">
<TextBlock Text="{Binding Message}" Foreground="#F4F1E8" TextWrapping="Wrap" /> <Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Width="28" Height="28" Source="{Binding Icon}" />
<TextBlock Grid.Column="1" Text="{Binding Message}" Foreground="#F4F1E8"
TextWrapping="Wrap" />
</Grid>
</Border> </Border>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>

View File

@@ -1,18 +1,17 @@
using System.Numerics; using Microsoft.Graphics.Canvas;
using Windows.Foundation;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.UI;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Text;
using Microsoft.Graphics.Canvas.UI; using Microsoft.Graphics.Canvas.UI;
using Microsoft.Graphics.Canvas.UI.Xaml; using Microsoft.Graphics.Canvas.UI.Xaml;
using Microsoft.UI; using Microsoft.UI;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media.Imaging;
using ReactorMaintenance.Simulation; using ReactorMaintenance.Simulation;
using System.Globalization; using System.Globalization;
using Windows.Foundation;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.UI;
using Windows.UI.Popups; using Windows.UI.Popups;
using WinRT.Interop; using WinRT.Interop;
@@ -24,40 +23,65 @@ public sealed partial class MainWindow
{ {
public Rect CellRect(int x, int y) public Rect CellRect(int x, int y)
{ {
return new(OriginX + x * CellSize, OriginY + y * CellSize, CellSize, CellSize); return new(OriginX + (x * CellSize), OriginY + (y * CellSize), CellSize, CellSize);
} }
public Rect DualTileRect(int x, int y) public Rect DualTileRect(int x, int y)
{ {
return new(OriginX + (x - 0.5) * CellSize, OriginY + (y - 0.5) * CellSize, CellSize, CellSize); return new(OriginX + ((x - 0.5) * CellSize), OriginY + ((y - 0.5) * CellSize), CellSize, CellSize);
} }
} }
private sealed record ForecastViewModel(BitmapImage Icon, string Message);
private sealed record EditorToolViewModel(EEditorTool Tool, BitmapImage? Icon, string Label);
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
m_Level = BuildStarterLevel(); m_Level = BuildStarterLevel();
ToolPicker.ItemsSource = Enum.GetValues<EEditorTool>(); m_EditorTools = Enum.GetValues<EEditorTool>().Select(tool => new EditorToolViewModel(tool, EditorToolIcon(tool), tool.ToString())).ToArray();
ToolPicker.SelectedItem = m_SelectedTool; ToolPicker.ItemsSource = m_EditorTools;
ToolPicker.SelectedItem = m_EditorTools.First(tool => tool.Tool == m_SelectedTool);
RefreshInspector(); RefreshInspector();
} }
private void LevelCanvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args) private void LevelCanvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
{ {
args.TrackAsyncAction(LoadTilemapAsync(sender).AsAsyncAction()); args.TrackAsyncAction(LoadImagesAsync(sender).AsAsyncAction());
} }
private async Task LoadTilemapAsync(CanvasControl sender) private async Task LoadImagesAsync(CanvasControl sender)
{ {
var tilemapPath = Path.Combine(AppContext.BaseDirectory, "Images", "tilemap.png"); m_TerrainTilemap = await LoadCanvasBitmapAsync(sender, "Images", "tilemap.png");
m_TerrainTilemap = await CanvasBitmap.LoadAsync(sender, tilemapPath); m_RobotSprite = await LoadCanvasBitmapAsync(sender, "Images", "Props", "robot.png");
m_LeakSprite = await LoadCanvasBitmapAsync(sender, "Images", "Props", "leak.png");
m_HeatSprite = await LoadCanvasBitmapAsync(sender, "Images", "Props", "heat.png");
m_FireSprite = await LoadCanvasBitmapAsync(sender, "Images", "Props", "fire.png");
m_PropSprites[ECellProp.Reactor] = await LoadCanvasBitmapAsync(sender, "Images", "Props", "reactor.png");
m_PropSprites[ECellProp.CoolingPump] = await LoadCanvasBitmapAsync(sender, "Images", "Props", "cooling-pump.png");
m_PropSprites[ECellProp.Generator] = await LoadCanvasBitmapAsync(sender, "Images", "Props", "generator.png");
m_PropSprites[ECellProp.PressureRegulator] = await LoadCanvasBitmapAsync(sender, "Images", "Props", "pressure-regulator.png");
m_PropSprites[ECellProp.DiagnosticTerminal] = await LoadCanvasBitmapAsync(sender, "Images", "Props", "diagnostic-terminal.png");
m_PropSprites[ECellProp.ControlTerminal] = await LoadCanvasBitmapAsync(sender, "Images", "Props", "control-terminal.png");
m_PipeTilemaps[EPipeMedium.Pressure] = await LoadCanvasBitmapAsync(sender, "Images", "Pipes", "pipe-pressure-tilemap.png");
m_PipeTilemaps[EPipeMedium.Coolant] = await LoadCanvasBitmapAsync(sender, "Images", "Pipes", "pipe-coolant-tilemap.png");
m_PipeTilemaps[EPipeMedium.Fuel] = await LoadCanvasBitmapAsync(sender, "Images", "Pipes", "pipe-fuel-tilemap.png");
}
private static async Task<CanvasBitmap> LoadCanvasBitmapAsync(CanvasControl sender, params string[] pathParts)
{
var path = Path.Combine([AppContext.BaseDirectory, .. pathParts]);
return await CanvasBitmap.LoadAsync(sender, path);
} }
private void ToolPicker_SelectionChanged(object sender, SelectionChangedEventArgs e) private void ToolPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
if (ToolPicker.SelectedItem is EEditorTool tool) if (ToolPicker.SelectedItem is EditorToolViewModel tool)
m_SelectedTool = tool; m_SelectedTool = tool.Tool;
} }
private void New_Click(object sender, RoutedEventArgs e) private void New_Click(object sender, RoutedEventArgs e)
@@ -183,45 +207,116 @@ public sealed partial class MainWindow
private void DrawTerrain(CanvasDrawingSession drawing, CanvasLayout layout) private void DrawTerrain(CanvasDrawingSession drawing, CanvasLayout layout)
{ {
for (var y = 0; y <= m_Level.Height; y++) for (var y = 0; y <= m_Level.Height; y++)
for (var x = 0; x <= m_Level.Width; x++) {
DrawDualTerrainTile(drawing, layout.DualTileRect(x, y), GetDualTileMask(x, y)); for (var x = 0; x <= m_Level.Width; x++)
{
DrawDualTerrainTile(drawing, layout.DualTileRect(x, y), GetDualTileMask(x, y));
}
}
} }
private void DrawCellOverlays(CanvasDrawingSession drawing, CanvasLayout layout) private void DrawCellOverlays(CanvasDrawingSession drawing, CanvasLayout layout)
{ {
for (var y = 0; y < m_Level.Height; y++) for (var y = 0; y < m_Level.Height; y++)
for (var x = 0; x < m_Level.Width; x++)
{ {
var position = new GridPosition(x, y); for (var x = 0; x < m_Level.Width; x++)
var cell = m_Level.GetCell(position);
var rect = layout.CellRect(x, y);
if (cell.HasPipe)
{ {
var center = new Vector2((float)(rect.X + rect.Width / 2), (float)(rect.Y + rect.Height / 2)); var position = new GridPosition(x, y);
var pipeColor = cell.Pipe switch { var cell = m_Level.GetCell(position);
EPipeMedium.Coolant => Colors.DeepSkyBlue, var rect = layout.CellRect(x, y);
EPipeMedium.Fuel => Colors.Goldenrod,
EPipeMedium.Pressure => Colors.LightSteelBlue, DrawPipe(drawing, position, cell, rect);
_ => Colors.Transparent
}; if (cell.LeakRate > 0)
drawing.DrawLine(center with { X = (float)rect.X + 6 }, center with { X = (float)(rect.X + rect.Width - 6) }, pipeColor, Math.Max(3, (float)rect.Width / 7)); DrawImage(drawing, m_LeakSprite, Inset(rect, 0.12));
drawing.DrawLine(center with { Y = (float)rect.Y + 6 }, center with { Y = (float)(rect.Y + rect.Height - 6) }, pipeColor, Math.Max(3, (float)rect.Width / 7));
if (cell.Hazards.Heat > 0)
DrawImage(drawing, m_HeatSprite, Inset(rect, 0.08), Math.Clamp(cell.Hazards.Heat / 10.0f, 0.35f, 0.9f));
if (cell.Hazards.Fire)
DrawImage(drawing, m_FireSprite, Inset(rect, 0.08));
if (m_SelectedCell == position)
drawing.DrawRectangle(rect, Colors.White, 3);
DrawCellProp(drawing, cell, rect);
} }
if (cell.LeakRate > 0)
drawing.DrawCircle(new((float)(rect.X + rect.Width - 10), (float)(rect.Y + 10)), 5, Colors.OrangeRed, 2);
if (cell.Hazards.Fire)
drawing.FillCircle(new((float)(rect.X + rect.Width * 0.5), (float)(rect.Y + rect.Height * 0.5)), (float)rect.Width * 0.24f, Colors.OrangeRed);
if (m_SelectedCell == position)
drawing.DrawRectangle(rect, Colors.White, 3);
DrawCellProp(drawing, cell, rect);
} }
} }
private void DrawPipe(CanvasDrawingSession drawing, GridPosition position, CellState cell, Rect rect)
{
if (!cell.HasPipe || !m_PipeTilemaps.TryGetValue(cell.Pipe, out var tilemap))
return;
var sourceRect = PipeTileSourceRect(GetPipeConnectionMask(position, cell.Pipe));
drawing.DrawImage(tilemap, rect, sourceRect);
}
private int GetPipeConnectionMask(GridPosition position, EPipeMedium medium)
{
var mask = 0;
if (HasMatchingPipe(position with { Y = position.Y - 1 }, medium))
mask |= c_NorthConnection;
if (HasMatchingPipe(position with { X = position.X + 1 }, medium))
mask |= c_EastConnection;
if (HasMatchingPipe(position with { Y = position.Y + 1 }, medium))
mask |= c_SouthConnection;
if (HasMatchingPipe(position with { X = position.X - 1 }, medium))
mask |= c_WestConnection;
return mask;
}
private bool HasMatchingPipe(GridPosition position, EPipeMedium medium)
{
return m_Level.InBounds(position) && m_Level.GetCell(position).Pipe == medium;
}
private static Rect PipeTileSourceRect(int connectionMask)
{
var tileIndex = connectionMask switch {
0 => 0,
c_NorthConnection => 1,
c_EastConnection => 2,
c_SouthConnection => 3,
c_WestConnection => 4,
c_NorthConnection | c_EastConnection => 5,
c_EastConnection | c_SouthConnection => 6,
c_SouthConnection | c_WestConnection => 7,
c_WestConnection | c_NorthConnection => 8,
c_NorthConnection | c_SouthConnection => 9,
c_EastConnection | c_WestConnection => 10,
c_NorthConnection | c_EastConnection | c_SouthConnection => 11,
c_EastConnection | c_SouthConnection | c_WestConnection => 12,
c_SouthConnection | c_WestConnection | c_NorthConnection => 13,
c_WestConnection | c_NorthConnection | c_EastConnection => 14,
c_NorthConnection | c_EastConnection | c_SouthConnection | c_WestConnection => 15,
_ => throw new ArgumentOutOfRangeException(nameof(connectionMask), connectionMask, "Unsupported pipe connection mask.")
};
return new(
tileIndex % c_PipeTilemapColumns * c_PipeTilemapTileSize,
tileIndex / c_PipeTilemapColumns * c_PipeTilemapTileSize,
c_PipeTilemapTileSize,
c_PipeTilemapTileSize);
}
private static void DrawImage(CanvasDrawingSession drawing, CanvasBitmap? image, Rect rect, float opacity = 1)
{
if (image is not null)
drawing.DrawImage(image, rect, image.Bounds, opacity);
}
private static Rect Inset(Rect rect, double fraction)
{
var inset = rect.Width * fraction;
return new(rect.X + inset, rect.Y + inset, rect.Width - inset * 2, rect.Height - inset * 2);
}
private void DrawDualTerrainTile(CanvasDrawingSession drawing, Rect rect, int floorMask) private void DrawDualTerrainTile(CanvasDrawingSession drawing, Rect rect, int floorMask)
{ {
if (m_TerrainTilemap is null) if (m_TerrainTilemap is null)
@@ -235,21 +330,21 @@ public sealed partial class MainWindow
private static Rect TilemapSourceRect(int wallMask) private static Rect TilemapSourceRect(int wallMask)
{ {
var tilePosition = wallMask switch { var tilePosition = wallMask switch {
c_BottomLeftCorner => new GridPosition(0, 0), c_BottomLeftCorner => new(0, 0),
c_TopRightCorner | c_BottomRightCorner => new GridPosition(1, 0), c_TopRightCorner | c_BottomRightCorner => new(1, 0),
c_TopLeftCorner | c_BottomLeftCorner | c_BottomRightCorner => new GridPosition(2, 0), c_TopLeftCorner | c_BottomLeftCorner | c_BottomRightCorner => new(2, 0),
c_BottomLeftCorner | c_BottomRightCorner => new GridPosition(3, 0), c_BottomLeftCorner | c_BottomRightCorner => new(3, 0),
c_TopLeftCorner | c_BottomRightCorner => new GridPosition(0, 1), c_TopLeftCorner | c_BottomRightCorner => new(0, 1),
c_BottomLeftCorner | c_TopRightCorner | c_BottomRightCorner => new GridPosition(1, 1), c_BottomLeftCorner | c_TopRightCorner | c_BottomRightCorner => new(1, 1),
c_AllCorners => new GridPosition(2, 1), c_AllCorners => new(2, 1),
c_TopLeftCorner | c_BottomLeftCorner | c_TopRightCorner => new GridPosition(3, 1), c_TopLeftCorner | c_BottomLeftCorner | c_TopRightCorner => new(3, 1),
c_TopRightCorner => new GridPosition(0, 2), c_TopRightCorner => new(0, 2),
c_TopLeftCorner | c_TopRightCorner => new GridPosition(1, 2), c_TopLeftCorner | c_TopRightCorner => new(1, 2),
c_TopLeftCorner | c_TopRightCorner | c_BottomRightCorner => new GridPosition(2, 2), c_TopLeftCorner | c_TopRightCorner | c_BottomRightCorner => new(2, 2),
c_BottomLeftCorner | c_TopLeftCorner => new GridPosition(3, 2), c_BottomLeftCorner | c_TopLeftCorner => new(3, 2),
0 => new GridPosition(0, 3), 0 => new(0, 3),
c_BottomRightCorner => new GridPosition(1, 3), c_BottomRightCorner => new(1, 3),
c_BottomLeftCorner | c_TopRightCorner => new GridPosition(2, 3), c_BottomLeftCorner | c_TopRightCorner => new(2, 3),
c_TopLeftCorner => new GridPosition(3, 3), c_TopLeftCorner => new GridPosition(3, 3),
_ => throw new ArgumentOutOfRangeException(nameof(wallMask), wallMask, "Unsupported tile mask.") _ => throw new ArgumentOutOfRangeException(nameof(wallMask), wallMask, "Unsupported tile mask.")
}; };
@@ -287,52 +382,29 @@ public sealed partial class MainWindow
private void DrawCellProp(CanvasDrawingSession drawing, CellState cell, Rect rect) private void DrawCellProp(CanvasDrawingSession drawing, CellState cell, Rect rect)
{ {
var text = cell.Prop switch { if (m_PropSprites.TryGetValue(cell.Prop, out var sprite))
ECellProp.Reactor => "R", drawing.DrawImage(sprite, rect, sprite.Bounds);
ECellProp.CoolingPump => "C",
ECellProp.Generator => "G",
ECellProp.PressureRegulator => "P",
ECellProp.DiagnosticTerminal => "D",
ECellProp.ControlTerminal => "T",
_ => string.Empty
};
if (string.IsNullOrEmpty(text))
return;
var propRect = new Rect(rect.X + rect.Width * 0.18, rect.Y + rect.Height * 0.18, rect.Width * 0.64, rect.Height * 0.64);
drawing.FillRoundedRectangle(propRect, 4, 4, PropColor(cell.Prop));
drawing.DrawRoundedRectangle(propRect, 4, 4, ColorHelper.FromArgb(210, 12, 14, 16), 2);
using var format = new CanvasTextFormat();
format.FontSize = Math.Max(14, (float)rect.Width * 0.34f);
format.HorizontalAlignment = CanvasHorizontalAlignment.Center;
format.VerticalAlignment = CanvasVerticalAlignment.Center;
drawing.DrawText(text, propRect, Colors.White, format);
} }
private void DrawGrid(CanvasDrawingSession drawing, CanvasLayout layout) private void DrawGrid(CanvasDrawingSession drawing, CanvasLayout layout)
{ {
for (var x = 0; x <= m_Level.Width; x++) for (var x = 0; x <= m_Level.Width; x++)
{ {
var xPos = (float)(layout.OriginX + x * layout.CellSize); var xPos = (float)(layout.OriginX + (x * layout.CellSize));
drawing.DrawLine(xPos, (float)layout.OriginY, xPos, (float)(layout.OriginY + m_Level.Height * layout.CellSize), ColorHelper.FromArgb(120, 91, 104, 115), 1); drawing.DrawLine(xPos, (float)layout.OriginY, xPos, (float)(layout.OriginY + (m_Level.Height * layout.CellSize)), ColorHelper.FromArgb(120, 91, 104, 115), 1);
} }
for (var y = 0; y <= m_Level.Height; y++) for (var y = 0; y <= m_Level.Height; y++)
{ {
var yPos = (float)(layout.OriginY + y * layout.CellSize); var yPos = (float)(layout.OriginY + (y * layout.CellSize));
drawing.DrawLine((float)layout.OriginX, yPos, (float)(layout.OriginX + m_Level.Width * layout.CellSize), yPos, ColorHelper.FromArgb(120, 91, 104, 115), 1); drawing.DrawLine((float)layout.OriginX, yPos, (float)(layout.OriginX + (m_Level.Width * layout.CellSize)), yPos, ColorHelper.FromArgb(120, 91, 104, 115), 1);
} }
} }
private void DrawRobot(CanvasDrawingSession drawing, CanvasLayout layout) private void DrawRobot(CanvasDrawingSession drawing, CanvasLayout layout)
{ {
var rect = layout.CellRect(m_Level.Robot.X, m_Level.Robot.Y); var rect = layout.CellRect(m_Level.Robot.X, m_Level.Robot.Y);
var center = new Vector2((float)(rect.X + rect.Width / 2), (float)(rect.Y + rect.Height / 2)); DrawImage(drawing, m_RobotSprite, rect);
drawing.FillCircle(center, (float)rect.Width * 0.28f, Colors.White);
drawing.DrawCircle(center, (float)rect.Width * 0.28f, Colors.Black, 2);
} }
private bool TryGetGridPosition(Point point, out GridPosition position) private bool TryGetGridPosition(Point point, out GridPosition position)
@@ -350,24 +422,11 @@ public sealed partial class MainWindow
var availableHeight = Math.Max(1, LevelCanvas.ActualHeight); var availableHeight = Math.Max(1, LevelCanvas.ActualHeight);
var size = Math.Floor(Math.Min(availableWidth / m_Level.Width, availableHeight / m_Level.Height)); var size = Math.Floor(Math.Min(availableWidth / m_Level.Width, availableHeight / m_Level.Height));
size = Math.Max(20, size); size = Math.Max(20, size);
var originX = Math.Max(0, (availableWidth - size * m_Level.Width) / 2); var originX = Math.Max(0, (availableWidth - (size * m_Level.Width)) / 2);
var originY = Math.Max(0, (availableHeight - size * m_Level.Height) / 2); var originY = Math.Max(0, (availableHeight - (size * m_Level.Height)) / 2);
return new(size, originX, originY); return new(size, originX, originY);
} }
private static Color PropColor(ECellProp prop)
{
return prop switch {
ECellProp.Reactor => ColorHelper.FromArgb(255, 61, 76, 82),
ECellProp.CoolingPump => ColorHelper.FromArgb(255, 25, 79, 96),
ECellProp.Generator => ColorHelper.FromArgb(255, 86, 75, 35),
ECellProp.PressureRegulator => ColorHelper.FromArgb(255, 70, 78, 98),
ECellProp.DiagnosticTerminal => ColorHelper.FromArgb(255, 39, 84, 62),
ECellProp.ControlTerminal => ColorHelper.FromArgb(255, 80, 61, 91),
_ => Colors.Transparent
};
}
private void RefreshInspector() private void RefreshInspector()
{ {
LevelNameText.Text = m_Level.Name; LevelNameText.Text = m_Level.Name;
@@ -383,7 +442,61 @@ public sealed partial class MainWindow
else else
CellText.Text = "No cell selected."; CellText.Text = "No cell selected.";
ForecastList.ItemsSource = m_Level.Forecasts; ForecastList.ItemsSource = m_Level.Forecasts.Select(forecast => new ForecastViewModel(FailureIcon(forecast.Kind), forecast.Message)).ToArray();
}
private static BitmapImage FailureIcon(EFailureKind kind)
{
return ImageFromOutputPath("Images", "Failures", FailureIconFileName(kind));
}
private static string FailureIconFileName(EFailureKind kind)
{
return kind switch {
EFailureKind.PipeBurst => "failure-pipe-burst.png",
EFailureKind.Ignition => "failure-ignition.png",
EFailureKind.Meltdown => "failure-meltdown.png",
EFailureKind.StabilityCollapse => "failure-stability-collapse.png",
EFailureKind.ReactorReady => "failure-reactor-ready.png",
_ => throw new ArgumentOutOfRangeException(nameof(kind), kind, "Unsupported failure kind.")
};
}
private static BitmapImage? EditorToolIcon(EEditorTool tool)
{
return tool switch {
EEditorTool.Floor or EEditorTool.Wall => null,
EEditorTool.Reactor => PropImage("reactor.png"),
EEditorTool.CoolingPump => PropImage("cooling-pump.png"),
EEditorTool.Generator => PropImage("generator.png"),
EEditorTool.PressureRegulator => PropImage("pressure-regulator.png"),
EEditorTool.DiagnosticTerminal => PropImage("diagnostic-terminal.png"),
EEditorTool.ControlTerminal => PropImage("control-terminal.png"),
EEditorTool.CoolantPipe => PipeImage("pipe-coolant-tilemap.png"),
EEditorTool.FuelPipe => PipeImage("pipe-fuel-tilemap.png"),
EEditorTool.PressurePipe => PipeImage("pipe-pressure-tilemap.png"),
EEditorTool.Leak => PropImage("leak.png"),
EEditorTool.Repair => PropImage("repair.png"),
EEditorTool.Heat => PropImage("heat.png"),
EEditorTool.Fire => PropImage("fire.png"),
EEditorTool.Robot => PropImage("robot.png"),
_ => throw new ArgumentOutOfRangeException(nameof(tool), tool, "Unsupported editor tool.")
};
}
private static BitmapImage PropImage(string fileName)
{
return ImageFromOutputPath("Images", "Props", fileName);
}
private static BitmapImage PipeImage(string fileName)
{
return ImageFromOutputPath("Images", "Pipes", fileName);
}
private static BitmapImage ImageFromOutputPath(params string[] pathParts)
{
return new(new(Path.Combine([AppContext.BaseDirectory, .. pathParts])));
} }
private static LevelState BuildStarterLevel() private static LevelState BuildStarterLevel()
@@ -438,17 +551,31 @@ public sealed partial class MainWindow
return level with { Forecasts = new SimulationEngine().Forecast(level) }; return level with { Forecasts = new SimulationEngine().Forecast(level) };
} }
private readonly SimulationEngine m_Simulation = new();
private const int c_TilemapTileSize = 512; private const int c_TilemapTileSize = 512;
private const int c_PipeTilemapTileSize = 256;
private const int c_PipeTilemapColumns = 4;
private const int c_TopLeftCorner = 1; private const int c_TopLeftCorner = 1;
private const int c_TopRightCorner = 2; private const int c_TopRightCorner = 2;
private const int c_BottomLeftCorner = 4; private const int c_BottomLeftCorner = 4;
private const int c_BottomRightCorner = 8; private const int c_BottomRightCorner = 8;
private const int c_AllCorners = c_TopLeftCorner | c_TopRightCorner | c_BottomLeftCorner | c_BottomRightCorner; private const int c_AllCorners = c_TopLeftCorner | c_TopRightCorner | c_BottomLeftCorner | c_BottomRightCorner;
private CanvasBitmap? m_TerrainTilemap; private const int c_NorthConnection = 1;
private const int c_EastConnection = 2;
private const int c_SouthConnection = 4;
private const int c_WestConnection = 8;
private readonly SimulationEngine m_Simulation = new();
private readonly Dictionary<ECellProp, CanvasBitmap> m_PropSprites = [];
private readonly Dictionary<EPipeMedium, CanvasBitmap> m_PipeTilemaps = [];
private StorageFile? m_CurrentFile; private StorageFile? m_CurrentFile;
private LevelState m_Level; private LevelState m_Level;
private IReadOnlyList<EditorToolViewModel> m_EditorTools = [];
private bool m_Painting; private bool m_Painting;
private GridPosition? m_SelectedCell; private GridPosition? m_SelectedCell;
private EEditorTool m_SelectedTool = EEditorTool.Floor; private EEditorTool m_SelectedTool = EEditorTool.Floor;
} private CanvasBitmap? m_TerrainTilemap;
private CanvasBitmap? m_RobotSprite;
private CanvasBitmap? m_LeakSprite;
private CanvasBitmap? m_HeatSprite;
private CanvasBitmap? m_FireSprite;
}

View File

@@ -26,7 +26,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Update="Images\tilemap.png"> <Content Update="Images\**\*.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>