Page 1 of 1

Subtitle UI depending on Number of Answer Options

Posted: Wed Jun 19, 2024 3:01 pm
by AJWantsToSleep
Hello,

I'm new to the Dialogue System and need some help:
1. The Size of the Dialogue Panel needs to change with it's content (Size/Length of the NPC Dialogue, Buttons, Menu Panel)
2. The content of the menu panel should change depending on how many options are available to the player (see attached images). What would be the best approach here?

I'm still trying to get the hang of everything, so I would really appreciate your help :)

Re: Subtitle UI depending on Number of Answer Options

Posted: Wed Jun 19, 2024 4:14 pm
by Tony Li
Hi,

Here are two ways you could approach this:

1. Set up two response menu panels: one with two response buttons, one with four response buttons. Make a subclass of StandardDialogueUI and override ShowResponsesImmediate():

Code: Select all

public class MyDialogueUI : StandardDialogueUI
{
    protected override void ShowResponsesImmediate(Subtitle subtitle, Response[] responses, float timeout)
    {
        // Use menu panel 0 for 1-2 responses, menu panel 1 for 3+ responses:
        var menuPanelToUse = conversationUIElements.menuPanels[(responses.Length <= 2) ? 0 : 1];
        conversationUIElements.standardMenuControls.ForceOverrideMenuPanel(menuPanelToUse);
        base.ShowResponsesImmediate(subtitle, responses, timeout);
    }
}
Then replace your dialogue UI's StandardDialogueUI component with the subclass in place, and assign the menus panels to the Menu Panels list.


2. Or use a single menu panel. Don't make a subclass of StandardDialogueUI. Instead, make a subclass of StandardUIMenuPanel and replace the StandardUIMenuPanel component on the menu panel. Instead of a Vertical Layout Group as most of the built-in prefabs have, use a Grid Layout Group. Override the ShowResponses() method to configure the Grid Layout Group to use 2 columns or 4 columns depending on the number of responses:

Code: Select all

public class MyMenuPanel : StandardUIMenuPanel
{
    public override void ShowResponses(Subtitle subtitle, Response[] responses, Transform target)
    {
       var rectTransform = GetComponent<RectTransform>();
        var gridLayout = GetComponent<GridLayoutGroup>();
        int numColumns = (responses.Length <= 2) ? 1 : 2;
        gridLayout.constraintCount = numColumns;
        gridLayout.cellSize = new Vector2(rectTransform.sizeDelta.x / numColumns, gridLayout.cellSize.y);
        base.ShowResponses(subtitle, responses, target);
    }
}

Re: Subtitle UI depending on Number of Answer Options

Posted: Wed Jun 26, 2024 11:37 am
by AJWantsToSleep
Thank you! It worked :)

Re: Subtitle UI depending on Number of Answer Options

Posted: Wed Jun 26, 2024 11:38 am
by Tony Li
Glad to help!