CHeroBackpackWindow.cpp 3.7 KB

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