mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Fixed move checks. Backpack buttons.
This commit is contained in:
parent
f47def3588
commit
9cc623c981
@ -27,13 +27,18 @@
|
||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||
|
||||
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet)
|
||||
{
|
||||
artSets.emplace_back(artSet);
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::addSetAndCallbacks(CArtifactsOfHeroPtr artSet)
|
||||
{
|
||||
CArtifactsOfHeroBase::PutBackPickedArtCallback artPutBackHandler = []() -> void
|
||||
{
|
||||
CCS->curh->dragAndDropCursor(nullptr);
|
||||
};
|
||||
|
||||
artSets.emplace_back(artSet);
|
||||
addSet(artSet);
|
||||
std::visit([this, artPutBackHandler](auto artSetWeak)
|
||||
{
|
||||
auto artSet = artSetWeak.lock();
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
using CloseCallback = std::function<void()>;
|
||||
|
||||
void addSet(CArtifactsOfHeroPtr artSet);
|
||||
void addSetAndCallbacks(CArtifactsOfHeroPtr artSet);
|
||||
void addCloseCallback(CloseCallback callback);
|
||||
const CGHeroInstance * getHeroPickedArtifact();
|
||||
const CArtifactInstance * getPickedArtifact();
|
||||
@ -39,7 +40,7 @@ public:
|
||||
void artifactDisassembled(const ArtifactLocation & artLoc) override;
|
||||
void artifactAssembled(const ArtifactLocation & artLoc) override;
|
||||
|
||||
private:
|
||||
protected:
|
||||
std::vector<CArtifactsOfHeroPtr> artSets;
|
||||
CloseCallback closeCallback;
|
||||
|
||||
|
@ -28,7 +28,7 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero)
|
||||
|
||||
arts = std::make_shared<CArtifactsOfHeroBackpack>(Point(windowMargin, windowMargin));
|
||||
arts->setHero(hero);
|
||||
addSet(arts);
|
||||
addSetAndCallbacks(arts);
|
||||
|
||||
addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
|
||||
|
||||
|
@ -219,7 +219,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
|
||||
{
|
||||
arts = std::make_shared<CArtifactsOfHeroMain>(Point(-65, -8));
|
||||
arts->setHero(curHero);
|
||||
addSet(arts);
|
||||
addSetAndCallbacks(arts);
|
||||
}
|
||||
|
||||
int serial = LOCPLINT->cb->getHeroSerial(curHero, false);
|
||||
|
@ -706,7 +706,7 @@ std::shared_ptr<CIntObject> CKingdHeroList::createHeroItem(size_t index)
|
||||
if(index < heroesList.size())
|
||||
{
|
||||
auto hero = std::make_shared<CHeroItem>(heroesList[index]);
|
||||
addSet(hero->heroArts);
|
||||
addSetAndCallbacks(hero->heroArts);
|
||||
return hero;
|
||||
}
|
||||
else
|
||||
|
@ -680,7 +680,7 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket * Market, const CGHeroInsta
|
||||
arts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46));
|
||||
arts->selectArtCallback = std::bind(&CTradeWindow::artifactSelected, this, _1);
|
||||
arts->setHero(hero);
|
||||
addSet(arts);
|
||||
addSetAndCallbacks(arts);
|
||||
}
|
||||
initItems(false);
|
||||
initItems(true);
|
||||
@ -1115,7 +1115,7 @@ CAltarWindow::CAltarWindow(const IMarket * Market, const CGHeroInstance * Hero,
|
||||
|
||||
arts = std::make_shared<CArtifactsOfHeroAltar>(Point(-365, -12));
|
||||
arts->setHero(hero);
|
||||
addSet(arts);
|
||||
addSetAndCallbacks(arts);
|
||||
|
||||
initItems(true);
|
||||
initItems(false);
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "CCastleInterface.h"
|
||||
#include "CCreatureWindow.h"
|
||||
#include "CHeroBackpackWindow.h"
|
||||
#include "CHeroWindow.h"
|
||||
#include "InfoWindows.h"
|
||||
|
||||
@ -662,8 +663,8 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
artifs[1] = std::make_shared<CArtifactsOfHeroMain>(Point(98, 150));
|
||||
artifs[1]->setHero(heroInst[1]);
|
||||
|
||||
addSet(artifs[0]);
|
||||
addSet(artifs[1]);
|
||||
addSetAndCallbacks(artifs[0]);
|
||||
addSetAndCallbacks(artifs[1]);
|
||||
|
||||
for(int g=0; g<4; ++g)
|
||||
{
|
||||
@ -754,7 +755,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
|
||||
if(qeLayout)
|
||||
{
|
||||
auto moveArtifacts = [this](std::function<void(bool, bool)> moveRoutine) -> void
|
||||
auto moveArtifacts = [this](const std::function<void(bool, bool)> moveRoutine) -> void
|
||||
{
|
||||
bool moveEquipped = true;
|
||||
bool moveBackpack = true;
|
||||
@ -766,7 +767,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
moveRoutine(moveEquipped, moveBackpack);
|
||||
};
|
||||
|
||||
auto moveArmy = [this](bool leftToRight) -> void
|
||||
auto moveArmy = [this](const bool leftToRight) -> void
|
||||
{
|
||||
std::optional<SlotID> slotId = std::nullopt;
|
||||
if(auto slot = getSelectedSlotID())
|
||||
@ -774,18 +775,42 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
controller.moveArmy(leftToRight, slotId);
|
||||
};
|
||||
|
||||
auto openBackpack = [this](const CGHeroInstance * hero) -> void
|
||||
{
|
||||
GH.windows().createAndPushWindow<CHeroBackpackWindow>(hero);
|
||||
for(auto artSet : artSets)
|
||||
GH.windows().topWindow<CHeroBackpackWindow>()->addSet(artSet);
|
||||
};
|
||||
|
||||
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));
|
||||
echangeGarrButton = std::make_shared<CButton>(Point(377, 118), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/swapAll.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[2]),
|
||||
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));
|
||||
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));
|
||||
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);}));
|
||||
echangeArtifactsButton = std::make_shared<CButton>(Point(377, 154), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/swapAll.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[4]),
|
||||
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);}));
|
||||
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);}));
|
||||
backpackButtonLeft = std::make_shared<CButton>(Point(325, 518), AnimationPath::builtin("buttons/backpack"), CButton::tooltipLocalized("vcmi.heroWindow.openBackpack"),
|
||||
std::bind(openBackpack, heroInst[0]));
|
||||
backpackButtonLeft->addOverlay(std::make_shared<CPicture>(ImagePath::builtin("buttons/backpackButtonIcon")));
|
||||
backpackButtonRight = std::make_shared<CButton>(Point(419, 518), AnimationPath::builtin("buttons/backpack"), CButton::tooltipLocalized("vcmi.heroWindow.openBackpack"),
|
||||
std::bind(openBackpack, heroInst[1]));
|
||||
backpackButtonRight->addOverlay(std::make_shared<CPicture>(ImagePath::builtin("buttons/backpackButtonIcon")));
|
||||
|
||||
auto leftHeroBlock = heroInst[0]->tempOwner != LOCPLINT->cb->getPlayerID();
|
||||
auto rightHeroBlock = heroInst[1]->tempOwner != LOCPLINT->cb->getPlayerID();
|
||||
moveAllGarrButtonLeft->block(leftHeroBlock);
|
||||
exchangeGarrButton->block(leftHeroBlock || rightHeroBlock);
|
||||
moveAllGarrButtonRight->block(rightHeroBlock);
|
||||
moveArtifactsButtonLeft->block(leftHeroBlock);
|
||||
exchangeArtifactsButton->block(leftHeroBlock || rightHeroBlock);
|
||||
moveArtifactsButtonRight->block(rightHeroBlock);
|
||||
backpackButtonLeft->block(leftHeroBlock);
|
||||
backpackButtonRight->block(rightHeroBlock);
|
||||
|
||||
for(int i = 0; i < GameConstants::ARMY_SIZE; i++)
|
||||
{
|
||||
@ -795,6 +820,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/unitLeft.DEF"),
|
||||
CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
|
||||
std::bind(&CExchangeController::moveStack, &controller, false, SlotID(i))));
|
||||
moveStackLeftButtons.back()->block(leftHeroBlock);
|
||||
|
||||
moveStackRightButtons.push_back(
|
||||
std::make_shared<CButton>(
|
||||
@ -802,6 +828,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/unitRight.DEF"),
|
||||
CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
|
||||
std::bind(&CExchangeController::moveStack, &controller, true, SlotID(i))));
|
||||
moveStackLeftButtons.back()->block(rightHeroBlock);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,13 +269,15 @@ class CExchangeWindow : public CStatusbarWindow, public IGarrisonHolder, public
|
||||
|
||||
std::shared_ptr<CGarrisonInt> garr;
|
||||
std::shared_ptr<CButton> moveAllGarrButtonLeft;
|
||||
std::shared_ptr<CButton> echangeGarrButton;
|
||||
std::shared_ptr<CButton> exchangeGarrButton;
|
||||
std::shared_ptr<CButton> moveAllGarrButtonRight;
|
||||
std::shared_ptr<CButton> moveArtifactsButtonLeft;
|
||||
std::shared_ptr<CButton> echangeArtifactsButton;
|
||||
std::shared_ptr<CButton> exchangeArtifactsButton;
|
||||
std::shared_ptr<CButton> moveArtifactsButtonRight;
|
||||
std::vector<std::shared_ptr<CButton>> moveStackLeftButtons;
|
||||
std::vector<std::shared_ptr<CButton>> moveStackRightButtons;
|
||||
std::shared_ptr<CButton> backpackButtonLeft;
|
||||
std::shared_ptr<CButton> backpackButtonRight;
|
||||
CExchangeController controller;
|
||||
|
||||
public:
|
||||
|
@ -68,7 +68,7 @@ void ApplyGhNetPackVisitor::visitArrangeStacks(ArrangeStacks & pack)
|
||||
|
||||
void ApplyGhNetPackVisitor::visitBulkMoveArmy(BulkMoveArmy & pack)
|
||||
{
|
||||
gh.throwIfWrongPlayer(&pack);
|
||||
gh.throwIfWrongOwner(&pack, pack.srcArmy);
|
||||
result = gh.bulkMoveArmy(pack.srcArmy, pack.destArmy, pack.srcSlot);
|
||||
}
|
||||
|
||||
@ -132,6 +132,8 @@ void ApplyGhNetPackVisitor::visitExchangeArtifacts(ExchangeArtifacts & pack)
|
||||
void ApplyGhNetPackVisitor::visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack)
|
||||
{
|
||||
gh.throwIfWrongOwner(&pack, pack.srcHero);
|
||||
if(pack.swap)
|
||||
gh.throwIfWrongOwner(&pack, pack.dstHero);
|
||||
result = gh.bulkMoveArtifacts(pack.srcHero, pack.dstHero, pack.swap, pack.equipped, pack.backpack);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user