mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-02 23:07:36 +02:00
Restored previously disabled University code, add interface to notify
market-like objects
This commit is contained in:
parent
c1ebb6b0e3
commit
fcafe53da9
@ -442,18 +442,20 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, Prim
|
|||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
if (which == PrimarySkill::EXPERIENCE)
|
if (which == PrimarySkill::EXPERIENCE)
|
||||||
{
|
{
|
||||||
for(auto ctw : GH.windows().findWindows<CMarketWindow>())
|
for(auto ctw : GH.windows().findWindows<IMarketHolder>())
|
||||||
ctw->updateHero();
|
ctw->updateExperience();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
adventureInt->onHeroChanged(hero);
|
adventureInt->onHeroChanged(hero);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlayerInterface::heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val)
|
void CPlayerInterface::heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val)
|
||||||
{
|
{
|
||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
for (auto cuw : GH.windows().findWindows<CUniversityWindow>())
|
for (auto cuw : GH.windows().findWindows<IMarketHolder>())
|
||||||
cuw->redraw();
|
cuw->updateSecondarySkills();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
|
void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
|
||||||
@ -472,8 +474,8 @@ void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
|
|||||||
void CPlayerInterface::receivedResource()
|
void CPlayerInterface::receivedResource()
|
||||||
{
|
{
|
||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
for (auto mw : GH.windows().findWindows<CMarketWindow>())
|
for (auto mw : GH.windows().findWindows<IMarketHolder>())
|
||||||
mw->updateResource();
|
mw->updateResources();
|
||||||
|
|
||||||
GH.windows().totalRedraw();
|
GH.windows().totalRedraw();
|
||||||
}
|
}
|
||||||
@ -1675,7 +1677,7 @@ void CPlayerInterface::showHillFortWindow(const CGObjectInstance *object, const
|
|||||||
void CPlayerInterface::availableArtifactsChanged(const CGBlackMarket * bm)
|
void CPlayerInterface::availableArtifactsChanged(const CGBlackMarket * bm)
|
||||||
{
|
{
|
||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
for (auto cmw : GH.windows().findWindows<CMarketWindow>())
|
for (auto cmw : GH.windows().findWindows<IMarketHolder>())
|
||||||
cmw->updateArtifacts();
|
cmw->updateArtifacts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +165,15 @@ public:
|
|||||||
virtual void updateGarrisons() = 0;
|
virtual void updateGarrisons() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class IMarketHolder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void updateResources() {};
|
||||||
|
virtual void updateExperience() {};
|
||||||
|
virtual void updateSecondarySkills() {};
|
||||||
|
virtual void updateArtifacts() {};
|
||||||
|
};
|
||||||
|
|
||||||
class ITownHolder
|
class ITownHolder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -70,12 +70,12 @@ void CMarketWindow::updateGarrisons()
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMarketWindow::updateResource()
|
void CMarketWindow::updateResources()
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMarketWindow::updateHero()
|
void CMarketWindow::updateExperience()
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ void CMarketWindow::createAltarArtifacts(const IMarket * market, const CGHeroIns
|
|||||||
};
|
};
|
||||||
addSet(heroArts);
|
addSet(heroArts);
|
||||||
initWidgetInternals(EMarketMode::ARTIFACT_EXP, CGI->generaltexth->zelp[568]);
|
initWidgetInternals(EMarketMode::ARTIFACT_EXP, CGI->generaltexth->zelp[568]);
|
||||||
updateHero();
|
updateExperience();
|
||||||
quitButton->addCallback([altarArtifacts](){altarArtifacts->putBackArtifacts();});
|
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);
|
background = createBg(ImagePath::builtin("ALTARMON.bmp"), PLAYER_COLORED);
|
||||||
marketWidget = std::make_shared<CAltarCreatures>(market, hero);
|
marketWidget = std::make_shared<CAltarCreatures>(market, hero);
|
||||||
initWidgetInternals(EMarketMode::CREATURE_EXP, CGI->generaltexth->zelp[568]);
|
initWidgetInternals(EMarketMode::CREATURE_EXP, CGI->generaltexth->zelp[568]);
|
||||||
updateHero();
|
updateExperience();
|
||||||
}
|
}
|
||||||
|
@ -12,14 +12,14 @@
|
|||||||
#include "../widgets/markets/CMarketBase.h"
|
#include "../widgets/markets/CMarketBase.h"
|
||||||
#include "CWindowWithArtifacts.h"
|
#include "CWindowWithArtifacts.h"
|
||||||
|
|
||||||
class CMarketWindow : public CStatusbarWindow, public CWindowWithArtifacts, public IGarrisonHolder
|
class CMarketWindow final : public CStatusbarWindow, public CWindowWithArtifacts, public IGarrisonHolder, public IMarketHolder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CMarketWindow(const IMarket * market, const CGHeroInstance * hero, const std::function<void()> & onWindowClosed, EMarketMode mode);
|
CMarketWindow(const IMarket * market, const CGHeroInstance * hero, const std::function<void()> & onWindowClosed, EMarketMode mode);
|
||||||
void updateResource();
|
void updateResources() override;
|
||||||
void updateArtifacts();
|
void updateArtifacts() override;
|
||||||
void updateGarrisons() override;
|
void updateGarrisons() override;
|
||||||
void updateHero();
|
void updateExperience() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
void close() override;
|
void close() override;
|
||||||
bool holdsGarrison(const CArmedInstance * army) override;
|
bool holdsGarrison(const CArmedInstance * army) override;
|
||||||
|
@ -891,26 +891,20 @@ CUniversityWindow::CItem::CItem(CUniversityWindow * _parent, int _ID, int X, int
|
|||||||
pos.x += X;
|
pos.x += X;
|
||||||
pos.y += Y;
|
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);
|
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.h = icon->pos.h;
|
||||||
pos.w = icon->pos.w;
|
pos.w = icon->pos.w;
|
||||||
|
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUniversityWindow::CItem::clickPressed(const Point & cursorPosition)
|
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);
|
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));
|
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)
|
void CUniversityWindow::CItem::hover(bool on)
|
||||||
{
|
{
|
||||||
if(on)
|
if(on)
|
||||||
GH.statusbar()->write(CGI->skillh->getByIndex(ID)->getNameTranslated());
|
GH.statusbar()->write(ID.toEntity(VLC)->getNameTranslated());
|
||||||
else
|
else
|
||||||
GH.statusbar()->clear();
|
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)
|
CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market, const std::function<void()> & onWindowClosed)
|
||||||
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("UNIVERS1")),
|
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("UNIVERS1")),
|
||||||
hero(_hero),
|
hero(_hero),
|
||||||
@ -987,12 +995,17 @@ void CUniversityWindow::close()
|
|||||||
CStatusbarWindow::close();
|
CStatusbarWindow::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CUniversityWindow::updateSecondarySkills()
|
||||||
|
{
|
||||||
|
for (auto const & item : items)
|
||||||
|
item->update();
|
||||||
|
}
|
||||||
|
|
||||||
void CUniversityWindow::makeDeal(SecondarySkill skill)
|
void CUniversityWindow::makeDeal(SecondarySkill skill)
|
||||||
{
|
{
|
||||||
LOCPLINT->cb->trade(market, EMarketMode::RESOURCE_SKILL, GameResID(GameResID::GOLD), skill, 1, hero);
|
LOCPLINT->cb->trade(market, EMarketMode::RESOURCE_SKILL, GameResID(GameResID::GOLD), skill, 1, hero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * owner_, SecondarySkill SKILL, bool available)
|
CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * owner_, SecondarySkill SKILL, bool available)
|
||||||
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("UNIVERS2.PCX")),
|
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("UNIVERS2.PCX")),
|
||||||
owner(owner_)
|
owner(owner_)
|
||||||
|
@ -358,9 +358,9 @@ public:
|
|||||||
CTransformerWindow(const IMarket * _market, const CGHeroInstance * _hero, const std::function<void()> & onWindowClosed);
|
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<CAnimImage> icon;
|
||||||
std::shared_ptr<CPicture> topBar;
|
std::shared_ptr<CPicture> topBar;
|
||||||
@ -374,7 +374,7 @@ class CUniversityWindow : public CStatusbarWindow
|
|||||||
void clickPressed(const Point & cursorPosition) override;
|
void clickPressed(const Point & cursorPosition) override;
|
||||||
void showPopupWindow(const Point & cursorPosition) override;
|
void showPopupWindow(const Point & cursorPosition) override;
|
||||||
void hover(bool on) 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);
|
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);
|
CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market, const std::function<void()> & onWindowClosed);
|
||||||
|
|
||||||
void makeDeal(SecondarySkill skill);
|
void makeDeal(SecondarySkill skill);
|
||||||
void close();
|
void close() override;
|
||||||
|
|
||||||
|
// IMarketHolder impl
|
||||||
|
void updateSecondarySkills() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Confirmation window for University
|
/// Confirmation window for University
|
||||||
class CUnivConfirmWindow : public CStatusbarWindow
|
class CUnivConfirmWindow final : public CStatusbarWindow
|
||||||
{
|
{
|
||||||
std::shared_ptr<CTextBox> clerkSpeech;
|
std::shared_ptr<CTextBox> clerkSpeech;
|
||||||
std::shared_ptr<CLabel> name;
|
std::shared_ptr<CLabel> name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user