/* * 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 "../widgets/CGarrisonInt.h" #include "../widgets/Images.h" class CButton; class CBuilding; class CCastleBuildings; class CCreaturePic; class CGStatusBar; class CGTownInstance; class CLabel; class CMinorResDataBar; class CPicture; class CResDataBar; class CSpell; class CTextBox; class CTownList; struct CStructure; class CGHeroInstance; class CGarrisonInt; class CCreature; class CComponent; class CComponentBox; /// Building "button" class CBuildingRect : public CShowableAnim { std::string getSubtitle(); public: /// returns building associated with this structure const CBuilding * getBuilding(); CCastleBuildings * parent; const CGTownInstance * town; const CStructure* str; SDL_Surface* border; SDL_Surface* area; ui32 stateCounter;//For building construction - current stage in animation CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str); ~CBuildingRect(); bool operator<(const CBuildingRect & p2) const; void hover(bool on) override; void clickLeft(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override; void mouseMoved (const SDL_MouseMotionEvent & sEvent) override; void show(SDL_Surface * to) override; void showAll(SDL_Surface * to) override; }; /// Dwelling info box - right-click screen for dwellings class CDwellingInfoBox : public CWindowObject { std::shared_ptr title; std::shared_ptr animation; std::shared_ptr available; std::shared_ptr costPerTroop; std::vector> resPicture; std::vector> 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 portrait; std::shared_ptr flag; std::shared_ptr 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 clickLeft(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) 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 garr; std::shared_ptr garrisonedHero; std::shared_ptr visitingHero; HeroSlots(const CGTownInstance * town, Point garrPos, Point visitPos, std::shared_ptr Garrison, bool ShowEmpty); ~HeroSlots(); void splitClicked(); //for hero meeting only (splitting stacks is handled by garrison int) 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 background; //List of buildings and structures that can represent them std::map > groups; // actual IntObject's visible on screen std::vector> buildings; const CGTownInstance * town; const CGHeroInstance* getHero();//Select hero for buildings usage void enterBlacksmith(ArtifactID artifactID);//support for blacksmith + ballista yard void enterBuilding(BuildingID building);//for buildings with simple description + pic left-click messages void enterCastleGate(); void enterFountain(const BuildingID & building, BuildingSubID::EBuildingSubID subID, BuildingID::EBuildingID upgrades);//Rampart's fountains void enterMagesGuild(); void enterTownHall(); void openMagesGuild(); void openTownHall(); void recreate(); public: CBuildingRect * selectedBuilding; CCastleBuildings(const CGTownInstance * town); ~CCastleBuildings(); void enterDwelling(int level); void enterToTheQuickRecruitmentWindow(); void buildingClicked(BuildingID building, BuildingSubID::EBuildingSubID subID = BuildingSubID::NONE, BuildingID::EBuildingID upgrades = BuildingID::NONE); void addBuilding(BuildingID building); void removeBuilding(BuildingID building);//FIXME: not tested!!! }; /// Creature info window class CCreaInfo : public CIntObject { const CGTownInstance * town; const CCreature * creature; int level; bool showAvailable; std::shared_ptr picture; std::shared_ptr 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 clickLeft(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override; }; /// Town hall and fort icons for town screen class CTownInfo : public CIntObject { const CGTownInstance * town; const CBuilding * building; public: std::shared_ptr picture; //if (townHall) hall-capital else fort - castle CTownInfo(int posX, int posY, const CGTownInstance * town, bool townHall); void hover(bool on) override; void clickRight(tribool down, bool previousState) override; }; /// Class which manages the castle window class CCastleInterface : public CStatusbarWindow, public CGarrisonHolder { std::shared_ptr title; std::shared_ptr income; std::shared_ptr icon; std::shared_ptr panel; std::shared_ptr resdatabar; std::shared_ptr hall; std::shared_ptr fort; std::shared_ptr exit; std::shared_ptr split; std::shared_ptr fastArmyPurchase; std::vector> creainfo;//small icons of creatures (bottom-left corner); public: std::shared_ptr townlist; //TODO: move to private const CGTownInstance * town; std::shared_ptr heroes; std::shared_ptr builds; std::shared_ptr garr; //from - previously selected castle (if any) CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr); ~CCastleInterface(); virtual void updateGarrisons() override; void castleTeleport(int where); void townChange(); void keyPressed(const SDL_KeyboardEvent & key) override; void close(); void addBuilding(BuildingID bid); void removeBuilding(BuildingID bid); void recreateIcons(); }; /// Hall window where you can build things class CHallInterface : public CStatusbarWindow { class CBuildingBox : public CIntObject { const CGTownInstance * town; const CBuilding * building; ui32 state;//Buildings::EBuildStructure enum std::shared_ptr header; std::shared_ptr icon; std::shared_ptr mark; std::shared_ptr name; public: CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building); void hover(bool on) override; void clickLeft(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override; }; const CGTownInstance * town; std::vector>> boxes; std::shared_ptr title; std::shared_ptr resdatabar; std::shared_ptr 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 icon; std::shared_ptr name; std::shared_ptr description; std::shared_ptr stateText; std::shared_ptr cost; std::shared_ptr buy; std::shared_ptr cancel; std::string getTextForState(int state); void buyFunc(); public: CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick); }; //Small class to display class LabeledValue : public CIntObject { std::string hoverText; std::shared_ptr name; std::shared_ptr 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 availableCount; std::vector> values; std::shared_ptr icons; std::shared_ptr buildingIcon; std::shared_ptr buildingName; const CCreature * getMyCreature(); const CBuilding * getMyBuilding(); public: RecruitArea(int posX, int posY, const CGTownInstance *town, int level); void creaturesChanged(); void hover(bool on) override; void clickLeft(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override; }; std::shared_ptr title; std::vector> recAreas; std::shared_ptr resdatabar; std::shared_ptr exit; std::string getBgName(const CGTownInstance * town); public: CFortScreen(const CGTownInstance * town); void creaturesChanged(); }; /// 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 image; public: Scroll(Point position, const CSpell *Spell); void clickLeft(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override; void hover(bool on) override; }; std::shared_ptr window; std::shared_ptr exit; std::vector> spells; std::vector> emptyScrolls; std::shared_ptr resdatabar; public: CMageGuildScreen(CCastleInterface * owner,std::string image); }; /// The blacksmith window where you can buy available in town war machine class CBlacksmithDialog : public CStatusbarWindow { std::shared_ptr buy; std::shared_ptr cancel; std::shared_ptr animBG; std::shared_ptr anim; std::shared_ptr title; std::shared_ptr costIcon; std::shared_ptr costText; std::shared_ptr costValue; public: CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid); };