public HybrasylDialog NewOptionsDialog(string displayText, HybrasylDialogOptions dialogOptions, string handler = "", string callback = "") { var dialog = new OptionsDialog(displayText); foreach (DictionaryEntry entry in dialogOptions.Options) { dialog.AddDialogOption(entry.Key as string, entry.Value as string); } dialog.SetInputHandler(handler); dialog.SetCallbackHandler(callback); return(new HybrasylDialog(dialog)); }
/// <summary> /// Create a new options dialog (a dialog that displays clickable options to the player). /// </summary> /// <param name="displayText">The text to be displayed in the dialog</param> /// <param name="dialogOptions">A collection of dialog options (eg HybrasylDialogOptions) associated with this dialog</param> /// <param name="callback">A callback function or expression that will fire when this dialog is shown to a player</param> /// <param name="handler">A callback function or expression that will handle the response once a player selects (clicks) an option</param> /// <returns>The constructed dialog</returns> public HybrasylDialog NewOptionsDialog(string displayText, HybrasylDialogOptions dialogOptions, string callback = "", string handler = "") { var dialog = new OptionsDialog(displayText); foreach (DictionaryEntry entry in dialogOptions.Options) { if (entry.Value is string) { // Callback dialog.AddDialogOption(entry.Key as string, entry.Value as string); } else if (entry.Value is HybrasylDialog) { var hd = entry.Value as HybrasylDialog; if (hd.DialogType == typeof(JumpDialog)) { // Dialog jump dialog.AddDialogOption(entry.Key as string, hd.Dialog as JumpDialog); } else { GameLog.Error("Unknown dialog type {0} in NewOptionsDialog - only JumpDialog is allowed currently"); } } else if (entry.Value is null) { // This is JUST an option, with no callback or jump dialog. The dialog handler will process the option itself. dialog.AddDialogOption(entry.Key as string); } else if (entry.Value is HybrasylDialogSequence) { var hds = entry.Value as HybrasylDialogSequence; dialog.AddDialogOption(entry.Key as string, hds.Sequence); } else { GameLog.Error($"Unknown type {entry.Value.GetType().Name} passed as argument to NewOptionsDialog call"); } } if (dialog.OptionCount == 0) { GameLog.Warning($"OptionsDialog with no options created. This dialog WILL NOT render. DisplayText follows: {displayText}"); } dialog.SetInputHandler(handler); dialog.SetCallbackHandler(callback); return(new HybrasylDialog(dialog)); }
/// <summary> /// Create a new options dialog (a dialog that displays clickable options to the player). /// </summary> /// <param name="displayText">The text to be displayed in the dialog</param> /// <param name="dialogOptions">A collection of dialog options (eg HybrasylDialogOptions) associated with this dialog</param> /// <param name="callback">A callback function or expression that will fire when this dialog is shown to a player</param> /// <param name="handler">A callback function or expression that will handle the response once a player selects (clicks) an option</param> /// <returns>The constructed dialog</returns> public HybrasylDialog NewOptionsDialog(string displayText, HybrasylDialogOptions dialogOptions, string callback = "", string handler = "") { if (string.IsNullOrEmpty(displayText)) { GameLog.ScriptingError("NewOptionsDialog: display text (first argument) cannot be null or empty"); return(null); } if (dialogOptions is null || dialogOptions.Options.Count == 0) { GameLog.ScriptingError("NewOptionsDialog: dialogOptions (second or greater argument(s)) null, or had no options"); return(null); } var dialog = new OptionsDialog(displayText); foreach (DictionaryEntry entry in dialogOptions.Options) { if (entry.Value is string) { // Callback dialog.AddDialogOption(entry.Key as string, entry.Value as string); } else if (entry.Value is HybrasylDialog) { var hd = entry.Value as HybrasylDialog; if (hd.DialogType == typeof(JumpDialog)) { // Dialog jump dialog.AddDialogOption(entry.Key as string, hd.Dialog as JumpDialog); } else { GameLog.ScriptingError("NewOptionsDialog: one or more passed option(s) uses type {type} - only jump dialogs are allowed currently", entry.Value.GetType().Name); } } else if (entry.Value is null) { // This is JUST an option, with no callback or jump dialog. The dialog handler will process the option itself. dialog.AddDialogOption(entry.Key as string); } else if (entry.Value is HybrasylDialogSequence) { var hds = entry.Value as HybrasylDialogSequence; dialog.AddDialogOption(entry.Key as string, hds.Sequence); } else { GameLog.ScriptingError("NewOptionsDialog: one or more passed option(s) was an unknown type {type} - this will not work", entry.Value.GetType().Name); } } if (dialog.OptionCount == 0) { GameLog.ScriptingError("NewOptionsDialog: no options were passed or created. This dialog WILL NOT render. DisplayText follows: {displayText}", displayText); } dialog.SetInputHandler(handler); dialog.SetCallbackHandler(callback); return(new HybrasylDialog(dialog)); }