2014-07-13 16:11:25 +03:00
|
|
|
#pragma once
|
|
|
|
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../windows/CWindowObject.h"
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CGarrisonInt.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CGarrisonInt;
|
2014-08-03 14:16:19 +03:00
|
|
|
class CButton;
|
2014-07-13 16:11:25 +03:00
|
|
|
class CArmedInstance;
|
|
|
|
class CAnimImage;
|
|
|
|
class CCreatureSet;
|
|
|
|
class CGarrisonSlot;
|
|
|
|
class CStackInstance;
|
|
|
|
class CLabel;
|
|
|
|
|
|
|
|
/// A single garrison slot which holds one creature of a specific amount
|
|
|
|
class CGarrisonSlot : public CIntObject
|
|
|
|
{
|
|
|
|
SlotID ID; //for identification
|
|
|
|
CGarrisonInt *owner;
|
|
|
|
const CStackInstance *myStack; //nullptr if slot is empty
|
|
|
|
const CCreature *creature;
|
2015-08-24 23:40:12 +02:00
|
|
|
|
|
|
|
/// Type of Garrison for slot (up or down)
|
|
|
|
enum EGarrisonType
|
|
|
|
{
|
|
|
|
UP=0, ///< 0 - up garrison (Garrisoned)
|
|
|
|
DOWN, ///< 1 - down garrison (Visiting)
|
|
|
|
} upg; ///< Flag indicating if it is the up or down garrison
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
CAnimImage * creatureImage;
|
|
|
|
CAnimImage * selectionImage; // image for selection, not always visible
|
|
|
|
CLabel * stackCount;
|
|
|
|
|
2015-08-24 22:39:56 +02:00
|
|
|
bool viewInfo();
|
|
|
|
bool highlightOrDropArtifact();
|
|
|
|
bool split();
|
2015-08-25 00:41:41 +02:00
|
|
|
bool mustForceReselection() const;
|
2015-08-24 22:39:56 +02:00
|
|
|
|
2014-07-13 16:11:25 +03:00
|
|
|
void setHighlight(bool on);
|
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
virtual void hover (bool on) override; //call-in
|
2014-07-13 16:11:25 +03:00
|
|
|
const CArmedInstance * getObj() const;
|
|
|
|
bool our() const;
|
2015-03-16 01:04:18 +02:00
|
|
|
bool ally() const;
|
2015-10-12 15:47:10 +02:00
|
|
|
void clickRight(tribool down, bool previousState) override;
|
|
|
|
void clickLeft(tribool down, bool previousState) override;
|
2014-07-13 16:11:25 +03:00
|
|
|
void update();
|
2015-08-24 23:40:12 +02:00
|
|
|
CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * Creature=nullptr);
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
friend class CGarrisonInt;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Class which manages slots of upper and lower garrison, splitting of units
|
|
|
|
class CGarrisonInt :public CIntObject
|
|
|
|
{
|
2015-08-25 00:45:46 +02:00
|
|
|
/// Chosen slot. Should be changed only via selectSlot.
|
|
|
|
CGarrisonSlot *highlighted;
|
2014-07-13 16:11:25 +03:00
|
|
|
bool inSplittingMode;
|
|
|
|
|
|
|
|
public:
|
2015-08-25 00:45:46 +02:00
|
|
|
void selectSlot(CGarrisonSlot * slot); ///< @param slot null = deselect
|
2014-07-13 16:11:25 +03:00
|
|
|
const CGarrisonSlot * getSelection();
|
|
|
|
|
|
|
|
void setSplittingMode(bool on);
|
|
|
|
bool getSplittingMode();
|
|
|
|
|
2015-08-25 00:45:46 +02:00
|
|
|
int interx; ///< Space between slots
|
|
|
|
Point garOffset; ///< Offset between garrisons (not used if only one hero)
|
|
|
|
std::vector<CButton *> splitButtons; ///< May be empty if no buttons
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-25 00:45:46 +02:00
|
|
|
SlotID p2; ///< TODO: comment me
|
|
|
|
int shiftPos; ///< 1st slot of the second row, set shiftPoint for effect
|
2014-07-13 16:11:25 +03:00
|
|
|
bool pb,
|
2015-08-25 00:45:46 +02:00
|
|
|
smallIcons, ///< true - 32x32 imgs, false - 58x64
|
|
|
|
removableUnits, ///< player Can remove units from up
|
|
|
|
twoRows, ///< slots Will be placed in 2 rows
|
|
|
|
owned[2]; ///< player Owns up or down army ([0] upper, [1] lower)
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-25 00:45:46 +02:00
|
|
|
// const CCreatureSet *set1; ///< Top set of creatures
|
|
|
|
// const CCreatureSet *set2; ///< Bottom set of creatures
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-25 00:45:46 +02:00
|
|
|
std::vector<CGarrisonSlot*> slotsUp, slotsDown; ///< Slots of upper and lower garrison
|
|
|
|
const CArmedInstance *armedObjs[2]; ///< [0] is upper, [1] is down
|
|
|
|
//const CArmedInstance *oup, *odown; ///< Upper and lower garrisons (heroes or towns)
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
void setArmy(const CArmedInstance *army, bool bottomGarrison);
|
2014-08-03 14:16:19 +03:00
|
|
|
void addSplitBtn(CButton * button);
|
2015-08-24 23:40:12 +02:00
|
|
|
void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, CGarrisonSlot::EGarrisonType Upg );
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
void createSlots();
|
|
|
|
void recreateSlots();
|
|
|
|
|
2015-08-25 00:45:46 +02:00
|
|
|
void splitClick(); ///< handles click on split button
|
|
|
|
void splitStacks(int amountLeft, int amountRight); ///< TODO: comment me
|
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
/// @param x, y Position
|
|
|
|
/// @param inx Distance between slots;
|
|
|
|
/// @param garsOffset
|
|
|
|
/// @param pomsur, SurOffset UNUSED
|
|
|
|
/// @param s1, s2 Top and bottom armies
|
|
|
|
/// @param _removableUnits You can take units from top
|
|
|
|
/// @param smallImgs Units images size 64x58 or 32x32
|
|
|
|
/// @param _twoRows Display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
|
|
|
|
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);
|
2014-07-13 16:11:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CGarrisonHolder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CGarrisonHolder();
|
|
|
|
virtual void updateGarrisons()=0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CWindowWithGarrison : public virtual CGarrisonHolder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CGarrisonInt *garr;
|
2015-10-12 15:47:10 +02:00
|
|
|
virtual void updateGarrisons() override;
|
2014-07-13 16:11:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Garrison window where you can take creatures out of the hero to place it on the garrison
|
|
|
|
class CGarrisonWindow : public CWindowObject, public CWindowWithGarrison
|
|
|
|
{
|
|
|
|
public:
|
2014-08-03 14:16:19 +03:00
|
|
|
CButton * quit;
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
|
|
|
|
};
|