* Updated class - file - handling * Renamed color constants * Renamed class AdventureMapButton to CAdventureMapButton * Moved basic controls like CTextBox from GuiClasses to CIntObjectClasses * Moved new creature window from GuiClasses to CCreatureWindow
virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
//virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
//virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
-void CHighlightableButtonsGroup::addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect, int key)
-{
- OBJ_CONSTRUCTION_CAPTURING_ALL;
- CHighlightableButton *bt = new CHighlightableButton(OnSelect, 0, tooltip, HelpBox, false, defName, 0, x, y, key);
-/// A group of buttons where one button can be selected
-class CHighlightableButtonsGroup : public CIntObject
-{
-public:
- CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
- std::vector<CHighlightableButton*> buttons;
- bool musicLike; //determines the behaviour of this group
-
- //void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
- void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
- void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect=0, int key=0); //creates new button
+ double projectileAngle; //in radians; if positive, projectiles goes up
+ double straightAngle = 0.2; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value)
+ static bool isToReverse(BattleHex hexFrom, BattleHex hexTo, bool curDir /*if true, creature is in attacker's direction*/, bool toDoubleWide, bool toDir); //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo)
+
+ CCreatureAnimation * myAnim(); //animation for our stack
+};
+
+/// This class is responsible for managing the battle attack animation
+class CAttackAnimation : public CBattleStackAnimation
+{
+protected:
+ BattleHex dest; //attacked hex
+ bool shooting;
+ CCreatureAnim::EAnimType group; //if shooting is true, print this animation group
+ const CStack *attackedStack;
+ const CStack *attackingStack;
+ int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
std::string enemyHeroName = opponent ? opponent->name : "#ENEMY#"; //TODO: should surrendering without enemy hero be enabled?
std::string enemyHeroName = opponent ? opponent->name : "#ENEMY#"; //TODO: should surrendering without enemy hero be enabled?
std::string surrenderMessage = boost::str(boost::format(CGI->generaltexth->allTexts[32]) % enemyHeroName % cost); //%s states: "I will accept your surrender and grant you and your troops safe passage for the price of %d gold."
std::string surrenderMessage = boost::str(boost::format(CGI->generaltexth->allTexts[32]) % enemyHeroName % cost); //%s states: "I will accept your surrender and grant you and your troops safe passage for the price of %d gold."
int mouseHoveredStack; //stack hovered by mouse; if -1 -> none
int mouseHoveredStack; //stack hovered by mouse; if -1 -> none
time_t lastMouseHoveredStackAnimationTime; // time when last mouse hovered animation occurred
time_t lastMouseHoveredStackAnimationTime; // time when last mouse hovered animation occurred
static const time_t HOVER_ANIM_DELTA;
static const time_t HOVER_ANIM_DELTA;
- std::vector<SBattleHex> occupyableHexes, //hexes available for active stack
+ std::vector<BattleHex> occupyableHexes, //hexes available for active stack
attackableHexes; //hexes attackable by active stack
attackableHexes; //hexes attackable by active stack
bool stackCountOutsideHexes[GameConstants::BFIELD_SIZE]; // hexes that when in front of a unit cause it's amount box to move back
bool stackCountOutsideHexes[GameConstants::BFIELD_SIZE]; // hexes that when in front of a unit cause it's amount box to move back
int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
@@ -124,18 +135,18 @@ private:
void showAliveStack(const CStack *stack, SDL_Surface * to); //helper function for function show
void showAliveStack(const CStack *stack, SDL_Surface * to); //helper function for function show
void showAliveStacks(std::vector<const CStack *> *aliveStacks, int hex, std::vector<const CStack *> *flyingStacks, SDL_Surface *to); // loops through all stacks at a given hex position
void showAliveStacks(std::vector<const CStack *> *aliveStacks, int hex, std::vector<const CStack *> *flyingStacks, SDL_Surface *to); // loops through all stacks at a given hex position
void showPieceOfWall(SDL_Surface * to, int hex, const std::vector<const CStack*> & stacks); //helper function for show
void showPieceOfWall(SDL_Surface * to, int hex, const std::vector<const CStack*> & stacks); //helper function for show
- void showObstacles(std::multimap<SBattleHex, int> *hexToObstacle, std::vector<CObstacleInstance> &obstacles, int hex, SDL_Surface *to); // show all obstacles at a given hex position
+ void showObstacles(std::multimap<BattleHex, int> *hexToObstacle, std::vector<CObstacleInstance> &obstacles, int hex, SDL_Surface *to); // show all obstacles at a given hex position
- bool isTileAttackable(const SBattleHex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles
- bool blockedByObstacle(SBattleHex hex) const;
- bool isCatapultAttackable(SBattleHex hex) const; //returns true if given tile can be attacked by catapult
+ bool isTileAttackable(const BattleHex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles
+ bool blockedByObstacle(BattleHex hex) const;
+ bool isCatapultAttackable(BattleHex hex) const; //returns true if given tile can be attacked by catapult
- std::list<SBattleEffect> battleEffects; //different animations to display on the screen like spell effects
+ std::list<BattleEffect> battleEffects; //different animations to display on the screen like spell effects
/// Class which is responsible for drawing the wall of a siege during battle
/// Class which is responsible for drawing the wall of a siege during battle
int getAnimSpeed() const; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest
int getAnimSpeed() const; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest
- CClickableHex bfield[GameConstants::BFIELD_SIZE]; //11 lines, 17 hexes on each
+ std::vector<CClickableHex> bfield; //11 lines, 17 hexes on each
//std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield
//std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield
SDL_Surface * cellBorder, * cellShade;
SDL_Surface * cellBorder, * cellShade;
CondSh<BattleAction *> *givenCommand; //data != NULL if we have i.e. moved current unit
CondSh<BattleAction *> *givenCommand; //data != NULL if we have i.e. moved current unit
@@ -215,10 +226,10 @@ public:
void newStack(const CStack * stack); //new stack appeared on battlefield
void newStack(const CStack * stack); //new stack appeared on battlefield
void stackRemoved(int stackID); //stack disappeared from batlefiled
void stackRemoved(int stackID); //stack disappeared from batlefiled
void stackActivated(const CStack * stack); //active stack has been changed
void stackActivated(const CStack * stack); //active stack has been changed
- void stackMoved(const CStack * stack, std::vector<SBattleHex> destHex, int distance); //stack with id number moved to destHex
+ void stackMoved(const CStack * stack, std::vector<BattleHex> destHex, int distance); //stack with id number moved to destHex
void waitForAnims();
void waitForAnims();
- void stacksAreAttacked(std::vector<SStackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
- void stackAttacking(const CStack * attacker, SBattleHex dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest
+ void stacksAreAttacked(std::vector<StackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
+ void stackAttacking(const CStack * attacker, BattleHex dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest
void newRoundFirst( int round );
void newRoundFirst( int round );
void newRound(int number); //caled when round is ended; number is the number of round
void newRound(int number); //caled when round is ended; number is the number of round
void hexLclicked(int whichOne); //hex only call-in
void hexLclicked(int whichOne); //hex only call-in
+/// Class which stands for a single hex field on a battlefield
+class CClickableHex : public CIntObject
+{
+private:
+ bool setAlterText; //if true, this hex has set alternative text in console and will clean it
+public:
+ ui32 myNumber; //number of hex in commonly used format
+ bool accessible; //if true, this hex is accessible for units
+ //CStack * ourStack;
+ bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
+ CBattleInterface * myInterface; //interface that owns me
+ static Point getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * creature, const CBattleInterface * cbi); //returns (x, y) of left top corner of animation
- static bool isToReverse(SBattleHex hexFrom, SBattleHex hexTo, bool curDir /*if true, creature is in attacker's direction*/, bool toDoubleWide, bool toDir); //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo)
-
- CCreatureAnimation *myAnim(); //animation for our stack
- * 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 which stands for a single hex field on a battlefield
-class CClickableHex : public CIntObject
-{
-private:
- bool setAlterText; //if true, this hex has set alternative text in console and will clean it
-public:
- ui32 myNumber; //number of hex in commonly used format
- bool accessible; //if true, this hex is accessible for units
- //CStack * ourStack;
- bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
- CBattleInterface * myInterface; //interface that owns me
- static SPoint getXYUnitAnim(const int &hexNum, const bool &attacker, const CStack *creature, const CBattleInterface *cbi); //returns (x, y) of left top corner of animation
- double projectileAngle; //in radians; if positive, projectiles goes up
- double straightAngle = 0.2; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value)
else if(!other->hero->stacksCount()) //hero has no creatures - strange, but if we have appropriate error message...
else if(!other->hero->stacksCount()) //hero has no creatures - strange, but if we have appropriate error message...
{
{
- LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[19],std::vector<SComponent*>(), soundBase::sound_todo); //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside.
+ LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[19],std::vector<CComponent*>(), soundBase::sound_todo); //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside.
statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false));
statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false));
- title = new CLabel(399, 12, FONT_MEDIUM, CENTER, zwykly, CGI->buildh->buildings[town->subID][town->hallLevel()+EBuilding::VILLAGE_HALL]->Name());
- exit = new AdventureMapButton(CGI->generaltexth->hcommands[8], "",
+ title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->buildh->buildings[town->subID][town->hallLevel()+EBuilding::VILLAGE_HALL]->Name());
+ exit = new CAdventureMapButton(CGI->generaltexth->hcommands[8], "",
- ok = new AdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CCreatureWindow::close,this), 489, 148, "hsbtns.def", SDLK_RETURN);
+ ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CCreatureWindow::close,this), 489, 148, "hsbtns.def", SDLK_RETURN);
- void showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
+ void showYesNoDialog(const std::string &text, const std::vector<CComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
- printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 58, FONT_SMALL, 55, zwykly, to); //Select starting options, handicap, and name for each player in the game.
- printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 102, FONT_SMALL, 14, tytulowy, to); //Player Name Handicap Type
- printAtMiddleWBLoc(CGI->generaltexth->allTexts[518], 197, 102, FONT_SMALL, 10, tytulowy, to); //Starting Town
+ printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 58, FONT_SMALL, 55, Colors::Cornsilk, to); //Select starting options, handicap, and name for each player in the game.
+ printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 102, FONT_SMALL, 14, Colors::Jasmine, to); //Player Name Handicap Type
+ printAtMiddleWBLoc(CGI->generaltexth->allTexts[518], 197, 102, FONT_SMALL, 10, Colors::Jasmine, to); //Starting Town
- static void showYesNoDialog( const std::string & text, const std::vector<SComponent*> *components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, bool DelComps = true, int player = 1); //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
+ static void showYesNoDialog( const std::string & text, const std::vector<CComponent*> *components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, bool DelComps = true, int player = 1); //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
- void showAll(SDL_Surface * to); //shows statusbar (with current text)
- void setTxt(const std::string &Txt);
- void setBounds(int limitW, int limitH);
- void recalculateLines(const std::string &Txt);
-
- void sliderMoved(int to);
-};
-
-/// Status bar which is shown at the bottom of the in-game screens
-class CGStatusBar
- : public CLabel, public IStatusBar
-{
- void init();
-public:
- IStatusBar *oldStatusBar;
-
- //statusbar interface overloads
- void print(const std::string & Text); //prints text and refreshes statusbar
- void clear();//clears statusbar and refreshes
- std::string getCurrent(); //returns currently displayed text
- void show(SDL_Surface * to); //shows statusbar (with current text)
-
- CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = "");
- CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
- CGStatusBar(int x, int y, std::string name, int maxw=-1);
-
- ~CGStatusBar();
- void calcOffset();
-};
-
-/// UIElement which can get input focus
-class CFocusable
- : public virtual CIntObject
-{
-public:
- bool focus; //only one focusable control can have focus at one moment
-
- void giveFocus(); //captures focus
- void moveFocus(); //moves focus to next active control (may be used for tab switching)
std::multiset<const CArtifactInstance*> artifactsOnAltar; //artifacts id that are technically present in backpack but in GUI are moved to the altar - they'll be omitted in backpack slots
std::multiset<const CArtifactInstance*> artifactsOnAltar; //artifacts id that are technically present in backpack but in GUI are moved to the altar - they'll be omitted in backpack slots
boost::function<void(CArtPlace*)> highlightModeCallback; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
boost::function<void(CArtPlace*)> highlightModeCallback; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
@@ -1141,10 +860,10 @@ public:
void updateSlot(int i);
void updateSlot(int i);
void eraseSlotData (CArtPlace* artPlace, int slotID);
void eraseSlotData (CArtPlace* artPlace, int slotID);
std::list<IShowActivatable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
std::list<IShowActivatable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
IStatusBar * statusbar;
IStatusBar * statusbar;
@@ -45,7 +62,7 @@ public:
SDL_Event * current; //current event - can be set to NULL to stop handling event
SDL_Event * current; //current event - can be set to NULL to stop handling event
- const SRect & center(const SRect &r, bool propagate = true); //sets pos so that r will be in the center of screen, assigns sizes of r to pos, returns new position
- const SRect & center(const SPoint &p, bool propagate = true); //moves object so that point p will be in its center
- const SRect & center(bool propagate = true); //centers when pos.w and pos.h are set, returns new position
+ bool isItInLoc(const SDL_Rect &rect, const Point &p);
+ const Rect & center(const Rect &r, bool propagate = true); //sets pos so that r will be in the center of screen, assigns sizes of r to pos, returns new position
+ const Rect & center(const Point &p, bool propagate = true); //moves object so that point p will be in its center
+ const Rect & center(bool propagate = true); //centers when pos.w and pos.h are set, returns new position
void fitToScreen(int borderWidth, bool propagate = true); //moves window to fit into screen
void fitToScreen(int borderWidth, bool propagate = true); //moves window to fit into screen
+void CHighlightableButtonsGroup::addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect, int key)
+{
+ OBJ_CONSTRUCTION_CAPTURING_ALL;
+ CHighlightableButton *bt = new CHighlightableButton(OnSelect, 0, tooltip, HelpBox, false, defName, 0, x, y, key);
+/// A group of buttons where one button can be selected
+class CHighlightableButtonsGroup : public CIntObject
+{
+public:
+ CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
+ std::vector<CHighlightableButton*> buttons;
+ bool musicLike; //determines the behaviour of this group
+
+ //void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
+ void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
+ void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect=0, int key=0); //creates new button
+/// a multi-line label that tries to fit text with given available width and height; if not possible, it creates a slider for scrolling text
+class CTextBox
+ : public CLabel
+{
+public:
+ int maxW; //longest line of text in px
+ int maxH; //total height needed to print all lines
+
+ int sliderStyle;
+ bool redrawParentOnScrolling;
+
+ std::vector<std::string> lines;
+ std::vector<CAnimImage* > effects;
+ CSlider *slider;
+
+ //CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk);
+ CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk);
+ void showAll(SDL_Surface * to); //shows statusbar (with current text)
+ void setTxt(const std::string &Txt);
+ void setBounds(int limitW, int limitH);
+ void recalculateLines(const std::string &Txt);
+
+ void sliderMoved(int to);
+};
+
+/// Status bar which is shown at the bottom of the in-game screens
+class CGStatusBar
+ : public CLabel, public IStatusBar
+{
+ void init();
+public:
+ IStatusBar *oldStatusBar;
+
+ //statusbar interface overloads
+ void print(const std::string & Text); //prints text and refreshes statusbar
+ void clear();//clears statusbar and refreshes
+ std::string getCurrent(); //returns currently displayed text
+ void show(SDL_Surface * to); //shows statusbar (with current text)
+
+ CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::Cornsilk, const std::string &Text = "");
+ CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::Cornsilk); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
+ CGStatusBar(int x, int y, std::string name, int maxw=-1);
+
+ ~CGStatusBar();
+ void calcOffset();
+};
+
+/// UIElement which can get input focus
+class CFocusable
+ : public virtual CIntObject
+{
+public:
+ bool focus; //only one focusable control can have focus at one moment
+
+ void giveFocus(); //captures focus
+ void moveFocus(); //moves focus to next active control (may be used for tab switching)