1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Add ctrl+click and shift+click behavior for creatures "arrows" - hero exchange

This commit is contained in:
Dydzio 2025-02-15 18:49:12 +01:00
parent 3f390c4aac
commit a6ab76d3ec
3 changed files with 21 additions and 0 deletions

View File

@ -110,6 +110,22 @@ void CExchangeController::moveStack(bool leftToRight, SlotID sourceSlot)
}
}
void CExchangeController::moveSingleStackCreature(bool leftToRight, SlotID sourceSlot, bool forceEmptySlotTarget)
{
const auto source = leftToRight ? left : right;
const auto target = leftToRight ? right : left;
auto creature = source->getCreature(sourceSlot);
if(creature == nullptr || source->stacksCount() == 1)
return;
SlotID targetSlot = forceEmptySlotTarget ? target->getFreeSlot() : target->getSlotFor(creature);
if(targetSlot.validSlot())
{
LOCPLINT->cb->splitStack(source, target, sourceSlot, targetSlot, target->getStackCount(targetSlot) + 1);
}
}
void CExchangeController::swapArtifacts(bool equipped, bool baclpack)
{
LOCPLINT->cb->bulkMoveArtifacts(left->id, right->id, true, equipped, baclpack);

View File

@ -20,6 +20,7 @@ public:
void swapArmy();
void moveArmy(bool leftToRight, std::optional<SlotID> heldSlot);
void moveStack(bool leftToRight, SlotID sourceSlot);
void moveSingleStackCreature(bool leftToRight, SlotID sourceSlot, bool forceEmptySlotTarget);
void swapArtifacts(bool equipped, bool baclpack);
void moveArtifacts(bool leftToRight, bool equipped, bool baclpack);

View File

@ -268,6 +268,10 @@ void CExchangeWindow::creatureArrowButtonCallback(bool leftToRight, SlotID slotI
{
if (GH.isKeyboardAltDown())
controller.moveArmy(leftToRight, slotId);
else if (GH.isKeyboardCtrlDown())
controller.moveSingleStackCreature(leftToRight, slotId, true);
else if (GH.isKeyboardShiftDown())
controller.moveSingleStackCreature(leftToRight, slotId, false);
else
controller.moveStack(leftToRight, slotId);
}