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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
|
/*
* CCastleInterface.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 "../windows/CWindowObject.h"
#include "../widgets/Images.h"
VCMI_LIB_NAMESPACE_BEGIN
class CBuilding;
class CGTownInstance;
class CSpell;
struct CStructure;
class CGHeroInstance;
class CCreature;
VCMI_LIB_NAMESPACE_END
class CButton;
class CCastleBuildings;
class CCreaturePic;
class CGStatusBar;
class CLabel;
class CMinorResDataBar;
class CPicture;
class CResDataBar;
class CTextBox;
class CTownList;
class CGarrisonInt;
class CComponent;
class CComponentBox;
class LRClickableArea;
/// Building "button"
class CBuildingRect : public CShowableAnim
{
std::string getSubtitle();
public:
enum EBuildingCreationAnimationPhases : uint32_t
{
BUILDING_APPEAR_TIMEPOINT = 500, //500 msec building appears: 0->100% transparency
BUILDING_WHITE_BORDER_TIMEPOINT = 900, //400 msec border glows from white to yellow
BUILDING_YELLOW_BORDER_TIMEPOINT = 1100, //200 msec border glows from yellow to normal (dark orange)
BUILD_ANIMATION_FINISHED_TIMEPOINT = 2100, // 1000msec once border is back to yellow nothing happens (this stage is basically removed by HD Mod)
BUILDING_FRAME_TIME = 150 // confirmed H3 timing: 150 ms for each building animation frame
};
/// returns building associated with this structure
const CBuilding * getBuilding();
CCastleBuildings * parent;
const CGTownInstance * town;
const CStructure* str;
std::shared_ptr<IImage> border;
std::shared_ptr<IImage> area;
ui32 stateTimeCounter;//For building construction - current stage in animation
CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str);
bool operator<(const CBuildingRect & p2) const;
void hover(bool on) override;
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
void mouseMoved (const Point & cursorPosition, const Point & lastUpdateDistance) override;
bool receiveEvent(const Point & position, int eventType) const override;
void tick(uint32_t msPassed) override;
void show(Canvas & to) override;
void showAll(Canvas & to) override;
};
/// Dwelling info box - right-click screen for dwellings
class CDwellingInfoBox : public CWindowObject
{
std::shared_ptr<CLabel> title;
std::shared_ptr<CCreaturePic> animation;
std::shared_ptr<CLabel> available;
std::shared_ptr<CLabel> costPerTroop;
std::vector<std::shared_ptr<CAnimImage>> resPicture;
std::vector<std::shared_ptr<CLabel>> resAmount;
public:
CDwellingInfoBox(int centerX, int centerY, const CGTownInstance * Town, int level);
~CDwellingInfoBox();
};
class HeroSlots;
/// Hero icon slot
class CHeroGSlot : public CIntObject
{
std::shared_ptr<CAnimImage> portrait;
std::shared_ptr<CAnimImage> flag;
std::shared_ptr<CAnimImage> selection; //selection border. nullptr if not selected
HeroSlots * owner;
const CGHeroInstance * hero;
int upg; //0 - up garrison, 1 - down garrison
public:
CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, HeroSlots * Owner);
~CHeroGSlot();
bool isSelected() const;
void setHighlight(bool on);
void set(const CGHeroInstance * newHero);
void hover (bool on) override;
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
void deactivate() override;
};
/// Two hero slots that can interact with each other
class HeroSlots : public CIntObject
{
public:
bool showEmpty;
const CGTownInstance * town;
std::shared_ptr<CGarrisonInt> garr;
std::shared_ptr<CHeroGSlot> garrisonedHero;
std::shared_ptr<CHeroGSlot> visitingHero;
HeroSlots(const CGTownInstance * town, Point garrPos, Point visitPos, std::shared_ptr<CGarrisonInt> Garrison, bool ShowEmpty);
~HeroSlots();
void update();
void swapArmies(); //exchange garrisoned and visiting heroes or move hero to\from garrison
};
/// Class for town screen management (town background and structures)
class CCastleBuildings : public CIntObject
{
std::shared_ptr<CPicture> background;
//List of buildings and structures that can represent them
std::map<BuildingID, std::vector<const CStructure *> > groups;
// actual IntObject's visible on screen
std::vector<std::shared_ptr<CBuildingRect>> buildings;
const CGTownInstance * town;
const CGHeroInstance* getHero();//Select hero for buildings usage
void enterBlacksmith(BuildingID building, ArtifactID artifactID);//support for blacksmith + ballista yard
void enterBuilding(BuildingID building);//for buildings with simple description + pic left-click messages
void enterCastleGate(BuildingID building);
void enterFountain(const BuildingID & building, BuildingSubID::EBuildingSubID subID, BuildingID upgrades);//Rampart's fountains
void openMagesGuild();
void openTownHall();
void recreate();
void drawOverlays(Canvas & to, std::vector<std::shared_ptr<CBuildingRect>> buildingRects);
void show(Canvas & to) override;
public:
CBuildingRect * selectedBuilding;
CCastleBuildings(const CGTownInstance * town);
~CCastleBuildings();
void enterDwelling(int level);
void enterTownHall();
void enterRewardable(BuildingID building);
void enterMagesGuild();
void enterAnyMarket();
void enterAnyThievesGuild();
void enterBank(BuildingID building);
void enterToTheQuickRecruitmentWindow();
bool buildingTryActivateCustomUI(BuildingID buildingToTest, BuildingID buildingTarget);
void buildingClicked(BuildingID building);
void addBuilding(BuildingID building);
void removeBuilding(BuildingID building);//FIXME: not tested!!!
};
/// Creature info window
class CCreaInfo : public CIntObject
{
const CGTownInstance * town;
CreatureID creature;
int level;
bool showAvailable;
std::shared_ptr<CAnimImage> picture;
std::shared_ptr<CLabel> label;
std::string genGrowthText();
public:
CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact=false, bool _showAvailable=false);
void update();
void hover(bool on) override;
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
bool getShowAvailable();
};
/// Town hall and fort icons for town screen
class CTownInfo : public CIntObject
{
const CGTownInstance * town;
const CBuilding * building;
public:
std::shared_ptr<CAnimImage> picture;
//if (townHall) hall-capital else fort - castle
CTownInfo(int posX, int posY, const CGTownInstance * town, bool townHall);
void hover(bool on) override;
void showPopupWindow(const Point & cursorPosition) override;
};
/// Class which manages the castle window
class CCastleInterface : public CStatusbarWindow, public IGarrisonHolder
{
std::shared_ptr<CLabel> title;
std::shared_ptr<CLabel> income;
std::shared_ptr<CAnimImage> icon;
std::shared_ptr<CPicture> panel;
std::shared_ptr<CResDataBar> resdatabar;
std::shared_ptr<CTownInfo> hall;
std::shared_ptr<CTownInfo> fort;
std::shared_ptr<CButton> exit;
std::shared_ptr<CButton> fastTownHall;
std::shared_ptr<CButton> fastArmyPurchase;
std::shared_ptr<LRClickableArea> fastMarket;
std::shared_ptr<LRClickableArea> fastTavern;
std::vector<std::shared_ptr<CCreaInfo>> creainfo;//small icons of creatures (bottom-left corner);
public:
std::shared_ptr<CTownList> townlist;
//TODO: move to private
const CGTownInstance * town;
std::shared_ptr<HeroSlots> heroes;
std::shared_ptr<CCastleBuildings> builds;
std::shared_ptr<CGarrisonInt> garr;
//from - previously selected castle (if any)
CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr);
~CCastleInterface();
void updateGarrisons() override;
bool holdsGarrison(const CArmedInstance * army) override;
void castleTeleport(int where);
void townChange();
void keyPressed(EShortcut key) override;
void close() override;
void addBuilding(BuildingID bid);
void removeBuilding(BuildingID bid);
void recreateIcons();
void creaturesChangedEventHandler();
};
/// Hall window where you can build things
class CHallInterface : public CStatusbarWindow
{
class CBuildingBox : public CIntObject
{
const CGTownInstance * town;
const CBuilding * building;
EBuildingState state;
std::shared_ptr<CAnimImage> header;
std::shared_ptr<CAnimImage> icon;
std::shared_ptr<CAnimImage> mark;
std::shared_ptr<CLabel> name;
public:
CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
void hover(bool on) override;
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
};
const CGTownInstance * town;
std::vector<std::vector<std::shared_ptr<CBuildingBox>>> boxes;
std::shared_ptr<CLabel> title;
std::shared_ptr<CMinorResDataBar> resdatabar;
std::shared_ptr<CButton> exit;
public:
CHallInterface(const CGTownInstance * Town);
};
/// Window where you can decide to buy a building or not
class CBuildWindow: public CStatusbarWindow
{
const CGTownInstance * town;
const CBuilding * building;
std::shared_ptr<CAnimImage> icon;
std::shared_ptr<CLabel> name;
std::shared_ptr<CTextBox> description;
std::shared_ptr<CTextBox> stateText;
std::shared_ptr<CComponentBox> cost;
std::shared_ptr<CButton> buy;
std::shared_ptr<CButton> cancel;
std::string getTextForState(EBuildingState state);
void buyFunc();
public:
CBuildWindow(const CGTownInstance *Town, const CBuilding * building, EBuildingState State, bool rightClick);
};
//Small class to display
class LabeledValue : public CIntObject
{
std::string hoverText;
std::shared_ptr<CLabel> name;
std::shared_ptr<CLabel> value;
void init(std::string name, std::string descr, int min, int max);
public:
LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
LabeledValue(Rect size, std::string name, std::string descr, int val);
void hover(bool on) override;
};
/// The fort screen where you can afford units
class CFortScreen : public CStatusbarWindow
{
class RecruitArea : public CIntObject
{
const CGTownInstance * town;
int level;
std::string hoverText;
std::shared_ptr<CLabel> availableCount;
std::vector<std::shared_ptr<LabeledValue>> values;
std::shared_ptr<CPicture> icons;
std::shared_ptr<CAnimImage> buildingIcon;
std::shared_ptr<CLabel> buildingName;
const CCreature * getMyCreature();
const CBuilding * getMyBuilding();
public:
RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
void creaturesChangedEventHandler();
void hover(bool on) override;
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
};
std::shared_ptr<CLabel> title;
std::vector<std::shared_ptr<RecruitArea>> recAreas;
std::shared_ptr<CMinorResDataBar> resdatabar;
std::shared_ptr<CButton> exit;
ImagePath getBgName(const CGTownInstance * town);
public:
CFortScreen(const CGTownInstance * town);
void creaturesChangedEventHandler();
};
/// The mage guild screen where you can see which spells you have
class CMageGuildScreen : public CStatusbarWindow
{
class Scroll : public CIntObject
{
const CSpell * spell;
std::shared_ptr<CAnimImage> image;
ObjectInstanceID townId;
public:
Scroll(Point position, const CSpell *Spell, ObjectInstanceID townId);
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
void hover(bool on) override;
};
std::shared_ptr<CPicture> window;
std::shared_ptr<CButton> exit;
std::vector<std::shared_ptr<Scroll>> spells;
std::vector<std::shared_ptr<CAnimImage>> emptyScrolls;
std::shared_ptr<CMinorResDataBar> resdatabar;
ObjectInstanceID townId;
public:
CMageGuildScreen(CCastleInterface * owner, const ImagePath & image);
void updateSpells(ObjectInstanceID tID);
};
/// The blacksmith window where you can buy available in town war machine
class CBlacksmithDialog : public CStatusbarWindow
{
std::shared_ptr<CButton> buy;
std::shared_ptr<CButton> cancel;
std::shared_ptr<CPicture> animBG;
std::shared_ptr<CCreatureAnim> anim;
std::shared_ptr<CLabel> title;
std::shared_ptr<CAnimImage> costIcon;
std::shared_ptr<CLabel> costText;
std::shared_ptr<CLabel> costValue;
public:
CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid);
};
|