TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ FormatWith()

string Terraria.Localization.LocalizedText.FormatWith ( object obj)
inline

Creates a string from this LocalizedText populated with data from the provided obj parameter. The properties of the provided object are substituted by name into the placeholders of the original text. For example, when used with M:Terraria.Lang.CreateDialogSubstitutionObject(Terraria.NPC), the text "{Nurse}" will be replaced with the first name of the Nurse in the world. Modded substitutions are not currently supported.

When used in conjunction with M:Terraria.Localization.Language.SelectRandom(Terraria.Localization.LanguageSearchFilter,Terraria.Utilities.UnifiedRandom) and M:Terraria.Lang.CreateDialogFilter(System.String,System.Object), simple boolean conditions expressed in each LocalizedText can be used to filter a collection of LocalizedText.

M:Terraria.Localization.LocalizedText.Format(System.Object[]) is more commonly used to format LocalizedText placeholders. That method replaces placeholders such as "{0}", "{1}", etc with the string representation of the corresponding objects provided.

Parameters
obj
Returns

Definition at line 64 of file LocalizedText.cs.

65 {
66 string value = Value;
67 PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(obj);
68 return _substitutionRegex.Replace(value, delegate(Match match)
69 {
70 if (match.Groups[1].Length != 0)
71 {
72 return "";
73 }
74 string name = match.Groups[2].ToString();
75 PropertyDescriptor propertyDescriptor = properties.Find(name, ignoreCase: false);
76 return (propertyDescriptor != null) ? (propertyDescriptor.GetValue(obj) ?? "").ToString() : "";
77 });
78 }
string Value
Retrieves the text value. This is the actual text the user should see.

References Terraria.Localization.LocalizedText._substitutionRegex, Terraria.Localization.LocalizedText.ToString(), and Terraria.Localization.LocalizedText.Value.

Referenced by Terraria.GameContent.UI.GameTipsDisplay.GameTip.GameTip(), Terraria.Lang.BartenderHelpText(), Terraria.Lang.DyeTraderQuestChat(), and Terraria.Main.HelpText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: