CAdvMapPanel.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "AdventureMapClasses.h"
  12. #include <SDL_timer.h>
  13. #include "MiscWidgets.h"
  14. #include "CComponent.h"
  15. #include "Images.h"
  16. #include "../CGameInfo.h"
  17. #include "../CMusicHandler.h"
  18. #include "../CPlayerInterface.h"
  19. #include "../mainmenu/CMainMenu.h"
  20. #include "../gui/CGuiHandler.h"
  21. #include "../gui/SDL_PixelAccess.h"
  22. #include "../gui/CAnimation.h"
  23. #include "../windows/InfoWindows.h"
  24. #include "../windows/CAdvmapInterface.h"
  25. #include "../battle/BattleInterfaceClasses.h"
  26. #include "../battle/BattleInterface.h"
  27. #include "../../CCallback.h"
  28. #include "../../lib/StartInfo.h"
  29. #include "../../lib/CGameState.h"
  30. #include "../../lib/CGeneralTextHandler.h"
  31. #include "../../lib/CHeroHandler.h"
  32. #include "../../lib/CModHandler.h"
  33. #include "../../lib/CTownHandler.h"
  34. #include "../../lib/TerrainHandler.h"
  35. #include "../../lib/mapObjects/CGHeroInstance.h"
  36. #include "../../lib/mapping/CMap.h"
  37. #include "ClientCommandManager.h"
  38. #include <SDL_surface.h>
  39. #include <SDL_keyboard.h>
  40. #include <SDL_events.h>
  41. CAdvMapPanel::CAdvMapPanel(std::shared_ptr<IImage> bg, Point position)
  42. : CIntObject()
  43. , background(bg)
  44. {
  45. defActions = 255;
  46. recActions = 255;
  47. pos.x += position.x;
  48. pos.y += position.y;
  49. if (bg)
  50. {
  51. pos.w = bg->width();
  52. pos.h = bg->height();
  53. }
  54. }
  55. void CAdvMapPanel::addChildColorableButton(std::shared_ptr<CButton> button)
  56. {
  57. colorableButtons.push_back(button);
  58. addChildToPanel(button, ACTIVATE | DEACTIVATE);
  59. }
  60. void CAdvMapPanel::setPlayerColor(const PlayerColor & clr)
  61. {
  62. for(auto & button : colorableButtons)
  63. {
  64. button->setPlayerColor(clr);
  65. }
  66. }
  67. void CAdvMapPanel::showAll(SDL_Surface * to)
  68. {
  69. if(background)
  70. background->draw(to, pos.x, pos.y);
  71. CIntObject::showAll(to);
  72. }
  73. void CAdvMapPanel::addChildToPanel(std::shared_ptr<CIntObject> obj, ui8 actions)
  74. {
  75. otherObjects.push_back(obj);
  76. obj->recActions |= actions | SHOWALL;
  77. obj->recActions &= ~DISPOSE;
  78. addChild(obj.get(), false);
  79. }
  80. CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(std::shared_ptr<CAnimation> _icons, std::shared_ptr<IImage> bg, Point position, int spaceBottom, const PlayerColor &color)
  81. : CAdvMapPanel(bg, position), icons(_icons)
  82. {
  83. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  84. int fillerHeight = bg ? spaceBottom - pos.y - pos.h : 0;
  85. if(fillerHeight > 0)
  86. {
  87. backgroundFiller = std::make_shared<CFilledTexture>("DIBOXBCK", Rect(0, pos.h, pos.w, fillerHeight));
  88. }
  89. }
  90. CAdvMapWorldViewPanel::~CAdvMapWorldViewPanel() = default;
  91. void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor & color, int indexOffset)
  92. {
  93. assert(iconsData.size() == currentIcons.size());
  94. for(size_t idx = 0; idx < iconsData.size(); idx++)
  95. {
  96. const auto & data = iconsData.at(idx);
  97. currentIcons[idx]->setFrame(data.first + indexOffset);
  98. }
  99. }
  100. void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, int indexOffset)
  101. {
  102. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
  103. iconsData.push_back(data);
  104. currentIcons.push_back(std::make_shared<CAnimImage>(icons, data.first + indexOffset, 0, data.second.x, data.second.y));
  105. }