CAltarWindow.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * CAltarWindow.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 "CAltarWindow.h"
  12. #include "../widgets/TextControls.h"
  13. #include "../CGameInfo.h"
  14. #include "../lib/networkPacks/ArtifactLocation.h"
  15. #include "../../lib/CHeroHandler.h"
  16. #include "../../lib/mapObjects/CGHeroInstance.h"
  17. void CAltarWindow::updateExpToLevel()
  18. {
  19. assert(altar);
  20. altar->expToLevel->setText(std::to_string(CGI->heroh->reqExp(CGI->heroh->level(altar->hero->exp) + 1) - altar->hero->exp));
  21. }
  22. void CAltarWindow::updateGarrisons()
  23. {
  24. if(auto altarCreatures = std::static_pointer_cast<CAltarCreatures>(altar))
  25. altarCreatures->updateSlots();
  26. }
  27. bool CAltarWindow::holdsGarrison(const CArmedInstance * army)
  28. {
  29. return getHero() == army;
  30. }
  31. void CAltarWindow::artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw)
  32. {
  33. if(!getState().has_value())
  34. return;
  35. if(auto altarArtifacts = std::static_pointer_cast<CAltarArtifacts>(altar))
  36. {
  37. if(srcLoc.artHolder == altarArtifacts->getObjId() || destLoc.artHolder == altarArtifacts->getObjId())
  38. altarArtifacts->updateSlots();
  39. if(const auto pickedArt = getPickedArtifact())
  40. altarArtifacts->setSelectedArtifact(pickedArt);
  41. else
  42. altarArtifacts->setSelectedArtifact(nullptr);
  43. }
  44. CWindowWithArtifacts::artifactMoved(srcLoc, destLoc, withRedraw);
  45. }