CGarrisonInt.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #pragma once
  2. #include "../windows/CWindowObject.h"
  3. /*
  4. * CGarrisonInt.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  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. CAnimImage * creatureImage;
  34. CAnimImage * selectionImage; // image for selection, not always visible
  35. CLabel * stackCount;
  36. bool viewInfo();
  37. bool highlightOrDropArtifact();
  38. bool split();
  39. bool mustForceReselection() const;
  40. void setHighlight(bool on);
  41. public:
  42. virtual void hover (bool on); //call-in
  43. const CArmedInstance * getObj() const;
  44. bool our() const;
  45. bool ally() const;
  46. void clickRight(tribool down, bool previousState);
  47. void clickLeft(tribool down, bool previousState);
  48. void update();
  49. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * Creature=nullptr);
  50. friend class CGarrisonInt;
  51. };
  52. /// Class which manages slots of upper and lower garrison, splitting of units
  53. class CGarrisonInt :public CIntObject
  54. {
  55. /// Chosen slot. Should be changed only via selectSlot.
  56. CGarrisonSlot *highlighted;
  57. bool inSplittingMode;
  58. public:
  59. void selectSlot(CGarrisonSlot * slot); ///< @param slot null = deselect
  60. const CGarrisonSlot * getSelection();
  61. void setSplittingMode(bool on);
  62. bool getSplittingMode();
  63. int interx; ///< Space between slots
  64. Point garOffset; ///< Offset between garrisons (not used if only one hero)
  65. std::vector<CButton *> splitButtons; ///< May be empty if no buttons
  66. SlotID p2; ///< TODO: comment me
  67. int shiftPos; ///< 1st slot of the second row, set shiftPoint for effect
  68. bool pb,
  69. smallIcons, ///< true - 32x32 imgs, false - 58x64
  70. removableUnits, ///< player Can remove units from up
  71. twoRows, ///< slots Will be placed in 2 rows
  72. owned[2]; ///< player Owns up or down army ([0] upper, [1] lower)
  73. // const CCreatureSet *set1; ///< Top set of creatures
  74. // const CCreatureSet *set2; ///< Bottom set of creatures
  75. std::vector<CGarrisonSlot*> slotsUp, slotsDown; ///< Slots of upper and lower garrison
  76. const CArmedInstance *armedObjs[2]; ///< [0] is upper, [1] is down
  77. //const CArmedInstance *oup, *odown; ///< Upper and lower garrisons (heroes or towns)
  78. void setArmy(const CArmedInstance *army, bool bottomGarrison);
  79. void addSplitBtn(CButton * button);
  80. void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, CGarrisonSlot::EGarrisonType Upg );
  81. void createSlots();
  82. void recreateSlots();
  83. void splitClick(); ///< handles click on split button
  84. void splitStacks(int amountLeft, int amountRight); ///< TODO: comment me
  85. /// Constructor
  86. /// @param x, y Position
  87. /// @param inx Distance between slots;
  88. /// @param garsOffset
  89. /// @param pomsur, SurOffset UNUSED
  90. /// @param s1, s2 Top and bottom armies
  91. /// @param _removableUnits You can take units from top
  92. /// @param smallImgs Units images size 64x58 or 32x32
  93. /// @param _twoRows Display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
  94. CGarrisonInt(int x, int y,
  95. int inx,
  96. const Point &garsOffset,
  97. SDL_Surface *pomsur, const Point &SurOffset,
  98. const CArmedInstance *s1, const CArmedInstance *s2=nullptr,
  99. bool _removableUnits = true,
  100. bool smallImgs = false,
  101. bool _twoRows=false);
  102. };
  103. class CGarrisonHolder
  104. {
  105. public:
  106. CGarrisonHolder();
  107. virtual void updateGarrisons()=0;
  108. };
  109. class CWindowWithGarrison : public virtual CGarrisonHolder
  110. {
  111. public:
  112. CGarrisonInt *garr;
  113. virtual void updateGarrisons();
  114. };
  115. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  116. class CGarrisonWindow : public CWindowObject, public CWindowWithGarrison
  117. {
  118. public:
  119. CButton * quit;
  120. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  121. };