Changes

→‎What's new for NPCs: + Dialogue changes
Line 3,431: Line 3,431:     
In C# code, you can get the inventory for a custom shop using <code>Utility.GetShopStock("shop id here")</code>, or open a shop menu using <code>Game1.activeClickableMenu = new ShopMenu(new(), who: "shop id here")</code>. The ID of the opened shop is stored in the shop menu's <samp>storeContext</samp> field.
 
In C# code, you can get the inventory for a custom shop using <code>Utility.GetShopStock("shop id here")</code>, or open a shop menu using <code>Game1.activeClickableMenu = new ShopMenu(new(), who: "shop id here")</code>. The ID of the opened shop is stored in the shop menu's <samp>storeContext</samp> field.
 +
 +
===Dialogue changes===
 +
<ul>
 +
<li>For C# mods, <samp>Dialogue</samp> now tracks the translation key used to build it (when applicable). For example, you can detect when the player is rejected at the [[Flower Dance]] (derived from the {{github|spacechase0/StardewValleyMods|Three-Heart Dance Partner}}):
 +
<syntaxhighlight lang="c#">
 +
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
 +
{
 +
    bool isDanceRejection =
 +
        Game1.currentLocation?.currentEvent?.FestivalName == "Flower Dance"
 +
        && e.NewMenu is DialogueBox dialogueBox
 +
        && dialogueBox.characterDialogue is {} dialogue
 +
        && dialogue.TranslationKey == $"Characters\\Dialogue\\{dialogue.speaker?.Name}:danceRejection";
 +
}
 +
</syntaxhighlight>
 +
 +
For C# mods that create <samp>Dialogue</samp> instances directly, there's a few ways to do it now:
 +
<syntaxhighlight lang="c#">
 +
// from a translation key
 +
var dialogue = new Dialogue(npc, "Strings\\StringsFromCSFiles:Utility.cs.5360");
 +
 +
// from custom text (with or without a translation key)
 +
var dialogue = new Dialogue(npc, null, "Some arbitrary text to show as-is");
 +
 +
// from a translation with tokens
 +
var dialogue = Dialogue.FromTranslation(npc, "Data\\ExtraDialogue:PurchasedItem_2_QualityLow_Willy", whatToCallPlayer, particle, i.DisplayName);
 +
</syntaxhighlight>
 +
 +
You can also easily add fallback logic using <samp>Dialogue.TryGetDialogue</samp> or <samp>npc.TryGetDialogue</samp>. For example:
 +
<syntaxhighlight lang="c#">
 +
Dialogue dialogue =
 +
    npc.TryGetDialogue($"rejection_{itemId}_{locationName}_{x}_{y}")
 +
    ?? npc.TryGetDialogue($"rejection_{itemId}_{locationName}")
 +
    ?? npc.TryGetDialogue($"rejection_{itemId}")
 +
    ?? new Dialogue(npc, "Strings\\StringsFromCSFiles:NPC.cs.3971");
 +
</syntaxhighlight>
 +
</li>
 +
<li>Fixed NPCs only using a <code>{day name}{hearts}_{year}</code> dialogue if they also have a <code>{day name}{hearts}</code> one.</li>
 +
<li>Fixed NPCs only using the <code>MovieInvitation</code> dialogue key in English.</li>
 +
</ul>
    
==What's new for everything else==
 
==What's new for everything else==
translators
8,447

edits