Add editor simulation playback
This commit is contained in:
@@ -15,7 +15,8 @@
|
|||||||
<AppBarButton Icon="OpenFile" Label="Open" Click="Open_Click" />
|
<AppBarButton Icon="OpenFile" Label="Open" Click="Open_Click" />
|
||||||
<AppBarButton Icon="Save" Label="Save" Click="Save_Click" />
|
<AppBarButton Icon="Save" Label="Save" Click="Save_Click" />
|
||||||
<AppBarSeparator />
|
<AppBarSeparator />
|
||||||
<AppBarButton Icon="Play" Label="End Turn" Click="EndTurn_Click" />
|
<AppBarButton x:Name="PlayPauseButton" Icon="Play" Label="Play" Click="PlayPause_Click" />
|
||||||
|
<AppBarButton Icon="Forward" Label="End Turn" Click="EndTurn_Click" />
|
||||||
<AppBarButton Label="Interact" Click="Interact_Click" />
|
<AppBarButton Label="Interact" Click="Interact_Click" />
|
||||||
<AppBarButton Label="Heat Shield" Click="HeatShield_Click" />
|
<AppBarButton Label="Heat Shield" Click="HeatShield_Click" />
|
||||||
<AppBarButton Icon="Accept" Label="Activate" Click="Activate_Click" />
|
<AppBarButton Icon="Accept" Label="Activate" Click="Activate_Click" />
|
||||||
|
|||||||
@@ -81,10 +81,13 @@ public sealed partial class MainWindow
|
|||||||
|
|
||||||
m_Level = BuildStarterLevel();
|
m_Level = BuildStarterLevel();
|
||||||
m_EditorTools = BuildEditorTools();
|
m_EditorTools = BuildEditorTools();
|
||||||
|
m_SimulationTimer.Interval = TimeSpan.FromSeconds(1.0 / c_SimulationStepsPerSecond);
|
||||||
|
m_SimulationTimer.Tick += SimulationTimer_Tick;
|
||||||
LayerPicker.ItemsSource = Enum.GetValues<EEditorLayer>();
|
LayerPicker.ItemsSource = Enum.GetValues<EEditorLayer>();
|
||||||
LayerPicker.SelectedItem = EEditorLayer.Surface;
|
LayerPicker.SelectedItem = EEditorLayer.Surface;
|
||||||
RefreshToolPicker();
|
RefreshToolPicker();
|
||||||
RefreshInspector();
|
RefreshInspector();
|
||||||
|
UpdatePlayPauseButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LevelCanvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
|
private void LevelCanvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
|
||||||
@@ -147,6 +150,7 @@ public sealed partial class MainWindow
|
|||||||
|
|
||||||
private void New_Click(object sender, RoutedEventArgs e)
|
private void New_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
StopSimulationTimer();
|
||||||
m_Level = BuildStarterLevel();
|
m_Level = BuildStarterLevel();
|
||||||
m_CurrentFile = null;
|
m_CurrentFile = null;
|
||||||
m_SelectedCell = null;
|
m_SelectedCell = null;
|
||||||
@@ -166,6 +170,7 @@ public sealed partial class MainWindow
|
|||||||
if (file is null)
|
if (file is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
StopSimulationTimer();
|
||||||
var json = await FileIO.ReadTextAsync(file);
|
var json = await FileIO.ReadTextAsync(file);
|
||||||
var loaded = LevelSerializer.Deserialize(json);
|
var loaded = LevelSerializer.Deserialize(json);
|
||||||
m_Level = loaded with { Forecasts = m_Simulation.Forecast(loaded) };
|
m_Level = loaded with { Forecasts = m_Simulation.Forecast(loaded) };
|
||||||
@@ -213,6 +218,43 @@ public sealed partial class MainWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void EndTurn_Click(object sender, RoutedEventArgs e)
|
private void EndTurn_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
RunSimulationStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlayPause_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (m_SimulationTimer.IsEnabled)
|
||||||
|
StopSimulationTimer();
|
||||||
|
else
|
||||||
|
StartSimulationTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SimulationTimer_Tick(object? sender, object e)
|
||||||
|
{
|
||||||
|
RunSimulationStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartSimulationTimer()
|
||||||
|
{
|
||||||
|
m_SimulationTimer.Start();
|
||||||
|
UpdatePlayPauseButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopSimulationTimer()
|
||||||
|
{
|
||||||
|
m_SimulationTimer.Stop();
|
||||||
|
UpdatePlayPauseButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdatePlayPauseButton()
|
||||||
|
{
|
||||||
|
var isPlaying = m_SimulationTimer.IsEnabled;
|
||||||
|
PlayPauseButton.Icon = new SymbolIcon(isPlaying ? Symbol.Pause : Symbol.Play);
|
||||||
|
PlayPauseButton.Label = isPlaying ? "Pause" : "Play";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RunSimulationStep()
|
||||||
{
|
{
|
||||||
m_Level = m_Simulation.EndTurn(m_Level);
|
m_Level = m_Simulation.EndTurn(m_Level);
|
||||||
RefreshInspector();
|
RefreshInspector();
|
||||||
@@ -1313,6 +1355,7 @@ public sealed partial class MainWindow
|
|||||||
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;
|
||||||
private const double c_ClickPixelThreshold = 10;
|
private const double c_ClickPixelThreshold = 10;
|
||||||
|
private const int c_SimulationStepsPerSecond = 2;
|
||||||
private const int c_TilemapTileSize = 512;
|
private const int c_TilemapTileSize = 512;
|
||||||
private const int c_TopLeftCorner = 1;
|
private const int c_TopLeftCorner = 1;
|
||||||
private const int c_TopRightCorner = 2;
|
private const int c_TopRightCorner = 2;
|
||||||
@@ -1326,6 +1369,7 @@ public sealed partial class MainWindow
|
|||||||
private readonly EditorImageRegistry m_Images = new();
|
private readonly EditorImageRegistry m_Images = new();
|
||||||
|
|
||||||
private readonly SimulationEngine m_Simulation = new();
|
private readonly SimulationEngine m_Simulation = new();
|
||||||
|
private readonly DispatcherTimer m_SimulationTimer = new();
|
||||||
private EEditorLayer m_ActiveLayer = EEditorLayer.Surface;
|
private EEditorLayer m_ActiveLayer = EEditorLayer.Surface;
|
||||||
private StorageFile? m_CurrentFile;
|
private StorageFile? m_CurrentFile;
|
||||||
private GridPosition? m_CursorDragStartCell;
|
private GridPosition? m_CursorDragStartCell;
|
||||||
|
|||||||
Reference in New Issue
Block a user