diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index e48e4e58d..06c5aff05 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -442,18 +442,20 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, Prim EVENT_HANDLER_CALLED_BY_CLIENT; if (which == PrimarySkill::EXPERIENCE) { - for(auto ctw : GH.windows().findWindows()) - ctw->updateHero(); + for(auto ctw : GH.windows().findWindows()) + ctw->updateExperience(); } else + { adventureInt->onHeroChanged(hero); + } } void CPlayerInterface::heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val) { EVENT_HANDLER_CALLED_BY_CLIENT; - for (auto cuw : GH.windows().findWindows()) - cuw->redraw(); + for (auto cuw : GH.windows().findWindows()) + cuw->updateSecondarySkills(); } void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero) @@ -472,8 +474,8 @@ void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero) void CPlayerInterface::receivedResource() { EVENT_HANDLER_CALLED_BY_CLIENT; - for (auto mw : GH.windows().findWindows()) - mw->updateResource(); + for (auto mw : GH.windows().findWindows()) + mw->updateResources(); GH.windows().totalRedraw(); } @@ -1675,7 +1677,7 @@ void CPlayerInterface::showHillFortWindow(const CGObjectInstance *object, const void CPlayerInterface::availableArtifactsChanged(const CGBlackMarket * bm) { EVENT_HANDLER_CALLED_BY_CLIENT; - for (auto cmw : GH.windows().findWindows()) + for (auto cmw : GH.windows().findWindows()) cmw->updateArtifacts(); } diff --git a/client/gui/CIntObject.h b/client/gui/CIntObject.h index 06b484376..a2afaea54 100644 --- a/client/gui/CIntObject.h +++ b/client/gui/CIntObject.h @@ -165,6 +165,15 @@ public: virtual void updateGarrisons() = 0; }; +class IMarketHolder +{ +public: + virtual void updateResources() {}; + virtual void updateExperience() {}; + virtual void updateSecondarySkills() {}; + virtual void updateArtifacts() {}; +}; + class ITownHolder { public: diff --git a/client/windows/CMarketWindow.cpp b/client/windows/CMarketWindow.cpp index de09e748b..2789f3ca8 100644 --- a/client/windows/CMarketWindow.cpp +++ b/client/windows/CMarketWindow.cpp @@ -70,12 +70,12 @@ void CMarketWindow::updateGarrisons() update(); } -void CMarketWindow::updateResource() +void CMarketWindow::updateResources() { update(); } -void CMarketWindow::updateHero() +void CMarketWindow::updateExperience() { update(); } @@ -251,7 +251,7 @@ void CMarketWindow::createAltarArtifacts(const IMarket * market, const CGHeroIns }; addSet(heroArts); initWidgetInternals(EMarketMode::ARTIFACT_EXP, CGI->generaltexth->zelp[568]); - updateHero(); + updateExperience(); quitButton->addCallback([altarArtifacts](){altarArtifacts->putBackArtifacts();}); } @@ -262,5 +262,5 @@ void CMarketWindow::createAltarCreatures(const IMarket * market, const CGHeroIns background = createBg(ImagePath::builtin("ALTARMON.bmp"), PLAYER_COLORED); marketWidget = std::make_shared(market, hero); initWidgetInternals(EMarketMode::CREATURE_EXP, CGI->generaltexth->zelp[568]); - updateHero(); + updateExperience(); } diff --git a/client/windows/CMarketWindow.h b/client/windows/CMarketWindow.h index 59403b84d..1f7d2179c 100644 --- a/client/windows/CMarketWindow.h +++ b/client/windows/CMarketWindow.h @@ -12,14 +12,14 @@ #include "../widgets/markets/CMarketBase.h" #include "CWindowWithArtifacts.h" -class CMarketWindow : public CStatusbarWindow, public CWindowWithArtifacts, public IGarrisonHolder +class CMarketWindow final : public CStatusbarWindow, public CWindowWithArtifacts, public IGarrisonHolder, public IMarketHolder { public: CMarketWindow(const IMarket * market, const CGHeroInstance * hero, const std::function & onWindowClosed, EMarketMode mode); - void updateResource(); - void updateArtifacts(); + void updateResources() override; + void updateArtifacts() override; void updateGarrisons() override; - void updateHero(); + void updateExperience() override; void update() override; void close() override; bool holdsGarrison(const CArmedInstance * army) override; diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index d9fd5683a..17f73ef91 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -891,26 +891,20 @@ CUniversityWindow::CItem::CItem(CUniversityWindow * _parent, int _ID, int X, int pos.x += X; pos.y += Y; - // TODO: restore - //bars->setCustom("UNIVRED", 0, 0); - //bars->setCustom("UNIVGOLD", 1, 0); - //bars->setCustom("UNIVGREN", 2, 0); - - topBar = std::make_shared(ImagePath::builtin("UNIVRED"), Point(-28, -22)); - bottomBar = std::make_shared(ImagePath::builtin("UNIVRED"), Point(-28, 48)); - icon = std::make_shared(AnimationPath::builtin("SECSKILL"), _ID * 3 + 3, 0); - name = std::make_shared(22, -13, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->skillh->getByIndex(ID)->getNameTranslated()); - level = std::make_shared(22, 57, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->levels[0]); - pos.h = icon->pos.h; pos.w = icon->pos.w; + + update(); } void CUniversityWindow::CItem::clickPressed(const Point & cursorPosition) { - if(state() == 2) + bool skillKnown = parent->hero->getSecSkillLevel(ID); + bool canLearn = parent->hero->canLearnSkill(ID); + + if (!skillKnown && canLearn) GH.windows().createAndPushWindow(parent, ID, LOCPLINT->cb->getResourceAmount(EGameResID::GOLD) >= 2000); } @@ -919,23 +913,37 @@ void CUniversityWindow::CItem::showPopupWindow(const Point & cursorPosition) CRClickPopup::createAndPush(CGI->skillh->getByIndex(ID)->getDescriptionTranslated(1), std::make_shared(ComponentType::SEC_SKILL, ID, 1)); } +void CUniversityWindow::CItem::update() +{ + bool skillKnown = parent->hero->getSecSkillLevel(ID); + bool canLearn = parent->hero->canLearnSkill(ID); + + ImagePath image; + + if (skillKnown) + image = ImagePath::builtin("UNIVGOLD"); + else if (canLearn) + image = ImagePath::builtin("UNIVGREN"); + else + image = ImagePath::builtin("UNIVRED"); + + OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); + topBar = std::make_shared(image, Point(-28, -22)); + bottomBar = std::make_shared(image, Point(-28, 48)); + + // needs to be on top of background bars + name = std::make_shared(22, -13, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, ID.toEntity(VLC)->getNameTranslated()); + level = std::make_shared(22, 57, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->levels[0]); +} + void CUniversityWindow::CItem::hover(bool on) { if(on) - GH.statusbar()->write(CGI->skillh->getByIndex(ID)->getNameTranslated()); + GH.statusbar()->write(ID.toEntity(VLC)->getNameTranslated()); else GH.statusbar()->clear(); } -int CUniversityWindow::CItem::state() -{ - if(parent->hero->getSecSkillLevel(SecondarySkill(ID)))//hero know this skill - return 1; - if(!parent->hero->canLearnSkill(SecondarySkill(ID)))//can't learn more skills - return 0; - return 2; -} - CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market, const std::function & onWindowClosed) : CWindowObject(PLAYER_COLORED, ImagePath::builtin("UNIVERS1")), hero(_hero), @@ -987,12 +995,17 @@ void CUniversityWindow::close() CStatusbarWindow::close(); } +void CUniversityWindow::updateSecondarySkills() +{ + for (auto const & item : items) + item->update(); +} + void CUniversityWindow::makeDeal(SecondarySkill skill) { LOCPLINT->cb->trade(market, EMarketMode::RESOURCE_SKILL, GameResID(GameResID::GOLD), skill, 1, hero); } - CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * owner_, SecondarySkill SKILL, bool available) : CWindowObject(PLAYER_COLORED, ImagePath::builtin("UNIVERS2.PCX")), owner(owner_) diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index 05c65c412..00bf4c8fa 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -358,9 +358,9 @@ public: CTransformerWindow(const IMarket * _market, const CGHeroInstance * _hero, const std::function & onWindowClosed); }; -class CUniversityWindow : public CStatusbarWindow +class CUniversityWindow final : public CStatusbarWindow, public IMarketHolder { - class CItem : public CIntObject + class CItem final : public CIntObject { std::shared_ptr icon; std::shared_ptr topBar; @@ -374,7 +374,7 @@ class CUniversityWindow : public CStatusbarWindow void clickPressed(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override; void hover(bool on) override; - int state();//0=can't learn, 1=learned, 2=can learn + void update(); CItem(CUniversityWindow * _parent, int _ID, int X, int Y); }; @@ -394,11 +394,14 @@ public: CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market, const std::function & onWindowClosed); void makeDeal(SecondarySkill skill); - void close(); + void close() override; + + // IMarketHolder impl + void updateSecondarySkills() override; }; /// Confirmation window for University -class CUnivConfirmWindow : public CStatusbarWindow +class CUnivConfirmWindow final : public CStatusbarWindow { std::shared_ptr clerkSpeech; std::shared_ptr name;