Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public HybrasylDialog NewOptionsDialog(string displayText, dynamic optionsStructure, dynamic handler = null, dynamic callback = null)
        {
            var dialog = new OptionsDialog(displayText);

            dialog.SetCallbackHandler(callback);

            if (optionsStructure is IronPython.Runtime.List)
            {
                // A simple options dialog with a callback handler for the response
                var optionlist = optionsStructure as IronPython.Runtime.List;
                foreach (var option in optionsStructure)
                {
                    if (option is string)
                    {
                        dialog.AddDialogOption(option as string);
                    }
                }
                if (handler != null)
                {
                    dialog.setInputHandler(handler);
                    Logger.InfoFormat("Input handler associated with dialog");
                }
            }
            else if (optionsStructure is IronPython.Runtime.PythonDictionary)
            {
                var hash = optionsStructure as IronPython.Runtime.PythonDictionary;
                foreach (var key in hash.Keys)
                {
                    if (key is string)
                    {
                        dialog.AddDialogOption(key as string, hash[key]);
                    }
                }
            }
            return(new HybrasylDialog(dialog));
        }
Exemplo n.º 4
0
        public HybrasylDialog NewOptionsDialog(String displayText, dynamic optionsStructure, dynamic handler = null, dynamic callback = null)
        {
            var dialog = new OptionsDialog(displayText);
            dialog.SetCallbackHandler(callback);

            if (optionsStructure is IronPython.Runtime.List)
            {
                // A simple options dialog with a callback handler for the response
                var optionlist = optionsStructure as IronPython.Runtime.List;
                foreach (var option in optionsStructure)
                {
                    if (option is String)
                    {
                        dialog.AddDialogOption(option as String);
                    }
                }
                if (handler != null)
                {
                    dialog.setInputHandler(handler);
                    Logger.InfoFormat("Input handler associated with dialog");
                }
            }
            else if (optionsStructure is IronPython.Runtime.PythonDictionary)
            {
                var hash = optionsStructure as IronPython.Runtime.PythonDictionary;
                foreach (var key in hash.Keys)
                {
                    if (key is String)
                    {
                        dialog.AddDialogOption(key as String, hash[key]);
                    }
                }

            }
            return new HybrasylDialog(dialog);
        }
Exemplo n.º 5
0
        /// <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));
        }