From 8dd347a9c0230977ae79f615ebe3c313db503931 Mon Sep 17 00:00:00 2001 From: dligr Date: Fri, 22 Nov 2024 21:58:11 +0300 Subject: [PATCH 1/8] Fix extinct species not having preview in auto-evo exporer --- src/auto-evo/AutoEvoExploringTool.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/auto-evo/AutoEvoExploringTool.cs b/src/auto-evo/AutoEvoExploringTool.cs index e3aa484e1ad..786284383a0 100644 --- a/src/auto-evo/AutoEvoExploringTool.cs +++ b/src/auto-evo/AutoEvoExploringTool.cs @@ -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); @@ -891,7 +896,16 @@ private void UpdateSpeciesPreview(Species species) private void EvolutionaryTreeNodeSelected(int generation, uint id) { HistoryListMenuIndexChanged(generation); - UpdateSpeciesPreview(world.SpeciesHistoryList[generation][id]); + + var species = GetActiveSpeciesDataFromGeneration(generation, id); + + if (species == null) + { + GD.PrintErr("Couldn't find active species data to show"); + return; + } + + UpdateSpeciesPreview(species); } private void PatchListMenuIndexChanged(int index) From a4f09566bd7b288b9527c62c9c095feb087e9116 Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 24 Nov 2024 13:58:28 +0300 Subject: [PATCH 2/8] Reset species preview in auto-evo explorer when the species is not found --- src/auto-evo/AutoEvoExploringTool.cs | 20 ++++++++++++------- src/gui_common/PhotographablePreview.cs | 5 +++++ src/gui_common/SpeciesDetailsPanel.cs | 8 ++++++-- .../SpeciesDetailsPanelWithFossilisation.cs | 2 +- src/gui_common/SpeciesPreview.cs | 2 ++ src/microbe_stage/CellHexesPreview.cs | 6 +++++- src/thriveopedia/ThriveopediaManager.cs | 3 +-- 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/auto-evo/AutoEvoExploringTool.cs b/src/auto-evo/AutoEvoExploringTool.cs index 786284383a0..a6ab3694e9a 100644 --- a/src/auto-evo/AutoEvoExploringTool.cs +++ b/src/auto-evo/AutoEvoExploringTool.cs @@ -887,24 +887,30 @@ 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); var species = GetActiveSpeciesDataFromGeneration(generation, id); - if (species == null) - { - GD.PrintErr("Couldn't find active species data to show"); - return; - } - UpdateSpeciesPreview(species); } diff --git a/src/gui_common/PhotographablePreview.cs b/src/gui_common/PhotographablePreview.cs index 70aad5b38ef..9e78de4959b 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 1ea4c22cb44..2a04dc97783 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/SpeciesDetailsPanelWithFossilisation.cs b/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs index 611ee30e51d..edc7dd4729a 100644 --- a/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs +++ b/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs @@ -81,6 +81,6 @@ private void OnFossilisePressed() private void UpdateFossilisationButtonState() { - fossilisationButton.Disabled = previewSpecies is not MicrobeSpecies; + fossilisationButton.Disabled = previewSpecies == null || previewSpecies is not MicrobeSpecies; } } diff --git a/src/gui_common/SpeciesPreview.cs b/src/gui_common/SpeciesPreview.cs index 400b8f6b8b5..be0b9ab6b1f 100644 --- a/src/gui_common/SpeciesPreview.cs +++ b/src/gui_common/SpeciesPreview.cs @@ -19,6 +19,8 @@ public Species? PreviewSpecies if (previewSpecies != null) UpdatePreview(); + else + ResetPreview(); } } diff --git a/src/microbe_stage/CellHexesPreview.cs b/src/microbe_stage/CellHexesPreview.cs index 67486c71abc..e59288d82ad 100644 --- a/src/microbe_stage/CellHexesPreview.cs +++ b/src/microbe_stage/CellHexesPreview.cs @@ -17,7 +17,11 @@ public MicrobeSpecies? PreviewSpecies return; microbeSpecies = value; - UpdatePreview(); + + if (microbeSpecies != null) + UpdatePreview(); + else + ResetPreview(); } } diff --git a/src/thriveopedia/ThriveopediaManager.cs b/src/thriveopedia/ThriveopediaManager.cs index 4e0f07dc504..bbd10dde76b 100644 --- a/src/thriveopedia/ThriveopediaManager.cs +++ b/src/thriveopedia/ThriveopediaManager.cs @@ -54,8 +54,7 @@ public static IThriveopediaPage GetPage(string pageName) { var species = provider.GetActiveSpeciesData(speciesId); - if (species != null) - return species; + return species; } return null; From 481ccfe62ebd0681310a36249070224d61fd247a Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 24 Nov 2024 15:12:18 +0300 Subject: [PATCH 3/8] Improve a check --- src/gui_common/SpeciesDetailsPanelWithFossilisation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs b/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs index edc7dd4729a..efa1e79b060 100644 --- a/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs +++ b/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs @@ -81,6 +81,6 @@ private void OnFossilisePressed() private void UpdateFossilisationButtonState() { - fossilisationButton.Disabled = previewSpecies == null || previewSpecies is not MicrobeSpecies; + fossilisationButton.Disabled = previewSpecies is null or not MicrobeSpecies; } } From 53dc81ef688a5a8a8c0a802fc27c9e9ec06f006c Mon Sep 17 00:00:00 2001 From: dligr Date: Tue, 26 Nov 2024 19:50:45 +0300 Subject: [PATCH 4/8] Remove null forgiving operator --- src/gui_common/PhotographablePreview.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui_common/PhotographablePreview.cs b/src/gui_common/PhotographablePreview.cs index 9e78de4959b..e08f12ddfd8 100644 --- a/src/gui_common/PhotographablePreview.cs +++ b/src/gui_common/PhotographablePreview.cs @@ -103,7 +103,7 @@ protected void UpdatePreview() protected void ResetPreview() { - textureRect.Texture = null!; + textureRect.Texture = null; } /// From ba30959a3d9bf1549f3f812ee4d0aa0274e4f320 Mon Sep 17 00:00:00 2001 From: dligr Date: Tue, 26 Nov 2024 19:51:00 +0300 Subject: [PATCH 5/8] Fix braces style --- src/gui_common/SpeciesPreview.cs | 4 ++++ src/microbe_stage/CellHexesPreview.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/gui_common/SpeciesPreview.cs b/src/gui_common/SpeciesPreview.cs index be0b9ab6b1f..b725a9991e4 100644 --- a/src/gui_common/SpeciesPreview.cs +++ b/src/gui_common/SpeciesPreview.cs @@ -18,9 +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 e59288d82ad..d0dd8231843 100644 --- a/src/microbe_stage/CellHexesPreview.cs +++ b/src/microbe_stage/CellHexesPreview.cs @@ -19,9 +19,13 @@ public MicrobeSpecies? PreviewSpecies microbeSpecies = value; if (microbeSpecies != null) + { UpdatePreview(); + } else + { ResetPreview(); + } } } From 1bb163de8f5dfa0514e30f52dd06139450ad2c98 Mon Sep 17 00:00:00 2001 From: dligr Date: Tue, 26 Nov 2024 19:52:09 +0300 Subject: [PATCH 6/8] Fix ThriveopediaManager's return logic --- src/thriveopedia/ThriveopediaManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/thriveopedia/ThriveopediaManager.cs b/src/thriveopedia/ThriveopediaManager.cs index bbd10dde76b..4e0f07dc504 100644 --- a/src/thriveopedia/ThriveopediaManager.cs +++ b/src/thriveopedia/ThriveopediaManager.cs @@ -54,7 +54,8 @@ public static IThriveopediaPage GetPage(string pageName) { var species = provider.GetActiveSpeciesData(speciesId); - return species; + if (species != null) + return species; } return null; From c69419a206d0a2503cd7aab483c1c42afd41b8bd Mon Sep 17 00:00:00 2001 From: dligr Date: Tue, 26 Nov 2024 19:55:02 +0300 Subject: [PATCH 7/8] Fix a type check --- src/gui_common/SpeciesDetailsPanelWithFossilisation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs b/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs index efa1e79b060..611ee30e51d 100644 --- a/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs +++ b/src/gui_common/SpeciesDetailsPanelWithFossilisation.cs @@ -81,6 +81,6 @@ private void OnFossilisePressed() private void UpdateFossilisationButtonState() { - fossilisationButton.Disabled = previewSpecies is null or not MicrobeSpecies; + fossilisationButton.Disabled = previewSpecies is not MicrobeSpecies; } } From c2ac73d0398688dbceb65ba5a630861132a95c2c Mon Sep 17 00:00:00 2001 From: dligr Date: Tue, 26 Nov 2024 19:55:55 +0300 Subject: [PATCH 8/8] Rename `GetActiveSpeciesDataFromGeneration` and add a clarification comment --- src/auto-evo/AutoEvoExploringTool.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/auto-evo/AutoEvoExploringTool.cs b/src/auto-evo/AutoEvoExploringTool.cs index a6ab3694e9a..b233a9cd8e8 100644 --- a/src/auto-evo/AutoEvoExploringTool.cs +++ b/src/auto-evo/AutoEvoExploringTool.cs @@ -386,10 +386,13 @@ public void AskExit() public Species? GetActiveSpeciesData(uint speciesId) { - return GetActiveSpeciesDataFromGeneration(generationDisplayed, speciesId); + return GetSpeciesDataFromGeneration(generationDisplayed, speciesId); } - public Species? GetActiveSpeciesDataFromGeneration(int generation, uint 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; @@ -909,7 +912,7 @@ private void EvolutionaryTreeNodeSelected(int generation, uint id) { HistoryListMenuIndexChanged(generation); - var species = GetActiveSpeciesDataFromGeneration(generation, id); + var species = GetSpeciesDataFromGeneration(generation, id); UpdateSpeciesPreview(species); }