1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-30 08:57:00 +02:00

Pass pointer to actual caller in showBlockingDialog callWith

Fixes activation of all rewardable buildings in town on blocking dialog
answer
This commit is contained in:
Ivan Savenko 2024-09-04 15:14:56 +00:00
parent d34b4a141e
commit b09d9d501b
17 changed files with 28 additions and 31 deletions

View File

@ -164,7 +164,7 @@ public:
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill which, si64 val, bool abs = false) override {};
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs = false) override {};
void showBlockingDialog(BlockingDialog * iw) override {};
void showBlockingDialog(const IObjectInterface * caller, BlockingDialog * iw) override {};
void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) override {};
void showTeleportDialog(TeleportDialog * iw) override {};
void showObjectWindow(const CGObjectInstance * object, EOpenWindowMode window, const CGHeroInstance * visitor, bool addQuery) override {};

View File

@ -33,6 +33,7 @@ class CStackBasicDescriptor;
class CGCreature;
class CSaveFile;
class CLoadFile;
class IObjectInterface;
enum class EOpenWindowMode : uint8_t;
namespace spells
@ -98,7 +99,7 @@ public:
virtual void giveExperience(const CGHeroInstance * hero, TExpType val) =0;
virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill which, si64 val, bool abs=false)=0;
virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0;
virtual void showBlockingDialog(BlockingDialog *iw) =0;
virtual void showBlockingDialog(const IObjectInterface * caller, BlockingDialog *iw) =0;
virtual void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) =0; //cb will be called when player closes garrison window
virtual void showTeleportDialog(TeleportDialog *iw) =0;
virtual void showObjectWindow(const CGObjectInstance * object, EOpenWindowMode window, const CGHeroInstance * visitor, bool addQuery) = 0;

View File

@ -178,7 +178,7 @@ void CBank::onHeroVisit(const CGHeroInstance * h) const
if (banktext == 32)
bd.text.replaceRawString(getObjectName());
cb->showBlockingDialog(&bd);
cb->showBlockingDialog(this, &bd);
}
void CBank::doVisit(const CGHeroInstance * hero) const

View File

@ -164,7 +164,7 @@ void CGCreature::onHeroVisit( const CGHeroInstance * h ) const
ynd.player = h->tempOwner;
ynd.text.appendLocalString(EMetaText::ADVOB_TXT, 86);
ynd.text.replaceName(getCreature(), getStackCount(SlotID(0)));
cb->showBlockingDialog(&ynd);
cb->showBlockingDialog(this, &ynd);
break;
}
default: //join for gold
@ -180,7 +180,7 @@ void CGCreature::onHeroVisit( const CGHeroInstance * h ) const
boost::algorithm::replace_first(tmp, "%d", std::to_string(action));
boost::algorithm::replace_first(tmp,"%s",VLC->creatures()->getById(getCreature())->getNamePluralTranslated());
ynd.text.appendRawString(tmp);
cb->showBlockingDialog(&ynd);
cb->showBlockingDialog(this, &ynd);
break;
}
}
@ -475,7 +475,7 @@ void CGCreature::flee( const CGHeroInstance * h ) const
ynd.player = h->tempOwner;
ynd.text.appendLocalString(EMetaText::ADVOB_TXT,91);
ynd.text.replaceName(getCreature(), getStackCount(SlotID(0)));
cb->showBlockingDialog(&ynd);
cb->showBlockingDialog(this, &ynd);
}
void CGCreature::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const

View File

@ -244,7 +244,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
else
bd.text.replaceLocalString(EMetaText::ARRAY_TXT, 173 + (int)Slots().begin()->second->getQuantityID()*3);
bd.text.replaceName(*Slots().begin()->second);
cb->showBlockingDialog(&bd);
cb->showBlockingDialog(this, &bd);
return;
}
@ -280,7 +280,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
bd.flags |= BlockingDialog::SAFE_TO_AUTOACCEPT;
}
cb->showBlockingDialog(&bd);
cb->showBlockingDialog(this, &bd);
}
void CGDwelling::newTurn(vstd::RNG & rand) const

View File

@ -175,7 +175,7 @@ void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
BlockingDialog bd (true, false);
bd.player = h->getOwner();
bd.text.appendLocalString(EMetaText::ADVOB_TXT, 14);
cb->showBlockingDialog(&bd);
cb->showBlockingDialog(this, &bd);
}
void CGPandoraBox::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const

View File

