Optional and configurable zone colors

master
Allan Ference 11 years ago
parent 5849136526
commit 5eabf6f518

@ -66,6 +66,7 @@ void Client::registerLuaFunctions()
g_lua.bindSingletonFunction("g_things", "getItemType", &ThingTypeManager::getItemType, &g_things);
g_lua.bindSingletonFunction("g_things", "getThingTypes", &ThingTypeManager::getThingTypes, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByClientId", &ThingTypeManager::findItemTypeByClientId, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByName", &ThingTypeManager::findItemTypeByName, &g_things);
g_lua.bindSingletonFunction("g_things", "findThingTypeByAttr", &ThingTypeManager::findThingTypeByAttr, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByCategory", &ThingTypeManager::findItemTypeByCategory, &g_things);
@ -122,6 +123,14 @@ void Client::registerLuaFunctions()
g_lua.bindSingletonFunction("g_map", "setSpawnFile", &Map::setSpawnFile, &g_map);
g_lua.bindSingletonFunction("g_map", "createTile", &Map::createTile, &g_map);
g_lua.bindSingletonFunction("g_map", "getSize", &Map::getSize, &g_map);
g_lua.bindSingletonFunction("g_map", "setShowZone", &Map::setShowZone, &g_map);
g_lua.bindSingletonFunction("g_map", "setShowZones", &Map::setShowZones, &g_map);
g_lua.bindSingletonFunction("g_map", "setZoneColor", &Map::setZoneColor, &g_map);
g_lua.bindSingletonFunction("g_map", "setZoneOpacity", &Map::setZoneOpacity, &g_map);
g_lua.bindSingletonFunction("g_map", "getZoneOpacity", &Map::getZoneOpacity, &g_map);
g_lua.bindSingletonFunction("g_map", "getZoneColor", &Map::getZoneColor, &g_map);
g_lua.bindSingletonFunction("g_map", "showZones", &Map::showZones, &g_map);
g_lua.bindSingletonFunction("g_map", "showZone", &Map::showZone, &g_map);
g_lua.registerSingletonClass("g_minimap");
g_lua.bindSingletonFunction("g_minimap", "clean", &Minimap::clean, &g_minimap);
@ -529,6 +538,10 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Tile>("isClickable", &Tile::isClickable);
g_lua.bindClassMemberFunction<Tile>("isPathable", &Tile::isPathable);
g_lua.bindClassMemberFunction<Tile>("overwriteMinimapColor", &Tile::overwriteMinimapColor);
g_lua.bindClassMemberFunction<Tile>("setFlag", &Tile::setFlag);
g_lua.bindClassMemberFunction<Tile>("setFlags", &Tile::setFlags);
g_lua.bindClassMemberFunction<Tile>("getFlags", &Tile::getFlags);
g_lua.bindClassMemberFunction<Tile>("hasFlag", &Tile::hasFlag);
g_lua.registerClass<UIItem, UIWidget>();
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); });

