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

show missing resources

This commit is contained in:
Laserlicht 2023-10-09 21:43:43 +02:00 committed by GitHub
parent 43636af2e4
commit fa9d5e9971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View File

@ -42,7 +42,13 @@
CComponent::CComponent(Etype Type, int Subtype, int Val, ESize imageSize, EFonts font):
perDay(false)
{
init(Type, Subtype, Val, imageSize, font);
init(Type, Subtype, Val, imageSize, font, "");
}
CComponent::CComponent(Etype Type, int Subtype, std::string Val, ESize imageSize, EFonts font):
perDay(false)
{
init(Type, Subtype, 0, imageSize, font, Val);
}
CComponent::CComponent(const Component & c, ESize imageSize, EFonts font)
@ -54,7 +60,7 @@ CComponent::CComponent(const Component & c, ESize imageSize, EFonts font)
init((Etype)c.id, c.subtype, c.val, imageSize, font);
}
void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts fnt)
void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts fnt, std::string ValText)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@ -63,6 +69,7 @@ void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts
compType = Type;
subtype = Subtype;
val = Val;
valText = ValText;
size = imageSize;
font = fnt;
@ -87,6 +94,9 @@ void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts
if (size < small)
max = 30;
if(Type == Etype::resource && !valText.empty())
max = 80;
std::vector<std::string> textLines = CMessage::breakText(getSubtitle(), std::max<int>(max, pos.w), font);
for(auto & line : textLines)
{
@ -209,7 +219,7 @@ std::string CComponent::getSubtitleInternal()
{
case primskill: return boost::str(boost::format("%+d %s") % val % (subtype < 4 ? CGI->generaltexth->primarySkillNames[subtype] : CGI->generaltexth->allTexts[387]));
case secskill: return CGI->generaltexth->levels[val-1] + "\n" + CGI->skillh->getByIndex(subtype)->getNameTranslated();
case resource: return std::to_string(val);
case resource: return valText.empty() ? std::to_string(val) : valText;
case creature:
{
auto creature = CGI->creh->getByIndex(subtype);

View File

@ -49,7 +49,7 @@ private:
void setSurface(const AnimationPath & defName, int imgPos);
std::string getSubtitleInternal();
void init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts font = FONT_SMALL);
void init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts font = FONT_SMALL, std::string ValText="");
public:
std::shared_ptr<CAnimImage> image;
@ -59,12 +59,14 @@ public:
EFonts font; //Font size of label
int subtype; //type-dependant subtype. See getSomething methods for details
int val; // value \ strength \ amount of component. See getSomething methods for details
std::string valText; // value instead of amount; currently only for resource
bool perDay; // add "per day" text to subtitle
std::string getDescription();
std::string getSubtitle();
CComponent(Etype Type, int Subtype, int Val = 0, ESize imageSize=large, EFonts font = FONT_SMALL);
CComponent(Etype Type, int Subtype, std::string Val, ESize imageSize=large, EFonts font = FONT_SMALL);
CComponent(const Component &c, ESize imageSize=large, EFonts font = FONT_SMALL);
void showPopupWindow(const Point & cursorPosition) override; //call-in

View File

@ -1473,7 +1473,13 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin
for(int i = 0; i<GameConstants::RESOURCE_QUANTITY; i++)
{
if(building->resources[i])
components.push_back(std::make_shared<CComponent>(CComponent::resource, i, building->resources[i], CComponent::small));
{
std::string text = std::to_string(building->resources[i]);
int resAfterBuy = LOCPLINT->cb->getResourceAmount(GameResID(i)) - building->resources[i];
if(resAfterBuy < 0 && settings["general"]["enableUiEnhancements"].Bool())
text += " {H3Red|(" + std::to_string(-resAfterBuy) + ")}";
components.push_back(std::make_shared<CComponent>(CComponent::resource, i, text, CComponent::small));
}
}
cost = std::make_shared<CComponentBox>(components, Rect(25, 300, pos.w - 50, 130));