1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Restored previously disabled University code, add interface to notify

market-like objects
This commit is contained in:
Ivan Savenko 2024-06-05 13:24:36 +00:00
parent c1ebb6b0e3
commit fcafe53da9
6 changed files with 70 additions and 43 deletions

View File

@ -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<CMarketWindow>())
ctw->updateHero();
for(auto ctw : GH.windows().findWindows<IMarketHolder>())
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<CUniversityWindow>())
cuw->redraw();
for (auto cuw : GH.windows().findWindows<IMarketHolder>())
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<CMarketWindow>())
mw->updateResource();
for (auto mw : GH.windows().findWindows<IMarketHolder>())
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<CMarketWindow>())
for (auto cmw : GH.windows().findWindows<IMarketHolder>())
cmw->updateArtifacts();
}

View File

@ -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:

View File

@ -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<CAltarCreatures>(market, hero);
initWidgetInternals(EMarketMode::CREATURE_EXP, CGI->generaltexth->zelp[568]);
updateHero();
updateExperience();
}

View File

@ -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<void()> & 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;

View File

@ -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<CPicture>(ImagePath::builtin("UNIVRED"), Point(-28, -22));
bottomBar = std::make_shared<CPicture>(ImagePath::builtin("UNIVRED"), Point(-28, 48));
icon = std::make_shared<CAnimImage>(AnimationPath::builtin("SECSKILL"), _ID * 3 + 3, 0);
name = std::make_shared<CLabel>(22, -13, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->skillh->getByIndex(ID)->getNameTranslated());
level = std::make_shared<CLabel>(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<CUnivConfirmWindow>(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<CComponent>(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<CPicture>(image, Point(-28, -22));
bottomBar = std::make_shared<CPicture>(image, Point(-28, 48));
// needs to be on top of background bars
name = std::make_shared<CLabel>(22, -13, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, ID.toEntity(VLC)->getNameTranslated());
level = std::make_shared<CLabel>(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<void()> & 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_)

View File

@ -358,9 +358,9 @@ public:
CTransformerWindow(const IMarket * _market, const CGHeroInstance * _hero, const std::function<void()> & onWindowClosed);
};
class CUniversityWindow : public CStatusbarWindow
class CUniversityWindow final : public CStatusbarWindow, public IMarketHolder
{
class CItem : public CIntObject
class CItem final : public CIntObject
{
std::shared_ptr<CAnimImage> icon;
std::shared_ptr<CPicture> 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<void()> & 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<CTextBox> clerkSpeech;
std::shared_ptr<CLabel> name;