mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Add keyboard shortcuts for quick army management from HD mod.
Just want add fast some really nice shortcuts from HD mod. 1) [LShift] + LClick – splits a half units from the selected stack into an empty slot. WARNING: The second behaviour ("smart split, ignores single creatures") of this HD mod option is not done. 2) [LCtrl] + LClick – splits a single unit from the selected stack into an empty slot. 3) [LCtrl] + [LShift] + LClick – split single units from the selected stack into all empty hero/garrison slots
This commit is contained in:
@@ -281,7 +281,10 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState)
|
|||||||
bool refr = false;
|
bool refr = false;
|
||||||
const CGarrisonSlot * selection = owner->getSelection();
|
const CGarrisonSlot * selection = owner->getSelection();
|
||||||
if(!selection)
|
if(!selection)
|
||||||
|
{
|
||||||
refr = highlightOrDropArtifact();
|
refr = highlightOrDropArtifact();
|
||||||
|
handleSplittingShortcuts();
|
||||||
|
}
|
||||||
else if(selection == this)
|
else if(selection == this)
|
||||||
refr = viewInfo();
|
refr = viewInfo();
|
||||||
// Re-highlight if troops aren't removable or not ours.
|
// Re-highlight if troops aren't removable or not ours.
|
||||||
@@ -396,6 +399,35 @@ CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, CGar
|
|||||||
stackCount->setText(boost::lexical_cast<std::string>(myStack->count));
|
stackCount->setText(boost::lexical_cast<std::string>(myStack->count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGarrisonSlot::splitIntoParts(CGarrisonSlot::EGarrisonType type, int amount, int maxOfSplittedSlots)
|
||||||
|
{
|
||||||
|
owner->pb = type;
|
||||||
|
for(CGarrisonSlot * slot : owner->getEmptySlots(type))
|
||||||
|
{
|
||||||
|
owner->p2 = slot->ID;
|
||||||
|
owner->splitStacks(1, amount);
|
||||||
|
maxOfSplittedSlots--;
|
||||||
|
if(!maxOfSplittedSlots || owner->getSelection()->myStack->count <= 1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGarrisonSlot::handleSplittingShortcuts()
|
||||||
|
{
|
||||||
|
const Uint8 * state = SDL_GetKeyboardState(NULL);
|
||||||
|
if(owner->getSelection() && owner->getEmptySlots(owner->getSelection()->upg).size() && owner->getSelection()->myStack->count > 1){
|
||||||
|
if (state[SDL_SCANCODE_LCTRL] && state[SDL_SCANCODE_LSHIFT])
|
||||||
|
splitIntoParts(owner->getSelection()->upg, 1, 7);
|
||||||
|
else if(state[SDL_SCANCODE_LCTRL])
|
||||||
|
splitIntoParts(owner->getSelection()->upg, 1, 1);
|
||||||
|
else if(state[SDL_SCANCODE_LSHIFT])
|
||||||
|
splitIntoParts(owner->getSelection()->upg, owner->getSelection()->myStack->count/2 , 1);
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
owner->selectSlot(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CGarrisonInt::addSplitBtn(CButton * button)
|
void CGarrisonInt::addSplitBtn(CButton * button)
|
||||||
{
|
{
|
||||||
addChild(button);
|
addChild(button);
|
||||||
@@ -519,6 +551,17 @@ bool CGarrisonInt::getSplittingMode()
|
|||||||
return inSplittingMode;
|
return inSplittingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CGarrisonSlot *> CGarrisonInt::getEmptySlots(CGarrisonSlot::EGarrisonType type)
|
||||||
|
{
|
||||||
|
std::vector<CGarrisonSlot *> emptySlots;
|
||||||
|
for(CGarrisonSlot * slot : availableSlots)
|
||||||
|
{
|
||||||
|
if(type == slot->upg && ((slot->our() || slot->ally()) && slot->creature == nullptr))
|
||||||
|
emptySlots.push_back(slot);
|
||||||
|
}
|
||||||
|
return emptySlots;
|
||||||
|
}
|
||||||
|
|
||||||
void CGarrisonInt::setArmy(const CArmedInstance *army, bool bottomGarrison)
|
void CGarrisonInt::setArmy(const CArmedInstance *army, bool bottomGarrison)
|
||||||
{
|
{
|
||||||
owned[bottomGarrison] = army ? (army->tempOwner == LOCPLINT->playerID || army->tempOwner == PlayerColor::UNFLAGGABLE) : false;
|
owned[bottomGarrison] = army ? (army->tempOwner == LOCPLINT->playerID || army->tempOwner == PlayerColor::UNFLAGGABLE) : false;
|
||||||
|
@@ -55,6 +55,9 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * Creature=nullptr);
|
CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * Creature=nullptr);
|
||||||
|
|
||||||
|
void splitIntoParts(EGarrisonType type, int amount, int maxOfSplittedSlots);
|
||||||
|
void handleSplittingShortcuts();
|
||||||
|
|
||||||
friend class CGarrisonInt;
|
friend class CGarrisonInt;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,7 +86,8 @@ public:
|
|||||||
twoRows, ///< slots Will be placed in 2 rows
|
twoRows, ///< slots Will be placed in 2 rows
|
||||||
owned[2]; ///< player Owns up or down army ([0] upper, [1] lower)
|
owned[2]; ///< player Owns up or down army ([0] upper, [1] lower)
|
||||||
|
|
||||||
std::vector<CGarrisonSlot*> availableSlots; ///< Slots of upper and lower garrison
|
std::vector<CGarrisonSlot *> availableSlots; ///< Slots of upper and lower garrison
|
||||||
|
std::vector<CGarrisonSlot *> getEmptySlots(CGarrisonSlot::EGarrisonType type);
|
||||||
|
|
||||||
const CArmedInstance *armedObjs[2]; ///< [0] is upper, [1] is down
|
const CArmedInstance *armedObjs[2]; ///< [0] is upper, [1] is down
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user