@ -301,12 +301,6 @@ void CGTownInstance::setOwner(const PlayerColor & player) const
cb->setOwner(this, player);
}
void CGTownInstance::blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const
{
for (auto building : rewardableBuildings)
building.second->blockingDialogAnswered(hero, answer); // FIXME: why call for every building?
}
void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
{
if(cb->gameState()->getPlayerRelations( getOwner(), h->getOwner() ) == PlayerRelations::ENEMIES)

View File

@ -239,7 +239,6 @@ public:
protected:
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
void serializeJsonOptions(JsonSerializeFormat & handler) override;
void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
private:
FactionID randomizeFaction(vstd::RNG & rand);

View File

@ -851,7 +851,7 @@ void CGBorderGuard::onHeroVisit(const CGHeroInstance * h) const
BlockingDialog bd (true, false);
bd.player = h->getOwner();
bd.text.appendLocalString (EMetaText::ADVOB_TXT, 17);
cb->showBlockingDialog (&bd);
cb->showBlockingDialog (this, &bd);
}
else
{

View File

@ -52,7 +52,7 @@ void CRewardableObject::selectRewardWithMessage(const CGHeroInstance * contextHe
sd.player = contextHero->tempOwner;
sd.text = dialog;
sd.components = loadComponents(contextHero, rewardIndices);
cb->showBlockingDialog(&sd);
cb->showBlockingDialog(this, &sd);
}

View File

@ -88,7 +88,7 @@ void CGMine::onHeroVisit( const CGHeroInstance * h ) const
BlockingDialog ynd(true,false);
ynd.player = h->tempOwner;
ynd.text.appendLocalString(EMetaText::ADVOB_TXT, isAbandoned() ? 84 : 187);
cb->showBlockingDialog(&ynd);
cb->showBlockingDialog(this, &ynd);
return;
}
@ -310,7 +310,7 @@ void CGResource::onHeroVisit( const CGHeroInstance * h ) const
BlockingDialog ynd(true,false);
ynd.player = h->getOwner();
ynd.text = message;
cb->showBlockingDialog(&ynd);
cb->showBlockingDialog(this, &ynd);
}
else
{
@ -879,7 +879,7 @@ void CGArtifact::onHeroVisit(const CGHeroInstance * h) const
ynd.text.replaceRawString(getArmyDescription());
ynd.text.replaceLocalString(EMetaText::GENERAL_TXT, 43); // creatures
}
cb->showBlockingDialog(&ynd);
cb->showBlockingDialog(this, &ynd);
}
break;
case Obj::SPELL_SCROLL:
@ -889,7 +889,7 @@ void CGArtifact::onHeroVisit(const CGHeroInstance * h) const
BlockingDialog ynd(true,false);
ynd.player = h->getOwner();
ynd.text = message;
cb->showBlockingDialog(&ynd);
cb->showBlockingDialog(this, &ynd);
}
else
blockingDialogAnswered(h, true);

View File

@ -221,7 +221,7 @@ void TownRewardableBuildingInstance::onHeroVisit(const CGHeroInstance *h) const
if (rewards.size() == 1)
configuration.info.at(rewards.front()).reward.loadComponents(sd.components, h);
cb->showBlockingDialog(&sd);
cb->showBlockingDialog(this, &sd);
};
if(!town->hasBuilt(getBuildingType()))

View File

@ -1078,9 +1078,9 @@ void CGameHandler::setOwner(const CGObjectInstance * obj, const PlayerColor owne
}
}
void CGameHandler::showBlockingDialog(BlockingDialog *iw)
void CGameHandler::showBlockingDialog(const IObjectInterface * caller, BlockingDialog *iw)
{
auto dialogQuery = std::make_shared<CBlockingDialogQuery>(this, *iw);
auto dialogQuery = std::make_shared<CBlockingDialogQuery>(this, caller, *iw);
queries->addQuery(dialogQuery);
iw->queryID = dialogQuery->queryID;
sendToAllClients(iw);

View File

@ -113,7 +113,7 @@ public:
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill which, si64 val, bool abs=false) override;
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override;
void showBlockingDialog(BlockingDialog *iw) override;
void showBlockingDialog(const IObjectInterface * caller, BlockingDialog *iw) override;
void showTeleportDialog(TeleportDialog *iw) override;
void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) override;
void showObjectWindow(const CGObjectInstance * object, EOpenWindowMode window, const CGHeroInstance * visitor, bool addQuery) override;

View File

@ -120,11 +120,12 @@ bool CGarrisonDialogQuery::blocksPack(const CPack * pack) const
void CBlockingDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
{
assert(answer);
visitedObject->blockingDialogAnswered(visitingHero, *answer);
caller->blockingDialogAnswered(visitingHero, *answer);
}
CBlockingDialogQuery::CBlockingDialogQuery(CGameHandler * owner, const BlockingDialog & bd):
CDialogQuery(owner)
CBlockingDialogQuery::CBlockingDialogQuery(CGameHandler * owner, const IObjectInterface * caller, const BlockingDialog & bd):
CDialogQuery(owner),
caller(caller)
{
this->bd = bd;
addPlayer(bd.player);

View File

@ -15,6 +15,7 @@
VCMI_LIB_NAMESPACE_BEGIN
class CGHeroInstance;
class CGObjectInstance;
class IObjectInterface;
VCMI_LIB_NAMESPACE_END
//Created when player starts turn or when player puts game on [ause
@ -60,9 +61,10 @@ public:
class CBlockingDialogQuery : public CDialogQuery
{
public:
const IObjectInterface * caller;
BlockingDialog bd; //copy of pack... debug purposes
CBlockingDialogQuery(CGameHandler * owner, const BlockingDialog &bd);
CBlockingDialogQuery(CGameHandler * owner, const IObjectInterface * caller, const BlockingDialog &bd);
void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override;
};

View File

@ -50,7 +50,7 @@ public:
void giveExperience(const CGHeroInstance * hero, TExpType val) override {}
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill which, si64 val, bool abs=false) override {}
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override {}
void showBlockingDialog(BlockingDialog *iw) override {}
void showBlockingDialog(const IObjectInterface * caller, BlockingDialog *iw) override {}
void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) override {} //cb will be called when player closes garrison window
void showTeleportDialog(TeleportDialog *iw) override {}
void showObjectWindow(const CGObjectInstance * object, EOpenWindowMode window, const CGHeroInstance * visitor, bool addQuery) override {};