using System; namespace Framework.Dialogue2 { /// Provides helper methods for dealing with dialogue canvases public static class DialogueCanvasHelper { #region class DialogueText /// Dialogue text container without any extras private class DialogueText : IDialogueText { /// Initialized a new text element for dialogues /// Text that will be shown on the dialogue public DialogueText(string text) { this.text = text; } /// Text that will be shown in the dialogue public string Text { get { return this.text; } } /// Text that will be shown in the dialogue private string text; } #endregion // class DialogueText /// Displays the dialogue canvas using only text for the dialogue /// Canvas on which dialogue will be shown /// Speech that will be shown on the canvas (can be null) /// Choices that will be available to the user (can be null) /// /// This constructs a simple text-only IDialogueText wrapper around the passed strings. /// It is useful for very simply dialogue and testing only. Actual games likely want /// to display character portraits, names and other things with their dialogue and /// need a custom object that decorates text with a wrapper providing these informations. /// public static void Show(this IDialogueCanvas canvas, string speech, params string[] choices) { // Count the number of choices specified by the caller int choiceCount; { if(choices == null) { choiceCount = 0; } else { choiceCount = choices.Length; } } // If the caller specified no choices, use the speech-only invocation if(choiceCount == 0) { canvas.ShowSpeech(new DialogueText(speech)); } else { // Choices specified // Wrap the choices in dialogue text elements var choiceTexts = new IDialogueText[choiceCount]; for(int index = 0; index < choiceCount; ++index) { choiceTexts[index] = new DialogueText(choices[index]); } // If no speech was specified, use a choice-only dialogue if(string.IsNullOrEmpty(speech)) { canvas.ShowChoices(new ArraySegment(choiceTexts, 0, choiceCount)); } else { // We have speech and choices canvas.ShowSpeechAndChoices( new DialogueText(speech), new ArraySegment(choiceTexts, 0, choiceCount) ); } } } } } // namespace Framework.Dialogue