Try to reuse existing logic for Eagle Eye dialog

This commit is contained in:
George King
2026-05-26 23:44:36 +02:00
committed by GitHub
parent 75367c7e25
commit ab6822250d
+12 -26
View File
@@ -117,6 +117,16 @@ void callBattleInterfaceIfPresentForBothSides(CClient & cl, const BattleID & bat
}
}
static void showEagleEyeLearnedSpellsDialog(CClient & cl, ObjectInstanceID heroId, const std::set<SpellID> & spells, PlayerColor player)
{
if(spells.empty())
return;
const auto * hero = cl.gameInfo().getHero(heroId);
assert(hero);
callInterfaceIfPresent(cl, player, &CGameInterface::showInfoDialog, EInfoWindowMode::AUTO, UIHelper::getEagleEyeInfoWindowText(*hero, spells), UIHelper::getSpellsComponents(spells), soundBase::soundID(0));
}
void ApplyClientNetPackVisitor::visitSetResources(SetResources & pack)
{
//todo: inform on actual resource set transferred
@@ -595,28 +605,10 @@ void ApplyClientNetPackVisitor::visitChangeSpells(ChangeSpells & pack)
if(!hero)
return;
bool heroInBattle = false;
for(const auto & battlePtr : gs.currentBattles)
{
if(!battlePtr)
continue;
const auto * attackerHero = battlePtr->battleGetFightingHero(BattleSide::ATTACKER);
const auto * defenderHero = battlePtr->battleGetFightingHero(BattleSide::DEFENDER);
if((attackerHero && attackerHero->id == pack.hid) || (defenderHero && defenderHero->id == pack.hid))
{
heroInBattle = true;
break;
}
}
if(!heroInBattle)
return;
if(hero->valOfBonuses(BonusType::LEARN_BATTLE_SPELL_CHANCE_PRE_BATTLE) <= 0)
return;
callInterfaceIfPresent(cl, hero->tempOwner, &CGameInterface::showInfoDialog, EInfoWindowMode::AUTO, UIHelper::getEagleEyeInfoWindowText(*hero, pack.spells), UIHelper::getSpellsComponents(pack.spells), soundBase::soundID(0));
showEagleEyeLearnedSpellsDialog(cl, pack.hid, pack.spells, hero->tempOwner);
}
void ApplyClientNetPackVisitor::visitSetHeroesInTown(SetHeroesInTown & pack)
@@ -869,13 +861,7 @@ void ApplyClientNetPackVisitor::visitStacksInjured(StacksInjured & pack)
void ApplyClientNetPackVisitor::visitBattleResultsApplied(BattleResultsApplied & pack)
{
if(!pack.learnedSpells.spells.empty())
{
const auto * hero = cl.gameInfo().getHero(pack.learnedSpells.hid);
assert(hero);
callInterfaceIfPresent(cl, pack.victor, &CGameInterface::showInfoDialog, EInfoWindowMode::MODAL,
UIHelper::getEagleEyeInfoWindowText(*hero, pack.learnedSpells.spells), UIHelper::getSpellsComponents(pack.learnedSpells.spells), soundBase::soundID(0));
}
showEagleEyeLearnedSpellsDialog(cl, pack.learnedSpells.hid, pack.learnedSpells.spells, pack.victor);
if(!pack.movingArtifacts.empty())
{