1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*
* 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"
#include "CConfigHandler.h"
#include "../../lib/filesystem/ResourcePath.h"
#include "../../lib/networkPacks/Component.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 CInteractableHeroTooltip;
class CTownTooltip;
class CInteractableTownTooltip;
class CLabel;
class CMultiLineLabel;
/// 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(Canvas & to) override;
protected:
std::shared_ptr<CPicture> background;
std::list<std::shared_ptr<CIntObject>> forceRefresh;
CVisibleInfo();
};
static constexpr int data_width = width - 2 * CVisibleInfo::offset_x;
static constexpr int data_height = height - 2 * CVisibleInfo::offset_y;
class EmptyVisibleInfo : public CVisibleInfo
{
public:
EmptyVisibleInfo();
};
class VisibleHeroInfo : public CVisibleInfo
{
std::shared_ptr<CIntObject> heroTooltip; //should have CHeroTooltip or CInteractableHeroTooltip;
public:
VisibleHeroInfo(const CGHeroInstance * hero);
};
class VisibleTownInfo : public CVisibleInfo
{
std::shared_ptr<CIntObject> townTooltip; //should have CTownTooltip or CInteractableTownTooltip;
public:
VisibleTownInfo(const CGTownInstance * town);
};
class VisibleDateInfo : public CVisibleInfo
{
std::shared_ptr<CShowableAnim> animation;
std::shared_ptr<CLabel> label;
AnimationPath getNewDayName();
public:
VisibleDateInfo();
};
class VisibleEnemyTurnInfo : public CVisibleInfo
{
std::shared_ptr<CAnimImage> banner;
std::shared_ptr<CShowableAnim> glass;
std::shared_ptr<CShowableAnim> sand;
public:
VisibleEnemyTurnInfo(PlayerColor player);
};
class VisibleGameStatusInfo : public CVisibleInfo
{
std::shared_ptr<CLabel> allyLabel;
std::shared_ptr<CLabel> enemyLabel;
std::vector<std::shared_ptr<CAnimImage>> flags;
std::vector<std::shared_ptr<CAnimImage>> hallIcons;
std::vector<std::shared_ptr<CLabel>> hallLabels;
public:
VisibleGameStatusInfo();
};
class VisibleComponentInfo : public CVisibleInfo
{
std::shared_ptr<CComponentBox> comps;
std::shared_ptr<CMultiLineLabel> text;
public:
struct Cache
{
std::vector<Component> compsToDisplay;
std::string message;
int textH;
bool tiny;
Cache(std::vector<Component> 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<Component> & compsToDisplay, std::string message, int textH, bool tiny);
};
enum EState
{
EMPTY, HERO, TOWN, DATE, GAME, AITURN, COMPONENT
};
std::shared_ptr<CVisibleInfo> visibleInfo;
EState state;
uint32_t timerCounter;
bool shouldPopAll = false;
SettingsListener listener;
std::queue<std::pair<VisibleComponentInfo::Cache, int>> componentsQueue;
//private helper for showing components
void showComponents(const std::vector<Component> & comps, std::string message, int textH, bool tiny, int timer);
void pushComponents(const std::vector<Component> & comps, std::string message, int textH, bool tiny, int timer);
void prepareComponents(const std::vector<Component> & comps, std::string message, int timer);
void popComponents(bool remove = false);
//removes all information about current state, deactivates timer (if any)
void reset();
void tick(uint32_t msPassed) override;
void clickReleased(const Point & cursorPosition, bool lastActivated) override;
void showPopupWindow(const Point & cursorPosition) override;
void hover(bool on) override;
void playNewDaySound();
void setTimer(uint32_t msToTrigger);
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<Component> & comps, std::string message, int timer = 3000);
/// Remove all queued components
void popAll();
/// Request infobar to pop all after next InfoWindow arrives.
void requestPopAll();
/// 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();
/// event handler for custom listening on game setting change
void OnInfoBarCreatureManagementChanged();
};
|