UI iteration.

This commit is contained in:
2026-05-12 00:01:07 +02:00
parent fbb7c0490c
commit 99482c7011
2 changed files with 129 additions and 83 deletions

View File

@@ -93,21 +93,23 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
<TextBlock Text="Inventory And Objects" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" /> <TextBlock Text="Inventory" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
<ItemsControl x:Name="GlobalGrid"> <ItemsControl x:Name="InventoryGrid">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border BorderBrush="#3C4650" BorderThickness="1" Padding="8" Margin="0,0,8,8" <Grid MinWidth="55" Margin="0,0,4,0">
CornerRadius="3"> <Grid.RowDefinitions>
<StackPanel Spacing="2"> <RowDefinition Height="Auto" />
<TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" <RowDefinition Height="Auto" />
TextWrapping="Wrap" /> </Grid.RowDefinitions>
<TextBlock Text="{Binding Value}" Foreground="#F4F1E8" FontSize="15" <TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" />
TextWrapping="Wrap" /> <TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="18" />
<TextBlock Text="{Binding Description}" Foreground="#9EA7AE" FontSize="11" </Grid>
TextWrapping="Wrap" />
</StackPanel>
</Border>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
@@ -134,23 +136,77 @@
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
<TextBlock Text="Selected Cell" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" /> <TextBlock x:Name="HoveredCellText" Text="Hovered Cell:" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
<TextBlock x:Name="SelectedCellTitleText" FontSize="19" FontWeight="SemiBold" <TextBlock x:Name="SelectedCellText" Text="Selected Cell:" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
Foreground="#F4F1E8" TextWrapping="Wrap" /> <Grid>
<ItemsControl x:Name="CellGrid"> <Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="Terrain" Foreground="#9EA7AE" FontSize="11" />
<TextBlock Grid.Column="0" Grid.Row="1" x:Name="TerrainText" Foreground="#F4F1E8" FontSize="16" Margin="0,0,10,0" />
<TextBlock Grid.Column="1" Grid.Row="0" Text="Prop" Foreground="#9EA7AE" FontSize="11" />
<TextBlock Grid.Column="1" Grid.Row="1" x:Name="PropText" Foreground="#F4F1E8" FontSize="16" />
</Grid>
<TextBlock Text="Consumers:" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
<ItemsControl x:Name="ConsumersGrid">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border BorderBrush="#3C4650" BorderThickness="1" Padding="8" Margin="0,0,8,8" <Grid Width="96" Margin="0,0,4,0">
CornerRadius="3"> <Grid.RowDefinitions>
<StackPanel Spacing="2"> <RowDefinition Height="Auto" />
<TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" <RowDefinition Height="Auto" />
TextWrapping="Wrap" /> </Grid.RowDefinitions>
<TextBlock Text="{Binding Value}" Foreground="#F4F1E8" FontSize="14" <TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" TextWrapping="NoWrap" />
TextWrapping="WrapWholeWords" /> <TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="16" />
<TextBlock Text="{Binding Description}" Foreground="#9EA7AE" FontSize="11" </Grid>
TextWrapping="Wrap" /> </DataTemplate>
</StackPanel> </ItemsControl.ItemTemplate>
</Border> </ItemsControl>
<TextBlock Text="Services:" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
<ItemsControl x:Name="ServicesGrid">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Width="96" Margin="0,0,4,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" TextWrapping="NoWrap" />
<TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="16" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Text="Leaks:" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
<ItemsControl x:Name="LeaksGrid">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,4,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Label}" Foreground="#F4F1E8" FontSize="16" Margin="0,0,10,0" />
<TextBlock Grid.Column="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="16" />
</Grid>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
@@ -169,10 +225,8 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" <TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" TextWrapping="NoWrap" />
TextWrapping="NoWrap" /> <TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="16" />
<TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8"
FontSize="16" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>

View File

