CArtifactsOfHeroMarket.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/entities/artifact/CArtifact.h"
  13. #include "../../lib/mapObjects/CGHeroInstance.h"
  14. CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position, const int selectionWidth)
  15. {
  16. init(position, std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
  17. setClickPressedArtPlacesCallback(std::bind(&CArtifactsOfHeroBase::clickPressedArtPlace, this, _1, _2));
  18. for(const auto & [slot, artPlace] : artWorn)
  19. artPlace->setSelectionWidth(selectionWidth);
  20. for(auto artPlace : backpack)
  21. artPlace->setSelectionWidth(selectionWidth);
  22. };
  23. void CArtifactsOfHeroMarket::clickPressedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition)
  24. {
  25. if(auto ownedPlace = getArtPlace(cursorPosition))
  26. {
  27. if(ownedPlace->isLocked())
  28. return;
  29. if(const auto art = getArt(ownedPlace->slot))
  30. {
  31. if(onSelectArtCallback && art->getType()->isTradable())
  32. {
  33. unmarkSlots();
  34. artPlace.selectSlot(true);
  35. onSelectArtCallback(ownedPlace.get());
  36. }
  37. else
  38. {
  39. if(onClickNotTradableCallback)
  40. onClickNotTradableCallback();
  41. }
  42. }
  43. }
  44. }