diff --git a/client/widgets/CComponent.cpp b/client/widgets/CComponent.cpp index 626c37f52..dd96e48ac 100644 --- a/client/widgets/CComponent.cpp +++ b/client/widgets/CComponent.cpp @@ -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 textLines = CMessage::breakText(getSubtitle(), std::max(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); diff --git a/client/widgets/CComponent.h b/client/widgets/CComponent.h index 7ef484fe8..3f94137ff 100644 --- a/client/widgets/CComponent.h +++ b/client/widgets/CComponent.h @@ -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 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 diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 20f0aef08..b41adbe3d 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -1473,7 +1473,13 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin for(int i = 0; iresources[i]) - components.push_back(std::make_shared(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::resource, i, text, CComponent::small)); + } } cost = std::make_shared(components, Rect(25, 300, pos.w - 50, 130));