-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Hello! Using MusicDisplay is simple, alongside getting information for music registered by the mod.
Example: musicDisplay.Call("AddMusic", musicSlot, displayName, author, modName)
AddMusic takes one of three overloads:
"AddMusic", short id, LocalizedText name, LocalizedText author, LocalizedText subTitle
Adds an entry for the given music slot with the given track name, author and subtitle. Subtitle is usually used for mod names, such as the standard format
"Track Name"
by Author
Mod Name
The ID must be a short!
"AddMusic", short id, LocalizedText name, LocalizedText author, LocalizedText subTitle, Func<bool> displayCondition
Behaves like the overload above, but additionally allows more control over when the display should show with the displayCondition func.
"AddMusic", short id, LocalizedText name, LocalizedText author, LocalizedText subTitle, Func<bool> displayCondition, Color[] colors
Behaves like the overload above, but additionally takes a 4-element Color array for each text item.
In order, these are the colors for the: Main text (Song name), Author name, Subtitle, and Now Playing text. You may pass an array of less than four colors, which will fill the remaining options will their default colors. For example, [Color.Green] would set the main text to green, and the rest would be unchanged.
You can skip the displayCondition by passing null.
Example: musicDisplay.Call("GetMusicText", musicSlot)
GetMusicText takes one overload, shown above, and returns the MusicText struct for the given music slot, if any. If there is no such struct, return the MusicText for Unknown Music (which is shown when a song is not recognized).
Example: musicDisplay.Call("GetMusicInfo", musicSlot)
GetMusicInfo takes one overload, shown above, and returns an object[] of the MusicText struct's information, in this order:
LocalizedText text.MainText, LocalizedText text.Author, LocalizedText text.Subtitle, Func<bool> text.ShouldDisplay
If no display is registered for the slot, this will return the info for the Unknown Music track.
For Spirit Reforged, and various other projects, I've simplified the code for this to one line per track:
// given "display", the Mod for MusicDisplay
LocalizedText modName = Language.GetText("Mods.SpiritReforged.MusicDisplay.ModName");
void AddMusic(string name)
{
LocalizedText author = Language.GetText("Mods.SpiritReforged.MusicDisplay." + name + ".Author");
LocalizedText displayName = Language.GetText("Mods.SpiritReforged.MusicDisplay." + name + ".DisplayName");
display.Call("AddMusic", (short)MusicLoader.GetMusicSlot(SpiritReforgedMod.Instance, "Assets/Music/" + name), displayName, author, modName);
}
AddMusic("Duststorm");
AddMusic("Savanna");This makes it trivial to add in music tracks without having to repeat code.