@@ -44,7 +44,7 @@ public sealed partial class MainWindow
} }
private sealed record ForecastViewModel(string Message); private sealed record ForecastViewModel(string Message);
private sealed record InspectorItemViewModel(string Label, string Value, string Description); private sealed record InspectorItemViewModel(string Label, string Value);
private sealed record NetworkInspectionViewModel(string Carrier, string State, string Amount, string Intensity, string Integrity); private sealed record NetworkInspectionViewModel(string Carrier, string State, string Amount, string Intensity, string Integrity);
private sealed class EditorToolViewModel(EditorToolCommand command, string label) : INotifyPropertyChanged private sealed class EditorToolViewModel(EditorToolCommand command, string label) : INotifyPropertyChanged
@@ -171,7 +171,6 @@ public sealed partial class MainWindow
m_Level = loaded with { Forecasts = m_Simulation.Forecast(loaded) }; m_Level = loaded with { Forecasts = m_Simulation.Forecast(loaded) };
m_CurrentFile = file; m_CurrentFile = file;
m_SelectedCell = null; m_SelectedCell = null;
m_SelectedReactorId = m_Level.Reactors.FirstOrDefault()?.ReactorId;
RefreshInspector(); RefreshInspector();
LevelCanvas.Invalidate(); LevelCanvas.Invalidate();
} }
@@ -332,7 +331,6 @@ public sealed partial class MainWindow
m_EditorFeedback = result.Reason; m_EditorFeedback = result.Reason;
if (result.Success) if (result.Success)
{ {
SelectReactorFromCell(destination);
RefreshForecasts(); RefreshForecasts();
} }
@@ -388,10 +386,6 @@ public sealed partial class MainWindow
{ {
ApplySelectedTool(position); ApplySelectedTool(position);
} }
else
{
SelectReactorFromCell(position);
}
RefreshInspector(); RefreshInspector();
LevelCanvas.Invalidate(); LevelCanvas.Invalidate();
@@ -408,11 +402,12 @@ public sealed partial class MainWindow
private void UpdateHoverCell(Point point) private void UpdateHoverCell(Point point)
{ {
var nextHover = TryGetGridPosition(point, out var position) ? position : null; var nextHover = TryGetGridPosition(point, out var position) ? position : null;
if (nextHover == m_HoverCell) if (nextHover == HoverCell)
return; return;
m_HoverCell = nextHover; HoverCell = nextHover;
LevelCanvas.Invalidate(); LevelCanvas.Invalidate();
RefreshInspector();
} }
private static bool IsDragPaintTool(EEditorTool tool) private static bool IsDragPaintTool(EEditorTool tool)
@@ -695,7 +690,7 @@ public sealed partial class MainWindow
DrawStatusBadge(drawing, rect, m_EditorFeedback); DrawStatusBadge(drawing, rect, m_EditorFeedback);
} }
if (m_HoverCell is { } hover && m_SelectedTool.Tool != EEditorTool.Cursor) if (HoverCell is { } hover && m_SelectedTool.Tool != EEditorTool.Cursor)
{ {
var rect = layout.CellRect(hover); var rect = layout.CellRect(hover);
var size = Math.Max(26, rect.Width * 0.42); var size = Math.Max(26, rect.Width * 0.42);
@@ -806,31 +801,49 @@ public sealed partial class MainWindow
StatusText.Text = string.IsNullOrWhiteSpace(m_EditorFeedback) StatusText.Text = string.IsNullOrWhiteSpace(m_EditorFeedback)
? $"{m_Level.Global.LevelState}: {m_Level.Global.Status}" ? $"{m_Level.Global.LevelState}: {m_Level.Global.Status}"
: $"{m_Level.Global.LevelState}: {m_EditorFeedback}"; : $"{m_Level.Global.LevelState}: {m_EditorFeedback}";
var doorCount = m_Level.Props.Count(prop => prop.Type == EPropType.Door); InventoryGrid.ItemsSource = new[] {
GlobalGrid.ItemsSource = new[] { new InspectorItemViewModel("Fuel", $"{m_Level.Robot.FuelNeutralizers}"),
new InspectorItemViewModel("Inventory", $"F {m_Level.Robot.FuelNeutralizers} / C {m_Level.Robot.CoolantNeutralizers} / E {m_Level.Robot.ElectricityNeutralizers} / H {m_Level.Robot.HeatShields}", "Remedies carried by the robot."), new InspectorItemViewModel("Coolant", $"{m_Level.Robot.CoolantNeutralizers}"),
new InspectorItemViewModel("Heat Shield", m_Level.Robot.HeatImmunitySteps.ToString(CultureInfo.InvariantCulture), "Remaining protected movement steps."), new InspectorItemViewModel("Electricity", $"{m_Level.Robot.ElectricityNeutralizers}"),
new InspectorItemViewModel("Objects", $"R {m_Level.Reactors.Count} / L {m_Level.Leaks.Count} / D {doorCount}", "Reactors, active leaks, and doors.") new InspectorItemViewModel("Heat", $"{m_Level.Robot.HeatShields} ({m_Level.Robot.HeatImmunitySteps.ToString(CultureInfo.InvariantCulture)} steps)"),
}; };
RequiredGrid.ItemsSource = new[] { RequiredGrid.ItemsSource = new[] {
new InspectorItemViewModel("Fuel", m_Level.RequiredFuelConsumers.ToString(CultureInfo.InvariantCulture), "Producing consumers needed for readiness."), new InspectorItemViewModel("Fuel", m_Level.RequiredFuelConsumers.ToString(CultureInfo.InvariantCulture)),
new InspectorItemViewModel("Coolant", m_Level.RequiredCoolantConsumers.ToString(CultureInfo.InvariantCulture), "Producing consumers needed for readiness."), new InspectorItemViewModel("Coolant", m_Level.RequiredCoolantConsumers.ToString(CultureInfo.InvariantCulture)),
new InspectorItemViewModel("Electric", m_Level.RequiredElectricityConsumers.ToString(CultureInfo.InvariantCulture), "Producing consumers needed for readiness.") new InspectorItemViewModel("Electric", m_Level.RequiredElectricityConsumers.ToString(CultureInfo.InvariantCulture))
}; };
if (m_SelectedCell is { } position && m_Level.InBounds(position)) if (m_SelectedCell is { } position && m_Level.InBounds(position))
{ {
SelectedCellTitleText.Text = SelectedCellTitle(position); SelectedCellText.Text = $"Selected cell: {position.X}, {position.Y}";
CellGrid.ItemsSource = CellInspectionItems(position); TerrainText.Text = m_Level.GetTerrain(position).ToString();
var prop = m_Level.GetProp(position);
PropText.Text = prop.Type != EPropType.None ? $"{prop.Type} {prop.SwitchState}" : "(none)";
ServicesGrid.ItemsSource = new[] {
new InspectorItemViewModel("Fuel", prop.FuelServiceState.ToString()),
new InspectorItemViewModel("Coolant", prop.CoolantServiceState.ToString()),
new InspectorItemViewModel("Electricity", prop.ElectricityServiceState.ToString()),
};
var surface = m_Level.GetSurface(position);
ConsumersGrid.ItemsSource = new[] {
new InspectorItemViewModel("Fuel", surface.FuelBlockTurns.ToString()),
new InspectorItemViewModel("Coolant", surface.CoolantBlockTurns.ToString()),
new InspectorItemViewModel("Electricity", surface.ElectricityBlockTurns.ToString()),
};
LeaksGrid.ItemsSource = m_Level.Leaks.Select(leak => new InspectorItemViewModel(leak.Carrier.ToString(), $"{leak.UndergroundPosition.X}, {leak.UndergroundPosition.Y}"));
SurfaceGrid.ItemsSource = SurfaceInspectionItems(position); SurfaceGrid.ItemsSource = SurfaceInspectionItems(position);
NetworkGrid.ItemsSource = NetworkInspectionItems(position); NetworkGrid.ItemsSource = NetworkInspectionItems(position);
} }
else else
{ {
SelectedCellTitleText.Text = "None"; SelectedCellText.Text = "Selected cell: (none)";
CellGrid.ItemsSource = new[] { new InspectorItemViewModel("Selection", "None", "Select a grid cell to inspect it.") }; TerrainText.Text = string.Empty;
SurfaceGrid.ItemsSource = Array.Empty<InspectorItemViewModel>(); PropText.Text = string.Empty;
NetworkGrid.ItemsSource = Array.Empty<NetworkInspectionViewModel>(); ServicesGrid.ItemsSource = null;
ConsumersGrid.ItemsSource = null;
LeaksGrid.ItemsSource = null;
SurfaceGrid.ItemsSource = null;
NetworkGrid.ItemsSource = null;
} }
ForecastList.ItemsSource = m_Level.Forecasts.Select(forecast => new ForecastViewModel($"{forecast.Turns}: {forecast.Message}")).ToArray(); ForecastList.ItemsSource = m_Level.Forecasts.Select(forecast => new ForecastViewModel($"{forecast.Turns}: {forecast.Message}")).ToArray();
@@ -849,7 +862,6 @@ public sealed partial class MainWindow
break; break;
default: default:
m_Level = LevelEditor.Apply(m_Level, position, m_SelectedTool); m_Level = LevelEditor.Apply(m_Level, position, m_SelectedTool);
SelectReactorFromCell(position);
RefreshForecasts(); RefreshForecasts();
break; break;
} }
@@ -861,27 +873,14 @@ public sealed partial class MainWindow
RefreshForecasts(); RefreshForecasts();
} }
private InspectorItemViewModel[] CellInspectionItems(GridPosition position)
{
var prop = m_Level.GetProp(position);
var surface = m_Level.GetSurface(position);
return [
new("Position", $"{position.X},{position.Y}", "Grid coordinate."),
new("Terrain", m_Level.GetTerrain(position).ToString(), "Static surface cell type."),
new("Prop", $"{prop.Type} {prop.SwitchState}", "Placed surface object and switch state."),
new("Services F/C/E", $"{prop.FuelServiceState}/{prop.CoolantServiceState}/{prop.ElectricityServiceState}", "Consumer service status."),
new("Blocks F/C/E", $"{surface.FuelBlockTurns}/{surface.CoolantBlockTurns}/{surface.ElectricityBlockTurns}", "Temporary remedy entry blocks.")
];
}
private InspectorItemViewModel[] SurfaceInspectionItems(GridPosition position) private InspectorItemViewModel[] SurfaceInspectionItems(GridPosition position)
{ {
var surface = m_Level.GetSurface(position); var surface = m_Level.GetSurface(position);
return [ return [
new("Fuel", Format(surface.Fuel), "Visible fuel hazard."), new("Fuel", Format(surface.Fuel)),
new("Coolant", Format(surface.Coolant), "Visible coolant hazard."), new("Coolant", Format(surface.Coolant)),
new("Electric", Format(surface.Electricity), "Visible electricity hazard."), new("Electric", Format(surface.Electricity)),
new("Heat", Format(surface.Heat), "Visible heat.") new("Heat", Format(surface.Heat))
]; ];
} }
@@ -1264,18 +1263,13 @@ public sealed partial class MainWindow
return command.Carrier == activeCarrier && command.Tool is EEditorTool.Underground or EEditorTool.Flow or EEditorTool.Leak; return command.Carrier == activeCarrier && command.Tool is EEditorTool.Underground or EEditorTool.Flow or EEditorTool.Leak;
} }
private void SelectReactorFromCell(GridPosition position)
{
var prop = m_Level.GetProp(position);
if (prop is { Type: EPropType.ReactorControl, ReactorId: > 0 })
m_SelectedReactorId = prop.ReactorId;
}
private void RefreshForecasts() private void RefreshForecasts()
{ {
m_Level = m_Level with { Forecasts = m_Simulation.Forecast(m_Level) }; m_Level = m_Level with { Forecasts = m_Simulation.Forecast(m_Level) };
} }
public GridPosition? HoverCell { get; private set; }
private const double c_MinZoom = 0.5; private const double c_MinZoom = 0.5;
private const double c_MaxZoom = 4; private const double c_MaxZoom = 4;
private const double c_ZoomStep = 1.15; private const double c_ZoomStep = 1.15;
@@ -1301,7 +1295,6 @@ public sealed partial class MainWindow
private GridPosition? m_DragPreviewDestination; private GridPosition? m_DragPreviewDestination;
private string m_EditorFeedback = string.Empty; private string m_EditorFeedback = string.Empty;
private CanvasBitmap? m_HeatSprite; private CanvasBitmap? m_HeatSprite;
private GridPosition? m_HoverCell;
private GridPosition? m_InvalidDragCell; private GridPosition? m_InvalidDragCell;
private bool m_IsPanning; private bool m_IsPanning;
private GridPosition? m_LastPaintedCell; private GridPosition? m_LastPaintedCell;
@@ -1313,7 +1306,6 @@ public sealed partial class MainWindow
private double m_PanX; private double m_PanX;
private double m_PanY; private double m_PanY;
private GridPosition? m_SelectedCell; private GridPosition? m_SelectedCell;
private int? m_SelectedReactorId = 1;
private EditorToolCommand m_SelectedTool = new() { Tool = EEditorTool.Cursor }; private EditorToolCommand m_SelectedTool = new() { Tool = EEditorTool.Cursor };
private CanvasBitmap? m_TerrainTilemap; private CanvasBitmap? m_TerrainTilemap;
private double m_Zoom = 1; private double m_Zoom = 1;