1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Added Ctrl & Shift versions for swap artifacts shortcut. Exchange window

shortcuts now work even without vcmi extras
This commit is contained in:
Ivan Savenko 2024-05-19 12:28:03 +00:00
parent 896fd27ead
commit 5feef488e3
6 changed files with 132 additions and 55 deletions

View File

@ -264,6 +264,12 @@ enum class EShortcut
EXCHANGE_ARTIFACTS_TO_LEFT,
EXCHANGE_ARTIFACTS_TO_RIGHT,
EXCHANGE_ARTIFACTS_SWAP,
EXCHANGE_EQUIPPED_TO_LEFT,
EXCHANGE_EQUIPPED_TO_RIGHT,
EXCHANGE_EQUIPPED_SWAP,
EXCHANGE_BACKPACK_TO_LEFT,
EXCHANGE_BACKPACK_TO_RIGHT,
EXCHANGE_BACKPACK_SWAP,
EXCHANGE_BACKPACK_LEFT,
EXCHANGE_BACKPACK_RIGHT,

View File

@ -327,6 +327,12 @@ EShortcut ShortcutHandler::findShortcut(const std::string & identifier ) const
{"exchangeArtifactsSwap", EShortcut::EXCHANGE_ARTIFACTS_SWAP },
{"exchangeBackpackLeft", EShortcut::EXCHANGE_BACKPACK_LEFT },
{"exchangeBackpackRight", EShortcut::EXCHANGE_BACKPACK_RIGHT },
{"exchangeEquippedToLeft", EShortcut::EXCHANGE_EQUIPPED_TO_LEFT },
{"exchangeEquippedToRight", EShortcut::EXCHANGE_EQUIPPED_TO_RIGHT},
{"exchangeEquippedSwap", EShortcut::EXCHANGE_EQUIPPED_SWAP },
{"exchangeBackpackToLeft", EShortcut::EXCHANGE_BACKPACK_TO_LEFT },
{"exchangeBackpackToRight", EShortcut::EXCHANGE_BACKPACK_TO_RIGHT},
{"exchangeBackpackSwap", EShortcut::EXCHANGE_BACKPACK_SWAP },
};
#ifndef ENABLE_GOLDMASTER

View File

