1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Merge pull request #1176 from IvanSavenko/tower_shooter_icons

Tower shooter icons fix
This commit is contained in:
Andrii Danylchenko
2022-12-01 12:30:24 +02:00
committed by GitHub
30 changed files with 99 additions and 35 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

View File

@@ -2,7 +2,7 @@
"name" : "VCMI essential files", "name" : "VCMI essential files",
"description" : "Essential files required for VCMI to run correctly", "description" : "Essential files required for VCMI to run correctly",
"version" : "0.99", "version" : "1.0",
"author" : "VCMI Team", "author" : "VCMI Team",
"contact" : "http://forum.vcmi.eu/index.php", "contact" : "http://forum.vcmi.eu/index.php",
"modType" : "Graphical", "modType" : "Graphical",

View File

@@ -429,11 +429,13 @@ void Graphics::loadErmuToPicture()
assert (etp_idx == 44); assert (etp_idx == 44);
} }
void Graphics::addImageListEntry(size_t index, const std::string & listName, const std::string & imageName) void Graphics::addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName)
{ {
if (!imageName.empty()) if (!imageName.empty())
{ {
JsonNode entry; JsonNode entry;
if (group != 0)
entry["group"].Integer() = group;
entry["frame"].Integer() = index; entry["frame"].Integer() = index;
entry["file"].String() = imageName; entry["file"].String() = imageName;
@@ -443,7 +445,7 @@ void Graphics::addImageListEntry(size_t index, const std::string & listName, con
void Graphics::addImageListEntries(const EntityService * service) void Graphics::addImageListEntries(const EntityService * service)
{ {
auto cb = std::bind(&Graphics::addImageListEntry, this, _1, _2, _3); auto cb = std::bind(&Graphics::addImageListEntry, this, _1, _2, _3, _4);
auto loopCb = [&](const Entity * entity, bool & stop) auto loopCb = [&](const Entity * entity, bool & stop)
{ {

View File

@@ -38,7 +38,7 @@ enum EFonts
/// Handles fonts, hero images, town images, various graphics /// Handles fonts, hero images, town images, various graphics
class Graphics class Graphics
{ {
void addImageListEntry(size_t index, const std::string & listName, const std::string & imageName); void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
void addImageListEntries(const EntityService * service); void addImageListEntries(const EntityService * service);

View File

@@ -156,7 +156,6 @@ CBattleInterface::CBattleInterface(const CCreatureSet *army1, const CCreatureSet
queue->moveTo(Point(pos.x, pos.y - queue->pos.h)); queue->moveTo(Point(pos.x, pos.y - queue->pos.h));
} }
queue->update();
//preparing siege info //preparing siege info
const CGTownInstance *town = curInt->cb->battleGetDefendedTown(); const CGTownInstance *town = curInt->cb->battleGetDefendedTown();
@@ -423,6 +422,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet *army1, const CCreatureSet
currentAction = PossiblePlayerBattleAction::INVALID; currentAction = PossiblePlayerBattleAction::INVALID;
selectedAction = PossiblePlayerBattleAction::INVALID; selectedAction = PossiblePlayerBattleAction::INVALID;
addUsedEvents(RCLICK | MOVE | KEYBOARD); addUsedEvents(RCLICK | MOVE | KEYBOARD);
queue->update();
blockUI(true); blockUI(true);
} }

View File

@@ -59,6 +59,7 @@ struct ProjectileInfo;
class CClickableHex; class CClickableHex;
class CAnimation; class CAnimation;
class IImage; class IImage;
class CStackQueue;
/// Small struct which contains information about the id of the attacked stack, the damage dealt,... /// Small struct which contains information about the id of the attacked stack, the damage dealt,...
struct StackAttackedInfo struct StackAttackedInfo
@@ -396,7 +397,7 @@ public:
friend class CPlayerInterface; friend class CPlayerInterface;
friend class CButton; friend class CButton;
friend class CInGameConsole; friend class CInGameConsole;
friend class CStackQueue;
friend class CBattleResultWindow; friend class CBattleResultWindow;
friend class CBattleHero; friend class CBattleHero;
friend class CEffectAnimation; friend class CEffectAnimation;

View File

@@ -763,7 +763,13 @@ void CStackQueue::update()
stackBoxes[boxIndex]->setUnit(nullptr); stackBoxes[boxIndex]->setUnit(nullptr);
} }
CStackQueue::StackBox::StackBox(CStackQueue * owner) int32_t CStackQueue::getSiegeShooterIconID()
{
return owner->siegeH->town->town->faction->index;
}
CStackQueue::StackBox::StackBox(CStackQueue * owner):
owner(owner)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
background = std::make_shared<CPicture>(owner->embedded ? "StackQueueSmall" : "StackQueueLarge"); background = std::make_shared<CPicture>(owner->embedded ? "StackQueueSmall" : "StackQueueLarge");
@@ -795,7 +801,16 @@ void CStackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
{ {
background->colorize(unit->unitOwner()); background->colorize(unit->unitOwner());
icon->visible = true; icon->visible = true;
icon->setFrame(unit->creatureIconIndex());
// temporary code for mod compatibility:
// first, set icon that should definitely exist (arrow tower icon in base vcmi mod)
// second, try to switch to icon that should be provided by mod
// if mod is not up to date and does have arrow tower icon yet - second setFrame call will fail and retain previously set image
// for 1.2 release & later next line should be moved into 'else' block
icon->setFrame(unit->creatureIconIndex(), 0);
if (unit->unitType()->idNumber == CreatureID::ARROW_TOWERS)
icon->setFrame(owner->getSiegeShooterIconID(), 1);
amount->setText(makeNumberShort(unit->getCount())); amount->setText(makeNumberShort(unit->getCount()));
if(stateIcon) if(stateIcon)

View File

@@ -157,6 +157,7 @@ class CStackQueue : public CIntObject
{ {
class StackBox : public CIntObject class StackBox : public CIntObject
{ {
CStackQueue * owner;
public: public:
std::shared_ptr<CPicture> background; std::shared_ptr<CPicture> background;
std::shared_ptr<CAnimImage> icon; std::shared_ptr<CAnimImage> icon;
@@ -175,6 +176,7 @@ class CStackQueue : public CIntObject
std::shared_ptr<CAnimation> icons; std::shared_ptr<CAnimation> icons;
std::shared_ptr<CAnimation> stateIcons; std::shared_ptr<CAnimation> stateIcons;
int32_t getSiegeShooterIconID();
public: public:
const bool embedded; const bool embedded;

View File

@@ -123,6 +123,8 @@
}, },
"graphics" : "graphics" :
{ {
"iconSmall" : "vcmi/creatureIcons/towerSmall",
"iconLarge" : "vcmi/creatureIcons/towerLarge",
"animation": "CLCBOW.DEF" // needed to pass validation, never used "animation": "CLCBOW.DEF" // needed to pass validation, never used
}, },
"sound": {} "sound": {}

View File

@@ -203,6 +203,8 @@
"siege" : "siege" :
{ {
"shooter" : "archer", "shooter" : "archer",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"imagePrefix" : "SGCS", "imagePrefix" : "SGCS",
"gate" : "gate" :
{ {

View File

@@ -210,6 +210,8 @@
"siege" : "siege" :
{ {
"shooter" : "stormElemental", "shooter" : "stormElemental",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"imagePrefix" : "SGEL", "imagePrefix" : "SGEL",
"gate" : "gate" :
{ {

View File

@@ -204,6 +204,8 @@
"siege" : "siege" :
{ {
"shooter" : "medusa", "shooter" : "medusa",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"imagePrefix" : "SGDN", "imagePrefix" : "SGDN",
"gate" : "gate" :
{ {

View File

@@ -209,6 +209,8 @@
"siege" : "siege" :
{ {
"shooter" : "lizardman", "shooter" : "lizardman",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"imagePrefix" : "SGFR", "imagePrefix" : "SGFR",
"gate" : "gate" :
{ {

View File

@@ -204,6 +204,8 @@
"siege" : "siege" :
{ {
"shooter" : "gog", "shooter" : "gog",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"imagePrefix" : "SGIN", "imagePrefix" : "SGIN",
"gate" : "gate" :
{ {

View File

@@ -214,6 +214,8 @@
"siege" : "siege" :
{ {
"shooter" : "lich", "shooter" : "lich",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"imagePrefix" : "SGNC", "imagePrefix" : "SGNC",
"gate" : "gate" :
{ {

View File

@@ -211,6 +211,8 @@
"siege" : "siege" :
{ {
"shooter" : "woodElf", "shooter" : "woodElf",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"imagePrefix" : "SGRM", "imagePrefix" : "SGRM",
"gate" : "gate" :
{ {

View File

@@ -203,6 +203,8 @@
{ {
"shooter" : "orc", "shooter" : "orc",
"imagePrefix" : "SGST", "imagePrefix" : "SGST",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"gate" : "gate" :
{ {
"arch" : { "x" : 478, "y" : 235 }, "arch" : { "x" : 478, "y" : 235 },

View File

@@ -202,6 +202,8 @@
"siege" : "siege" :
{ {
"shooter" : "mage", "shooter" : "mage",
"towerIconSmall" : "vcmi/creatureIcons/towerSmall",
"towerIconLarge" : "vcmi/creatureIcons/towerLarge",
"imagePrefix" : "SGTW", "imagePrefix" : "SGTW",
"gate" : "gate" :
{ {

View File

@@ -6,6 +6,7 @@
"description" : "Format used to define town siege screen in VCMI", "description" : "Format used to define town siege screen in VCMI",
"required" : [ "required" : [
"gate", "imagePrefix", "moat", "shooter", "gate", "imagePrefix", "moat", "shooter",
"towerIconLarge", "towerIconSmall",
"static", "towers", "walls" "static", "towers", "walls"
], ],
@@ -80,6 +81,16 @@
"type":"string", "type":"string",
"description" : "Identifier of creature that will be used as tower shooter" "description" : "Identifier of creature that will be used as tower shooter"
}, },
"towerIconSmall": {
"type":"string",
"description": "Small icon for tower, used in battle queue",
"format" : "imageFile"
},
"towerIconLarge": {
"type":"string",
"description": "Large icon for tower, used in battle queue",
"format" : "imageFile"
},
"static": { "static": {
"type":"object", "type":"object",
"additionalProperties" : false, "additionalProperties" : false,

View File

@@ -17,7 +17,7 @@ class IBonusBearer;
class DLL_LINKAGE Entity class DLL_LINKAGE Entity
{ {
public: public:
using IconRegistar = std::function<void(int32_t index, const std::string & listName, const std::string & imageName)>; using IconRegistar = std::function<void(int32_t index, int32_t group, const std::string & listName, const std::string & imageName)>;
virtual ~Entity() = default; virtual ~Entity() = default;

View File

@@ -72,8 +72,8 @@ const std::string & CArtifact::getJsonKey() const
void CArtifact::registerIcons(const IconRegistar & cb) const void CArtifact::registerIcons(const IconRegistar & cb) const
{ {
cb(getIconIndex(), "ARTIFACT", image); cb(getIconIndex(), 0, "ARTIFACT", image);
cb(getIconIndex(), "ARTIFACTLARGE", large); cb(getIconIndex(), 0, "ARTIFACTLARGE", large);
} }
ArtifactID CArtifact::getId() const ArtifactID CArtifact::getId() const

View File

@@ -46,8 +46,8 @@ const std::string & CCreature::getJsonKey() const
void CCreature::registerIcons(const IconRegistar & cb) const void CCreature::registerIcons(const IconRegistar & cb) const
{ {
cb(getIconIndex(), "CPRSMALL", smallIconName); cb(getIconIndex(), 0, "CPRSMALL", smallIconName);
cb(getIconIndex(), "TWCRPORT", largeIconName); cb(getIconIndex(), 0, "TWCRPORT", largeIconName);
} }
CreatureID CCreature::getId() const CreatureID CCreature::getId() const

View File

@@ -59,10 +59,10 @@ HeroTypeID CHero::getId() const
void CHero::registerIcons(const IconRegistar & cb) const void CHero::registerIcons(const IconRegistar & cb) const
{ {
cb(getIconIndex(), "UN32", iconSpecSmall); cb(getIconIndex(), 0, "UN32", iconSpecSmall);
cb(getIconIndex(), "UN44", iconSpecLarge); cb(getIconIndex(), 0, "UN44", iconSpecLarge);
cb(getIconIndex(), "PORTRAITSLARGE", portraitLarge); cb(getIconIndex(), 0, "PORTRAITSLARGE", portraitLarge);
cb(getIconIndex(), "PORTRAITSSMALL", portraitSmall); cb(getIconIndex(), 0, "PORTRAITSSMALL", portraitSmall);
} }
void CHero::updateFrom(const JsonNode & data) void CHero::updateFrom(const JsonNode & data)

View File

@@ -70,9 +70,9 @@ void CSkill::registerIcons(const IconRegistar & cb) const
{ {
int frame = 2 + level + 3 * id; int frame = 2 + level + 3 * id;
const LevelInfo & skillAtLevel = at(level); const LevelInfo & skillAtLevel = at(level);
cb(frame, "SECSK32", skillAtLevel.iconSmall); cb(frame, 0, "SECSK32", skillAtLevel.iconSmall);
cb(frame, "SECSKILL", skillAtLevel.iconMedium); cb(frame, 0, "SECSKILL", skillAtLevel.iconMedium);
cb(frame, "SECSK82", skillAtLevel.iconLarge); cb(frame, 0, "SECSK82", skillAtLevel.iconLarge);
} }
} }

View File

@@ -126,15 +126,19 @@ void CFaction::registerIcons(const IconRegistar & cb) const
if(town) if(town)
{ {
auto & info = town->clientInfo; auto & info = town->clientInfo;
cb(info.icons[0][0], "ITPT", info.iconLarge[0][0]); cb(info.icons[0][0], 0, "ITPT", info.iconLarge[0][0]);
cb(info.icons[0][1], "ITPT", info.iconLarge[0][1]); cb(info.icons[0][1], 0, "ITPT", info.iconLarge[0][1]);
cb(info.icons[1][0], "ITPT", info.iconLarge[1][0]); cb(info.icons[1][0], 0, "ITPT", info.iconLarge[1][0]);
cb(info.icons[1][1], "ITPT", info.iconLarge[1][1]); cb(info.icons[1][1], 0, "ITPT", info.iconLarge[1][1]);
cb(info.icons[0][0] + 2, 0, "ITPA", info.iconSmall[0][0]);
cb(info.icons[0][1] + 2, 0, "ITPA", info.iconSmall[0][1]);
cb(info.icons[1][0] + 2, 0, "ITPA", info.iconSmall[1][0]);
cb(info.icons[1][1] + 2, 0, "ITPA", info.iconSmall[1][1]);
cb(index, 1, "CPRSMALL", info.towerIconSmall);
cb(index, 1, "TWCRPORT", info.towerIconLarge);
cb(info.icons[0][0] + 2, "ITPA", info.iconSmall[0][0]);
cb(info.icons[0][1] + 2, "ITPA", info.iconSmall[0][1]);
cb(info.icons[1][0] + 2, "ITPA", info.iconSmall[1][0]);
cb(info.icons[1][1] + 2, "ITPA", info.iconSmall[1][1]);
} }
} }
@@ -755,6 +759,9 @@ CTown::ClientInfo::Point JsonToPoint(const JsonNode & node)
void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source) void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source)
{ {
town.clientInfo.siegePrefix = source["imagePrefix"].String(); town.clientInfo.siegePrefix = source["imagePrefix"].String();
town.clientInfo.towerIconSmall = source["towerIconSmall"].String();
town.clientInfo.towerIconLarge = source["towerIconLarge"].String();
VLC->modh->identifiers.requestIdentifier("creature", source["shooter"], [&town](si32 creature) VLC->modh->identifiers.requestIdentifier("creature", source["shooter"], [&town](si32 creature)
{ {
auto crId = CreatureID(creature); auto crId = CreatureID(creature);

View File

@@ -303,6 +303,8 @@ public:
std::string siegePrefix; std::string siegePrefix;
std::vector<Point> siegePositions; std::vector<Point> siegePositions;
CreatureID siegeShooter; // shooter creature ID CreatureID siegeShooter; // shooter creature ID
std::string towerIconSmall;
std::string towerIconLarge;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@@ -321,6 +323,8 @@ public:
h & siegePrefix; h & siegePrefix;
h & siegePositions; h & siegePositions;
h & siegeShooter; h & siegeShooter;
h & towerIconSmall;
h & towerIconLarge;
} }
} clientInfo; } clientInfo;

View File

@@ -505,10 +505,10 @@ std::unique_ptr<spells::Mechanics> CSpell::battleMechanics(const spells::IBattle
void CSpell::registerIcons(const IconRegistar & cb) const void CSpell::registerIcons(const IconRegistar & cb) const
{ {
cb(getIndex(), "SPELLS", iconBook); cb(getIndex(), 0, "SPELLS", iconBook);
cb(getIndex()+1, "SPELLINT", iconEffect); cb(getIndex()+1, 0, "SPELLINT", iconEffect);
cb(getIndex(), "SPELLBON", iconScenarioBonus); cb(getIndex(), 0, "SPELLBON", iconScenarioBonus);
cb(getIndex(), "SPELLSCR", iconScroll); cb(getIndex(), 0, "SPELLSCR", iconScroll);
} }
void CSpell::updateFrom(const JsonNode & data) void CSpell::updateFrom(const JsonNode & data)

View File

@@ -310,11 +310,13 @@ std::shared_ptr<Animation> Graphics::getAnimation(const std::shared_ptr<const Ob
return ret; return ret;
} }
void Graphics::addImageListEntry(size_t index, const std::string & listName, const std::string & imageName) void Graphics::addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName)
{ {
if (!imageName.empty()) if (!imageName.empty())
{ {
JsonNode entry; JsonNode entry;
if(group != 0)
entry["group"].Integer() = group;
entry["frame"].Integer() = index; entry["frame"].Integer() = index;
entry["file"].String() = imageName; entry["file"].String() = imageName;
@@ -324,7 +326,7 @@ void Graphics::addImageListEntry(size_t index, const std::string & listName, con
void Graphics::addImageListEntries(const EntityService * service) void Graphics::addImageListEntries(const EntityService * service)
{ {
auto cb = std::bind(&Graphics::addImageListEntry, this, _1, _2, _3); auto cb = std::bind(&Graphics::addImageListEntry, this, _1, _2, _3, _4);
auto loopCb = [&](const Entity * entity, bool & stop) auto loopCb = [&](const Entity * entity, bool & stop)
{ {

View File

@@ -27,7 +27,7 @@ class JsonNode;
/// Handles fonts, hero images, town images, various graphics /// Handles fonts, hero images, town images, various graphics
class Graphics class Graphics
{ {
void addImageListEntry(size_t index, const std::string & listName, const std::string & imageName); void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
void addImageListEntries(const EntityService * service); void addImageListEntries(const EntityService * service);