/* * CInfoBar.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 * */ #pragma once #include "../gui/CIntObject.h" VCMI_LIB_NAMESPACE_BEGIN class CGHeroInstance; class CGTownInstance; struct Component; class PlayerColor; VCMI_LIB_NAMESPACE_END class CAnimImage; class CShowableAnim; class CComponent; class CComponentBox; class CHeroTooltip; class CTownTooltip; class CLabel; class CTextBox; /// Info box which shows next week/day information, hold the current date class CInfoBar : public CIntObject { private: /// Infobar actually have a fixed size /// Declare before to compute correct size of widgets static constexpr int width = 192; static constexpr int height = 192; static constexpr int offset = 4; //all visible information located in one object - for ease of replacing class CVisibleInfo : public CIntObject { public: static constexpr int offset_x = 8; static constexpr int offset_y = 12; void show(SDL_Surface * to) override; protected: std::shared_ptr background; std::list> forceRefresh; CVisibleInfo(); }; static constexpr int data_width = width - 2 * CVisibleInfo::offset_x; static constexpr int data_height = height - 2 * CVisibleInfo::offset_y + 4; //yes, +4 is required class EmptyVisibleInfo : public CVisibleInfo { public: EmptyVisibleInfo(); }; class VisibleHeroInfo : public CVisibleInfo { std::shared_ptr heroTooltip; public: VisibleHeroInfo(const CGHeroInstance * hero); }; class VisibleTownInfo : public CVisibleInfo { std::shared_ptr townTooltip; public: VisibleTownInfo(const CGTownInstance * town); }; class VisibleDateInfo : public CVisibleInfo { std::shared_ptr animation; std::shared_ptr label; std::string getNewDayName(); public: VisibleDateInfo(); }; class VisibleEnemyTurnInfo : public CVisibleInfo { std::shared_ptr banner; std::shared_ptr glass; std::shared_ptr sand; public: VisibleEnemyTurnInfo(PlayerColor player); }; class VisibleGameStatusInfo : public CVisibleInfo { std::shared_ptr allyLabel; std::shared_ptr enemyLabel; std::vector> flags; std::vector> hallIcons; std::vector> hallLabels; public: VisibleGameStatusInfo(); }; class VisibleComponentInfo : public CVisibleInfo { std::shared_ptr comps; std::shared_ptr text; public: struct Cache { std::vector compsToDisplay; std::string message; int textH; bool tiny; Cache(std::vector comps, std::string msg, int textH, bool tiny): compsToDisplay(std::move(comps)), message(std::move(msg)), textH(textH), tiny(tiny) {} }; VisibleComponentInfo(const Cache & c): VisibleComponentInfo(c.compsToDisplay, c.message, c.textH, c.tiny) {} VisibleComponentInfo(const std::vector & compsToDisplay, std::string message, int textH, bool tiny); }; enum EState { EMPTY, HERO, TOWN, DATE, GAME, AITURN, COMPONENT }; std::shared_ptr visibleInfo; EState state; std::queue> componentsQueue; //private helper for showing components void showComponents(const std::vector & comps, std::string message, int textH, bool tiny, int timer); void pushComponents(const std::vector & comps, std::string message, int textH, bool tiny, int timer); void prepareComponents(const std::vector & comps, std::string message, int timer); void popComponents(); //removes all information about current state, deactivates timer (if any) void reset(); void tick() override; void clickLeft(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override; void hover(bool on) override; void playNewDaySound(); public: CInfoBar(const Rect & pos); CInfoBar(const Point & pos); /// show new day/week animation void showDate(); /// show components for 3 seconds. Used to display picked up resources. Can display up to 8 components void pushComponents(const std::vector & comps, std::string message, int timer = 3000); /// Remove all queued components void popAll(); /// print enemy turn progress void startEnemyTurn(PlayerColor color); /// reset to default view - selected object void showSelection(); /// show hero\town information void showHeroSelection(const CGHeroInstance * hero); void showTownSelection(const CGTownInstance * town); /// for 3 seconds shows amount of town halls and players status void showGameStatus(); /// check if infobar is showed something about pickups bool showingComponents(); /// get estimated component height for InfoBar int getEstimatedComponentHeight(int numComps) const; };