Conversation Option Navigation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
rykaan
Posts: 75
Joined: Tue Feb 11, 2020 6:22 am

Conversation Option Navigation

Post 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
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation Option Navigation

Post 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
User avatar
rykaan
Posts: 75
Joined: Tue Feb 11, 2020 6:22 am

Re: Conversation Option Navigation

Post 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
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation Option Navigation

Post by Tony Li »

Good thinking - the Lua function will be handy!
Post Reply