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

Static waypoint labels #1363

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions src/screenComponents/radarView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,15 @@ void GuiRadarView::drawWaypoints(sf::RenderTarget& window)

for(unsigned int n=0; n<my_spaceship->waypoints.size(); n++)
{
sf::Vector2f screen_position = worldToScreen(my_spaceship->waypoints[n]);
sf::Vector2f screen_position = worldToScreen(my_spaceship->waypoints[n].first);

sf::Sprite object_sprite;
textureManager.setTexture(object_sprite, "waypoint");
object_sprite.setColor(colorConfig.ship_waypoint_background);
object_sprite.setPosition(screen_position - sf::Vector2f(0, 10));
object_sprite.setScale(0.8, 0.8);
window.draw(object_sprite);
drawText(window, sf::FloatRect(screen_position.x, screen_position.y - 10, 0, 0), string(n + 1), ACenter, 18, bold_font, colorConfig.ship_waypoint_text);
drawText(window, sf::FloatRect(screen_position.x, screen_position.y - 10, 0, 0), string(my_spaceship->waypoints[n].second), ACenter, 18, bold_font, colorConfig.ship_waypoint_text);

if (style != Rectangular && sf::length(screen_position - radar_screen_center) > std::min(rect.width, rect.height) * 0.5f)
{
Expand All @@ -435,7 +435,7 @@ void GuiRadarView::drawWaypoints(sf::RenderTarget& window)
object_sprite.setRotation(sf::vector2ToAngle(screen_position - radar_screen_center) - 90);
window.draw(object_sprite);

drawText(window, sf::FloatRect(screen_position.x, screen_position.y, 0, 0), string(n + 1), ACenter, 18, bold_font, colorConfig.ship_waypoint_text);
drawText(window, sf::FloatRect(screen_position.x, screen_position.y, 0, 0), string(my_spaceship->waypoints[n].second), ACenter, 18, bold_font, colorConfig.ship_waypoint_text);
}
}
}
Expand Down Expand Up @@ -736,7 +736,7 @@ void GuiRadarView::drawTargets(sf::RenderTarget& window)

