Page 1 of 1

Conversation Option Navigation

Posted: Mon Mar 29, 2021 6:45 am
by rykaan
Hi Tony,

I'm looking to make a selection menu within a conversation easier to navigate and I wanted to ask a couple of quick questions. Here's what it looks like:
Sandwich Menu.jpg
Sandwich Menu.jpg (150.67 KiB) Viewed 310 times
By default the top option is highlighted whenever navigating to a selection of conversation options. Is there a simple way to choose which option is highlighted instead? That way if the player picked to add a Cucumber, it would be automatically highlighted next time round and reduce the amount of navigation required.

My other question was if it's possible to set up the Response Button Template in Dialogue UI to wrap around a 'down' input back to the top of the responses? So on the image above I would be able to press down on 'Sweetcorn' and 'Lettuce' would be highlighted. In the template it's currently set to automatic navigation, but I'm not sure how to get the wrap around set up when the buttons are being created dynamically.

Cheers,
Rob

Re: Conversation Option Navigation

Posted: Mon Mar 29, 2021 9:05 am
by Tony Li
Hi Rob,
rykaan wrote: Mon Mar 29, 2021 6:45 amBy default the top option is highlighted whenever navigating to a selection of conversation options. Is there a simple way to choose which option is highlighted instead? That way if the player picked to add a Cucumber, it would be automatically highlighted next time round and reduce the amount of navigation required.
You can do it with a bit of scripting. Make a subclass of StandardUIMenuPanel and replace the component on your dialogue UI's menu panel. Override Update() and ShowResponses(). Something like:

Code: Select all

public class MyMenuPanel : StandardUIMenuPanel
{
    private int lastSelectedButtonIndex;
    
    // Record the current menu position:
    protected override void Update()
    {
        base.Update();
        var index = instantiatedButtons.IndexOf(EventSystem.current.currentSelectedGameObject);
        if (index != -1) lastSelectedButtonIndex = index;
    }

    // When showing new menu, try to set selection to 
    public override void ShowResponses(Subtitle subtitle, Response[] responses, Transform target)
    {
        base.ShowResponses(subtitle, responses, target);
        if (0 <= lastSelectedButtonIndex && lastSelectedButtonIndex < instantiatedButtons.Count)
        {
            UITools.Select(instantiatedButtons[lastSelectedButtonIndex].GetComponent<UnityEngine.UI.Button>());
        }
    }
}
rykaan wrote: Mon Mar 29, 2021 6:45 amMy other question was if it's possible to set up the Response Button Template in Dialogue UI to wrap around a 'down' input back to the top of the responses? So on the image above I would be able to press down on 'Sweetcorn' and 'Lettuce' would be highlighted. In the template it's currently set to automatic navigation, but I'm not sure how to get the wrap around set up when the buttons are being created dynamically.
Inspect your response menu's StandardUIMenuPanel component. Tick 'Loop Explicit Navigation':

loopExplicitNavigation.png
loopExplicitNavigation.png (95.4 KiB) Viewed 304 times

Re: Conversation Option Navigation

Posted: Mon Mar 29, 2021 12:22 pm
by rykaan
Excellent response as always Tony.

I hooked up your suggested code to a LUA function that I can call from within conversations, so now I can selectively turn it on and off for specific looping questions. I also ticked the box, good stuff.

Cheers a bunch!
Rob

Re: Conversation Option Navigation

Posted: Mon Mar 29, 2021 12:57 pm
by Tony Li
Good thinking - the Lua function will be handy!