mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-04 00:15:53 +02:00
Merge pull request #386 from FeniksFire/SplittingShortcuts
Add keyboard shortcuts for splitting army from HD mod.
This commit is contained in:
commit
52e837bde3
@ -281,7 +281,10 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState)
|
||||
bool refr = false;
|
||||
const CGarrisonSlot * selection = owner->getSelection();
|
||||
if(!selection)
|
||||
{
|
||||
refr = highlightOrDropArtifact();
|
||||
handleSplittingShortcuts();
|
||||
}
|
||||
else if(selection == this)
|
||||
refr = viewInfo();
|
||||
// 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));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
addChild(button);
|
||||
@ -519,6 +551,17 @@ bool CGarrisonInt::getSplittingMode()
|
||||
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)
|
||||
{
|
||||
owned[bottomGarrison] = army ? (army->tempOwner == LOCPLINT->playerID || army->tempOwner == PlayerColor::UNFLAGGABLE) : false;
|
||||
|
@ -55,6 +55,9 @@ public:
|
||||
void update();
|
||||
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;
|
||||
};
|
||||
|
||||
@ -84,6 +87,7 @@ public:
|
||||
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 *> getEmptySlots(CGarrisonSlot::EGarrisonType type);
|
||||
|
||||
const CArmedInstance *armedObjs[2]; ///< [0] is upper, [1] is down
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user