How to get reference of the Response Button generated by dialogue system

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hyf4053
Posts: 4
Joined: Mon Feb 12, 2024 1:10 pm

How to get reference of the Response Button generated by dialogue system

Post by hyf4053 »

Hello! Here is the situation. I would like to know how to get the reference of the response button generated by the template in the standard UI. Since I need to add a tooltip when the mouse cursor hovers on the response button and not all the response buttons need a tooltip. So I wrote a script for the button template, however, I just could not figure out how to tell the script on the button that the response needs a tooltip when the mouse cursor is on it. Because some information about the context of the tooltips is written in the dialogue, so I need to tell the tooltip the context to display through the dialogue. Is there any way to easily get the reference of the generated response button to tell each button's tooltip what to display? Thanks in advance!
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get reference of the Response Button generated by dialogue system

Post by Tony Li »

Hi,

The cleanest way is to make a subclass of StandardUIResponseButton and use the subclass in place of StandardUIResponseButton on your response buttons.

Override the SetFormattedText() method and access the response property. For example, say the response dialogue entry has a field named "Tooltip":

tooltipField.png
tooltipField.png (14.13 KiB) Viewed 101 times
(I trimmed some irrelevant fields from the screenshot above.)

Then your overridden method might look like:

Code: Select all

public override void SetFormattedText(FormattedText formattedText)
{
    base.SetFormattedText(formattedText);
    var tooltip = Field.LookupValue(response.destinationEntry.fields, "Tooltip");
    if (string.IsNullOrEmpty(tooltip))
    {
        ClearTooltip();
    }
    else
    {
        SetTooltip(tooltip);
    }
}
hyf4053
Posts: 4
Joined: Mon Feb 12, 2024 1:10 pm

Re: How to get reference of the Response Button generated by dialogue system

Post by hyf4053 »

Tony Li wrote: Mon Feb 12, 2024 2:47 pm Hi,

The cleanest way is to make a subclass of StandardUIResponseButton and use the subclass in place of StandardUIResponseButton on your response buttons.

Override the SetFormattedText() method and access the response property. For example, say the response dialogue entry has a field named "Tooltip":


tooltipField.png

(I trimmed some irrelevant fields from the screenshot above.)

Then your overridden method might look like:

Code: Select all

public override void SetFormattedText(FormattedText formattedText)
{
    base.SetFormattedText(formattedText);
    var tooltip = Field.LookupValue(response.destinationEntry.fields, "Tooltip");
    if (string.IsNullOrEmpty(tooltip))
    {
        ClearTooltip();
    }
    else
    {
        SetTooltip(tooltip);
    }
}
Thank you Tony, this is helpful!
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get reference of the Response Button generated by dialogue system

Post by Tony Li »

Glad to help!
Post Reply