Skip to content

Commit

Permalink
fix(ui): Render animated sprites in the hail panel correctly (endless…
Browse files Browse the repository at this point in the history
  • Loading branch information
warp-core authored Feb 11, 2024
1 parent ad24e3f commit 8d33ce1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions source/HailPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ using namespace std;


HailPanel::HailPanel(PlayerInfo &player, const shared_ptr<Ship> &ship, function<void(const Government *)> bribeCallback)
: player(player), ship(ship), bribeCallback(std::move(bribeCallback)),
sprite(ship->GetSprite()), facing(ship->Facing())
: player(player), ship(ship), bribeCallback(std::move(bribeCallback)), facing(ship->Facing())
{
SetInterruptible(false);

Expand Down Expand Up @@ -125,7 +124,7 @@ HailPanel::HailPanel(PlayerInfo &player, const shared_ptr<Ship> &ship, function<


HailPanel::HailPanel(PlayerInfo &player, const StellarObject *object)
: player(player), planet(object->GetPlanet()), sprite(object->GetSprite()), facing(object->Facing())
: player(player), object(object), planet(object->GetPlanet()), facing(object->Facing())
{
SetInterruptible(false);

Expand Down Expand Up @@ -209,11 +208,14 @@ void HailPanel::Draw()
const Interface *hailUi = GameData::Interfaces().Get("hail panel");
hailUi->Draw(info, this);

const Sprite *sprite = ship ? ship->GetSprite() : object->GetSprite();

// Draw the sprite, rotated, scaled, and swizzled as necessary.
float zoom = min(2.f, 400.f / max(sprite->Width(), sprite->Height()));
Point center(-170., -10.);

DrawList draw;
draw.Clear(step);
// If this is a ship, copy its swizzle, animation settings, etc.
// Also draw its fighters and weapon hardpoints.
if(ship)
Expand Down Expand Up @@ -263,7 +265,7 @@ void HailPanel::Draw()
addFighter(bay);
}
else
draw.Add(Body(sprite, center, Point(), facing, zoom));
draw.Add(Body(*object, center, Point(), facing, zoom));

draw.Draw();

Expand All @@ -274,6 +276,8 @@ void HailPanel::Draw()
wrap.SetFont(FontSet::Get(14));
wrap.Wrap(message);
wrap.Draw(Point(-50., -50.), *GameData::Colors().Get("medium"));

++step;
}


Expand Down
3 changes: 2 additions & 1 deletion source/HailPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ class HailPanel : public Panel {
PlayerInfo &player;
std::shared_ptr<Ship> ship = nullptr;
std::function<void(const Government *)> bribeCallback = nullptr;
const StellarObject *object = nullptr;
const Planet *planet = nullptr;
const Sprite *sprite = nullptr;
Angle facing;
int step = 0;

std::string header;
std::string message;
Expand Down

0 comments on commit 8d33ce1

Please sign in to comment.