/// 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)
    {
        ds.ClearOptions();
        end = false;

        waitingForOptionSelection = true;

        currentOptionSelectionHandler = selectOption;

        foreach (var optionString in optionsCollection.Options)
        {
            string text = localisationProvider.GetLocalisedTextForLine(optionString.Line);
            ds.AddChoice(text, () => SelectOption(optionString.ID));
        }

        onOptionsStart?.Invoke();

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

        onOptionsEnd?.Invoke();
    }
Example #2
0
    private IEnumerator DoRunOptions(Yarn.OptionSet optionsCollection, ILineLocalisationProvider localisationProvider, System.Action <int> selectOption)
    {
        if (optionsCollection.Options.Length > optionButtons.Count)
        {
            Debug.LogWarning("There arent enough buttons for the amount of choices we need to display. This will cause problems");
        }

        int i = 0;

        ds = DialogState.Choices;

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

            optionButtons[i].onClick.RemoveAllListeners();
            optionButtons[i].onClick.AddListener(() => SelectOption(optionString.ID, selectOption));

            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 <TextMeshProUGUI> ();
            if (unityText != null)
            {
                unityText.text = optionText;
            }
            i++;
        }

        while (ds == DialogState.Choices)
        {
            yield return(null);
        }
        Debug.Log("Alpha");

        // TODO: THIS SEEMS KINDA SKETCH
        // speaker.portraitUI.SetActive(false);

        // Hide all the buttons
        foreach (var button in optionButtons)
        {
            button.gameObject.SetActive(false);
        }
    }
Example #3
0
    public void SetupOptions(Yarn.OptionSet optionsCollection, IDictionary <string, string> strings, System.Action <int> selectOption)
    {
        //Do the initial setup for the options
        IsInOptions      = true;
        optionSelected   = 0;
        optionsAvailable = optionsCollection;
        RightArrow.SetActive(true);
        dialogueUI.SetIsInOptions(true);
        dialogueUI.SetWaitingForOptionSelection(true);
        dialogueUI.SetcurrentOptionSelectionHandler(selectOption);
        dialogueUI.CallOnOptionsStart();

        //This is to handle localisation, but I'm not doing that yet

        /*
         * if (strings.TryGetValue(optionsCollection.Options[0].Line.ID, out var optionText) == false)
         * {
         *  Debug.LogWarning($"Option {optionsCollection.Options[0].Line.ID} doesn't have any localised text");
         *  optionText = optionsCollection.Options[0].Line.ID;
         * }
         */
        //Show the first option
        dialogueRunner.HandleLine(optionsCollection.Options[0].Line);
    }
 /// Runs a set of options.
 /// <inheritdoc/>
 public override void RunOptions(Yarn.OptionSet optionSet, ILineLocalisationProvider localisationProvider, System.Action <int> onOptionSelected)
 {
     StartCoroutine(DoRunOptions(optionSet, localisationProvider, onOptionSelected));
 }