CHeroBackpackWindow.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include "../../lib/mapObjects/CGHeroInstance.h"
  21. #include "../../lib/networkPacks/ArtifactLocation.h"
  22. CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets)
  23. : CWindowWithArtifacts(&artsSets)
  24. {
  25. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  26. stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
  27. arts = std::make_shared<CArtifactsOfHeroBackpack>();
  28. arts->moveBy(Point(windowMargin, windowMargin));
  29. arts->clickPressedCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
  30. {
  31. clickPressedOnArtPlace(arts->getHero(), artPlace.slot, true, false, true);
  32. };
  33. arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
  34. {
  35. showArtifactAssembling(*arts, artPlace, cursorPosition);
  36. };
  37. addSet(arts);
  38. arts->setHero(hero);
  39. addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
  40. quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""),
  41. [this]() { WindowBase::close(); }, EShortcut::GLOBAL_RETURN);
  42. pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
  43. pos.h = stretchedBackground->pos.h = arts->pos.h + quitButton->pos.h + 3 * windowMargin;
  44. quitButton->moveTo(Point(pos.x + pos.w / 2 - quitButton->pos.w / 2, pos.y + arts->pos.h + 2 * windowMargin));
  45. statusbar = CGStatusBar::create(0, pos.h, ImagePath::builtin("ADROLLVR.bmp"), pos.w);
  46. pos.h += statusbar->pos.h;
  47. center();
  48. }
  49. void CHeroBackpackWindow::showAll(Canvas & to)
  50. {
  51. CIntObject::showAll(to);
  52. CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
  53. }
  54. CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot)
  55. {
  56. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  57. stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
  58. arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
  59. arts->moveBy(Point(windowMargin, windowMargin));
  60. arts->clickPressedCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
  61. {
  62. if(const auto curHero = arts->getHero())
  63. swapArtifactAndClose(*arts, artPlace.slot, ArtifactLocation(curHero->id, arts->getFilterSlot()));
  64. };
  65. arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
  66. {
  67. showArifactInfo(artPlace, cursorPosition);
  68. };
  69. addSet(arts);
  70. arts->setHero(hero);
  71. addCloseCallback(std::bind(&CHeroQuickBackpackWindow::close, this));
  72. addUsedEvents(GESTURE);
  73. pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
  74. pos.h = stretchedBackground->pos.h = arts->pos.h + windowMargin;
  75. }
  76. void CHeroQuickBackpackWindow::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
  77. {
  78. if(on)
  79. return;
  80. arts->swapSelected();
  81. close();
  82. }
  83. void CHeroQuickBackpackWindow::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
  84. {
  85. arts->selectSlotAt(currentPosition);
  86. redraw();
  87. }
  88. void CHeroQuickBackpackWindow::showAll(Canvas & to)
  89. {
  90. if(arts->getSlotsNum() == 0)
  91. {
  92. // Dirty solution for closing that window
  93. close();
  94. return;
  95. }
  96. CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w + 28, pos.h + 29, pos.x - 14, pos.y - 15);
  97. CIntObject::showAll(to);
  98. }