diff --git a/src/client/item.cpp b/src/client/item.cpp index c0f810c0..69fa994f 100644 --- a/src/client/item.cpp +++ b/src/client/item.cpp @@ -40,7 +40,8 @@ Item::Item() : m_clientId(0), m_serverId(0), - m_countOrSubType(1) + m_countOrSubType(1), + m_color(Color::alpha) { } @@ -75,7 +76,15 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate, LightView *l int xPattern = 0, yPattern = 0, zPattern = 0; calculatePatterns(xPattern, yPattern, zPattern); + if(m_color != Color::alpha) + g_painter->setColor(m_color); rawGetThingType()->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase, lightView); + + /// Sanity check + /// This is just to ensure that we don't overwrite some color and + /// screw up the whole rendering. + if(m_color != Color::alpha) + g_painter->resetColor(); } void Item::setId(uint32 id) diff --git a/src/client/item.h b/src/client/item.h index 161c43a1..e5ad727e 100644 --- a/src/client/item.h +++ b/src/client/item.h @@ -24,6 +24,7 @@ #define ITEM_H #include + #include "thing.h" #include "effect.h" #include "itemtype.h" @@ -88,6 +89,7 @@ public: void setCountOrSubType(int value) { m_countOrSubType = value; } void setCount(int count) { m_countOrSubType = count; } void setSubType(int subType) { m_countOrSubType = subType; } + void setColor(const Color& c) { m_color = c; } int getCountOrSubType() { return m_countOrSubType; } int getSubType(); @@ -138,6 +140,7 @@ private: uint8 m_countOrSubType; stdext::packed_storage m_attribs; ItemList m_containerItems; + Color m_color; }; #pragma pack(pop) diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index b6cd3850..0c04f54c 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -103,6 +103,8 @@ void Client::registerLuaFunctions() g_lua.bindSingletonFunction("g_map", "getThing", &Map::getThing, &g_map); g_lua.bindSingletonFunction("g_map", "removeThingByPos", &Map::removeThingByPos, &g_map); g_lua.bindSingletonFunction("g_map", "removeThing", &Map::removeThing, &g_map); + g_lua.bindSingletonFunction("g_map", "colorizeThing", &Map::colorizeThing, &g_map); + g_lua.bindSingletonFunction("g_map", "removeThingColor", &Map::removeThingColor, &g_map); g_lua.bindSingletonFunction("g_map", "clean", &Map::clean, &g_map); g_lua.bindSingletonFunction("g_map", "cleanTile", &Map::cleanTile, &g_map); g_lua.bindSingletonFunction("g_map", "cleanTexts", &Map::cleanTexts, &g_map); diff --git a/src/client/map.cpp b/src/client/map.cpp index 6badea78..71bb7b61 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -216,6 +216,42 @@ bool Map::removeThingByPos(const Position& pos, int stackPos) return false; } +void Map::colorizeThing(const ThingPtr& thing, const Color& color) +{ + if(!thing) + return; + + if(thing->isItem()) + thing->static_self_cast()->setColor(color); + else if(thing->isCreature()) { + const TilePtr& tile = thing->getTile(); + assert(tile); + + const ThingPtr& topThing = tile->getTopThing(); + assert(topThing); + + topThing->static_self_cast()->setColor(color); + } +} + +void Map::removeThingColor(const ThingPtr& thing) +{ + if(!thing) + return; + + if(thing->isItem()) + thing->static_self_cast()->setColor(Color::alpha); + else if(thing->isCreature()) { + const TilePtr& tile = thing->getTile(); + assert(tile); + + const ThingPtr& topThing = tile->getTopThing(); + assert(topThing); + + topThing->static_self_cast()->setColor(Color::alpha); + } +} + StaticTextPtr Map::getStaticText(const Position& pos) { for(auto staticText : m_staticTexts) { @@ -732,3 +768,5 @@ std::tuple, Otc::PathFindResult> Map::findPath(const return ret; } + +/* vim: set ts=4 sw=4 et: */ diff --git a/src/client/map.h b/src/client/map.h index f714cec2..99dbdba1 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -169,6 +169,8 @@ public: ThingPtr getThing(const Position& pos, int stackPos); bool removeThing(const ThingPtr& thing); bool removeThingByPos(const Position& pos, int stackPos); + void colorizeThing(const ThingPtr& thing, const Color& color); + void removeThingColor(const ThingPtr& thing); StaticTextPtr getStaticText(const Position& pos);