Skip to content

Commit

Permalink
feat: possible to highlight objects (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
conde2 authored Nov 27, 2023
1 parent 94fbbbc commit 6693113
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ void Creature::draw(const Point& dest, bool drawThings, LightView* lightView)

if (isMarked())
internalDraw(_dest, nullptr, getMarkedColor());
else if (isHighlighted())
internalDraw(_dest, nullptr, getHighlightColor());
}

if (lightView) {
Expand Down Expand Up @@ -115,6 +117,9 @@ void Creature::draw(const Rect& destRect, uint8_t size)
internalDraw(p);
if (isMarked())
internalDraw(p, nullptr, getMarkedColor());
else if (isHighlighted())
internalDraw(p, nullptr, getHighlightColor());

} g_drawPool.releaseFrameBuffer(destRect);
}

Expand Down Expand Up @@ -234,9 +239,8 @@ void Creature::drawInformation(const MapPosInfo& mapRect, const Point& dest, boo

void Creature::internalDraw(Point dest, LightView* lightView, const Color& color)
{
bool isMarked = color != Color::white;

if (isMarked)
bool replaceColorShader = color != Color::white;
if (replaceColorShader)
g_drawPool.setShaderProgram(g_painter->getReplaceColorShader());
else
drawAttachedEffect(dest, lightView, false); // On Bottom
Expand All @@ -247,7 +251,7 @@ void Creature::internalDraw(Point dest, LightView* lightView, const Color& color
if (m_outfit.hasMount()) {
dest -= m_mountType->getDisplacement() * g_drawPool.getScaleFactor();

if (!isMarked && m_mountShader)
if (!replaceColorShader && m_mountShader)
g_drawPool.setShaderProgram(m_mountShader, true, m_mountShaderAction);
m_mountType->draw(dest, 0, m_numPatternX, 0, 0, getCurrentAnimationPhase(true), color);

Expand All @@ -262,7 +266,7 @@ void Creature::internalDraw(Point dest, LightView* lightView, const Color& color
const auto& datType = getThingType();
const int animationPhase = getCurrentAnimationPhase();

if (!isMarked && m_shader)
if (!replaceColorShader && m_shader)
g_drawPool.setShaderProgram(m_shader, true, m_shaderAction);

// yPattern => creature addon
Expand All @@ -273,7 +277,7 @@ void Creature::internalDraw(Point dest, LightView* lightView, const Color& color

datType->draw(dest, 0, m_numPatternX, yPattern, m_numPatternZ, animationPhase, color);

if (m_drawOutfitColor && !isMarked && getLayers() > 1) {
if (m_drawOutfitColor && !replaceColorShader && getLayers() > 1) {
g_drawPool.setCompositionMode(CompositionMode::MULTIPLY);
datType->draw(dest, SpriteMaskYellow, m_numPatternX, yPattern, m_numPatternZ, animationPhase, m_outfit.getHeadColor());
datType->draw(dest, SpriteMaskRed, m_numPatternX, yPattern, m_numPatternZ, animationPhase, m_outfit.getBodyColor());
Expand Down Expand Up @@ -303,13 +307,13 @@ void Creature::internalDraw(Point dest, LightView* lightView, const Color& color
if (m_outfit.isEffect())
animationPhase = std::min<int>(animationPhase + 1, animationPhases);

if (!isMarked && m_shader)
if (!replaceColorShader && m_shader)
g_drawPool.setShaderProgram(m_shader, true, m_shaderAction);
m_thingType->draw(dest - (getDisplacement() * g_drawPool.getScaleFactor()), 0, 0, 0, 0, animationPhase, color);
}
}

if (isMarked)
if (replaceColorShader)
g_drawPool.resetShaderProgram();
else
drawAttachedEffect(dest, lightView, true); // On Top
Expand Down
8 changes: 5 additions & 3 deletions src/client/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ void Item::draw(const Point& dest, bool drawThings, LightView* lightView)

if (isMarked())
internalDraw(animationPhase, dest, getMarkedColor(), drawThings, true);
else if (isHighlighted())
internalDraw(animationPhase, dest, getHighlightColor(), drawThings, true);
}

void Item::internalDraw(int animationPhase, const Point& dest, const Color& color, bool drawThings, bool isMarked, LightView* lightView)
void Item::internalDraw(int animationPhase, const Point& dest, const Color& color, bool drawThings, bool replaceColorShader, LightView* lightView)
{
if (isMarked)
if (replaceColorShader)
g_drawPool.setShaderProgram(g_painter->getReplaceColorShader(), true);
else {
drawAttachedEffect(dest, lightView, false); // On Bottom
Expand All @@ -72,7 +74,7 @@ void Item::internalDraw(int animationPhase, const Point& dest, const Color& colo
getThingType()->draw(dest, 0, m_numPatternX, m_numPatternY, m_numPatternZ, animationPhase, color, drawThings, lightView, m_drawConductor);
g_drawPool.resetShaderProgram();

if (!isMarked)
if (!replaceColorShader)
drawAttachedEffect(dest, lightView, true); // On Top

drawAttachedParticlesEffect(dest);
Expand Down
2 changes: 1 addition & 1 deletion src/client/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Item : public Thing
#endif

private:
void internalDraw(int animationPhase, const Point& dest, const Color& color, bool drawThings, bool isMarked, LightView* lightView = nullptr);
void internalDraw(int animationPhase, const Point& dest, const Color& color, bool drawThings, bool replaceColorShader, LightView* lightView = nullptr);
void setConductor();

uint16_t m_countOrSubType{ 0 };
Expand Down
2 changes: 2 additions & 0 deletions src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Thing>("isLyingCorpse", &Thing::isLyingCorpse);
g_lua.bindClassMemberFunction<Thing>("getDefaultAction", &Thing::getDefaultAction);
g_lua.bindClassMemberFunction<Thing>("getClassification", &Thing::getClassification);
g_lua.bindClassMemberFunction<Thing>("setHighlight", &Thing::lua_setHighlight);
g_lua.bindClassMemberFunction<Thing>("isHighlighted", &Thing::isHighlighted);

#ifdef FRAMEWORK_EDITOR
g_lua.registerClass<House>();
Expand Down
13 changes: 13 additions & 0 deletions src/client/thing.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ class Thing : public AttachableObject
bool isMarked() { return m_markedColor != Color::white; }
void setMarked(const Color& color) { if (m_markedColor != color) m_markedColor = color; }

const Color& getHighlightColor() {
if (m_highlightColor == Color::white)
return Color::white;

m_highlightColor.setAlpha(0.1f + std::abs(500 - g_clock.millis() % 1000) / 1000.0f);
return m_highlightColor;
}

bool isHighlighted() { return m_highlightColor != Color::white; }
void setHighlight(const Color& color) { if (m_highlightColor != color) m_highlightColor = color; }

bool isHided() { return isOwnerHidden(); }
void onStartAttachEffect(const AttachedEffectPtr& effect) override;
void onDispatcherAttachEffect(const AttachedEffectPtr& effect) override;
Expand All @@ -209,13 +220,15 @@ class Thing : public AttachableObject
DrawConductor m_drawConductor{ false, DrawOrder::THIRD };

Color m_markedColor{ Color::white };
Color m_highlightColor{ Color::white };

// Shader
PainterShaderProgramPtr m_shader;
std::function<void()> m_shaderAction{ nullptr };

private:
void lua_setMarked(std::string_view color) { setMarked(Color(color)); }
void lua_setHighlight(std::string_view color) { setHighlight(Color(color)); }

bool m_canDraw{ true };

Expand Down

0 comments on commit 6693113

Please sign in to comment.