1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Army exchange implementation

This commit is contained in:
Andrii Danylchenko 2021-02-11 21:06:47 +02:00 committed by Andrii Danylchenko
parent 2ce73fd4e1
commit 8fa0b30985
2 changed files with 29 additions and 22 deletions

View File

@ -288,10 +288,18 @@ void CAnimImage::showAll(SDL_Surface * to)
if(!visible) if(!visible)
return; return;
if(flags & CShowableAnim::BASE && frame != 0) std::vector<size_t> frames = {frame};
if(auto img = anim->getImage(0, group))
if((flags & CShowableAnim::BASE) && frame != 0)
{
frames.insert(frames.begin(), 0);
}
for(auto targetFrame : frames)
{
if(auto img = anim->getImage(targetFrame, group))
{ {
if (isScaled()) if(isScaled())
{ {
auto scaled = img->scaleFast(float(scaledSize.x) / img->width()); auto scaled = img->scaleFast(float(scaledSize.x) / img->width());
scaled->draw(to, pos.x, pos.y); scaled->draw(to, pos.x, pos.y);
@ -299,16 +307,6 @@ void CAnimImage::showAll(SDL_Surface * to)
else else
img->draw(to, pos.x, pos.y); img->draw(to, pos.x, pos.y);
} }
if(auto img = anim->getImage(frame, group))
{
if (isScaled())
{
auto scaled = img->scaleFast(float(scaledSize.x) / img->width());
scaled->draw(to, pos.x, pos.y);
}
else
img->draw(to, pos.x, pos.y);
} }
} }

View File

@ -812,25 +812,29 @@ std::function<void()> CExchangeController::onMoveArmyToRight()
std::function<void()> CExchangeController::onSwapArmy() std::function<void()> CExchangeController::onSwapArmy()
{ {
return [&]() { return [&]()
auto cb = LOCPLINT->cb; {
std::shared_ptr<CCallback> cb = LOCPLINT->cb;
const TSlots & leftSlots = left->Slots();
const TSlots & rightSlots = right->Slots();
for(SlotID i = SlotID(0); i.validSlot(); i.advance(1)) for(auto i = leftSlots.begin(), j = rightSlots.begin(); i != leftSlots.end() && j != rightSlots.end(); i++, j++)
{ {
if(left->hasStackAtSlot(i) || right->hasStackAtSlot(i)) cb->swapCreatures(left, right, i->first, j->first);
cb->swapCreatures(left, right, SlotID(i), SlotID(i));
} }
}; };
} }
void CExchangeController::hdModQuickExchangeArmy(bool leftToRight) void CExchangeController::hdModQuickExchangeArmy(bool leftToRight)
{ {
auto source = leftToRight ? left : right; const CGHeroInstance * source = leftToRight ? left : right;
auto target = leftToRight ? right : left; const CGHeroInstance * target = leftToRight ? right : left;
auto cb = LOCPLINT->cb; std::shared_ptr<CCallback> cb = LOCPLINT->cb;
boost::thread([=] boost::thread([=]
{ {
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
auto slots = source->Slots(); auto slots = source->Slots();
std::vector<std::pair<SlotID, CStackInstance *>> stacks(slots.begin(), slots.end()); std::vector<std::pair<SlotID, CStackInstance *>> stacks(slots.begin(), slots.end());
@ -839,7 +843,11 @@ void CExchangeController::hdModQuickExchangeArmy(bool leftToRight)
return a.second->type->level > b.second->type->level; return a.second->type->level > b.second->type->level;
}); });
auto originalWaitTillRealize = cb->waitTillRealize;
auto originalUnlockGsWhenWating = cb->unlockGsWhenWaiting;
cb->waitTillRealize = true; cb->waitTillRealize = true;
cb->unlockGsWhenWaiting = true;
for(auto pair : stacks) for(auto pair : stacks)
{ {
@ -866,7 +874,8 @@ void CExchangeController::hdModQuickExchangeArmy(bool leftToRight)
} }
} }
cb->waitTillRealize = false; cb->waitTillRealize = originalWaitTillRealize;
cb->unlockGsWhenWaiting = originalUnlockGsWhenWating;
}); });
} }