Your own dialogue window
What this page is for
Section titled “What this page is for”The ready-made dialogue window is one way to draw a dialogue. If your game has its own UI, you can draw dialogues and announcements yourself, in any technology. Intrigues keeps everything that is not drawing: the conditions of the choices, the time limit, the order of open dialogues, restore after a load, the sounds, and the multiplayer routes.
When you come here
Section titled “When you come here”- Your game uses UI Toolkit, a UI kit, IMGUI or a 3D speech bubble.
- The ready-made window does not fit your look, and you would rather draw the dialogue in your own UI than restyle it.
Install your view
Section titled “Install your view”Write a class that implements IDialogueView. It has one method:
void Show(DialogueModel dialogue);Show is called once per dialogue or announcement, late in the frame it was asked for. The model is never null. Show must not throw: an exception is logged once and the dialogue closes at once with the reason Code, because nobody would draw it.
Install the view with IntrigueUI.Dialogues.Use(IDialogueView view). From then on every dialogue and announcement of this machine goes to it. Use(null) brings the ready-made window back. Dialogues that are already open stay where they opened. Call Use once, for example in Awake; the setting is cleared when Play mode starts.
Member of IntrigueUI.Dialogues |
What it gives |
|---|---|
View |
The installed view; null while the ready-made window draws. |
Open |
The open dialogues the view draws, bottom first, top last, hidden ones included. |
Top |
The top-most shown dialogue; null when none. |
What the model holds
Section titled “What the model holds”DialogueModel is what you draw.
| Member | What it is |
|---|---|
Title, PlainTitle |
The title, with and without rich text tags. |
Text, PlainText |
The text. Text is TextMesh Pro rich text with pacing marks; PlainText is plain letters, marks removed. |
Speaker, Recipient, Listener (the same as Recipient), Conspirator, Target, Scheme |
The actors and the scheme; null where they do not apply. |
Picture, Style, Kind |
The picture, the style, and the kind of message. |
Choices |
IReadOnlyList<ChoiceModel>. |
HasTimeLimit, TimeLimit, Remaining, IsCountingDown |
The time limit. |
IsTop, IsHidden, IsOpen, IsRestored, IsRevealed, ChoicesHeld, ChoicesReady, CloseReason, ContinuesConversation, AnnouncementCount |
State. |
Events ChoicesChanged, Changed, TopChanged, SkipRequested(bool), Closed(DialogueCloseReason) |
Redraw cues. Closed is the last event: take the window away. |
A ChoiceModel has Text, PlainText, Icon, Selectable, Available, IsHidden, ClosesDialogue, Tooltip, UnavailableTooltip, SuccessChance, FailureChance, Index, Key, Dialogue, Conditional, HideWhenUnavailable, Data and Refresh().
Only the top-most dialogue starts and counts down. The others stand still, as covered windows do, so a view that shows several at once should dim the ones that are not on top and listen to TopChanged to know when that changes.
Writing the text at your own pace
Section titled “Writing the text at your own pace”By default the choices can be picked at once and the time limit runs from Show. A view that writes the text letter by letter calls dialogue.HoldChoices() inside Show and dialogue.ReleaseChoices() once the text is written. Until then the time limit waits. HoldChoices() returns false when there is nothing to hold, for a restored dialogue. A style that shows the choices with the text lets them be picked while the text is written (ChoicesReady). SkipRequested asks a writing view to finish.
Answer and close
Section titled “Answer and close”| Call | What it does |
|---|---|
ChoiceModel.Pick() |
Picks the choice, as a click on a ready-made button. On a client it reaches the host. |
ChoiceModel.CanPick() |
What Pick would answer now. |
DialogueModel.Skip() |
Asks the view to finish writing. |
DialogueModel.Close() |
Closes the dialogue from code, with the reason Code. A scheme flow that waited for an answer does not go on. |
They return a CommandResult (Outcome, Ok, Reason) and never throw. The same commands exist as IntrigueUI.Commands.Answer, CanAnswer, SkipDialogue, CloseDialogue and their Can... twins.
An example
Section titled “An example”This is the example from the XML comment of IDialogueView.cs. MyUI and window stand for your own drawing code. They are not part of Intrigues.
public sealed class MyDialogueView : IDialogueView{ public void Show(DialogueModel dialogue) { var window = MyUI.OpenWindow(dialogue.Title, dialogue.PlainText, dialogue.Picture); dialogue.HoldChoices(); // this view writes the text letter by letter window.WriteText(dialogue.PlainText, onDone: dialogue.ReleaseChoices); dialogue.SkipRequested += forced => window.FinishWriting();
void DrawChoices() { window.ClearButtons(); foreach (var choice in dialogue.Choices) { if (choice.IsHidden) continue; var button = window.AddButton(choice.PlainText, choice.Icon, enabled: choice.Selectable); button.Tooltip = choice.Selectable ? choice.Tooltip : choice.UnavailableTooltip; button.Clicked += () => choice.Pick(); } }
DrawChoices(); dialogue.ChoicesChanged += DrawChoices; dialogue.Changed += () => window.SetTexts(dialogue.Title, dialogue.PlainText, dialogue.Picture); dialogue.TopChanged += () => window.SetDimmed(!dialogue.IsTop); window.EveryFrame += () => window.SetCountdown(dialogue.HasTimeLimit ? dialogue.Remaining : -1f); dialogue.Closed += reason => window.Close(); }}// Once, for example in a game component's Awake: IntrigueUI.Dialogues.Use(new MyDialogueView());Mistakes and messages
Section titled “Mistakes and messages”- A view that throws in
Showloses the dialogue: it closes at once. - Choices held for more than 120 seconds of real time are released with a warning. Call
ReleaseChoiceswhen the text is written. - With a view installed, the scene needs no Dialogue Manager prefab. Intrigues makes a bare Dialogue Host under the Intrigue Manager, which keeps sessions, time limits, order and audio. The Intrigue Manager is still needed. If you install the view after the Intrigue Manager started, it logs “No Dialogue Manager is assigned” once at start-up; dialogues still reach your view.
- With your own view, cue sounds are not played and all cues come at once when the text counts as written. While your view shows a dialogue, open ready-made windows stand still.
How it connects
Section titled “How it connects”- Dialogues and announcements from code opens the messages your view draws.
- IntrigueUI from code lists the other parts of the UI layer.
- Dialogues and announcements shows the ready-made window from the Studio side.