diff --git a/src/auto-evo/AutoEvoExploringTool.cs b/src/auto-evo/AutoEvoExploringTool.cs index e3aa484e1a..b233a9cd8e 100644 --- a/src/auto-evo/AutoEvoExploringTool.cs +++ b/src/auto-evo/AutoEvoExploringTool.cs @@ -385,10 +385,18 @@ public void AskExit() } public Species? GetActiveSpeciesData(uint speciesId) + { + return GetSpeciesDataFromGeneration(generationDisplayed, speciesId); + } + + /// + /// Returns a record of the species from the given generation or earlier + /// + public Species? GetSpeciesDataFromGeneration(int generation, uint speciesId) { var gameWorld = world.GameProperties.GameWorld; - for (int i = generationDisplayed; i >= 0; --i) + for (int i = generation; i >= 0; --i) { gameWorld.GenerationHistory[i].AllSpeciesData .TryGetValue(speciesId, out var speciesRecord); @@ -882,16 +890,31 @@ private void SpeciesListMenuIndexChanged(int index) UpdateSpeciesPreview(species); } - private void UpdateSpeciesPreview(Species species) + private void UpdateSpeciesPreview(Species? species) { + if (species == null) + { + ResetSpeciesPreview(); + return; + } + speciesListMenu.Text = species.FormattedName; speciesDetailsPanelWithFossilisation.PreviewSpecies = species; } + private void ResetSpeciesPreview() + { + speciesListMenu.Text = string.Empty; + speciesDetailsPanelWithFossilisation.PreviewSpecies = null; + } + private void EvolutionaryTreeNodeSelected(int generation, uint id) { HistoryListMenuIndexChanged(generation); - UpdateSpeciesPreview(world.SpeciesHistoryList[generation][id]); + + var species = GetSpeciesDataFromGeneration(generation, id); + + UpdateSpeciesPreview(species); } private void PatchListMenuIndexChanged(int index) diff --git a/src/gui_common/PhotographablePreview.cs b/src/gui_common/PhotographablePreview.cs index 70aad5b38e..e08f12ddfd 100644 --- a/src/gui_common/PhotographablePreview.cs +++ b/src/gui_common/PhotographablePreview.cs @@ -101,6 +101,11 @@ protected void UpdatePreview() task = SetupImageTask(); } + protected void ResetPreview() + { + textureRect.Texture = null; + } + /// /// Return an ImageTask ready for PhotoStudio to process /// diff --git a/src/gui_common/SpeciesDetailsPanel.cs b/src/gui_common/SpeciesDetailsPanel.cs index 1ea4c22cb4..2a04dc9778 100644 --- a/src/gui_common/SpeciesDetailsPanel.cs +++ b/src/gui_common/SpeciesDetailsPanel.cs @@ -32,7 +32,7 @@ public Species? PreviewSpecies previewSpecies = value; - if (previewSpecies != null && speciesDetailsLabel != null) + if (speciesDetailsLabel != null) UpdateSpeciesPreview(); } } @@ -83,7 +83,11 @@ private void UpdateSpeciesPreview() { speciesPreview.PreviewSpecies = PreviewSpecies; - if (PreviewSpecies is MicrobeSpecies microbeSpecies) + if (PreviewSpecies == null) + { + hexesPreview.PreviewSpecies = null; + } + else if (PreviewSpecies is MicrobeSpecies microbeSpecies) { hexesPreview.PreviewSpecies = microbeSpecies; } diff --git a/src/gui_common/SpeciesPreview.cs b/src/gui_common/SpeciesPreview.cs index 400b8f6b8b..b725a9991e 100644 --- a/src/gui_common/SpeciesPreview.cs +++ b/src/gui_common/SpeciesPreview.cs @@ -18,7 +18,13 @@ public Species? PreviewSpecies previewSpecies = value; if (previewSpecies != null) + { UpdatePreview(); + } + else + { + ResetPreview(); + } } } diff --git a/src/microbe_stage/CellHexesPreview.cs b/src/microbe_stage/CellHexesPreview.cs index 67486c71ab..d0dd823184 100644 --- a/src/microbe_stage/CellHexesPreview.cs +++ b/src/microbe_stage/CellHexesPreview.cs @@ -17,7 +17,15 @@ public MicrobeSpecies? PreviewSpecies return; microbeSpecies = value; - UpdatePreview(); + + if (microbeSpecies != null) + { + UpdatePreview(); + } + else + { + ResetPreview(); + } } }