CGarrisonInt.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * CGarrisonInt.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 "../windows/CWindowObject.h"
  12. class CGarrisonInt;
  13. class CButton;
  14. class CArmedInstance;
  15. class CAnimImage;
  16. class CCreatureSet;
  17. class CGarrisonSlot;
  18. class CStackInstance;
  19. class CLabel;
  20. /// A single garrison slot which holds one creature of a specific amount
  21. class CGarrisonSlot : public CIntObject
  22. {
  23. SlotID ID; //for identification
  24. CGarrisonInt *owner;
  25. const CStackInstance * myStack; //nullptr if slot is empty
  26. const CCreature * creature;
  27. /// Type of Garrison for slot (up or down)
  28. enum EGarrisonType
  29. {
  30. UP=0, ///< 0 - up garrison (Garrisoned)
  31. DOWN, ///< 1 - down garrison (Visiting)
  32. } upg; ///< Flag indicating if it is the up or down garrison
  33. std::shared_ptr<CAnimImage> creatureImage;
  34. std::shared_ptr<CAnimImage> selectionImage; // image for selection, not always visible
  35. std::shared_ptr<CLabel> stackCount;
  36. bool viewInfo();
  37. bool highlightOrDropArtifact();
  38. bool split();
  39. bool mustForceReselection() const;
  40. void setHighlight(bool on);
  41. std::function<void()> getDismiss() const;
  42. public:
  43. virtual void hover (bool on) override; //call-in
  44. const CArmedInstance * getObj() const;
  45. bool our() const;
  46. SlotID getSlot() const { return ID; }
  47. bool ally() const;
  48. void clickRight(tribool down, bool previousState) override;
  49. void clickLeft(tribool down, bool previousState) override;
  50. void update();
  51. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * creature_ = nullptr);
  52. void splitIntoParts(EGarrisonType type, int amount);
  53. bool handleSplittingShortcuts(); /// Returns true when some shortcut is pressed, false otherwise
  54. friend class CGarrisonInt;
  55. };
  56. /// Class which manages slots of upper and lower garrison, splitting of units
  57. class CGarrisonInt :public CIntObject
  58. {
  59. /// Chosen slot. Should be changed only via selectSlot.
  60. CGarrisonSlot * highlighted;
  61. bool inSplittingMode;
  62. std::vector<std::shared_ptr<CGarrisonSlot>> availableSlots; ///< Slots of upper and lower garrison
  63. void createSlots();
  64. bool checkSelected(const CGarrisonSlot * selected, TQuantity min = 0) const;
  65. public:
  66. int interx; ///< Space between slots
  67. Point garOffset; ///< Offset between garrisons (not used if only one hero)
  68. std::vector<std::shared_ptr<CButton>> splitButtons; ///< May be empty if no buttons
  69. SlotID p2; ///< TODO: comment me
  70. bool pb,
  71. smallIcons, ///< true - 32x32 imgs, false - 58x64
  72. removableUnits, ///< player Can remove units from up
  73. twoRows, ///< slots Will be placed in 2 rows
  74. owned[2]; ///< player Owns up or down army ([0] upper, [1] lower)
  75. void selectSlot(CGarrisonSlot * slot); ///< @param slot null = deselect
  76. const CGarrisonSlot * getSelection() const;
  77. void setSplittingMode(bool on);
  78. bool getSplittingMode();
  79. bool hasEmptySlot(CGarrisonSlot::EGarrisonType type) const;
  80. SlotID getEmptySlot(CGarrisonSlot::EGarrisonType type) const;
  81. const CArmedInstance * armedObjs[2]; ///< [0] is upper, [1] is down
  82. void setArmy(const CArmedInstance * army, bool bottomGarrison);
  83. void addSplitBtn(std::shared_ptr<CButton> button);
  84. void recreateSlots();
  85. void splitClick(); ///< handles click on split button
  86. void splitStacks(int amountLeft, int amountRight); ///< TODO: comment me
  87. void moveStackToAnotherArmy(const CGarrisonSlot * selected);
  88. void bulkMoveArmy(const CGarrisonSlot * selected);
  89. void bulkMergeStacks(const CGarrisonSlot * selected); // Gather all creatures of selected type to the selected slot from other hero/garrison slots
  90. void bulkSplitStack(const CGarrisonSlot * selected); // Used to separate one-creature troops from main stack
  91. void bulkSmartSplitStack(const CGarrisonSlot * selected);
  92. /// Constructor
  93. /// @param x, y Position
  94. /// @param inx Distance between slots;
  95. /// @param garsOffset
  96. /// @param s1, s2 Top and bottom armies
  97. /// @param _removableUnits You can take units from top
  98. /// @param smallImgs Units images size 64x58 or 32x32
  99. /// @param _twoRows Display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
  100. CGarrisonInt(int x, int y, int inx,
  101. const Point & garsOffset,
  102. const CArmedInstance * s1, const CArmedInstance * s2 = nullptr,
  103. bool _removableUnits = true,
  104. bool smallImgs = false,
  105. bool _twoRows = false);
  106. };
  107. class CGarrisonHolder
  108. {
  109. public:
  110. virtual void updateGarrisons() = 0;
  111. };