Skip to content

Commit

Permalink
feat(ui): "Fancy" cloaked ship outlines (endless-sky#9642)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koranir authored May 12, 2024
1 parent 4975f57 commit bc058c0
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 31 deletions.
2 changes: 2 additions & 0 deletions data/_ui/interfaces.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ color "escort split fuel" .35 .31 .215 0.

color "flagship highlight" .5 .8 .2 0.

color "cloak highlight" .45 0. 0. .65

color "drag select" .2 1. 0. 0.

# Colors used for drawing mission or job pointers on the map,
Expand Down
3 changes: 3 additions & 0 deletions data/_ui/tooltips.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,9 @@ tip "Ship outlines in shops"
tip "Ship outlines in HUD"
`Controls the display of your flagship and target ship icons in the HUD. When fancy, applies a sobel filter to the sprites. (This can result in high GPU load for some ships on very old or low performance computers.) When fast, just uses the ship's sprite.`

tip "Cloaked ship outlines"
`Controls the display of cloaked escorts. When fancy, causes the ship to become transparent and applies a red outline. When fast, simply shifts the ship to being red.`

tip "Show status overlays"
`Display status overlays over top of all ships when in flight. Status overlays display a ship's shields and hull. If the damaged option is chosen, overlays only appear on ships that have taken damage.`

Expand Down
4 changes: 2 additions & 2 deletions source/DrawList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ bool DrawList::AddUnblurred(const Body &body)



bool DrawList::AddSwizzled(const Body &body, int swizzle)
bool DrawList::AddSwizzled(const Body &body, int swizzle, double cloak)
{
Point position = body.Position() - center;
Point blur = body.Velocity() - centerVelocity;
if(Cull(body, position, blur))
return false;

Push(body, position, blur, 0., swizzle);
Push(body, position, blur, cloak, swizzle);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion source/DrawList.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DrawList {
// Add an object that should not be drawn with motion blur.
bool AddUnblurred(const Body &body);
// Add an object using a specific swizzle (rather than its own).
bool AddSwizzled(const Body &body, int swizzle);
bool AddSwizzled(const Body &body, int swizzle, double cloak = 0.);

// Draw all the items in this list.
void Draw() const;
Expand Down
59 changes: 35 additions & 24 deletions source/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,24 @@ void Engine::Step(bool isActive)
}
}

// Draw a highlight to distinguish the flagship from other ships.
outlines.clear();
const Color &cloakColor = *GameData::Colors().Get("cloak highlight");
if(Preferences::Has("Cloaked ship outlines"))
for(const auto &ship : player.Ships())
{
if(ship->IsParked() || ship->GetSystem() != player.GetSystem() || ship->Cloaking() == 0.)
continue;

outlines.emplace_back(ship->GetSprite(), (ship->Position() - center) * zoom, ship->Unit() * zoom,
ship->GetFrame(), Color::Multiply(ship->Cloaking(), cloakColor));
}

// Add the flagship outline last to distinguish the flagship from other ships.
if(flagship && !flagship->IsDestroyed() && Preferences::Has("Highlight player's flagship"))
{
highlightSprite = flagship->GetSprite();
highlightUnit = flagship->Unit() * zoom;
highlightFrame = flagship->GetFrame();
outlines.emplace_back(flagship->GetSprite(), (flagship->Position() - center) * zoom, flagship->Unit() * zoom,
flagship->GetFrame(), *GameData::Colors().Get("flagship highlight"));
}
else
highlightSprite = nullptr;

// Any of the player's ships that are in system are assumed to have
// landed along with the player.
Expand Down Expand Up @@ -1061,13 +1070,10 @@ void Engine::Draw() const
for(const AlertLabel &label : missileLabels)
label.Draw();

// Draw the flagship highlight, if any.
if(highlightSprite)
for(const auto &outline : outlines)
{
Point size(highlightSprite->Width(), highlightSprite->Height());
const Color &color = *colors.Get("flagship highlight");
// The flagship is always in the dead center of the screen.
OutlineShader::Draw(highlightSprite, Point(), size, color, highlightUnit, highlightFrame);
Point size(outline.sprite->Width(), outline.sprite->Height());
OutlineShader::Draw(outline.sprite, outline.position, size, outline.color, outline.unit, outline.frame);
}

if(flash)
Expand Down Expand Up @@ -2508,13 +2514,14 @@ void Engine::DrawShipSprites(const Ship &ship)
bool hasFighters = ship.PositionFighters();
double cloak = ship.Cloaking();
bool drawCloaked = (cloak && ship.IsYours());
bool fancyCloak = Preferences::Has("Cloaked ship outlines");
auto &itemsToDraw = draw[currentCalcBuffer];
auto drawObject = [&itemsToDraw, cloak, drawCloaked](const Body &body) -> void
auto drawObject = [&itemsToDraw, cloak, drawCloaked, fancyCloak](const Body &body) -> void
{
// Draw cloaked/cloaking sprites swizzled red, and overlay this solid
// sprite with an increasingly transparent "regular" sprite.
// Draw cloaked/cloaking sprites swizzled red or transparent (depending on whether we are using fancy
// cloaking effects), and overlay this solid sprite with an increasingly transparent "regular" sprite.
if(drawCloaked)
itemsToDraw.AddSwizzled(body, 27);
itemsToDraw.AddSwizzled(body, fancyCloak ? 9 : 27, fancyCloak ? 0.5 : 0.25);
itemsToDraw.Add(body, cloak);
};

Expand Down Expand Up @@ -2681,27 +2688,27 @@ void Engine::CreateStatusOverlays()

for(const auto &it : ships)
{
if(!it->GetGovernment() || it->GetSystem() != currentSystem ||
it->IsCloaked())
if(!it->GetGovernment() || it->GetSystem() != currentSystem || (!it->IsYours() && it->Cloaking() == 1.))
continue;
// Don't show status for dead ships.
if(it->IsDestroyed())
continue;

if(it == flagship)
EmplaceStatusOverlay(it, overlaySettings[Preferences::OverlayType::FLAGSHIP], 0);
EmplaceStatusOverlay(it, overlaySettings[Preferences::OverlayType::FLAGSHIP], 0, it->Cloaking());
else if(it->GetGovernment()->IsEnemy())
EmplaceStatusOverlay(it, overlaySettings[Preferences::OverlayType::ENEMY], 2);
EmplaceStatusOverlay(it, overlaySettings[Preferences::OverlayType::ENEMY], 2, it->Cloaking());
else if(it->IsYours() || it->GetPersonality().IsEscort())
EmplaceStatusOverlay(it, overlaySettings[Preferences::OverlayType::ESCORT], 1);
EmplaceStatusOverlay(it, overlaySettings[Preferences::OverlayType::ESCORT], 1, it->Cloaking());
else
EmplaceStatusOverlay(it, overlaySettings[Preferences::OverlayType::NEUTRAL], 3);
EmplaceStatusOverlay(it, overlaySettings[Preferences::OverlayType::NEUTRAL], 3, it->Cloaking());
}
}



