RogueLibs' logo

Custom Names

Custom localization in RogueLibs is implemented using instances of the CustomName class, which contain all languages' translations at the same time (which isn't really efficient, but whatever, Matt's code is even worse). You can integrate your custom names into the game using the RogueLibs.CreateCustomName(…) method.

CustomNameInfo structure

CustomNameInfo structure is used to create custom names and transfer localization data.

/MyAwesomeProject/MyAwesomeNames.cs
CustomNameInfo emptyInfo = new CustomNameInfo();CustomNameInfo nameInfo = new CustomNameInfo("english text");

You can add more translations to the custom names too:

/MyAwesomeProject/MyAwesomeNames.cs
nameInfo = new CustomNameInfo{    French = "texte français",    Spanish = "texto en español",};// ornameInfo.French = "texte français";nameInfo.Spanish = "texto en español";

Unlike dictionaries, both CustomName and CustomNameInfo return null, if they don't contain the specified LanguageCode:

/MyAwesomeProject/MyAwesomeNames.cs
string translation = nameInfo[(LanguageCode)123];// returns null, if that language is not specifiedstring display = translation ?? nameInfo.English;

CustomName class

Usually, CustomNames are created automatically, when you add names and descriptions to your items, traits, abilities and etc.:

/MyAwesomeProject/MyAwesomeItem.cs
RogueLibs.CreateCustomItem<MyAwesomeItem>()    .WithName(new CustomNameInfo("English name")    {        French = "nom français",        Spanish = "nombre español",    })    .WithDescription(new CustomNameInfo("English description")    {        French = "description française",        Spanish = "descripción en español",    });

You can initialize them yourself too, although you have to provide the name and type of the CustomName yourself:

/MyAwesomeProject/MyAwesomeNames.cs
CustomName name = RogueLibs.CreateCustomName("Name", NameTypes.Type, new CustomNameInfo("Info"));

If you're going to use the second method, here's the list of name types used in the game:

  • "Item" - item and special ability names;
  • "Description" - item, special ability, trait, status effect and agent descriptions;
  • "StatusEffect" - trait and status effect names;
  • "Interface" - interface buttons, labels and stuff;
  • "Unlock" - mutator and Big Quest names and descriptions;
  • "Object" - object and chunk type names;
  • "Agent" - agent names;
  • "Dialogue" - agent dialogue lines;
Pro-tip: Name type const strings

Use string consts in the NameTypes static class to avoid typos.

Usage

If you want to use your custom names in the game, use NameDB.GetName() or any other methods that use it:

/MyAwesomeProject/MyAwesomeItem.cs
string dialogue = gc.nameDB.GetName("CryForHelp", NameTypes.Dialogue);
/MyAwesomeProject/MyAwesomeItem.cs
Owner.SayDialogue("CryForHelp");

CustomNames and CustomNameInfos can also be implicitly converted into CustomTooltip:

/MyAwesomeProject/Recycler.cs
public class Recycler : CustomItem, IItemCombinable{    [RLSetup]    public static void Setup()    {        recycleTooltip = RogueLibs.CreateCustomName("Recycle", NameTypes.Interface, new CustomNameInfo        {            English = "Recycle",            Russian = "Переработать",        });    }    private static CustomName recycleTooltip;    /* ... */    public CustomTooltip CombineTooltip(InvItem _) => recycleTooltip;}