Add ItemDrop glow

This commit is contained in:
Kae 2023-08-20 11:56:37 +10:00
parent 3990b196a2
commit 9af6bfe60e
4 changed files with 42 additions and 2 deletions

View File

@ -14,6 +14,7 @@ struct Drawable {
struct LinePart { struct LinePart {
Line2F line; Line2F line;
float width; float width;
Maybe<Color> endColor;
}; };
struct PolyPart { struct PolyPart {

View File

@ -265,6 +265,32 @@ bool ItemDrop::shouldDestroy() const {
} }
void ItemDrop::render(RenderCallback* renderCallback) { void ItemDrop::render(RenderCallback* renderCallback) {
if (m_mode.get() != Mode::Taken) {
Color beamColor;
switch (m_item->rarity()) {
case Rarity::Uncommon:
beamColor = Color::rgb(87, 255, 81);
break;
case Rarity::Rare:
beamColor = Color::rgb(87, 220, 255);
break;
case Rarity::Legendary:
beamColor = Color::rgb(176, 81, 255);
break;
case Rarity::Essential:
beamColor = Color::rgb(255, 255, 81);
break;
default:
beamColor = Color::White;
}
beamColor.setAlphaF(0.8f);
auto line = Drawable::makeLine({ Vec2F(), Vec2F(0.0f, 1.5f) }, 2.0f, beamColor, position());
(line.linePart().endColor = beamColor)->setAlphaF(0.0f);
line.fullbright = true;
renderCallback->addDrawable(move(line), RenderLayerItemDrop);
}
if (!m_drawables) { if (!m_drawables) {
m_drawables = m_item->dropDrawables(); m_drawables = m_item->dropDrawables();
if (Directives dropDirectives = m_config.getString("directives", "")) { if (Directives dropDirectives = m_config.getString("directives", "")) {
@ -282,6 +308,15 @@ void ItemDrop::render(RenderCallback* renderCallback) {
} }
} }
void ItemDrop::renderLightSources(RenderCallback* renderCallback) {
LightSource light;
light.pointLight = false;
light.color = Vec3B::filled(20);
light.position = position();
renderCallback->addLightSource(move(light));
}
ItemPtr ItemDrop::item() const { ItemPtr ItemDrop::item() const {
return m_item; return m_item;
} }

View File

@ -58,7 +58,7 @@ public:
bool shouldDestroy() const override; bool shouldDestroy() const override;
virtual void render(RenderCallback* renderCallback) override; virtual void render(RenderCallback* renderCallback) override;
virtual void renderLightSources(RenderCallback* renderCallback) override;
// The item that this drop contains // The item that this drop contains
ItemPtr item() const; ItemPtr item() const;

View File

@ -17,12 +17,16 @@ void DrawablePainter::drawDrawable(Drawable const& drawable) {
Vec2F left = Vec2F(vnorm(line.diff())).rot90() * linePart->width / 2.0f; Vec2F left = Vec2F(vnorm(line.diff())).rot90() * linePart->width / 2.0f;
float fullbright = drawable.fullbright ? 0.0f : 1.0f; float fullbright = drawable.fullbright ? 0.0f : 1.0f;
primitives.emplace_back(std::in_place_type_t<RenderQuad>(), auto& primitive = primitives.emplace_back(std::in_place_type_t<RenderQuad>(),
line.min() + left, line.min() + left,
line.min() - left, line.min() - left,
line.max() - left, line.max() - left,
line.max() + left, line.max() + left,
color, fullbright); color, fullbright);
if (auto* endColor = linePart->endColor.ptr()) {
RenderQuad& quad = primitive.get<RenderQuad>();
quad.c.color = quad.d.color = endColor->toRgba();
}
} else if (auto polyPart = drawable.part.ptr<Drawable::PolyPart>()) { } else if (auto polyPart = drawable.part.ptr<Drawable::PolyPart>()) {
PolyF poly = polyPart->poly; PolyF poly = polyPart->poly;
poly.translate(drawable.position); poly.translate(drawable.position);