Skip to content

Commit

Permalink
fix(ui-bug): Fix mission waypoint/stopover/mark pointers disappearing (
Browse files Browse the repository at this point in the history
  • Loading branch information
warp-core authored Dec 14, 2024
1 parent 8ebe1e4 commit ce007a3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
62 changes: 45 additions & 17 deletions source/MapPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -1463,39 +1486,44 @@ 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<bool, bool> 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<bool, bool> 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)
{
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);
}

Expand Down
2 changes: 1 addition & 1 deletion source/MapPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ce007a3

Please sign in to comment.