mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-13 22:06:58 +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"
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||||
|
|
||||||
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet)
|
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet)
|
||||||
|
{
|
||||||
|
artSets.emplace_back(artSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWindowWithArtifacts::addSetAndCallbacks(CArtifactsOfHeroPtr artSet)
|
||||||
{
|
{
|
||||||
CArtifactsOfHeroBase::PutBackPickedArtCallback artPutBackHandler = []() -> void
|
CArtifactsOfHeroBase::PutBackPickedArtCallback artPutBackHandler = []() -> void
|
||||||
{
|
{
|
||||||
CCS->curh->dragAndDropCursor(nullptr);
|
CCS->curh->dragAndDropCursor(nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
artSets.emplace_back(artSet);
|
addSet(artSet);
|
||||||
std::visit([this, artPutBackHandler](auto artSetWeak)
|
std::visit([this, artPutBackHandler](auto artSetWeak)
|
||||||
{
|
{
|
||||||
auto artSet = artSetWeak.lock();
|
auto artSet = artSetWeak.lock();
|
||||||
|
@ -28,6 +28,7 @@ public:
|
|||||||
using CloseCallback = std::function<void()>;
|
using CloseCallback = std::function<void()>;
|
||||||
|
|
||||||
void addSet(CArtifactsOfHeroPtr artSet);
|
void addSet(CArtifactsOfHeroPtr artSet);
|
||||||
|
void addSetAndCallbacks(CArtifactsOfHeroPtr artSet);
|
||||||
void addCloseCallback(CloseCallback callback);
|
void addCloseCallback(CloseCallback callback);
|
||||||
const CGHeroInstance * getHeroPickedArtifact();
|
const CGHeroInstance * getHeroPickedArtifact();
|
||||||
const CArtifactInstance * getPickedArtifact();
|
const CArtifactInstance * getPickedArtifact();
|
||||||
@ -39,7 +40,7 @@ public:
|
|||||||
void artifactDisassembled(const ArtifactLocation & artLoc) override;
|
void artifactDisassembled(const ArtifactLocation & artLoc) override;
|
||||||
void artifactAssembled(const ArtifactLocation & artLoc) override;
|
void artifactAssembled(const ArtifactLocation & artLoc) override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
std::vector<CArtifactsOfHeroPtr> artSets;
|
std::vector<CArtifactsOfHeroPtr> artSets;
|
||||||
CloseCallback closeCallback;
|
CloseCallback closeCallback;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero)
|
|||||||
|
|
||||||
arts = std::make_shared<CArtifactsOfHeroBackpack>(Point(windowMargin, windowMargin));
|
arts = std::make_shared<CArtifactsOfHeroBackpack>(Point(windowMargin, windowMargin));
|
||||||
arts->setHero(hero);
|
arts->setHero(hero);
|
||||||
addSet(arts);
|
addSetAndCallbacks(arts);
|
||||||
|
|
||||||
addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
|
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 = std::make_shared<CArtifactsOfHeroMain>(Point(-65, -8));
|
||||||
arts->setHero(curHero);
|
arts->setHero(curHero);
|
||||||
addSet(arts);
|
addSetAndCallbacks(arts);
|
||||||
}
|
}
|
||||||
|
|
||||||
int serial = LOCPLINT->cb->getHeroSerial(curHero, false);
|
int serial = LOCPLINT->cb->getHeroSerial(curHero, false);
|
||||||
|
@ -706,7 +706,7 @@ std::shared_ptr<CIntObject> CKingdHeroList::createHeroItem(size_t index)
|
|||||||
if(index < heroesList.size())
|
if(index < heroesList.size())
|
||||||
{
|
{
|
||||||
auto hero = std::make_shared<CHeroItem>(heroesList[index]);
|
auto hero = std::make_shared<CHeroItem>(heroesList[index]);
|
||||||
addSet(hero->heroArts);
|
addSetAndCallbacks(hero->heroArts);
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -680,7 +680,7 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket * Market, const CGHeroInsta
|
|||||||
arts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46));
|
arts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46));
|
||||||
arts->selectArtCallback = std::bind(&CTradeWindow::artifactSelected, this, _1);
|
arts->selectArtCallback = std::bind(&CTradeWindow::artifactSelected, this, _1);
|
||||||
arts->setHero(hero);
|
arts->setHero(hero);
|
||||||
addSet(arts);
|
addSetAndCallbacks(arts);
|
||||||
}
|
}
|
||||||
initItems(false);
|
initItems(false);
|
||||||
initItems(true);
|
initItems(true);
|
||||||
@ -1115,7 +1115,7 @@ CAltarWindow::CAltarWindow(const IMarket * Market, const CGHeroInstance * Hero,
|
|||||||
|
|
||||||
arts = std::make_shared<CArtifactsOfHeroAltar>(Point(-365, -12));
|
arts = std::make_shared<CArtifactsOfHeroAltar>(Point(-365, -12));
|
||||||
arts->setHero(hero);
|
arts->setHero(hero);
|
||||||
addSet(arts);
|
addSetAndCallbacks(arts);
|
||||||
|
|
||||||
initItems(true);
|
initItems(true);
|
||||||
initItems(false);
|
initItems(false);
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "CCastleInterface.h"
|
#include "CCastleInterface.h"
|
||||||
#include "CCreatureWindow.h"
|
#include "CCreatureWindow.h"
|
||||||
|
#include "CHeroBackpackWindow.h"
|
||||||
#include "CHeroWindow.h"
|
#include "CHeroWindow.h"
|
||||||
#include "InfoWindows.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] = std::make_shared<CArtifactsOfHeroMain>(Point(98, 150));
|
||||||
artifs[1]->setHero(heroInst[1]);
|
artifs[1]->setHero(heroInst[1]);
|
||||||
|
|
||||||
addSet(artifs[0]);
|
addSetAndCallbacks(artifs[0]);
|
||||||
addSet(artifs[1]);
|
addSetAndCallbacks(artifs[1]);
|
||||||
|
|
||||||
for(int g=0; g<4; ++g)
|
for(int g=0; g<4; ++g)
|
||||||
{
|
{
|
||||||
@ -754,7 +755,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
|
|
||||||
if(qeLayout)
|
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 moveEquipped = true;
|
||||||
bool moveBackpack = true;
|
bool moveBackpack = true;
|
||||||
@ -766,7 +767,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
moveRoutine(moveEquipped, moveBackpack);
|
moveRoutine(moveEquipped, moveBackpack);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto moveArmy = [this](bool leftToRight) -> void
|
auto moveArmy = [this](const bool leftToRight) -> void
|
||||||
{
|
{
|
||||||
std::optional<SlotID> slotId = std::nullopt;
|
std::optional<SlotID> slotId = std::nullopt;
|
||||||
if(auto slot = getSelectedSlotID())
|
if(auto slot = getSelectedSlotID())
|
||||||
@ -774,18 +775,42 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
controller.moveArmy(leftToRight, slotId);
|
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]),
|
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));
|
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));
|
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]),
|
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));
|
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]),
|
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);}));
|
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);}));
|
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]),
|
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);}));
|
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++)
|
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"),
|
AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/unitLeft.DEF"),
|
||||||
CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
|
CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
|
||||||
std::bind(&CExchangeController::moveStack, &controller, false, SlotID(i))));
|
std::bind(&CExchangeController::moveStack, &controller, false, SlotID(i))));
|
||||||
|
moveStackLeftButtons.back()->block(leftHeroBlock);
|
||||||
|
|
||||||
moveStackRightButtons.push_back(
|
moveStackRightButtons.push_back(
|
||||||
std::make_shared<CButton>(
|
std::make_shared<CButton>(
|
||||||
@ -802,6 +828,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/unitRight.DEF"),
|
AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/unitRight.DEF"),
|
||||||
CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
|
CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
|
||||||
std::bind(&CExchangeController::moveStack, &controller, true, SlotID(i))));
|
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<CGarrisonInt> garr;
|
||||||
std::shared_ptr<CButton> moveAllGarrButtonLeft;
|
std::shared_ptr<CButton> moveAllGarrButtonLeft;
|
||||||
std::shared_ptr<CButton> echangeGarrButton;
|
std::shared_ptr<CButton> exchangeGarrButton;
|
||||||
std::shared_ptr<CButton> moveAllGarrButtonRight;
|
std::shared_ptr<CButton> moveAllGarrButtonRight;
|
||||||
std::shared_ptr<CButton> moveArtifactsButtonLeft;
|
std::shared_ptr<CButton> moveArtifactsButtonLeft;
|
||||||
std::shared_ptr<CButton> echangeArtifactsButton;
|
std::shared_ptr<CButton> exchangeArtifactsButton;
|
||||||
std::shared_ptr<CButton> moveArtifactsButtonRight;
|
std::shared_ptr<CButton> moveArtifactsButtonRight;
|
||||||
std::vector<std::shared_ptr<CButton>> moveStackLeftButtons;
|
std::vector<std::shared_ptr<CButton>> moveStackLeftButtons;
|
||||||
std::vector<std::shared_ptr<CButton>> moveStackRightButtons;
|
std::vector<std::shared_ptr<CButton>> moveStackRightButtons;
|
||||||
|
std::shared_ptr<CButton> backpackButtonLeft;
|
||||||
|
std::shared_ptr<CButton> backpackButtonRight;
|
||||||
CExchangeController controller;
|
CExchangeController controller;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -68,7 +68,7 @@ void ApplyGhNetPackVisitor::visitArrangeStacks(ArrangeStacks & pack)
|
|||||||
|
|
||||||
void ApplyGhNetPackVisitor::visitBulkMoveArmy(BulkMoveArmy & pack)
|
void ApplyGhNetPackVisitor::visitBulkMoveArmy(BulkMoveArmy & pack)
|
||||||
{
|
{
|
||||||
gh.throwIfWrongPlayer(&pack);
|
gh.throwIfWrongOwner(&pack, pack.srcArmy);
|
||||||
result = gh.bulkMoveArmy(pack.srcArmy, pack.destArmy, pack.srcSlot);
|
result = gh.bulkMoveArmy(pack.srcArmy, pack.destArmy, pack.srcSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +132,8 @@ void ApplyGhNetPackVisitor::visitExchangeArtifacts(ExchangeArtifacts & pack)
|
|||||||
void ApplyGhNetPackVisitor::visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack)
|
void ApplyGhNetPackVisitor::visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack)
|
||||||
{
|
{
|
||||||
gh.throwIfWrongOwner(&pack, pack.srcHero);
|
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);
|
result = gh.bulkMoveArtifacts(pack.srcHero, pack.dstHero, pack.swap, pack.equipped, pack.backpack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user