CAltarWindow.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "../render/Canvas.h"
  13. #include "../widgets/TextControls.h"
  14. #include "../CGameInfo.h"
  15. #include "../lib/networkPacks/ArtifactLocation.h"
  16. #include "../../lib/CHeroHandler.h"
  17. #include "../../lib/mapObjects/CGHeroInstance.h"
  18. void CAltarWindow::updateExpToLevel()
  19. {
  20. assert(altar);
  21. altar->expToLevel->setText(std::to_string(CGI->heroh->reqExp(CGI->heroh->level(altar->hero->exp) + 1) - altar->hero->exp));
  22. }
  23. void CAltarWindow::updateGarrisons()
  24. {
  25. if(auto altarCreatures = std::static_pointer_cast<CAltarCreatures>(altar))
  26. altarCreatures->updateSlots();
  27. }
  28. bool CAltarWindow::holdsGarrison(const CArmedInstance * army)
  29. {
  30. return getHero() == army;
  31. }
  32. void CAltarWindow::artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw)
  33. {
  34. if(!getState().has_value())
  35. return;
  36. if(auto altarArtifacts = std::static_pointer_cast<CAltarArtifacts>(altar))
  37. {
  38. if(srcLoc.artHolder == altarArtifacts->getObjId() || destLoc.artHolder == altarArtifacts->getObjId())
  39. altarArtifacts->updateSlots();
  40. if(const auto pickedArt = getPickedArtifact())
  41. altarArtifacts->setSelectedArtifact(pickedArt);
  42. else
  43. altarArtifacts->setSelectedArtifact(nullptr);
  44. }
  45. CWindowWithArtifacts::artifactMoved(srcLoc, destLoc, withRedraw);
  46. }
  47. /*void CAltarWindow::showAll(Canvas& to)
  48. {
  49. // This func is temporary workaround for compliance with CTradeWindow
  50. CWindowObject::showAll(to);
  51. if(altar->hRight)
  52. {
  53. altar->hRight->showAllAt(altar->pos.topLeft() + Point(396, 423), "", to);
  54. }
  55. if(altar->hLeft)
  56. {
  57. altar->hLeft->showAllAt(altar->pos.topLeft() + Point(150, 423), "", to);
  58. }
  59. }*/