@ -305,6 +305,30 @@ void Map::cleanTile(const Position& pos)
}
}
void Map::setShowZone(tileflags_t zone, bool show)
{
if(show)
m_zoneFlags |= (uint32)zone;
else
m_zoneFlags &= ~(uint32)zone;
}
void Map::setShowZones(bool show)
{
static constexpr uint32 defaultZoneFlags
= TILESTATE_HOUSE | TILESTATE_PROTECTIONZONE;
if(!show)
m_zoneFlags = 0;
else if(m_zoneFlags == 0)
m_zoneFlags = defaultZoneFlags;
}
void Map::setZoneColor(tileflags_t zone, const Color& color)
{
if((m_zoneFlags & zone) == zone)
m_zoneColors[zone] = color;
}
void Map::addCreature(const CreaturePtr& creature)
{
m_knownCreatures[creature->getId()] = creature;

@ -179,6 +179,18 @@ public:
const TilePtr& getTile(const Position& pos);
void cleanTile(const Position& pos);
// tile zone related
void setShowZone(tileflags_t zone, bool show);
void setShowZones(bool show);
void setZoneColor(tileflags_t flag, const Color& color);
void setZoneOpacity(float opacity) { m_zoneOpacity = opacity; }
float getZoneOpacity() { return m_zoneOpacity; }
Color getZoneColor(tileflags_t flag) { return m_zoneColors[flag]; }
tileflags_t getZoneFlags() { return (tileflags_t)m_zoneFlags; }
bool showZones() { return m_zoneFlags != 0; }
bool showZone(tileflags_t zone) { return (m_zoneFlags & zone) == zone; }
// known creature related
void addCreature(const CreaturePtr& creature);
CreaturePtr getCreatureById(uint32 id);
@ -223,6 +235,10 @@ private:
std::vector<MapViewPtr> m_mapViews;
std::unordered_map<Position, std::string, PositionHasher> m_waypoints;
uint32 m_zoneFlags;
std::array<Color, TILESTATE_LAST> m_zoneColors;
float m_zoneOpacity;
Light m_light;
Position m_centralPosition;
Rect m_tilesRect;

@ -43,15 +43,11 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *
{
bool animate = drawFlags & Otc::DrawAnimations;
// Added for MapEditor purposes.
// This check will and must evaluate to false if using
// normal client, unless some flag error.
// Save last color
Color lastColor = g_painter->getColor();
if((m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE)
g_painter->setColor(Color::blue);
else if((m_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE)
g_painter->setColor(Color::green);
/* Flags to be checked for. */
static const tileflags_t flags[] = {
TILESTATE_HOUSE,
TILESTATE_PROTECTIONZONE,
};
// first bottom items
if(drawFlags & (Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawOnBottom)) {
@ -60,10 +56,31 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom())
break;
Color prevColor = g_painter->getColor();
float prevOpacity = g_painter->getOpacity();
bool restore = false;
if(g_map.showZones() && thing->isGround()) {
for(unsigned int i = 0; i < sizeof(flags) / sizeof(tileflags_t); ++i) {
tileflags_t flag = flags[i];
if(hasFlag(flag) && g_map.showZone(flag)) {
g_painter->setOpacity(g_map.getZoneOpacity());
g_painter->setColor(g_map.getZoneColor(flag));
restore = true;
break;
}
}
}
if((thing->isGround() && drawFlags & Otc::DrawGround) ||
(thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) ||
(thing->isOnBottom() && drawFlags & Otc::DrawOnBottom)) {
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
if(restore) {
g_painter->setOpacity(prevOpacity);
g_painter->setColor(prevColor);
}
}
m_drawElevation += thing->getElevation();
@ -131,20 +148,15 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *
}
// effects
if(drawFlags & Otc::DrawEffects) {
for(const EffectPtr& effect : m_effects){
if(drawFlags & Otc::DrawEffects)
for(const EffectPtr& effect : m_effects)
effect->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
}
}
// top items
if(drawFlags & Otc::DrawOnTop) {
for(const ThingPtr& thing : m_things) {
if(thing->isOnTop()){
thing->draw(dest, scaleFactor, animate, lightView);
}
}
}
if(drawFlags & Otc::DrawOnTop)
for(const ThingPtr& thing : m_things)
if(thing->isOnTop())
thing->draw(dest, scaleFactor, animate, lightView);
// draw translucent light (for tiles beneath holes)
if(hasTranslucentLight() && lightView) {
@ -152,9 +164,6 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *
light.intensity = 1;
lightView->addLightSource(dest + Point(16,16) * scaleFactor, scaleFactor, light);
}
// Restore color
g_painter->setColor(lastColor);
}
void Tile::clean()
@ -652,3 +661,5 @@ void Tile::checkTranslucentLight()
else
tile->m_flags = tile->m_flags & ~TILESTATE_TRANSLUECENT_LIGHT;
}
/* vim: set ts=8 sw=4 tw=0 et :*/

@ -48,7 +48,9 @@ enum tileflags_t
TILESTATE_TRASHHOLDER = 1 << 20,
TILESTATE_BED = 1 << 21,
TILESTATE_DEPOT = 1 << 22,
TILESTATE_TRANSLUECENT_LIGHT = 1 << 23
TILESTATE_TRANSLUECENT_LIGHT = 1 << 23,
TILESTATE_LAST = 1 << 24
};
class Tile : public LuaObject
@ -112,6 +114,7 @@ public:
void setFlag(tileflags_t flag) { m_flags |= (uint32)flag; }
void setFlags(tileflags_t flags) { m_flags = (uint32)flags; }
bool hasFlag(tileflags_t flag) { return (m_flags & flag) == flag; }
uint32 getFlags() { return m_flags; }
void setHouseId(uint32 hid) { m_houseId = hid; }

Loading…
Cancel
Save