@ -37,8 +37,7 @@
#include "../lib/CSkillHandler.h"
#include "../lib/TextOperations.h"
static const std::string QUICK_EXCHANGE_MOD_PREFIX = "quick-exchange";
static const std::string QUICK_EXCHANGE_BG = QUICK_EXCHANGE_MOD_PREFIX + "/TRADEQE";
static const std::string QUICK_EXCHANGE_BG = "quick-exchange/TRADEQE";
static bool isQuickExchangeLayoutAvailable()
{
@ -54,6 +53,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
const bool qeLayout = isQuickExchangeLayoutAvailable();
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
addUsedEvents(KEYBOARD);
heroInst[0] = LOCPLINT->cb->getHero(hero1);
heroInst[1] = LOCPLINT->cb->getHero(hero2);
@ -178,8 +178,8 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
if(queryID.getNum() > 0)
quit->addCallback([=](){ LOCPLINT->cb->selectionMade(0, queryID); });
questlogButton[0] = std::make_shared<CButton>(Point( 10, qeLayout ? 39 : 44), AnimationPath::builtin("hsbtns4.def"), CButton::tooltip(CGI->generaltexth->heroscrn[0]), std::bind(&CExchangeWindow::questlog, this, 0), EShortcut::ADVENTURE_QUEST_LOG);
questlogButton[1] = std::make_shared<CButton>(Point(740, qeLayout ? 39 : 44), AnimationPath::builtin("hsbtns4.def"), CButton::tooltip(CGI->generaltexth->heroscrn[0]), std::bind(&CExchangeWindow::questlog, this, 1), EShortcut::ADVENTURE_QUEST_LOG);
questlogButton[0] = std::make_shared<CButton>(Point( 10, qeLayout ? 39 : 44), AnimationPath::builtin("hsbtns4.def"), CButton::tooltip(CGI->generaltexth->heroscrn[0]), std::bind(&CExchangeWindow::questLogShortcut, this), EShortcut::ADVENTURE_QUEST_LOG);
questlogButton[1] = std::make_shared<CButton>(Point(740, qeLayout ? 39 : 44), AnimationPath::builtin("hsbtns4.def"), CButton::tooltip(CGI->generaltexth->heroscrn[0]), std::bind(&CExchangeWindow::questLogShortcut, this), EShortcut::ADVENTURE_QUEST_LOG);
Rect barRect(5, 578, 725, 18);
statusbar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), barRect, 5, 578));
@ -193,48 +193,24 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
if(qeLayout)
{
auto moveArtifacts = [](const std::function<void(bool, bool)> moveRoutine) -> void
{
bool moveEquipped = true;
bool moveBackpack = true;
moveAllGarrButtonLeft = std::make_shared<CButton>(Point(325, 118), AnimationPath::builtin("quick-exchange/armRight.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
[this](){ this->moveUnitsShortcut(false); });
exchangeGarrButton = std::make_shared<CButton>(Point(377, 118), AnimationPath::builtin("quick-exchange/swapAll.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[2]),
[this](){ controller.swapArmy(); });
moveAllGarrButtonRight = std::make_shared<CButton>(Point(425, 118), AnimationPath::builtin("quick-exchange/armLeft.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
[this](){ this->moveUnitsShortcut(true); });
moveArtifactsButtonLeft = std::make_shared<CButton>(Point(325, 154), AnimationPath::builtin("quick-exchange/artRight.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[3]),
[this](){ this->moveArtifactsCallback(false);});
exchangeArtifactsButton = std::make_shared<CButton>(Point(377, 154), AnimationPath::builtin("quick-exchange/swapAll.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[4]),
[this](){ this->swapArtifactsCallback(); });
moveArtifactsButtonRight = std::make_shared<CButton>(Point(425, 154), AnimationPath::builtin("quick-exchange/artLeft.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[3]),
[this](){ this->moveArtifactsCallback(true);});
if(GH.isKeyboardCmdDown())
moveBackpack = false;
else if(GH.isKeyboardShiftDown())
moveEquipped = false;
moveRoutine(moveEquipped, moveBackpack);
};
auto moveArmy = [this](const bool leftToRight) -> void
{
std::optional<SlotID> slotId = std::nullopt;
if(auto slot = getSelectedSlotID())
slotId = slot->getSlot();
controller.moveArmy(leftToRight, slotId);
};
auto openBackpack = [this](const CGHeroInstance * hero) -> void
{
GH.windows().createAndPushWindow<CHeroBackpackWindow>(hero, artSets);
};
moveAllGarrButtonLeft = std::make_shared<CButton>(Point(325, 118), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/armRight.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
std::bind(moveArmy, true), EShortcut::EXCHANGE_ARMY_TO_LEFT);
exchangeGarrButton = std::make_shared<CButton>(Point(377, 118), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/swapAll.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[2]),
std::bind(&CExchangeController::swapArmy, &controller), EShortcut::EXCHANGE_ARMY_SWAP);
moveAllGarrButtonRight = std::make_shared<CButton>(Point(425, 118), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/armLeft.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
std::bind(moveArmy, false), EShortcut::EXCHANGE_ARMY_TO_RIGHT);
moveArtifactsButtonLeft = std::make_shared<CButton>(Point(325, 154), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/artRight.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[3]),
std::bind(moveArtifacts, [this](bool equipped, bool baclpack) -> void {controller.moveArtifacts(true, equipped, baclpack);}), EShortcut::EXCHANGE_ARTIFACTS_TO_LEFT);
exchangeArtifactsButton = std::make_shared<CButton>(Point(377, 154), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/swapAll.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[4]),
std::bind(moveArtifacts, [this](bool equipped, bool baclpack) -> void {controller.swapArtifacts(equipped, baclpack);}), EShortcut::EXCHANGE_ARTIFACTS_SWAP);
moveArtifactsButtonRight = std::make_shared<CButton>(Point(425, 154), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/artLeft.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[3]),
std::bind(moveArtifacts, [this](bool equipped, bool baclpack) -> void {controller.moveArtifacts(false, equipped, baclpack);}), EShortcut::EXCHANGE_ARTIFACTS_TO_RIGHT);
backpackButtonLeft = std::make_shared<CButton>(Point(325, 518), AnimationPath::builtin("heroBackpack"), CButton::tooltipLocalized("vcmi.heroWindow.openBackpack"),
std::bind(openBackpack, heroInst[0]), EShortcut::EXCHANGE_BACKPACK_LEFT);
backpackButtonLeft->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("heroWindow/backpackButtonIcon")));
[this](){ this->backpackShortcut(true); });
backpackButtonRight = std::make_shared<CButton>(Point(419, 518), AnimationPath::builtin("heroBackpack"), CButton::tooltipLocalized("vcmi.heroWindow.openBackpack"),
std::bind(openBackpack, heroInst[1]), EShortcut::EXCHANGE_BACKPACK_RIGHT);
[this](){ this->backpackShortcut(false); });
backpackButtonLeft->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("heroWindow/backpackButtonIcon")));
backpackButtonRight->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("heroWindow/backpackButtonIcon")));
auto leftHeroBlock = heroInst[0]->tempOwner != LOCPLINT->cb->getPlayerID();
@ -253,7 +229,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
moveStackLeftButtons.push_back(
std::make_shared<CButton>(
Point(484 + 35 * i, 154),
AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/unitLeft.DEF"),
AnimationPath::builtin("quick-exchange/unitLeft.DEF"),
CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
std::bind(&CExchangeController::moveStack, &controller, false, SlotID(i))));
moveStackLeftButtons.back()->block(leftHeroBlock);
@ -261,7 +237,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
moveStackRightButtons.push_back(
std::make_shared<CButton>(
Point(66 + 35 * i, 154),
AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/unitRight.DEF"),
AnimationPath::builtin("quick-exchange/unitRight.DEF"),
CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
std::bind(&CExchangeController::moveStack, &controller, true, SlotID(i))));
moveStackLeftButtons.back()->block(rightHeroBlock);
@ -271,6 +247,82 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
updateWidgets();
}
void CExchangeWindow::moveArtifactsCallback(bool leftToRight)
{
bool moveEquipped = !GH.isKeyboardShiftDown();
bool moveBackpack = !GH.isKeyboardCmdDown();
controller.moveArtifacts(leftToRight, moveEquipped, moveBackpack);
};
void CExchangeWindow::swapArtifactsCallback()
{
bool moveEquipped = !GH.isKeyboardShiftDown();
bool moveBackpack = !GH.isKeyboardCmdDown();
controller.swapArtifacts(moveEquipped, moveBackpack);
}
void CExchangeWindow::moveUnitsShortcut(bool leftToRight)
{
std::optional<SlotID> slotId = std::nullopt;
if(const auto * slot = getSelectedSlotID())
slotId = slot->getSlot();
controller.moveArmy(leftToRight, slotId);
};
void CExchangeWindow::backpackShortcut(bool leftHero)
{
GH.windows().createAndPushWindow<CHeroBackpackWindow>(heroInst[leftHero ? 0 : 1], artSets);
};
void CExchangeWindow::keyPressed(EShortcut key)
{
switch (key)
{
case EShortcut::EXCHANGE_ARMY_TO_LEFT:
moveUnitsShortcut(false);
break;
case EShortcut::EXCHANGE_ARMY_TO_RIGHT:
moveUnitsShortcut(true);
break;
case EShortcut::EXCHANGE_ARMY_SWAP:
controller.swapArmy();
break;
case EShortcut::EXCHANGE_ARTIFACTS_TO_LEFT:
controller.moveArtifacts(false, true, true);
break;
case EShortcut::EXCHANGE_ARTIFACTS_TO_RIGHT:
controller.moveArtifacts(true, true, true);
break;
case EShortcut::EXCHANGE_ARTIFACTS_SWAP:
controller.swapArtifacts(true, true);
break;
case EShortcut::EXCHANGE_EQUIPPED_TO_LEFT:
controller.moveArtifacts(false, true, false);
break;
case EShortcut::EXCHANGE_EQUIPPED_TO_RIGHT:
controller.moveArtifacts(true, true, false);
break;
case EShortcut::EXCHANGE_EQUIPPED_SWAP:
controller.swapArtifacts(true, false);
break;
case EShortcut::EXCHANGE_BACKPACK_TO_LEFT:
controller.moveArtifacts(false, false, true);
break;
case EShortcut::EXCHANGE_BACKPACK_TO_RIGHT:
controller.moveArtifacts(true, false, true);
break;
case EShortcut::EXCHANGE_BACKPACK_SWAP:
controller.swapArtifacts(false, true);
break;
case EShortcut::EXCHANGE_BACKPACK_LEFT:
backpackShortcut(true);
break;
case EShortcut::EXCHANGE_BACKPACK_RIGHT:
backpackShortcut(false);
break;
}
}
const CGarrisonSlot * CExchangeWindow::getSelectedSlotID() const
{
return garr->getSelection();
@ -288,7 +340,7 @@ bool CExchangeWindow::holdsGarrison(const CArmedInstance * army)
return garr->upperArmy() == army || garr->lowerArmy() == army;
}
void CExchangeWindow::questlog(int whichHero)
void CExchangeWindow::questLogShortcut()
{
CCS->curh->dragAndDropCursor(nullptr);
LOCPLINT->showQuestLog();

View File

@ -53,18 +53,26 @@ class CExchangeWindow : public CStatusbarWindow, public IGarrisonHolder, public
std::shared_ptr<CButton> backpackButtonRight;
CExchangeController controller;
public:
void moveArtifactsCallback(bool leftToRight);
void swapArtifactsCallback();
void moveUnitsShortcut(bool leftToRight);
void backpackShortcut(bool leftHero);
void questLogShortcut();
std::array<const CGHeroInstance *, 2> heroInst;
std::array<std::shared_ptr<CArtifactsOfHeroMain>, 2> artifs;
void updateGarrisons() override;
bool holdsGarrison(const CArmedInstance * army) override;
const CGarrisonSlot * getSelectedSlotID() const;
void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
public:
CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID);
void keyPressed(EShortcut key) override;
void updateWidgets();
const CGarrisonSlot * getSelectedSlotID() const;
// IGarrisonHolder impl
void updateGarrisons() override;
bool holdsGarrison(const CArmedInstance * army) override;
CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID);
};

View File

@ -282,8 +282,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
for(auto cew : GH.windows().findWindows<CExchangeWindow>())
{
for(int g=0; g < cew->heroInst.size(); ++g)
if(cew->heroInst[g] == curHero)
if (cew->holdsGarrison(curHero))
noDismiss = true;
}

View File

@ -79,6 +79,12 @@
"exchangeArtifactsToRight": [],
"exchangeBackpackLeft": [],
"exchangeBackpackRight": [],
"exchangeBackpackSwap": "Shift+F11",
"exchangeBackpackToLeft": [],
"exchangeBackpackToRight": [],
"exchangeEquippedSwap": "Ctrl+F11",
"exchangeEquippedToLeft": [],
"exchangeEquippedToRight": [],
"gameActivateConsole": "Tab",
"globalAccept": [ "Return", "Keypad Enter"],
"globalBackspace": "Backspace",