BattleFieldController.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * BattleFieldController.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 "../../lib/battle/BattleHex.h"
  12. #include "../gui/CIntObject.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CStack;
  15. class Rect;
  16. class Point;
  17. VCMI_LIB_NAMESPACE_END
  18. class BattleHero;
  19. class Canvas;
  20. class IImage;
  21. class BattleInterface;
  22. /// Handles battlefield grid as well as rendering of background layer of battle interface
  23. class BattleFieldController : public CIntObject
  24. {
  25. BattleInterface & owner;
  26. std::shared_ptr<IImage> background;
  27. std::shared_ptr<IImage> cellBorder;
  28. std::shared_ptr<IImage> cellShade;
  29. /// Canvas that contains background, hex grid (if enabled), absolute obstacles and movement range of active stack
  30. std::unique_ptr<Canvas> backgroundWithHexes;
  31. /// hex from which the stack would perform attack with current cursor
  32. BattleHex attackingHex;
  33. /// hexes to which currently active stack can move
  34. std::vector<BattleHex> occupyableHexes;
  35. /// hexes that when in front of a unit cause it's amount box to move back
  36. std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes;
  37. void showHighlightedHex(Canvas & to, BattleHex hex, bool darkBorder);
  38. std::set<BattleHex> getHighlightedHexesStackRange();
  39. std::set<BattleHex> getHighlightedHexesSpellRange();
  40. std::set<BattleHex> getHighlightedHexesMovementTarget();
  41. void showBackground(Canvas & canvas);
  42. void showBackgroundImage(Canvas & canvas);
  43. void showBackgroundImageWithHexes(Canvas & canvas);
  44. void showHighlightedHexes(Canvas & canvas);
  45. void updateAccessibleHexes();
  46. BattleHex::EDir selectAttackDirection(BattleHex myNumber, const Point & point);
  47. void mouseMoved(const Point & cursorPosition) override;
  48. void clickLeft(tribool down, bool previousState) override;
  49. void clickRight(tribool down, bool previousState) override;
  50. void showAll(SDL_Surface * to) override;
  51. void show(SDL_Surface * to) override;
  52. public:
  53. BattleFieldController(BattleInterface & owner);
  54. void createHeroes();
  55. void redrawBackgroundWithHexes();
  56. void renderBattlefield(Canvas & canvas);
  57. /// Returns position of hex relative to owner (BattleInterface)
  58. Rect hexPositionLocal(BattleHex hex) const;
  59. /// Returns position of hex relative to game window
  60. Rect hexPositionAbsolute(BattleHex hex) const;
  61. /// Checks whether selected pixel is transparent, uses local coordinates of a hex
  62. bool isPixelInHex(Point const & position);
  63. /// Returns ID of currently hovered hex or BattleHex::INVALID if none
  64. BattleHex getHoveredHex();
  65. /// returns true if selected tile can be attacked in melee by current stack
  66. bool isTileAttackable(const BattleHex & number) const;
  67. /// returns true if stack should render its stack count image in default position - outside own hex
  68. bool stackCountOutsideHex(const BattleHex & number) const;
  69. void setBattleCursor(BattleHex myNumber);
  70. BattleHex fromWhichHexAttack(BattleHex myNumber);
  71. };