Introduce 2 new functions to Map
- g_map.colorizeThing - g_map.removeThingColor
This commit is contained in:
parent
644d4daeea
commit
32647f11bf
|
@ -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)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define ITEM_H
|
||||
|
||||
#include <framework/global.h>
|
||||
|
||||
#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<uint8> m_attribs;
|
||||
ItemList m_containerItems;
|
||||
Color m_color;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Item>()->setColor(color);
|
||||
else if(thing->isCreature()) {
|
||||
const TilePtr& tile = thing->getTile();
|
||||
assert(tile);
|
||||
|
||||
const ThingPtr& topThing = tile->getTopThing();
|
||||
assert(topThing);
|
||||
|
||||
topThing->static_self_cast<Item>()->setColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::removeThingColor(const ThingPtr& thing)
|
||||
{
|
||||
if(!thing)
|
||||
return;
|
||||
|
||||
if(thing->isItem())
|
||||
thing->static_self_cast<Item>()->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<Item>()->setColor(Color::alpha);
|
||||
}
|
||||
}
|
||||
|
||||
StaticTextPtr Map::getStaticText(const Position& pos)
|
||||
{
|
||||
for(auto staticText : m_staticTexts) {
|
||||
|
@ -732,3 +768,5 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4 et: */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue