CArtifactsOfHeroMarket.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * CArtifactsOfHeroMarket.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CArtifactsOfHeroMarket.h"
  12. #include "../../lib/mapObjects/CGHeroInstance.h"
  13. CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position, const int selectionWidth)
  14. {
  15. init(position, std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
  16. setClickPressedArtPlacesCallback(std::bind(&CArtifactsOfHeroBase::clickPressedArtPlace, this, _1, _2));
  17. for(const auto & [slot, artPlace] : artWorn)
  18. artPlace->setSelectionWidth(selectionWidth);
  19. for(auto artPlace : backpack)
  20. artPlace->setSelectionWidth(selectionWidth);
  21. };
  22. void CArtifactsOfHeroMarket::clickPressedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition)
  23. {
  24. auto ownedPlace = getArtPlace(cursorPosition);
  25. assert(ownedPlace != nullptr);
  26. if(ownedPlace->isLocked())
  27. return;
  28. if(const auto art = getArt(ownedPlace->slot))
  29. {
  30. if(onSelectArtCallback && art->getType()->isTradable())
  31. {
  32. unmarkSlots();
  33. artPlace.selectSlot(true);
  34. onSelectArtCallback(ownedPlace.get());
  35. }
  36. else
  37. {
  38. if(onClickNotTradableCallback)
  39. onClickNotTradableCallback();
  40. }
  41. }
  42. }