CMinimap.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "../../lib/GameConstants.h"
  13. #include "../render/Canvas.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class ColorRGBA;
  16. VCMI_LIB_NAMESPACE_END
  17. class CMinimap;
  18. class CMinimapInstance : public CIntObject
  19. {
  20. CMinimap * parent;
  21. std::unique_ptr<Canvas> minimap;
  22. int level;
  23. //get color of selected tile on minimap
  24. ColorRGBA getTileColor(const int3 & pos) const;
  25. void redrawMinimap();
  26. public:
  27. CMinimapInstance(CMinimap * parent, int level);
  28. void showAll(SDL_Surface * 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. Rect screenArea;
  37. int level;
  38. void clickLeft(tribool down, bool previousState) override;
  39. void clickRight(tribool down, bool previousState) override;
  40. void hover (bool on) override;
  41. void mouseMoved (const Point & cursorPosition) override;
  42. /// relocates center of adventure map screen to currently hovered tile
  43. void moveAdvMapSelection();
  44. protected:
  45. /// computes coordinates of tile below cursor pos
  46. int3 pixelToTile(const Point & cursorPos) const;
  47. /// computes position of tile within minimap instance
  48. Point tileToPixels(const int3 & position) const;
  49. public:
  50. explicit CMinimap(const Rect & position);
  51. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  52. void update();
  53. void setAIRadar(bool on);
  54. void showAll(SDL_Surface * to) override;
  55. void updateTiles(std::unordered_set<int3> positions);
  56. };