CHeroBackpackWindow.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * CHeroBackpackWindow.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 "CHeroBackpackWindow.h"
  12. #include "../gui/CGuiHandler.h"
  13. #include "../gui/Shortcut.h"
  14. #include "../widgets/Buttons.h"
  15. #include "../widgets/Images.h"
  16. #include "CMessage.h"
  17. #include "render/Canvas.h"
  18. #include "CPlayerInterface.h"
  19. CHeroBackpackWindow::CHeroBackpackWindow()
  20. : CWindowObject((EOptions)0)
  21. {
  22. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  23. stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
  24. }
  25. CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero)
  26. : CHeroBackpackWindow()
  27. {
  28. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  29. arts = std::make_shared<CArtifactsOfHeroBackpack>(Point(windowMargin, windowMargin));
  30. addSetAndCallbacks(arts);
  31. arts->setHero(hero);
  32. addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
  33. init();
  34. center();
  35. }
  36. void CHeroBackpackWindow::init()
  37. {
  38. quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""), [this]() { close(); }, EShortcut::GLOBAL_RETURN);
  39. pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
  40. pos.h = stretchedBackground->pos.h = arts->pos.h + quitButton->pos.h + 3 * windowMargin;
  41. quitButton->moveTo(Point(pos.x + pos.w / 2 - quitButton->pos.w / 2, pos.y + arts->pos.h + 2 * windowMargin));
  42. }
  43. void CHeroBackpackWindow::showAll(Canvas & to)
  44. {
  45. CIntObject::showAll(to);
  46. CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to.getInternalSurface(), pos.w+28, pos.h+29, pos.x-14, pos.y-15);
  47. }
  48. CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot)
  49. : CHeroBackpackWindow()
  50. {
  51. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  52. auto artsQuickBp = std::make_shared<CArtifactsOfHeroQuickBackpack>(Point(windowMargin, windowMargin), targetSlot);
  53. addSetAndCallbacks(static_cast<std::weak_ptr<CArtifactsOfHeroQuickBackpack>>(artsQuickBp));
  54. arts = artsQuickBp;
  55. arts->setHero(hero);
  56. addCloseCallback(std::bind(&CHeroQuickBackpackWindow::close, this));
  57. init();
  58. }
  59. void CHeroQuickBackpackWindow::showAll(Canvas & to)
  60. {
  61. if(arts->getSlotsNum() == 0)
  62. {
  63. close();
  64. return;
  65. }
  66. CHeroBackpackWindow::showAll(to);
  67. }