1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-17 00:07:41 +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

@ -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_)