CHeroBackpackWindow.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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(const CGHeroInstance * hero)
  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. arts = std::make_shared<CArtifactsOfHeroBackpack>();
  25. arts->moveBy(Point(windowMargin, windowMargin));
  26. addSetAndCallbacks(arts);
  27. arts->setHero(hero);
  28. addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
  29. quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""), [this]() { close(); }, EShortcut::GLOBAL_RETURN);
  30. pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
  31. pos.h = stretchedBackground->pos.h = arts->pos.h + quitButton->pos.h + 3 * windowMargin;
  32. quitButton->moveTo(Point(pos.x + pos.w / 2 - quitButton->pos.w / 2, pos.y + arts->pos.h + 2 * windowMargin));
  33. center();
  34. }
  35. void CHeroBackpackWindow::showAll(Canvas & to)
  36. {
  37. CIntObject::showAll(to);
  38. CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to.getInternalSurface(), pos.w+28, pos.h+29, pos.x-14, pos.y-15);
  39. }
  40. CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot)
  41. : CWindowObject((EOptions)0)
  42. {
  43. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  44. stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
  45. arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
  46. arts->moveBy(Point(windowMargin, windowMargin));
  47. addSetAndCallbacks(static_cast<std::weak_ptr<CArtifactsOfHeroQuickBackpack>>(arts));
  48. arts->setHero(hero);
  49. addCloseCallback(std::bind(&CHeroQuickBackpackWindow::close, this));
  50. addUsedEvents(GESTURE);
  51. pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
  52. pos.h = stretchedBackground->pos.h = arts->pos.h + windowMargin;
  53. }
  54. void CHeroQuickBackpackWindow::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
  55. {
  56. if(on)
  57. return;
  58. arts->swapSelected();
  59. close();
  60. }
  61. void CHeroQuickBackpackWindow::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
  62. {
  63. arts->selectSlotAt(currentPosition);
  64. redraw();
  65. }
  66. void CHeroQuickBackpackWindow::showAll(Canvas & to)
  67. {
  68. if(arts->getSlotsNum() == 0)
  69. {
  70. // Dirty solution for closing that window
  71. close();
  72. return;
  73. }
  74. CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to.getInternalSurface(), pos.w + 28, pos.h + 29, pos.x - 14, pos.y - 15);
  75. CIntObject::showAll(to);
  76. }