From ce007a392344d292663a214b5919609db358dd04 Mon Sep 17 00:00:00 2001 From: warp-core Date: Sat, 14 Dec 2024 21:22:58 +0000 Subject: [PATCH] fix(ui-bug): Fix mission waypoint/stopover/mark pointers disappearing (#10841) --- source/MapPanel.cpp | 62 ++++++++++++++++++++++++++++++++------------- source/MapPanel.h | 2 +- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/source/MapPanel.cpp b/source/MapPanel.cpp index 2cd64594faa8..19f4dff68965 100644 --- a/source/MapPanel.cpp +++ b/source/MapPanel.cpp @@ -69,15 +69,37 @@ namespace { const unsigned MAX_MISSION_POINTERS_DRAWN = 12; const double MISSION_POINTERS_ANGLE_DELTA = 30.; - // Struct to track per system how many pointers are drawn and still + // Class to track per system how many pointers are drawn and still // need to be drawn. - struct PointerDrawCount { + class PointerDrawCount { + public: + // Calculate and check the most number of pointer positions that should be available for active missions. + // This can be up to half the maximum number of pointers that can be drawn. + void Reserve(); + + unsigned MaximumActive() const; + + public: // Amount of systems already drawn. unsigned drawn = 0; unsigned available = 0; unsigned unavailable = 0; + + private: + unsigned maximumActive = MAX_MISSION_POINTERS_DRAWN; }; + void PointerDrawCount::Reserve() + { + maximumActive = max(MAX_MISSION_POINTERS_DRAWN / 2, MAX_MISSION_POINTERS_DRAWN - (available + unavailable)); + } + + unsigned PointerDrawCount::MaximumActive() const + { + return maximumActive; + } + + // Struct for storing the ends of wormhole links and their colors. struct WormholeArrow { WormholeArrow() = default; @@ -1454,6 +1476,7 @@ void MapPanel::DrawMissions() else ++it.unavailable; } + for_each(missionCount.begin(), missionCount.end(), [](auto &it) { it.second.Reserve(); }); for(const Mission &mission : player.Missions()) { if(!mission.IsVisible()) @@ -1463,22 +1486,25 @@ void MapPanel::DrawMissions() if(!system) continue; - // Reserve a maximum of half of the slots for available missions. - auto &&it = missionCount[system]; - int reserved = min(MAX_MISSION_POINTERS_DRAWN / 2, it.available + it.unavailable); - if(it.drawn >= MAX_MISSION_POINTERS_DRAWN - reserved) - continue; - - pair blink = BlinkMissionIndicator(player, mission, step); - bool isSatisfied = IsSatisfied(player, mission) && blink.second; - DrawPointer(system, it.drawn, blink.first ? black : isSatisfied ? currentColor : blockedColor, isSatisfied); + auto &it = missionCount[system]; + if(it.drawn < it.MaximumActive()) + { + pair blink = BlinkMissionIndicator(player, mission, step); + bool isSatisfied = IsSatisfied(player, mission) && blink.second; + const Color &color = blink.first ? black : isSatisfied ? currentColor : blockedColor; + DrawPointer(system, it.drawn, it.MaximumActive(), color, isSatisfied); + } for(const System *waypoint : mission.Waypoints()) - DrawPointer(waypoint, missionCount[waypoint].drawn, waypointColor); + DrawPointer(waypoint, missionCount[waypoint].drawn, missionCount[waypoint].MaximumActive(), waypointColor); for(const Planet *stopover : mission.Stopovers()) - DrawPointer(stopover->GetSystem(), missionCount[stopover->GetSystem()].drawn, waypointColor); + { + const System *stopoverSystem = stopover->GetSystem(); + auto &counts = missionCount[stopoverSystem]; + DrawPointer(stopoverSystem, counts.drawn, counts.MaximumActive(), waypointColor); + } for(const System *mark : mission.MarkedSystems()) - DrawPointer(mark, missionCount[mark].drawn, waypointColor); + DrawPointer(mark, missionCount[mark].drawn, missionCount[mark].MaximumActive(), waypointColor); } // Draw the available and unavailable jobs. for(auto &&it : missionCount) @@ -1486,16 +1512,18 @@ void MapPanel::DrawMissions() const auto &system = it.first; auto &&counters = it.second; for(unsigned i = 0; i < counters.available; ++i) - DrawPointer(system, counters.drawn, availableColor); + DrawPointer(system, counters.drawn, MAX_MISSION_POINTERS_DRAWN, availableColor); for(unsigned i = 0; i < counters.unavailable; ++i) - DrawPointer(system, counters.drawn, unavailableColor); + DrawPointer(system, counters.drawn, MAX_MISSION_POINTERS_DRAWN, unavailableColor); } } -void MapPanel::DrawPointer(const System *system, unsigned &systemCount, const Color &color, bool bigger) +void MapPanel::DrawPointer(const System *system, unsigned &systemCount, unsigned max, const Color &color, bool bigger) { + if(systemCount >= max) + return; DrawPointer(Zoom() * (system->Position() + center), systemCount, color, true, bigger); } diff --git a/source/MapPanel.h b/source/MapPanel.h index b28d04964d4b..20d659880aa6 100644 --- a/source/MapPanel.h +++ b/source/MapPanel.h @@ -176,7 +176,7 @@ class MapPanel : public Panel { void DrawSystems(); void DrawNames(); void DrawMissions(); - void DrawPointer(const System *system, unsigned &systemCount, const Color &color, bool bigger = false); + void DrawPointer(const System *system, unsigned &systemCount, unsigned max, const Color &color, bool bigger = false); static void DrawPointer(Point position, unsigned &systemCount, const Color &color, bool drawBack = true, bool bigger = false);