void Engine::EmplaceStatusOverlay(const shared_ptr<Ship> &it, Preferences::OverlayState overlaySetting, int type)
void Engine::EmplaceStatusOverlay(const shared_ptr<Ship> &it, Preferences::OverlayState overlaySetting,
int type, double cloak)
{
if(overlaySetting == Preferences::OverlayState::OFF)
return;
Expand All @@ -2724,6 +2731,10 @@ void Engine::EmplaceStatusOverlay(const shared_ptr<Ship> &it, Preferences::Overl
else
alpha = 0.f;
}

if(it->IsYours())
cloak *= 0.6;

statuses.emplace_back(it->Position() - center, it->Shields(), it->Hull(),
min(it->Hull(), it->DisabledHull()), max(20., width * .5), type, alpha);
min(it->Hull(), it->DisabledHull()), max(20., width * .5), type, alpha * (1. - cloak));
}
23 changes: 19 additions & 4 deletions source/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ this program. If not, see <https://www.gnu.org/licenses/>.
#include "AsteroidField.h"
#include "BatchDrawList.h"
#include "CollisionSet.h"
#include "Color.h"
#include "Command.h"
#include "DrawList.h"
#include "EscortDisplay.h"
Expand Down Expand Up @@ -100,6 +101,21 @@ class Engine {


private:
class Outline {
public:
constexpr Outline(const Sprite *sprite, const Point &position, const Point &unit,
const float frame, const Color &color)
: sprite(sprite), position(position), unit(unit), frame(frame), color(color)
{
}

const Sprite *sprite;
const Point position;
const Point unit;
const float frame;
const Color color;
};

class Target {
public:
Point center;
Expand Down Expand Up @@ -167,7 +183,8 @@ class Engine {
void DoGrudge(const std::shared_ptr<Ship> &target, const Government *attacker);

void CreateStatusOverlays();
void EmplaceStatusOverlay(const std::shared_ptr<Ship> &ship, Preferences::OverlayState overlaySetting, int value);
void EmplaceStatusOverlay(const std::shared_ptr<Ship> &ship, Preferences::OverlayState overlaySetting,
int value, double cloak);


private:
Expand Down Expand Up @@ -220,15 +237,13 @@ class Engine {
int targetSwizzle = -1;
EscortDisplay escorts;
AmmoDisplay ammoDisplay;
std::vector<Outline> outlines;
std::vector<Status> statuses;
std::vector<PlanetLabel> labels;
std::vector<AlertLabel> missileLabels;
std::vector<std::pair<const Outfit *, int>> ammo;
int jumpCount = 0;
const System *jumpInProgress[2] = {nullptr, nullptr};
const Sprite *highlightSprite = nullptr;
Point highlightUnit;
float highlightFrame = 0.f;

int step = 0;

Expand Down
1 change: 1 addition & 0 deletions source/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void Preferences::Load()
// values for settings that are off by default.
settings["Landing zoom"] = true;
settings["Render motion blur"] = true;
settings["Cloaked ship outlines"] = true;
settings[FRUGAL_ESCORTS] = true;
settings[EXPEND_AMMO] = true;
settings["Damaged fighters retreat"] = true;
Expand Down
7 changes: 7 additions & 0 deletions source/PreferencesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace {
const string AUTO_FIRE_SETTING = "Automatic firing";
const string SCREEN_MODE_SETTING = "Screen mode";
const string VSYNC_SETTING = "VSync";
const string CLOAK_OUTLINE = "Cloaked ship outlines";
const string STATUS_OVERLAYS_ALL = "Show status overlays";
const string STATUS_OVERLAYS_FLAGSHIP = " Show flagship overlay";
const string STATUS_OVERLAYS_ESCORT = " Show escort overlays";
Expand Down Expand Up @@ -645,6 +646,7 @@ void PreferencesPanel::DrawSettings()
EXTENDED_JUMP_EFFECTS,
SHIP_OUTLINES,
HUD_SHIP_OUTLINES,
CLOAK_OUTLINE,
"\t",
"HUD",
STATUS_OVERLAYS_ALL,
Expand Down Expand Up @@ -784,6 +786,11 @@ void PreferencesPanel::DrawSettings()
text = Preferences::StatusOverlaysSetting(Preferences::OverlayType::NEUTRAL);
isOn = text != "off" && text != "--";
}
else if(setting == CLOAK_OUTLINE)
{
text = Preferences::Has(CLOAK_OUTLINE) ? "fancy" : "fast";
isOn = true;
}
else if(setting == AUTO_AIM_SETTING)
{
text = Preferences::AutoAimSetting();
Expand Down

0 comments on commit bc058c0

Please sign in to comment.