CHeroBackpackWindow.cpp 3.1 KB

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