Page 1 of 2
Skip dialogue choices outside of dialogue
Posted: Wed May 26, 2021 12:55 am
by boz
How might one accomplish the following:
In the dialogue you are given various options, but outside of the dialogue you can take an action that will move the dialogue to a result that is only selected if you take action outside of the dialogue.
Another way of asking this is imagine a made up situation where there are 2 dialogue choices:
Yes
No
And then there's a button outside the dialogue that says "Maybe".
Each of these three buttons have their own dialogue result.
How might this 'Maybe' button notify the dialogue system to go to that third result?
Re: Skip dialogue choices outside of dialogue
Posted: Wed May 26, 2021 8:31 am
by Tony Li
Hi,
I'll assume that you want to define the Maybe button in the conversation editor, so the question node actually links to 3 response nodes (Yes, No, Maybe).
On the Dialogue Editor window's Templates page, you could add a custom field to the dialogue entry template to indicate that the entry's button should appear outside the regular menu.
Then use a subclass of StandardUIMenuPanel that overrides the SetResponseButtons method. For each response, if the custom field indicates the button should appear outside the regular menu, add it there. Rough example:
Code: Select all
public class MyMenuPanel : StandardUIMenuPanel
{
protected override void SetResponseButtons(Response[] responses, Transform target)
{
var regularResponses = new List<Response>();
foreach (var response in responses)
{
if (Field.LookupBool(response.destinationEntry.fields, "Show Outside UI"))
{
// Show special response button somewhere else
}
else
{
regularResponses.Add(response);
}
}
base.SetResponseButtons(regularResponses.ToArray(), target);
}
}
Re: Skip dialogue choices outside of dialogue
Posted: Wed May 26, 2021 6:23 pm
by boz
Oooh I like this.
So let me expand into a specific use-case.
You are given a selection of cards - you can respond "No I don't want any of these" in the dialogue, or you can select a card - each one has a different reaction. (Examples attached)
In the example
Code: Select all
// Show special response button somewhere else
, would there be a way for it to attach itself to those card selection buttons, so that when you click on any one of them, it triggers the <Card Selected> node and drops into the "Our Contract is complete." node?
Thanks
Re: Skip dialogue choices outside of dialogue
Posted: Wed May 26, 2021 7:25 pm
by Tony Li
It's easiest if you set up the <Card Selected> node to always be in a specific position in the response list, such as the first response. Then you can configure your card buttons to click the first response. Example:
Code: Select all
private Response cardSelectedResponse;
public void OnConversationResponseMenu(Response[] responses)
{
cardSelectedResponse = responses[0];
}
public void SelectCard(int cardNumber)
{
// Record the selected card number for the Dialogue System:
DialogueLua.SetVariable("SelectedCardNumber", cardNumber);
// Tell the StandardDialogueUI to use the card selected response:
(DialogueManager.dialogueUI as StandardDialogueUI).OnClick(cardSelectedResponse);
}
Re: Skip dialogue choices outside of dialogue
Posted: Wed May 26, 2021 7:48 pm
by boz
Great! I'll give this a try, thank you!
Re: Skip dialogue choices outside of dialogue
Posted: Wed May 26, 2021 9:46 pm
by Tony Li
Happy to help!
Re: Skip dialogue choices outside of dialogue
Posted: Thu May 27, 2021 2:33 am
by boz
Worked like a charm. Here's what I ended up using:
Code: Select all
protected override void SetResponseButtons(Response[] responses, Transform target)
{
var regularResponses = new List<Response>();
foreach (var response in responses)
{
if (Field.LookupBool(response.destinationEntry.fields, "CardButton"))
{
// Show special response button somewhere else
cardSelectedResponse = response;
}
else
{
regularResponses.Add(response);
}
}
base.SetResponseButtons(regularResponses.ToArray(), target);
}
public void SelectCard()
{
if (Field.LookupBool(cardSelectedResponse.destinationEntry.fields, "CardButton"))
{
(DialogueManager.dialogueUI as StandardDialogueUI).OnClick(cardSelectedResponse);
ResponseMenuController.I.cardSelectedResponse = null;
}
}
Thanks again
Re: Skip dialogue choices outside of dialogue
Posted: Thu May 27, 2021 8:00 am
by Tony Li
Awesome! Glad to help.
Re: Skip dialogue choices outside of dialogue
Posted: Fri Sep 30, 2022 8:38 pm
by boz
Is there a way I could show potential responses in the dialogue, but you can't select one there - instead, you do things in the game and it makes a selection for you?
Sort of like making dialogue selections via your behavior.
Re: Skip dialogue choices outside of dialogue
Posted: Fri Sep 30, 2022 10:02 pm
by Tony Li
Yes. Here are two ways to do that:
1. Make a subclass of StandardUIMenuPanel that overrides the behavior. For example, it could set all of the buttons non-interactable, and instead let actions in the game call the buttons' StandardUIResponseButton.OnClick() methods.
2. Or assign anything to the response buttons' Button component > OnClick() UnityEvent. If anything is assigned to OnClick(), the StandardUIResponseButton component will not automatically add its own OnClick() method to the UnityEvent. This means clicking the button will not select the response. When the player performs a game action, loop through the responses to identify the button that corresponds to the game action. Then call its StandardUIResponseButton.OnClick() method.