BattleFieldController.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. VCMI_LIB_NAMESPACE_END
  16. struct Rect;
  17. struct Point;
  18. class ClickableHex;
  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. /// Canvas that contains cell borders of all tiles in the battlefield
  32. std::unique_ptr<Canvas> cellBorders;
  33. /// hex from which the stack would perform attack with current cursor
  34. BattleHex attackingHex;
  35. /// hexes to which currently active stack can move
  36. std::vector<BattleHex> occupyableHexes;
  37. /// hexes that when in front of a unit cause it's amount box to move back
  38. std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes;
  39. std::vector<std::shared_ptr<ClickableHex>> bfield;
  40. void showHighlightedHex(Canvas & to, BattleHex hex, bool darkBorder);
  41. std::set<BattleHex> getHighlightedHexesStackRange();
  42. std::set<BattleHex> getHighlightedHexesSpellRange();
  43. std::set<BattleHex> getHighlightedHexesMovementTarget();
  44. void showBackground(Canvas & canvas);
  45. void showBackgroundImage(Canvas & canvas);
  46. void showBackgroundImageWithHexes(Canvas & canvas);
  47. void showHighlightedHexes(Canvas & canvas);
  48. public:
  49. BattleFieldController(BattleInterface & owner);
  50. void redrawBackgroundWithHexes();
  51. void renderBattlefield(Canvas & canvas);
  52. /// Returns position of hex relative to owner (BattleInterface)
  53. Rect hexPositionLocal(BattleHex hex) const;
  54. /// Returns position of hex relative to game window
  55. Rect hexPositionAbsolute(BattleHex hex) const;
  56. /// Checks whether selected pixel is transparent, uses local coordinates of a hex
  57. bool isPixelInHex(Point const & position);
  58. /// Returns ID of currently hovered hex or BattleHex::INVALID if none
  59. BattleHex getHoveredHex();
  60. /// returns true if selected tile can be attacked in melee by current stack
  61. bool isTileAttackable(const BattleHex & number) const;
  62. /// returns true if stack should render its stack count image in default position - outside own hex
  63. bool stackCountOutsideHex(const BattleHex & number) const;
  64. void setBattleCursor(BattleHex myNumber);
  65. BattleHex fromWhichHexAttack(BattleHex myNumber);
  66. };