if (my_spaceship && targets->getWaypointIndex() > -1 && targets->getWaypointIndex() < my_spaceship->getWaypointCount())
{
sf::Vector2f object_position_on_screen = worldToScreen(my_spaceship->waypoints[targets->getWaypointIndex()]);
sf::Vector2f object_position_on_screen = worldToScreen(my_spaceship->waypoints[targets->getWaypointIndex()].first);

target_sprite.setPosition(object_position_on_screen - sf::Vector2f(0, 10));
window.draw(target_sprite);
Expand Down
10 changes: 5 additions & 5 deletions src/screenComponents/targetsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ void TargetsContainer::setToClosestTo(sf::Vector2f position, float max_range, ES
{
for(int n=0; n<my_spaceship->getWaypointCount(); n++)
{
if ((my_spaceship->waypoints[n] - position) < max_range)
if ((my_spaceship->waypoints[n].first - position) < max_range)
{
if (!target || sf::length(position - my_spaceship->waypoints[n]) < sf::length(position - target->getPosition()))
if (!target || sf::length(position - my_spaceship->waypoints[n].first) < sf::length(position - target->getPosition()))
{
clear();
waypoint_selection_index = n;
waypoint_selection_position = my_spaceship->waypoints[n];
waypoint_selection_position = my_spaceship->waypoints[n].first;
return;
}
}
Expand All @@ -97,7 +97,7 @@ int TargetsContainer::getWaypointIndex()
waypoint_selection_index = -1;
else if (waypoint_selection_index >= my_spaceship->getWaypointCount())
waypoint_selection_index = -1;
else if (my_spaceship->waypoints[waypoint_selection_index] != waypoint_selection_position)
else if (my_spaceship->waypoints[waypoint_selection_index].first != waypoint_selection_position)
waypoint_selection_index = -1;
return waypoint_selection_index;
}
Expand All @@ -106,5 +106,5 @@ void TargetsContainer::setWaypointIndex(int index)
{
waypoint_selection_index = index;
if (my_spaceship && index >= 0 && index < (int)my_spaceship->waypoints.size())
waypoint_selection_position = my_spaceship->waypoints[index];
waypoint_selection_position = my_spaceship->waypoints[index].first;
}
2 changes: 1 addition & 1 deletion src/screens/crew4/operationsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ OperationScreen::OperationScreen(GuiContainer* owner)
{
// ... and we select something near a waypoint, switch to move
// waypoint mode.
if (sf::length(my_spaceship->waypoints[science->targets.getWaypointIndex()] - position) < 1000.0)
if (sf::length(my_spaceship->waypoints[science->targets.getWaypointIndex()].first - position) < 1000.0)
{
mode = MoveWaypoint;
drag_waypoint_index = science->targets.getWaypointIndex();
Expand Down
2 changes: 1 addition & 1 deletion src/screens/crew6/relayScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RelayScreen::RelayScreen(GuiContainer* owner, bool allow_comms)
[this](sf::Vector2f position) { //down
if (mode == TargetSelection && targets.getWaypointIndex() > -1 && my_spaceship)
{
if (sf::length(my_spaceship->waypoints[targets.getWaypointIndex()] - position) < 1000.0)
if (sf::length(my_spaceship->waypoints[targets.getWaypointIndex()].first - position) < 1000.0)
{
mode = MoveWaypoint;
drag_waypoint_index = targets.getWaypointIndex();
Expand Down
2 changes: 1 addition & 1 deletion src/screens/crew6/scienceScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void ScienceScreen::onDraw(sf::RenderTarget& window)
else if (targets.getWaypointIndex() >= 0)
{
sidebar_pager->hide();
sf::Vector2f position_diff = my_spaceship->waypoints[targets.getWaypointIndex()] - my_spaceship->getPosition();
sf::Vector2f position_diff = my_spaceship->waypoints[targets.getWaypointIndex()].first - my_spaceship->getPosition();
float distance = sf::length(position_diff);
float heading = sf::vector2ToAngle(position_diff) - 270;

Expand Down
21 changes: 18 additions & 3 deletions src/spaceObjects/playerSpaceship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,8 +1539,23 @@ void PlayerSpaceship::onReceiveClientCommand(int32_t client_id, sf::Packet& pack
{
sf::Vector2f position;
packet >> position;
if (waypoints.size() < 9)
waypoints.push_back(position);
if (waypoints.size() < max_waypoints) {
std::bitset<max_waypoints> taken_labels;

for(const auto& waypoint: waypoints) {
taken_labels[waypoint.second-1] = true;
}

uint8_t label = 0;
for(int n=0; n<taken_labels.size(); n++) {
if(taken_labels[n] != true) {
label = n+1;
break;
}
}

waypoints.emplace_back(position, label);
}
}
break;
case CMD_REMOVE_WAYPOINT:
Expand All @@ -1557,7 +1572,7 @@ void PlayerSpaceship::onReceiveClientCommand(int32_t client_id, sf::Packet& pack
sf::Vector2f position;
packet >> index >> position;
if (index >= 0 && index < int(waypoints.size()))
waypoints[index] = position;
waypoints[index].first = position;
}
break;
case CMD_ACTIVATE_SELF_DESTRUCT:
Expand Down
9 changes: 7 additions & 2 deletions src/spaceObjects/playerSpaceship.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "commsScriptInterface.h"
#include "playerInfo.h"
#include <iostream>
#include <bitset>

class ScanProbe;

Expand Down Expand Up @@ -54,6 +55,9 @@ class PlayerSpaceship : public SpaceShip
// Maximum number of self-destruction confirmation codes
constexpr static int max_self_destruct_codes = 3;

// Maximum number of waypoints
constexpr static size_t max_waypoints = 9;

constexpr static int16_t CMD_PLAY_CLIENT_SOUND = 0x0001;

// Content of a line in the ship's log
Expand Down Expand Up @@ -115,10 +119,11 @@ class PlayerSpaceship : public SpaceShip
CommsScriptInterface comms_script_interface; // Server only
// Ship's log container
std::vector<ShipLogEntry> ships_log;

public:
std::vector<CustomShipFunction> custom_functions;

std::vector<sf::Vector2f> waypoints;
std::vector<std::pair<sf::Vector2f,uint8_t>> waypoints;

// Ship functionality
// Capable of scanning a target
Expand Down Expand Up @@ -328,7 +333,7 @@ class PlayerSpaceship : public SpaceShip

// Waypoint functions
int getWaypointCount() { return waypoints.size(); }
sf::Vector2f getWaypoint(int index) { if (index > 0 && index <= int(waypoints.size())) return waypoints[index - 1]; return sf::Vector2f(0, 0); }
sf::Vector2f getWaypoint(int index) { if (index > 0 && index <= int(waypoints.size())) return waypoints[index - 1].first; return sf::Vector2f(0, 0); }

// Ship control code/password setter
void setControlCode(string code) { control_code = code.upper(); }
Expand Down