CMinimap.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * CMinimap.h, 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. #pragma once
  11. #include "../gui/CIntObject.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class ColorRGBA;
  14. VCMI_LIB_NAMESPACE_END
  15. class Canvas;
  16. class CMinimap;
  17. class IImage;
  18. class CMinimapInstance : public CIntObject
  19. {
  20. std::unique_ptr<Canvas> minimap;
  21. int level;
  22. //get color of selected tile on minimap
  23. ColorRGBA getTileColor(const int3 & pos) const;
  24. void redrawMinimap();
  25. public:
  26. CMinimapInstance(const Point & position, const Point & dimensions, int level);
  27. ~CMinimapInstance();
  28. void showAll(Canvas & to) override;
  29. void refreshTile(const int3 & pos);
  30. };
  31. /// Minimap which is displayed at the right upper corner of adventure map
  32. class CMinimap : public CIntObject
  33. {
  34. std::shared_ptr<CPicture> aiShield; //the graphic displayed during AI turn
  35. std::shared_ptr<CMinimapInstance> minimap;
  36. std::vector<ObjectInstanceID> visibleHeroes;
  37. std::shared_ptr<IImage> heroIcon;
  38. Rect screenArea;
  39. int level;
  40. void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
  41. void clickPressed(const Point & cursorPosition) override;
  42. void showPopupWindow(const Point & cursorPosition) override;
  43. void hover(bool on) override;
  44. void mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) override;
  45. void updateVisibleHeroes();
  46. /// relocates center of adventure map screen to currently hovered tile
  47. void moveAdvMapSelection(const Point & positionGlobal);
  48. protected:
  49. /// computes coordinates of tile below cursor pos
  50. int3 pixelToTile(const Point & cursorPos) const;
  51. /// computes position of tile within minimap instance
  52. Point tileToPixels(const int3 & position) const;
  53. public:
  54. explicit CMinimap(const Rect & position);
  55. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  56. void update();
  57. void setAIRadar(bool on);
  58. void showAll(Canvas & to) override;
  59. void updateTiles(const std::unordered_set<int3> & positions);
  60. };