Skip to content

Do not show contract limit when limit is at maxValue, add FormatContractText() method - #70

Merged
siimav merged 6 commits into
KSP-RO:masterfrom
Clayell:master
May 25, 2026
Merged

Do not show contract limit when limit is at maxValue, add FormatContractText() method#70
siimav merged 6 commits into
KSP-RO:masterfrom
Clayell:master

Conversation

@Clayell

@Clayell Clayell commented May 25, 2026

Copy link
Copy Markdown

Bug reported by Worcester

Before:
image

After:
image

Also condensed all of this text into a method, since it was very repetitive and hard to follow.

@Clayell Clayell changed the title Add FormatContractText() method, do not show contract limit when limit is at maxValue Do not show contract limit when limit is at maxValue, add FormatContractText() method May 25, 2026
Comment thread source/ContractConfigurator/MissionControlUI.cs Outdated
Comment on lines +1302 to +1317
string stars = string.Concat(Enumerable.Repeat("<sprite=\"CurrencySpriteAsset\" name=\"Reputation\" tint=1>", starCount));

string text;

if (max == int.MaxValue)
{
text = "{2}";
}
else
{
text = current >= max ? "<color=#f97306>{2} [{1}: {3}]</color>" : "{2} [{1}: {3}]";
}

text = addNewLine ? text + "\n" : text;

output += StringBuilderCache.Format($"<b><color=#f4ee21>{stars}{starSpacing}</color><color=#DB8310>{{0}}{titleSpacing}</color></b>{text}", Localizer.Format(title), Localizer.Format("#cc.mcui.max"), current, max);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use stringbuilder from start to finish. Way too many string concats in there now.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what you mean?

23a9ead

(still works)
image
image

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean then?


private void FormatContractCounts(ref string output, int starCount, string title, int current, int max, string starSpacing, string titleSpacing, bool addNewLine)
{
string stars = string.Concat(Enumerable.Repeat("<sprite=\"CurrencySpriteAsset\" name=\"Reputation\" tint=1>", starCount));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concatenation here.

Comment thread source/ContractConfigurator/MissionControlUI.cs Outdated

text = addNewLine ? text + "\n" : text;

output += StringBuilderCache.Format("<b><color=#f4ee21>{0}{1}</color><color=#DB8310>{2}{3}</color></b>" + text, stars, starSpacing, Localizer.Format(title), titleSpacing, Localizer.Format("#cc.mcui.max"), current, max);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You allocate a new chonker of a string here for + text. Then another chonker when Format fills in the placeholders.

@siimav
siimav merged commit 4d845f5 into KSP-RO:master May 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants