CHeroBackpackWindow.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "../widgets/TextControls.h"
  17. #include "CMessage.h"
  18. #include "render/Canvas.h"
  19. #include "CPlayerInterface.h"
  20. CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets)
  21. : CStatusbarWindow(0)
  22. , CWindowWithArtifacts(&artsSets)
  23. {
  24. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  25. stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
  26. arts = std::make_shared<CArtifactsOfHeroBackpack>();
  27. arts->moveBy(Point(windowMargin, windowMargin));
  28. addSetAndCallbacks(arts);
  29. arts->setHero(hero);
  30. addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
  31. quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""),
  32. [this]() { WindowBase::close(); }, EShortcut::GLOBAL_RETURN);
  33. pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
  34. pos.h = stretchedBackground->pos.h = arts->pos.h + quitButton->pos.h + 3 * windowMargin;
  35. quitButton->moveTo(Point(pos.x + pos.w / 2 - quitButton->pos.w / 2, pos.y + arts->pos.h + 2 * windowMargin));
  36. statusbar = CGStatusBar::create(0, pos.h, ImagePath::builtin("ADROLLVR.bmp"), pos.w);
  37. pos.h += statusbar->pos.h;
  38. center();
  39. }
  40. void CHeroBackpackWindow::showAll(Canvas & to)
  41. {
  42. CIntObject::showAll(to);
  43. CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
  44. }
  45. void CHeroBackpackWindow::activate()
  46. {
  47. if(const auto art = getPickedArtifact())
  48. setCursorAnimation(*art);
  49. CIntObject::activate();
  50. }
  51. CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot)
  52. : CWindowObject(0)
  53. {
  54. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  55. stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
  56. arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
  57. arts->moveBy(Point(windowMargin, windowMargin));
  58. addSetAndCallbacks(static_cast<std::weak_ptr<CArtifactsOfHeroQuickBackpack>>(arts));
  59. arts->setHero(hero);
  60. addCloseCallback(std::bind(&CHeroQuickBackpackWindow::close, this));
  61. addUsedEvents(GESTURE);
  62. pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
  63. pos.h = stretchedBackground->pos.h = arts->pos.h + windowMargin;
  64. }
  65. void CHeroQuickBackpackWindow::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
  66. {
  67. if(on)
  68. return;
  69. arts->swapSelected();
  70. close();
  71. }
  72. void CHeroQuickBackpackWindow::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
  73. {
  74. arts->selectSlotAt(currentPosition);
  75. redraw();
  76. }
  77. void CHeroQuickBackpackWindow::showAll(Canvas & to)
  78. {
  79. if(arts->getSlotsNum() == 0)
  80. {
  81. // Dirty solution for closing that window
  82. close();
  83. return;
  84. }
  85. CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w + 28, pos.h + 29, pos.x - 14, pos.y - 15);
  86. CIntObject::showAll(to);
  87. }