CAdvMapPanel.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor & color, int indexOffset)
  67. {
  68. assert(iconsData.size() == currentIcons.size());
  69. for(size_t idx = 0; idx < iconsData.size(); idx++)
  70. {
  71. const auto & data = iconsData.at(idx);
  72. currentIcons[idx]->setFrame(data.first + indexOffset);
  73. }
  74. }
  75. void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, int indexOffset)
  76. {
  77. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
  78. iconsData.push_back(data);
  79. currentIcons.push_back(std::make_shared<CAnimImage>(icons, data.first + indexOffset, 0, data.second.x, data.second.y));
  80. }