mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
CArtifactsOfHeroBase refactoring
This commit is contained in:
@ -1780,7 +1780,10 @@ void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const Artifact
|
|||||||
{
|
{
|
||||||
artWin->artifactMoved(src, dst);
|
artWin->artifactMoved(src, dst);
|
||||||
if(numOfMovedArts == 0)
|
if(numOfMovedArts == 0)
|
||||||
|
{
|
||||||
artWin->update();
|
artWin->update();
|
||||||
|
artWin->redraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
waitWhileDialog();
|
waitWhileDialog();
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,8 @@
|
|||||||
|
|
||||||
CArtifactsOfHeroAltar::CArtifactsOfHeroAltar(const Point & position)
|
CArtifactsOfHeroAltar::CArtifactsOfHeroAltar(const Point & position)
|
||||||
{
|
{
|
||||||
init(
|
init(position, std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
|
||||||
std::bind(&CArtifactsOfHeroBase::clickPrassedArtPlace, this, _1, _2),
|
enableGesture();
|
||||||
std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2),
|
|
||||||
position,
|
|
||||||
std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
|
|
||||||
|
|
||||||
// The backpack is in the altar window above and to the right
|
// The backpack is in the altar window above and to the right
|
||||||
for(auto & slot : backpack)
|
for(auto & slot : backpack)
|
||||||
slot->moveBy(Point(2, -1));
|
slot->moveBy(Point(2, -1));
|
||||||
|
@ -47,8 +47,6 @@ void CArtifactsOfHeroBase::putBackPickedArtifact()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactsOfHeroBase::init(
|
void CArtifactsOfHeroBase::init(
|
||||||
const CArtPlace::ClickFunctor & onClickPressedCallback,
|
|
||||||
const CArtPlace::ClickFunctor & onShowPopupCallback,
|
|
||||||
const Point & position,
|
const Point & position,
|
||||||
const BpackScrollFunctor & scrollCallback)
|
const BpackScrollFunctor & scrollCallback)
|
||||||
{
|
{
|
||||||
@ -69,14 +67,14 @@ void CArtifactsOfHeroBase::init(
|
|||||||
{
|
{
|
||||||
artPlace.second->slot = artPlace.first;
|
artPlace.second->slot = artPlace.first;
|
||||||
artPlace.second->setArtifact(nullptr);
|
artPlace.second->setArtifact(nullptr);
|
||||||
artPlace.second->setClickPressedCallback(onClickPressedCallback);
|
artPlace.second->setClickPressedCallback(std::bind(&CArtifactsOfHeroBase::clickPrassedArtPlace, this, _1, _2));
|
||||||
artPlace.second->setShowPopupCallback(onShowPopupCallback);
|
artPlace.second->setShowPopupCallback(std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2));
|
||||||
}
|
}
|
||||||
for(auto artPlace : backpack)
|
for(auto artPlace : backpack)
|
||||||
{
|
{
|
||||||
artPlace->setArtifact(nullptr);
|
artPlace->setArtifact(nullptr);
|
||||||
artPlace->setClickPressedCallback(onClickPressedCallback);
|
artPlace->setClickPressedCallback(std::bind(&CArtifactsOfHeroBase::clickPrassedArtPlace, this, _1, _2));
|
||||||
artPlace->setShowPopupCallback(onShowPopupCallback);
|
artPlace->setShowPopupCallback(std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2));
|
||||||
}
|
}
|
||||||
leftBackpackRoll = std::make_shared<CButton>(Point(379, 364), AnimationPath::builtin("hsbtns3.def"), CButton::tooltip(),
|
leftBackpackRoll = std::make_shared<CButton>(Point(379, 364), AnimationPath::builtin("hsbtns3.def"), CButton::tooltip(),
|
||||||
[scrollCallback](){scrollCallback(true);}, EShortcut::MOVE_LEFT);
|
[scrollCallback](){scrollCallback(true);}, EShortcut::MOVE_LEFT);
|
||||||
@ -226,11 +224,11 @@ const CArtifactInstance * CArtifactsOfHeroBase::getPickedArtifact()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactsOfHeroBase::addGestureCallback(CArtPlace::ClickFunctor callback)
|
void CArtifactsOfHeroBase::enableGesture()
|
||||||
{
|
{
|
||||||
for(auto & artPlace : artWorn)
|
for(auto & artPlace : artWorn)
|
||||||
{
|
{
|
||||||
artPlace.second->setGestureCallback(callback);
|
artPlace.second->setGestureCallback(std::bind(&CArtifactsOfHeroBase::gestureArtPlace, this, _1, _2));
|
||||||
artPlace.second->addUsedEvents(GESTURE);
|
artPlace.second->addUsedEvents(GESTURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,10 @@ public:
|
|||||||
virtual void updateBackpackSlots();
|
virtual void updateBackpackSlots();
|
||||||
virtual void updateSlot(const ArtifactPosition & slot);
|
virtual void updateSlot(const ArtifactPosition & slot);
|
||||||
virtual const CArtifactInstance * getPickedArtifact();
|
virtual const CArtifactInstance * getPickedArtifact();
|
||||||
void addGestureCallback(CArtPlace::ClickFunctor callback);
|
void enableGesture();
|
||||||
const CArtifactInstance * getArt(const ArtifactPosition & slot) const;
|
const CArtifactInstance * getArt(const ArtifactPosition & slot) const;
|
||||||
void enableKeyboardShortcuts();
|
void enableKeyboardShortcuts();
|
||||||
|
|
||||||
protected:
|
|
||||||
const CGHeroInstance * curHero;
|
const CGHeroInstance * curHero;
|
||||||
ArtPlaceMap artWorn;
|
ArtPlaceMap artWorn;
|
||||||
std::vector<ArtPlacePtr> backpack;
|
std::vector<ArtPlacePtr> backpack;
|
||||||
@ -67,8 +66,8 @@ protected:
|
|||||||
Point(381,295) //18
|
Point(381,295) //18
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void init(const CHeroArtPlace::ClickFunctor & lClickCallback, const CHeroArtPlace::ClickFunctor & showPopupCallback,
|
protected:
|
||||||
const Point & position, const BpackScrollFunctor & scrollCallback);
|
virtual void init(const Point & position, const BpackScrollFunctor & scrollCallback);
|
||||||
// Assigns an artifacts to an artifact place depending on it's new slot ID
|
// Assigns an artifacts to an artifact place depending on it's new slot ID
|
||||||
virtual void setSlotData(ArtPlacePtr artPlace, const ArtifactPosition & slot);
|
virtual void setSlotData(ArtPlacePtr artPlace, const ArtifactPosition & slot);
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,7 @@ CArtifactsOfHeroKingdom::CArtifactsOfHeroKingdom(ArtPlaceMap ArtWorn, std::vecto
|
|||||||
artPlace.second->setClickPressedCallback(std::bind(&CArtifactsOfHeroBase::clickPrassedArtPlace, this, _1, _2));
|
artPlace.second->setClickPressedCallback(std::bind(&CArtifactsOfHeroBase::clickPrassedArtPlace, this, _1, _2));
|
||||||
artPlace.second->setShowPopupCallback(std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2));
|
artPlace.second->setShowPopupCallback(std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2));
|
||||||
}
|
}
|
||||||
addGestureCallback(std::bind(&CArtifactsOfHeroBase::gestureArtPlace, this, _1, _2));
|
enableGesture();
|
||||||
for(auto artPlace : backpack)
|
for(auto artPlace : backpack)
|
||||||
{
|
{
|
||||||
artPlace->setArtifact(nullptr);
|
artPlace->setArtifact(nullptr);
|
||||||
|
@ -20,12 +20,8 @@
|
|||||||
|
|
||||||
CArtifactsOfHeroMain::CArtifactsOfHeroMain(const Point & position)
|
CArtifactsOfHeroMain::CArtifactsOfHeroMain(const Point & position)
|
||||||
{
|
{
|
||||||
init(
|
init(position, std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
|
||||||
std::bind(&CArtifactsOfHeroBase::clickPrassedArtPlace, this, _1, _2),
|
enableGesture();
|
||||||
std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2),
|
|
||||||
position,
|
|
||||||
std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
|
|
||||||
addGestureCallback(std::bind(&CArtifactsOfHeroBase::gestureArtPlace, this, _1, _2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CArtifactsOfHeroMain::~CArtifactsOfHeroMain()
|
CArtifactsOfHeroMain::~CArtifactsOfHeroMain()
|
||||||
|
@ -14,11 +14,7 @@
|
|||||||
|
|
||||||
CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position, const int selectionWidth)
|
CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position, const int selectionWidth)
|
||||||
{
|
{
|
||||||
init(
|
init(position, std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
|
||||||
std::bind(&CArtifactsOfHeroBase::clickPrassedArtPlace, this, _1, _2),
|
|
||||||
std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2),
|
|
||||||
position,
|
|
||||||
std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
|
|
||||||
|
|
||||||
for(const auto & [slot, artPlace] : artWorn)
|
for(const auto & [slot, artPlace] : artWorn)
|
||||||
artPlace->setSelectionWidth(selectionWidth);
|
artPlace->setSelectionWidth(selectionWidth);
|
||||||
@ -26,8 +22,11 @@ CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position, const int
|
|||||||
artPlace->setSelectionWidth(selectionWidth);
|
artPlace->setSelectionWidth(selectionWidth);
|
||||||
};
|
};
|
||||||
|
|
||||||
void CArtifactsOfHeroMarket::onClickPressedArtPlace(CArtPlace & artPlace)
|
void CArtifactsOfHeroMarket::clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
|
if(artPlace.isLocked())
|
||||||
|
return;
|
||||||
|
|
||||||
if(const auto art = getArt(artPlace.slot))
|
if(const auto art = getArt(artPlace.slot))
|
||||||
{
|
{
|
||||||
if(onSelectArtCallback && art->artType->isTradable())
|
if(onSelectArtCallback && art->artType->isTradable())
|
||||||
|
@ -18,5 +18,5 @@ public:
|
|||||||
std::function<void()> onClickNotTradableCallback;
|
std::function<void()> onClickNotTradableCallback;
|
||||||
|
|
||||||
CArtifactsOfHeroMarket(const Point & position, const int selectionWidth);
|
CArtifactsOfHeroMarket(const Point & position, const int selectionWidth);
|
||||||
void onClickPressedArtPlace(CArtPlace & artPlace);
|
void clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition) override;
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std:
|
|||||||
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
|
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
|
||||||
arts = std::make_shared<CArtifactsOfHeroBackpack>();
|
arts = std::make_shared<CArtifactsOfHeroBackpack>();
|
||||||
arts->moveBy(Point(windowMargin, windowMargin));
|
arts->moveBy(Point(windowMargin, windowMargin));
|
||||||
arts->clickPressedCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
arts->clickPressedCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
clickPressedOnArtPlace(arts->getHero(), artPlace.slot, true, false, true);
|
clickPressedOnArtPlace(arts->getHero(), artPlace.slot, true, false, true);
|
||||||
};
|
};
|
||||||
@ -41,7 +41,6 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std:
|
|||||||
};
|
};
|
||||||
addSet(arts);
|
addSet(arts);
|
||||||
arts->setHero(hero);
|
arts->setHero(hero);
|
||||||
addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
|
|
||||||
quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""),
|
quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""),
|
||||||
[this]() { WindowBase::close(); }, EShortcut::GLOBAL_RETURN);
|
[this]() { WindowBase::close(); }, EShortcut::GLOBAL_RETURN);
|
||||||
pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
|
pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
|
||||||
@ -66,18 +65,17 @@ CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero,
|
|||||||
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
|
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
|
||||||
arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
|
arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
|
||||||
arts->moveBy(Point(windowMargin, windowMargin));
|
arts->moveBy(Point(windowMargin, windowMargin));
|
||||||
arts->clickPressedCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
arts->clickPressedCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
if(const auto curHero = arts->getHero())
|
if(const auto curHero = arts->getHero())
|
||||||
swapArtifactAndClose(*arts, artPlace.slot, ArtifactLocation(curHero->id, arts->getFilterSlot()));
|
swapArtifactAndClose(*arts, artPlace.slot, ArtifactLocation(curHero->id, arts->getFilterSlot()));
|
||||||
};
|
};
|
||||||
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
showArifactInfo(artPlace, cursorPosition);
|
showArifactInfo(*arts, artPlace, cursorPosition);
|
||||||
};
|
};
|
||||||
addSet(arts);
|
addSet(arts);
|
||||||
arts->setHero(hero);
|
arts->setHero(hero);
|
||||||
addCloseCallback(std::bind(&CHeroQuickBackpackWindow::close, this));
|
|
||||||
addUsedEvents(GESTURE);
|
addUsedEvents(GESTURE);
|
||||||
pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
|
pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
|
||||||
pos.h = stretchedBackground->pos.h = arts->pos.h + windowMargin;
|
pos.h = stretchedBackground->pos.h = arts->pos.h + windowMargin;
|
||||||
|
@ -213,19 +213,10 @@ void CHeroWindow::update()
|
|||||||
if(!arts)
|
if(!arts)
|
||||||
{
|
{
|
||||||
arts = std::make_shared<CArtifactsOfHeroMain>(Point(-65, -8));
|
arts = std::make_shared<CArtifactsOfHeroMain>(Point(-65, -8));
|
||||||
|
arts->clickPressedCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition){clickPressedOnArtPlace(curHero, artPlace.slot, true, false, false);};
|
||||||
|
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition){showArtifactAssembling(*arts, artPlace, cursorPosition);};
|
||||||
|
arts->gestureCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition){showQuickBackpackWindow(curHero, artPlace.slot, cursorPosition);};
|
||||||
arts->setHero(curHero);
|
arts->setHero(curHero);
|
||||||
arts->clickPressedCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
clickPressedOnArtPlace(arts->getHero(), artPlace.slot, true, false, false);
|
|
||||||
};
|
|
||||||
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
showArtifactAssembling(*arts, artPlace, cursorPosition);
|
|
||||||
};
|
|
||||||
arts->gestureCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
showQuickBackpackWindow(arts->getHero(), artPlace.slot, cursorPosition);
|
|
||||||
};
|
|
||||||
addSet(arts);
|
addSet(arts);
|
||||||
enableKeyboardShortcuts();
|
enableKeyboardShortcuts();
|
||||||
}
|
}
|
||||||
|
@ -550,7 +550,7 @@ std::shared_ptr<CIntObject> CKingdomInterface::createMainTab(size_t index)
|
|||||||
case 0:
|
case 0:
|
||||||
return std::make_shared<CKingdHeroList>(size, [this](const CWindowWithArtifacts::CArtifactsOfHeroPtr & newHeroSet)
|
return std::make_shared<CKingdHeroList>(size, [this](const CWindowWithArtifacts::CArtifactsOfHeroPtr & newHeroSet)
|
||||||
{
|
{
|
||||||
newHeroSet->clickPressedCallback = [this, newHeroSet](CArtPlace & artPlace, const Point & cursorPosition)
|
newHeroSet->clickPressedCallback = [this, newHeroSet](const CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
clickPressedOnArtPlace(newHeroSet->getHero(), artPlace.slot, false, false, false);
|
clickPressedOnArtPlace(newHeroSet->getHero(), artPlace.slot, false, false, false);
|
||||||
};
|
};
|
||||||
@ -558,7 +558,7 @@ std::shared_ptr<CIntObject> CKingdomInterface::createMainTab(size_t index)
|
|||||||
{
|
{
|
||||||
showArtifactAssembling(*newHeroSet, artPlace, cursorPosition);
|
showArtifactAssembling(*newHeroSet, artPlace, cursorPosition);
|
||||||
};
|
};
|
||||||
newHeroSet->gestureCallback = [this, newHeroSet](CArtPlace & artPlace, const Point & cursorPosition)
|
newHeroSet->gestureCallback = [this, newHeroSet](const CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
showQuickBackpackWindow(newHeroSet->getHero(), artPlace.slot, cursorPosition);
|
showQuickBackpackWindow(newHeroSet->getHero(), artPlace.slot, cursorPosition);
|
||||||
};
|
};
|
||||||
|
@ -195,14 +195,7 @@ void CMarketWindow::createArtifactsSelling(const IMarket * market, const CGHeroI
|
|||||||
auto artsSellingMarket = std::make_shared<CArtifactsSelling>(market, hero);
|
auto artsSellingMarket = std::make_shared<CArtifactsSelling>(market, hero);
|
||||||
artSets.clear();
|
artSets.clear();
|
||||||
const auto heroArts = artsSellingMarket->getAOHset();
|
const auto heroArts = artsSellingMarket->getAOHset();
|
||||||
heroArts->clickPressedCallback = [heroArts](CArtPlace & artPlace, const Point & cursorPosition)
|
heroArts->showPopupCallback = [this, heroArts](CArtPlace & artPlace, const Point & cursorPosition){showArifactInfo(*heroArts, artPlace, cursorPosition);};
|
||||||
{
|
|
||||||
heroArts->onClickPressedArtPlace(artPlace);
|
|
||||||
};
|
|
||||||
heroArts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
showArifactInfo(artPlace, cursorPosition);
|
|
||||||
};
|
|
||||||
addSet(heroArts);
|
addSet(heroArts);
|
||||||
marketWidget = artsSellingMarket;
|
marketWidget = artsSellingMarket;
|
||||||
initWidgetInternals(EMarketMode::ARTIFACT_RESOURCE, CGI->generaltexth->zelp[600]);
|
initWidgetInternals(EMarketMode::ARTIFACT_RESOURCE, CGI->generaltexth->zelp[600]);
|
||||||
@ -244,7 +237,7 @@ void CMarketWindow::createAltarArtifacts(const IMarket * market, const CGHeroIns
|
|||||||
marketWidget = altarArtifacts;
|
marketWidget = altarArtifacts;
|
||||||
artSets.clear();
|
artSets.clear();
|
||||||
const auto heroArts = altarArtifacts->getAOHset();
|
const auto heroArts = altarArtifacts->getAOHset();
|
||||||
heroArts->clickPressedCallback = [this, heroArts](CArtPlace & artPlace, const Point & cursorPosition)
|
heroArts->clickPressedCallback = [this, heroArts](const CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, true, false);
|
clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, true, false);
|
||||||
};
|
};
|
||||||
@ -252,7 +245,7 @@ void CMarketWindow::createAltarArtifacts(const IMarket * market, const CGHeroIns
|
|||||||
{
|
{
|
||||||
showArtifactAssembling(*heroArts, artPlace, cursorPosition);
|
showArtifactAssembling(*heroArts, artPlace, cursorPosition);
|
||||||
};
|
};
|
||||||
heroArts->gestureCallback = [this, heroArts](CArtPlace & artPlace, const Point & cursorPosition)
|
heroArts->gestureCallback = [this, heroArts](const CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
showQuickBackpackWindow(heroArts->getHero(), artPlace.slot, cursorPosition);
|
showQuickBackpackWindow(heroArts->getHero(), artPlace.slot, cursorPosition);
|
||||||
};
|
};
|
||||||
|
@ -44,16 +44,11 @@ void CWindowWithArtifacts::addSet(const std::shared_ptr<CArtifactsOfHeroBase> &
|
|||||||
artSets.emplace_back(newArtSet);
|
artSets.emplace_back(newArtSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::addCloseCallback(const CloseCallback & callback)
|
const CGHeroInstance * CWindowWithArtifacts::getHeroPickedArtifact() const
|
||||||
{
|
|
||||||
closeCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CGHeroInstance * CWindowWithArtifacts::getHeroPickedArtifact()
|
|
||||||
{
|
{
|
||||||
const CGHeroInstance * hero = nullptr;
|
const CGHeroInstance * hero = nullptr;
|
||||||
|
|
||||||
for(auto & artSet : artSets)
|
for(const auto & artSet : artSets)
|
||||||
if(const auto pickedArt = artSet->getHero()->getArt(ArtifactPosition::TRANSITION_POS))
|
if(const auto pickedArt = artSet->getHero()->getArt(ArtifactPosition::TRANSITION_POS))
|
||||||
{
|
{
|
||||||
hero = artSet->getHero();
|
hero = artSet->getHero();
|
||||||
@ -62,11 +57,11 @@ const CGHeroInstance * CWindowWithArtifacts::getHeroPickedArtifact()
|
|||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CArtifactInstance * CWindowWithArtifacts::getPickedArtifact()
|
const CArtifactInstance * CWindowWithArtifacts::getPickedArtifact() const
|
||||||
{
|
{
|
||||||
const CArtifactInstance * art = nullptr;
|
const CArtifactInstance * art = nullptr;
|
||||||
|
|
||||||
for(auto & artSet : artSets)
|
for(const auto & artSet : artSets)
|
||||||
if(const auto pickedArt = artSet->getHero()->getArt(ArtifactPosition::TRANSITION_POS))
|
if(const auto pickedArt = artSet->getHero()->getArt(ArtifactPosition::TRANSITION_POS))
|
||||||
{
|
{
|
||||||
art = pickedArt;
|
art = pickedArt;
|
||||||
@ -108,11 +103,10 @@ void CWindowWithArtifacts::clickPressedOnArtPlace(const CGHeroInstance * hero, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::swapArtifactAndClose(const CArtifactsOfHeroBase & artsInst, const ArtifactPosition & slot,
|
void CWindowWithArtifacts::swapArtifactAndClose(const CArtifactsOfHeroBase & artsInst, const ArtifactPosition & slot,
|
||||||
const ArtifactLocation & dstLoc) const
|
const ArtifactLocation & dstLoc)
|
||||||
{
|
{
|
||||||
LOCPLINT->cb->swapArtifacts(ArtifactLocation(artsInst.getHero()->id, slot), dstLoc);
|
LOCPLINT->cb->swapArtifacts(ArtifactLocation(artsInst.getHero()->id, slot), dstLoc);
|
||||||
if(closeCallback)
|
close();
|
||||||
closeCallback();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace,
|
void CWindowWithArtifacts::showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace,
|
||||||
@ -129,9 +123,9 @@ void CWindowWithArtifacts::showArtifactAssembling(const CArtifactsOfHeroBase & a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::showArifactInfo(CArtPlace & artPlace, const Point & cursorPosition) const
|
void CWindowWithArtifacts::showArifactInfo(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition) const
|
||||||
{
|
{
|
||||||
if(artPlace.getArt() && artPlace.text.size())
|
if(artsInst.getArt(artPlace.slot) && artPlace.text.size())
|
||||||
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +170,7 @@ void CWindowWithArtifacts::artifactRemoved(const ArtifactLocation & artLoc)
|
|||||||
|
|
||||||
void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc)
|
void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc)
|
||||||
{
|
{
|
||||||
for(auto & artSet : artSets)
|
for(const auto & artSet : artSets)
|
||||||
if(const auto pickedArtInst = getPickedArtifact())
|
if(const auto pickedArtInst = getPickedArtifact())
|
||||||
{
|
{
|
||||||
markPossibleSlots();
|
markPossibleSlots();
|
||||||
@ -202,7 +196,7 @@ void CWindowWithArtifacts::artifactAssembled(const ArtifactLocation & artLoc)
|
|||||||
|
|
||||||
void CWindowWithArtifacts::update()
|
void CWindowWithArtifacts::update()
|
||||||
{
|
{
|
||||||
for(auto & artSet : artSets)
|
for(const auto & artSet : artSets)
|
||||||
{
|
{
|
||||||
artSet->updateWornSlots();
|
artSet->updateWornSlots();
|
||||||
artSet->updateBackpackSlots();
|
artSet->updateBackpackSlots();
|
||||||
@ -213,20 +207,19 @@ void CWindowWithArtifacts::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::markPossibleSlots()
|
void CWindowWithArtifacts::markPossibleSlots() const
|
||||||
{
|
{
|
||||||
if(const auto pickedArtInst = getPickedArtifact())
|
if(const auto pickedArtInst = getPickedArtifact())
|
||||||
{
|
{
|
||||||
const auto heroArtOwner = getHeroPickedArtifact();
|
for(const auto & artSet : artSets)
|
||||||
for(auto & artSet : artSets)
|
|
||||||
{
|
{
|
||||||
if(artSet->isActive())
|
const auto hero = artSet->getHero();
|
||||||
{
|
if(hero == nullptr || !artSet->isActive())
|
||||||
const auto hero = artSet->getHero();
|
continue;
|
||||||
if(heroArtOwner == hero || !std::dynamic_pointer_cast<CArtifactsOfHeroKingdom>(artSet))
|
|
||||||
artSet->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
if(getHeroPickedArtifact() == hero || !std::dynamic_pointer_cast<CArtifactsOfHeroKingdom>(artSet))
|
||||||
}
|
artSet->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +248,7 @@ bool CWindowWithArtifacts::checkSpecialArts(const CArtifactInstance & artInst, c
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::setCursorAnimation(const CArtifactInstance & artInst)
|
void CWindowWithArtifacts::setCursorAnimation(const CArtifactInstance & artInst) const
|
||||||
{
|
{
|
||||||
if(artInst.isScroll() && settings["general"]["enableUiEnhancements"].Bool())
|
if(artInst.isScroll() && settings["general"]["enableUiEnhancements"].Bool())
|
||||||
{
|
{
|
||||||
@ -270,7 +263,7 @@ void CWindowWithArtifacts::setCursorAnimation(const CArtifactInstance & artInst)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::putPickedArtifact(const CGHeroInstance & curHero, const ArtifactPosition & targetSlot)
|
void CWindowWithArtifacts::putPickedArtifact(const CGHeroInstance & curHero, const ArtifactPosition & targetSlot) const
|
||||||
{
|
{
|
||||||
const auto heroArtOwner = getHeroPickedArtifact();
|
const auto heroArtOwner = getHeroPickedArtifact();
|
||||||
const auto pickedArt = getPickedArtifact();
|
const auto pickedArt = getPickedArtifact();
|
||||||
@ -307,16 +300,13 @@ void CWindowWithArtifacts::onClickPressedCommonArtifact(const CGHeroInstance & c
|
|||||||
|
|
||||||
if(GH.isKeyboardCmdDown())
|
if(GH.isKeyboardCmdDown())
|
||||||
{
|
{
|
||||||
for(auto & anotherSet : artSets)
|
for(const auto & anotherSet : artSets)
|
||||||
{
|
{
|
||||||
if(std::dynamic_pointer_cast<CArtifactsOfHeroMain>(anotherSet))
|
if(std::dynamic_pointer_cast<CArtifactsOfHeroMain>(anotherSet) && curHero.id != anotherSet->getHero()->id)
|
||||||
{
|
{
|
||||||
if(curHero.id != anotherSet->getHero()->id)
|
dstLoc.slot = ArtifactPosition::FIRST_AVAILABLE;
|
||||||
{
|
dstLoc.artHolder = anotherSet->getHero()->id;
|
||||||
dstLoc.slot = ArtifactPosition::FIRST_AVAILABLE;
|
break;
|
||||||
dstLoc.artHolder = anotherSet->getHero()->id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(const auto heroSetAltar = std::dynamic_pointer_cast<CArtifactsOfHeroAltar>(anotherSet))
|
if(const auto heroSetAltar = std::dynamic_pointer_cast<CArtifactsOfHeroAltar>(anotherSet))
|
||||||
{
|
{
|
||||||
@ -334,11 +324,10 @@ void CWindowWithArtifacts::onClickPressedCommonArtifact(const CGHeroInstance & c
|
|||||||
else if(ArtifactUtils::isSlotBackpack(slot))
|
else if(ArtifactUtils::isSlotBackpack(slot))
|
||||||
dstLoc.slot = ArtifactUtils::getArtEquippedPosition(&curHero, artId);
|
dstLoc.slot = ArtifactUtils::getArtEquippedPosition(&curHero, artId);
|
||||||
}
|
}
|
||||||
else if(closeWindow && closeCallback)
|
else if(closeWindow)
|
||||||
{
|
{
|
||||||
closeCallback();
|
close();
|
||||||
}
|
}
|
||||||
if(dstLoc.slot != ArtifactPosition::PRE_FIRST)
|
if(dstLoc.slot != ArtifactPosition::PRE_FIRST)
|
||||||
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
|
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,21 +20,18 @@ class CWindowWithArtifacts : virtual public CWindowObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using CArtifactsOfHeroPtr = std::shared_ptr<CArtifactsOfHeroBase>;
|
using CArtifactsOfHeroPtr = std::shared_ptr<CArtifactsOfHeroBase>;
|
||||||
using CloseCallback = std::function<void()>;
|
|
||||||
|
|
||||||
std::vector<CArtifactsOfHeroPtr> artSets;
|
std::vector<CArtifactsOfHeroPtr> artSets;
|
||||||
CloseCallback closeCallback;
|
|
||||||
|
|
||||||
explicit CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr> * artSets = nullptr);
|
explicit CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr> * artSets = nullptr);
|
||||||
void addSet(const std::shared_ptr<CArtifactsOfHeroBase> & newArtSet);
|
void addSet(const std::shared_ptr<CArtifactsOfHeroBase> & newArtSet);
|
||||||
void addCloseCallback(const CloseCallback & callback);
|
const CGHeroInstance * getHeroPickedArtifact() const;
|
||||||
const CGHeroInstance * getHeroPickedArtifact();
|
const CArtifactInstance * getPickedArtifact() const;
|
||||||
const CArtifactInstance * getPickedArtifact();
|
|
||||||
void clickPressedOnArtPlace(const CGHeroInstance * hero, const ArtifactPosition & slot,
|
void clickPressedOnArtPlace(const CGHeroInstance * hero, const ArtifactPosition & slot,
|
||||||
bool allowExchange, bool altarTrading, bool closeWindow);
|
bool allowExchange, bool altarTrading, bool closeWindow);
|
||||||
void swapArtifactAndClose(const CArtifactsOfHeroBase & artsInst, const ArtifactPosition & slot, const ArtifactLocation & dstLoc) const;
|
void swapArtifactAndClose(const CArtifactsOfHeroBase & artsInst, const ArtifactPosition & slot, const ArtifactLocation & dstLoc);
|
||||||
void showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition) const;
|
void showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition) const;
|
||||||
void showArifactInfo(CArtPlace & artPlace, const Point & cursorPosition) const;
|
void showArifactInfo(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition) const;
|
||||||
void showQuickBackpackWindow(const CGHeroInstance * hero, const ArtifactPosition & slot, const Point & cursorPosition) const;
|
void showQuickBackpackWindow(const CGHeroInstance * hero, const ArtifactPosition & slot, const Point & cursorPosition) const;
|
||||||
void activate() override;
|
void activate() override;
|
||||||
void deactivate() override;
|
void deactivate() override;
|
||||||
@ -47,9 +44,9 @@ public:
|
|||||||
virtual void update();
|
virtual void update();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void markPossibleSlots();
|
void markPossibleSlots() const;
|
||||||
bool checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance & hero, bool isTrade) const;
|
bool checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance & hero, bool isTrade) const;
|
||||||
void setCursorAnimation(const CArtifactInstance & artInst);
|
void setCursorAnimation(const CArtifactInstance & artInst) const;
|
||||||
void putPickedArtifact(const CGHeroInstance & curHero, const ArtifactPosition & targetSlot);
|
void putPickedArtifact(const CGHeroInstance & curHero, const ArtifactPosition & targetSlot) const;
|
||||||
void onClickPressedCommonArtifact(const CGHeroInstance & curHero, const ArtifactPosition & slot, bool closeWindow);
|
void onClickPressedCommonArtifact(const CGHeroInstance & curHero, const ArtifactPosition & slot, bool closeWindow);
|
||||||
};
|
};
|
||||||
|
@ -759,35 +759,16 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
}
|
}
|
||||||
|
|
||||||
artifs[0] = std::make_shared<CArtifactsOfHeroMain>(Point(-334, 151));
|
artifs[0] = std::make_shared<CArtifactsOfHeroMain>(Point(-334, 151));
|
||||||
|
artifs[0]->clickPressedCallback = [this, hero = heroInst[0]](const CArtPlace & artPlace, const Point & cursorPosition){clickPressedOnArtPlace(hero, artPlace.slot, true, false, false);};
|
||||||
|
artifs[0]->showPopupCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition){showArtifactAssembling(*heroArts, artPlace, cursorPosition);};
|
||||||
|
artifs[0]->gestureCallback = [this, hero = heroInst[0]](const CArtPlace & artPlace, const Point & cursorPosition){showQuickBackpackWindow(hero, artPlace.slot, cursorPosition);};
|
||||||
artifs[0]->setHero(heroInst[0]);
|
artifs[0]->setHero(heroInst[0]);
|
||||||
artifs[1] = std::make_shared<CArtifactsOfHeroMain>(Point(98, 151));
|
artifs[1] = std::make_shared<CArtifactsOfHeroMain>(Point(98, 151));
|
||||||
|
artifs[1]->clickPressedCallback = [this, hero = heroInst[1]](const CArtPlace & artPlace, const Point & cursorPosition){clickPressedOnArtPlace(hero, artPlace.slot, true, false, false);};
|
||||||
|
artifs[1]->showPopupCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition){showArtifactAssembling(*heroArts, artPlace, cursorPosition);};
|
||||||
|
artifs[1]->gestureCallback = [this, hero = heroInst[1]](const CArtPlace & artPlace, const Point & cursorPosition){showQuickBackpackWindow(hero, artPlace.slot, cursorPosition);};
|
||||||
artifs[1]->setHero(heroInst[1]);
|
artifs[1]->setHero(heroInst[1]);
|
||||||
|
|
||||||
artifs[0]->clickPressedCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, false, false);
|
|
||||||
};
|
|
||||||
artifs[0]->showPopupCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
showArtifactAssembling(*heroArts, artPlace, cursorPosition);
|
|
||||||
};
|
|
||||||
artifs[0]->gestureCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
showQuickBackpackWindow(heroArts->getHero(), artPlace.slot, cursorPosition);
|
|
||||||
};
|
|
||||||
artifs[1]->clickPressedCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, false, false);
|
|
||||||
};
|
|
||||||
artifs[1]->showPopupCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
showArtifactAssembling(*heroArts, artPlace, cursorPosition);
|
|
||||||
};
|
|
||||||
artifs[1]->gestureCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition)
|
|
||||||
{
|
|
||||||
showQuickBackpackWindow(heroArts->getHero(), artPlace.slot, cursorPosition);
|
|
||||||
};
|
|
||||||
|
|
||||||
addSet(artifs[0]);
|
addSet(artifs[0]);
|
||||||
addSet(artifs[1]);
|
addSet(artifs[1]);
|
||||||
|
|
||||||
@ -950,7 +931,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
CWindowWithArtifacts::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CGarrisonSlot * CExchangeWindow::getSelectedSlotID() const
|
const CGarrisonSlot * CExchangeWindow::getSelectedSlotID() const
|
||||||
|
Reference in New Issue
Block a user