CHeroBackpackWindow.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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)
  21. : CStatusbarWindow(0)
  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.getInternalSurface(), pos.w+28, pos.h+29, pos.x-14, pos.y-15);
  43. }
  44. CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot)
  45. : CWindowObject(0)
  46. {
  47. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  48. stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
  49. arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
  50. arts->moveBy(Point(windowMargin, windowMargin));
  51. addSetAndCallbacks(static_cast<std::weak_ptr<CArtifactsOfHeroQuickBackpack>>(arts));
  52. arts->setHero(hero);
  53. addCloseCallback(std::bind(&CHeroQuickBackpackWindow::close, this));
  54. addUsedEvents(GESTURE);
  55. pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
  56. pos.h = stretchedBackground->pos.h = arts->pos.h + windowMargin;
  57. }
  58. void CHeroQuickBackpackWindow::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
  59. {
  60. if(on)
  61. return;
  62. arts->swapSelected();
  63. close();
  64. }
  65. void CHeroQuickBackpackWindow::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
  66. {
  67. arts->selectSlotAt(currentPosition);
  68. redraw();
  69. }
  70. void CHeroQuickBackpackWindow::showAll(Canvas & to)
  71. {
  72. if(arts->getSlotsNum() == 0)
  73. {
  74. // Dirty solution for closing that window
  75. close();
  76. return;
  77. }
  78. CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to.getInternalSurface(), pos.w + 28, pos.h + 29, pos.x - 14, pos.y - 15);
  79. CIntObject::showAll(to);
  80. }