CAltarWindow.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 "../gui/CGuiHandler.h"
  13. #include "../render/Canvas.h"
  14. #include "../gui/Shortcut.h"
  15. #include "../widgets/Buttons.h"
  16. #include "../widgets/TextControls.h"
  17. #include "../CGameInfo.h"
  18. #include "../../lib/CGeneralTextHandler.h"
  19. #include "../../lib/CHeroHandler.h"
  20. #include "../../lib/mapObjects/CGHeroInstance.h"
  21. CAltarWindow::CAltarWindow(const IMarket * market, const CGHeroInstance * hero, const std::function<void()> & onWindowClosed, EMarketMode mode)
  22. : CWindowObject(PLAYER_COLORED, ImagePath::builtin(mode == EMarketMode::CREATURE_EXP ? "ALTARMON.bmp" : "ALTRART2.bmp"))
  23. , hero(hero)
  24. , windowClosedCallback(onWindowClosed)
  25. {
  26. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
  27. if(mode == EMarketMode::ARTIFACT_EXP)
  28. createAltarArtifacts(market, hero);
  29. else if (mode == EMarketMode::CREATURE_EXP)
  30. createAltarCreatures(market, hero);
  31. else
  32. close();
  33. updateExpToLevel();
  34. statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
  35. }
  36. void CAltarWindow::updateExpToLevel()
  37. {
  38. altar->expToLevel->setText(std::to_string(CGI->heroh->reqExp(CGI->heroh->level(altar->hero->exp) + 1) - altar->hero->exp));
  39. }
  40. void CAltarWindow::updateGarrison()
  41. {
  42. if(auto altarCreatures = std::static_pointer_cast<CAltarCreatures>(altar))
  43. altarCreatures->updateGarrison();
  44. }
  45. const CGHeroInstance * CAltarWindow::getHero() const
  46. {
  47. return hero;
  48. }
  49. void CAltarWindow::close()
  50. {
  51. if(windowClosedCallback)
  52. windowClosedCallback();
  53. CWindowObject::close();
  54. }
  55. void CAltarWindow::createAltarArtifacts(const IMarket * market, const CGHeroInstance * hero)
  56. {
  57. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
  58. background = createBg(ImagePath::builtin("ALTRART2.bmp"), PLAYER_COLORED);
  59. auto altarArtifacts = std::make_shared<CAltarArtifacts>(market, hero);
  60. altar = altarArtifacts;
  61. artSets.clear();
  62. addSetAndCallbacks(altarArtifacts->getAOHset());
  63. changeModeButton = std::make_shared<CButton>(Point(516, 421), AnimationPath::builtin("ALTSACC.DEF"),
  64. CGI->generaltexth->zelp[572], std::bind(&CAltarWindow::createAltarCreatures, this, market, hero));
  65. if(altar->hero->getAlignment() == EAlignment::GOOD)
  66. changeModeButton->block(true);
  67. quitButton = std::make_shared<CButton>(Point(516, 520), AnimationPath::builtin("IOK6432.DEF"),
  68. CGI->generaltexth->zelp[568], std::bind(&CAltarWindow::close, this), EShortcut::GLOBAL_RETURN);
  69. altar->setRedrawParent(true);
  70. redraw();
  71. }
  72. void CAltarWindow::createAltarCreatures(const IMarket * market, const CGHeroInstance * hero)
  73. {
  74. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
  75. background = createBg(ImagePath::builtin("ALTARMON.bmp"), PLAYER_COLORED);
  76. altar = std::make_shared<CAltarCreatures>(market, hero);
  77. changeModeButton = std::make_shared<CButton>(Point(516, 421), AnimationPath::builtin("ALTART.DEF"),
  78. CGI->generaltexth->zelp[580], std::bind(&CAltarWindow::createAltarArtifacts, this, market, hero));
  79. if(altar->hero->getAlignment() == EAlignment::EVIL)
  80. changeModeButton->block(true);
  81. quitButton = std::make_shared<CButton>(Point(516, 520), AnimationPath::builtin("IOK6432.DEF"),
  82. CGI->generaltexth->zelp[568], std::bind(&CAltarWindow::close, this), EShortcut::GLOBAL_RETURN);
  83. altar->setRedrawParent(true);
  84. redraw();
  85. }
  86. void CAltarWindow::artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw)
  87. {
  88. if(!getState().has_value())
  89. return;
  90. if(auto altarArtifacts = std::static_pointer_cast<CAltarArtifacts>(altar))
  91. {
  92. if(const auto pickedArt = getPickedArtifact())
  93. altarArtifacts->setSelectedArtifact(pickedArt);
  94. else
  95. altarArtifacts->setSelectedArtifact(nullptr);
  96. }
  97. CWindowWithArtifacts::artifactMoved(srcLoc, destLoc, withRedraw);
  98. }
  99. void CAltarWindow::showAll(Canvas & to)
  100. {
  101. // This func is temporary workaround for compliance with CTradeWindow
  102. CWindowObject::showAll(to);
  103. if(altar->hRight)
  104. {
  105. to.drawBorder(Rect::createAround(altar->hRight->pos, 1), Colors::BRIGHT_YELLOW, 2);
  106. altar->hRight->showAllAt(altar->pos.topLeft() + Point(396, 423), "", to);
  107. }
  108. if(altar->hLeft)
  109. {
  110. to.drawBorder(Rect::createAround(altar->hLeft->pos, 1), Colors::BRIGHT_YELLOW, 2);
  111. altar->hLeft->showAllAt(altar->pos.topLeft() + Point(150, 423), "", to);
  112. }
  113. }