CAdvMapPanel.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * CAdvMapPanel.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 "CAdvMapPanel.h"
  12. #include "../widgets/Buttons.h"
  13. #include "../widgets/Images.h"
  14. #include "../render/CAnimation.h"
  15. #include "../render/IImage.h"
  16. #include "../gui/CGuiHandler.h"
  17. CAdvMapPanel::CAdvMapPanel(std::shared_ptr<IImage> bg, Point position)
  18. : CIntObject()
  19. , background(bg)
  20. {
  21. defActions = 255;
  22. recActions = 255;
  23. pos.x += position.x;
  24. pos.y += position.y;
  25. if (bg)
  26. {
  27. pos.w = bg->width();
  28. pos.h = bg->height();
  29. }
  30. }
  31. void CAdvMapPanel::addChildColorableButton(std::shared_ptr<CButton> button)
  32. {
  33. colorableButtons.push_back(button);
  34. addChildToPanel(button, ACTIVATE | DEACTIVATE);
  35. }
  36. void CAdvMapPanel::setPlayerColor(const PlayerColor & clr)
  37. {
  38. for(auto & button : colorableButtons)
  39. {
  40. button->setPlayerColor(clr);
  41. }
  42. }
  43. void CAdvMapPanel::showAll(SDL_Surface * to)
  44. {
  45. if(background)
  46. background->draw(to, pos.x, pos.y);
  47. CIntObject::showAll(to);
  48. }
  49. void CAdvMapPanel::addChildToPanel(std::shared_ptr<CIntObject> obj, ui8 actions)
  50. {
  51. otherObjects.push_back(obj);
  52. obj->recActions |= actions | SHOWALL;
  53. obj->recActions &= ~DISPOSE;
  54. addChild(obj.get(), false);
  55. }
  56. CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(std::shared_ptr<CAnimation> _icons, std::shared_ptr<IImage> bg, Point position, int spaceBottom, const PlayerColor &color)
  57. : CAdvMapPanel(bg, position), icons(_icons)
  58. {
  59. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  60. int fillerHeight = bg ? spaceBottom - pos.y - pos.h : 0;
  61. if(fillerHeight > 0)
  62. {
  63. backgroundFiller = std::make_shared<CFilledTexture>("DIBOXBCK", Rect(0, pos.h, pos.w, fillerHeight));
  64. }
  65. }
  66. CAdvMapWorldViewPanel::~CAdvMapWorldViewPanel() = default;
  67. void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor & color, int indexOffset)
  68. {
  69. assert(iconsData.size() == currentIcons.size());
  70. for(size_t idx = 0; idx < iconsData.size(); idx++)
  71. {
  72. const auto & data = iconsData.at(idx);
  73. currentIcons[idx]->setFrame(data.first + indexOffset);
  74. }
  75. }
  76. void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, int indexOffset)
  77. {
  78. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
  79. iconsData.push_back(data);
  80. currentIcons.push_back(std::make_shared<CAnimImage>(icons, data.first + indexOffset, 0, data.second.x, data.second.y));
  81. }