1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

Raw version of hero flags

This commit is contained in:
nordsoft 2022-09-11 21:00:30 +04:00
parent 82d6a6350c
commit 656ee8c2b2
6 changed files with 74 additions and 23 deletions

View File

@ -290,9 +290,35 @@ void Graphics::blueToPlayersAdv(QImage * sur, PlayerColor player)
std::shared_ptr<Animation> Graphics::getAnimation(const CGObjectInstance* obj)
{
if(obj->ID == Obj::HERO)
return getHeroAnimation(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)
{
//the only(?) invisible object

View File

@ -78,6 +78,7 @@ public:
std::shared_ptr<Animation> getAnimation(const CGObjectInstance * obj);
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;

View File

@ -524,7 +524,9 @@ void MainWindow::loadObjectsTree()
addGroupIntoCatalog("MISC", true, false, Obj::FREELANCERS_GUILD);
addGroupIntoCatalog("MISC", true, false, Obj::SANCTUARY);
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", false, false, Obj::RANDOM_ART);
addGroupIntoCatalog("ARTIFACTS", false, false, Obj::RANDOM_TREASURE_ART);

View File

@ -341,6 +341,16 @@ void MapController::commitObjectCreate(int level)
main->setStatusMessage(QString("Reached map limit for object %1 - %2").arg(typeName, subTypeName));
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);

View File

@ -177,7 +177,7 @@ void MapHandler::initObjectRects()
if(animation->size(0) == 0)
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 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)
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
@ -264,19 +264,20 @@ std::shared_ptr<QImage> MapHandler::findFlagBitmapInternal(std::shared_ptr<Anima
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();
// normal object
std::shared_ptr<Animation> animation = graphics->getAnimation(obj);
size_t groupSize = animation->size();
size_t groupSize = animation->size(group);
if(groupSize == 0)
return MapHandler::AnimBitmapHolder();
animation->playerColored(obj->tempOwner);
auto bitmap = animation->getImage(anim % groupSize);
auto bitmap = animation->getImage(anim % groupSize, group);
if(!bitmap)
return MapHandler::AnimBitmapHolder();
@ -303,16 +304,20 @@ void MapHandler::drawObjects(QPainter & painter, int x, int y, int z)
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)
{
auto pos = obj->getPosition();
painter.drawImage(QPoint(x * tileSize, y * tileSize), *objData.objBitmap, object.rect);
if(objData.flagBitmap)
{
if (obj->pos.x == pos.x && obj->pos.y == pos.y)
painter.drawImage(QPoint(x * tileSize, y * tileSize), *objData.flagBitmap, object.rect);
if (x == pos.x - 1 && y == pos.y - 1)
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;
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)
{
auto pos = obj->getPosition();
painter.drawImage(pos.x * tileSize - object.rect.x(), pos.y * tileSize - object.rect.y(), *objData.objBitmap);
if (objData.flagBitmap)
{
if (obj->pos.x == pos.x && obj->pos.y == pos.y)
{
painter.drawImage(pos.x * tileSize - object.rect.x(), pos.y * tileSize - object.rect.y(), *objData.flagBitmap);
}
if(object.rect.x() == pos.x && object.rect.y() == pos.y)
painter.drawImage(pos.x * tileSize, pos.y * tileSize, *objData.flagBitmap);
}
}
}
@ -356,14 +363,19 @@ void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj,
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)
{
painter.drawImage(QPoint((x + 1) * 32 - objData.objBitmap->width(), (y + 1) * 32 - objData.objBitmap->height()), *objData.objBitmap);
if (objData.flagBitmap)
{
painter.drawImage(QPoint((x + 1) * 32 - objData.objBitmap->width(), (y + 1) * 32 - objData.objBitmap->height()), *objData.flagBitmap);
}
painter.drawImage(QPoint((x - 1) * 32, (y - 1) * 32), *objData.flagBitmap);
}
}
@ -433,7 +445,7 @@ void MapHandler::invalidate(CGObjectInstance * obj)
if(!animation || animation->size(0) == 0)
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 fy=0; fy < obj->getHeight(); ++fy)

View File

@ -44,8 +44,8 @@ private:
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> findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int group) const;
AnimBitmapHolder findObjectBitmap(const CGObjectInstance * obj, int anim) const;
std::shared_ptr<QImage> findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor color, int group) 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
typedef std::map<std::string, std::shared_ptr<Animation>> TFlippedAnimations; //[type, rotation]