mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-20 03:29:32 +02:00
Raw version of hero flags
This commit is contained in:
parent
82d6a6350c
commit
656ee8c2b2
@ -290,9 +290,35 @@ void Graphics::blueToPlayersAdv(QImage * sur, PlayerColor player)
|
|||||||
|
|
||||||
std::shared_ptr<Animation> Graphics::getAnimation(const CGObjectInstance* obj)
|
std::shared_ptr<Animation> Graphics::getAnimation(const CGObjectInstance* obj)
|
||||||
{
|
{
|
||||||
|
if(obj->ID == Obj::HERO)
|
||||||
|
return getHeroAnimation(obj->appearance);
|
||||||
return getAnimation(obj->appearance);
|
return getAnimation(obj->appearance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Animation> Graphics::getHeroAnimation(const std::shared_ptr<const ObjectTemplate> info)
|
||||||
|
{
|
||||||
|
if(info->animationFile.empty())
|
||||||
|
{
|
||||||
|
logGlobal->warn("Def name for hero (%d,%d) is empty!", info->id, info->subid);
|
||||||
|
return std::shared_ptr<Animation>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Animation> ret = loadHeroAnimation(info->animationFile);
|
||||||
|
|
||||||
|
//already loaded
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
ret->preload();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = std::make_shared<Animation>(info->animationFile);
|
||||||
|
heroAnimations[info->animationFile] = ret;
|
||||||
|
|
||||||
|
ret->preload();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Animation> Graphics::getAnimation(const std::shared_ptr<const ObjectTemplate> info)
|
std::shared_ptr<Animation> Graphics::getAnimation(const std::shared_ptr<const ObjectTemplate> info)
|
||||||
{
|
{
|
||||||
//the only(?) invisible object
|
//the only(?) invisible object
|
||||||
|
@ -78,6 +78,7 @@ public:
|
|||||||
|
|
||||||
std::shared_ptr<Animation> getAnimation(const CGObjectInstance * obj);
|
std::shared_ptr<Animation> getAnimation(const CGObjectInstance * obj);
|
||||||
std::shared_ptr<Animation> getAnimation(const std::shared_ptr<const ObjectTemplate> info);
|
std::shared_ptr<Animation> getAnimation(const std::shared_ptr<const ObjectTemplate> info);
|
||||||
|
std::shared_ptr<Animation> getHeroAnimation(const std::shared_ptr<const ObjectTemplate> info);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Graphics * graphics;
|
extern Graphics * graphics;
|
||||||
|
@ -524,7 +524,9 @@ void MainWindow::loadObjectsTree()
|
|||||||
addGroupIntoCatalog("MISC", true, false, Obj::FREELANCERS_GUILD);
|
addGroupIntoCatalog("MISC", true, false, Obj::FREELANCERS_GUILD);
|
||||||
addGroupIntoCatalog("MISC", true, false, Obj::SANCTUARY);
|
addGroupIntoCatalog("MISC", true, false, Obj::SANCTUARY);
|
||||||
addGroupIntoCatalog("MISC", true, false, Obj::MARLETTO_TOWER);
|
addGroupIntoCatalog("MISC", true, false, Obj::MARLETTO_TOWER);
|
||||||
//addGroupIntoCatalog("PRISON", true, false, Obj::PRISON);
|
addGroupIntoCatalog("HERO", true, false, Obj::PRISON);
|
||||||
|
addGroupIntoCatalog("HERO", false, false, Obj::HERO);
|
||||||
|
addGroupIntoCatalog("HERO", false, false, Obj::RANDOM_HERO);
|
||||||
addGroupIntoCatalog("ARTIFACTS", true, false, Obj::ARTIFACT);
|
addGroupIntoCatalog("ARTIFACTS", true, false, Obj::ARTIFACT);
|
||||||
addGroupIntoCatalog("ARTIFACTS", false, false, Obj::RANDOM_ART);
|
addGroupIntoCatalog("ARTIFACTS", false, false, Obj::RANDOM_ART);
|
||||||
addGroupIntoCatalog("ARTIFACTS", false, false, Obj::RANDOM_TREASURE_ART);
|
addGroupIntoCatalog("ARTIFACTS", false, false, Obj::RANDOM_TREASURE_ART);
|
||||||
|
@ -341,6 +341,16 @@ void MapController::commitObjectCreate(int level)
|
|||||||
main->setStatusMessage(QString("Reached map limit for object %1 - %2").arg(typeName, subTypeName));
|
main->setStatusMessage(QString("Reached map limit for object %1 - %2").arg(typeName, subTypeName));
|
||||||
return; //maplimit reached
|
return; //maplimit reached
|
||||||
}
|
}
|
||||||
|
if(defaultPlayer == PlayerColor::NEUTRAL && (newObj->ID == Obj::HERO || newObj->ID == Obj::RANDOM_HERO))
|
||||||
|
{
|
||||||
|
main->setStatusMessage("Hero cannot be created as NEUTRAL");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(defaultPlayer != PlayerColor::NEUTRAL && newObj->ID == Obj::PRISON)
|
||||||
|
{
|
||||||
|
main->setStatusMessage("Prison must be a NEUTRAL");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Initializer init(map(), newObj, defaultPlayer);
|
Initializer init(map(), newObj, defaultPlayer);
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ void MapHandler::initObjectRects()
|
|||||||
if(animation->size(0) == 0)
|
if(animation->size(0) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto image = animation->getImage(0,0);
|
auto image = animation->getImage(0, obj->ID == Obj::HERO ? 2 : 0);
|
||||||
for(int fx=0; fx < obj->getWidth(); ++fx)
|
for(int fx=0; fx < obj->getWidth(); ++fx)
|
||||||
{
|
{
|
||||||
for(int fy=0; fy < obj->getHeight(); ++fy)
|
for(int fy=0; fy < obj->getHeight(); ++fy)
|
||||||
@ -244,12 +244,12 @@ TileObject::~TileObject()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<QImage> MapHandler::findFlagBitmap(const CGHeroInstance * hero, int anim, const PlayerColor * color, int group) const
|
std::shared_ptr<QImage> MapHandler::findFlagBitmap(const CGHeroInstance * hero, int anim, const PlayerColor color, int group) const
|
||||||
{
|
{
|
||||||
if(!hero || hero->boat)
|
if(!hero || hero->boat)
|
||||||
return std::shared_ptr<QImage>();
|
return std::shared_ptr<QImage>();
|
||||||
|
|
||||||
return findFlagBitmapInternal(graphics->heroFlagAnimations.at(color->getNum()), anim, group, hero->moveDir, !hero->isStanding);
|
return findFlagBitmapInternal(graphics->heroFlagAnimations.at(color.getNum()), anim, group, hero->moveDir, !hero->isStanding);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<QImage> MapHandler::findFlagBitmapInternal(std::shared_ptr<Animation> animation, int anim, int group, ui8 dir, bool moving) const
|
std::shared_ptr<QImage> MapHandler::findFlagBitmapInternal(std::shared_ptr<Animation> animation, int anim, int group, ui8 dir, bool moving) const
|
||||||
@ -264,19 +264,20 @@ std::shared_ptr<QImage> MapHandler::findFlagBitmapInternal(std::shared_ptr<Anima
|
|||||||
return animation->getImage((anim / 4) % groupSize, group);
|
return animation->getImage((anim / 4) % groupSize, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapHandler::AnimBitmapHolder MapHandler::findObjectBitmap(const CGObjectInstance * obj, int anim) const
|
MapHandler::AnimBitmapHolder MapHandler::findObjectBitmap(const CGObjectInstance * obj, int anim, int group) const
|
||||||
{
|
{
|
||||||
if(!obj || obj->ID == Obj::HERO || obj->ID == Obj::BOAT)
|
if(!obj)
|
||||||
return MapHandler::AnimBitmapHolder();
|
return MapHandler::AnimBitmapHolder();
|
||||||
|
|
||||||
// normal object
|
// normal object
|
||||||
std::shared_ptr<Animation> animation = graphics->getAnimation(obj);
|
std::shared_ptr<Animation> animation = graphics->getAnimation(obj);
|
||||||
size_t groupSize = animation->size();
|
size_t groupSize = animation->size(group);
|
||||||
if(groupSize == 0)
|
if(groupSize == 0)
|
||||||
return MapHandler::AnimBitmapHolder();
|
return MapHandler::AnimBitmapHolder();
|
||||||
|
|
||||||
animation->playerColored(obj->tempOwner);
|
animation->playerColored(obj->tempOwner);
|
||||||
auto bitmap = animation->getImage(anim % groupSize);
|
auto bitmap = animation->getImage(anim % groupSize, group);
|
||||||
|
|
||||||
if(!bitmap)
|
if(!bitmap)
|
||||||
return MapHandler::AnimBitmapHolder();
|
return MapHandler::AnimBitmapHolder();
|
||||||
|
|
||||||
@ -303,16 +304,20 @@ void MapHandler::drawObjects(QPainter & painter, int x, int y, int z)
|
|||||||
|
|
||||||
uint8_t animationFrame = 0;
|
uint8_t animationFrame = 0;
|
||||||
|
|
||||||
auto objData = findObjectBitmap(obj, animationFrame);
|
auto objData = findObjectBitmap(obj, animationFrame, obj->ID == Obj::HERO ? 2 : 0);
|
||||||
|
if(obj->ID == Obj::HERO && obj->tempOwner.isValidPlayer())
|
||||||
|
objData.flagBitmap = findFlagBitmap(dynamic_cast<const CGHeroInstance*>(obj), 0, obj->tempOwner, 4);
|
||||||
|
|
||||||
if (objData.objBitmap)
|
if (objData.objBitmap)
|
||||||
{
|
{
|
||||||
auto pos = obj->getPosition();
|
auto pos = obj->getPosition();
|
||||||
|
|
||||||
painter.drawImage(QPoint(x * tileSize, y * tileSize), *objData.objBitmap, object.rect);
|
painter.drawImage(QPoint(x * tileSize, y * tileSize), *objData.objBitmap, object.rect);
|
||||||
|
|
||||||
if(objData.flagBitmap)
|
if(objData.flagBitmap)
|
||||||
{
|
{
|
||||||
if (obj->pos.x == pos.x && obj->pos.y == pos.y)
|
if (x == pos.x - 1 && y == pos.y - 1)
|
||||||
painter.drawImage(QPoint(x * tileSize, y * tileSize), *objData.flagBitmap, object.rect);
|
painter.drawImage(QPoint(x * tileSize, y * tileSize), *objData.flagBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,18 +334,20 @@ void MapHandler::drawObject(QPainter & painter, const TileObject & object)
|
|||||||
|
|
||||||
uint8_t animationFrame = 0;
|
uint8_t animationFrame = 0;
|
||||||
|
|
||||||
auto objData = findObjectBitmap(obj, animationFrame);
|
auto objData = findObjectBitmap(obj, animationFrame, obj->ID == Obj::HERO ? 2 : 0);
|
||||||
|
if(obj->ID == Obj::HERO && obj->tempOwner.isValidPlayer())
|
||||||
|
objData.flagBitmap = findFlagBitmap(dynamic_cast<const CGHeroInstance*>(obj), 0, obj->tempOwner, 4);
|
||||||
|
|
||||||
if (objData.objBitmap)
|
if (objData.objBitmap)
|
||||||
{
|
{
|
||||||
auto pos = obj->getPosition();
|
auto pos = obj->getPosition();
|
||||||
|
|
||||||
painter.drawImage(pos.x * tileSize - object.rect.x(), pos.y * tileSize - object.rect.y(), *objData.objBitmap);
|
painter.drawImage(pos.x * tileSize - object.rect.x(), pos.y * tileSize - object.rect.y(), *objData.objBitmap);
|
||||||
|
|
||||||
if (objData.flagBitmap)
|
if (objData.flagBitmap)
|
||||||
{
|
{
|
||||||
if (obj->pos.x == pos.x && obj->pos.y == pos.y)
|
if(object.rect.x() == pos.x && object.rect.y() == pos.y)
|
||||||
{
|
painter.drawImage(pos.x * tileSize, pos.y * tileSize, *objData.flagBitmap);
|
||||||
painter.drawImage(pos.x * tileSize - object.rect.x(), pos.y * tileSize - object.rect.y(), *objData.flagBitmap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -356,14 +363,19 @@ void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj,
|
|||||||
|
|
||||||
uint8_t animationFrame = 0;
|
uint8_t animationFrame = 0;
|
||||||
|
|
||||||
auto objData = findObjectBitmap(obj, animationFrame);
|
auto objData = findObjectBitmap(obj, animationFrame, obj->ID == Obj::HERO ? 2 : 0);
|
||||||
|
std::vector<std::shared_ptr<QImage>> debugFlagImages;
|
||||||
|
if(obj->ID == Obj::HERO && obj->tempOwner.isValidPlayer())
|
||||||
|
{
|
||||||
|
objData.flagBitmap = findFlagBitmap(dynamic_cast<const CGHeroInstance*>(obj), 0, obj->tempOwner, 4);
|
||||||
|
}
|
||||||
|
|
||||||
if (objData.objBitmap)
|
if (objData.objBitmap)
|
||||||
{
|
{
|
||||||
painter.drawImage(QPoint((x + 1) * 32 - objData.objBitmap->width(), (y + 1) * 32 - objData.objBitmap->height()), *objData.objBitmap);
|
painter.drawImage(QPoint((x + 1) * 32 - objData.objBitmap->width(), (y + 1) * 32 - objData.objBitmap->height()), *objData.objBitmap);
|
||||||
|
|
||||||
if (objData.flagBitmap)
|
if (objData.flagBitmap)
|
||||||
{
|
painter.drawImage(QPoint((x - 1) * 32, (y - 1) * 32), *objData.flagBitmap);
|
||||||
painter.drawImage(QPoint((x + 1) * 32 - objData.objBitmap->width(), (y + 1) * 32 - objData.objBitmap->height()), *objData.flagBitmap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,7 +445,7 @@ void MapHandler::invalidate(CGObjectInstance * obj)
|
|||||||
if(!animation || animation->size(0) == 0)
|
if(!animation || animation->size(0) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto image = animation->getImage(0,0);
|
auto image = animation->getImage(0, obj->ID == Obj::HERO ? 2 : 0);
|
||||||
for(int fx=0; fx < obj->getWidth(); ++fx)
|
for(int fx=0; fx < obj->getWidth(); ++fx)
|
||||||
{
|
{
|
||||||
for(int fy=0; fy < obj->getHeight(); ++fy)
|
for(int fy=0; fy < obj->getHeight(); ++fy)
|
||||||
|
@ -44,8 +44,8 @@ private:
|
|||||||
int index(const int3 &) const;
|
int index(const int3 &) const;
|
||||||
|
|
||||||
std::shared_ptr<QImage> findFlagBitmapInternal(std::shared_ptr<Animation> animation, int anim, int group, ui8 dir, bool moving) const;
|
std::shared_ptr<QImage> findFlagBitmapInternal(std::shared_ptr<Animation> animation, int anim, int group, ui8 dir, bool moving) const;
|
||||||
std::shared_ptr<QImage> findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int group) const;
|
std::shared_ptr<QImage> findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor color, int group) const;
|
||||||
AnimBitmapHolder findObjectBitmap(const CGObjectInstance * obj, int anim) const;
|
AnimBitmapHolder findObjectBitmap(const CGObjectInstance * obj, int anim, int group = 0) const;
|
||||||
|
|
||||||
//FIXME: unique_ptr should be enough, but fails to compile in MSVS 2013
|
//FIXME: unique_ptr should be enough, but fails to compile in MSVS 2013
|
||||||
typedef std::map<std::string, std::shared_ptr<Animation>> TFlippedAnimations; //[type, rotation]
|
typedef std::map<std::string, std::shared_ptr<Animation>> TFlippedAnimations; //[type, rotation]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user