Skip to content

Commit

Permalink
Fixed extinct species not having a preview in auto-evo explorer (#5701)
Browse files Browse the repository at this point in the history
* Fix extinct species not having preview in auto-evo exporer

* Reset species preview in auto-evo explorer when the species is not found

* Improve a check

* Remove null forgiving operator

* Fix braces style

* Fix ThriveopediaManager's return logic

* Fix a type check

* Rename `GetActiveSpeciesDataFromGeneration` and add a clarification comment
  • Loading branch information
dligr authored Nov 26, 2024
1 parent 28f1087 commit b6b3f54
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
29 changes: 26 additions & 3 deletions src/auto-evo/AutoEvoExploringTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,18 @@ public void AskExit()
}

public Species? GetActiveSpeciesData(uint speciesId)
{
return GetSpeciesDataFromGeneration(generationDisplayed, speciesId);
}

/// <summary>
/// Returns a record of the species from the given generation or earlier
/// </summary>
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);
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/gui_common/PhotographablePreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ protected void UpdatePreview()
task = SetupImageTask();
}

protected void ResetPreview()
{
textureRect.Texture = null;
}

/// <summary>
/// Return an ImageTask ready for PhotoStudio to process
/// </summary>
Expand Down
8 changes: 6 additions & 2 deletions src/gui_common/SpeciesDetailsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Species? PreviewSpecies

previewSpecies = value;

if (previewSpecies != null && speciesDetailsLabel != null)
if (speciesDetailsLabel != null)
UpdateSpeciesPreview();
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/gui_common/SpeciesPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public Species? PreviewSpecies
previewSpecies = value;

if (previewSpecies != null)
{
UpdatePreview();
}
else
{
ResetPreview();
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/microbe_stage/CellHexesPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ public MicrobeSpecies? PreviewSpecies
return;

microbeSpecies = value;
UpdatePreview();

if (microbeSpecies != null)
{
UpdatePreview();
}
else
{
ResetPreview();
}
}
}

Expand Down

0 comments on commit b6b3f54

Please sign in to comment.