CMinimap.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. struct SDL_Color;
  14. class CMinimap;
  15. class CMinimapInstance : public CIntObject
  16. {
  17. CMinimap * parent;
  18. SDL_Surface * minimap;
  19. int level;
  20. //get color of selected tile on minimap
  21. const SDL_Color & getTileColor(const int3 & pos);
  22. void blitTileWithColor(const SDL_Color & color, const int3 & pos, SDL_Surface * to, int x, int y);
  23. //draw minimap already scaled.
  24. //result is not antialiased. Will result in "missing" pixels on huge maps (>144)
  25. void drawScaled(int level);
  26. public:
  27. CMinimapInstance(CMinimap * parent, int level);
  28. ~CMinimapInstance();
  29. void showAll(SDL_Surface * to) override;
  30. void tileToPixels (const int3 & tile, int & x, int & y, int toX = 0, int toY = 0);
  31. void refreshTile(const int3 & pos);
  32. };
  33. /// Minimap which is displayed at the right upper corner of adventure map
  34. class CMinimap : public CIntObject
  35. {
  36. protected:
  37. std::shared_ptr<CPicture> aiShield; //the graphic displayed during AI turn
  38. std::shared_ptr<CMinimapInstance> minimap;
  39. int level;
  40. //to initialize colors
  41. std::map<TerrainId, std::pair<SDL_Color, SDL_Color> > loadColors();
  42. void clickLeft(tribool down, bool previousState) override;
  43. void clickRight(tribool down, bool previousState) override;
  44. void hover (bool on) override;
  45. void mouseMoved (const SDL_MouseMotionEvent & sEvent) override;
  46. void moveAdvMapSelection();
  47. public:
  48. // terrainID -> (normal color, blocked color)
  49. const std::map<TerrainId, std::pair<SDL_Color, SDL_Color> > colors;
  50. CMinimap(const Rect & position);
  51. //should be called to invalidate whole map - different player or level
  52. int3 translateMousePosition();
  53. void update();
  54. void setLevel(int level);
  55. void setAIRadar(bool on);
  56. void showAll(SDL_Surface * to) override;
  57. void hideTile(const int3 &pos); //puts FoW
  58. void showTile(const int3 &pos); //removes FoW
  59. };