CGarrisonInt.h 4.0 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,
  31. ///< 0 - up garrison (Garrisoned)
  32. DOWN,
  33. ///< 1 - down garrison (Visiting)
  34. } upg; ///< Flag indicating if it is the up or down garrison
  35. CAnimImage * creatureImage;
  36. CAnimImage * selectionImage; // image for selection, not always visible
  37. CLabel * stackCount;
  38. bool viewInfo();
  39. bool highlightOrDropArtifact();
  40. bool split();
  41. bool mustForceReselection() const;
  42. void setHighlight(bool on);
  43. public:
  44. virtual void hover(bool on) override; //call-in
  45. const CArmedInstance * getObj() const;
  46. bool our() const;
  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. friend class CGarrisonInt;
  53. };
  54. /// Class which manages slots of upper and lower garrison, splitting of units
  55. class CGarrisonInt : public CIntObject
  56. {
  57. /// Chosen slot. Should be changed only via selectSlot.
  58. CGarrisonSlot * highlighted;
  59. bool inSplittingMode;
  60. public:
  61. void selectSlot(CGarrisonSlot * slot); ///< @param slot null = deselect
  62. const CGarrisonSlot * getSelection();
  63. void setSplittingMode(bool on);
  64. bool getSplittingMode();
  65. int interx; ///< Space between slots
  66. Point garOffset; ///< Offset between garrisons (not used if only one hero)
  67. std::vector<CButton *> splitButtons; ///< May be empty if no buttons
  68. SlotID p2; ///< TODO: comment me
  69. bool pb,
  70. smallIcons, ///< true - 32x32 imgs, false - 58x64
  71. removableUnits, ///< player Can remove units from up
  72. twoRows, ///< slots Will be placed in 2 rows
  73. owned[2]; ///< player Owns up or down army ([0] upper, [1] lower)
  74. std::vector<CGarrisonSlot *> availableSlots; ///< Slots of upper and lower garrison
  75. const CArmedInstance * armedObjs[2]; ///< [0] is upper, [1] is down
  76. void setArmy(const CArmedInstance * army, bool bottomGarrison);
  77. void addSplitBtn(CButton * button);
  78. void createSlots();
  79. void recreateSlots();
  80. void splitClick(); ///< handles click on split button
  81. void splitStacks(int amountLeft, int amountRight); ///< TODO: comment me
  82. /// Constructor
  83. /// @param x, y Position
  84. /// @param inx Distance between slots;
  85. /// @param garsOffset
  86. /// @param pomsur, SurOffset UNUSED
  87. /// @param s1, s2 Top and bottom armies
  88. /// @param _removableUnits You can take units from top
  89. /// @param smallImgs Units images size 64x58 or 32x32
  90. /// @param _twoRows Display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
  91. CGarrisonInt(int x, int y, int inx, const Point & garsOffset, SDL_Surface * pomsur, const Point & SurOffset, const CArmedInstance * s1, const CArmedInstance * s2 = nullptr, bool _removableUnits = true, bool smallImgs = false, bool _twoRows = false);
  92. };
  93. class CGarrisonHolder
  94. {
  95. public:
  96. CGarrisonHolder();
  97. virtual void updateGarrisons() = 0;
  98. };
  99. class CWindowWithGarrison : public virtual CGarrisonHolder
  100. {
  101. public:
  102. CGarrisonInt * garr;
  103. virtual void updateGarrisons() override;
  104. };
  105. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  106. class CGarrisonWindow : public CWindowObject, public CWindowWithGarrison
  107. {
  108. public:
  109. CButton * quit;
  110. CGarrisonWindow(const CArmedInstance * up, const CGHeroInstance * down, bool removableUnits);
  111. };