Page 1 of 1
Sorting response buttons depending on some value
Posted: Thu Jan 05, 2023 6:11 am
by Adeoon
Hi, for my case I have 4 types of response buttons (dialogues buttons): Quest lore, side quest, call to action (trade, craft etc.), random normal talk. I want to order response buttons depending on that type, I don't know where should I code that, or maybe there is a way to do that without coding.
Re: Sorting response buttons depending on some value
Posted: Thu Jan 05, 2023 9:13 am
by Tony Li
Hi,
One way to handle this is to set up your dialogue UI's response menu with button positions that are used for different types of responses. If you look at BioWare-style games, for example, their response wheels often put "nice" options in the lower right, "mean" options in the upper right, and skill-based options on the left. You can do the same with the Dialogue System. Set up your buttons, and assign them to the StandardUIResponseMenu component's Buttons list. Note their element numbers in the list (0, 1, 2, etc.). Then include [position=#]
markup tags in your response text. If, for example, a response's Menu Text is "[position=2] Your mother was a hamster and your father smelt of elderberries!" then the Dialogue System will use button #2 in the Buttons list.
If that's not what you want to do -- if you instead want to use a straight list of buttons -- you can add a script with an OnConversationLine(Response[]) method to the Dialogue Manager. In this method, you can sort the Response[] array using whatever criteria you prefer.
Re: Sorting response buttons depending on some value
Posted: Mon Jan 09, 2023 3:28 am
by Adeoon
I can only see OnConversationResponseMenu(Response[]). I don't know if I understood correctly, I attached dialogue system events under my dialogues manager and there I can drag my method which will sort my responses? Also I am not sure, do that method should return array of responses?
Re: Sorting response buttons depending on some value
Posted: Mon Jan 09, 2023 9:23 am
by Tony Li
Which approach do you want to take?
If you want to set up your buttons like this:
- wheelPositions.png (16.94 KiB) Viewed 460 times
Or like this;
- listPositions.png (5.5 KiB) Viewed 460 times
Then use the Buttons list as I described in the first paragraph of my reply. You don't need an OnConversationLine() method. Note that the second image tries to convey that you can tell the menu to hide buttons that aren't needed. The list will show 0, 2, and 3 in a straight list without spaces for the unused buttons.
If you don't want to, or can't, use [position=#], then you'll need to use OnConversationResponseMenu() [EDIT: had incorrectly typed OnConversationLine()]. Sort the array in place. You don't need a Dialogue System Events component. Just add a script with an OnConversationResponseMenu() method to the Dialogue Manager. Each Response object in the Response[] array points to its destinationEntry (the player response dialogue entry). You can use info in the destinationEntry to determine how to sort the array.
Re: Sorting response buttons depending on some value
Posted: Mon Jan 09, 2023 10:33 am
by Adeoon
I want second approach, can't use [position=#]. But I still don't know what you mean saying just use OnConversationLine. I've created script I have to attach it to some gameobject? What is dialogue manager, you mean dialogue controller (prefab)? And my script should inherit something to get that method or is it static like DialogueManager.OnConversationLine or what? I don't really know what you mean saying use OnConversationLine.
Re: Sorting response buttons depending on some value
Posted: Mon Jan 09, 2023 11:33 am
by Tony Li
Sorry, I typo'd OnConversationLine -- I meant to type OnConversationResponseMenu.
Your scene will have a Dialogue Manager GameObject. You may have put the Dialogue Manager prefab in this scene, or the Dialogue Manager may have survived from a previous scene at runtime. (See the
Quick Start tutorial for info about the Dialogue Manager.)
The Dialogue Manager GameObject will receive
Dialogue System Script Messages such as OnConversationResponseMenu.
If you create a new script that contains an OnConversationResponseMenu method and add the script to the Dialogue Manager GameObject, the OnConversationResponseMenu method will run just before the Dialogue System shows the menu to the player.
Let's say, for example, that you have added a custom field named "Importance" to your dialogue entries. (See
Templates for adding custom fields.) Then you can set the Importance field for each response dialogue entry. You can set Quest Lore entries' Importance to 1, Side Quest entries' Importance to 2, etc.
Then create a script with an OnConversationResponseMenu method that sorts the Response[] array by the Importance values. Example:
Code: Select all
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class SortResponsesByImportance : MonoBehaviour
{
public void OnConversationResponseMenu(Response[] responses)
{
var list = new List<Response>(responses);
list.Sort((a, b) => (Importance(a).CompareTo(Importance(b))));
for (int i = 0; i < responses.Length; i++)
{
responses[i] = list[i];
}
}
private int Importance(Response response)
{
return Field.LookupInt(response.destinationEntry.fields, "Importance");
}
}
Re: Sorting response buttons depending on some value
Posted: Tue Jan 10, 2023 5:59 am
by Adeoon
Okay, It seems to work now. Thank you very much!
Re: Sorting response buttons depending on some value
Posted: Tue Jan 10, 2023 9:05 am
by Tony Li
Glad to help!