Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extinct species not having preview in auto-evo exporer #5701

Merged
merged 8 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/auto-evo/AutoEvoExploringTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,15 @@ public void AskExit()
}

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

public Species? GetActiveSpeciesDataFromGeneration(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 +887,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 = GetActiveSpeciesDataFromGeneration(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
2 changes: 1 addition & 1 deletion src/gui_common/SpeciesDetailsPanelWithFossilisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ private void OnFossilisePressed()

private void UpdateFossilisationButtonState()
{
fossilisationButton.Disabled = previewSpecies is not MicrobeSpecies;
fossilisationButton.Disabled = previewSpecies is null or not MicrobeSpecies;
}
}
2 changes: 2 additions & 0 deletions src/gui_common/SpeciesPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public Species? PreviewSpecies

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

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

microbeSpecies = value;
UpdatePreview();

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

Expand Down
3 changes: 1 addition & 2 deletions src/thriveopedia/ThriveopediaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public static IThriveopediaPage GetPage(string pageName)
{
var species = provider.GetActiveSpeciesData(speciesId);

if (species != null)
return species;
return species;
}

return null;
Expand Down