public override void RunOptions(Yarn.OptionSet optionSet, ILineLocalisationProvider localisationProvider, Action <int> onOptionSelected)
        {
            if (_options.IsNull())
            {
                _options = new List <IDialogueOptions>();
            }

            if (_poolOptions.IsNull())
            {
                _poolOptions = new Queue <IDialogueOptions>();
            }

            //pool
            for (int i = 0; i < optionSet.Options.Length; i++)
            {
                var option       = optionSet.Options[i];
                var id           = option.ID;
                var localizeText = localisationProvider.GetLocalisedTextForLine(option.Line);
                var text         = localizeText;

                if (_options.Count - 1 < i)
                {
                    var newValue = _poolOptions.Count > 0? _poolOptions.Dequeue() : new YarnSpinnerDialogueOptions(id, text, localizeText);
                    _options.Add(newValue);
                }

                var current = _options[i] as YarnSpinnerDialogueOptions;
                current.id           = id;
                current.text         = text;
                current.localizeText = localizeText;
                current.RemoveAllListener();
                current.AddListener(val =>
                {
                    onOptionSelected?.Invoke(val.id);
                    _ui?.OnOptionsSelected(val.id);
                    _ui?.OnOptionsEnd();
                });
            }

            if (_options.Count > optionSet.Options.Length)
            {
                var count = _options.Count - optionSet.Options.Length;
                for (int i = 0; i < count; i++)
                {
                    var option = _options.Last() as YarnSpinnerDialogueOptions;
                    option.RemoveAllListener();

                    _poolOptions.Enqueue(option);
                    _options.Remove(option);
                }
            }

            _ui?.OnOptionsStart(_options);
        }
Exemple #2
0
        /// Show a list of options, and wait for the player to make a
        /// selection.
        public IEnumerator DoRunOptions(Yarn.OptionSet optionsCollection, IDictionary <string, string> strings, System.Action <int> selectOption)
        {
            // Do a little bit of safety checking
            if (optionsCollection.Options.Length > optionButtons.Count)
            {
                Debug.LogWarning("There are more options to present than there are" +
                                 "buttons to present them in. This will cause problems.");
            }

            // Display each option in a button, and make it visible
            int i = 0;

            waitingForOptionSelection = true;

            foreach (var optionString in optionsCollection.Options)
            {
                optionButtons [i].gameObject.SetActive(true);

                // When the button is selected, tell the dialogue about it
                optionButtons [i].onClick.RemoveAllListeners();
                optionButtons [i].onClick.AddListener(() => {
                    waitingForOptionSelection = false;
                    selectOption(optionString.ID);
                });

                if (strings.TryGetValue(optionString.Line.ID, out var optionText) == false)
                {
                    Debug.LogWarning($"Option {optionString.Line.ID} doesn't have any localised text");
                    optionText = optionString.Line.ID;
                }

                optionButtons [i].GetComponentInChildren <Text> ().text = optionText;

                i++;
            }

            onOptionsStart?.Invoke();

            // Wait until the chooser has been used and then removed
            while (waitingForOptionSelection)
            {
                yield return(null);
            }


            // Hide all the buttons
            foreach (var button in optionButtons)
            {
                button.gameObject.SetActive(false);
            }

            onOptionsEnd?.Invoke();
        }
Exemple #3
0
 /// Display the options, and call the optionChooser when done.
 public abstract void RunOptions(Yarn.OptionSet optionSet,
                                 IDictionary <string, string> strings,
                                 System.Action <int> onOptionSelected);
Exemple #4
0
 public override void RunOptions(Yarn.OptionSet optionsCollection, IDictionary <string, string> strings, System.Action <int> selectOption)
 {
     StartCoroutine(DoRunOptions(optionsCollection, strings, selectOption));
 }
Exemple #5
0
        /// Show a list of options, and wait for the player to make a
        /// selection.
        private IEnumerator DoRunOptions(Yarn.OptionSet optionsCollection, ILineLocalisationProvider localisationProvider, System.Action <int> selectOption)
        {
            // Do a little bit of safety checking
            if (optionsCollection.Options.Length > optionButtons.Count)
            {
                Debug.LogWarning("There are more options to present than there are" +
                                 "buttons to present them in. This will cause problems.");
            }

            // Display each option in a button, and make it visible
            int i = 0;

            waitingForOptionSelection = true;

            currentOptionSelectionHandler = selectOption;

            foreach (var optionString in optionsCollection.Options)
            {
                optionButtons [i].gameObject.SetActive(true);

                // When the button is selected, tell the dialogue about it
                optionButtons [i].onClick.RemoveAllListeners();
                optionButtons [i].onClick.AddListener(() => SelectOption(optionString.ID));

                var optionText = localisationProvider.GetLocalisedTextForLine(optionString.Line);

                if (optionText == null)
                {
                    Debug.LogWarning($"Option {optionString.Line.ID} doesn't have any localised text");
                    optionText = optionString.Line.ID;
                }

                var unityText = optionButtons [i].GetComponentInChildren <Text> ();
                if (unityText != null)
                {
                    if (optionText[0] == '#')
                    {
                        unityText.fontStyle = FontStyle.Bold;
                        optionText          = optionText.Substring(1);
                    }
                    else
                    {
                        unityText.fontStyle = FontStyle.Normal;
                    }
                    unityText.text = optionText;
                }

                var textMeshProText = optionButtons [i].GetComponentInChildren <TMPro.TMP_Text> ();
                if (textMeshProText != null)
                {
                    textMeshProText.text = optionText;
                }

                i++;
            }

            onOptionsStart?.Invoke();

            // Wait until the chooser has been used and then removed
            while (waitingForOptionSelection)
            {
                yield return(null);
            }


            // Hide all the buttons
            foreach (var button in optionButtons)
            {
                button.gameObject.SetActive(false);
            }

            onOptionsEnd?.Invoke();
        }
Exemple #6
0
 /// Runs a set of options.
 /// <inheritdoc/>
 public override void RunOptions(Yarn.OptionSet optionSet, ILineLocalisationProvider localisationProvider, System.Action <int> onOptionSelected)
 {
     StartCoroutine(DoRunOptions(optionSet, localisationProvider, onOptionSelected));
 }
        public override void RunOptions(Yarn.OptionSet optionSet, ILineLocalisationProvider localisationProvider, global::System.Action <int> onOptionSelected)
        {
            DialogueSystem.OnChoicesStarted(optionSet.Options, localisationProvider);

            OptionSelectionHandler = onOptionSelected;
        }