From b6ba60c0227f421cc33c0bddcdb92d2d3a1f400f Mon Sep 17 00:00:00 2001 From: Joao Pasqualini Costa Date: Mon, 27 Nov 2023 15:42:34 -0300 Subject: [PATCH] feat: possible to highlight objects --- src/client/creature.cpp | 20 ++++++++++++-------- src/client/item.cpp | 8 +++++--- src/client/item.h | 2 +- src/client/luafunctions.cpp | 2 ++ src/client/thing.h | 13 +++++++++++++ 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/client/creature.cpp b/src/client/creature.cpp index b278ecd4ec..f361467549 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -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) { @@ -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); } @@ -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 @@ -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); @@ -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 @@ -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()); @@ -303,13 +307,13 @@ void Creature::internalDraw(Point dest, LightView* lightView, const Color& color if (m_outfit.isEffect()) animationPhase = std::min(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 diff --git a/src/client/item.cpp b/src/client/item.cpp index 2d97e90532..aa9030d183 100644 --- a/src/client/item.cpp +++ b/src/client/item.cpp @@ -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 @@ -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); diff --git a/src/client/item.h b/src/client/item.h index 12d8693b5c..36295ff6ea 100644 --- a/src/client/item.h +++ b/src/client/item.h @@ -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 }; diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index 2a5989bfcc..58b9bf6d97 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -460,6 +460,8 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("isLyingCorpse", &Thing::isLyingCorpse); g_lua.bindClassMemberFunction("getDefaultAction", &Thing::getDefaultAction); g_lua.bindClassMemberFunction("getClassification", &Thing::getClassification); + g_lua.bindClassMemberFunction("setHighlight", &Thing::lua_setHighlight); + g_lua.bindClassMemberFunction("isHighlighted", &Thing::isHighlighted); #ifdef FRAMEWORK_EDITOR g_lua.registerClass(); diff --git a/src/client/thing.h b/src/client/thing.h index 780c2f976b..07aac984e2 100644 --- a/src/client/thing.h +++ b/src/client/thing.h @@ -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; @@ -209,6 +220,7 @@ class Thing : public AttachableObject DrawConductor m_drawConductor{ false, DrawOrder::THIRD }; Color m_markedColor{ Color::white }; + Color m_highlightColor{ Color::white }; // Shader PainterShaderProgramPtr m_shader; @@ -216,6 +228,7 @@ class Thing : public AttachableObject 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 };