Dialogues and announcements from code
What this page is for
Section titled “What this page is for”Your own scripts can open a dialogue, show an announcement, put a message in a player’s flag tray and set the volume of the sounds. This page lists those calls. The nodes of a scheme do the same through Show Dialogue and Show Announcement; see Dialogues and announcements for how they work from the Studio.
When you come here
Section titled “When you come here”- A button in your own UI should open a dialogue.
- A script must tell the player something, now or as a flag.
- You build an options menu with sound sliders.
All of these are main thread only. The types are in the namespace MrW.Intrigues.UI, and IM is in MrW.Intrigues.
Open a dialogue
Section titled “Open a dialogue”Two overloads of DialogueManager.OpenDialogue, both static. Both throw an ArgumentException when no Dialogue Manager can be found or made. That happens without an Intrigue Manager, or when the Intrigue Manager names no Dialogue Manager prefab and no view of your own is installed. The Dialogue Manager is made from the prefab named on the Intrigue Manager (DialogueManager.Instance does this on first use).
| Signature | What it does |
|---|---|
Dialogue OpenDialogue(string title, string content, float time = 0, bool typeWriter = false, Action<float> onUpdate = null, bool isSchemeDialog = false) |
Opens a dialogue. time is a limit in seconds, counted once the choices appear; 0 is none. typeWriter writes the text letter by letter. onUpdate gets the seconds left every frame. |
MessageHandle OpenDialogue(DialogueOptions options) |
Opens it as the options say, also as a flag or silently. The dialogue never leaves this machine. Null for null options, and off the main thread. |
The window is built late in the frame. Choices you add to the returned object right away are there from its first frame. The text can hold pacing marks such as {pause}, {wait}, {slow} and {cue Name}. Format your own tokens first, with IntrigueText.Format(text, context.WithMarks()).
Example, not compiled:
var dialogue = DialogueManager.OpenDialogue("A letter", "It is signed, but not by a hand you know.", typeWriter: true);dialogue.AddChoice("Burn it", () => Debug.Log("burned"));dialogue.AddChoice("Keep it");Source: Dialogue/DialogueManager.cs, Dialogue/Dialogue.cs.
DialogueOptions
Section titled “DialogueOptions”A class of public fields. Create one with new DialogueOptions { ... }.
| Field | Default | What it is |
|---|---|---|
Title |
empty | A text key or a text as written. |
Content |
empty | The text; pacing marks are read. |
Time |
0 | Time limit in seconds; 0 is none. |
Typewriter |
false | Write the text letter by letter. |
OnUpdate |
null | Action<float>, the seconds left. |
Style |
null | The window style; null uses the Dialogue Manager’s default style. |
Priority |
MessagePriority.Interrupt |
How it arrives. |
FlagTitle |
empty | The title in the tray; empty uses Title. |
FlagIcon |
null | The flag icon; null uses the style’s flag icon. |
FlagImportance |
FlagImportance.Medium |
How much the flag matters. |
NeedsAnswer |
true | The dialogue waits for its answer, so a full tray shows it on screen instead of recording it silently. |
Source: Dialogue/Presentation/MessageHandle.cs.
How a message arrives
Section titled “How a message arrives”MessagePriority has three values.
| Value | Studio label | What happens |
|---|---|---|
Interrupt |
On screen now | It opens at once. |
Flag |
As a flag | A flag waits in the player’s tray. Opening the flag shows the same window. |
Silent |
Silently | No window and no flag. The message is only recorded, and a dialogue that waits answers itself. |
FlagImportance is Low (a tray may hide it), Medium (the default) or High (with Flags Pause Days on, the host pauses the days when one is raised for a player).
The Dialogue you get back
Section titled “The Dialogue you get back”The Set... and Add... methods return the dialogue, so you can chain them. Public members:
| Member | What it does |
|---|---|
AddChoice(string text, Sprite icon, Action action, Func<bool> condition = null, bool closeWhenSelected = true, bool hideIfConditionNotMet = false, ChoiceData data = null) |
The full form. A choice is clickable only while condition returns true. |
AddChoice(string text), AddChoice(string text, Sprite icon), AddChoice(string text, Action action), AddChoice(string text, Sprite icon, Action action, bool closeWhenSelected) |
Short forms. The first three close the dialogue. |
SetText, SetBackground, SetPicture, SetStyle, SetSpeaker, SetNativeSize |
Change the content and look. |
SetMusic, SetAmbience |
A DialogueTrack or an AudioClip with a volume, played while it is open. |
AddSound(DialogueSound), AddVoice(DialogueVoice) |
A sound that starts when it is shown, and the voice-over (only the first call counts). |
Close(bool withoutNotification = false), Close(DialogueCloseReason reason), Hide, Show, Skip |
Control it. |
IsOpen, IsClosed, IsHidden, IsWriting, IsWaiting, IsSchemeDialog, IsTop, CloseReason |
State. |
Events onTimeout, onDialogueClose, onDialogueShow, onDialogueHide, onTextRevealed, onCue(string) |
Per dialogue. |
DialogueManager also closes many at once: Close(bool justSchemeDialog = false, bool withoutNotification = false), HideAll(...) and ShowAll(...) with the same two parameters. DialogueManager.PictureFromTags(string tags) gives a sprite from the Sprite Database for words such as Throne, Imperial; null when none has them all.
DialogueCloseReason has seven values: Choice, Timeout, Code, Cancelled, SceneChange, Load, Dismissed. The events of the manager are in Events reference.
The MessageHandle
Section titled “The MessageHandle”OpenDialogue(DialogueOptions), IM.Announce and IM.Present return a MessageHandle, because the message may be a window, a flag or nothing.
| Member | What it gives |
|---|---|
Request |
The DialogueRequest as asked for. |
IsOpen, IsFlagged, IsSilent, IsClosed |
Where it is. |
CloseReason |
Valid once IsClosed is true. |
Dialogue |
The window of this machine; null while it waits as a flag, or when silent or shown elsewhere. |
Flag |
The MessageFlag, also after it was opened; null when it never was one. |
Closed |
event Action<DialogueCloseReason>, raised once when it closes. |
Close() |
Closes the window or takes the flag out of the tray. |
AddChoice(string text, Action action = null, Func<bool> condition = null, Sprite icon = null) |
Adds a choice that works in every case. A flag shows it when it is opened. Returns the handle. |
Source: Dialogue/Presentation/MessageHandle.cs.
IM.Announce
Section titled “IM.Announce”An announcement with one button.
public static MessageHandle Announce(string title, string text, Actor to = null, MessagePriority priority = MessagePriority.Interrupt, DialogueStyle style = null, string button = "Ok")| Parameter | What it is |
|---|---|
to |
The actor it is for. It is shown only when a player plays that actor; for any other actor nothing is shown and a debug line says so. Null is every player. |
style |
Null uses the Dialogue Manager’s announcement style. |
button |
The text of its one button, which closes it. |
It returns the message for this machine or for to, and null when nobody is shown it or the call was refused. It is a host call: on a multiplayer client it is refused. On such a client DialogueManager.OpenDialogue(DialogueOptions) and IntrigueUI.Notify stay local messages of that machine. Source: Manager/IM.Messages.cs.
IM.Present
Section titled “IM.Present”public static MessageHandle Present(DialogueRequest request, Actor recipient)Shows a DialogueRequest that your code built, to recipient (null is this machine). It is routed as Show Dialogue routes its windows. Add what a click does through the returned handle. A request is shown once; make a new one for each recipient. A host call, refused on a multiplayer client, and null for a null request. A request that is not an announcement waits for its answer.
A flag is a message in the player’s tray. IM.MessageFlags is a static class:
| Member | What it does |
|---|---|
Count |
How many flags wait, for every player of this machine. |
Get(Actor recipient, List<MessageFlag> into) |
Adds the flags that wait for the actor (null is every flag), oldest first. |
bool Open(MessageFlag flag) |
Opens the flag: its window opens now. |
bool Dismiss(MessageFlag flag) |
Takes the flag out without opening it. False for a flag that needs an answer. |
Events onRaised, onOpened, onClosed, onChanged |
All Action<MessageFlag>. |
A MessageFlag is read-only for you. It has Id, RecipientId, Recipient, Kind, Title, ShortText, Icon, Importance, DayRaised, NeedsAnswer, DaysLeft, Scheme, Speaker, Opened, IsWaiting and Count. Count counts repeated announcements when Merge Identical Announcements is on. Source: Dialogue/Presentation/MessageFlag.cs.
Volumes
Section titled “Volumes”DialogueAudio has five channels (AudioChannel): Music, Ambience, Voice, Effects and Interface. All members are static.
| Signature | What it does |
|---|---|
float MasterVolume { get; set; } |
The volume of every dialogue sound, 0 to 1, default 1. |
void SetVolume(AudioChannel channel, float value) |
One channel, 0 to 1. Applies at once, also during a fade. |
float GetVolume(AudioChannel channel) |
The volume set, 1 by default. |
void SetTrack(AudioChannel channel, AudioClip clip, float volume = 1f, float fade = -1f) |
Plays a clip in a loop as the game’s music or ambience until Release. Only Music and Ambience play tracks. A dialogue’s own music plays over it while open. |
void Release(AudioChannel channel, float fade = -1f) |
Stops that track. |
DialogueAudio Instance { get; } |
Null before the Dialogue Manager exists. |
The README shows the call for an options menu: DialogueAudio.SetVolume(AudioChannel.Music, 0.5f). Volumes are not saved, and they go back to 1 when Play mode starts. Save them with your options and set them again at start. Source: Dialogue/Audio/DialogueAudio.cs.
Mistakes and messages
Section titled “Mistakes and messages”OpenDialoguethrows when no Dialogue Manager exists. Assign the Dialogue prefab (Runtime/Dialogue/Dialogue.prefab) to the Dialogue Manager field of the Intrigue Manager, or install your own view.- Calling these from another thread logs an error and does nothing. Move the call to the main thread.
IM.Announceto an actor no player plays shows nothing. The Debug line names the actor.
How it connects
Section titled “How it connects”- Dialogues and announcements explains the Studio side, Show Dialogue and Show Announcement are the nodes.
- Your own dialogue window shows how to draw a dialogue yourself.
- Rules for code that touches Intrigues has the host and main thread rules.