diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 1e0348698..ac82305e5 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -1096,7 +1096,7 @@ void CTownInfo::clickRight(tribool down, bool previousState) } CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from): - CWindowObject(PLAYER_COLORED | BORDERED), + CStatusbarWindow(PLAYER_COLORED | BORDERED), town(Town) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -1316,7 +1316,7 @@ void CHallInterface::CBuildingBox::clickRight(tribool down, bool previousState) } CHallInterface::CHallInterface(const CGTownInstance * Town): - CWindowObject(PLAYER_COLORED | BORDERED, Town->town->clientInfo.hallBackground), + CStatusbarWindow(PLAYER_COLORED | BORDERED, Town->town->clientInfo.hallBackground), town(Town) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -1365,7 +1365,7 @@ CHallInterface::CHallInterface(const CGTownInstance * Town): } CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Building, int state, bool rightClick): - CWindowObject(PLAYER_COLORED | (rightClick ? RCLICK_POPUP : 0), "TPUBUILD"), + CStatusbarWindow(PLAYER_COLORED | (rightClick ? RCLICK_POPUP : 0), "TPUBUILD"), town(Town), building(Building) { @@ -1494,7 +1494,7 @@ void LabeledValue::hover(bool on) } CFortScreen::CFortScreen(const CGTownInstance * town): - CWindowObject(PLAYER_COLORED | BORDERED, getBgName(town)) + CStatusbarWindow(PLAYER_COLORED | BORDERED, getBgName(town)) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); ui32 fortSize = town->creatures.size(); @@ -1678,7 +1678,7 @@ void CFortScreen::RecruitArea::clickRight(tribool down, bool previousState) } CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner,std::string imagem) - : CWindowObject(BORDERED, imagem) + : CStatusbarWindow(BORDERED, imagem) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -1750,7 +1750,7 @@ void CMageGuildScreen::Scroll::hover(bool on) } CBlacksmithDialog::CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid): - CWindowObject(PLAYER_COLORED, "TPSMITH") + CStatusbarWindow(PLAYER_COLORED, "TPSMITH") { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 1bc020531..3ddbe485f 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -195,7 +195,7 @@ public: }; /// Class which manages the castle window -class CCastleInterface : public CWindowObject, public CGarrisonHolder +class CCastleInterface : public CStatusbarWindow, public CGarrisonHolder { std::shared_ptr title; std::shared_ptr income; @@ -203,7 +203,6 @@ class CCastleInterface : public CWindowObject, public CGarrisonHolder std::shared_ptr panel; std::shared_ptr resdatabar; - std::shared_ptr statusbar; std::shared_ptr hall; std::shared_ptr fort; @@ -240,7 +239,7 @@ public: }; /// Hall window where you can build things -class CHallInterface : public CWindowObject +class CHallInterface : public CStatusbarWindow { class CBuildingBox : public CIntObject { @@ -264,7 +263,6 @@ class CHallInterface : public CWindowObject std::vector>> boxes; std::shared_ptr title; std::shared_ptr resdatabar; - std::shared_ptr statusbar; std::shared_ptr exit; public: @@ -272,13 +270,12 @@ public: }; /// Window where you can decide to buy a building or not -class CBuildWindow: public CWindowObject +class CBuildWindow: public CStatusbarWindow { const CGTownInstance * town; const CBuilding * building; std::shared_ptr icon; - std::shared_ptr statusbar; std::shared_ptr name; std::shared_ptr description; std::shared_ptr stateText; @@ -308,7 +305,7 @@ public: }; /// The fort screen where you can afford units -class CFortScreen : public CWindowObject +class CFortScreen : public CStatusbarWindow { class RecruitArea : public CIntObject { @@ -336,7 +333,6 @@ class CFortScreen : public CWindowObject std::shared_ptr title; std::vector> recAreas; std::shared_ptr resdatabar; - std::shared_ptr statusbar; std::shared_ptr exit; std::string getBgName(const CGTownInstance * town); @@ -348,7 +344,7 @@ public: }; /// The mage guild screen where you can see which spells you have -class CMageGuildScreen : public CWindowObject +class CMageGuildScreen : public CStatusbarWindow { class Scroll : public CIntObject { @@ -367,14 +363,13 @@ class CMageGuildScreen : public CWindowObject std::vector> emptyScrolls; std::shared_ptr resdatabar; - std::shared_ptr statusbar; public: CMageGuildScreen(CCastleInterface * owner,std::string image); }; /// The blacksmith window where you can buy available in town war machine -class CBlacksmithDialog : public CWindowObject +class CBlacksmithDialog : public CStatusbarWindow { std::shared_ptr buy; std::shared_ptr cancel; @@ -384,7 +379,6 @@ class CBlacksmithDialog : public CWindowObject std::shared_ptr costIcon; std::shared_ptr costText; std::shared_ptr costValue; - std::shared_ptr statusbar; public: CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid); diff --git a/client/windows/CWindowObject.cpp b/client/windows/CWindowObject.cpp index ef26f873c..d3e78564b 100644 --- a/client/windows/CWindowObject.cpp +++ b/client/windows/CWindowObject.cpp @@ -238,3 +238,17 @@ void CWindowObject::clickRight(tribool down, bool previousState) close(); CCS->curh->show(); } + +CStatusbarWindow::CStatusbarWindow(int options, std::string imageName, Point centerAt) : CWindowObject(options, imageName, centerAt) +{ +} + +CStatusbarWindow::CStatusbarWindow(int options, std::string imageName) : CWindowObject(options, imageName) +{ +} + +void CStatusbarWindow::activate() +{ + CIntObject::activate(); + GH.statusbar = statusbar; +} \ No newline at end of file diff --git a/client/windows/CWindowObject.h b/client/windows/CWindowObject.h index acdf01ccd..133074b37 100644 --- a/client/windows/CWindowObject.h +++ b/client/windows/CWindowObject.h @@ -11,6 +11,8 @@ #include "../gui/CIntObject.h" +class CGStatusBar; + class CWindowObject : public WindowBase { std::shared_ptr createBg(std::string imageName, bool playerColored); @@ -50,3 +52,13 @@ public: void showAll(SDL_Surface * to) override; }; + +class CStatusbarWindow : public CWindowObject +{ +public: + CStatusbarWindow(int options, std::string imageName, Point centerAt); + CStatusbarWindow(int options, std::string imageName = ""); + void activate() override; +protected: + std::shared_ptr statusbar; +}; diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 86f861712..3825e2c6f 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -194,7 +194,7 @@ void CRecruitmentWindow::showAll(SDL_Surface * to) } CRecruitmentWindow::CRecruitmentWindow(const CGDwelling * Dwelling, int Level, const CArmedInstance * Dst, const std::function & Recruit, int y_offset): - CWindowObject(PLAYER_COLORED, "TPRCRT"), + CStatusbarWindow(PLAYER_COLORED, "TPRCRT"), onRecruit(Recruit), level(Level), dst(Dst), @@ -205,7 +205,7 @@ CRecruitmentWindow::CRecruitmentWindow(const CGDwelling * Dwelling, int Level, c OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); - statusBar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); + statusbar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); slider = std::make_shared(Point(176,279),135,std::bind(&CRecruitmentWindow::sliderMoved,this, _1),0,0,0,true); @@ -630,7 +630,7 @@ void CSystemOptionsWindow::closeAndPushEvent(int eventType, int code) } CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj) - : CWindowObject(PLAYER_COLORED, "TPTAVERN"), + : CStatusbarWindow(PLAYER_COLORED, "TPTAVERN"), tavernObj(TavernObj) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -656,7 +656,7 @@ CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj) auto rumorText = boost::str(boost::format(CGI->generaltexth->allTexts[216]) % LOCPLINT->cb->getTavernRumor(tavernObj)); rumor = std::make_shared(rumorText, Rect(32, 190, 330, 68), 0, FONT_SMALL, CENTER, Colors::WHITE); - statusBar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); + statusbar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); cancel = std::make_shared(Point(310, 428), "ICANCEL.DEF", CButton::tooltip(CGI->generaltexth->tavernInfo[7]), std::bind(&CTavernWindow::close, this), SDLK_ESCAPE); recruit = std::make_shared(Point(272, 355), "TPTAV01.DEF", CButton::tooltip(), std::bind(&CTavernWindow::recruitb, this), SDLK_RETURN); thiefGuild = std::make_shared(Point(22, 428), "TPTAV02.DEF", CButton::tooltip(CGI->generaltexth->tavernInfo[5]), std::bind(&CTavernWindow::thievesguildb, this), SDLK_t); @@ -788,7 +788,7 @@ void CTavernWindow::HeroPortrait::hover(bool on) } CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID) - : CWindowObject(PLAYER_COLORED | BORDERED, "TRADE2") + : CStatusbarWindow(PLAYER_COLORED | BORDERED, "TRADE2") { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -920,7 +920,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, questlogButton[1] = std::make_shared(Point(740, 44), "hsbtns4.def", CButton::tooltip(CGI->generaltexth->heroscrn[0]), std::bind(&CExchangeWindow::questlog, this, 1)); Rect barRect(5, 578, 725, 18); - statusBar = CGStatusBar::create(std::make_shared(*background, barRect, 5, 578, false)); + statusbar = CGStatusBar::create(std::make_shared(*background, barRect, 5, 578, false)); //garrison interface garr = std::make_shared(69, 131, 4, Point(418,0), heroInst[0], heroInst[1], true, true); @@ -978,7 +978,7 @@ void CExchangeWindow::updateWidgets() } CShipyardWindow::CShipyardWindow(const std::vector & cost, int state, int boatType, const std::function & onBuy) - : CWindowObject(PLAYER_COLORED, "TPSHIP") + : CStatusbarWindow(PLAYER_COLORED, "TPSHIP") { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -1013,7 +1013,7 @@ CShipyardWindow::CShipyardWindow(const std::vector & cost, int state, int } } - statusBar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); + statusbar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); title = std::make_shared(164, 27, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[13]); costLabel = std::make_shared(164, 220, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->jktexts[14]); @@ -1159,7 +1159,7 @@ void CTransformerWindow::updateGarrisons() } CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town) - : CWindowObject(PLAYER_COLORED, "SKTRNBK"), + : CStatusbarWindow(PLAYER_COLORED, "SKTRNBK"), hero(_hero), town(_town) { @@ -1178,7 +1178,7 @@ CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTow all = std::make_shared(Point(146, 416), "ALTARMY.DEF", CGI->generaltexth->zelp[590], [&](){ addAll(); }, SDLK_a); convert = std::make_shared(Point(269, 416), "ALTSACR.DEF", CGI->generaltexth->zelp[591], [&](){ makeDeal(); }, SDLK_RETURN); cancel = std::make_shared(Point(392, 416), "ICANCEL.DEF", CGI->generaltexth->zelp[592], [&](){ close(); },SDLK_ESCAPE); - statusBar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); + statusbar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); titleLeft = std::make_shared(153, 29,FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[485]);//holding area titleRight = std::make_shared(153+295, 29, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[486]);//transformer @@ -1254,7 +1254,7 @@ void CUniversityWindow::CItem::showAll(SDL_Surface * to) } CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market) - : CWindowObject(PLAYER_COLORED, "UNIVERS1"), + : CStatusbarWindow(PLAYER_COLORED, "UNIVERS1"), hero(_hero), market(_market) { @@ -1283,7 +1283,7 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket items.push_back(std::make_shared(this, goods[i], 54+i*104, 234)); cancel = std::make_shared(Point(200, 313), "IOKAY.DEF", CGI->generaltexth->zelp[632], [&](){ close(); }, SDLK_RETURN); - statusBar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); + statusbar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); } void CUniversityWindow::makeDeal(int skill) @@ -1293,7 +1293,7 @@ void CUniversityWindow::makeDeal(int skill) CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * owner_, int SKILL, bool available) - : CWindowObject(PLAYER_COLORED, "UNIVERS2.PCX"), + : CStatusbarWindow(PLAYER_COLORED, "UNIVERS2.PCX"), owner(owner_) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -1324,7 +1324,7 @@ CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * owner_, int SKILL, bo confirm->block(!available); cancel = std::make_shared(Point(252,299), "ICANCEL.DEF", CGI->generaltexth->zelp[631], [&](){ close(); }, SDLK_ESCAPE); - statusBar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); + statusbar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); } void CUnivConfirmWindow::makeDeal(int skill) @@ -1375,7 +1375,7 @@ void CGarrisonWindow::updateGarrisons() } CHillFortWindow::CHillFortWindow(const CGHeroInstance * visitor, const CGObjectInstance * object) - : CWindowObject(PLAYER_COLORED, "APHLFTBK"), + : CStatusbarWindow(PLAYER_COLORED, "APHLFTBK"), fort(object), hero(visitor) { @@ -1409,7 +1409,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance * visitor, const CGObjectI upgradeAll->addImage(image); quit = std::make_shared(Point(294, 275), "IOKAY.DEF", CButton::tooltip(), std::bind(&CHillFortWindow::close, this), SDLK_RETURN); - statusBar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); + statusbar = CGStatusBar::create(std::make_shared(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); garr = std::make_shared(108, 60, 18, Point(), hero, nullptr); updateGarrisons(); @@ -1579,7 +1579,7 @@ int CHillFortWindow::getState(SlotID slot) } CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner): - CWindowObject(PLAYER_COLORED | BORDERED, "TpRank"), + CStatusbarWindow(PLAYER_COLORED | BORDERED, "TpRank"), owner(_owner) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -1590,7 +1590,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner): exitb = std::make_shared(Point(748, 556), "TPMAGE1", CButton::tooltip(CGI->generaltexth->allTexts[600]), [&](){ close();}, SDLK_RETURN); exitb->assignedKeys.insert(SDLK_ESCAPE); - statusBar = CGStatusBar::create(3, 555, "TStatBar.bmp", 742); + statusbar = CGStatusBar::create(3, 555, "TStatBar.bmp", 742); resdatabar = std::make_shared(); resdatabar->moveBy(pos.topLeft(), true); diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index 064ecb9d5..6167e1370 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -38,7 +38,7 @@ class CResDataBar; class CHeroWithMaybePickedArtifact; /// Recruitment window where you can recruit creatures -class CRecruitmentWindow : public CWindowObject +class CRecruitmentWindow : public CStatusbarWindow { class CCreatureCard : public CIntObject, public std::enable_shared_from_this { @@ -64,8 +64,6 @@ class CRecruitmentWindow : public CWindowObject int level; const CArmedInstance * dst; - std::shared_ptr statusBar; - std::shared_ptr selected; std::vector> cards; @@ -235,7 +233,7 @@ public: CSystemOptionsWindow(); }; -class CTavernWindow : public CWindowObject +class CTavernWindow : public CStatusbarWindow { public: class HeroPortrait : public CIntObject @@ -273,7 +271,6 @@ public: std::shared_ptr title; std::shared_ptr cost; std::shared_ptr rumor; - std::shared_ptr statusBar; CTavernWindow(const CGObjectInstance * TavernObj); ~CTavernWindow(); @@ -283,7 +280,7 @@ public: void show(SDL_Surface * to) override; }; -class CExchangeWindow : public CWindowObject, public CGarrisonHolder, public CWindowWithArtifacts +class CExchangeWindow : public CStatusbarWindow, public CGarrisonHolder, public CWindowWithArtifacts { std::array, 2> herosWArt; @@ -312,7 +309,6 @@ class CExchangeWindow : public CWindowObject, public CGarrisonHolder, public CWi std::shared_ptr quit; std::array, 2> questlogButton; - std::shared_ptr statusBar; std::shared_ptr garr; public: @@ -330,7 +326,7 @@ public: }; /// Here you can buy ships -class CShipyardWindow : public CWindowObject +class CShipyardWindow : public CStatusbarWindow { std::shared_ptr bgWater; std::shared_ptr bgShip; @@ -346,7 +342,6 @@ class CShipyardWindow : public CWindowObject std::shared_ptr build; std::shared_ptr quit; - std::shared_ptr statusBar; public: CShipyardWindow(const std::vector & cost, int state, int boatType, const std::function & onBuy); }; @@ -373,7 +368,7 @@ public: }; /// Creature transformer window -class CTransformerWindow : public CWindowObject, public CGarrisonHolder +class CTransformerWindow : public CStatusbarWindow, public CGarrisonHolder { class CItem : public CIntObject { @@ -405,7 +400,6 @@ class CTransformerWindow : public CWindowObject, public CGarrisonHolder std::shared_ptr all; std::shared_ptr convert; std::shared_ptr cancel; - std::shared_ptr statusBar; public: void makeDeal(); @@ -414,7 +408,7 @@ public: CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); }; -class CUniversityWindow : public CWindowObject +class CUniversityWindow : public CStatusbarWindow { class CItem : public CIntObject { @@ -443,7 +437,6 @@ class CUniversityWindow : public CWindowObject std::vector> items; std::shared_ptr cancel; - std::shared_ptr statusBar; std::shared_ptr titlePic; std::shared_ptr title; std::shared_ptr clerkSpeech; @@ -455,7 +448,7 @@ public: }; /// Confirmation window for University -class CUnivConfirmWindow : public CWindowObject +class CUnivConfirmWindow : public CStatusbarWindow { std::shared_ptr clerkSpeech; std::shared_ptr name; @@ -463,7 +456,6 @@ class CUnivConfirmWindow : public CWindowObject std::shared_ptr icon; CUniversityWindow * owner; - std::shared_ptr statusBar; std::shared_ptr confirm; std::shared_ptr cancel; @@ -494,7 +486,7 @@ public: }; /// Hill fort is the building where you can upgrade units -class CHillFortWindow : public CWindowObject, public CGarrisonHolder +class CHillFortWindow : public CStatusbarWindow, public CGarrisonHolder { private: static const int slotsCount = 7; @@ -522,8 +514,6 @@ private: std::shared_ptr garr; - std::shared_ptr statusBar; - std::string getDefForSlot(SlotID slot); std::string getTextForSlot(SlotID slot); @@ -534,11 +524,10 @@ public: void updateGarrisons() override;//update buttons after garrison changes }; -class CThievesGuildWindow : public CWindowObject +class CThievesGuildWindow : public CStatusbarWindow { const CGObjectInstance * owner; - std::shared_ptr statusBar; std::shared_ptr exitb; std::shared_ptr resdatabar;