Esempio n. 1
0
    public override IEnumerator RunOptions(Yarn.Options optionsCollection,
                                           Yarn.OptionChooser optionChooser)
    {
        options.gameObject.SetActive(true);

        // todo: make sure that the options aren't too big to fit in the box
        // i don't really know how to check this without actually blitting the
        // text (if i figure that out, change the convoluted logic in RunCommand)

        uint numOptions = (uint)optionsCollection.options.Count;

        if (numOptions > options.Count())
        {
            Debug.LogWarning("Too many options");
        }

        // display all needed options
        for (int i = 0; i < options.Count(); i++)
        {
            DialogueOption option = options.GetOption(i);
            if (i < numOptions)
            {
                option.gameObject.SetActive(true);
                option.SetText(optionsCollection.options[i]);
            }
            else
            {
                option.gameObject.SetActive(false);
            }
        }

        // quick explanation of how cursor math works. bottom-most option is
        // option 0. the one above is option 1 and so on. so with 3 options
        // where the cursor is currently on the the top-most option:
        // -> [option 2]
        //    [option 1]
        //    [option 0]

        // enable and put cursor next to topmost option
        uint currCursorOption = numOptions - 1;

        options.PlaceCursor(currCursorOption);

        while (!Input.GetButtonDown("interact"))
        {
            // move cursor if we get an up or down input
            bool moveCursor = Input.GetButtonDown("vertical");
            if (moveCursor)
            {
                float updown = Input.GetAxisRaw("vertical");
                if (updown == 1)
                {
                    currCursorOption = (currCursorOption + 1) % numOptions;
                }
                else   // updown == -1 (can't be 0 if button was pressed)
                {
                    currCursorOption = (currCursorOption - 1) % numOptions;
                }
                options.PlaceCursor(currCursorOption);
            }
            yield return(null);
        }

        options.gameObject.SetActive(false);
        optionChooser((int)currCursorOption);
        yield return(null);
    }