Browse Source

Merge pull request #5032 from dydzio0614/alt-creature-buttons

Exchange full army by holding alt while pressing VCMI extras creature arrow button
Ivan Savenko 10 months ago
parent
commit
7543635847

+ 4 - 0
client/widgets/CExchangeController.cpp

@@ -79,6 +79,10 @@ void CExchangeController::moveArmy(bool leftToRight, std::optional<SlotID> heldS
 			});
 		heldSlot = weakestSlot->first;
 	}
+	
+	if (source->getCreature(heldSlot.value()) == nullptr)
+		return;
+
 	LOCPLINT->cb->bulkMoveArmy(source->id, target->id, heldSlot.value());
 }
 

+ 10 - 2
client/windows/CExchangeWindow.cpp

@@ -248,7 +248,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
 					Point(484 + 35 * i, 154),
 					AnimationPath::builtin("quick-exchange/unitLeft.DEF"),
 					CButton::tooltip(CGI->generaltexth->translate("vcmi.quickExchange.moveUnit")),
-					std::bind(&CExchangeController::moveStack, &controller, false, SlotID(i))));
+					[this, i]() { creatureArrowButtonCallback(false, SlotID(i)); }));
 			moveUnitFromRightToLeftButtons.back()->block(leftHeroBlock);
 
 			moveUnitFromLeftToRightButtons.push_back(
@@ -256,7 +256,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
 					Point(66 + 35 * i, 154),
 					AnimationPath::builtin("quick-exchange/unitRight.DEF"),
 					CButton::tooltip(CGI->generaltexth->translate("vcmi.quickExchange.moveUnit")),
-					std::bind(&CExchangeController::moveStack, &controller, true, SlotID(i))));
+					[this, i]() { creatureArrowButtonCallback(true, SlotID(i)); }));
 			moveUnitFromLeftToRightButtons.back()->block(rightHeroBlock);
 		}
 	}
@@ -264,6 +264,14 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
 	CExchangeWindow::update();
 }
 
+void CExchangeWindow::creatureArrowButtonCallback(bool leftToRight, SlotID slotId)
+{
+	if (GH.isKeyboardAltDown())
+		controller.moveArmy(leftToRight, slotId);
+	else
+		controller.moveStack(leftToRight, slotId);
+}
+
 void CExchangeWindow::moveArtifactsCallback(bool leftToRight)
 {
 	bool moveEquipped = !GH.isKeyboardShiftDown();

+ 1 - 0
client/windows/CExchangeWindow.h

@@ -54,6 +54,7 @@ class CExchangeWindow : public CStatusbarWindow, public IGarrisonHolder, public
 	std::shared_ptr<CButton> backpackButtonRight;
 	CExchangeController controller;
 
+	void creatureArrowButtonCallback(bool leftToRight, SlotID slotID);
 	void moveArtifactsCallback(bool leftToRight);
 	void swapArtifactsCallback();
 	void moveUnitsShortcut(bool leftToRight);