Skip to content

Commit 8ac748f

Browse files
tibetirokawarp-coreRisingLeaf
authored
fix(ui): Don't display undefined outfits and categories (endless-sky#10426)
Co-authored-by: warp-core <warp-core@users.noreply.github.com> Co-authored-by: Rising Leaf <control@thvk.net>
1 parent 4f018d5 commit 8ac748f

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

source/MainPanel.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ void MainPanel::ShowScanDialog(const ShipEvent &event)
366366
for(const auto &it : target->Outfits())
367367
{
368368
string outfitNameForDisplay = (it.second == 1 ? it.first->DisplayName() : it.first->PluralName());
369-
outfitsByCategory[it.first->Category()].emplace(std::move(outfitNameForDisplay), it.second);
369+
if(it.first->IsDefined() && !it.first->Category().empty() && !outfitNameForDisplay.empty())
370+
outfitsByCategory[it.first->Category()].emplace(std::move(outfitNameForDisplay), it.second);
370371
}
371372
for(const auto &it : outfitsByCategory)
372373
{

source/ShipInfoDisplay.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ void ShipInfoDisplay::UpdateOutfits(const Ship &ship, const PlayerInfo &player,
434434

435435
map<string, map<string, int>> listing;
436436
for(const auto &it : ship.Outfits())
437-
listing[it.first->Category()][it.first->DisplayName()] += it.second;
437+
if(it.first->IsDefined() && !it.first->Category().empty() && !it.first->DisplayName().empty())
438+
listing[it.first->Category()][it.first->DisplayName()] += it.second;
438439

439440
for(const auto &cit : listing)
440441
{

source/ShipInfoPanel.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ this program. If not, see <https://www.gnu.org/licenses/>.
4444
#include "UI.h"
4545

4646
#include <algorithm>
47+
#include <ranges>
4748

4849
using namespace std;
4950

@@ -391,10 +392,18 @@ void ShipInfoPanel::DrawOutfits(const Rectangle &bounds, Rectangle &cargoBounds)
391392
for(const auto &cat : GameData::GetCategory(CategoryType::OUTFIT))
392393
{
393394
const string &category = cat.Name();
395+
if(category.empty())
396+
continue;
394397
auto it = outfits.find(category);
395398
if(it == outfits.end())
396399
continue;
397400

401+
auto validOutfits = std::ranges::filter_view(it->second,
402+
[](const Outfit *outfit){ return outfit->IsDefined() && !outfit->DisplayName().empty(); });
403+
404+
if(validOutfits.empty())
405+
continue;
406+
398407
// Skip to the next column if there is no space for this category label
399408
// plus at least one outfit.
400409
if(table.GetRowBounds().Bottom() + 40. > bounds.Bottom())
@@ -408,7 +417,7 @@ void ShipInfoPanel::DrawOutfits(const Rectangle &bounds, Rectangle &cargoBounds)
408417
// Draw the category label.
409418
table.Draw(category, bright);
410419
table.Advance();
411-
for(const Outfit *outfit : it->second)
420+
for(const Outfit *outfit : validOutfits)
412421
{
413422
// Check if we've gone below the bottom of the bounds.
414423
if(table.GetRowBounds().Bottom() > bounds.Bottom())

0 commit comments

Comments
 (0)